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