@placetopay/lightbox-sdk 2.2.0 → 2.4.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.
@@ -7,7 +7,8 @@ export declare enum ElementIds {
7
7
  export declare enum LightboxEvents {
8
8
  CLOSE = "close",
9
9
  UPDATE_STYLES = "updateStyles",
10
- HIDE_CLOSE_BUTTON = "hideCloseButton"
10
+ HIDE_CLOSE_BUTTON = "hideCloseButton",
11
+ CLOSE_BY_USER = "closeByUser"
11
12
  }
12
13
  export declare enum Styles {
13
14
  BACKDROP_COLOR = "--placetopay-lightbox-backdrop-color",
package/dist/constants.js CHANGED
@@ -10,6 +10,7 @@ export var LightboxEvents;
10
10
  LightboxEvents["CLOSE"] = "close";
11
11
  LightboxEvents["UPDATE_STYLES"] = "updateStyles";
12
12
  LightboxEvents["HIDE_CLOSE_BUTTON"] = "hideCloseButton";
13
+ LightboxEvents["CLOSE_BY_USER"] = "closeByUser";
13
14
  })(LightboxEvents || (LightboxEvents = {}));
14
15
  export var Styles;
15
16
  (function (Styles) {
@@ -1,5 +1,6 @@
1
1
  import { Styles, ElementIds, LightboxEvents as LE } from '../constants';
2
2
  import { setStyle, unsetStyle, openWithBackup, closePopupByLightboxId, hasOpenedPopup } from '../helpers';
3
+ import { isSafariOrIOS } from './index';
3
4
  let listener;
4
5
  export const mountLightbox = ({ id, url, element, callbacks, styles, closeButtonEnabled, enforceStyles, allowRedirects, backupTarget, }) => {
5
6
  // Only respect allowRedirects for 'self' redirection
@@ -7,10 +8,7 @@ export const mountLightbox = ({ id, url, element, callbacks, styles, closeButton
7
8
  // If allowRedirects is false and backupTarget is 'self', don't redirect
8
9
  return;
9
10
  }
10
- // Check if we need to use fallback behavior for Safari/iOS
11
- const isSafariOrIOS = navigator.userAgent.match(/iPhone|iPad|iPod/i) ||
12
- /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
13
- if (isSafariOrIOS) {
11
+ if (isSafariOrIOS()) {
14
12
  if (window.self !== window.top) {
15
13
  window.parent.postMessage({ type: "placetopay-lightbox:redirect", url }, "*"); // dont change this, it would be a broken change
16
14
  }
@@ -1,5 +1,8 @@
1
1
  import { InitialOptions, LightboxInstance, ApiStructure, LightboxStyles } from '../types';
2
2
  export declare const isInside: () => boolean;
3
+ export declare const isInsideIframe: () => boolean;
4
+ export declare const isInsidePopup: () => boolean;
5
+ export declare const isSafariOrIOS: () => boolean;
3
6
  export declare const updateStyles: (styles: LightboxStyles) => any;
4
7
  export declare const hideCloseButton: () => any;
5
8
  export declare const emitClose: (payload?: unknown, preventClose?: boolean) => void;
@@ -2,6 +2,10 @@ import { LightboxEvents as LE } from '../constants';
2
2
  import { postMessage } from '../helpers';
3
3
  import { mountLightbox, unmountLightbox } from './assemblers';
4
4
  export const isInside = () => globalThis.location !== globalThis.parent.location;
5
+ export const isInsideIframe = () => globalThis.self !== globalThis.top;
6
+ export const isInsidePopup = () => !!globalThis.opener;
7
+ export const isSafariOrIOS = () => /iPhone|iPad|iPod/i.test(navigator.userAgent) ||
8
+ /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
5
9
  export const updateStyles = (styles) => postMessage(LE.UPDATE_STYLES, styles);
6
10
  export const hideCloseButton = () => postMessage(LE.HIDE_CLOSE_BUTTON);
7
11
  export const emitClose = (payload, preventClose) => {
package/dist/helpers.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { LightboxEvents as LE } from './constants';
1
2
  export const postMessage = (type, payload, preventClose) => {
2
3
  const target = globalThis.opener || globalThis.parent;
3
4
  return target.postMessage({ type, preventClose, payload }, '*');
@@ -11,6 +12,9 @@ export const unsetStyle = (name) => {
11
12
  let openedWindow = null;
12
13
  let backdropElement = null;
13
14
  const openedWindows = {};
15
+ const generatePopupName = (lightboxId) => {
16
+ return lightboxId !== null && lightboxId !== void 0 ? lightboxId : `placetopay_${crypto.randomUUID()}`;
17
+ };
14
18
  // Private translations
15
19
  const translations = {
16
20
  en: {
@@ -107,6 +111,7 @@ export const unmountBackdrop = () => {
107
111
  document.body.style.overflow = '';
108
112
  document.body.classList.remove('placetopay-lightbox-open');
109
113
  openedWindow = null;
114
+ postMessage(LE.CLOSE_BY_USER);
110
115
  };
111
116
  export const openWithBackup = (url, backupTarget = 'self', lightboxId) => {
112
117
  switch (backupTarget) {
@@ -119,7 +124,7 @@ export const openWithBackup = (url, backupTarget = 'self', lightboxId) => {
119
124
  // Calculate center position
120
125
  const left = (window.screen.width - popupWidth) / 2;
121
126
  const top = (window.screen.height - popupHeight) / 2;
122
- openedWindow = window.open(url, 'placetopay', `popup=true,width=${popupWidth},height=${popupHeight},left=${left},top=${top}`);
127
+ openedWindow = window.open(url, generatePopupName(lightboxId), `popup=true,width=${popupWidth},height=${popupHeight},left=${left},top=${top}`);
123
128
  break;
124
129
  }
125
130
  case 'self':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@placetopay/lightbox-sdk",
3
- "version": "2.2.0",
3
+ "version": "2.4.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",