1 | import React from 'react';
|
2 | import { Middleware as ReduxMiddleware, Store as ReduxStore } from 'redux';
|
3 | import { buildMiddleware } from './Middleware';
|
4 | import { ReducerMap, Store } from './store/async';
|
5 | import { TrackingEventPayload, Application, ApiClientConfig } from './types';
|
6 | import { Props as HostProps } from './Host';
|
7 | /**
|
8 | * The current pathname, search params and hash
|
9 | * @internal
|
10 | * */
|
11 | export interface Location {
|
12 | pathname: string;
|
13 | search?: string;
|
14 | hash?: string;
|
15 | }
|
16 | /**
|
17 | * The method to call when attempting to update the router history
|
18 | * When the return value is a string or `true`, the router update will be blocked
|
19 | * @internal
|
20 | * */
|
21 | export interface Prompt {
|
22 | (nextLocation?: Location): string | false | void;
|
23 | }
|
24 | /**
|
25 | * The interface for the Navigation Context
|
26 | * @public
|
27 | * */
|
28 | export interface RouterContext {
|
29 | /** The `handle` or `apiKey` for the current app */
|
30 | appRoot: string;
|
31 | hostname: string;
|
32 | /** The router to be to handle router actions */
|
33 | history: {
|
34 | replace(path: string): void;
|
35 | replace(nextLocation: Location): void;
|
36 | push(path: string): void;
|
37 | push(nextLocation: Location): void;
|
38 | block?(prompt?: boolean | string | Prompt): () => void;
|
39 | };
|
40 | location: Location;
|
41 | }
|
42 | /**
|
43 | * The interface for the HostProvider
|
44 | * @public
|
45 | * */
|
46 | export interface Props extends HostProps {
|
47 | /** Configuration of the app to load*/
|
48 | config?: ApiClientConfig;
|
49 | /** Optional handler for when App Bridge actions are dispatched */
|
50 | dispatchClientEventHandler?: (trackingEventPayload: TrackingEventPayload) => void;
|
51 | /** Required to set the initial app state
|
52 | * @remarks feature permissions must be specified using the key `features` which will take effect immediately
|
53 | * other state properties (ex. `loading`, `toast`, etc..) will only be set after the relevant reducer has loaded
|
54 | */
|
55 | initialState: Partial<Store> & Pick<Store, 'features'>;
|
56 | /** The middleware to use when creating the Redux store */
|
57 | middleware?: Array<ReturnType<typeof buildMiddleware> | ReduxMiddleware>;
|
58 | router?: RouterContext;
|
59 | /** Enables the Redux dev tools if set to `true` */
|
60 | debug?: boolean;
|
61 | }
|
62 | /**
|
63 | * The interface for the Host Context that can be
|
64 | * consumed by the Host Provider's child components
|
65 | * @public
|
66 | * */
|
67 | export interface HostContext {
|
68 | app: Application;
|
69 | config: ApiClientConfig;
|
70 | addReducer<State>(reducerMap: ReducerMap<State>): void;
|
71 | store: ReduxStore;
|
72 | }
|
73 | /**
|
74 | * The context provider for the app, config and addReducer method
|
75 | * @public
|
76 | * */
|
77 | export declare const HostContext: React.Context<HostContext | null>;
|
78 | /**
|
79 | * The context provider for the router.
|
80 | * Keeps track of the current location and
|
81 | * handles history push/replace
|
82 | * @public
|
83 | * */
|
84 | export declare const RouterContext: React.Context<RouterContext | null>;
|
85 | /**
|
86 | * A component that creates a dynamic Redux store
|
87 | * and renders the Host
|
88 | * @public
|
89 | * */
|
90 | export default function HostProvider(props: Props): JSX.Element;
|