@pixui-dev/pxw 0.1.19 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/pxw.js +199 -199
- package/bin/wpbuild.js +10 -10
- package/config/default.conf +20 -20
- package/config/devops.js +372 -361
- package/config/h5es.js +10 -10
- package/config/index.html +183 -181
- package/config/pfbs.js +245 -245
- package/config/util.js +140 -140
- package/config/webpack.js +325 -309
- package/lib/assets/check.html +62 -62
- package/lib/assets/preact.js +4354 -4354
- package/lib/check/main.less +62 -62
- package/lib/check/main.tsx +41 -41
- package/lib/check/tool.js +3 -3
- package/lib/check/util.tsx +110 -110
- package/lib/grpc-web/dist/ChunkParser.js +117 -117
- package/lib/grpc-web/dist/Code.js +58 -58
- package/lib/grpc-web/dist/client.js +299 -299
- package/lib/grpc-web/dist/debug.js +16 -16
- package/lib/grpc-web/dist/detach.js +7 -7
- package/lib/grpc-web/dist/index.js +29 -29
- package/lib/grpc-web/dist/invoke.js +32 -32
- package/lib/grpc-web/dist/message.js +3 -3
- package/lib/grpc-web/dist/metadata.js +5 -5
- package/lib/grpc-web/dist/service.js +3 -3
- package/lib/grpc-web/dist/transports/Transport.js +15 -15
- package/lib/grpc-web/dist/transports/http/fetch.js +117 -117
- package/lib/grpc-web/dist/transports/http/http.js +15 -15
- package/lib/grpc-web/dist/transports/http/xhr.js +136 -136
- package/lib/grpc-web/dist/transports/http/xhrUtil.js +36 -36
- package/lib/grpc-web/dist/transports/websocket/websocket.js +95 -95
- package/lib/grpc-web/dist/typings/ChunkParser.d.ts +17 -17
- package/lib/grpc-web/dist/typings/Code.d.ts +20 -20
- package/lib/grpc-web/dist/typings/client.d.ts +25 -25
- package/lib/grpc-web/dist/typings/debug.d.ts +1 -1
- package/lib/grpc-web/dist/typings/detach.d.ts +1 -1
- package/lib/grpc-web/dist/typings/index.d.ts +45 -45
- package/lib/grpc-web/dist/typings/invoke.d.ts +20 -20
- package/lib/grpc-web/dist/typings/message.d.ts +8 -8
- package/lib/grpc-web/dist/typings/metadata.d.ts +2 -2
- package/lib/grpc-web/dist/typings/service.d.ts +16 -16
- package/lib/grpc-web/dist/typings/transports/Transport.d.ts +22 -22
- package/lib/grpc-web/dist/typings/transports/http/fetch.d.ts +6 -6
- package/lib/grpc-web/dist/typings/transports/http/http.d.ts +5 -5
- package/lib/grpc-web/dist/typings/transports/http/xhr.d.ts +27 -27
- package/lib/grpc-web/dist/typings/transports/http/xhrUtil.d.ts +3 -3
- package/lib/grpc-web/dist/typings/transports/websocket/websocket.d.ts +2 -2
- package/lib/grpc-web/dist/typings/unary.d.ts +23 -23
- package/lib/grpc-web/dist/typings/util.d.ts +2 -2
- package/lib/grpc-web/dist/unary.js +44 -44
- package/lib/grpc-web/dist/util.js +11 -11
- package/lib/grpcTransport/PixHttp2Transport.ts +107 -107
- package/lib/grpcTransport/PixLuaTransport.ts +82 -82
- package/lib/h5es-types/v1.9.2/h5es.d.ts +1698 -1698
- package/lib/h5es-types/v3.5.0/h5es.d.ts +1788 -1788
- package/lib/pi_component/tinyList/tinyList.js +483 -483
- package/lib/pi_component/tinyList/tinyList.tsx +517 -517
- package/lib/preact-router.js +395 -395
- package/lib/preact.js +4355 -4355
- package/lib/preact.tq.js +4385 -4385
- package/lib/react-window/src/FixedSizeGrid.js +172 -172
- package/lib/react-window/src/FixedSizeList.js +91 -91
- package/lib/react-window/src/VariableSizeGrid.js +329 -329
- package/lib/react-window/src/VariableSizeList.js +231 -231
- package/lib/react-window/src/__tests__/FixedSizeGrid.js +942 -942
- package/lib/react-window/src/__tests__/FixedSizeList.js +749 -749
- package/lib/react-window/src/__tests__/VariableSizeGrid.js +598 -598
- package/lib/react-window/src/__tests__/VariableSizeList.js +345 -345
- package/lib/react-window/src/__tests__/__snapshots__/FixedSizeGrid.js.snap +912 -912
- package/lib/react-window/src/__tests__/__snapshots__/FixedSizeList.js.snap +568 -568
- package/lib/react-window/src/__tests__/__snapshots__/VariableSizeGrid.js.snap +542 -542
- package/lib/react-window/src/__tests__/__snapshots__/VariableSizeList.js.snap +331 -331
- package/lib/react-window/src/__tests__/areEqual.js +28 -28
- package/lib/react-window/src/__tests__/shouldComponentUpdate.js +32 -32
- package/lib/react-window/src/areEqual.js +13 -13
- package/lib/react-window/src/createGridComponent.js +657 -657
- package/lib/react-window/src/createListComponent.js +574 -574
- package/lib/react-window/src/domHelpers.js +69 -69
- package/lib/react-window/src/index.js +9 -9
- package/lib/react-window/src/shallowDiffers.js +17 -17
- package/lib/react-window/src/shouldComponentUpdate.js +11 -11
- package/lib/react-window/src/test.js.flow +382 -382
- package/lib/react-window/src/timer.js +36 -36
- package/lib/types/dom.ts +17 -17
- package/lib/types/ext.d.ts +81 -81
- package/lib/types/{css.d.ts → preact/css.d.ts} +7476 -7476
- package/lib/types/{preact.d.ts → preact/index.d.ts} +340 -340
- package/lib/types/{internal.d.ts → preact/internal.d.ts} +94 -94
- package/lib/types/{jsx.d.ts → preact/jsx.d.ts} +309 -309
- package/lib/types/preact-router/index.d.ts +85 -0
- package/package.json +113 -113
- package/scripts/pack.js +40 -40
- package/scripts/postinstall.js +11 -11
- package/scripts/run-pxw.js +12 -12
- package/tsconfig.json +30 -30
|
@@ -1,340 +1,340 @@
|
|
|
1
|
-
export = preact;
|
|
2
|
-
export as namespace preact;
|
|
3
|
-
|
|
4
|
-
import { JSXInternal, CSSProperties } from './jsx';
|
|
5
|
-
|
|
6
|
-
// declare module 'preact' {
|
|
7
|
-
declare namespace preact {
|
|
8
|
-
export import JSX = JSXInternal;
|
|
9
|
-
export import CSSProperties = CSSProperties;
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
// Preact Virtual DOM
|
|
13
|
-
// -----------------------------------
|
|
14
|
-
|
|
15
|
-
interface VNode<P = {}> {
|
|
16
|
-
type: ComponentType<P> | string;
|
|
17
|
-
props: P & { children: ComponentChildren };
|
|
18
|
-
key: Key;
|
|
19
|
-
/**
|
|
20
|
-
* ref is not guaranteed by React.ReactElement, for compatiblity reasons
|
|
21
|
-
* with popular react libs we define it as optional too
|
|
22
|
-
*/
|
|
23
|
-
ref?: Ref<any> | null;
|
|
24
|
-
/**
|
|
25
|
-
* The time this `vnode` started rendering. Will only be set when
|
|
26
|
-
* the devtools are attached.
|
|
27
|
-
* Default value: `0`
|
|
28
|
-
*/
|
|
29
|
-
startTime?: number;
|
|
30
|
-
/**
|
|
31
|
-
* The time that the rendering of this `vnode` was completed. Will only be
|
|
32
|
-
* set when the devtools are attached.
|
|
33
|
-
* Default value: `-1`
|
|
34
|
-
*/
|
|
35
|
-
endTime?: number;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
// Preact Component interface
|
|
40
|
-
// -----------------------------------
|
|
41
|
-
|
|
42
|
-
type Key = string | number | any;
|
|
43
|
-
|
|
44
|
-
type RefObject<T> = { current?: T | null };
|
|
45
|
-
type RefCallback<T> = (instance: T | null) => void;
|
|
46
|
-
type Ref<T> = RefObject<T> | RefCallback<T>;
|
|
47
|
-
|
|
48
|
-
type ComponentChild = VNode<any> | object | string | number | boolean | null | undefined;
|
|
49
|
-
type ComponentChildren = ComponentChild[] | ComponentChild;
|
|
50
|
-
|
|
51
|
-
interface Attributes {
|
|
52
|
-
key?: Key;
|
|
53
|
-
jsx?: boolean;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
interface ClassAttributes<T> extends Attributes {
|
|
57
|
-
ref?: Ref<T>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
interface PreactDOMAttributes {
|
|
61
|
-
children?: ComponentChildren;
|
|
62
|
-
dangerouslySetInnerHTML?: {
|
|
63
|
-
__html: string;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
type RenderableProps<P, RefType = any> = P & Readonly<Attributes & { children?: ComponentChildren; ref?: Ref<RefType> }>;
|
|
68
|
-
|
|
69
|
-
type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
|
|
70
|
-
type ComponentFactory<P = {}> = ComponentType<P>;
|
|
71
|
-
|
|
72
|
-
type ComponentProps<C extends ComponentType<any>> = C extends ComponentType<infer P> ? P : never;
|
|
73
|
-
|
|
74
|
-
interface FunctionComponent<P = {}> {
|
|
75
|
-
(props: RenderableProps<P>, context?: any): VNode<any> | null;
|
|
76
|
-
displayName?: string;
|
|
77
|
-
defaultProps?: Partial<P>;
|
|
78
|
-
}
|
|
79
|
-
interface FunctionalComponent<P = {}> extends FunctionComponent<P> {}
|
|
80
|
-
|
|
81
|
-
interface ComponentClass<P = {}, S = {}> {
|
|
82
|
-
new (props: P, context?: any): Component<P, S>;
|
|
83
|
-
displayName?: string;
|
|
84
|
-
defaultProps?: Partial<P>;
|
|
85
|
-
getDerivedStateFromProps?(props: Readonly<P>, state: Readonly<S>): Partial<S> | null;
|
|
86
|
-
getDerivedStateFromError?(error: any): Partial<S> | null;
|
|
87
|
-
}
|
|
88
|
-
interface ComponentConstructor<P = {}, S = {}> extends ComponentClass<P, S> {}
|
|
89
|
-
|
|
90
|
-
// Type alias for a component instance considered generally, whether stateless or stateful.
|
|
91
|
-
type AnyComponent<P = {}, S = {}> = FunctionComponent<P> | Component<P, S>;
|
|
92
|
-
|
|
93
|
-
interface Component<P = {}, S = {}> {
|
|
94
|
-
refs: { [key: string]: Component<any> | Element };
|
|
95
|
-
componentWillMount?(): void;
|
|
96
|
-
componentDidMount?(): void;
|
|
97
|
-
componentWillUnmount?(): void;
|
|
98
|
-
getChildContext?(): object;
|
|
99
|
-
componentWillReceiveProps?(nextProps: Readonly<P>, nextContext: any): void;
|
|
100
|
-
shouldComponentUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): boolean;
|
|
101
|
-
componentWillUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): void;
|
|
102
|
-
getSnapshotBeforeUpdate?(oldProps: Readonly<P>, oldState: Readonly<S>): any;
|
|
103
|
-
componentDidUpdate?(previousProps: Readonly<P>, previousState: Readonly<S>, snapshot: any): void;
|
|
104
|
-
componentDidCatch?(error: any, errorInfo: any): void;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
abstract class Component<P, S> {
|
|
108
|
-
constructor(props?: P, context?: any);
|
|
109
|
-
|
|
110
|
-
static displayName?: string;
|
|
111
|
-
static defaultProps?: any;
|
|
112
|
-
static contextType?: Context<any>;
|
|
113
|
-
|
|
114
|
-
// Static members cannot reference class type parameters. This is not
|
|
115
|
-
// supported in TypeScript. Reusing the same type arguments from `Component`
|
|
116
|
-
// will lead to an impossible state where one cannot satisfy the type
|
|
117
|
-
// constraint under no circumstances, see #1356.In general type arguments
|
|
118
|
-
// seem to be a bit buggy and not supported well at the time of this
|
|
119
|
-
// writing with TS 3.3.3333.
|
|
120
|
-
static getDerivedStateFromProps?(props: Readonly<object>, state: Readonly<object>): object | null;
|
|
121
|
-
static getDerivedStateFromError?(error: any): object | null;
|
|
122
|
-
|
|
123
|
-
state: Readonly<S>;
|
|
124
|
-
props: RenderableProps<P>;
|
|
125
|
-
context: any;
|
|
126
|
-
base?: Element | Text;
|
|
127
|
-
|
|
128
|
-
// From https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e836acc75a78cf0655b5dfdbe81d69fdd4d8a252/types/react/index.d.ts#L402
|
|
129
|
-
// // We MUST keep setState() as a unified signature because it allows proper checking of the method return type.
|
|
130
|
-
// // See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365#issuecomment-351013257
|
|
131
|
-
setState<K extends keyof S>(state: ((prevState: Readonly<S>, props: Readonly<P>) => Pick<S, K> | Partial<S> | null) | (Pick<S, K> | Partial<S> | null), callback?: () => void): void;
|
|
132
|
-
|
|
133
|
-
forceUpdate(callback?: () => void): void;
|
|
134
|
-
|
|
135
|
-
abstract render(props?: RenderableProps<P>, state?: Readonly<S>, context?: any): ComponentChild;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
//
|
|
139
|
-
// Preact createElement
|
|
140
|
-
// -----------------------------------
|
|
141
|
-
|
|
142
|
-
function createElement(type: string, props: (JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record<string, any>) | null, ...children: ComponentChildren[]): VNode<any>;
|
|
143
|
-
function createElement<P>(type: ComponentType<P>, props: (Attributes & P) | null, ...children: ComponentChildren[]): VNode<any>;
|
|
144
|
-
namespace createElement {
|
|
145
|
-
export import JSX = JSXInternal;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function h(type: string, props: (JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record<string, any>) | null, ...children: ComponentChildren[]): VNode<any>;
|
|
149
|
-
function h<P>(type: ComponentType<P>, props: (Attributes & P) | null, ...children: ComponentChildren[]): VNode<any>;
|
|
150
|
-
namespace h {
|
|
151
|
-
export import JSX = JSXInternal;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
//
|
|
155
|
-
// Preact render
|
|
156
|
-
// -----------------------------------
|
|
157
|
-
|
|
158
|
-
function render(vnode: ComponentChild, parent: Element | Document | ShadowRoot | DocumentFragment, replaceNode?: Element | Text): void;
|
|
159
|
-
function hydrate(vnode: ComponentChild, parent: Element | Document | ShadowRoot | DocumentFragment): void;
|
|
160
|
-
function cloneElement(vnode: VNode<any>, props?: any, ...children: ComponentChildren[]): VNode<any>;
|
|
161
|
-
function cloneElement<P>(vnode: VNode<P>, props?: any, ...children: ComponentChildren[]): VNode<P>;
|
|
162
|
-
|
|
163
|
-
//
|
|
164
|
-
// Preact Built-in Components
|
|
165
|
-
// -----------------------------------
|
|
166
|
-
|
|
167
|
-
// TODO: Revisit what the public type of this is...
|
|
168
|
-
const Fragment: ComponentClass<{}, {}>;
|
|
169
|
-
|
|
170
|
-
//
|
|
171
|
-
// Preact options
|
|
172
|
-
// -----------------------------------
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Global options for preact
|
|
176
|
-
*/
|
|
177
|
-
interface Options {
|
|
178
|
-
/** Attach a hook that is invoked whenever a VNode is created. */
|
|
179
|
-
vnode?(vnode: VNode): void;
|
|
180
|
-
/** Attach a hook that is invoked immediately before a vnode is unmounted. */
|
|
181
|
-
unmount?(vnode: VNode): void;
|
|
182
|
-
/** Attach a hook that is invoked after a vnode has rendered. */
|
|
183
|
-
diffed?(vnode: VNode): void;
|
|
184
|
-
event?(e: Event): any;
|
|
185
|
-
requestAnimationFrame?: typeof requestAnimationFrame;
|
|
186
|
-
debounceRendering?(cb: () => void): void;
|
|
187
|
-
useDebugValue?(value: string | number): void;
|
|
188
|
-
__suspenseDidResolve?(vnode: VNode, cb: () => void): void;
|
|
189
|
-
// __canSuspenseResolve?(vnode: VNode, cb: () => void): void;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const options: Options;
|
|
193
|
-
|
|
194
|
-
//
|
|
195
|
-
// Preact helpers
|
|
196
|
-
// -----------------------------------
|
|
197
|
-
function createRef<T = any>(): RefObject<T>;
|
|
198
|
-
function toChildArray(children: ComponentChildren): Array<VNode | string | number>;
|
|
199
|
-
function isValidElement(vnode: any): vnode is VNode;
|
|
200
|
-
|
|
201
|
-
//
|
|
202
|
-
// Context
|
|
203
|
-
// -----------------------------------
|
|
204
|
-
interface Consumer<T>
|
|
205
|
-
extends FunctionComponent<{
|
|
206
|
-
children: (value: T) => ComponentChildren;
|
|
207
|
-
}> {}
|
|
208
|
-
interface PreactConsumer<T> extends Consumer<T> {}
|
|
209
|
-
|
|
210
|
-
interface Provider<T>
|
|
211
|
-
extends FunctionComponent<{
|
|
212
|
-
value: T;
|
|
213
|
-
children: ComponentChildren;
|
|
214
|
-
}> {}
|
|
215
|
-
interface PreactProvider<T> extends Provider<T> {}
|
|
216
|
-
|
|
217
|
-
interface Context<T> {
|
|
218
|
-
Consumer: Consumer<T>;
|
|
219
|
-
Provider: Provider<T>;
|
|
220
|
-
}
|
|
221
|
-
interface PreactContext<T> extends Context<T> {}
|
|
222
|
-
|
|
223
|
-
function createContext<T>(defaultValue: T): Context<T>;
|
|
224
|
-
function useContext<T>(defaultValue: Context<T>);
|
|
225
|
-
}
|
|
226
|
-
type Inputs = ReadonlyArray<unknown>;
|
|
227
|
-
|
|
228
|
-
export type StateUpdater<S> = (value: S | ((prevState: S) => S)) => void;
|
|
229
|
-
/**
|
|
230
|
-
* Returns a stateful value, and a function to update it.
|
|
231
|
-
* @param initialState The initial value (or a function that returns the initial value)
|
|
232
|
-
*/
|
|
233
|
-
export function useState<S>(initialState: S | (() => S)): [S, StateUpdater<S>];
|
|
234
|
-
|
|
235
|
-
export type Reducer<S, A> = (prevState: S, action: A) => S;
|
|
236
|
-
/**
|
|
237
|
-
* An alternative to `useState`.
|
|
238
|
-
*
|
|
239
|
-
* `useReducer` is usually preferable to `useState` when you have complex state logic that involves
|
|
240
|
-
* multiple sub-values. It also lets you optimize performance for components that trigger deep
|
|
241
|
-
* updates because you can pass `dispatch` down instead of callbacks.
|
|
242
|
-
* @param reducer Given the current state and an action, returns the new state
|
|
243
|
-
* @param initialState The initial value to store as state
|
|
244
|
-
*/
|
|
245
|
-
export function useReducer<S, A>(reducer: Reducer<S, A>, initialState: S): [S, (action: A) => void];
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* An alternative to `useState`.
|
|
249
|
-
*
|
|
250
|
-
* `useReducer` is usually preferable to `useState` when you have complex state logic that involves
|
|
251
|
-
* multiple sub-values. It also lets you optimize performance for components that trigger deep
|
|
252
|
-
* updates because you can pass `dispatch` down instead of callbacks.
|
|
253
|
-
* @param reducer Given the current state and an action, returns the new state
|
|
254
|
-
* @param initialArg The initial argument to pass to the `init` function
|
|
255
|
-
* @param init A function that, given the `initialArg`, returns the initial value to store as state
|
|
256
|
-
*/
|
|
257
|
-
export function useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I, init: (arg: I) => S): [S, (action: A) => void];
|
|
258
|
-
|
|
259
|
-
type PropRef<T> = { current?: T };
|
|
260
|
-
type Ref<T> = { current: T };
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
|
|
264
|
-
* (`initialValue`). The returned object will persist for the full lifetime of the component.
|
|
265
|
-
*
|
|
266
|
-
* Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
|
|
267
|
-
* value around similar to how you’d use instance fields in classes.
|
|
268
|
-
*/
|
|
269
|
-
export function useRef<T>(initialValue: T | null): Ref<T>;
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* `useRef` without an initial value is the special case handling `ref` props.
|
|
273
|
-
* If you want a non prop-based, mutable ref, you can explicitly give it an initial value of undefined/null/etc.
|
|
274
|
-
* You should explicitly set the type parameter for the expected ref value to either a DOM Element like `HTMLInputElement` or a `Component`
|
|
275
|
-
*/
|
|
276
|
-
export function useRef<T = unknown>(): PropRef<T>;
|
|
277
|
-
|
|
278
|
-
type EffectCallback = () => void | (() => void);
|
|
279
|
-
/**
|
|
280
|
-
* Accepts a function that contains imperative, possibly effectful code.
|
|
281
|
-
* The effects run after browser paint, without blocking it.
|
|
282
|
-
*
|
|
283
|
-
* @param effect Imperative function that can return a cleanup function
|
|
284
|
-
* @param inputs If present, effect will only activate if the values in the list change (using ===).
|
|
285
|
-
*/
|
|
286
|
-
export function useEffect(effect: EffectCallback, inputs?: Inputs): void;
|
|
287
|
-
|
|
288
|
-
type CreateHandle = () => object;
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* @param ref The ref that will be mutated
|
|
292
|
-
* @param create The function that will be executed to get the value that will be attached to
|
|
293
|
-
* ref.current
|
|
294
|
-
* @param inputs If present, effect will only activate if the values in the list change (using ===).
|
|
295
|
-
*/
|
|
296
|
-
export function useImperativeHandle<T, R extends T>(ref: PreactRef<T>, create: () => R, inputs?: Inputs): void;
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Accepts a function that contains imperative, possibly effectful code.
|
|
300
|
-
* Use this to read layout from the DOM and synchronously re-render.
|
|
301
|
-
* Updates scheduled inside `useLayoutEffect` will be flushed synchronously, after all DOM mutations but before the browser has a chance to paint.
|
|
302
|
-
* Prefer the standard `useEffect` hook when possible to avoid blocking visual updates.
|
|
303
|
-
*
|
|
304
|
-
* @param effect Imperative function that can return a cleanup function
|
|
305
|
-
* @param inputs If present, effect will only activate if the values in the list change (using ===).
|
|
306
|
-
*/
|
|
307
|
-
export function useLayoutEffect(effect: EffectCallback, inputs?: Inputs): void;
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Returns a memoized version of the callback that only changes if one of the `inputs`
|
|
311
|
-
* has changed (using ===).
|
|
312
|
-
*/
|
|
313
|
-
export function useCallback<T extends Function>(callback: T, inputs: Inputs): T;
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Pass a factory function and an array of inputs.
|
|
317
|
-
* useMemo will only recompute the memoized value when one of the inputs has changed.
|
|
318
|
-
* This optimization helps to avoid expensive calculations on every render.
|
|
319
|
-
* If no array is provided, a new value will be computed whenever a new function instance is passed as the first argument.
|
|
320
|
-
*/
|
|
321
|
-
// for `inputs`, allow undefined, but don't make it optional as that is very likely a mistake
|
|
322
|
-
export function useMemo<T>(factory: () => T, inputs: Inputs | undefined): T;
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Returns the current context value, as given by the nearest context provider for the given context.
|
|
326
|
-
* When the provider updates, this Hook will trigger a rerender with the latest context value.
|
|
327
|
-
*
|
|
328
|
-
* @param context The context you want to use
|
|
329
|
-
*/
|
|
330
|
-
export function useContext<T>(context: PreactContext<T>): T;
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Customize the displayed value in the devtools panel.
|
|
334
|
-
*
|
|
335
|
-
* @param value Custom hook name or object that is passed to formatter
|
|
336
|
-
* @param formatter Formatter to modify value before sending it to the devtools
|
|
337
|
-
*/
|
|
338
|
-
export function useDebugValue<T>(value: T, formatter?: (value: T) => string | number): void;
|
|
339
|
-
|
|
340
|
-
export function useErrorBoundary(callback?: (error: any) => Promise<void> | void): [any, () => void];
|
|
1
|
+
export = preact;
|
|
2
|
+
export as namespace preact;
|
|
3
|
+
|
|
4
|
+
import { JSXInternal, CSSProperties } from './jsx';
|
|
5
|
+
|
|
6
|
+
// declare module 'preact' {
|
|
7
|
+
declare namespace preact {
|
|
8
|
+
export import JSX = JSXInternal;
|
|
9
|
+
export import CSSProperties = CSSProperties;
|
|
10
|
+
|
|
11
|
+
//
|
|
12
|
+
// Preact Virtual DOM
|
|
13
|
+
// -----------------------------------
|
|
14
|
+
|
|
15
|
+
interface VNode<P = {}> {
|
|
16
|
+
type: ComponentType<P> | string;
|
|
17
|
+
props: P & { children: ComponentChildren };
|
|
18
|
+
key: Key;
|
|
19
|
+
/**
|
|
20
|
+
* ref is not guaranteed by React.ReactElement, for compatiblity reasons
|
|
21
|
+
* with popular react libs we define it as optional too
|
|
22
|
+
*/
|
|
23
|
+
ref?: Ref<any> | null;
|
|
24
|
+
/**
|
|
25
|
+
* The time this `vnode` started rendering. Will only be set when
|
|
26
|
+
* the devtools are attached.
|
|
27
|
+
* Default value: `0`
|
|
28
|
+
*/
|
|
29
|
+
startTime?: number;
|
|
30
|
+
/**
|
|
31
|
+
* The time that the rendering of this `vnode` was completed. Will only be
|
|
32
|
+
* set when the devtools are attached.
|
|
33
|
+
* Default value: `-1`
|
|
34
|
+
*/
|
|
35
|
+
endTime?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//
|
|
39
|
+
// Preact Component interface
|
|
40
|
+
// -----------------------------------
|
|
41
|
+
|
|
42
|
+
type Key = string | number | any;
|
|
43
|
+
|
|
44
|
+
type RefObject<T> = { current?: T | null };
|
|
45
|
+
type RefCallback<T> = (instance: T | null) => void;
|
|
46
|
+
type Ref<T> = RefObject<T> | RefCallback<T>;
|
|
47
|
+
|
|
48
|
+
type ComponentChild = VNode<any> | object | string | number | boolean | null | undefined;
|
|
49
|
+
type ComponentChildren = ComponentChild[] | ComponentChild;
|
|
50
|
+
|
|
51
|
+
interface Attributes {
|
|
52
|
+
key?: Key;
|
|
53
|
+
jsx?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface ClassAttributes<T> extends Attributes {
|
|
57
|
+
ref?: Ref<T>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface PreactDOMAttributes {
|
|
61
|
+
children?: ComponentChildren;
|
|
62
|
+
dangerouslySetInnerHTML?: {
|
|
63
|
+
__html: string;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type RenderableProps<P, RefType = any> = P & Readonly<Attributes & { children?: ComponentChildren; ref?: Ref<RefType> }>;
|
|
68
|
+
|
|
69
|
+
type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
|
|
70
|
+
type ComponentFactory<P = {}> = ComponentType<P>;
|
|
71
|
+
|
|
72
|
+
type ComponentProps<C extends ComponentType<any>> = C extends ComponentType<infer P> ? P : never;
|
|
73
|
+
|
|
74
|
+
interface FunctionComponent<P = {}> {
|
|
75
|
+
(props: RenderableProps<P>, context?: any): VNode<any> | null;
|
|
76
|
+
displayName?: string;
|
|
77
|
+
defaultProps?: Partial<P>;
|
|
78
|
+
}
|
|
79
|
+
interface FunctionalComponent<P = {}> extends FunctionComponent<P> {}
|
|
80
|
+
|
|
81
|
+
interface ComponentClass<P = {}, S = {}> {
|
|
82
|
+
new (props: P, context?: any): Component<P, S>;
|
|
83
|
+
displayName?: string;
|
|
84
|
+
defaultProps?: Partial<P>;
|
|
85
|
+
getDerivedStateFromProps?(props: Readonly<P>, state: Readonly<S>): Partial<S> | null;
|
|
86
|
+
getDerivedStateFromError?(error: any): Partial<S> | null;
|
|
87
|
+
}
|
|
88
|
+
interface ComponentConstructor<P = {}, S = {}> extends ComponentClass<P, S> {}
|
|
89
|
+
|
|
90
|
+
// Type alias for a component instance considered generally, whether stateless or stateful.
|
|
91
|
+
type AnyComponent<P = {}, S = {}> = FunctionComponent<P> | Component<P, S>;
|
|
92
|
+
|
|
93
|
+
interface Component<P = {}, S = {}> {
|
|
94
|
+
refs: { [key: string]: Component<any> | Element };
|
|
95
|
+
componentWillMount?(): void;
|
|
96
|
+
componentDidMount?(): void;
|
|
97
|
+
componentWillUnmount?(): void;
|
|
98
|
+
getChildContext?(): object;
|
|
99
|
+
componentWillReceiveProps?(nextProps: Readonly<P>, nextContext: any): void;
|
|
100
|
+
shouldComponentUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): boolean;
|
|
101
|
+
componentWillUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): void;
|
|
102
|
+
getSnapshotBeforeUpdate?(oldProps: Readonly<P>, oldState: Readonly<S>): any;
|
|
103
|
+
componentDidUpdate?(previousProps: Readonly<P>, previousState: Readonly<S>, snapshot: any): void;
|
|
104
|
+
componentDidCatch?(error: any, errorInfo: any): void;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
abstract class Component<P, S> {
|
|
108
|
+
constructor(props?: P, context?: any);
|
|
109
|
+
|
|
110
|
+
static displayName?: string;
|
|
111
|
+
static defaultProps?: any;
|
|
112
|
+
static contextType?: Context<any>;
|
|
113
|
+
|
|
114
|
+
// Static members cannot reference class type parameters. This is not
|
|
115
|
+
// supported in TypeScript. Reusing the same type arguments from `Component`
|
|
116
|
+
// will lead to an impossible state where one cannot satisfy the type
|
|
117
|
+
// constraint under no circumstances, see #1356.In general type arguments
|
|
118
|
+
// seem to be a bit buggy and not supported well at the time of this
|
|
119
|
+
// writing with TS 3.3.3333.
|
|
120
|
+
static getDerivedStateFromProps?(props: Readonly<object>, state: Readonly<object>): object | null;
|
|
121
|
+
static getDerivedStateFromError?(error: any): object | null;
|
|
122
|
+
|
|
123
|
+
state: Readonly<S>;
|
|
124
|
+
props: RenderableProps<P>;
|
|
125
|
+
context: any;
|
|
126
|
+
base?: Element | Text;
|
|
127
|
+
|
|
128
|
+
// From https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e836acc75a78cf0655b5dfdbe81d69fdd4d8a252/types/react/index.d.ts#L402
|
|
129
|
+
// // We MUST keep setState() as a unified signature because it allows proper checking of the method return type.
|
|
130
|
+
// // See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365#issuecomment-351013257
|
|
131
|
+
setState<K extends keyof S>(state: ((prevState: Readonly<S>, props: Readonly<P>) => Pick<S, K> | Partial<S> | null) | (Pick<S, K> | Partial<S> | null), callback?: () => void): void;
|
|
132
|
+
|
|
133
|
+
forceUpdate(callback?: () => void): void;
|
|
134
|
+
|
|
135
|
+
abstract render(props?: RenderableProps<P>, state?: Readonly<S>, context?: any): ComponentChild;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//
|
|
139
|
+
// Preact createElement
|
|
140
|
+
// -----------------------------------
|
|
141
|
+
|
|
142
|
+
function createElement(type: string, props: (JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record<string, any>) | null, ...children: ComponentChildren[]): VNode<any>;
|
|
143
|
+
function createElement<P>(type: ComponentType<P>, props: (Attributes & P) | null, ...children: ComponentChildren[]): VNode<any>;
|
|
144
|
+
namespace createElement {
|
|
145
|
+
export import JSX = JSXInternal;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function h(type: string, props: (JSXInternal.HTMLAttributes & JSXInternal.SVGAttributes & Record<string, any>) | null, ...children: ComponentChildren[]): VNode<any>;
|
|
149
|
+
function h<P>(type: ComponentType<P>, props: (Attributes & P) | null, ...children: ComponentChildren[]): VNode<any>;
|
|
150
|
+
namespace h {
|
|
151
|
+
export import JSX = JSXInternal;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
//
|
|
155
|
+
// Preact render
|
|
156
|
+
// -----------------------------------
|
|
157
|
+
|
|
158
|
+
function render(vnode: ComponentChild, parent: Element | Document | ShadowRoot | DocumentFragment, replaceNode?: Element | Text): void;
|
|
159
|
+
function hydrate(vnode: ComponentChild, parent: Element | Document | ShadowRoot | DocumentFragment): void;
|
|
160
|
+
function cloneElement(vnode: VNode<any>, props?: any, ...children: ComponentChildren[]): VNode<any>;
|
|
161
|
+
function cloneElement<P>(vnode: VNode<P>, props?: any, ...children: ComponentChildren[]): VNode<P>;
|
|
162
|
+
|
|
163
|
+
//
|
|
164
|
+
// Preact Built-in Components
|
|
165
|
+
// -----------------------------------
|
|
166
|
+
|
|
167
|
+
// TODO: Revisit what the public type of this is...
|
|
168
|
+
const Fragment: ComponentClass<{}, {}>;
|
|
169
|
+
|
|
170
|
+
//
|
|
171
|
+
// Preact options
|
|
172
|
+
// -----------------------------------
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Global options for preact
|
|
176
|
+
*/
|
|
177
|
+
interface Options {
|
|
178
|
+
/** Attach a hook that is invoked whenever a VNode is created. */
|
|
179
|
+
vnode?(vnode: VNode): void;
|
|
180
|
+
/** Attach a hook that is invoked immediately before a vnode is unmounted. */
|
|
181
|
+
unmount?(vnode: VNode): void;
|
|
182
|
+
/** Attach a hook that is invoked after a vnode has rendered. */
|
|
183
|
+
diffed?(vnode: VNode): void;
|
|
184
|
+
event?(e: Event): any;
|
|
185
|
+
requestAnimationFrame?: typeof requestAnimationFrame;
|
|
186
|
+
debounceRendering?(cb: () => void): void;
|
|
187
|
+
useDebugValue?(value: string | number): void;
|
|
188
|
+
__suspenseDidResolve?(vnode: VNode, cb: () => void): void;
|
|
189
|
+
// __canSuspenseResolve?(vnode: VNode, cb: () => void): void;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const options: Options;
|
|
193
|
+
|
|
194
|
+
//
|
|
195
|
+
// Preact helpers
|
|
196
|
+
// -----------------------------------
|
|
197
|
+
function createRef<T = any>(): RefObject<T>;
|
|
198
|
+
function toChildArray(children: ComponentChildren): Array<VNode | string | number>;
|
|
199
|
+
function isValidElement(vnode: any): vnode is VNode;
|
|
200
|
+
|
|
201
|
+
//
|
|
202
|
+
// Context
|
|
203
|
+
// -----------------------------------
|
|
204
|
+
interface Consumer<T>
|
|
205
|
+
extends FunctionComponent<{
|
|
206
|
+
children: (value: T) => ComponentChildren;
|
|
207
|
+
}> {}
|
|
208
|
+
interface PreactConsumer<T> extends Consumer<T> {}
|
|
209
|
+
|
|
210
|
+
interface Provider<T>
|
|
211
|
+
extends FunctionComponent<{
|
|
212
|
+
value: T;
|
|
213
|
+
children: ComponentChildren;
|
|
214
|
+
}> {}
|
|
215
|
+
interface PreactProvider<T> extends Provider<T> {}
|
|
216
|
+
|
|
217
|
+
interface Context<T> {
|
|
218
|
+
Consumer: Consumer<T>;
|
|
219
|
+
Provider: Provider<T>;
|
|
220
|
+
}
|
|
221
|
+
interface PreactContext<T> extends Context<T> {}
|
|
222
|
+
|
|
223
|
+
function createContext<T>(defaultValue: T): Context<T>;
|
|
224
|
+
function useContext<T>(defaultValue: Context<T>);
|
|
225
|
+
}
|
|
226
|
+
type Inputs = ReadonlyArray<unknown>;
|
|
227
|
+
|
|
228
|
+
export type StateUpdater<S> = (value: S | ((prevState: S) => S)) => void;
|
|
229
|
+
/**
|
|
230
|
+
* Returns a stateful value, and a function to update it.
|
|
231
|
+
* @param initialState The initial value (or a function that returns the initial value)
|
|
232
|
+
*/
|
|
233
|
+
export function useState<S>(initialState: S | (() => S)): [S, StateUpdater<S>];
|
|
234
|
+
|
|
235
|
+
export type Reducer<S, A> = (prevState: S, action: A) => S;
|
|
236
|
+
/**
|
|
237
|
+
* An alternative to `useState`.
|
|
238
|
+
*
|
|
239
|
+
* `useReducer` is usually preferable to `useState` when you have complex state logic that involves
|
|
240
|
+
* multiple sub-values. It also lets you optimize performance for components that trigger deep
|
|
241
|
+
* updates because you can pass `dispatch` down instead of callbacks.
|
|
242
|
+
* @param reducer Given the current state and an action, returns the new state
|
|
243
|
+
* @param initialState The initial value to store as state
|
|
244
|
+
*/
|
|
245
|
+
export function useReducer<S, A>(reducer: Reducer<S, A>, initialState: S): [S, (action: A) => void];
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* An alternative to `useState`.
|
|
249
|
+
*
|
|
250
|
+
* `useReducer` is usually preferable to `useState` when you have complex state logic that involves
|
|
251
|
+
* multiple sub-values. It also lets you optimize performance for components that trigger deep
|
|
252
|
+
* updates because you can pass `dispatch` down instead of callbacks.
|
|
253
|
+
* @param reducer Given the current state and an action, returns the new state
|
|
254
|
+
* @param initialArg The initial argument to pass to the `init` function
|
|
255
|
+
* @param init A function that, given the `initialArg`, returns the initial value to store as state
|
|
256
|
+
*/
|
|
257
|
+
export function useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I, init: (arg: I) => S): [S, (action: A) => void];
|
|
258
|
+
|
|
259
|
+
type PropRef<T> = { current?: T };
|
|
260
|
+
type Ref<T> = { current: T };
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
|
|
264
|
+
* (`initialValue`). The returned object will persist for the full lifetime of the component.
|
|
265
|
+
*
|
|
266
|
+
* Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
|
|
267
|
+
* value around similar to how you’d use instance fields in classes.
|
|
268
|
+
*/
|
|
269
|
+
export function useRef<T>(initialValue: T | null): Ref<T>;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* `useRef` without an initial value is the special case handling `ref` props.
|
|
273
|
+
* If you want a non prop-based, mutable ref, you can explicitly give it an initial value of undefined/null/etc.
|
|
274
|
+
* You should explicitly set the type parameter for the expected ref value to either a DOM Element like `HTMLInputElement` or a `Component`
|
|
275
|
+
*/
|
|
276
|
+
export function useRef<T = unknown>(): PropRef<T>;
|
|
277
|
+
|
|
278
|
+
type EffectCallback = () => void | (() => void);
|
|
279
|
+
/**
|
|
280
|
+
* Accepts a function that contains imperative, possibly effectful code.
|
|
281
|
+
* The effects run after browser paint, without blocking it.
|
|
282
|
+
*
|
|
283
|
+
* @param effect Imperative function that can return a cleanup function
|
|
284
|
+
* @param inputs If present, effect will only activate if the values in the list change (using ===).
|
|
285
|
+
*/
|
|
286
|
+
export function useEffect(effect: EffectCallback, inputs?: Inputs): void;
|
|
287
|
+
|
|
288
|
+
type CreateHandle = () => object;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* @param ref The ref that will be mutated
|
|
292
|
+
* @param create The function that will be executed to get the value that will be attached to
|
|
293
|
+
* ref.current
|
|
294
|
+
* @param inputs If present, effect will only activate if the values in the list change (using ===).
|
|
295
|
+
*/
|
|
296
|
+
export function useImperativeHandle<T, R extends T>(ref: PreactRef<T>, create: () => R, inputs?: Inputs): void;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Accepts a function that contains imperative, possibly effectful code.
|
|
300
|
+
* Use this to read layout from the DOM and synchronously re-render.
|
|
301
|
+
* Updates scheduled inside `useLayoutEffect` will be flushed synchronously, after all DOM mutations but before the browser has a chance to paint.
|
|
302
|
+
* Prefer the standard `useEffect` hook when possible to avoid blocking visual updates.
|
|
303
|
+
*
|
|
304
|
+
* @param effect Imperative function that can return a cleanup function
|
|
305
|
+
* @param inputs If present, effect will only activate if the values in the list change (using ===).
|
|
306
|
+
*/
|
|
307
|
+
export function useLayoutEffect(effect: EffectCallback, inputs?: Inputs): void;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Returns a memoized version of the callback that only changes if one of the `inputs`
|
|
311
|
+
* has changed (using ===).
|
|
312
|
+
*/
|
|
313
|
+
export function useCallback<T extends Function>(callback: T, inputs: Inputs): T;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Pass a factory function and an array of inputs.
|
|
317
|
+
* useMemo will only recompute the memoized value when one of the inputs has changed.
|
|
318
|
+
* This optimization helps to avoid expensive calculations on every render.
|
|
319
|
+
* If no array is provided, a new value will be computed whenever a new function instance is passed as the first argument.
|
|
320
|
+
*/
|
|
321
|
+
// for `inputs`, allow undefined, but don't make it optional as that is very likely a mistake
|
|
322
|
+
export function useMemo<T>(factory: () => T, inputs: Inputs | undefined): T;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Returns the current context value, as given by the nearest context provider for the given context.
|
|
326
|
+
* When the provider updates, this Hook will trigger a rerender with the latest context value.
|
|
327
|
+
*
|
|
328
|
+
* @param context The context you want to use
|
|
329
|
+
*/
|
|
330
|
+
export function useContext<T>(context: PreactContext<T>): T;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Customize the displayed value in the devtools panel.
|
|
334
|
+
*
|
|
335
|
+
* @param value Custom hook name or object that is passed to formatter
|
|
336
|
+
* @param formatter Formatter to modify value before sending it to the devtools
|
|
337
|
+
*/
|
|
338
|
+
export function useDebugValue<T>(value: T, formatter?: (value: T) => string | number): void;
|
|
339
|
+
|
|
340
|
+
export function useErrorBoundary(callback?: (error: any) => Promise<void> | void): [any, () => void];
|