@placetopay/lightbox-sdk 0.2.0 → 0.3.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 CHANGED
@@ -3,15 +3,14 @@ Small javascript library to encapsulate websites in a lightbox with configurable
3
3
 
4
4
  The library consists of 2 parts:
5
5
 
6
- - LightboxClient
7
6
  - LightboxApp
7
+ - LightboxClient
8
8
 
9
9
  If you have a site A, and within it you want to display a site B using Lightbox-sdk:
10
10
 
11
11
  On site A the LightboxClient will be used (site that will display a lightbox)
12
12
 
13
13
  - It will define which site will be displayed in the lightbox
14
- - It will define the style of the lightbox
15
14
  - It will define the callbacks for each lightbox event
16
15
 
17
16
  On site B LightboxApp will be used (site that will be shown in a lightbox)
package/package.json CHANGED
@@ -1,26 +1,12 @@
1
1
  {
2
2
  "name": "@placetopay/lightbox-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
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
- "/dist/lib"
8
+ "/dist"
9
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
10
  "repository": {
25
11
  "type": "git",
26
12
  "url": "git+https://JuanZea@bitbucket.org/placetopay/lightbox-sdk.git"
@@ -39,19 +25,6 @@
39
25
  },
40
26
  "homepage": "https://bitbucket.org/placetopay/lightbox-sdk#readme",
41
27
  "devDependencies": {
42
- "@types/node": "^18.7.23",
43
- "@types/react": "^18.0.21",
44
- "@types/react-dom": "^18.0.6",
45
- "@typescript-eslint/eslint-plugin": "^5.38.1",
46
- "@typescript-eslint/parser": "^5.38.1",
47
- "@vitejs/plugin-react": "^2.1.0",
48
- "copyfiles": "^2.4.1",
49
- "eslint": "^8.24.0",
50
- "prettier": "^2.7.1",
51
- "react": "^18.2.0",
52
- "react-dom": "^18.2.0",
53
- "rimraf": "^3.0.2",
54
- "typescript": "^4.8.3",
55
- "vite": "^3.1.4"
28
+ "typescript": "^4.8.3"
56
29
  }
57
30
  }
