1 | import * as preact from './index';
|
2 |
|
3 | export enum HookType {
|
4 | useState = 1,
|
5 | useReducer = 2,
|
6 | useEffect = 3,
|
7 | useLayoutEffect = 4,
|
8 | useRef = 5,
|
9 | useImperativeHandle = 6,
|
10 | useMemo = 7,
|
11 | useCallback = 8,
|
12 | useContext = 9,
|
13 | useErrorBoundary = 10,
|
14 |
|
15 | useDebugvalue = 11
|
16 | }
|
17 |
|
18 | export interface DevSource {
|
19 | fileName: string;
|
20 | lineNumber: number;
|
21 | }
|
22 |
|
23 | export interface ErrorInfo {
|
24 | componentStack?: string;
|
25 | }
|
26 |
|
27 | export interface Options extends preact.Options {
|
28 |
|
29 | _root?(
|
30 | vnode: ComponentChild,
|
31 | parent: Element | Document | ShadowRoot | DocumentFragment
|
32 | ): void;
|
33 |
|
34 | _diff?(vnode: VNode): void;
|
35 |
|
36 | _commit?(vnode: VNode, commitQueue: Component[]): void;
|
37 |
|
38 | _render?(vnode: VNode): void;
|
39 |
|
40 | _hook?(component: Component, index: number, type: HookType): void;
|
41 |
|
42 | _skipEffects?: boolean;
|
43 |
|
44 | _catchError(
|
45 | error: any,
|
46 | vnode: VNode,
|
47 | oldVNode: VNode | undefined,
|
48 | errorInfo: ErrorInfo | undefined
|
49 | ): void;
|
50 | }
|
51 |
|
52 | export type ComponentChild =
|
53 | | VNode<any>
|
54 | | string
|
55 | | number
|
56 | | boolean
|
57 | | null
|
58 | | undefined;
|
59 | export type ComponentChildren = ComponentChild[] | ComponentChild;
|
60 |
|
61 | export interface FunctionComponent<P = {}> extends preact.FunctionComponent<P> {
|
62 |
|
63 |
|
64 | contextType?: PreactContext;
|
65 |
|
66 |
|
67 |
|
68 | _contextRef?: PreactContext;
|
69 |
|
70 |
|
71 |
|
72 | getDerivedStateFromProps?: undefined;
|
73 | getDerivedStateFromError?: undefined;
|
74 | }
|
75 |
|
76 | export interface ComponentClass<P = {}> extends preact.ComponentClass<P> {
|
77 | _contextRef?: any;
|
78 |
|
79 |
|
80 | contextType?: PreactContext;
|
81 | }
|
82 |
|
83 |
|
84 | export type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
|
85 |
|
86 | export interface PreactElement extends HTMLElement {
|
87 | _children?: VNode<any> | null;
|
88 |
|
89 | _listeners?: Record<string, (e: Event) => void>;
|
90 |
|
91 |
|
92 | ownerSVGElement?: SVGElement | null;
|
93 |
|
94 |
|
95 |
|
96 | data?: string | number;
|
97 | }
|
98 |
|
99 |
|
100 |
|
101 | type RefObject<T> = { current: T | null };
|
102 | type RefCallback<T> = { (instance: T | null): void; current: undefined };
|
103 | type Ref<T> = RefObject<T> | RefCallback<T>;
|
104 |
|
105 | export interface VNode<P = {}> extends preact.VNode<P> {
|
106 |
|
107 | type: string | ComponentType<P>;
|
108 | props: P & { children: ComponentChildren };
|
109 | ref?: Ref<any> | null;
|
110 | _children: Array<VNode<any>> | null;
|
111 | _parent: VNode | null;
|
112 | _depth: number | null;
|
113 | |
114 |
|
115 |
|
116 | _dom: PreactElement | null;
|
117 | |
118 |
|
119 |
|
120 | _nextDom: PreactElement | null;
|
121 | _component: Component | null;
|
122 | _hydrating: boolean | null;
|
123 | constructor: undefined;
|
124 | _original: number;
|
125 | }
|
126 |
|
127 | export interface Component<P = {}, S = {}> extends preact.Component<P, S> {
|
128 |
|
129 | constructor: ComponentType<P>;
|
130 | state: S; // Override Component["state"] to not be readonly for internal use, specifically Hooks
|
131 | base?: PreactElement;
|
132 |
|
133 | _dirty: boolean;
|
134 | _force?: boolean;
|
135 | _renderCallbacks: Array<() => void>; // Only class components
|
136 | _stateCallbacks: Array<() => void>; // Only class components
|
137 | _globalContext?: any;
|
138 | _vnode?: VNode<P> | null;
|
139 | _nextState?: S | null; // Only class components
|
140 | /** Only used in the devtools to later dirty check if state has changed */
|
141 | _prevState?: S | null;
|
142 | /**
|
143 | * Pointer to the parent dom node. This is only needed for top-level Fragment
|
144 | * components or array returns.
|
145 | */
|
146 | _parentDom?: PreactElement | null;
|
147 | // Always read, set only when handling error
|
148 | _processingException?: Component<any, any> | null;
|
149 | // Always read, set only when handling error. This is used to indicate at diffTime to set _processingException
|
150 | _pendingError?: Component<any, any> | null;
|
151 | }
|
152 |
|
153 | export interface PreactContext extends preact.Context<any> {
|
154 | _id: string;
|
155 | _defaultValue: any;
|
156 | }
|