1 | declare module "single-spa" {
|
2 | interface CustomProps {
|
3 | [str: string]: any;
|
4 | [num: number]: any;
|
5 | }
|
6 |
|
7 | type CustomPropsFn<ExtraProps extends CustomProps = CustomProps> = (
|
8 | name: string,
|
9 | location: Location
|
10 | ) => ExtraProps;
|
11 |
|
12 | export type AppProps = {
|
13 | name: string;
|
14 | singleSpa: any;
|
15 | mountParcel(
|
16 | parcelConfig: ParcelConfig,
|
17 | customProps: ParcelProps & CustomProps
|
18 | ): Parcel;
|
19 | };
|
20 |
|
21 | export type ParcelConfig<ExtraProps = CustomProps> =
|
22 | | ParcelConfigObject<ExtraProps>
|
23 | | (() => Promise<ParcelConfigObject<ExtraProps>>);
|
24 |
|
25 | type ParcelProps = { domElement: HTMLElement };
|
26 | type ParcelConfigObject<ExtraProps = CustomProps> = {
|
27 | name?: string;
|
28 | } & LifeCycles<ExtraProps>;
|
29 |
|
30 | type Parcel<ExtraProps = CustomProps> = {
|
31 | mount(): Promise<null>;
|
32 | unmount(): Promise<null>;
|
33 | update?(customProps: ExtraProps): Promise<any>;
|
34 | getStatus():
|
35 | | "NOT_LOADED"
|
36 | | "LOADING_SOURCE_CODE"
|
37 | | "NOT_BOOTSTRAPPED"
|
38 | | "BOOTSTRAPPING"
|
39 | | "NOT_MOUNTED"
|
40 | | "MOUNTING"
|
41 | | "MOUNTED"
|
42 | | "UPDATING"
|
43 | | "UNMOUNTING"
|
44 | | "UNLOADING"
|
45 | | "SKIP_BECAUSE_BROKEN"
|
46 | | "LOAD_ERROR";
|
47 | loadPromise: Promise<null>;
|
48 | bootstrapPromise: Promise<null>;
|
49 | mountPromise: Promise<null>;
|
50 | unmountPromise: Promise<null>;
|
51 | };
|
52 |
|
53 | type LifeCycleFn<ExtraProps> = (
|
54 | config: ExtraProps & AppProps
|
55 | ) => Promise<any>;
|
56 | export type LifeCycles<ExtraProps = {}> = {
|
57 | bootstrap: LifeCycleFn<ExtraProps> | Array<LifeCycleFn<ExtraProps>>;
|
58 | mount: LifeCycleFn<ExtraProps> | Array<LifeCycleFn<ExtraProps>>;
|
59 | unmount: LifeCycleFn<ExtraProps> | Array<LifeCycleFn<ExtraProps>>;
|
60 | update?: LifeCycleFn<ExtraProps> | Array<LifeCycleFn<ExtraProps>>;
|
61 | };
|
62 |
|
63 | export type StartOpts = {
|
64 | urlRerouteOnly?: boolean;
|
65 | };
|
66 |
|
67 |
|
68 | export function start(opts?: StartOpts): void;
|
69 |
|
70 |
|
71 | export function ensureJQuerySupport(jQuery?: any): void;
|
72 |
|
73 |
|
74 | export function setBootstrapMaxTime(
|
75 | time: number,
|
76 | dieOnTimeout?: boolean
|
77 | ): void;
|
78 | export function setMountMaxTime(time: number, dieOnTimeout?: boolean): void;
|
79 | export function setUnmountMaxTime(time: number, dieOnTimeout?: boolean): void;
|
80 | export function setUnloadMaxTime(time: number, dieOnTimeout?: boolean): void;
|
81 |
|
82 | type Application<ExtraProps = {}> =
|
83 | | LifeCycles<ExtraProps>
|
84 | | ((config: ExtraProps & AppProps) => Promise<LifeCycles<ExtraProps>>);
|
85 |
|
86 | type ActivityFn = (location: Location) => boolean;
|
87 |
|
88 | type Activity = ActivityFn | string | (ActivityFn | string)[];
|
89 |
|
90 | export type RegisterApplicationConfig<ExtraProps extends CustomProps = {}> = {
|
91 | name: string;
|
92 | app: Application<ExtraProps>;
|
93 | activeWhen: Activity;
|
94 | customProps?: ExtraProps | CustomPropsFn<ExtraProps>;
|
95 | };
|
96 |
|
97 | interface SingleSpaNewAppStatus {
|
98 | [key: string]:
|
99 | | "MOUNTED"
|
100 | | "NOT_MOUNTED"
|
101 | | "NOT_LOADED"
|
102 | | "SKIP_BECAUSE_BROKEN";
|
103 | }
|
104 | interface SingleSpaAppsByNewStatus {
|
105 | [MOUNTED]: [];
|
106 | [NOT_MOUNTED]: [];
|
107 | [NOT_LOADED]: [];
|
108 | [SKIP_BECAUSE_BROKEN]: [];
|
109 | }
|
110 | export type SingleSpaCustomEventDetail = {
|
111 | newAppStatuses: SingleSpaNewAppStatus;
|
112 | appsByNewStatus: SingleSpaAppsByNewStatus;
|
113 | totalAppChanges: number;
|
114 | originalEvent?: Event;
|
115 | oldUrl: string;
|
116 | newUrl: string;
|
117 | navigationIsCanceled: boolean;
|
118 | cancelNavigation?: () => void;
|
119 | };
|
120 |
|
121 |
|
122 | export function registerApplication<ExtraProps extends CustomProps = {}>(
|
123 | appName: string,
|
124 | applicationOrLoadingFn: Application<ExtraProps>,
|
125 | activityFn: ActivityFn,
|
126 | customProps?: ExtraProps | CustomPropsFn<ExtraProps>
|
127 | ): void;
|
128 |
|
129 | export function registerApplication<ExtraProps extends CustomProps = {}>(
|
130 | config: RegisterApplicationConfig<ExtraProps>
|
131 | ): void;
|
132 |
|
133 | export function unregisterApplication(appName: string): Promise<any>;
|
134 |
|
135 | export function getMountedApps(): string[];
|
136 |
|
137 | export const {
|
138 | NOT_LOADED = "NOT_LOADED",
|
139 | LOADING_SOURCE_CODE = "LOADING_SOURCE_CODE",
|
140 | NOT_BOOTSTRAPPED = "NOT_BOOTSTRAPPED",
|
141 | BOOTSTRAPPING = "BOOTSTRAPPING",
|
142 | NOT_MOUNTED = "NOT_MOUNTED",
|
143 | MOUNTING = "MOUNTING",
|
144 | MOUNTED = "MOUNTED",
|
145 | UPDATING = "UPDATING",
|
146 | UNMOUNTING = "UNMOUNTING",
|
147 | UNLOADING = "UNLOADING",
|
148 | SKIP_BECAUSE_BROKEN = "SKIP_BECAUSE_BROKEN",
|
149 | LOAD_ERROR = "LOAD_ERROR",
|
150 | };
|
151 |
|
152 | export function getAppStatus(appName: string): string | null;
|
153 |
|
154 | export function unloadApplication(
|
155 | appName: string,
|
156 | opts?: { waitForUnmount: boolean }
|
157 | ): Promise<any>;
|
158 |
|
159 | export function checkActivityFunctions(location: Location): string[];
|
160 | export function getAppNames(): string[];
|
161 |
|
162 |
|
163 | export function navigateToUrl(
|
164 | obj:
|
165 | | string
|
166 | | {
|
167 | currentTarget: {
|
168 | href: string;
|
169 | };
|
170 | preventDefault: any;
|
171 | },
|
172 | opts?: Object
|
173 | ): void;
|
174 |
|
175 |
|
176 | export function triggerAppChange(): Promise<any>;
|
177 |
|
178 |
|
179 | type AppError = Error & {
|
180 | appOrParcelName: string;
|
181 | };
|
182 | export function addErrorHandler(handler: (error: AppError) => void): void;
|
183 | export function removeErrorHandler(handler: (error: AppError) => void): void;
|
184 |
|
185 |
|
186 | export function mountRootParcel<ExtraProps = CustomProps>(
|
187 | parcelConfig: ParcelConfig<ExtraProps>,
|
188 | parcelProps: ParcelProps & ExtraProps
|
189 | ): Parcel<ExtraProps>;
|
190 |
|
191 | export function pathToActiveWhen(
|
192 | path: string,
|
193 | exactMatch?: boolean
|
194 | ): ActivityFn;
|
195 | }
|