@hairy/react-lib 1.1.2 → 1.6.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.
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019-PRESENT Hairyf<https://github.com/hairyf>
3
+ Copyright (c) 2025-PRESENT Hairyf <https://github.com/antfu>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -19,5 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
-
23
-
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @hairy/react-lib
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![bundle][bundle-src]][bundle-href]
6
+ [![JSDocs][jsdocs-src]][jsdocs-href]
7
+ [![License][license-src]][license-href]
8
+
9
+ ## Install
10
+
11
+ ```
12
+ ni @hairy/react-lib
13
+ ```
14
+
15
+ ## CDN
16
+
17
+ ```html
18
+ <script src="https://unpkg.com/@hairy/react-lib"></script>
19
+ ```
20
+
21
+ ## License
22
+
23
+ [MIT](./LICENSE) License © [Hairyf](https://github.com/hairyf)
24
+
25
+ <!-- Badges -->
26
+
27
+ [npm-version-src]: https://img.shields.io/npm/v/@hairy/react-lib?style=flat&colorA=080f12&colorB=1fa669
28
+ [npm-version-href]: https://npmjs.com/package/@hairy/react-lib
29
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@hairy/react-lib?style=flat&colorA=080f12&colorB=1fa669
30
+ [npm-downloads-href]: https://npmjs.com/package/@hairy/react-lib
31
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/@hairy/react-lib?style=flat&colorA=080f12&colorB=1fa669&label=minzip
32
+ [bundle-href]: https://bundlephobia.com/result?p=@hairy/react-lib
33
+ [license-src]: https://img.shields.io/github/license/hairyf/hairylib.svg?style=flat&colorA=080f12&colorB=1fa669
34
+ [license-href]: https://github.com/hairyf/hairylib/blob/main/LICENSE
35
+ [jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
36
+ [jsdocs-href]: https://www.jsdocs.io/package/@hairy/react-lib
package/dist/index.cjs CHANGED
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  Case: () => Case,
34
34
  Default: () => Default,
35
35
  Else: () => Else,
@@ -40,11 +40,6 @@ __export(src_exports, {
40
40
  Trans: () => Trans,
41
41
  Unless: () => Unless,
42
42
  cls: () => cls,
43
- defineAsyncStorage: () => defineAsyncStorage,
44
- defineStore: () => defineStore,
45
- proxyWithPersistant: () => proxyWithPersistant,
46
- storeToState: () => storeToState,
47
- storeToStates: () => storeToStates,
48
43
  useAsyncCallback: () => useAsyncCallback,
49
44
  useAsyncState: () => useAsyncState,
50
45
  useDebounce: () => useDebounce,
@@ -52,11 +47,10 @@ __export(src_exports, {
52
47
  useFetchRequestIntercept: () => useFetchRequestIntercept,
53
48
  useFetchResponseIntercept: () => useFetchResponseIntercept,
54
49
  useMounted: () => useMounted,
55
- useStore: () => useStore,
56
50
  useWatch: () => useWatch,
57
51
  useWhenever: () => useWhenever
58
52
  });
59
- module.exports = __toCommonJS(src_exports);
53
+ module.exports = __toCommonJS(index_exports);
60
54
 
61
55
  // src/components/condition/Case.ts
62
56
  function Case(props) {
@@ -93,7 +87,6 @@ function If(props) {
93
87
  // src/components/condition/Switch.ts
94
88
  var import_react2 = require("react");
95
89
  function Switch(props) {
96
- var _a;
97
90
  const isUseValue = props.value !== void 0;
98
91
  let matchingCase;
99
92
  let defaultCase;
@@ -110,7 +103,7 @@ function Switch(props) {
110
103
  if (!defaultCase && child.type === Default)
111
104
  defaultCase = child;
112
105
  });
113
- return (_a = matchingCase != null ? matchingCase : defaultCase) != null ? _a : null;
106
+ return matchingCase ?? defaultCase ?? null;
114
107
  }
115
108
 
116
109
  // src/components/condition/Unless.ts
@@ -140,15 +133,15 @@ function repack(c) {
140
133
  }
141
134
 
142
135
  // src/components/utils/Trans.ts
143
- var import_react_i18next = require("react-i18next");
136
+ var import_html_parse_stringify = __toESM(require("html-parse-stringify"), 1);
144
137
  var import_react5 = require("react");
145
- var import_html_parse_stringify = __toESM(require("html-parse-stringify"));
138
+ var import_react_i18next = require("react-i18next");
146
139
  function Trans({ i18nKey, ...additionalProps }) {
147
140
  const translation = (0, import_react_i18next.useTranslation)().t(i18nKey, additionalProps);
148
141
  return renderNodes(import_html_parse_stringify.default.parse(translation), additionalProps);
149
142
  }
150
- var index = 0;
151
143
  function renderNodes(tokens, values) {
144
+ let index = 0;
152
145
  return tokens.map((token) => {
153
146
  if (token.type === "text")
154
147
  return token.content;
@@ -158,11 +151,39 @@ function renderNodes(tokens, values) {
158
151
  });
159
152
  }
160
153
 
161
- // src/hooks/useDebounce.ts
154
+ // src/hooks/useAsyncCallback.ts
162
155
  var import_react6 = require("react");
156
+ function useAsyncCallback(fun) {
157
+ const [error, setError] = (0, import_react6.useState)();
158
+ const [loading, setLoading] = (0, import_react6.useState)(false);
159
+ async function execute(...args) {
160
+ try {
161
+ setLoading(true);
162
+ const result = await fun(...args);
163
+ setLoading(false);
164
+ return result;
165
+ } catch (error2) {
166
+ setLoading(false);
167
+ setError(error2);
168
+ throw error2;
169
+ }
170
+ }
171
+ return [loading, execute, error];
172
+ }
173
+
174
+ // src/hooks/useAsyncState.ts
175
+ var import_react_use = require("react-use");
176
+ function useAsyncState(fn, deps, options) {
177
+ const [state, _fn] = (0, import_react_use.useAsyncFn)(fn, deps, options?.initial);
178
+ (0, import_react_use.useMount)(() => options?.immediate && _fn());
179
+ return [state, _fn];
180
+ }
181
+
182
+ // src/hooks/useDebounce.ts
183
+ var import_react7 = require("react");
163
184
  function useDebounce(value, delay) {
164
- const [debouncedValue, setDebouncedValue] = (0, import_react6.useState)(value);
165
- (0, import_react6.useEffect)(() => {
185
+ const [debouncedValue, setDebouncedValue] = (0, import_react7.useState)(value);
186
+ (0, import_react7.useEffect)(() => {
166
187
  const handler = setTimeout(() => setDebouncedValue(value), delay);
167
188
  return () => clearTimeout(handler);
168
189
  }, [value, delay]);
@@ -170,15 +191,15 @@ function useDebounce(value, delay) {
170
191
  }
171
192
 
172
193
  // src/hooks/useEventBus.ts
173
- var import_react7 = require("react");
174
- var import_mitt = __toESM(require("mitt"));
194
+ var import_mitt = __toESM(require("mitt"), 1);
195
+ var import_react8 = require("react");
175
196
  var emitter = (0, import_mitt.default)();
176
197
  function useEventBus(key) {
177
- const onRef = (0, import_react7.useRef)();
198
+ const onRef = (0, import_react8.useRef)();
178
199
  function on(listener) {
179
200
  emitter.on(key, listener);
180
201
  onRef.current = listener;
181
- (0, import_react7.useEffect)(() => {
202
+ (0, import_react8.useEffect)(() => {
182
203
  if (!onRef.current)
183
204
  return;
184
205
  emitter.off(key, onRef.current);
@@ -200,72 +221,6 @@ function useEventBus(key) {
200
221
  };
201
222
  }
202
223
 
203
- // src/hooks/useMounted.ts
204
- var import_react8 = require("react");
205
- function useMounted() {
206
- const [mounted, setMounted] = (0, import_react8.useState)(false);
207
- (0, import_react8.useEffect)(() => setMounted(true), []);
208
- return mounted;
209
- }
210
-
211
- // src/hooks/useWatch.ts
212
- var import_react9 = require("react");
213
- function useWatch(source, callback, options = {}) {
214
- const firstUpdate = (0, import_react9.useRef)(false);
215
- const then = (0, import_react9.useRef)();
216
- const deps = (0, import_react9.useMemo)(
217
- () => Array.isArray(source) ? source : [source],
218
- [source]
219
- );
220
- (0, import_react9.useEffect)(() => {
221
- if (!firstUpdate.current)
222
- recordFirst();
223
- else
224
- callback(source);
225
- }, deps);
226
- async function recordFirst() {
227
- if (then.current)
228
- return;
229
- then.current = Promise.resolve(source);
230
- then.current.then(() => firstUpdate.current = true);
231
- if (options.immediate)
232
- then.current.then((value) => callback(value));
233
- }
234
- }
235
-
236
- // src/hooks/useWhenever.ts
237
- function useWhenever(source, cb, options) {
238
- useWatch(source, () => source && cb(source), options);
239
- }
240
-
241
- // src/hooks/useAsyncCallback.ts
242
- var import_react10 = require("react");
243
- function useAsyncCallback(fun) {
244
- const [error, setError] = (0, import_react10.useState)();
245
- const [loading, setLoading] = (0, import_react10.useState)(false);
246
- async function execute(...args) {
247
- try {
248
- setLoading(true);
249
- const result = await fun(...args);
250
- setLoading(false);
251
- return result;
252
- } catch (error2) {
253
- setLoading(false);
254
- setError(error2);
255
- throw error2;
256
- }
257
- }
258
- return [loading, execute, error];
259
- }
260
-
261
- // src/hooks/useAsyncState.ts
262
- var import_react_use = require("react-use");
263
- function useAsyncState(fn, deps, options) {
264
- const [state, _fn] = (0, import_react_use.useAsyncFn)(fn, deps, options == null ? void 0 : options.initial);
265
- (0, import_react_use.useMount)(() => (options == null ? void 0 : options.immediate) && _fn());
266
- return [state, _fn];
267
- }
268
-
269
224
  // src/hooks/useFetchIntercept.ts
270
225
  var import_react_use2 = require("react-use");
271
226
  function useFetchResponseIntercept(intercept) {
@@ -290,102 +245,42 @@ function fetchRequestIntercept(intercept) {
290
245
  };
291
246
  }
292
247
 
293
- // src/storage/storeToState.ts
294
- var import_valtio = require("valtio");
295
- function storeToState(store, key) {
296
- const snapshot = (0, import_valtio.useSnapshot)(store);
297
- function get() {
298
- return snapshot[key];
299
- }
300
- function set(value) {
301
- store[key] = value;
302
- }
303
- return [get(), set];
304
- }
305
-
306
- // src/storage/proxyWithPersistant.ts
307
- var import_valtio2 = require("valtio");
308
- function proxyWithPersistant(key, initialObject, options = {}) {
309
- const storage = options.storage || (typeof localStorage !== "undefined" ? localStorage : void 0);
310
- const state = (0, import_valtio2.proxy)(parse(storage == null ? void 0 : storage.getItem(key)) || initialObject);
311
- (0, import_valtio2.subscribe)(state, () => {
312
- storage == null ? void 0 : storage.setItem(key, JSON.stringify(state));
313
- });
314
- return state;
315
- }
316
- function parse(text) {
317
- try {
318
- return JSON.parse(text || "");
319
- } catch (e) {
320
- }
248
+ // src/hooks/useMounted.ts
249
+ var import_react9 = require("react");
250
+ function useMounted() {
251
+ const [mounted, setMounted] = (0, import_react9.useState)(false);
252
+ (0, import_react9.useEffect)(() => setMounted(true), []);
253
+ return mounted;
321
254
  }
322
255
 
323
- // src/storage/storeToStates.ts
324
- var import_valtio3 = require("valtio");
325
- function storeToStates(store) {
326
- const snapshot = (0, import_valtio3.useSnapshot)(store);
327
- const states = {};
328
- function toState(key) {
329
- const get = () => snapshot[key];
330
- const set = (value) => {
331
- store[key] = value;
332
- };
333
- return [get(), set];
256
+ // src/hooks/useWatch.ts
257
+ var import_react10 = require("react");
258
+ function useWatch(source, callback, options = {}) {
259
+ const firstUpdate = (0, import_react10.useRef)(false);
260
+ const then = (0, import_react10.useRef)();
261
+ const deps = (0, import_react10.useMemo)(
262
+ () => Array.isArray(source) ? source : [source],
263
+ [source]
264
+ );
265
+ (0, import_react10.useEffect)(() => {
266
+ if (!firstUpdate.current)
267
+ recordFirst();
268
+ else
269
+ callback(source);
270
+ }, deps);
271
+ async function recordFirst() {
272
+ if (then.current)
273
+ return;
274
+ then.current = Promise.resolve(source);
275
+ then.current.then(() => firstUpdate.current = true);
276
+ if (options.immediate)
277
+ then.current.then((value) => callback(value));
334
278
  }
335
- for (const key of Object.keys(snapshot))
336
- states[key] = toState(key);
337
- return states;
338
- }
339
-
340
- // src/storage/defineStore.ts
341
- var import_valtio4 = require("valtio");
342
- function defineStore(store, options = {}) {
343
- const state = typeof store.state === "function" ? store.state() : store.state;
344
- const actions = store.actions || {};
345
- const $state = options.persistant ? proxyWithPersistant(options.persistant, state) : (0, import_valtio4.proxy)(state);
346
- const $actions = {};
347
- for (const key in actions)
348
- $actions[key] = actions[key].bind($state);
349
- return {
350
- $state: state,
351
- $actions: actions,
352
- ...actions
353
- };
354
- }
355
- function useStore(store) {
356
- return (0, import_valtio4.useSnapshot)(store.$state);
357
279
  }
358
280
 
359
- // src/hooks/defineAsyncStorage.ts
360
- function defineAsyncStorage(options) {
361
- const store = defineStore(
362
- {
363
- state: () => ({
364
- promise: void 0,
365
- value: options.initial,
366
- loading: false,
367
- error: void 0
368
- })
369
- },
370
- { persistant: options.persistant }
371
- );
372
- function use() {
373
- const fn = options.setup();
374
- const state = useStore(store);
375
- function fetch(...args) {
376
- if (state.loading)
377
- return;
378
- store.$state.loading = true;
379
- store.$state.promise = fn(...args);
380
- store.$state.promise.then((value) => store.$state.value = value).finally(() => store.$state.loading = false).catch((error) => {
381
- store.$state.error = error;
382
- throw error;
383
- });
384
- return store.$state.promise;
385
- }
386
- return [state, fetch];
387
- }
388
- return use;
281
+ // src/hooks/useWhenever.ts
282
+ function useWhenever(source, cb, options) {
283
+ useWatch(source, () => source && cb(source), options);
389
284
  }
390
285
 
391
286
  // src/utils/index.ts
@@ -432,11 +327,6 @@ function appendClass(value, newClass) {
432
327
  Trans,
433
328
  Unless,
434
329
  cls,
435
- defineAsyncStorage,
436
- defineStore,
437
- proxyWithPersistant,
438
- storeToState,
439
- storeToStates,
440
330
  useAsyncCallback,
441
331
  useAsyncState,
442
332
  useDebounce,
@@ -444,7 +334,6 @@ function appendClass(value, newClass) {
444
334
  useFetchRequestIntercept,
445
335
  useFetchResponseIntercept,
446
336
  useMounted,
447
- useStore,
448
337
  useWatch,
449
338
  useWhenever
450
339
  });
package/dist/index.d.ts CHANGED
@@ -1,173 +1,111 @@
1
+ import { BooleanLike } from '@hairy/utils';
1
2
  import * as react from 'react';
2
- import { DetailedHTMLProps as DetailedHTMLProps$1, HTMLAttributes, ReactNode, PropsWithChildren, ReactElement, FC, ComponentClass, DependencyList } from 'react';
3
+ import { ReactNode, PropsWithChildren, ReactElement, FC, ComponentClass, DependencyList, DetailedHTMLProps, HTMLAttributes } from 'react';
3
4
  import { FunctionReturningPromise, PromiseType } from 'react-use/lib/misc/types';
4
5
  import { AsyncState, AsyncFnReturn } from 'react-use/lib/useAsyncFn';
5
- import { INTERNAL_Snapshot } from 'valtio';
6
6
 
7
- type DetailedHTMLProps<T = HTMLDivElement> = DetailedHTMLProps$1<HTMLAttributes<T>, T>;
8
- type BooleanLike = any;
9
-
10
- interface CaseProps {
11
- cond?: BooleanLike;
12
- children?: ReactNode;
13
- }
7
+ interface CaseProps {
8
+ cond?: BooleanLike;
9
+ children?: ReactNode;
10
+ }
14
11
  declare function Case(props: CaseProps): ReactNode;
15
12
 
16
13
  declare function Default(props: PropsWithChildren): react.ReactNode;
17
14
 
18
15
  declare function Else(props: PropsWithChildren): react.ReactNode;
19
16
 
20
- interface IfProps {
21
- cond?: BooleanLike;
22
- then?: ReactNode;
23
- else?: ReactNode;
24
- children?: ReactNode;
25
- }
17
+ interface IfProps {
18
+ cond?: BooleanLike;
19
+ then?: ReactNode;
20
+ else?: ReactNode;
21
+ children?: ReactNode;
22
+ }
26
23
  declare function If(props: IfProps): ReactNode;
27
24
 
28
- interface SwitchProps extends PropsWithChildren {
29
- value?: BooleanLike;
30
- }
25
+ interface SwitchProps extends PropsWithChildren {
26
+ value?: BooleanLike;
27
+ }
31
28
  declare function Switch(props: SwitchProps): ReactElement<any, string | react.JSXElementConstructor<any>> | null;
32
29
 
33
30
  declare function Then(props: PropsWithChildren): react.ReactNode;
34
31
 
35
- interface UnlessProps {
36
- cond?: BooleanLike;
37
- then?: ReactNode;
38
- else?: ReactNode;
39
- children?: ReactNode;
40
- }
32
+ interface UnlessProps {
33
+ cond?: BooleanLike;
34
+ then?: ReactNode;
35
+ else?: ReactNode;
36
+ children?: ReactNode;
37
+ }
41
38
  declare function Unless(props: UnlessProps): ReactNode;
42
39
 
43
- interface InjectComponent<P> {
44
- component: FC<P> | ComponentClass<P>;
45
- props?: P;
46
- }
47
- interface InjectorProps {
48
- install: (FC<any> | InjectComponent<any> | ComponentClass<any>)[];
49
- children?: ReactNode;
50
- }
40
+ interface InjectComponent<P> {
41
+ component: FC<P> | ComponentClass<P>;
42
+ props?: P;
43
+ }
44
+ interface InjectorProps {
45
+ install: (FC<any> | InjectComponent<any> | ComponentClass<any>)[];
46
+ children?: ReactNode;
47
+ }
51
48
  declare function Injector(props: InjectorProps): ReactNode;
52
49
 
53
- interface TransProps {
54
- i18nKey: string;
55
- [key: string]: ReactNode;
56
- }
50
+ interface TransProps {
51
+ i18nKey: string;
52
+ [key: string]: ReactNode;
53
+ }
57
54
  declare function Trans({ i18nKey, ...additionalProps }: TransProps): ReactNode[];
58
55
 
56
+ declare function useAsyncCallback<T extends (...args: any[]) => any>(fun: T): readonly [boolean, T, Error | undefined];
57
+
58
+ type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>;
59
+ interface UseAsyncStateOptions<T extends FunctionReturningPromise> {
60
+ immediate?: boolean;
61
+ initial?: StateFromFunctionReturningPromise<T>;
62
+ }
63
+ declare function useAsyncState<T extends FunctionReturningPromise>(fn: T, deps?: DependencyList, options?: UseAsyncStateOptions<T>): AsyncFnReturn<T>;
64
+
59
65
  declare function useDebounce<T>(value: T, delay: number): T;
60
66
 
61
- interface EventBusListener<T = any> {
62
- (event: T): void;
63
- }
64
- declare function useEventBus<T>(key: string): {
65
- on: (listener: EventBusListener<T>) => void;
66
- emit: (event?: T) => void;
67
- off: (listener: EventBusListener) => void;
67
+ interface EventBusListener<T = any> {
68
+ (event: T): void;
69
+ }
70
+ declare function useEventBus<T>(key: string): {
71
+ on: (listener: EventBusListener<T>) => void;
72
+ emit: (event?: T) => void;
73
+ off: (listener: EventBusListener) => void;
68
74
  };
69
75
 
76
+ interface FetchResponseInterceptCallback {
77
+ (response: Response): Response | Promise<Response>;
78
+ }
79
+ interface FetchRequestInterceptCallback {
80
+ (fetch: typeof window.fetch, input: RequestInfo | URL, init?: RequestInit | undefined): Response | Promise<Response>;
81
+ }
82
+ declare function useFetchResponseIntercept(intercept: FetchResponseInterceptCallback): void;
83
+ declare function useFetchRequestIntercept(intercept: FetchRequestInterceptCallback): void;
84
+
70
85
  declare function useMounted(): boolean;
71
86
 
72
- interface WatchCallback<T> {
73
- (value: T): void;
74
- }
75
- interface WatchOptions {
76
- immediate?: boolean;
77
- }
87
+ interface WatchCallback<T> {
88
+ (value: T): void;
89
+ }
90
+ interface WatchOptions {
91
+ immediate?: boolean;
92
+ }
78
93
  declare function useWatch<T>(source: T, callback: WatchCallback<T>, options?: WatchOptions): void;
79
94
 
80
95
  declare function useWhenever<T>(source: T, cb: WatchCallback<Exclude<T, null | undefined>>, options?: WatchOptions): void;
81
96
 
82
- declare function useAsyncCallback<T extends (...args: any[]) => any>(fun: T): readonly [boolean, T, Error | undefined];
83
-
84
- type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>;
85
- interface UseAsyncStateOptions<T extends FunctionReturningPromise> {
86
- immediate?: boolean;
87
- initial?: StateFromFunctionReturningPromise<T>;
88
- }
89
- declare function useAsyncState<T extends FunctionReturningPromise>(fn: T, deps?: DependencyList, options?: UseAsyncStateOptions<T>): AsyncFnReturn<T>;
90
-
91
- interface FetchResponseInterceptCallback {
92
- (response: Response): Response | Promise<Response>;
93
- }
94
- interface FetchRequestInterceptCallback {
95
- (fetch: typeof window.fetch, input: RequestInfo | URL, init?: RequestInit | undefined): Response | Promise<Response>;
96
- }
97
- declare function useFetchResponseIntercept(intercept: FetchResponseInterceptCallback): void;
98
- declare function useFetchRequestIntercept(intercept: FetchRequestInterceptCallback): void;
99
-
100
- interface AsyncStorageOptions<T extends FunctionReturningPromise> {
101
- initial?: ReturnType<T> extends Promise<infer U> ? U : undefined;
102
- setup: () => T;
103
- persistant?: string;
104
- }
105
- declare function defineAsyncStorage<T extends FunctionReturningPromise>(options: AsyncStorageOptions<T>): () => readonly [{
106
- readonly promise: any;
107
- readonly value: ((ReturnType<T> extends Promise<infer U> ? U : undefined) extends infer T_1 ? T_1 extends (ReturnType<T> extends Promise<infer U> ? U : undefined) ? T_1 extends {
108
- $$valtioSnapshot: infer S;
109
- } ? S : T_1 extends RegExp | Error | Date | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | ((...args: any[]) => any) | (string | number | bigint | boolean | symbol | null | undefined) ? T_1 : T_1 extends Promise<unknown> ? Awaited<T_1> : T_1 extends object ? T_1 extends infer T_2 extends object ? { readonly [K in keyof T_2]: T_1[K] extends infer T_3 ? T_3 extends T_1[K] ? T_3 extends {
110
- $$valtioSnapshot: infer S;
111
- } ? S : T_3 extends RegExp | Error | Date | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | ((...args: any[]) => any) | (string | number | bigint | boolean | symbol | null | undefined) ? T_3 : T_3 extends Promise<unknown> ? Awaited<T_3> : T_3 extends object ? T_3 extends infer T_4 extends object ? { readonly [K_1 in keyof T_4]: T_3[K_1] extends infer T_5 ? T_5 extends T_3[K_1] ? T_5 extends {
112
- $$valtioSnapshot: infer S;
113
- } ? S : T_5 extends RegExp | Error | Date | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | ((...args: any[]) => any) | (string | number | bigint | boolean | symbol | null | undefined) ? T_5 : T_5 extends Promise<unknown> ? Awaited<T_5> : T_5 extends object ? T_5 extends infer T_6 extends object ? { readonly [K_2 in keyof T_6]: T_5[K_2] extends infer T_7 ? T_7 extends T_5[K_2] ? T_7 extends {
114
- $$valtioSnapshot: infer S;
115
- } ? S : T_7 extends RegExp | Error | Date | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | ((...args: any[]) => any) | (string | number | bigint | boolean | symbol | null | undefined) ? T_7 : T_7 extends Promise<unknown> ? Awaited<T_7> : T_7 extends object ? T_7 extends infer T_8 extends object ? { readonly [K_3 in keyof T_8]: T_7[K_3] extends infer T_9 ? T_9 extends T_7[K_3] ? T_9 extends {
116
- $$valtioSnapshot: infer S;
117
- } ? S : T_9 extends RegExp | Error | Date | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | ((...args: any[]) => any) | (string | number | bigint | boolean | symbol | null | undefined) ? T_9 : T_9 extends Promise<unknown> ? Awaited<T_9> : T_9 extends object ? T_9 extends infer T_10 extends object ? { readonly [K_4 in keyof T_10]: T_9[K_4] extends infer T_11 ? T_11 extends T_9[K_4] ? T_11 extends {
118
- $$valtioSnapshot: infer S;
119
- } ? S : T_11 extends RegExp | Error | Date | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | ((...args: any[]) => any) | (string | number | bigint | boolean | symbol | null | undefined) ? T_11 : T_11 extends Promise<unknown> ? Awaited<T_11> : T_11 extends object ? T_11 extends infer T_12 extends object ? { readonly [K_5 in keyof T_12]: T_11[K_5] extends infer T_13 ? T_13 extends T_11[K_5] ? T_13 extends {
120
- $$valtioSnapshot: infer S;
121
- } ? S : T_13 extends RegExp | Error | Date | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | ((...args: any[]) => any) | (string | number | bigint | boolean | symbol | null | undefined) ? T_13 : T_13 extends Promise<unknown> ? Awaited<T_13> : T_13 extends object ? T_13 extends infer T_14 extends object ? { readonly [K_6 in keyof T_14]: T_13[K_6] extends infer T_15 ? T_15 extends T_13[K_6] ? T_15 extends {
122
- $$valtioSnapshot: infer S;
123
- } ? S : T_15 extends RegExp | Error | Date | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | ((...args: any[]) => any) | (string | number | bigint | boolean | symbol | null | undefined) ? T_15 : T_15 extends Promise<unknown> ? Awaited<T_15> : T_15 extends object ? T_15 extends infer T_16 extends object ? { readonly [K_7 in keyof T_16]: T_15[K_7] extends infer T_17 ? T_17 extends T_15[K_7] ? T_17 extends {
124
- $$valtioSnapshot: infer S;
125
- } ? S : T_17 extends RegExp | Error | Date | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | ((...args: any[]) => any) | (string | number | bigint | boolean | symbol | null | undefined) ? T_17 : T_17 extends Promise<unknown> ? Awaited<T_17> : T_17 extends object ? T_17 extends infer T_18 extends object ? { readonly [K_8 in keyof T_18]: T_17[K_8] extends infer T_19 ? T_19 extends T_17[K_8] ? T_19 extends {
126
- $$valtioSnapshot: infer S;
127
- } ? S : T_19 extends RegExp | Error | Date | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | ((...args: any[]) => any) | (string | number | bigint | boolean | symbol | null | undefined) ? T_19 : T_19 extends Promise<unknown> ? Awaited<T_19> : T_19 extends object ? T_19 extends infer T_20 extends object ? { readonly [K_9 in keyof T_20]: T_19[K_9] extends infer T_21 ? T_21 extends T_19[K_9] ? T_21 extends {
128
- $$valtioSnapshot: infer S;
129
- } ? S : T_21 extends RegExp | Error | Date | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | ((...args: any[]) => any) | (string | number | bigint | boolean | symbol | null | undefined) ? T_21 : T_21 extends Promise<unknown> ? Awaited<T_21> : T_21 extends object ? any : T_21 : never : never; } : never : T_19 : never : never; } : never : T_17 : never : never; } : never : T_15 : never : never; } : never : T_13 : never : never; } : never : T_11 : never : never; } : never : T_9 : never : never; } : never : T_7 : never : never; } : never : T_5 : never : never; } : never : T_3 : never : never; } : never : T_1 : never : never) | undefined;
130
- readonly loading: boolean;
131
- readonly error: Error | undefined;
132
- }, T];
133
-
134
- declare function storeToState<T extends object, K extends keyof T>(store: T, key: K): readonly [T[K], (value: T[K]) => void];
135
-
136
- interface PersistantOptions {
137
- storage?: Storage;
138
- }
139
- declare function proxyWithPersistant<T extends object>(key: string, initialObject?: T, options?: PersistantOptions): T;
140
-
141
- type StoreToStates<S> = {
142
- [K in keyof S]: [S[K], (value: S[K]) => void];
143
- };
144
- declare function storeToStates<S extends object>(store: S): StoreToStates<S>;
145
-
146
- interface StoreDefine<S extends object, A extends Actions<S> = Record<string, any>> {
147
- state: (() => S) | S;
148
- actions?: A;
149
- }
150
- interface StoreOptions {
151
- persistant?: string;
152
- }
153
- type Actions<S> = Record<string, (this: S) => void>;
154
- type Store<S, A> = {
155
- $state: S;
156
- $actions: A;
157
- } & A;
158
- declare function defineStore<S extends object, A extends Actions<S>>(store: StoreDefine<S, A>, options?: StoreOptions): Store<S, A>;
159
- declare function useStore<S extends object, A extends Actions<S>>(store: Store<S, A>): INTERNAL_Snapshot<S>;
160
-
161
- type Value = string | boolean | undefined | null;
162
- type Mapping = Record<string, any>;
163
- interface ArgumentArray extends Array<Argument> {
164
- }
165
- interface ReadonlyArgumentArray extends ReadonlyArray<Argument> {
166
- }
167
- type Argument = Value | Mapping | ArgumentArray | ReadonlyArgumentArray;
168
- /**
169
- * A simple JavaScript utility for conditionally joining classNames together.
170
- */
97
+ type PropWithHtmlProps<T = HTMLDivElement> = DetailedHTMLProps<HTMLAttributes<T>, T>;
98
+
99
+ type Value = string | boolean | undefined | null;
100
+ type Mapping = Record<string, any>;
101
+ interface ArgumentArray extends Array<Argument> {
102
+ }
103
+ interface ReadonlyArgumentArray extends ReadonlyArray<Argument> {
104
+ }
105
+ type Argument = Value | Mapping | ArgumentArray | ReadonlyArgumentArray;
106
+ /**
107
+ * A simple JavaScript utility for conditionally joining classNames together.
108
+ */
171
109
  declare function cls(...args: ArgumentArray): string;
172
110
 
173
- export { Argument, ArgumentArray, AsyncStorageOptions, BooleanLike, Case, CaseProps, Default, DetailedHTMLProps, Else, EventBusListener, FetchRequestInterceptCallback, FetchResponseInterceptCallback, If, IfProps, InjectComponent, Injector, InjectorProps, Mapping, PersistantOptions, ReadonlyArgumentArray, StateFromFunctionReturningPromise, StoreToStates, Switch, SwitchProps, Then, Trans, TransProps, Unless, UnlessProps, UseAsyncStateOptions, Value, WatchCallback, WatchOptions, cls, defineAsyncStorage, defineStore, proxyWithPersistant, storeToState, storeToStates, useAsyncCallback, useAsyncState, useDebounce, useEventBus, useFetchRequestIntercept, useFetchResponseIntercept, useMounted, useStore, useWatch, useWhenever };
111
+ export { type Argument, type ArgumentArray, Case, type CaseProps, Default, Else, type EventBusListener, type FetchRequestInterceptCallback, type FetchResponseInterceptCallback, If, type IfProps, type InjectComponent, Injector, type InjectorProps, type Mapping, type PropWithHtmlProps, type ReadonlyArgumentArray, type StateFromFunctionReturningPromise, Switch, type SwitchProps, Then, Trans, type TransProps, Unless, type UnlessProps, type UseAsyncStateOptions, type Value, type WatchCallback, type WatchOptions, cls, useAsyncCallback, useAsyncState, useDebounce, useEventBus, useFetchRequestIntercept, useFetchResponseIntercept, useMounted, useWatch, useWhenever };