/* Public and internal type declarations shared across the library. */ import type { WompoChildren } from './dynamics.js'; export type { WompoChildren }; /** The html`` template function result type. */ export interface RenderHtml { parts: TemplateStringsArray; values: any[]; key?: string; _$wompoHtml: true; _$wompoSvg?: boolean; _$portal?: HTMLElement; } /** The props of any component. */ export interface WompoProps { children?: WompoChildren; styles?: { [key: string]: string }; ['wc-perf']?: boolean; wcPerf?: boolean; style?: string | Partial | object; ref?: RefHook; id?: string; class?: string; [event: `on${string}`]: (ev: Event) => void; } /** The options that a component can have when instantiating. */ export interface WompoComponentOptions { name?: string; shadow?: boolean; cssModule?: boolean; /** Default hydration trigger. When set, every instance of this component is treated as an * island and hydrated according to this mode unless overridden by a `client:*` attribute on * the call site. */ island?: 'load' | 'idle' | 'visible'; } /** Wompo component function with extra metadata fields populated by `defineWompo`. */ export interface WompoComponent { (props: Props): RenderHtml; css?: string; componentName?: string; _$wompoF?: true; class?: WompoElementClass; options?: { generatedCSS: string; styles: { [key: string]: string }; shadow: boolean; island?: 'load' | 'idle' | 'visible'; }; } /** A Wompo component instance (HTMLElement + internal fields). */ export type WompoElement = HTMLElement & E & { props: Props; hooks: Hook[]; _$initialProps: WompoProps; _$portals: any[]; _$measurePerf: boolean; _$usesContext: boolean; _$hasBeenMoved: boolean; _$effects: EffectHook[]; _$asyncCalls: AsyncHook[]; _$suspendedAsyncCalls: AsyncHook[]; _$layoutEffects: EffectHook[]; requestRender: () => void; onDisconnected: () => void; updateProp: (prop: string, newValue: any) => void; _$wompo: true; _$updating: boolean; }; export type Hook = | StateHook | EffectHook | RefHook | CallbackHook | IdHook | MemoHook | ReducerHook | AsyncHook | ContextHook; export type StateHook = [S, (newValue: S | ((oldValue: S) => S)) => void]; export interface EffectHook { dependencies: any; callback: VoidFunction | (() => VoidFunction); cleanupFunction: VoidFunction | void; } export interface RefHook { current: V; __wcRef: true; } export interface CallbackHook { dependencies?: any[]; value: C; } export type IdHook = string; export interface MemoHook { dependencies: any[]; value: T; } export interface ReducerAction { [key: string]: any; } export type ReducerHook = [State, (action: ReducerAction) => void]; export interface AsyncHook { asyncCallback: () => Promise; dependencies: any[]; value: S; activateSuspense: boolean; } export interface ContextProviderProps extends WompoProps { value: any; } export interface ContextProviderExposed { subscribers: RefHook>; } export type ContextProviderElement = WompoElement; export interface ContextHook { node: ContextProviderElement; } /** The type of the class generated by the wompo() function. */ export interface WompoElementClass { new (): WompoElement; _$cachedTemplates: Map; _$getOrCreateTemplate(parts: TemplateStringsArray): any; } /** Metadata for a single dynamic part inside a CachedTemplate. */ export interface Dependency { type: number; index: number; name?: string; attrDynamics?: string; } /** The bag of attributes returned by the `attrs` function. */ export interface AttrsBag { _$wompoAttrs: true; entries: { [key: string]: any }; } export interface Context { Provider: WompoComponent; default: S; name: string; } export type LazyCallbackResult = Promise<{ default: WompoComponent }>; export type LazyResult = { (): Promise>; _$wompoLazy: boolean; }; export interface SuspenseProps extends WompoProps { fallback: RenderHtml; } export interface SuspenseInstance extends WompoElement { loadingComponents: Set; addSuspense: (node: Node) => void; removeSuspense: (node: Node, newNode?: Node) => void; }