UNPKG

@ts-kit/lit-framework

Version:
48 lines (47 loc) 1.72 kB
import { Injector, ClassProviderToken } from '@ts-kit/di'; import { TemplateResult } from 'lit-html'; import { ComponentState } from './state'; declare type TemplateDef<T> = (state: T, run: (event: string, ...args: unknown[]) => (e: Event) => void) => TemplateResult; export interface ComponentConfig<T> { tag: string; template: TemplateDef<T>; defaultState: T; style?: TemplateResult; observedAttributes?: string[]; } export interface OnPropChanges { onPropChanges: (prop: string, value: any) => void; } export interface OnInit { onInit: () => void; } export interface OnConnected { connectedCallback: () => void; } export interface OnDisconnected { disconnectedCallback: () => void; } export interface OnAttributeChanged { attributeChangedCallback: (attr: string, oldVal: string, newVal: string) => void; } export declare type ComponentInstance = { props: string[]; handlers: { [key: string]: Function; }; [key: string]: any; } & Partial<OnPropChanges> & Partial<OnInit> & Partial<OnConnected> & Partial<OnDisconnected> & Partial<OnAttributeChanged>; export declare const ElementInstance: <T>(element: HTMLElement) => ElementInstance<T>; export declare type ElementInstance<T> = { componentInjector: Injector; componentInstance: ComponentInstance; componentState: ComponentState<T>; } & HTMLElement & { [key: string]: any; }; export declare type ComponentDef<T> = ClassProviderToken<T> & { tag?: string; }; export declare const createComponent: <S, C>(componentDef: ComponentDef<C>) => ElementInstance<S>; export declare const Component: <T = any>(config: ComponentConfig<T>) => (componentDef: ComponentDef<any>) => void; export {};