@pushwoosh/smart-components-kit 1.0.49 → 1.0.51

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,7 @@ import { PlatformLogoIcon } from '@pushwoosh/kit-icons';
7
7
  import { Text } from '@pushwoosh/kit-typography';
8
8
  import { LinkRow, ClickActionSection } from './styles';
9
9
  import { useSPAContext } from '../../../context';
10
- import { getSafariUrl } from '../../helpers';
10
+ import { getSafariUrl, isWebLink } from '../../helpers';
11
11
  export const OpenActionsSummary = ({
12
12
  openActions
13
13
  }) => {
@@ -68,7 +68,7 @@ export const OpenActionsSummary = ({
68
68
  };
69
69
  return React.createElement(Vertical, {
70
70
  "$gap": 8
71
- }, openActions ? React.createElement(React.Fragment, null, showRichmedia && renderInfoBlock('mobile', 'open in-app banner', getRichmediaLink(showRichmedia), showRichmedia.name || showRichmedia.code), !showRichmedia && hasCustomPlatformsDeeplink && renderInfoBlock('mobile', 'follow the Deep link'), !showRichmedia && Object.entries(platformsDeeplinkUrls).map(([platformKey, url]) => renderPlatformDeepLink(+platformKey, url)), !showRichmedia && allPlatformsDeeplinkUrl && hasCustomPlatformsDeeplink && renderPlatformDeepLink('Other platforms', allPlatformsDeeplinkUrl), !showRichmedia && allPlatformsDeeplinkUrl && !hasCustomPlatformsDeeplink && renderInfoBlock('mobile', 'follow the Deep link', allPlatformsDeeplinkUrl), !showRichmedia && !allPlatformsDeeplinkUrl && !hasCustomPlatformsDeeplink && renderInfoBlock('mobile', 'open home page in application'), webPageUrl && renderInfoBlock('web', 'open URL in browser', webPageUrl), webPageUrl && safariUrl && renderInfoBlock('Safari', 'open URL in Safari browser', safariUrl), !webPageUrl && renderInfoBlock('web', 'open home page in browser')) : React.createElement(Spinner, {
71
+ }, openActions ? React.createElement(React.Fragment, null, showRichmedia && renderInfoBlock('mobile', 'open in-app banner', getRichmediaLink(showRichmedia), showRichmedia.name || showRichmedia.code), !showRichmedia && hasCustomPlatformsDeeplink && renderInfoBlock('mobile', 'follow the Deep link'), !showRichmedia && Object.entries(platformsDeeplinkUrls).map(([platformKey, url]) => renderPlatformDeepLink(+platformKey, url)), !showRichmedia && allPlatformsDeeplinkUrl && hasCustomPlatformsDeeplink && renderPlatformDeepLink('Other platforms', allPlatformsDeeplinkUrl, isWebLink(allPlatformsDeeplinkUrl) ? 'open URL in browser' : 'deep link'), !showRichmedia && allPlatformsDeeplinkUrl && !hasCustomPlatformsDeeplink && renderInfoBlock('mobile', isWebLink(allPlatformsDeeplinkUrl) ? 'open URL in browser' : 'follow the Deep link', allPlatformsDeeplinkUrl), !showRichmedia && !allPlatformsDeeplinkUrl && !hasCustomPlatformsDeeplink && renderInfoBlock('mobile', 'open home page in application'), webPageUrl && renderInfoBlock('web', 'open URL in browser', webPageUrl), webPageUrl && safariUrl && renderInfoBlock('Safari', 'open URL in Safari browser', safariUrl), !webPageUrl && renderInfoBlock('web', 'open home page in browser')) : React.createElement(Spinner, {
72
72
  color: Color.MAIN,
73
73
  size: "medium"
74
74
  }));
@@ -33,7 +33,7 @@ export const usePresetOpenActions = pushPreset => {
33
33
  platformsDeeplinkUrls,
34
34
  showRichmedia
35
35
  } = await getPlatformDeeplinksByOpenActions(pushPreset, getDeeplinkUrl);
36
- let defaultDeeplinkUrl = null;
36
+ let defaultDeeplinkUrl = pushPreset.url ?? null;
37
37
  // openAction - for common all mobile deeplink; web url is located in 'url' prop, openActions - map with mobile deeplink platform as a key (0 we should ignore)
38
38
  if (((_pushPreset$openActio = pushPreset.openAction) === null || _pushPreset$openActio === void 0 || (_pushPreset$openActio = _pushPreset$openActio.kind) === null || _pushPreset$openActio === void 0 ? void 0 : _pushPreset$openActio.type) === 'deepLink') {
39
39
  const deeplinkCommonInfo = pushPreset.openAction.kind.data;
@@ -101,7 +101,7 @@ const getPlatformDeeplinksByOpenActions = async (pushPreset, getDeeplinkUrl) =>
101
101
  const getOpenActionsFromV1Preset = async pushPreset => {
102
102
  var _pushPreset$localized2, _pushPreset$localized3;
103
103
  const webPageUrl = !pushPreset.deeplink && isWebLink(pushPreset.url) ? pushPreset.url : null;
104
- const defaultDeeplinkUrl = pushPreset.deeplink && pushPreset.url ? pushPreset.url : null;
104
+ const defaultDeeplinkUrl = pushPreset.url ?? null;
105
105
  const showRichmedia = pushPreset.richmedia ? {
106
106
  code: pushPreset.richmedia
107
107
  } : null;
@@ -1,9 +1,11 @@
1
1
  type Listener<T> = (payload: T) => void;
2
2
  export declare class SimpleEventEmitter {
3
3
  private listeners;
4
- on<T>(eventName: string, fn: Listener<T>): () => void;
4
+ private lastPayloads;
5
+ on<T>(eventName: string, fn: Listener<T>, callImmediately?: boolean): () => void;
5
6
  off<T>(eventName: string, fn: Listener<T>): void;
6
7
  emit<T>(eventName: string, payload: T): void;
8
+ getLastPayload<T>(eventName: string): T | undefined;
7
9
  clear(eventName?: string): void;
8
10
  }
9
11
  export {};
@@ -1,10 +1,15 @@
1
1
  export class SimpleEventEmitter {
2
2
  listeners = {};
3
- on(eventName, fn) {
3
+ lastPayloads = {};
4
+ on(eventName, fn, callImmediately) {
4
5
  if (!this.listeners[eventName]) {
5
6
  this.listeners[eventName] = [];
6
7
  }
7
8
  this.listeners[eventName].push(fn);
9
+ // Call immediately with last payload if requested and available
10
+ if (callImmediately && eventName in this.lastPayloads) {
11
+ fn(this.lastPayloads[eventName]);
12
+ }
8
13
  return () => {
9
14
  this.off(eventName, fn);
10
15
  };
@@ -17,15 +22,22 @@ export class SimpleEventEmitter {
17
22
  }
18
23
  }
19
24
  emit(eventName, payload) {
25
+ // Store last payload
26
+ this.lastPayloads[eventName] = payload;
20
27
  if (!this.listeners[eventName]) return;
21
28
  // Copy to avoid reentrancy issues if a listener removes itself
22
29
  [...this.listeners[eventName]].forEach(l => l(payload));
23
30
  }
31
+ getLastPayload(eventName) {
32
+ return this.lastPayloads[eventName];
33
+ }
24
34
  clear(eventName) {
25
35
  if (eventName) {
26
36
  delete this.listeners[eventName];
37
+ delete this.lastPayloads[eventName];
27
38
  } else {
28
39
  this.listeners = {};
40
+ this.lastPayloads = {};
29
41
  }
30
42
  }
31
43
  }
@@ -1 +1 @@
1
- export declare function useEventBusListener<T>(eventName: string, handler: (payload: T) => void): void;
1
+ export declare function useEventBusListener<T>(eventName: string, handler: (payload: T) => void, callImmediately?: boolean): void;
@@ -1,12 +1,12 @@
1
1
  import { useEffect } from 'react';
2
2
  import { usePersistentFunction } from '@pushwoosh/kit-helpers';
3
3
  import { useSPAContext } from '../context';
4
- export function useEventBusListener(eventName, handler) {
4
+ export function useEventBusListener(eventName, handler, callImmediately) {
5
5
  const {
6
6
  eventBus
7
7
  } = useSPAContext();
8
8
  const persistentHandler = usePersistentFunction(handler);
9
9
  useEffect(() => {
10
- return eventBus.on(eventName, persistentHandler);
11
- }, [eventBus, eventName, persistentHandler]);
10
+ return eventBus.on(eventName, persistentHandler, callImmediately);
11
+ }, [eventBus, eventName, persistentHandler, callImmediately]);
12
12
  }
package/package.json CHANGED
@@ -50,5 +50,5 @@
50
50
  "engines": {
51
51
  "node": ">= 18"
52
52
  },
53
- "version": "1.0.49"
53
+ "version": "1.0.51"
54
54
  }