@wonderkits/app
Version:
WonderKits micro-frontend application framework with Wujie integration support
229 lines (224 loc) • 6.05 kB
TypeScript
import * as React$1 from 'react';
import { RouteObject } from 'react-router-dom';
interface AppLifecycleHooks {
onInstall?: () => Promise<void> | void;
onActivate?: () => Promise<void> | void;
onDeactivate?: () => Promise<void> | void;
onUninstall?: () => Promise<void> | void;
onUpdate?: (oldVersion: string, newVersion: string) => Promise<void> | void;
}
interface AppNavItem {
name: string;
href: string;
matchPath?: string;
icon: React$1.ElementType;
iconPath?: React$1.ElementType;
order?: number;
visible?: boolean;
current?: boolean;
}
interface AppPermission {
id: string;
name: string;
description: string;
required?: boolean;
}
interface AppRouteConfig extends Omit<RouteObject, 'children'> {
meta?: {
title?: string;
requireAuth?: boolean;
permissions?: string[];
layout?: 'default' | 'fullscreen' | 'minimal';
isMicroApp?: boolean;
appId?: string;
};
children?: AppRouteConfig[];
}
interface AppDependency {
id: string;
version: string;
optional?: boolean;
}
interface AppManifest {
id: string;
name: string;
displayName: string;
version: string;
description: string;
author: string;
homepage?: string;
keywords?: string[];
category?: string;
icon?: string;
screenshots?: string[];
dependencies?: AppDependency[];
permissions?: AppPermission[];
minSystemVersion?: string;
}
type AppMode = 'wujie' | 'module' | 'auto';
interface AppConfig {
manifest: AppManifest;
navigation?: AppNavItem;
routes?: AppRouteConfig[];
hooks?: AppLifecycleHooks;
entry?: () => Promise<React$1.ComponentType>;
wujie?: WujieConfig;
mode?: AppMode;
}
interface WujieConfig {
name?: string;
url: string;
props?: Record<string, any>;
attrs?: Record<string, any>;
replace?: boolean;
sync?: boolean;
prefix?: {
'prefix-url'?: string;
'prefix-class'?: string;
};
alive?: boolean;
sandbox?: boolean;
fetch?: (url: string, options?: any) => Promise<Response>;
plugins?: Array<{
htmlLoader?: Function;
jsLoader?: Function;
cssLoader?: Function;
}>;
beforeLoad?: (appWindow: Window) => void;
beforeMount?: (appWindow: Window) => void;
afterMount?: (appWindow: Window) => void;
beforeUnmount?: (appWindow: Window) => void;
afterUnmount?: (appWindow: Window) => void;
activated?: () => void;
deactivated?: () => void;
}
/**
* 微前端相关类型定义
*/
interface MicroAppRouteInfo {
appId: string;
currentPath: string;
subAppPath: string;
basePath: string;
query?: Record<string, string>;
hash?: string;
}
interface SubAppEvents {
'sub-route-change': {
appId: string;
path: string;
timestamp: number;
};
'sub-app-ready': {
appId: string;
version: string;
};
'sub-app-error': {
appId: string;
error: string;
timestamp: number;
};
'sub-app-message': {
appId: string;
type: string;
data: any;
};
}
interface ParentAppEvents {
'parent-route-change': {
path: string;
timestamp: number;
};
'parent-app-message': {
type: string;
data: any;
};
'app-config-update': {
appId: string;
config: Partial<AppConfig>;
};
}
interface WujieExtendedConfig {
routeSync?: {
enabled: boolean;
syncMode: 'auto' | 'manual';
pathPrefix?: string;
};
lifecycle?: {
beforeMount?: (appId: string) => Promise<void> | void;
afterMount?: (appId: string) => Promise<void> | void;
beforeUnmount?: (appId: string) => Promise<void> | void;
afterUnmount?: (appId: string) => Promise<void> | void;
};
errorHandling?: {
onError?: (error: Error, appId: string) => void;
fallbackComponent?: React.ComponentType<{
error: Error;
appId: string;
}>;
};
performance?: {
enableMonitoring: boolean;
onMetrics?: (metrics: MicroAppMetrics) => void;
};
}
interface MicroAppMetrics {
appId: string;
loadTime: number;
mountTime: number;
firstContentfulPaint?: number;
firstMeaningfulPaint?: number;
memoryUsage?: {
used: number;
total: number;
};
}
interface MicroAppState {
appId: string;
status: 'loading' | 'loaded' | 'mounting' | 'mounted' | 'unmounting' | 'error';
error?: string;
routeInfo?: MicroAppRouteInfo;
metrics?: MicroAppMetrics;
lastActiveTime?: number;
}
interface MicroAppContainerProps {
config: AppConfig;
routeInfo?: MicroAppRouteInfo;
onStateChange?: (state: MicroAppState) => void;
onRouteChange?: (routeInfo: MicroAppRouteInfo) => void;
onError?: (error: Error) => void;
onMetrics?: (metrics: MicroAppMetrics) => void;
}
interface SubAppUtils {
isInWujie: boolean;
props?: any;
appInfo: {
appId?: string;
parentName?: string;
currentPath?: string;
subAppPath?: string;
};
communication: {
emitToParent: (eventName: string, data?: any) => void;
listenFromParent: (eventName: string, callback: (data?: any) => void) => () => void;
};
routing: {
notifyRouteChange: (newPath: string) => void;
listenParentRouteChange: (callback: (path: string) => void) => () => void;
};
}
interface RouteMatchResult {
matched: boolean;
appId?: string;
appConfig?: AppConfig;
routeInfo?: MicroAppRouteInfo;
exactMatch: boolean;
score: number;
}
interface RouteMatcherConfig {
strictMode: boolean;
caseSensitive: boolean;
trailingSlash: boolean;
priority: 'order' | 'specificity';
}
export type { MicroAppContainerProps, MicroAppMetrics, MicroAppRouteInfo, MicroAppState, ParentAppEvents, RouteMatchResult, RouteMatcherConfig, SubAppEvents, SubAppUtils, WujieExtendedConfig };