import type { ComponentType, ReactNode } from 'react'; import { RouteProps } from 'react-router'; export interface Plugin { title: JSX.Element; icon: JSX.Element; content?: JSX.Element; onDismount?(): void; } interface ServerResponseSuccess { success: true; result: TRes; } interface ServerResponseError { success: false; result: string; } type ServerResponse = ServerResponseSuccess | ServerResponseError; type RoutePatch = (route: RouteProps) => RouteProps; export interface RouterHook { addRoute(path: string, component: ComponentType, props?: Omit): void; addPatch(path: string, patch: RoutePatch): RoutePatch; removePatch(path: string, patch: RoutePatch): void; removeRoute(path: string): void; } export interface ToastData { title: ReactNode; body: ReactNode; onClick?: () => void; logo?: ReactNode; icon?: ReactNode; className?: string; contentClassName?: string; duration?: number critical?: boolean } export interface Toaster { toast(toast: ToastData): void; } export interface ServerAPI { routerHook: RouterHook; toaster: Toaster; callPluginMethod(methodName: string, args: TArgs): Promise>; callServerMethod(methodName: string, args: TArgs): Promise>; fetchNoCors(url: RequestInfo, request?: RequestInit): Promise>; executeInTab(tab: string, runAsync: boolean, code: string): Promise; injectCssIntoTab(tab: string, style: string): Promise>; removeCssFromTab(tab: string, cssId: string): Promise; } type DefinePluginFn = (serverAPI: ServerAPI) => Plugin; // TypeScript helper function export const definePlugin = (fn: DefinePluginFn): DefinePluginFn => { return (...args) => { // TODO: Maybe wrap this return fn(...args); }; };