@@ -1,5 +0,0 @@
1
- import { ClientStyles } from '@/types';
2
- export declare const LightboxApp: {
3
- emit: (type: string, data: unknown) => void;
4
- sendStyles: (styles: ClientStyles) => void;
5
- };
@@ -1,9 +0,0 @@
1
- import { LightboxAppEvents } from '@/constants';
2
- export var LightboxApp = {
3
- emit: function (type, data) {
4
- globalThis.parent.postMessage({ event: LightboxAppEvents.EMIT, type: type, data: data }, '*');
5
- },
6
- sendStyles: function (styles) {
7
- globalThis.parent.postMessage({ event: LightboxAppEvents.SEND_STYLES, styles: styles }, '*');
8
- },
9
- };
@@ -1,3 +0,0 @@
1
- import { ClientCallbacks, ClientStyles } from '@/types';
2
- export declare const mountListeners: (callbacks: ClientCallbacks, styles: ClientStyles) => void;
3
- export declare const mountIFrameElement: (url: string, styles: ClientStyles) => void;
@@ -1,64 +0,0 @@
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
- import { Config } from '@/config';
13
- import { Styles, ElementIds, Dimensions, LightboxAppEvents } from '@/constants';
14
- export var mountListeners = function (callbacks, styles) {
15
- if (!callbacks)
16
- return;
17
- var callbacksListener = function (event) {
18
- var _a;
19
- if (event.data.event !== LightboxAppEvents.EMIT)
20
- return;
21
- (_a = callbacks[event.data.type]) === null || _a === void 0 ? void 0 : _a.call(callbacks, event.data.data);
22
- unmountLightbox(callbacksListener);
23
- };
24
- var stylesListener = function (event) {
25
- if (event.data.event !== LightboxAppEvents.SEND_STYLES)
26
- return;
27
- mountStyles(__assign(__assign(__assign({}, event.data.styles), styles), { background: __assign(__assign({}, event.data.styles.background), styles.background) }));
28
- globalThis.removeEventListener('message', stylesListener);
29
- };
30
- globalThis.addEventListener('message', callbacksListener);
31
- globalThis.addEventListener('message', stylesListener);
32
- };
33
- export var mountIFrameElement = function (url, styles) {
34
- var wrapper = document.createElement('div');
35
- wrapper.id = ElementIds.WRAPPER_ID;
36
- var iframe = document.createElement('iframe');
37
- iframe.src = url;
38
- iframe.id = ElementIds.IFRAME_ID;
39
- mountStyles(styles);
40
- document.body.appendChild(wrapper);
41
- wrapper.appendChild(iframe);
42
- };
43
- var mountStyles = function (styles) {
44
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
45
- 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];
46
- 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, "rgb(".concat(background.join(', '), ")"));
48
- var rounded = (_g = styles.rounded) !== null && _g !== void 0 ? _g : 0;
49
- document.documentElement.style.setProperty(Styles.ROUNDED, "".concat(rounded.toString(), "px"));
50
- var height = (_h = styles.height) !== null && _h !== void 0 ? _h : Config.defaultDimension.height;
51
- if (styles.dimension)
52
- height = Dimensions[styles.dimension.toUpperCase()].height;
53
- document.documentElement.style.setProperty(Styles.MAX_HEIGHT, "".concat(height.toString(), "px"));
54
- var width = (_j = styles.width) !== null && _j !== void 0 ? _j : Config.defaultDimension.width;
55
- if (styles.dimension)
56
- width = Dimensions[styles.dimension.toUpperCase()].width;
57
- document.documentElement.style.setProperty(Styles.MAX_WIDTH, "".concat(width.toString(), "px"));
58
- };
59
- var unmountLightbox = function (listener) {
60
- var _a;
61
- (_a = document.getElementById(ElementIds.WRAPPER_ID)) === null || _a === void 0 ? void 0 : _a.remove();
62
- globalThis.removeEventListener('message', listener);
63
- document.documentElement.style.removeProperty(Styles.BACKGROUND_COLOR);
64
- };
@@ -1,4 +0,0 @@
1
- import { InitOptions, LightboxInstance } from '@/types';
2
- export declare const LightboxClient: {
3
- init: (url: string, options?: InitOptions) => LightboxInstance;
4
- };
@@ -1,22 +0,0 @@
1
- import { redirectBasedOnDriver } from '@/helpers';
2
- import { mountIFrameElement, mountListeners } from './assemblers';
3
- export var LightboxClient = {
4
- init: function (url, options) {
5
- var _a, _b, _c;
6
- var lightbox = {
7
- callbacks: (_a = options === null || options === void 0 ? void 0 : options.callbacks) !== null && _a !== void 0 ? _a : {},
8
- allowRedirects: (_b = options === null || options === void 0 ? void 0 : options.allowRedirects) !== null && _b !== void 0 ? _b : true,
9
- styles: (_c = options === null || options === void 0 ? void 0 : options.styles) !== null && _c !== void 0 ? _c : {},
10
- open: function () {
11
- if (lightbox.allowRedirects)
12
- redirectBasedOnDriver(url);
13
- mountListeners(lightbox.callbacks, lightbox.styles);
14
- mountIFrameElement(url, lightbox.styles);
15
- },
16
- };
17
- if (options === null || options === void 0 ? void 0 : options.dispatch)
18
- lightbox.open();
19
- console.log("lightbox-sdk | client initialized (".concat(url, ")"));
20
- return lightbox;
21
- },
22
- };
@@ -1,6 +0,0 @@
1
- export declare const Config: {
2
- defaultDimension: {
3
- height: number;
4
- width: number;
5
- };
6
- };
@@ -1,4 +0,0 @@
1
- import { Dimensions } from './constants';
2
- export var Config = {
3
- defaultDimension: Dimensions.MD,
4
- };
@@ -1,29 +0,0 @@
1
- export declare const ElementIds: {
2
- WRAPPER_ID: string;
3
- IFRAME_ID: string;
4
- STYLES_ID: string;
5
- };
6
- export declare enum LightboxAppEvents {
7
- EMIT = "emit",
8
- SEND_STYLES = "sendStyles"
9
- }
10
- export declare const Styles: {
11
- BACKGROUND_COLOR: string;
12
- ROUNDED: string;
13
- MAX_HEIGHT: string;
14
- MAX_WIDTH: string;
15
- };
16
- export declare const Dimensions: {
17
- SM: {
18
- height: number;
19
- width: number;
20
- };
21
- MD: {
22
- height: number;
23
- width: number;
24
- };
25
- LG: {
26
- height: number;
27
- width: number;
28
- };
29
- };
@@ -1,21 +0,0 @@
1
- export var ElementIds = {
2
- WRAPPER_ID: 'placetopay_lightbox_wrapper',
3
- IFRAME_ID: 'placetopay_lightbox',
4
- STYLES_ID: 'placetopay-lightbox',
5
- };
6
- export var LightboxAppEvents;
7
- (function (LightboxAppEvents) {
8
- LightboxAppEvents["EMIT"] = "emit";
9
- LightboxAppEvents["SEND_STYLES"] = "sendStyles";
10
- })(LightboxAppEvents || (LightboxAppEvents = {}));
11
- export var Styles = {
12
- BACKGROUND_COLOR: '--placetopay-lightbox-background-color',
13
- ROUNDED: '--placetopay-lightbox-border-radius',
14
- MAX_HEIGHT: '--placetopay-lightbox-max-height',
15
- MAX_WIDTH: '--placetopay-lightbox-max-width',
16
- };
17
- export var Dimensions = {
18
- SM: { height: 400, width: 320 },
19
- MD: { height: 640, width: 512 },
20
- LG: { height: 1000, width: 800 },
21
- };
@@ -1 +0,0 @@
1
- export declare const redirectBasedOnDriver: (url: string) => void;
@@ -1,7 +0,0 @@
1
- export var redirectBasedOnDriver = function (url) {
2
- if (navigator.userAgent.match(/iPhone|iPad|iPod/i) ||
3
- /^((?!chrome|android).)*safari/i.test(navigator.userAgent) // regex from https://stackoverflow.com/a/23522755
4
- ) {
5
- location.href = url;
6
- }
7
- };
@@ -1,2 +0,0 @@
1
- export { LightboxApp } from './LightboxApp';
2
- export { LightboxClient } from './LightboxClient';
@@ -1,2 +0,0 @@
1
- export { LightboxApp } from './LightboxApp';
2
- export { LightboxClient } from './LightboxClient';
@@ -1,32 +0,0 @@
1
- import { LightboxAppEvents } from './constants';
2
- export declare type ClientCallback = (data: unknown) => void;
3
- export declare type ClientCallbacks = {
4
- [key: string]: ClientCallback | undefined;
5
- };
6
- export declare type ClientStyles = {
7
- background?: {
8
- color?: string;
9
- opacity?: number;
10
- };
11
- rounded?: number;
12
- dimension?: 'sm' | 'md' | 'lg';
13
- height?: number;
14
- width?: number;
15
- };
16
- export declare type InitOptions = {
17
- dispatch?: boolean;
18
- callbacks?: ClientCallbacks;
19
- allowRedirects?: boolean;
20
- styles?: ClientStyles;
21
- };
22
- export declare type ApiStructure = {
23
- event: LightboxAppEvents;
24
- data: unknown;
25
- type: string;
26
- };
27
- export declare type LightboxInstance = {
28
- styles: ClientStyles;
29
- allowRedirects: boolean;
30
- callbacks: ClientCallbacks;
31
- open: () => void;
32
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
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
- user-select: none;
13
- }
14
-
15
- #placetopay_lightbox {
16
- border: 0;
17
- border-radius: var(--placetopay-lightbox-border-radius);
18
- overflow: hidden;
19
- background-color: white;
20
- height: 100%;
21
- width: 100%;
22
- max-height: var(--placetopay-lightbox-max-height);
23
- max-width: var(--placetopay-lightbox-max-width);
24
- overflow: auto;
25
- box-shadow: 0px 0px 60px rgba(0, 0, 0, 0.5);
26
- }