@hairy/react-lib 1.22.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 +53 -35
- package/dist/index.d.ts +25 -3
- package/dist/index.global.js +62 -45
- package/dist/index.js +50 -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,10 +203,26 @@ 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) {
|
|
210
227
|
set({ loading: true });
|
|
211
228
|
return fun(...args).then((value) => {
|
|
@@ -221,30 +238,15 @@ function useAsyncCallback(fun) {
|
|
|
221
238
|
|
|
222
239
|
// src/hooks/useAsyncState.ts
|
|
223
240
|
var import_react9 = require("react");
|
|
224
|
-
|
|
225
|
-
// ../../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
|
|
226
|
-
var import_react8 = require("react");
|
|
227
|
-
var useEffectOnce = function(effect) {
|
|
228
|
-
(0, import_react8.useEffect)(effect, []);
|
|
229
|
-
};
|
|
230
|
-
var useEffectOnce_default = useEffectOnce;
|
|
231
|
-
|
|
232
|
-
// ../../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
|
|
233
|
-
var useMount = function(fn) {
|
|
234
|
-
useEffectOnce_default(function() {
|
|
235
|
-
fn();
|
|
236
|
-
});
|
|
237
|
-
};
|
|
238
|
-
var useMount_default = useMount;
|
|
239
|
-
|
|
240
|
-
// src/hooks/useAsyncState.ts
|
|
241
|
-
function useAsyncState(fun, options) {
|
|
241
|
+
function useAsyncState(fun, deps = [], options) {
|
|
242
242
|
const [value, set] = (0, import_react9.useState)(options?.initial);
|
|
243
243
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
244
|
+
(0, import_react9.useEffect)(
|
|
245
|
+
() => {
|
|
246
|
+
execute();
|
|
247
|
+
},
|
|
248
|
+
deps
|
|
249
|
+
);
|
|
248
250
|
return [{ value, loading, error }, execute];
|
|
249
251
|
}
|
|
250
252
|
|
|
@@ -290,6 +292,21 @@ function useEventBus(key) {
|
|
|
290
292
|
};
|
|
291
293
|
}
|
|
292
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
|
+
|
|
293
310
|
// src/hooks/useFetchIntercept.ts
|
|
294
311
|
function useFetchResponseIntercept(intercept) {
|
|
295
312
|
useMount_default(() => fetchResponseIntercept(intercept));
|
|
@@ -314,23 +331,23 @@ function fetchRequestIntercept(intercept) {
|
|
|
314
331
|
}
|
|
315
332
|
|
|
316
333
|
// src/hooks/useMounted.ts
|
|
317
|
-
var
|
|
334
|
+
var import_react13 = require("react");
|
|
318
335
|
function useMounted() {
|
|
319
|
-
const [mounted, setMounted] = (0,
|
|
320
|
-
(0,
|
|
336
|
+
const [mounted, setMounted] = (0, import_react13.useState)(false);
|
|
337
|
+
(0, import_react13.useEffect)(() => setMounted(true), []);
|
|
321
338
|
return mounted;
|
|
322
339
|
}
|
|
323
340
|
|
|
324
341
|
// src/hooks/useWatch.ts
|
|
325
|
-
var
|
|
342
|
+
var import_react14 = require("react");
|
|
326
343
|
function useWatch(source, callback, options = {}) {
|
|
327
|
-
const firstUpdate = (0,
|
|
328
|
-
const then = (0,
|
|
329
|
-
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)(
|
|
330
347
|
() => Array.isArray(source) ? source : [source],
|
|
331
348
|
[source]
|
|
332
349
|
);
|
|
333
|
-
(0,
|
|
350
|
+
(0, import_react14.useEffect)(() => {
|
|
334
351
|
if (!firstUpdate.current)
|
|
335
352
|
recordFirst();
|
|
336
353
|
else
|
|
@@ -355,7 +372,7 @@ function useWhenever(source, cb, options) {
|
|
|
355
372
|
var import_utils8 = require("valtio/utils");
|
|
356
373
|
|
|
357
374
|
// src/storage/defineStore.ts
|
|
358
|
-
var
|
|
375
|
+
var import_react15 = require("react");
|
|
359
376
|
var import_valtio2 = require("valtio");
|
|
360
377
|
|
|
361
378
|
// ../util-core/src/util/json.ts
|
|
@@ -418,10 +435,10 @@ function defineStore(store, options = {}) {
|
|
|
418
435
|
Object.assign($state, patch);
|
|
419
436
|
}
|
|
420
437
|
function $signal(fn) {
|
|
421
|
-
return (0,
|
|
438
|
+
return (0, import_react15.createElement)(() => fn((0, import_valtio2.useSnapshot)($state)));
|
|
422
439
|
}
|
|
423
440
|
$signal.status = function(fn) {
|
|
424
|
-
return (0,
|
|
441
|
+
return (0, import_react15.createElement)(() => fn((0, import_valtio2.useSnapshot)($status)));
|
|
425
442
|
};
|
|
426
443
|
return {
|
|
427
444
|
$subscribe,
|
|
@@ -548,6 +565,7 @@ function useStore(store) {
|
|
|
548
565
|
defineAsyncStore,
|
|
549
566
|
defineStore,
|
|
550
567
|
proxyWithPersistant,
|
|
568
|
+
ref,
|
|
551
569
|
useAsyncCallback,
|
|
552
570
|
useAsyncState,
|
|
553
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,10 +306,26 @@ 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) {
|
|
313
330
|
set({ loading: true });
|
|
314
331
|
return fun(...args).then((value) => {
|
|
@@ -324,30 +341,15 @@ var LibReact = (() => {
|
|
|
324
341
|
|
|
325
342
|
// src/hooks/useAsyncState.ts
|
|
326
343
|
var import_react9 = __toESM(require_react(), 1);
|
|
327
|
-
|
|
328
|
-
// ../../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
|
|
329
|
-
var import_react8 = __toESM(require_react());
|
|
330
|
-
var useEffectOnce = function(effect) {
|
|
331
|
-
(0, import_react8.useEffect)(effect, []);
|
|
332
|
-
};
|
|
333
|
-
var useEffectOnce_default = useEffectOnce;
|
|
334
|
-
|
|
335
|
-
// ../../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
|
|
336
|
-
var useMount = function(fn) {
|
|
337
|
-
useEffectOnce_default(function() {
|
|
338
|
-
fn();
|
|
339
|
-
});
|
|
340
|
-
};
|
|
341
|
-
var useMount_default = useMount;
|
|
342
|
-
|
|
343
|
-
// src/hooks/useAsyncState.ts
|
|
344
|
-
function useAsyncState(fun, options) {
|
|
344
|
+
function useAsyncState(fun, deps = [], options) {
|
|
345
345
|
const [value, set] = (0, import_react9.useState)(options?.initial);
|
|
346
346
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
347
|
+
(0, import_react9.useEffect)(
|
|
348
|
+
() => {
|
|
349
|
+
execute();
|
|
350
|
+
},
|
|
351
|
+
deps
|
|
352
|
+
);
|
|
351
353
|
return [{ value, loading, error }, execute];
|
|
352
354
|
}
|
|
353
355
|
|
|
@@ -410,6 +412,21 @@ var LibReact = (() => {
|
|
|
410
412
|
};
|
|
411
413
|
}
|
|
412
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
|
+
|
|
413
430
|
// src/hooks/useFetchIntercept.ts
|
|
414
431
|
function useFetchResponseIntercept(intercept) {
|
|
415
432
|
useMount_default(() => fetchResponseIntercept(intercept));
|
|
@@ -434,23 +451,23 @@ var LibReact = (() => {
|
|
|
434
451
|
}
|
|
435
452
|
|
|
436
453
|
// src/hooks/useMounted.ts
|
|
437
|
-
var
|
|
454
|
+
var import_react13 = __toESM(require_react(), 1);
|
|
438
455
|
function useMounted() {
|
|
439
|
-
const [mounted, setMounted] = (0,
|
|
440
|
-
(0,
|
|
456
|
+
const [mounted, setMounted] = (0, import_react13.useState)(false);
|
|
457
|
+
(0, import_react13.useEffect)(() => setMounted(true), []);
|
|
441
458
|
return mounted;
|
|
442
459
|
}
|
|
443
460
|
|
|
444
461
|
// src/hooks/useWatch.ts
|
|
445
|
-
var
|
|
462
|
+
var import_react14 = __toESM(require_react(), 1);
|
|
446
463
|
function useWatch(source, callback, options = {}) {
|
|
447
|
-
const firstUpdate = (0,
|
|
448
|
-
const then = (0,
|
|
449
|
-
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)(
|
|
450
467
|
() => Array.isArray(source) ? source : [source],
|
|
451
468
|
[source]
|
|
452
469
|
);
|
|
453
|
-
(0,
|
|
470
|
+
(0, import_react14.useEffect)(() => {
|
|
454
471
|
if (!firstUpdate.current)
|
|
455
472
|
recordFirst();
|
|
456
473
|
else
|
|
@@ -978,27 +995,27 @@ var LibReact = (() => {
|
|
|
978
995
|
var { proxyStateMap: proxyStateMap2, snapCache: snapCache2 } = unstable_getInternalStates();
|
|
979
996
|
|
|
980
997
|
// ../../node_modules/.pnpm/valtio@2.1.4_@types+react@18.3.18_react@18.3.1/node_modules/valtio/esm/react.mjs
|
|
981
|
-
var
|
|
998
|
+
var import_react15 = __toESM(require_react(), 1);
|
|
982
999
|
var import_meta2 = {};
|
|
983
1000
|
var useAffectedDebugValue = (state, affected) => {
|
|
984
|
-
const pathList = (0,
|
|
985
|
-
(0,
|
|
1001
|
+
const pathList = (0, import_react15.useRef)(void 0);
|
|
1002
|
+
(0, import_react15.useEffect)(() => {
|
|
986
1003
|
pathList.current = affectedToPathList(state, affected, true);
|
|
987
1004
|
});
|
|
988
|
-
(0,
|
|
1005
|
+
(0, import_react15.useDebugValue)(pathList.current);
|
|
989
1006
|
};
|
|
990
1007
|
var condUseAffectedDebugValue = useAffectedDebugValue;
|
|
991
1008
|
var targetCache = /* @__PURE__ */ new WeakMap();
|
|
992
1009
|
function useSnapshot(proxyObject, options) {
|
|
993
1010
|
const notifyInSync = options == null ? void 0 : options.sync;
|
|
994
|
-
const affected = (0,
|
|
1011
|
+
const affected = (0, import_react15.useMemo)(
|
|
995
1012
|
() => proxyObject && /* @__PURE__ */ new WeakMap(),
|
|
996
1013
|
[proxyObject]
|
|
997
1014
|
);
|
|
998
|
-
const lastSnapshot = (0,
|
|
1015
|
+
const lastSnapshot = (0, import_react15.useRef)(void 0);
|
|
999
1016
|
let inRender = true;
|
|
1000
|
-
const currSnapshot = (0,
|
|
1001
|
-
(0,
|
|
1017
|
+
const currSnapshot = (0, import_react15.useSyncExternalStore)(
|
|
1018
|
+
(0, import_react15.useCallback)(
|
|
1002
1019
|
(callback) => {
|
|
1003
1020
|
const unsub = subscribe(proxyObject, callback, notifyInSync);
|
|
1004
1021
|
callback();
|
|
@@ -1024,18 +1041,18 @@ var LibReact = (() => {
|
|
|
1024
1041
|
() => snapshot(proxyObject)
|
|
1025
1042
|
);
|
|
1026
1043
|
inRender = false;
|
|
1027
|
-
(0,
|
|
1044
|
+
(0, import_react15.useLayoutEffect)(() => {
|
|
1028
1045
|
lastSnapshot.current = currSnapshot;
|
|
1029
1046
|
});
|
|
1030
1047
|
if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production") {
|
|
1031
1048
|
condUseAffectedDebugValue(currSnapshot, affected);
|
|
1032
1049
|
}
|
|
1033
|
-
const proxyCache2 = (0,
|
|
1050
|
+
const proxyCache2 = (0, import_react15.useMemo)(() => /* @__PURE__ */ new WeakMap(), []);
|
|
1034
1051
|
return createProxy(currSnapshot, affected, proxyCache2, targetCache);
|
|
1035
1052
|
}
|
|
1036
1053
|
|
|
1037
1054
|
// src/storage/defineStore.ts
|
|
1038
|
-
var
|
|
1055
|
+
var import_react16 = __toESM(require_react(), 1);
|
|
1039
1056
|
|
|
1040
1057
|
// ../util-core/src/util/json.ts
|
|
1041
1058
|
function jsonTryParse(text) {
|
|
@@ -1096,10 +1113,10 @@ var LibReact = (() => {
|
|
|
1096
1113
|
Object.assign($state, patch);
|
|
1097
1114
|
}
|
|
1098
1115
|
function $signal(fn) {
|
|
1099
|
-
return (0,
|
|
1116
|
+
return (0, import_react16.createElement)(() => fn(useSnapshot($state)));
|
|
1100
1117
|
}
|
|
1101
1118
|
$signal.status = function(fn) {
|
|
1102
|
-
return (0,
|
|
1119
|
+
return (0, import_react16.createElement)(() => fn(useSnapshot($status)));
|
|
1103
1120
|
};
|
|
1104
1121
|
return {
|
|
1105
1122
|
$subscribe,
|
package/dist/index.js
CHANGED
|
@@ -142,10 +142,26 @@ 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) {
|
|
150
166
|
set({ loading: true });
|
|
151
167
|
return fun(...args).then((value) => {
|
|
@@ -160,39 +176,24 @@ function useAsyncCallback(fun) {
|
|
|
160
176
|
}
|
|
161
177
|
|
|
162
178
|
// src/hooks/useAsyncState.ts
|
|
163
|
-
import { useEffect
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
import { useEffect } from "react";
|
|
167
|
-
var useEffectOnce = function(effect) {
|
|
168
|
-
useEffect(effect, []);
|
|
169
|
-
};
|
|
170
|
-
var useEffectOnce_default = useEffectOnce;
|
|
171
|
-
|
|
172
|
-
// ../../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
|
|
173
|
-
var useMount = function(fn) {
|
|
174
|
-
useEffectOnce_default(function() {
|
|
175
|
-
fn();
|
|
176
|
-
});
|
|
177
|
-
};
|
|
178
|
-
var useMount_default = useMount;
|
|
179
|
-
|
|
180
|
-
// src/hooks/useAsyncState.ts
|
|
181
|
-
function useAsyncState(fun, options) {
|
|
182
|
-
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);
|
|
183
182
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
183
|
+
useEffect(
|
|
184
|
+
() => {
|
|
185
|
+
execute();
|
|
186
|
+
},
|
|
187
|
+
deps
|
|
188
|
+
);
|
|
188
189
|
return [{ value, loading, error }, execute];
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
// src/hooks/useDebounce.ts
|
|
192
|
-
import { useEffect as
|
|
193
|
+
import { useEffect as useEffect2, useState as useState4 } from "react";
|
|
193
194
|
function useDebounce(value, delay) {
|
|
194
|
-
const [debouncedValue, setDebouncedValue] =
|
|
195
|
-
|
|
195
|
+
const [debouncedValue, setDebouncedValue] = useState4(value);
|
|
196
|
+
useEffect2(() => {
|
|
196
197
|
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
197
198
|
return () => clearTimeout(handler);
|
|
198
199
|
}, [value, delay]);
|
|
@@ -201,14 +202,14 @@ function useDebounce(value, delay) {
|
|
|
201
202
|
|
|
202
203
|
// src/hooks/useEventBus.ts
|
|
203
204
|
import mitt from "mitt";
|
|
204
|
-
import { useEffect as
|
|
205
|
+
import { useEffect as useEffect3, useRef } from "react";
|
|
205
206
|
var emitter = mitt();
|
|
206
207
|
function useEventBus(key) {
|
|
207
208
|
const onRef = useRef();
|
|
208
209
|
function on(listener) {
|
|
209
210
|
emitter.on(key, listener);
|
|
210
211
|
onRef.current = listener;
|
|
211
|
-
|
|
212
|
+
useEffect3(() => {
|
|
212
213
|
if (!onRef.current)
|
|
213
214
|
return;
|
|
214
215
|
emitter.off(key, onRef.current);
|
|
@@ -230,6 +231,21 @@ function useEventBus(key) {
|
|
|
230
231
|
};
|
|
231
232
|
}
|
|
232
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
|
+
|
|
233
249
|
// src/hooks/useFetchIntercept.ts
|
|
234
250
|
function useFetchResponseIntercept(intercept) {
|
|
235
251
|
useMount_default(() => fetchResponseIntercept(intercept));
|
|
@@ -254,9 +270,9 @@ function fetchRequestIntercept(intercept) {
|
|
|
254
270
|
}
|
|
255
271
|
|
|
256
272
|
// src/hooks/useMounted.ts
|
|
257
|
-
import { useEffect as useEffect5, useState as
|
|
273
|
+
import { useEffect as useEffect5, useState as useState5 } from "react";
|
|
258
274
|
function useMounted() {
|
|
259
|
-
const [mounted, setMounted] =
|
|
275
|
+
const [mounted, setMounted] = useState5(false);
|
|
260
276
|
useEffect5(() => setMounted(true), []);
|
|
261
277
|
return mounted;
|
|
262
278
|
}
|
|
@@ -487,6 +503,7 @@ export {
|
|
|
487
503
|
defineAsyncStore,
|
|
488
504
|
defineStore,
|
|
489
505
|
proxyWithPersistant,
|
|
506
|
+
ref,
|
|
490
507
|
useAsyncCallback,
|
|
491
508
|
useAsyncState,
|
|
492
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",
|