@hairy/react-lib 1.21.0 → 1.23.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/dist/index.cjs +54 -35
- package/dist/index.d.ts +25 -3
- package/dist/index.global.js +63 -45
- package/dist/index.js +51 -33
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -43,6 +43,7 @@ __export(index_exports, {
|
|
|
43
43
|
defineAsyncStore: () => defineAsyncStore,
|
|
44
44
|
defineStore: () => defineStore,
|
|
45
45
|
proxyWithPersistant: () => proxyWithPersistant,
|
|
46
|
+
ref: () => ref,
|
|
46
47
|
useAsyncCallback: () => useAsyncCallback,
|
|
47
48
|
useAsyncState: () => useAsyncState,
|
|
48
49
|
useDebounce: () => useDebounce,
|
|
@@ -202,11 +203,28 @@ function renderNodes(tokens, values) {
|
|
|
202
203
|
});
|
|
203
204
|
}
|
|
204
205
|
|
|
205
|
-
// src/hooks/
|
|
206
|
+
// src/hooks/ref.ts
|
|
206
207
|
var import_react7 = require("react");
|
|
208
|
+
function ref(value) {
|
|
209
|
+
function define(value2) {
|
|
210
|
+
if (typeof value2 === "function")
|
|
211
|
+
return (prev) => define(value2(prev.value));
|
|
212
|
+
return Object.defineProperty({}, "value", {
|
|
213
|
+
set: (action) => set(define(action)),
|
|
214
|
+
get: () => value2,
|
|
215
|
+
enumerable: true
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
const [ref2, set] = (0, import_react7.useState)(define(value));
|
|
219
|
+
return ref2;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/hooks/useAsyncCallback.ts
|
|
223
|
+
var import_react8 = require("react");
|
|
207
224
|
function useAsyncCallback(fun) {
|
|
208
|
-
const [state, set] = (0,
|
|
225
|
+
const [state, set] = (0, import_react8.useState)({ loading: false });
|
|
209
226
|
async function execute(...args) {
|
|
227
|
+
set({ loading: true });
|
|
210
228
|
return fun(...args).then((value) => {
|
|
211
229
|
set({ loading: false });
|
|
212
230
|
return value;
|
|
@@ -220,30 +238,15 @@ function useAsyncCallback(fun) {
|
|
|
220
238
|
|
|
221
239
|
// src/hooks/useAsyncState.ts
|
|
222
240
|
var import_react9 = require("react");
|
|
223
|
-
|
|
224
|
-
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useEffectOnce.js
|
|
225
|
-
var import_react8 = require("react");
|
|
226
|
-
var useEffectOnce = function(effect) {
|
|
227
|
-
(0, import_react8.useEffect)(effect, []);
|
|
228
|
-
};
|
|
229
|
-
var useEffectOnce_default = useEffectOnce;
|
|
230
|
-
|
|
231
|
-
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useMount.js
|
|
232
|
-
var useMount = function(fn) {
|
|
233
|
-
useEffectOnce_default(function() {
|
|
234
|
-
fn();
|
|
235
|
-
});
|
|
236
|
-
};
|
|
237
|
-
var useMount_default = useMount;
|
|
238
|
-
|
|
239
|
-
// src/hooks/useAsyncState.ts
|
|
240
|
-
function useAsyncState(fun, options) {
|
|
241
|
+
function useAsyncState(fun, deps = [], options) {
|
|
241
242
|
const [value, set] = (0, import_react9.useState)(options?.initial);
|
|
242
243
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
(0, import_react9.useEffect)(
|
|
245
|
+
() => {
|
|
246
|
+
execute();
|
|
247
|
+
},
|
|
248
|
+
deps
|
|
249
|
+
);
|
|
247
250
|
return [{ value, loading, error }, execute];
|
|
248
251
|
}
|
|
249
252
|
|
|
@@ -289,6 +292,21 @@ function useEventBus(key) {
|
|
|
289
292
|
};
|
|
290
293
|
}
|
|
291
294
|
|
|
295
|
+
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useEffectOnce.js
|
|
296
|
+
var import_react12 = require("react");
|
|
297
|
+
var useEffectOnce = function(effect) {
|
|
298
|
+
(0, import_react12.useEffect)(effect, []);
|
|
299
|
+
};
|
|
300
|
+
var useEffectOnce_default = useEffectOnce;
|
|
301
|
+
|
|
302
|
+
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useMount.js
|
|
303
|
+
var useMount = function(fn) {
|
|
304
|
+
useEffectOnce_default(function() {
|
|
305
|
+
fn();
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
var useMount_default = useMount;
|
|
309
|
+
|
|
292
310
|
// src/hooks/useFetchIntercept.ts
|
|
293
311
|
function useFetchResponseIntercept(intercept) {
|
|
294
312
|
useMount_default(() => fetchResponseIntercept(intercept));
|
|
@@ -313,23 +331,23 @@ function fetchRequestIntercept(intercept) {
|
|
|
313
331
|
}
|
|
314
332
|
|
|
315
333
|
// src/hooks/useMounted.ts
|
|
316
|
-
var
|
|
334
|
+
var import_react13 = require("react");
|
|
317
335
|
function useMounted() {
|
|
318
|
-
const [mounted, setMounted] = (0,
|
|
319
|
-
(0,
|
|
336
|
+
const [mounted, setMounted] = (0, import_react13.useState)(false);
|
|
337
|
+
(0, import_react13.useEffect)(() => setMounted(true), []);
|
|
320
338
|
return mounted;
|
|
321
339
|
}
|
|
322
340
|
|
|
323
341
|
// src/hooks/useWatch.ts
|
|
324
|
-
var
|
|
342
|
+
var import_react14 = require("react");
|
|
325
343
|
function useWatch(source, callback, options = {}) {
|
|
326
|
-
const firstUpdate = (0,
|
|
327
|
-
const then = (0,
|
|
328
|
-
const deps = (0,
|
|
344
|
+
const firstUpdate = (0, import_react14.useRef)(false);
|
|
345
|
+
const then = (0, import_react14.useRef)();
|
|
346
|
+
const deps = (0, import_react14.useMemo)(
|
|
329
347
|
() => Array.isArray(source) ? source : [source],
|
|
330
348
|
[source]
|
|
331
349
|
);
|
|
332
|
-
(0,
|
|
350
|
+
(0, import_react14.useEffect)(() => {
|
|
333
351
|
if (!firstUpdate.current)
|
|
334
352
|
recordFirst();
|
|
335
353
|
else
|
|
@@ -354,7 +372,7 @@ function useWhenever(source, cb, options) {
|
|
|
354
372
|
var import_utils8 = require("valtio/utils");
|
|
355
373
|
|
|
356
374
|
// src/storage/defineStore.ts
|
|
357
|
-
var
|
|
375
|
+
var import_react15 = require("react");
|
|
358
376
|
var import_valtio2 = require("valtio");
|
|
359
377
|
|
|
360
378
|
// ../util-core/src/util/json.ts
|
|
@@ -417,10 +435,10 @@ function defineStore(store, options = {}) {
|
|
|
417
435
|
Object.assign($state, patch);
|
|
418
436
|
}
|
|
419
437
|
function $signal(fn) {
|
|
420
|
-
return (0,
|
|
438
|
+
return (0, import_react15.createElement)(() => fn((0, import_valtio2.useSnapshot)($state)));
|
|
421
439
|
}
|
|
422
440
|
$signal.status = function(fn) {
|
|
423
|
-
return (0,
|
|
441
|
+
return (0, import_react15.createElement)(() => fn((0, import_valtio2.useSnapshot)($status)));
|
|
424
442
|
};
|
|
425
443
|
return {
|
|
426
444
|
$subscribe,
|
|
@@ -547,6 +565,7 @@ function useStore(store) {
|
|
|
547
565
|
defineAsyncStore,
|
|
548
566
|
defineStore,
|
|
549
567
|
proxyWithPersistant,
|
|
568
|
+
ref,
|
|
550
569
|
useAsyncCallback,
|
|
551
570
|
useAsyncState,
|
|
552
571
|
useDebounce,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BooleanLike, PromiseFn, PromiseType, AnyFn } from '@hairy/utils';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
-
import { JSX, ReactNode, PropsWithChildren, ReactElement, FC, ComponentClass, DetailedHTMLProps, HTMLAttributes } from 'react';
|
|
3
|
+
import { JSX, ReactNode, PropsWithChildren, ReactElement, FC, ComponentClass, SetStateAction, DetailedHTMLProps, HTMLAttributes } from 'react';
|
|
4
4
|
import * as valtio from 'valtio';
|
|
5
5
|
|
|
6
6
|
type Value = string | boolean | undefined | null;
|
|
@@ -79,6 +79,26 @@ interface TransProps {
|
|
|
79
79
|
}
|
|
80
80
|
declare function Trans({ i18nKey, ...additionalProps }: TransProps): ReactNode[];
|
|
81
81
|
|
|
82
|
+
interface Ref<S> {
|
|
83
|
+
set value(action: SetStateAction<S>);
|
|
84
|
+
get value(): S;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* This is a toy, do not use it in a production environment to avoid causing problems
|
|
88
|
+
*
|
|
89
|
+
* Similar to vue's ref function, used to create a responsive reference object
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* const count = ref(0)
|
|
93
|
+
* count.value++
|
|
94
|
+
* console.log(count.value) // 1
|
|
95
|
+
* // or
|
|
96
|
+
* count.value = prev => prev + 1
|
|
97
|
+
* @param value
|
|
98
|
+
*/
|
|
99
|
+
declare function ref<T>(value: T): Ref<T>;
|
|
100
|
+
declare function ref<T>(value?: T): Ref<T | undefined>;
|
|
101
|
+
|
|
82
102
|
declare function useAsyncCallback<T extends PromiseFn>(fun: T): readonly [boolean, T, Error | undefined];
|
|
83
103
|
|
|
84
104
|
type AsyncState<T> = {
|
|
@@ -107,11 +127,13 @@ declare type AsyncStateReturn<T extends PromiseFn = PromiseFn> = [
|
|
|
107
127
|
type UseAsyncStateOptions<T extends AnyFn> = {
|
|
108
128
|
immediate?: boolean;
|
|
109
129
|
initial?: PromiseType<ReturnType<T>>;
|
|
130
|
+
deps?: any[];
|
|
110
131
|
} | {
|
|
111
132
|
immediate?: boolean;
|
|
112
133
|
initial: PromiseType<ReturnType<T>>;
|
|
134
|
+
deps?: any[];
|
|
113
135
|
};
|
|
114
|
-
declare function useAsyncState<T extends PromiseFn>(fun: T, options?: UseAsyncStateOptions<T>): AsyncStateReturn<T>;
|
|
136
|
+
declare function useAsyncState<T extends PromiseFn>(fun: T, deps?: any[], options?: UseAsyncStateOptions<T>): AsyncStateReturn<T>;
|
|
115
137
|
|
|
116
138
|
declare function useDebounce<T>(value: T, delay: number): T;
|
|
117
139
|
|
|
@@ -236,4 +258,4 @@ declare function useStore<S extends object, A extends Actions<S>, G extends Gett
|
|
|
236
258
|
|
|
237
259
|
type PropsWithDetailedHTML<T = HTMLDivElement> = DetailedHTMLProps<HTMLAttributes<T>, T>;
|
|
238
260
|
|
|
239
|
-
export { type Argument, type ArgumentArray, type AsyncStoreOptions, Case, type CaseProps, Default, type DefaultProps, Else, type ElseProps, type EventBusListener, type FetchRequestInterceptCallback, type FetchResponseInterceptCallback, If, type IfProps, type InjectComponent, Injector, type InjectorProps, type Mapping, type PersistantOptions, type PropsWithDetailedHTML, type ReadonlyArgumentArray, Switch, type SwitchProps, Then, type ThenProps, Trans, type TransProps, Unless, type UnlessProps, type UseAsyncStateOptions, type Value, type WatchCallback, type WatchOptions, type WrapperProps, type WrapperTag, cls, defineAsyncStore, defineStore, proxyWithPersistant, useAsyncCallback, useAsyncState, useDebounce, useEventBus, useFetchRequestIntercept, useFetchResponseIntercept, useMounted, useStatus, useStore, useWatch, useWhenever, wrapper };
|
|
261
|
+
export { type Argument, type ArgumentArray, type AsyncStoreOptions, Case, type CaseProps, Default, type DefaultProps, Else, type ElseProps, type EventBusListener, type FetchRequestInterceptCallback, type FetchResponseInterceptCallback, If, type IfProps, type InjectComponent, Injector, type InjectorProps, type Mapping, type PersistantOptions, type PropsWithDetailedHTML, type ReadonlyArgumentArray, type Ref, Switch, type SwitchProps, Then, type ThenProps, Trans, type TransProps, Unless, type UnlessProps, type UseAsyncStateOptions, type Value, type WatchCallback, type WatchOptions, type WrapperProps, type WrapperTag, cls, defineAsyncStore, defineStore, proxyWithPersistant, ref, useAsyncCallback, useAsyncState, useDebounce, useEventBus, useFetchRequestIntercept, useFetchResponseIntercept, useMounted, useStatus, useStore, useWatch, useWhenever, wrapper };
|
package/dist/index.global.js
CHANGED
|
@@ -86,6 +86,7 @@ var LibReact = (() => {
|
|
|
86
86
|
defineAsyncStore: () => defineAsyncStore,
|
|
87
87
|
defineStore: () => defineStore,
|
|
88
88
|
proxyWithPersistant: () => proxyWithPersistant,
|
|
89
|
+
ref: () => ref,
|
|
89
90
|
useAsyncCallback: () => useAsyncCallback,
|
|
90
91
|
useAsyncState: () => useAsyncState,
|
|
91
92
|
useDebounce: () => useDebounce,
|
|
@@ -305,11 +306,28 @@ var LibReact = (() => {
|
|
|
305
306
|
});
|
|
306
307
|
}
|
|
307
308
|
|
|
308
|
-
// src/hooks/
|
|
309
|
+
// src/hooks/ref.ts
|
|
309
310
|
var import_react7 = __toESM(require_react(), 1);
|
|
311
|
+
function ref(value) {
|
|
312
|
+
function define(value2) {
|
|
313
|
+
if (typeof value2 === "function")
|
|
314
|
+
return (prev) => define(value2(prev.value));
|
|
315
|
+
return Object.defineProperty({}, "value", {
|
|
316
|
+
set: (action) => set(define(action)),
|
|
317
|
+
get: () => value2,
|
|
318
|
+
enumerable: true
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
const [ref2, set] = (0, import_react7.useState)(define(value));
|
|
322
|
+
return ref2;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// src/hooks/useAsyncCallback.ts
|
|
326
|
+
var import_react8 = __toESM(require_react(), 1);
|
|
310
327
|
function useAsyncCallback(fun) {
|
|
311
|
-
const [state, set] = (0,
|
|
328
|
+
const [state, set] = (0, import_react8.useState)({ loading: false });
|
|
312
329
|
async function execute(...args) {
|
|
330
|
+
set({ loading: true });
|
|
313
331
|
return fun(...args).then((value) => {
|
|
314
332
|
set({ loading: false });
|
|
315
333
|
return value;
|
|
@@ -323,30 +341,15 @@ var LibReact = (() => {
|
|
|
323
341
|
|
|
324
342
|
// src/hooks/useAsyncState.ts
|
|
325
343
|
var import_react9 = __toESM(require_react(), 1);
|
|
326
|
-
|
|
327
|
-
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useEffectOnce.js
|
|
328
|
-
var import_react8 = __toESM(require_react());
|
|
329
|
-
var useEffectOnce = function(effect) {
|
|
330
|
-
(0, import_react8.useEffect)(effect, []);
|
|
331
|
-
};
|
|
332
|
-
var useEffectOnce_default = useEffectOnce;
|
|
333
|
-
|
|
334
|
-
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useMount.js
|
|
335
|
-
var useMount = function(fn) {
|
|
336
|
-
useEffectOnce_default(function() {
|
|
337
|
-
fn();
|
|
338
|
-
});
|
|
339
|
-
};
|
|
340
|
-
var useMount_default = useMount;
|
|
341
|
-
|
|
342
|
-
// src/hooks/useAsyncState.ts
|
|
343
|
-
function useAsyncState(fun, options) {
|
|
344
|
+
function useAsyncState(fun, deps = [], options) {
|
|
344
345
|
const [value, set] = (0, import_react9.useState)(options?.initial);
|
|
345
346
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
347
|
+
(0, import_react9.useEffect)(
|
|
348
|
+
() => {
|
|
349
|
+
execute();
|
|
350
|
+
},
|
|
351
|
+
deps
|
|
352
|
+
);
|
|
350
353
|
return [{ value, loading, error }, execute];
|
|
351
354
|
}
|
|
352
355
|
|
|
@@ -409,6 +412,21 @@ var LibReact = (() => {
|
|
|
409
412
|
};
|
|
410
413
|
}
|
|
411
414
|
|
|
415
|
+
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useEffectOnce.js
|
|
416
|
+
var import_react12 = __toESM(require_react());
|
|
417
|
+
var useEffectOnce = function(effect) {
|
|
418
|
+
(0, import_react12.useEffect)(effect, []);
|
|
419
|
+
};
|
|
420
|
+
var useEffectOnce_default = useEffectOnce;
|
|
421
|
+
|
|
422
|
+
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useMount.js
|
|
423
|
+
var useMount = function(fn) {
|
|
424
|
+
useEffectOnce_default(function() {
|
|
425
|
+
fn();
|
|
426
|
+
});
|
|
427
|
+
};
|
|
428
|
+
var useMount_default = useMount;
|
|
429
|
+
|
|
412
430
|
// src/hooks/useFetchIntercept.ts
|
|
413
431
|
function useFetchResponseIntercept(intercept) {
|
|
414
432
|
useMount_default(() => fetchResponseIntercept(intercept));
|
|
@@ -433,23 +451,23 @@ var LibReact = (() => {
|
|
|
433
451
|
}
|
|
434
452
|
|
|
435
453
|
// src/hooks/useMounted.ts
|
|
436
|
-
var
|
|
454
|
+
var import_react13 = __toESM(require_react(), 1);
|
|
437
455
|
function useMounted() {
|
|
438
|
-
const [mounted, setMounted] = (0,
|
|
439
|
-
(0,
|
|
456
|
+
const [mounted, setMounted] = (0, import_react13.useState)(false);
|
|
457
|
+
(0, import_react13.useEffect)(() => setMounted(true), []);
|
|
440
458
|
return mounted;
|
|
441
459
|
}
|
|
442
460
|
|
|
443
461
|
// src/hooks/useWatch.ts
|
|
444
|
-
var
|
|
462
|
+
var import_react14 = __toESM(require_react(), 1);
|
|
445
463
|
function useWatch(source, callback, options = {}) {
|
|
446
|
-
const firstUpdate = (0,
|
|
447
|
-
const then = (0,
|
|
448
|
-
const deps = (0,
|
|
464
|
+
const firstUpdate = (0, import_react14.useRef)(false);
|
|
465
|
+
const then = (0, import_react14.useRef)();
|
|
466
|
+
const deps = (0, import_react14.useMemo)(
|
|
449
467
|
() => Array.isArray(source) ? source : [source],
|
|
450
468
|
[source]
|
|
451
469
|
);
|
|
452
|
-
(0,
|
|
470
|
+
(0, import_react14.useEffect)(() => {
|
|
453
471
|
if (!firstUpdate.current)
|
|
454
472
|
recordFirst();
|
|
455
473
|
else
|
|
@@ -977,27 +995,27 @@ var LibReact = (() => {
|
|
|
977
995
|
var { proxyStateMap: proxyStateMap2, snapCache: snapCache2 } = unstable_getInternalStates();
|
|
978
996
|
|
|
979
997
|
// ../../node_modules/.pnpm/valtio@2.1.4_@types+react@18.3.18_react@18.3.1/node_modules/valtio/esm/react.mjs
|
|
980
|
-
var
|
|
998
|
+
var import_react15 = __toESM(require_react(), 1);
|
|
981
999
|
var import_meta2 = {};
|
|
982
1000
|
var useAffectedDebugValue = (state, affected) => {
|
|
983
|
-
const pathList = (0,
|
|
984
|
-
(0,
|
|
1001
|
+
const pathList = (0, import_react15.useRef)(void 0);
|
|
1002
|
+
(0, import_react15.useEffect)(() => {
|
|
985
1003
|
pathList.current = affectedToPathList(state, affected, true);
|
|
986
1004
|
});
|
|
987
|
-
(0,
|
|
1005
|
+
(0, import_react15.useDebugValue)(pathList.current);
|
|
988
1006
|
};
|
|
989
1007
|
var condUseAffectedDebugValue = useAffectedDebugValue;
|
|
990
1008
|
var targetCache = /* @__PURE__ */ new WeakMap();
|
|
991
1009
|
function useSnapshot(proxyObject, options) {
|
|
992
1010
|
const notifyInSync = options == null ? void 0 : options.sync;
|
|
993
|
-
const affected = (0,
|
|
1011
|
+
const affected = (0, import_react15.useMemo)(
|
|
994
1012
|
() => proxyObject && /* @__PURE__ */ new WeakMap(),
|
|
995
1013
|
[proxyObject]
|
|
996
1014
|
);
|
|
997
|
-
const lastSnapshot = (0,
|
|
1015
|
+
const lastSnapshot = (0, import_react15.useRef)(void 0);
|
|
998
1016
|
let inRender = true;
|
|
999
|
-
const currSnapshot = (0,
|
|
1000
|
-
(0,
|
|
1017
|
+
const currSnapshot = (0, import_react15.useSyncExternalStore)(
|
|
1018
|
+
(0, import_react15.useCallback)(
|
|
1001
1019
|
(callback) => {
|
|
1002
1020
|
const unsub = subscribe(proxyObject, callback, notifyInSync);
|
|
1003
1021
|
callback();
|
|
@@ -1023,18 +1041,18 @@ var LibReact = (() => {
|
|
|
1023
1041
|
() => snapshot(proxyObject)
|
|
1024
1042
|
);
|
|
1025
1043
|
inRender = false;
|
|
1026
|
-
(0,
|
|
1044
|
+
(0, import_react15.useLayoutEffect)(() => {
|
|
1027
1045
|
lastSnapshot.current = currSnapshot;
|
|
1028
1046
|
});
|
|
1029
1047
|
if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production") {
|
|
1030
1048
|
condUseAffectedDebugValue(currSnapshot, affected);
|
|
1031
1049
|
}
|
|
1032
|
-
const proxyCache2 = (0,
|
|
1050
|
+
const proxyCache2 = (0, import_react15.useMemo)(() => /* @__PURE__ */ new WeakMap(), []);
|
|
1033
1051
|
return createProxy(currSnapshot, affected, proxyCache2, targetCache);
|
|
1034
1052
|
}
|
|
1035
1053
|
|
|
1036
1054
|
// src/storage/defineStore.ts
|
|
1037
|
-
var
|
|
1055
|
+
var import_react16 = __toESM(require_react(), 1);
|
|
1038
1056
|
|
|
1039
1057
|
// ../util-core/src/util/json.ts
|
|
1040
1058
|
function jsonTryParse(text) {
|
|
@@ -1095,10 +1113,10 @@ var LibReact = (() => {
|
|
|
1095
1113
|
Object.assign($state, patch);
|
|
1096
1114
|
}
|
|
1097
1115
|
function $signal(fn) {
|
|
1098
|
-
return (0,
|
|
1116
|
+
return (0, import_react16.createElement)(() => fn(useSnapshot($state)));
|
|
1099
1117
|
}
|
|
1100
1118
|
$signal.status = function(fn) {
|
|
1101
|
-
return (0,
|
|
1119
|
+
return (0, import_react16.createElement)(() => fn(useSnapshot($status)));
|
|
1102
1120
|
};
|
|
1103
1121
|
return {
|
|
1104
1122
|
$subscribe,
|
package/dist/index.js
CHANGED
|
@@ -142,11 +142,28 @@ function renderNodes(tokens, values) {
|
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
// src/hooks/
|
|
145
|
+
// src/hooks/ref.ts
|
|
146
146
|
import { useState } from "react";
|
|
147
|
+
function ref(value) {
|
|
148
|
+
function define(value2) {
|
|
149
|
+
if (typeof value2 === "function")
|
|
150
|
+
return (prev) => define(value2(prev.value));
|
|
151
|
+
return Object.defineProperty({}, "value", {
|
|
152
|
+
set: (action) => set(define(action)),
|
|
153
|
+
get: () => value2,
|
|
154
|
+
enumerable: true
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const [ref2, set] = useState(define(value));
|
|
158
|
+
return ref2;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/hooks/useAsyncCallback.ts
|
|
162
|
+
import { useState as useState2 } from "react";
|
|
147
163
|
function useAsyncCallback(fun) {
|
|
148
|
-
const [state, set] =
|
|
164
|
+
const [state, set] = useState2({ loading: false });
|
|
149
165
|
async function execute(...args) {
|
|
166
|
+
set({ loading: true });
|
|
150
167
|
return fun(...args).then((value) => {
|
|
151
168
|
set({ loading: false });
|
|
152
169
|
return value;
|
|
@@ -159,39 +176,24 @@ function useAsyncCallback(fun) {
|
|
|
159
176
|
}
|
|
160
177
|
|
|
161
178
|
// src/hooks/useAsyncState.ts
|
|
162
|
-
import { useEffect
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
import { useEffect } from "react";
|
|
166
|
-
var useEffectOnce = function(effect) {
|
|
167
|
-
useEffect(effect, []);
|
|
168
|
-
};
|
|
169
|
-
var useEffectOnce_default = useEffectOnce;
|
|
170
|
-
|
|
171
|
-
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useMount.js
|
|
172
|
-
var useMount = function(fn) {
|
|
173
|
-
useEffectOnce_default(function() {
|
|
174
|
-
fn();
|
|
175
|
-
});
|
|
176
|
-
};
|
|
177
|
-
var useMount_default = useMount;
|
|
178
|
-
|
|
179
|
-
// src/hooks/useAsyncState.ts
|
|
180
|
-
function useAsyncState(fun, options) {
|
|
181
|
-
const [value, set] = useState2(options?.initial);
|
|
179
|
+
import { useEffect, useState as useState3 } from "react";
|
|
180
|
+
function useAsyncState(fun, deps = [], options) {
|
|
181
|
+
const [value, set] = useState3(options?.initial);
|
|
182
182
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
useEffect(
|
|
184
|
+
() => {
|
|
185
|
+
execute();
|
|
186
|
+
},
|
|
187
|
+
deps
|
|
188
|
+
);
|
|
187
189
|
return [{ value, loading, error }, execute];
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
// src/hooks/useDebounce.ts
|
|
191
|
-
import { useEffect as
|
|
193
|
+
import { useEffect as useEffect2, useState as useState4 } from "react";
|
|
192
194
|
function useDebounce(value, delay) {
|
|
193
|
-
const [debouncedValue, setDebouncedValue] =
|
|
194
|
-
|
|
195
|
+
const [debouncedValue, setDebouncedValue] = useState4(value);
|
|
196
|
+
useEffect2(() => {
|
|
195
197
|
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
196
198
|
return () => clearTimeout(handler);
|
|
197
199
|
}, [value, delay]);
|
|
@@ -200,14 +202,14 @@ function useDebounce(value, delay) {
|
|
|
200
202
|
|
|
201
203
|
// src/hooks/useEventBus.ts
|
|
202
204
|
import mitt from "mitt";
|
|
203
|
-
import { useEffect as
|
|
205
|
+
import { useEffect as useEffect3, useRef } from "react";
|
|
204
206
|
var emitter = mitt();
|
|
205
207
|
function useEventBus(key) {
|
|
206
208
|
const onRef = useRef();
|
|
207
209
|
function on(listener) {
|
|
208
210
|
emitter.on(key, listener);
|
|
209
211
|
onRef.current = listener;
|
|
210
|
-
|
|
212
|
+
useEffect3(() => {
|
|
211
213
|
if (!onRef.current)
|
|
212
214
|
return;
|
|
213
215
|
emitter.off(key, onRef.current);
|
|
@@ -229,6 +231,21 @@ function useEventBus(key) {
|
|
|
229
231
|
};
|
|
230
232
|
}
|
|
231
233
|
|
|
234
|
+
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useEffectOnce.js
|
|
235
|
+
import { useEffect as useEffect4 } from "react";
|
|
236
|
+
var useEffectOnce = function(effect) {
|
|
237
|
+
useEffect4(effect, []);
|
|
238
|
+
};
|
|
239
|
+
var useEffectOnce_default = useEffectOnce;
|
|
240
|
+
|
|
241
|
+
// ../../node_modules/.pnpm/react-use@17.6.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/react-use/esm/useMount.js
|
|
242
|
+
var useMount = function(fn) {
|
|
243
|
+
useEffectOnce_default(function() {
|
|
244
|
+
fn();
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
var useMount_default = useMount;
|
|
248
|
+
|
|
232
249
|
// src/hooks/useFetchIntercept.ts
|
|
233
250
|
function useFetchResponseIntercept(intercept) {
|
|
234
251
|
useMount_default(() => fetchResponseIntercept(intercept));
|
|
@@ -253,9 +270,9 @@ function fetchRequestIntercept(intercept) {
|
|
|
253
270
|
}
|
|
254
271
|
|
|
255
272
|
// src/hooks/useMounted.ts
|
|
256
|
-
import { useEffect as useEffect5, useState as
|
|
273
|
+
import { useEffect as useEffect5, useState as useState5 } from "react";
|
|
257
274
|
function useMounted() {
|
|
258
|
-
const [mounted, setMounted] =
|
|
275
|
+
const [mounted, setMounted] = useState5(false);
|
|
259
276
|
useEffect5(() => setMounted(true), []);
|
|
260
277
|
return mounted;
|
|
261
278
|
}
|
|
@@ -486,6 +503,7 @@ export {
|
|
|
486
503
|
defineAsyncStore,
|
|
487
504
|
defineStore,
|
|
488
505
|
proxyWithPersistant,
|
|
506
|
+
ref,
|
|
489
507
|
useAsyncCallback,
|
|
490
508
|
useAsyncState,
|
|
491
509
|
useDebounce,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hairy/react-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.23.0",
|
|
5
5
|
"description": "Library for react",
|
|
6
6
|
"author": "Hairyf <wwu710632@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react-dom": "^18.2.0",
|
|
39
39
|
"react-i18next": "^14.1.2",
|
|
40
40
|
"react-use": "^17.6.0",
|
|
41
|
-
"@hairy/utils": "1.
|
|
41
|
+
"@hairy/utils": "1.23.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsup",
|