@hairy/react-lib 1.47.0 → 1.50.0
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/{LICENSE.md → LICENSE} +21 -21
- package/README.md +258 -36
- package/dist/index.cjs +412 -769
- package/dist/index.d.cts +258 -0
- package/dist/index.d.mts +258 -0
- package/dist/index.mjs +447 -0
- package/package.json +26 -21
- package/dist/index.d.ts +0 -374
- package/dist/index.global.js +0 -1550
- package/dist/index.js +0 -790
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { AnyFn, BooleanLike, Deferred, PromiseFn, PromiseType } from "@hairy/utils";
|
|
2
|
+
import * as react from "react";
|
|
3
|
+
import { ComponentClass, DetailedHTMLProps, FC, HTMLAttributes, JSX, PropsWithChildren, ReactElement, ReactNode, useCallback, useEffect, useInsertionEffect, useReducer, useRef, useState } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/cls.d.ts
|
|
6
|
+
type Value = string | boolean | undefined | null;
|
|
7
|
+
type Mapping = Record<string, any>;
|
|
8
|
+
interface ArgumentArray extends Array<Argument> {}
|
|
9
|
+
interface ReadonlyArgumentArray extends ReadonlyArray<Argument> {}
|
|
10
|
+
type Argument = Value | Mapping | ArgumentArray | ReadonlyArgumentArray;
|
|
11
|
+
/**
|
|
12
|
+
* A simple JavaScript utility for conditionally joining classNames together.
|
|
13
|
+
*/
|
|
14
|
+
declare function cls(...args: ArgumentArray): string;
|
|
15
|
+
declare namespace cls {
|
|
16
|
+
var parse: (arg: any) => string;
|
|
17
|
+
var append: (value: any, newClass: any) => any;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/utils/track.d.ts
|
|
21
|
+
/**
|
|
22
|
+
* @requires `Trigger` component to be mounted in the tree.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* // Obtain externally
|
|
27
|
+
* import { track } from '@hairy/lib-react'
|
|
28
|
+
* const context = await track(() => useContext(YourContext))
|
|
29
|
+
* console.log(context) // { ... }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function track<T extends AnyFn>(fn: T, ...args: Parameters<T>): Promise<ReturnType<T>>;
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/utils/wrapper.d.ts
|
|
35
|
+
type WrapperTag = keyof JSX.IntrinsicElements | Function;
|
|
36
|
+
type WrapperProps<As extends keyof JSX.IntrinsicElements | React.FC | unknown> = {
|
|
37
|
+
/** @deprecated use `as` instead */tag?: As;
|
|
38
|
+
as?: As;
|
|
39
|
+
} & (As extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[As] : unknown) & (As extends React.FC<infer P> ? P : unknown);
|
|
40
|
+
declare function wrapper(asChild: any, props: unknown, children?: React.ReactNode): react.ReactNode;
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/components/condition/Case.d.ts
|
|
43
|
+
type CaseProps<Kag> = WrapperProps<Kag> & {
|
|
44
|
+
cond?: BooleanLike;
|
|
45
|
+
children?: ReactNode;
|
|
46
|
+
};
|
|
47
|
+
declare function Case<Tag extends WrapperTag>(props: CaseProps<Tag>): ReactNode;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/components/condition/Default.d.ts
|
|
50
|
+
type DefaultProps<Tag> = WrapperProps<Tag> & {
|
|
51
|
+
children?: ReactNode;
|
|
52
|
+
};
|
|
53
|
+
declare function Default<Tag extends WrapperTag>(props: DefaultProps<Tag>): ReactNode;
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/components/condition/If.d.ts
|
|
56
|
+
type IfProps<Kag> = WrapperProps<Kag> & {
|
|
57
|
+
cond?: BooleanLike;
|
|
58
|
+
then?: ReactNode;
|
|
59
|
+
else?: ReactNode;
|
|
60
|
+
children?: ReactNode;
|
|
61
|
+
};
|
|
62
|
+
declare function If<K extends WrapperTag>(props: IfProps<K>): ReactNode;
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/components/condition/Else.d.ts
|
|
65
|
+
type ElseProps<Tag> = IfProps<Tag>;
|
|
66
|
+
declare function Else<Tag extends WrapperTag>(props: ElseProps<Tag>): react.ReactNode;
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/components/condition/Switch.d.ts
|
|
69
|
+
interface SwitchProps extends PropsWithChildren {
|
|
70
|
+
value?: BooleanLike;
|
|
71
|
+
}
|
|
72
|
+
declare function Switch(props: SwitchProps): ReactElement<unknown, string | react.JSXElementConstructor<any>> | null;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/components/condition/Then.d.ts
|
|
75
|
+
type ThenProps<Tag> = IfProps<Tag>;
|
|
76
|
+
declare function Then<Tag extends WrapperTag>(props: ThenProps<Tag>): react.ReactNode;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/components/condition/Unless.d.ts
|
|
79
|
+
type UnlessProps<Tag> = WrapperProps<Tag> & {
|
|
80
|
+
cond?: BooleanLike;
|
|
81
|
+
then?: ReactNode;
|
|
82
|
+
else?: ReactNode;
|
|
83
|
+
children?: ReactNode;
|
|
84
|
+
};
|
|
85
|
+
declare function Unless<Tag extends WrapperTag>(props: UnlessProps<Tag>): ReactNode;
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/components/utils/Injector.d.ts
|
|
88
|
+
interface InjectComponent<P> {
|
|
89
|
+
component: FC<P> | ComponentClass<P>;
|
|
90
|
+
props?: P;
|
|
91
|
+
}
|
|
92
|
+
interface InjectorProps {
|
|
93
|
+
install: (FC<any> | InjectComponent<any> | ComponentClass<any>)[];
|
|
94
|
+
children?: ReactNode;
|
|
95
|
+
}
|
|
96
|
+
declare function Injector(props: InjectorProps): ReactNode;
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/components/utils/Trigger.d.ts
|
|
99
|
+
interface Exposer {
|
|
100
|
+
deferred: Deferred<any>;
|
|
101
|
+
args: any[];
|
|
102
|
+
fn: AnyFn;
|
|
103
|
+
id: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @example
|
|
107
|
+
* ```tsx
|
|
108
|
+
* import { Trigger } from '@hairy/lib-react'
|
|
109
|
+
*
|
|
110
|
+
* // Use triggers to capture context
|
|
111
|
+
* function App() {
|
|
112
|
+
* return (
|
|
113
|
+
* <YourContext.Provider>
|
|
114
|
+
* <Trigger />
|
|
115
|
+
* </YourContext.Provider>
|
|
116
|
+
* )
|
|
117
|
+
* }
|
|
118
|
+
*
|
|
119
|
+
* // Obtain externally
|
|
120
|
+
* import { track } from '@hairy/lib-react'
|
|
121
|
+
* const context = await track(() => useContext(YourContext))
|
|
122
|
+
* console.log(context) // { ... }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function Trigger(): ReactNode[];
|
|
126
|
+
declare namespace Trigger {
|
|
127
|
+
var id: number;
|
|
128
|
+
var tasks: Map<number, Exposer> & {
|
|
129
|
+
$$valtioSnapshot: Omit<Map<number, Exposer>, "set" | "delete" | "clear">;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/hooks/tryUseCallback.d.ts
|
|
134
|
+
declare const tryUseCallback: typeof useCallback;
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/hooks/tryUseEffect.d.ts
|
|
137
|
+
declare const tryUseEffect: typeof useEffect;
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/hooks/tryUseInsertionEffect.d.ts
|
|
140
|
+
declare const tryUseInsertionEffect: typeof useInsertionEffect;
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/hooks/tryUseReducer.d.ts
|
|
143
|
+
declare const tryUseReducer: typeof useReducer;
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/hooks/tryUseRef.d.ts
|
|
146
|
+
declare const tryUseRef: typeof useRef;
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/hooks/tryUseState.d.ts
|
|
149
|
+
declare const tryUseState: typeof useState;
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/hooks/tryUseUpdate.d.ts
|
|
152
|
+
declare function tryUseUpdate(): () => void;
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/hooks/useAsyncCallback.d.ts
|
|
155
|
+
declare function useAsyncCallback<T extends PromiseFn>(fun: T): readonly [boolean, T, Error | undefined];
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/hooks/types/index.d.ts
|
|
158
|
+
type AsyncState<T> = {
|
|
159
|
+
loading: boolean;
|
|
160
|
+
error?: undefined;
|
|
161
|
+
value?: undefined;
|
|
162
|
+
} | {
|
|
163
|
+
loading: true;
|
|
164
|
+
error?: Error | undefined;
|
|
165
|
+
value?: T;
|
|
166
|
+
} | {
|
|
167
|
+
loading: false;
|
|
168
|
+
error: Error;
|
|
169
|
+
value?: undefined;
|
|
170
|
+
} | {
|
|
171
|
+
loading: false;
|
|
172
|
+
error?: undefined;
|
|
173
|
+
value: T;
|
|
174
|
+
};
|
|
175
|
+
type StateFromFnReturningPromise<T extends PromiseFn = PromiseFn> = AsyncState<PromiseType<ReturnType<T>>>;
|
|
176
|
+
declare type AsyncStateReturn<T extends PromiseFn = PromiseFn> = [StateFromFnReturningPromise<T>, T];
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/hooks/useAsyncState.d.ts
|
|
179
|
+
type UseAsyncStateOptions<T extends AnyFn> = {
|
|
180
|
+
immediate?: boolean;
|
|
181
|
+
initial?: PromiseType<ReturnType<T>>;
|
|
182
|
+
deps?: any[];
|
|
183
|
+
} | {
|
|
184
|
+
immediate?: boolean;
|
|
185
|
+
initial: PromiseType<ReturnType<T>>;
|
|
186
|
+
deps?: any[];
|
|
187
|
+
};
|
|
188
|
+
declare function useAsyncState<T extends PromiseFn>(fun: T, deps?: any[], options?: UseAsyncStateOptions<T>): AsyncStateReturn<T>;
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/hooks/useDebounce.d.ts
|
|
191
|
+
declare function useDebounce<T>(value: T, delay: number): T;
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/hooks/useEventBus.d.ts
|
|
194
|
+
interface EventBusListener<T = any> {
|
|
195
|
+
(event: T): void;
|
|
196
|
+
}
|
|
197
|
+
declare function useEventBus<T>(key: string): {
|
|
198
|
+
on: (listener: EventBusListener<T>) => void;
|
|
199
|
+
emit: (event?: T) => void;
|
|
200
|
+
off: (listener: EventBusListener) => void;
|
|
201
|
+
};
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/hooks/useFetchIntercept.d.ts
|
|
204
|
+
interface FetchResponseInterceptCallback {
|
|
205
|
+
(response: Response, init: RequestInit | undefined): Response | Promise<Response>;
|
|
206
|
+
}
|
|
207
|
+
interface FetchRequestInterceptCallback {
|
|
208
|
+
(fetch: typeof window.fetch, input: RequestInfo | URL, init?: RequestInit | undefined): Response | Promise<Response>;
|
|
209
|
+
}
|
|
210
|
+
declare function useFetchResponseIntercept(intercept: FetchResponseInterceptCallback): void;
|
|
211
|
+
declare function useFetchRequestIntercept(intercept: FetchRequestInterceptCallback): void;
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/hooks/useMounted.d.ts
|
|
214
|
+
declare function useMounted(): boolean;
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/hooks/useOffsetPagination.d.ts
|
|
217
|
+
interface UseOffsetPaginationOptions {
|
|
218
|
+
total?: number;
|
|
219
|
+
page?: number;
|
|
220
|
+
pageSize?: number;
|
|
221
|
+
onChange?: (pagination: Pagination) => void;
|
|
222
|
+
onPageSizeChange?: (pagination: Pagination) => void;
|
|
223
|
+
onPageCountChange?: (pagination: Pagination) => void;
|
|
224
|
+
}
|
|
225
|
+
interface Pagination {
|
|
226
|
+
pageSizeChange: (limit: number) => void;
|
|
227
|
+
pageChange: (page: number) => void;
|
|
228
|
+
next: () => void;
|
|
229
|
+
prev: () => void;
|
|
230
|
+
page: number;
|
|
231
|
+
pageSize: number;
|
|
232
|
+
isFirstPage: boolean;
|
|
233
|
+
isLastPage: boolean;
|
|
234
|
+
pageCount: number;
|
|
235
|
+
total: number;
|
|
236
|
+
}
|
|
237
|
+
declare function useOffsetPagination(options: UseOffsetPaginationOptions): Pagination;
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/hooks/useUpdate.d.ts
|
|
240
|
+
declare function useUpdate(): () => void;
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/hooks/useWatch.d.ts
|
|
243
|
+
interface UseWatchCallback<T = any> {
|
|
244
|
+
(value: T, oldValue: T): void;
|
|
245
|
+
}
|
|
246
|
+
interface UseWatchOptions {
|
|
247
|
+
immediate?: boolean;
|
|
248
|
+
}
|
|
249
|
+
declare function useWatch<T extends any[]>(source: readonly [...T], callback: UseWatchCallback<[...T]>, options?: UseWatchOptions): void;
|
|
250
|
+
declare function useWatch<T>(source: T, callback: UseWatchCallback<T>, options?: UseWatchOptions): void;
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/hooks/useWhenever.d.ts
|
|
253
|
+
declare function useWhenever<T>(source: T, cb: UseWatchCallback<Exclude<T, null | undefined>>, options?: UseWatchOptions): void;
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/types/index.d.ts
|
|
256
|
+
type PropsWithDetailedHTML<T = HTMLDivElement> = DetailedHTMLProps<HTMLAttributes<T>, T>;
|
|
257
|
+
//#endregion
|
|
258
|
+
export { Argument, ArgumentArray, Case, CaseProps, Default, DefaultProps, Else, ElseProps, EventBusListener, Exposer, FetchRequestInterceptCallback, FetchResponseInterceptCallback, If, IfProps, InjectComponent, Injector, InjectorProps, Mapping, Pagination, PropsWithDetailedHTML, ReadonlyArgumentArray, Switch, SwitchProps, Then, ThenProps, Trigger, Unless, UnlessProps, UseAsyncStateOptions, UseOffsetPaginationOptions, UseWatchCallback, UseWatchOptions, Value, WrapperProps, WrapperTag, cls, track, tryUseCallback, tryUseEffect, tryUseInsertionEffect, tryUseReducer, tryUseRef, tryUseState, tryUseUpdate, useAsyncCallback, useAsyncState, useDebounce, useEventBus, useFetchRequestIntercept, useFetchResponseIntercept, useMounted, useOffsetPagination, useUpdate, useWatch, useWhenever, wrapper };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { AnyFn, BooleanLike, Deferred, PromiseFn, PromiseType } from "@hairy/utils";
|
|
2
|
+
import * as react from "react";
|
|
3
|
+
import { ComponentClass, DetailedHTMLProps, FC, HTMLAttributes, JSX, PropsWithChildren, ReactElement, ReactNode, useCallback, useEffect, useInsertionEffect, useReducer, useRef, useState } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/cls.d.ts
|
|
6
|
+
type Value = string | boolean | undefined | null;
|
|
7
|
+
type Mapping = Record<string, any>;
|
|
8
|
+
interface ArgumentArray extends Array<Argument> {}
|
|
9
|
+
interface ReadonlyArgumentArray extends ReadonlyArray<Argument> {}
|
|
10
|
+
type Argument = Value | Mapping | ArgumentArray | ReadonlyArgumentArray;
|
|
11
|
+
/**
|
|
12
|
+
* A simple JavaScript utility for conditionally joining classNames together.
|
|
13
|
+
*/
|
|
14
|
+
declare function cls(...args: ArgumentArray): string;
|
|
15
|
+
declare namespace cls {
|
|
16
|
+
var parse: (arg: any) => string;
|
|
17
|
+
var append: (value: any, newClass: any) => any;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/utils/track.d.ts
|
|
21
|
+
/**
|
|
22
|
+
* @requires `Trigger` component to be mounted in the tree.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* // Obtain externally
|
|
27
|
+
* import { track } from '@hairy/lib-react'
|
|
28
|
+
* const context = await track(() => useContext(YourContext))
|
|
29
|
+
* console.log(context) // { ... }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function track<T extends AnyFn>(fn: T, ...args: Parameters<T>): Promise<ReturnType<T>>;
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/utils/wrapper.d.ts
|
|
35
|
+
type WrapperTag = keyof JSX.IntrinsicElements | Function;
|
|
36
|
+
type WrapperProps<As extends keyof JSX.IntrinsicElements | React.FC | unknown> = {
|
|
37
|
+
/** @deprecated use `as` instead */tag?: As;
|
|
38
|
+
as?: As;
|
|
39
|
+
} & (As extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[As] : unknown) & (As extends React.FC<infer P> ? P : unknown);
|
|
40
|
+
declare function wrapper(asChild: any, props: unknown, children?: React.ReactNode): react.ReactNode;
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/components/condition/Case.d.ts
|
|
43
|
+
type CaseProps<Kag> = WrapperProps<Kag> & {
|
|
44
|
+
cond?: BooleanLike;
|
|
45
|
+
children?: ReactNode;
|
|
46
|
+
};
|
|
47
|
+
declare function Case<Tag extends WrapperTag>(props: CaseProps<Tag>): ReactNode;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/components/condition/Default.d.ts
|
|
50
|
+
type DefaultProps<Tag> = WrapperProps<Tag> & {
|
|
51
|
+
children?: ReactNode;
|
|
52
|
+
};
|
|
53
|
+
declare function Default<Tag extends WrapperTag>(props: DefaultProps<Tag>): ReactNode;
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/components/condition/If.d.ts
|
|
56
|
+
type IfProps<Kag> = WrapperProps<Kag> & {
|
|
57
|
+
cond?: BooleanLike;
|
|
58
|
+
then?: ReactNode;
|
|
59
|
+
else?: ReactNode;
|
|
60
|
+
children?: ReactNode;
|
|
61
|
+
};
|
|
62
|
+
declare function If<K extends WrapperTag>(props: IfProps<K>): ReactNode;
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/components/condition/Else.d.ts
|
|
65
|
+
type ElseProps<Tag> = IfProps<Tag>;
|
|
66
|
+
declare function Else<Tag extends WrapperTag>(props: ElseProps<Tag>): react.ReactNode;
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/components/condition/Switch.d.ts
|
|
69
|
+
interface SwitchProps extends PropsWithChildren {
|
|
70
|
+
value?: BooleanLike;
|
|
71
|
+
}
|
|
72
|
+
declare function Switch(props: SwitchProps): ReactElement<unknown, string | react.JSXElementConstructor<any>> | null;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/components/condition/Then.d.ts
|
|
75
|
+
type ThenProps<Tag> = IfProps<Tag>;
|
|
76
|
+
declare function Then<Tag extends WrapperTag>(props: ThenProps<Tag>): react.ReactNode;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/components/condition/Unless.d.ts
|
|
79
|
+
type UnlessProps<Tag> = WrapperProps<Tag> & {
|
|
80
|
+
cond?: BooleanLike;
|
|
81
|
+
then?: ReactNode;
|
|
82
|
+
else?: ReactNode;
|
|
83
|
+
children?: ReactNode;
|
|
84
|
+
};
|
|
85
|
+
declare function Unless<Tag extends WrapperTag>(props: UnlessProps<Tag>): ReactNode;
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/components/utils/Injector.d.ts
|
|
88
|
+
interface InjectComponent<P> {
|
|
89
|
+
component: FC<P> | ComponentClass<P>;
|
|
90
|
+
props?: P;
|
|
91
|
+
}
|
|
92
|
+
interface InjectorProps {
|
|
93
|
+
install: (FC<any> | InjectComponent<any> | ComponentClass<any>)[];
|
|
94
|
+
children?: ReactNode;
|
|
95
|
+
}
|
|
96
|
+
declare function Injector(props: InjectorProps): ReactNode;
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/components/utils/Trigger.d.ts
|
|
99
|
+
interface Exposer {
|
|
100
|
+
deferred: Deferred<any>;
|
|
101
|
+
args: any[];
|
|
102
|
+
fn: AnyFn;
|
|
103
|
+
id: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @example
|
|
107
|
+
* ```tsx
|
|
108
|
+
* import { Trigger } from '@hairy/lib-react'
|
|
109
|
+
*
|
|
110
|
+
* // Use triggers to capture context
|
|
111
|
+
* function App() {
|
|
112
|
+
* return (
|
|
113
|
+
* <YourContext.Provider>
|
|
114
|
+
* <Trigger />
|
|
115
|
+
* </YourContext.Provider>
|
|
116
|
+
* )
|
|
117
|
+
* }
|
|
118
|
+
*
|
|
119
|
+
* // Obtain externally
|
|
120
|
+
* import { track } from '@hairy/lib-react'
|
|
121
|
+
* const context = await track(() => useContext(YourContext))
|
|
122
|
+
* console.log(context) // { ... }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function Trigger(): ReactNode[];
|
|
126
|
+
declare namespace Trigger {
|
|
127
|
+
var id: number;
|
|
128
|
+
var tasks: Map<number, Exposer> & {
|
|
129
|
+
$$valtioSnapshot: Omit<Map<number, Exposer>, "set" | "delete" | "clear">;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/hooks/tryUseCallback.d.ts
|
|
134
|
+
declare const tryUseCallback: typeof useCallback;
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/hooks/tryUseEffect.d.ts
|
|
137
|
+
declare const tryUseEffect: typeof useEffect;
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/hooks/tryUseInsertionEffect.d.ts
|
|
140
|
+
declare const tryUseInsertionEffect: typeof useInsertionEffect;
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/hooks/tryUseReducer.d.ts
|
|
143
|
+
declare const tryUseReducer: typeof useReducer;
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/hooks/tryUseRef.d.ts
|
|
146
|
+
declare const tryUseRef: typeof useRef;
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/hooks/tryUseState.d.ts
|
|
149
|
+
declare const tryUseState: typeof useState;
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/hooks/tryUseUpdate.d.ts
|
|
152
|
+
declare function tryUseUpdate(): () => void;
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/hooks/useAsyncCallback.d.ts
|
|
155
|
+
declare function useAsyncCallback<T extends PromiseFn>(fun: T): readonly [boolean, T, Error | undefined];
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/hooks/types/index.d.ts
|
|
158
|
+
type AsyncState<T> = {
|
|
159
|
+
loading: boolean;
|
|
160
|
+
error?: undefined;
|
|
161
|
+
value?: undefined;
|
|
162
|
+
} | {
|
|
163
|
+
loading: true;
|
|
164
|
+
error?: Error | undefined;
|
|
165
|
+
value?: T;
|
|
166
|
+
} | {
|
|
167
|
+
loading: false;
|
|
168
|
+
error: Error;
|
|
169
|
+
value?: undefined;
|
|
170
|
+
} | {
|
|
171
|
+
loading: false;
|
|
172
|
+
error?: undefined;
|
|
173
|
+
value: T;
|
|
174
|
+
};
|
|
175
|
+
type StateFromFnReturningPromise<T extends PromiseFn = PromiseFn> = AsyncState<PromiseType<ReturnType<T>>>;
|
|
176
|
+
declare type AsyncStateReturn<T extends PromiseFn = PromiseFn> = [StateFromFnReturningPromise<T>, T];
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/hooks/useAsyncState.d.ts
|
|
179
|
+
type UseAsyncStateOptions<T extends AnyFn> = {
|
|
180
|
+
immediate?: boolean;
|
|
181
|
+
initial?: PromiseType<ReturnType<T>>;
|
|
182
|
+
deps?: any[];
|
|
183
|
+
} | {
|
|
184
|
+
immediate?: boolean;
|
|
185
|
+
initial: PromiseType<ReturnType<T>>;
|
|
186
|
+
deps?: any[];
|
|
187
|
+
};
|
|
188
|
+
declare function useAsyncState<T extends PromiseFn>(fun: T, deps?: any[], options?: UseAsyncStateOptions<T>): AsyncStateReturn<T>;
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/hooks/useDebounce.d.ts
|
|
191
|
+
declare function useDebounce<T>(value: T, delay: number): T;
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/hooks/useEventBus.d.ts
|
|
194
|
+
interface EventBusListener<T = any> {
|
|
195
|
+
(event: T): void;
|
|
196
|
+
}
|
|
197
|
+
declare function useEventBus<T>(key: string): {
|
|
198
|
+
on: (listener: EventBusListener<T>) => void;
|
|
199
|
+
emit: (event?: T) => void;
|
|
200
|
+
off: (listener: EventBusListener) => void;
|
|
201
|
+
};
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/hooks/useFetchIntercept.d.ts
|
|
204
|
+
interface FetchResponseInterceptCallback {
|
|
205
|
+
(response: Response, init: RequestInit | undefined): Response | Promise<Response>;
|
|
206
|
+
}
|
|
207
|
+
interface FetchRequestInterceptCallback {
|
|
208
|
+
(fetch: typeof window.fetch, input: RequestInfo | URL, init?: RequestInit | undefined): Response | Promise<Response>;
|
|
209
|
+
}
|
|
210
|
+
declare function useFetchResponseIntercept(intercept: FetchResponseInterceptCallback): void;
|
|
211
|
+
declare function useFetchRequestIntercept(intercept: FetchRequestInterceptCallback): void;
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/hooks/useMounted.d.ts
|
|
214
|
+
declare function useMounted(): boolean;
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/hooks/useOffsetPagination.d.ts
|
|
217
|
+
interface UseOffsetPaginationOptions {
|
|
218
|
+
total?: number;
|
|
219
|
+
page?: number;
|
|
220
|
+
pageSize?: number;
|
|
221
|
+
onChange?: (pagination: Pagination) => void;
|
|
222
|
+
onPageSizeChange?: (pagination: Pagination) => void;
|
|
223
|
+
onPageCountChange?: (pagination: Pagination) => void;
|
|
224
|
+
}
|
|
225
|
+
interface Pagination {
|
|
226
|
+
pageSizeChange: (limit: number) => void;
|
|
227
|
+
pageChange: (page: number) => void;
|
|
228
|
+
next: () => void;
|
|
229
|
+
prev: () => void;
|
|
230
|
+
page: number;
|
|
231
|
+
pageSize: number;
|
|
232
|
+
isFirstPage: boolean;
|
|
233
|
+
isLastPage: boolean;
|
|
234
|
+
pageCount: number;
|
|
235
|
+
total: number;
|
|
236
|
+
}
|
|
237
|
+
declare function useOffsetPagination(options: UseOffsetPaginationOptions): Pagination;
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/hooks/useUpdate.d.ts
|
|
240
|
+
declare function useUpdate(): () => void;
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/hooks/useWatch.d.ts
|
|
243
|
+
interface UseWatchCallback<T = any> {
|
|
244
|
+
(value: T, oldValue: T): void;
|
|
245
|
+
}
|
|
246
|
+
interface UseWatchOptions {
|
|
247
|
+
immediate?: boolean;
|
|
248
|
+
}
|
|
249
|
+
declare function useWatch<T extends any[]>(source: readonly [...T], callback: UseWatchCallback<[...T]>, options?: UseWatchOptions): void;
|
|
250
|
+
declare function useWatch<T>(source: T, callback: UseWatchCallback<T>, options?: UseWatchOptions): void;
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/hooks/useWhenever.d.ts
|
|
253
|
+
declare function useWhenever<T>(source: T, cb: UseWatchCallback<Exclude<T, null | undefined>>, options?: UseWatchOptions): void;
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/types/index.d.ts
|
|
256
|
+
type PropsWithDetailedHTML<T = HTMLDivElement> = DetailedHTMLProps<HTMLAttributes<T>, T>;
|
|
257
|
+
//#endregion
|
|
258
|
+
export { Argument, ArgumentArray, Case, CaseProps, Default, DefaultProps, Else, ElseProps, EventBusListener, Exposer, FetchRequestInterceptCallback, FetchResponseInterceptCallback, If, IfProps, InjectComponent, Injector, InjectorProps, Mapping, Pagination, PropsWithDetailedHTML, ReadonlyArgumentArray, Switch, SwitchProps, Then, ThenProps, Trigger, Unless, UnlessProps, UseAsyncStateOptions, UseOffsetPaginationOptions, UseWatchCallback, UseWatchOptions, Value, WrapperProps, WrapperTag, cls, track, tryUseCallback, tryUseEffect, tryUseInsertionEffect, tryUseReducer, tryUseRef, tryUseState, tryUseUpdate, useAsyncCallback, useAsyncState, useDebounce, useEventBus, useFetchRequestIntercept, useFetchResponseIntercept, useMounted, useOffsetPagination, useUpdate, useWatch, useWhenever, wrapper };
|