import { SlotBindingData, TemplateChunk, BindingData, AttributeExpressionData, ExpressionType, BindingType } from '@riotjs/dom-bindings' // Internal Types and shortcuts export type RegisteredComponentsMap = Map RiotComponent> export type ComponentEnhancer = (component: RiotComponent) => RiotComponent export type InstalledPluginsSet = Set export type RiotComponentsMap = { [key: string]: RiotComponentWrapper } export type AutobindObjectMethods = { [K in keyof Object]: Object[K] extends (...args: any) => any ? (this: This, ...args: Parameters) => ReturnType : Object[K] } export interface RiotComponent { // automatically generated on any component instance readonly props: Props readonly root: HTMLElement readonly name?: string readonly slots: SlotBindingData[] // mutable state property state: State // optional alias to map the children component names components?: RiotComponentsMap mount( element: HTMLElement, initialState?: State, parentScope?: object ): RiotComponent update( newState?: Partial, parentScope?: object ): RiotComponent unmount(keepRootElement?: boolean): RiotComponent // Helpers $(selector: string): Element | null $$(selector: string): Element[] // state handling methods shouldUpdate?(newProps: Props, oldProps: Props): boolean // lifecycle methods onBeforeMount?(props: Props, state: State): void onMounted?(props: Props, state: State): void onBeforeUpdate?(props: Props, state: State): void onUpdated?(props: Props, state: State): void onBeforeUnmount?(props: Props, state: State): void onUnmounted?(props: Props, state: State): void } // The Riot component object without the internals // The internal attributes will be handled by the framework export type RiotComponentWithoutInternals = Omit export type RiotComponentWithoutInternalsAndInitialState = Omit, 'state'> // Riot Pure Component interface that should be used together with riot.pure export interface RiotPureComponent { mount( element: HTMLElement, context?: Context, ): RiotPureComponent update( context?: Context, ): RiotPureComponent unmount(keepRootElement: boolean): RiotPureComponent } export interface PureComponentFactoryFunction { ({ slots, attributes, props }: { slots?: SlotBindingData[], attributes?: AttributeExpressionData[], props?: InitialProps; }): RiotPureComponent } // This object interface is created anytime a riot file will be compiled into javascript export interface RiotComponentWrapper { readonly css?: string | null readonly exports?: RiotComponentFactoryFunction | Component | null readonly name?: string | null template?( template: (template: string, bindings?: BindingData[]) => TemplateChunk, expressionTypes: Record, bindingTypes: Record, getComponent: (componentName: string) => any ): TemplateChunk | null } // Interface for components factory functions export interface RiotComponentFactoryFunction { (): Component components?: RiotComponentsMap } // Riot public API export function register(componentName: string, wrapper: RiotComponentWrapper>): RegisteredComponentsMap export function unregister(componentName: string): RegisteredComponentsMap export function mount(selector: string | HTMLElement, initialProps?: Props, componentName?: string): RiotComponent[] export function unmount(selector: string | HTMLElement, keepRootElement?: boolean): HTMLElement[] export function install(plugin: ComponentEnhancer): InstalledPluginsSet export function uninstall(plugin: ComponentEnhancer): InstalledPluginsSet export function component>(wrapper: RiotComponentWrapper): ( el: HTMLElement, initialProps?: Props, meta?: { slots: SlotBindingData[]; attributes: AttributeExpressionData[]; parentScope: any; } ) => Component export function pure>(func: FactoryFunction): FactoryFunction export const version: string // typescript specific methods export function withTypes, Component>> >(fn: ComponentFactory): () => Component export function withTypes, Component>> >(fn: ComponentFactory): () => Component export function withTypes>(component: AutobindObjectMethods): Component export function withTypes>(component: AutobindObjectMethods): Component