import { TemplateChunk, BindingData, AttributeExpressionData, ExpressionType, BindingType, template, createBinding, createExpression, bindingTypes, expressionTypes, TagSlotData, TagBindingData, } from '@riotjs/dom-bindings' // Internal Types and shortcuts export type DefaultProps = Record export type DefaultState = Record export type RegisteredComponentsMap = Map< string, ({ slots, attributes, props, }: { slots?: TagSlotData[] attributes?: AttributeExpressionData[] props?: DefaultProps }) => RiotComponent > export type ComponentEnhancer = < Props extends DefaultProps = DefaultProps, State extends DefaultState = DefaultState, >( component: RiotComponent, ) => RiotComponent export type InstalledPluginsSet = Set export type RiotComponentsMap = { [key: string]: RiotComponentWrapper } export type AutobindObjectMethods = { [K in keyof Object]: Object[K] extends (...args: infer Args) => infer Return ? (this: Component & Object, ...args: Args) => Return : Object[K] } export interface RiotComponent< Props extends DefaultProps = DefaultProps, State extends DefaultState = DefaultState, > { // automatically generated on any component instance readonly props: Props readonly root: HTMLElement readonly name?: string readonly slots: TagSlotData[] // 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< Component, | 'props' | 'root' | 'name' | 'slots' | 'mount' | 'update' | 'unmount' | '$' | '$$' > // Riot Pure Component interface that should be used together with riot.pure export interface RiotPureComponent { mount(element: HTMLElement, context?: Context): void update(context?: Context): void unmount(keepRootElement: boolean): void } export interface PureComponentFactoryFunction< InitialProps extends DefaultProps = DefaultProps, Context = any, > { ({ slots, attributes, props, }: { slots?: TagSlotData[] attributes?: AttributeExpressionData[] props?: InitialProps }): RiotPureComponent } // This object represents the Output of the Riot compiler 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: TagBindingData['getComponent'], ): TemplateChunk | null } // Interface for components factory functions export interface RiotComponentFactoryFunction { (...args: any[]): Component components?: RiotComponentsMap } // Riot public API export declare function register< Props extends DefaultProps, State extends DefaultState, >( componentName: string, wrapper: RiotComponentWrapper>, ): RegisteredComponentsMap export declare function unregister( componentName: string, ): RegisteredComponentsMap export declare function mount< Props extends DefaultProps, State extends DefaultState, >( selector: string | HTMLElement, initialProps?: Props, componentName?: string, ): RiotComponent[] export declare function unmount( selector: string | HTMLElement, keepRootElement?: boolean, ): HTMLElement[] export declare function install(plugin: ComponentEnhancer): InstalledPluginsSet export declare function uninstall( plugin: ComponentEnhancer, ): InstalledPluginsSet export declare function component< Props extends DefaultProps, State extends DefaultState, Component extends RiotComponent = RiotComponent, >( wrapper: RiotComponentWrapper, ): ( el: HTMLElement, initialProps?: Props, meta?: { slots: TagSlotData[] attributes: AttributeExpressionData[] parentScope: any }, ) => Component export declare function pure< InitialProps extends DefaultProps = DefaultProps, Context = any, FactoryFunction = PureComponentFactoryFunction, >(func: FactoryFunction): FactoryFunction export declare const version: string // typescript specific methods // Helper to infer the component object type InferComponent = T extends (...args: any[]) => infer C ? C : never // Functional component instantiation export declare function withTypes< Factory extends (...args: any[], Component = InferComponent) => any, Component = InferComponent, ComponentWithoutInternals = RiotComponentWithoutInternals, >( factory: RiotComponentFactoryFunction< AutobindObjectMethods >, ): ReturnType //Static component objects export declare function withTypes< Component, ComponentWithoutInternals = RiotComponentWithoutInternals, >( component: AutobindObjectMethods & { // Prevent functions from matching, prototype?: never }, ): typeof component /** * Internal stuff exposed for advanced use cases * IMPORTANT: * The things exposed under __ are not part of the official API and might break at any time * Use it at your own risk! */ export interface CSSManager { CSS_BY_NAME: Map add: (name: string, css: string) => CSSManager inject: () => CSSManager remove: (name: string) => CSSManager } export declare const __: { cssManager: CSSManager DOMBindings: { template: typeof template createBinding: typeof createBinding createExpression: typeof createExpression bindingTypes: typeof bindingTypes expressionTypes: typeof expressionTypes } globals: { PROPS_KEY: string STATE_KEY: string IS_COMPONENT_UPDATING: Symbol ATTRIBUTES_KEY_SYMBOL: Symbol PARENT_KEY_SYMBOL: Symbol DOM_COMPONENT_INSTANCE_PROPERTY: Symbol COMPONENTS_IMPLEMENTATION_MAP: RegisteredComponentsMap PLUGINS_SET: InstalledPluginsSet } }