@pushwoosh/smart-components-kit 1.0.48 → 1.0.49
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/DynamicContentPicker/DynamicContentPicker.d.ts +1 -1
- package/DynamicContentPicker/DynamicContentPicker.js +2 -2
- package/context/SimpleEventEmitter.d.ts +9 -0
- package/context/SimpleEventEmitter.js +31 -0
- package/context/index.d.ts +2 -1
- package/context/index.js +2 -1
- package/context/types.d.ts +6 -4
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useEventBusListener.d.ts +1 -0
- package/hooks/useEventBusListener.js +12 -0
- package/package.json +2 -2
|
@@ -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) {
|
|
@@ -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
|
+
}
|
package/context/index.d.ts
CHANGED
|
@@ -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;
|
package/context/types.d.ts
CHANGED
|
@@ -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
package/hooks/index.js
CHANGED
|
@@ -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
|
|
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.
|
|
53
|
+
"version": "1.0.49"
|
|
54
54
|
}
|