@pushwoosh/smart-components-kit 1.0.48 → 1.0.50

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,6 +1,6 @@
1
1
  import { type FC, type ReactNode } from 'react';
2
- import { type VariedDynamicContent } from '../DynamicContentPickerForm/types';
3
2
  import { type RenderDynamicContentProps } from './types';
3
+ import { type VariedDynamicContent } from '../DynamicContentPickerForm/types';
4
4
  type State = Record<string, VariedDynamicContent>;
5
5
  type DynamicContentPickerProps = {
6
6
  applicationCode: string;
@@ -4,11 +4,11 @@ import { Color } from '@pushwoosh/kit-constants';
4
4
  import { elementAddListener, Horizontal, usePersistentFunction } from '@pushwoosh/kit-helpers';
5
5
  import { WarningRoundIcon } from '@pushwoosh/kit-icons';
6
6
  import { Text } from '@pushwoosh/kit-typography';
7
- import { Arrow, FieldPlace, TextPlace } from './styled';
8
- import { VariedDynamicContentPickerFormSmart } from '../DynamicContentPickerForm/VariedDynamicContentPickerFormSmart';
9
7
  import ArrowIcon from './assets/arrow.svg';
10
8
  import { placementToDirection } from './helpers';
11
9
  import { Line } from './Line';
10
+ import { Arrow, FieldPlace, TextPlace } from './styled';
11
+ import { VariedDynamicContentPickerFormSmart } from '../DynamicContentPickerForm/VariedDynamicContentPickerFormSmart';
12
12
  const initialState = {};
13
13
  const reducer = (state, action) => {
14
14
  switch (action.type) {
@@ -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;
@@ -0,0 +1,9 @@
1
+ type Listener<T> = (payload: T) => void;
2
+ export declare class SimpleEventEmitter {
3
+ private listeners;
4
+ on<T>(eventName: string, fn: Listener<T>): () => void;
5
+ off<T>(eventName: string, fn: Listener<T>): void;
6
+ emit<T>(eventName: string, payload: T): void;
7
+ clear(eventName?: string): void;
8
+ }
9
+ export {};
@@ -0,0 +1,31 @@
1
+ export class SimpleEventEmitter {
2
+ listeners = {};
3
+ on(eventName, fn) {
4
+ if (!this.listeners[eventName]) {
5
+ this.listeners[eventName] = [];
6
+ }
7
+ this.listeners[eventName].push(fn);
8
+ return () => {
9
+ this.off(eventName, fn);
10
+ };
11
+ }
12
+ off(eventName, fn) {
13
+ if (!this.listeners[eventName]) return;
14
+ this.listeners[eventName] = this.listeners[eventName].filter(l => l !== fn);
15
+ if (this.listeners[eventName].length === 0) {
16
+ delete this.listeners[eventName];
17
+ }
18
+ }
19
+ emit(eventName, payload) {
20
+ if (!this.listeners[eventName]) return;
21
+ // Copy to avoid reentrancy issues if a listener removes itself
22
+ [...this.listeners[eventName]].forEach(l => l(payload));
23
+ }
24
+ clear(eventName) {
25
+ if (eventName) {
26
+ delete this.listeners[eventName];
27
+ } else {
28
+ this.listeners = {};
29
+ }
30
+ }
31
+ }
@@ -1,5 +1,6 @@
1
+ import { SimpleEventEmitter } from './SimpleEventEmitter';
1
2
  import type { SPAContextType } from './types';
2
3
  import { useSPAContext } from './useSPAContext';
3
4
  export type { SPAContextType };
4
- export { useSPAContext };
5
+ export { useSPAContext, SimpleEventEmitter };
5
6
  export declare const SPAContextProvider: import("react").Provider<SPAContextType | undefined>;
package/context/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { SPAContext } from './context';
2
+ import { SimpleEventEmitter } from './SimpleEventEmitter';
2
3
  import { useSPAContext } from './useSPAContext';
3
- export { useSPAContext };
4
+ export { useSPAContext, SimpleEventEmitter };
4
5
  export const SPAContextProvider = SPAContext.Provider;
@@ -4,14 +4,15 @@ import type { API as RpcGatewayJourneyAPI } from '@pushwoosh/rpc-gateway-journey
4
4
  import type { API as RpcGatewayPaymentAPI } from '@pushwoosh/rpc-gateway-payment-data';
5
5
  import type { API as RpcGatewayAPI } from '@pushwoosh/rpc-v2-http-api-data';
6
6
  import type { SessionStore } from '@pushwoosh/session-store';
7
+ import type { SimpleEventEmitter } from './SimpleEventEmitter';
7
8
  export type SPAContextType = {
8
9
  readonly history: History;
9
10
  readonly httpClient: HttpClient;
10
11
  readonly rpcClient: RpcClient;
11
12
  readonly grpcClient: GrpcClient;
12
13
  readonly grpcBridge: {
13
- clients: {
14
- billingGrpcClient: GrpcClient;
14
+ readonly clients: {
15
+ readonly billingGrpcClient: GrpcClient;
15
16
  };
16
17
  };
17
18
  readonly sessionStore: SessionStore;
@@ -20,8 +21,9 @@ export type SPAContextType = {
20
21
  readonly rpcGatewayPayment: RpcGatewayPaymentAPI;
21
22
  readonly language: string;
22
23
  readonly helpers: {
23
- getApiOrigin: (name: string) => string;
24
- getJsonApiUrl: (method: string) => string;
24
+ readonly getApiOrigin: (name: string) => string;
25
+ readonly getJsonApiUrl: (method: string) => string;
25
26
  };
27
+ readonly eventBus: SimpleEventEmitter;
26
28
  readonly __smartComponentsCache: Record<string, any>;
27
29
  };
package/hooks/index.d.ts CHANGED
@@ -1 +1,2 @@
1
+ export { useEventBusListener } from './useEventBusListener';
1
2
  export { useSession } from './useSession';
package/hooks/index.js CHANGED
@@ -1 +1,2 @@
1
+ export { useEventBusListener } from './useEventBusListener';
1
2
  export { useSession } from './useSession';
@@ -0,0 +1 @@
1
+ export declare function useEventBusListener<T>(eventName: string, handler: (payload: T) => void): void;
@@ -0,0 +1,12 @@
1
+ import { useEffect } from 'react';
2
+ import { usePersistentFunction } from '@pushwoosh/kit-helpers';
3
+ import { useSPAContext } from '../context';
4
+ export function useEventBusListener(eventName, handler) {
5
+ const {
6
+ eventBus
7
+ } = useSPAContext();
8
+ const persistentHandler = usePersistentFunction(handler);
9
+ useEffect(() => {
10
+ return eventBus.on(eventName, persistentHandler);
11
+ }, [eventBus, eventName, persistentHandler]);
12
+ }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "playground": "`pushwoosh-engine lib:command:playground`",
12
12
  "check": "npm run check:lint && npm run check:types",
13
13
  "check:lint": "echo \"Run check:lint\" && NODE_ENV=production eslint src",
14
- "check:lint-fix": "echo \"Run check:lint\" && NODE_ENV=production eslint . --fix",
14
+ "check:lint-fix": "echo \"Run check:lint\" && NODE_ENV=production eslint src --fix",
15
15
  "check:types": "echo \"Run check:types\" && pushwoosh-engine lib:check-types"
16
16
  },
17
17
  "pre-commit": "check",
@@ -50,5 +50,5 @@
50
50
  "engines": {
51
51
  "node": ">= 18"
52
52
  },
53
- "version": "1.0.48"
53
+ "version": "1.0.50"
54
54
  }