@placetopay/lightbox-sdk 2.0.4 → 2.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.
@@ -1,3 +1,3 @@
1
- import { ClientCallbacks, LightboxStyles } from '../types';
2
- export declare const mountLightbox: (url: string, callbacks: ClientCallbacks, styles: LightboxStyles, closeButtonEnabled: boolean) => void;
1
+ import { MountLightboxOptions } from '../types';
2
+ export declare const mountLightbox: ({ url, callbacks, styles, closeButtonEnabled, enforceStyles }: MountLightboxOptions) => void;
3
3
  export declare const unmountLightbox: (target: string) => void;
@@ -1,7 +1,7 @@
1
1
  import { Styles, ElementIds, LightboxEvents as LE } from '../constants';
2
2
  import { setStyle, unsetStyle } from '../helpers';
3
3
  let listener;
4
- export const mountLightbox = (url, callbacks, styles, closeButtonEnabled) => {
4
+ export const mountLightbox = ({ url, callbacks, styles, closeButtonEnabled, enforceStyles }) => {
5
5
  const wrapper = document.createElement('div');
6
6
  wrapper.id = new URL(url).origin;
7
7
  wrapper.className = ElementIds.WRAPPER_ID;
@@ -21,15 +21,18 @@ export const mountLightbox = (url, callbacks, styles, closeButtonEnabled) => {
21
21
  });
22
22
  wrapper.appendChild(closeButton);
23
23
  }
24
- mountListener(callbacks, styles, closeButton);
24
+ mountListener({ callbacks, styles, closeButton, enforceStyles });
25
25
  };
26
- const mountListener = (callbacks, styles, closeButton) => {
26
+ const mountListener = ({ callbacks, styles, closeButton, enforceStyles }) => {
27
27
  listener = (event) => {
28
28
  var _a;
29
29
  if (event.data.type === LE.CLOSE)
30
30
  unmountLightbox(event.origin);
31
- if (event.data.type === LE.UPDATE_STYLES)
32
- updateStyles(Object.assign(Object.assign({}, event.data.payload), styles));
31
+ if (event.data.type === LE.UPDATE_STYLES) {
32
+ const newStyles = enforceStyles
33
+ ? Object.assign(Object.assign({}, event.data.payload), styles) : Object.assign(Object.assign({}, styles), event.data.payload);
34
+ updateStyles(newStyles);
35
+ }
33
36
  if (event.data.type === LE.HIDE_CLOSE_BUTTON)
34
37
  closeButton === null || closeButton === void 0 ? void 0 : closeButton.remove();
35
38
  (_a = callbacks[event.data.type]) === null || _a === void 0 ? void 0 : _a.call(callbacks, event.data.payload);
@@ -23,9 +23,16 @@ export const createLightbox = (url, options) => {
23
23
  lightbox.callbacks[name] = callback;
24
24
  },
25
25
  open: () => {
26
+ var _a;
26
27
  if (lightbox.allowRedirects)
27
28
  redirectBasedOnDriver(url);
28
- mountLightbox(url, lightbox.callbacks, lightbox.styles, lightbox.closeButton);
29
+ mountLightbox({
30
+ url,
31
+ callbacks: lightbox.callbacks,
32
+ styles: lightbox.styles,
33
+ closeButtonEnabled: lightbox.closeButton,
34
+ enforceStyles: (_a = options === null || options === void 0 ? void 0 : options.enforceStyles) !== null && _a !== void 0 ? _a : false,
35
+ });
29
36
  },
30
37
  };
31
38
  if (options === null || options === void 0 ? void 0 : options.launch)
package/dist/types.d.ts CHANGED
@@ -1,29 +1,41 @@
1
1
  export type ClientCallback = (payload?: unknown) => void;
2
- export type ClientCallbacks = {
3
- [key: string]: ClientCallback | undefined;
4
- };
5
- export type LightboxStyles = {
6
- backdropColor?: string;
7
- backdropOpacity?: number;
8
- height?: string | number;
9
- width?: string | number;
10
- radius?: number;
11
- };
2
+ export type ClientCallbacks = Record<string, ClientCallback | undefined>;
3
+ export type LightboxStyles = Partial<{
4
+ backdropColor: string;
5
+ backdropOpacity: number;
6
+ height: string | number;
7
+ width: string | number;
8
+ radius: number;
9
+ }>;
12
10
  export type ApiStructure = {
13
11
  type: string;
14
12
  payload?: unknown;
15
13
  preventClose?: boolean;
16
14
  };
17
- export type InternalOptions = {
18
- launch?: boolean;
15
+ export type InternalOptions = Partial<{
16
+ launch: boolean;
17
+ enforceStyles: boolean;
18
+ }>;
19
+ export type ExposedOptions = Partial<{
20
+ allowRedirects: boolean;
21
+ callbacks: ClientCallbacks;
22
+ closeButton: boolean;
23
+ styles: LightboxStyles;
24
+ }>;
25
+ export type InitialOptions = ExposedOptions & InternalOptions;
26
+ export type MountLightboxOptions = {
27
+ url: string;
28
+ callbacks: ClientCallbacks;
29
+ styles: LightboxStyles;
30
+ closeButtonEnabled: boolean;
31
+ enforceStyles: boolean;
19
32
  };
20
- export type ExposedOptions = {
21
- allowRedirects?: boolean;
22
- callbacks?: ClientCallbacks;
23
- closeButton?: boolean;
24
- styles?: LightboxStyles;
33
+ export type MountListenerOptions = {
34
+ callbacks: ClientCallbacks;
35
+ styles: LightboxStyles;
36
+ closeButton: HTMLButtonElement;
37
+ enforceStyles: boolean;
25
38
  };
26
- export type InitialOptions = ExposedOptions & InternalOptions;
27
39
  export type LightboxInstance = Required<ExposedOptions> & {
28
40
  url: string;
29
41
  on: (name: string, callback: ClientCallback) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@placetopay/lightbox-sdk",
3
- "version": "2.0.4",
3
+ "version": "2.1.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",