1 | import lodash from 'lodash';
|
2 | import { connect } from 'react-redux';
|
3 | import { Debugger } from 'debug';
|
4 | import { ReactNode, Context, FC, FunctionComponent, ReactElement, ComponentClass } from 'react';
|
5 | import { Terminal as XTerminal, ITerminalOptions } from 'xterm';
|
6 | import * as hooks from '@umijs/hooks';
|
7 | import moment from 'moment';
|
8 | import * as intl from './locale';
|
9 | import { IRoute } from './';
|
10 |
|
11 | declare namespace IUI {
|
12 | export enum LOCALES {
|
13 | 'zh-CN' = '中文',
|
14 | 'en-US' = 'English',
|
15 | }
|
16 |
|
17 | export enum THEME {
|
18 | 'dark' = 'dark',
|
19 | 'light' = 'light',
|
20 | }
|
21 |
|
22 | export enum CONFIG_TYPES {
|
23 | 'string' = 'string',
|
24 | 'string[]' = 'string[]',
|
25 | 'boolean' = 'boolean',
|
26 | 'object' = 'object',
|
27 | 'object[]' = 'object[]',
|
28 | 'list' = 'list',
|
29 | 'textarea' = 'textarea',
|
30 | 'any' = 'any',
|
31 | }
|
32 |
|
33 | interface IBasicUI {
|
34 |
|
35 | name: string;
|
36 |
|
37 | logo: ReactNode;
|
38 |
|
39 | logo_remote: string;
|
40 |
|
41 | feedback: {
|
42 |
|
43 | src: string;
|
44 |
|
45 | width: number;
|
46 |
|
47 | height: number;
|
48 | };
|
49 |
|
50 | 'create.project.button': ReactNode;
|
51 |
|
52 | helpDoc: string;
|
53 |
|
54 | 'project.pages': {
|
55 |
|
56 | create: ReactNode;
|
57 | };
|
58 |
|
59 | dashboard: {
|
60 |
|
61 | siderFooter: ReactNode;
|
62 | };
|
63 | }
|
64 |
|
65 | type ILang = keyof typeof LOCALES;
|
66 | type ITheme = keyof typeof THEME;
|
67 |
|
68 | type Locale = { [key in string]: string };
|
69 |
|
70 | type ILocale = { [x in ILang]: Locale };
|
71 |
|
72 | interface IconType {
|
73 | type: string;
|
74 | theme?: 'filled' | 'outlined' | 'twoTone';
|
75 | rotate?: number;
|
76 | twoToneColor?: string;
|
77 | }
|
78 |
|
79 | interface IPanelConfigAction {
|
80 | title: string;
|
81 | type?: 'default' | 'primary';
|
82 | action?: IAction;
|
83 | onClick?: () => void;
|
84 | }
|
85 |
|
86 | type IPanelAction = (IPanelConfigAction | ReactNode | FC)[];
|
87 |
|
88 | interface IPanel extends IRoute {
|
89 | path: string;
|
90 | component: FunctionComponent | ComponentClass;
|
91 | icon: IconType | string;
|
92 | actions?: IPanelAction;
|
93 | beta?: boolean;
|
94 |
|
95 | headerTitle?: ReactNode;
|
96 |
|
97 | renderTitle?: (title: string) => ReactNode;
|
98 | }
|
99 |
|
100 | interface IService {
|
101 | panels: IPanel[];
|
102 | locales: ILocale[];
|
103 | configSections: any[];
|
104 | basicUI: Partial<IBasicUI>;
|
105 | dashboard: IDashboard[];
|
106 | }
|
107 |
|
108 | type SetFactory<T> = ((state: T) => T) | T;
|
109 |
|
110 | interface IAction<T = object, K = void> {
|
111 | type: string;
|
112 | payload?: T;
|
113 | onProgress?: (data: K) => void;
|
114 | onMessage?: (data: any) => void;
|
115 | keep?: boolean;
|
116 | }
|
117 |
|
118 | type IValue = string | object | boolean | string[] | object[];
|
119 |
|
120 | interface IFieldLabel {
|
121 |
|
122 | title: string;
|
123 |
|
124 | description: string;
|
125 |
|
126 | link: string;
|
127 | }
|
128 |
|
129 | export interface IFieldProps {
|
130 |
|
131 | type: IConfigTypes;
|
132 |
|
133 | name: string;
|
134 |
|
135 | defaultValue?: IValue;
|
136 |
|
137 | options?: string[];
|
138 |
|
139 | form: object;
|
140 |
|
141 | label: string | ReactNode | IFieldLabel;
|
142 |
|
143 | size?: 'default' | 'small' | 'large';
|
144 |
|
145 | [key: string]: any;
|
146 | }
|
147 |
|
148 | type IConfigTypes = keyof typeof CONFIG_TYPES;
|
149 | type ITerminal = XTerminal;
|
150 |
|
151 | interface ITwoColumnPanel {
|
152 | className?: string;
|
153 | sections: Array<{
|
154 | key?: string;
|
155 | title: string;
|
156 | icon: string | ReactNode;
|
157 | description: string;
|
158 | component: FunctionComponent<any>;
|
159 | }>;
|
160 | disableLeftOverflow?: boolean;
|
161 | disableRightOverflow?: boolean;
|
162 | }
|
163 |
|
164 | interface ITerminalProps {
|
165 |
|
166 | title?: ReactNode;
|
167 | className?: string;
|
168 | terminalClassName?: string;
|
169 |
|
170 | defaultValue?: string;
|
171 |
|
172 | onInit?: (ins: XTerminal, fitAddon: any) => void;
|
173 |
|
174 | config?: ITerminalOptions;
|
175 | onResize?: (ins: XTerminal) => void;
|
176 | [key: string]: any;
|
177 | }
|
178 |
|
179 | interface IDirectoryForm {
|
180 |
|
181 | value?: string;
|
182 | onChange?: (value: string) => void;
|
183 | }
|
184 |
|
185 | interface IStepItemForm {
|
186 | currentStep: number;
|
187 | handleFinish: () => void;
|
188 | goNext: () => void;
|
189 | goPrev: () => void;
|
190 | index: number;
|
191 | active: boolean;
|
192 | [key: string]: any;
|
193 | }
|
194 |
|
195 | interface IStepItemProps {
|
196 | children: ReactElement<Partial<IStepItemForm>>;
|
197 | [key: string]: any;
|
198 | }
|
199 |
|
200 | interface IStepFormProps {
|
201 | onFinish: (values: object) => void;
|
202 | className?: string;
|
203 | children: ReactElement<IStepItemForm>[];
|
204 | }
|
205 | type IStepForm = FC<IStepFormProps> & {
|
206 | StepItem: FC<IStepItemProps>;
|
207 | };
|
208 |
|
209 |
|
210 | export interface FuseOptions<T> {
|
211 | id?: keyof T;
|
212 | caseSensitive?: boolean;
|
213 | includeMatches?: boolean;
|
214 | includeScore?: boolean;
|
215 | shouldSort?: boolean;
|
216 | sortFn?: (a: { score: number }, b: { score: number }) => number;
|
217 | getFn?: (obj: any, path: string) => any;
|
218 | keys?: (keyof T)[] | T[keyof T] | { name: keyof T; weight: number }[];
|
219 | verbose?: boolean;
|
220 | tokenize?: boolean;
|
221 | tokenSeparator?: RegExp;
|
222 | matchAllTokens?: boolean;
|
223 | location?: number;
|
224 | distance?: number;
|
225 | threshold?: number;
|
226 | maxPatternLength?: number;
|
227 | minMatchCharLength?: number;
|
228 | findAllMatches?: boolean;
|
229 | }
|
230 |
|
231 | interface IConfigFormProps {
|
232 |
|
233 | title: string;
|
234 |
|
235 | list: string;
|
236 |
|
237 | edit: string;
|
238 |
|
239 | enableToc?: boolean;
|
240 |
|
241 | fuseOpts?: FuseOptions<number>;
|
242 | }
|
243 |
|
244 | type IApiActionFactory<P = {}, K = {}> = (action: IAction<P, K>) => Promise<K>;
|
245 |
|
246 | type ICallRemote<T = unknown, P = unknown> = IApiActionFactory<T, P>;
|
247 | type IListenRemote = IApiActionFactory<{}, () => void>;
|
248 | type ISend = IApiActionFactory<{}, void>;
|
249 | type IFormatMessage = typeof intl.formatMessage;
|
250 | type PickIntl = Pick<
|
251 | typeof intl,
|
252 | | 'FormattedDate'
|
253 | | 'FormattedTime'
|
254 | | 'FormattedRelative'
|
255 | | 'FormattedNumber'
|
256 | | 'FormattedPlural'
|
257 | | 'FormattedMessage'
|
258 | | 'FormattedHTMLMessage'
|
259 | | 'formatMessage'
|
260 | | 'formatHTMLMessage'
|
261 | | 'formatDate'
|
262 | | 'formatTime'
|
263 | | 'formatRelative'
|
264 | | 'formatNumber'
|
265 | | 'formatPlural'
|
266 | >;
|
267 | type IIntl<T = PickIntl> = { [key in keyof T]: T[key] } & typeof intl.formatMessage;
|
268 | type IGetCwd = () => Promise<string>;
|
269 |
|
270 | interface INotifyParams {
|
271 | title: string;
|
272 | message: string;
|
273 | subtitle?: string;
|
274 |
|
275 | open?: string;
|
276 | |
277 |
|
278 |
|
279 |
|
280 | timeout?: number;
|
281 |
|
282 | type?: 'error' | 'info' | 'warning' | 'success';
|
283 | }
|
284 | interface IDashboard {
|
285 |
|
286 | key: string;
|
287 | enable?: boolean;
|
288 |
|
289 | title: ReactNode;
|
290 |
|
291 | description: ReactNode;
|
292 |
|
293 | icon: ReactNode;
|
294 |
|
295 | right?: ReactNode;
|
296 |
|
297 | colClassName?: string;
|
298 |
|
299 | backgroundColor?: string;
|
300 | content: ReactNode | ReactNode[];
|
301 | }
|
302 |
|
303 | type INotify = (params: INotifyParams) => void | boolean;
|
304 | type IAddPanel = (panel: IPanel) => void;
|
305 | type IAddDashboard = (dashboard: IDashboard | IDashboard[]) => void;
|
306 | type IRegisterModel = (model: any) => void;
|
307 | type IAddLocales = (locale: ILocale) => void;
|
308 | type IShowLogPanel = () => void;
|
309 | type IHideLogPanel = () => void;
|
310 | type ILodash = typeof lodash;
|
311 | interface ICurrentProject {
|
312 | key?: string;
|
313 | name?: string;
|
314 | path?: string;
|
315 | created_at?: number;
|
316 | opened_at?: number;
|
317 | npmClient?: string;
|
318 | taobaoSpeedUp?: boolean;
|
319 | }
|
320 |
|
321 | type IRedirect = (url: string) => void;
|
322 | type IEvent = NodeJS.EventEmitter;
|
323 | type IDebug = Debugger;
|
324 | type IConnect = typeof connect;
|
325 | type IMini = () => boolean;
|
326 | type IShowMini = () => void;
|
327 | type IHideMini = () => void;
|
328 | type IGetLocale = () => ILang;
|
329 | type IGetDashboard = () => IDashboard[];
|
330 | type IGetBasicUI = () => IBasicUI;
|
331 | type IGetSharedDataDir = () => Promise<string>;
|
332 | type IGetSearchParams = () => any;
|
333 | type IDetectLanguage = () => Promise<string>;
|
334 | type ISetActionPanel = (action: SetFactory<IPanelAction>) => void;
|
335 | type IModifyBasicUI = (memo: Partial<IBasicUI>) => void;
|
336 | type LaunchEditorTypes = 'project' | 'config';
|
337 | type IMoment = typeof moment;
|
338 | interface IAnalyze {
|
339 | gtag: any;
|
340 | Tracert: any;
|
341 | }
|
342 |
|
343 | interface ILaunchEditorParams {
|
344 | type: LaunchEditorTypes;
|
345 | lineNumber?: number;
|
346 | editor?: string;
|
347 | }
|
348 |
|
349 | type ILaunchEditor = (params: ILaunchEditorParams) => void;
|
350 |
|
351 | interface IContext {
|
352 | theme: ITheme;
|
353 | locale: ILang;
|
354 | currentProject?: ICurrentProject;
|
355 | formatMessage: typeof intl.formatMessage;
|
356 | FormattedMessage: typeof intl.FormattedMessage;
|
357 | setLocale: typeof intl.setLocale;
|
358 | setTheme: (theme: ITheme) => void;
|
359 |
|
360 | showLogPanel: IShowLogPanel;
|
361 |
|
362 | hideLogPanel: IHideLogPanel;
|
363 | isMini: boolean;
|
364 | basicUI: IBasicUI;
|
365 | service: IService;
|
366 | }
|
367 |
|
368 | type UmiHooks = typeof hooks;
|
369 |
|
370 | interface Hooks extends UmiHooks {
|
371 |
|
372 | }
|
373 |
|
374 | class IApiClass {
|
375 | constructor(service: IService);
|
376 | service: IService;
|
377 | /** event */
|
378 | event: IEvent;
|
379 | /** React hooks for UI development */
|
380 | readonly hooks: Hooks;
|
381 | /** umi-request */
|
382 | readonly request: any;
|
383 | /** lodash */
|
384 | readonly _: ILodash;
|
385 | /** debug for client */
|
386 | readonly debug: IDebug;
|
387 | /** can use as vars */
|
388 | readonly mini: boolean;
|
389 | /** whether Bigfish */
|
390 | readonly bigfish: boolean;
|
391 | readonly _analyze: IAnalyze;
|
392 | /** currentProject */
|
393 | currentProject: ICurrentProject;
|
394 | /** get current locale: zh-CN or en-US */
|
395 | getLocale: IGetLocale;
|
396 | getCwd: IGetCwd;
|
397 | /** current is in Mini version */
|
398 | isMini(): boolean;
|
399 | /** intl, formatMessage */
|
400 | intl: IIntl;
|
401 | /** add plugin Panel */
|
402 | addPanel: IAddPanel;
|
403 | addDashboard: IAddDashboard;
|
404 | /** register dva model Panel */
|
405 | registerModel: IRegisterModel;
|
406 | /** add plugin locales { zh-CN: {}, en-US: {} } */
|
407 | addLocales: IAddLocales;
|
408 |
|
409 | getContext(): Context<IContext>;
|
410 |
|
411 | getBasicUI: IGetBasicUI;
|
412 |
|
413 | notify: INotify;
|
414 |
|
415 | moment: IMoment;
|
416 |
|
417 | redirect: IRedirect;
|
418 | callRemote: ICallRemote;
|
419 |
|
420 | TwoColumnPanel: FC<ITwoColumnPanel>;
|
421 |
|
422 | Terminal: FC<ITerminalProps>;
|
423 | DirectoryForm: FC<IDirectoryForm>;
|
424 | StepForm: IStepForm;
|
425 |
|
426 | ConfigForm: FC<IConfigFormProps>;
|
427 |
|
428 | Field: FC<IFieldProps>;
|
429 | listenRemote: IListenRemote;
|
430 | launchEditor: ILaunchEditor;
|
431 |
|
432 | showLogPanel: IShowLogPanel;
|
433 |
|
434 | hideLogPanel: IHideLogPanel;
|
435 | setActionPanel: ISetActionPanel;
|
436 |
|
437 | showMini: IShowMini;
|
438 |
|
439 | hideMini: IHideMini;
|
440 | send: ISend;
|
441 | connect: IConnect;
|
442 |
|
443 | getDashboard: IGetDashboard;
|
444 |
|
445 | getSharedDataDir: IGetSharedDataDir;
|
446 |
|
447 | getSearchParams: IGetSearchParams;
|
448 | detectLanguage: IDetectLanguage;
|
449 | detectNpmClients: () => Promise<string[]>;
|
450 | modifyBasicUI: IModifyBasicUI;
|
451 | }
|
452 |
|
453 | type IApi = InstanceType<typeof IApiClass>;
|
454 | }
|
455 |
|
456 | export = IUI;
|