UNPKG

starchild-widget

Version:

Starchild Widget

169 lines 4.61 kB
import { Position, Locale, ThemeMode, ErrorCallback, PositionCallback, VoidCallback, DockEdgeCallback, ChatModalDetachFromEdgeCallback, BaseConfig } from '../common'; import { ThemeConfig } from '../theme'; import { AuthCredentials } from '../store/auth'; export declare enum ComponentType { CHAT = "CHAT", SEARCH = "SEARCH" } export interface ComponentConfig { type: ComponentType; visible?: boolean; position?: Position; disabled?: boolean; placeholder?: string; value?: string; isModalOpen?: boolean; } export interface ComponentPositions { [componentType: string]: Position; } export interface WidgetConfig extends BaseConfig { environment?: 'testnet' | 'mainnet'; secretKey: string; accountId: string; orderlyKey: string; aiChatKey: string; telegramUserId: string; themeMode?: ThemeMode; customTheme?: ThemeConfig; locale?: Locale; components?: { chat?: ComponentConfig; search?: ComponentConfig; }; onError?: ErrorCallback; onPositionChange?: PositionCallback; onReady?: VoidCallback; onSearchOpen?: VoidCallback; onSearchClose?: VoidCallback; onChatModalOpen?: VoidCallback; onChatModalClose?: VoidCallback; onChatModalDockToEdge?: DockEdgeCallback; onChatModalDetachFromEdge?: ChatModalDetachFromEdgeCallback; zIndex?: number; globalCSS?: string; } export interface WidgetInstance { init(): void; destroy(): void; isInitialized(): boolean; updateConfig(config: Partial<WidgetConfig>): void; getConfig(): WidgetConfig; configureCommonState(config: { theme?: ThemeMode; locale?: Locale; environment?: 'testnet' | 'mainnet'; }): void; configureAuthState(config: Partial<AuthCredentials>): void; configureChatState(config: { visible?: boolean; position?: Position; disabled?: boolean; }): void; configureSearchState(config: { visible?: boolean; disabled?: boolean; value?: string; placeholder?: string; }): void; showChatModal(containerId?: string): void; resetPosition(componentType: ComponentType): void; } export interface WidgetConstructor { new (config?: WidgetConfig): WidgetInstance; } export interface WidgetGlobalAPI { init: (config?: WidgetConfig) => WidgetInstance; getInstance: () => WidgetInstance | null; destroy: () => void; version: string; } export interface ComponentState { visible: boolean; position: Position | null; disabled: boolean; value?: string; placeholder?: string; } export interface WidgetInternalState { mounted: boolean; theme: ThemeMode; locale: Locale; error: Error | null; components: { chat: ComponentState; search: ComponentState; }; } export type WidgetAction = { type: 'INITIALIZE'; payload: Partial<WidgetInternalState>; } | { type: 'SET_MOUNTED'; payload: boolean; } | { type: 'SET_THEME'; payload: ThemeMode; } | { type: 'SET_LOCALE'; payload: Locale; } | { type: 'SET_AUTH_TOKEN'; payload: string | null; } | { type: 'SET_ERROR'; payload: Error | null; } | { type: 'SET_COMPONENT_VISIBLE'; payload: { componentType: ComponentType; visible: boolean; }; } | { type: 'SET_COMPONENT_POSITION'; payload: { componentType: ComponentType; position: Position; }; } | { type: 'SET_COMPONENT_DISABLED'; payload: { componentType: ComponentType; disabled: boolean; }; } | { type: 'SET_INPUT_VALUE'; payload: string; } | { type: 'SET_INPUT_PLACEHOLDER'; payload: string; } | { type: 'DESTROY'; }; export interface WidgetContext { state: WidgetInternalState; dispatch: React.Dispatch<WidgetAction>; } export interface WidgetActions { initialize: (config: Partial<WidgetInternalState>) => void; setMounted: (mounted: boolean) => void; setTheme: (theme: ThemeMode) => void; setLocale: (locale: Locale) => void; setDisabled: (disabled: boolean) => void; setPosition: (position: Position) => void; setAuthCredentials: (credentials: Partial<AuthCredentials>) => void; setError: (error: Error | null) => void; destroy: () => void; } export interface WidgetSelectors { isInitialized: boolean; isMounted: boolean; theme: ThemeMode; locale: Locale; disabled: boolean; position: Position | null; error: Error | null; canOperate: boolean; hasError: boolean; } //# sourceMappingURL=index.d.ts.map