@hairy/react-lib 1.27.0 → 1.28.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 +194 -40
- package/dist/index.d.ts +19 -25
- package/dist/index.global.js +193 -45
- package/dist/index.js +176 -28
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -43,8 +43,13 @@ __export(index_exports, {
|
|
|
43
43
|
defineAsyncStore: () => defineAsyncStore,
|
|
44
44
|
defineStore: () => defineStore,
|
|
45
45
|
proxyWithPersistant: () => proxyWithPersistant,
|
|
46
|
-
ref: () => ref2,
|
|
47
46
|
track: () => track,
|
|
47
|
+
tryUseCallback: () => tryUseCallback,
|
|
48
|
+
tryUseEffect: () => tryUseEffect,
|
|
49
|
+
tryUseReducer: () => tryUseReducer,
|
|
50
|
+
tryUseRef: () => tryUseRef,
|
|
51
|
+
tryUseState: () => tryUseState,
|
|
52
|
+
tryUseUpdate: () => tryUseUpdate,
|
|
48
53
|
useAsyncCallback: () => useAsyncCallback,
|
|
49
54
|
useAsyncState: () => useAsyncState,
|
|
50
55
|
useDebounce: () => useDebounce,
|
|
@@ -54,6 +59,7 @@ __export(index_exports, {
|
|
|
54
59
|
useMounted: () => useMounted,
|
|
55
60
|
useStatus: () => useStatus,
|
|
56
61
|
useStore: () => useStore,
|
|
62
|
+
useUpdate: () => useUpdate,
|
|
57
63
|
useWatch: () => useWatch,
|
|
58
64
|
useWhenever: () => useWhenever,
|
|
59
65
|
wrapper: () => wrapper
|
|
@@ -93,6 +99,84 @@ cls.append = function(value, newClass) {
|
|
|
93
99
|
return value ? `${value} ${newClass}` : newClass;
|
|
94
100
|
};
|
|
95
101
|
|
|
102
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
|
|
103
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
104
|
+
var freeGlobal_default = freeGlobal;
|
|
105
|
+
|
|
106
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_root.js
|
|
107
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
108
|
+
var root = freeGlobal_default || freeSelf || Function("return this")();
|
|
109
|
+
var root_default = root;
|
|
110
|
+
|
|
111
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Symbol.js
|
|
112
|
+
var Symbol2 = root_default.Symbol;
|
|
113
|
+
var Symbol_default = Symbol2;
|
|
114
|
+
|
|
115
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
|
|
116
|
+
var objectProto = Object.prototype;
|
|
117
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
118
|
+
var nativeObjectToString = objectProto.toString;
|
|
119
|
+
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
120
|
+
function getRawTag(value) {
|
|
121
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
122
|
+
try {
|
|
123
|
+
value[symToStringTag] = void 0;
|
|
124
|
+
var unmasked = true;
|
|
125
|
+
} catch (e) {
|
|
126
|
+
}
|
|
127
|
+
var result = nativeObjectToString.call(value);
|
|
128
|
+
if (unmasked) {
|
|
129
|
+
if (isOwn) {
|
|
130
|
+
value[symToStringTag] = tag;
|
|
131
|
+
} else {
|
|
132
|
+
delete value[symToStringTag];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
var getRawTag_default = getRawTag;
|
|
138
|
+
|
|
139
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
|
|
140
|
+
var objectProto2 = Object.prototype;
|
|
141
|
+
var nativeObjectToString2 = objectProto2.toString;
|
|
142
|
+
function objectToString(value) {
|
|
143
|
+
return nativeObjectToString2.call(value);
|
|
144
|
+
}
|
|
145
|
+
var objectToString_default = objectToString;
|
|
146
|
+
|
|
147
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
|
|
148
|
+
var nullTag = "[object Null]";
|
|
149
|
+
var undefinedTag = "[object Undefined]";
|
|
150
|
+
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
151
|
+
function baseGetTag(value) {
|
|
152
|
+
if (value == null) {
|
|
153
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
154
|
+
}
|
|
155
|
+
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
156
|
+
}
|
|
157
|
+
var baseGetTag_default = baseGetTag;
|
|
158
|
+
|
|
159
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
|
|
160
|
+
function isObject(value) {
|
|
161
|
+
var type = typeof value;
|
|
162
|
+
return value != null && (type == "object" || type == "function");
|
|
163
|
+
}
|
|
164
|
+
var isObject_default = isObject;
|
|
165
|
+
|
|
166
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isFunction.js
|
|
167
|
+
var asyncTag = "[object AsyncFunction]";
|
|
168
|
+
var funcTag = "[object Function]";
|
|
169
|
+
var genTag = "[object GeneratorFunction]";
|
|
170
|
+
var proxyTag = "[object Proxy]";
|
|
171
|
+
function isFunction(value) {
|
|
172
|
+
if (!isObject_default(value)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
var tag = baseGetTag_default(value);
|
|
176
|
+
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
177
|
+
}
|
|
178
|
+
var isFunction_default = isFunction;
|
|
179
|
+
|
|
96
180
|
// ../util-core/src/util/noop.ts
|
|
97
181
|
var noop = () => {
|
|
98
182
|
};
|
|
@@ -257,26 +341,77 @@ function Trigger() {
|
|
|
257
341
|
Trigger.id = 0;
|
|
258
342
|
Trigger.tasks = pendingTasks;
|
|
259
343
|
|
|
260
|
-
// src/hooks/
|
|
344
|
+
// src/hooks/tryUseCallback.ts
|
|
261
345
|
var import_react7 = require("react");
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
346
|
+
var tryUseCallback = (callback, deps) => {
|
|
347
|
+
try {
|
|
348
|
+
return (0, import_react7.useCallback)(callback, deps);
|
|
349
|
+
} catch {
|
|
350
|
+
return callback;
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
// src/hooks/tryUseEffect.ts
|
|
355
|
+
var import_react8 = require("react");
|
|
356
|
+
var tryUseEffect = (effect, deps) => {
|
|
357
|
+
try {
|
|
358
|
+
(0, import_react8.useEffect)(effect, deps);
|
|
359
|
+
} catch {
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// src/hooks/tryUseReducer.ts
|
|
364
|
+
var import_react9 = require("react");
|
|
365
|
+
var tryUseReducer = (reducer, initializerArg, initializer) => {
|
|
366
|
+
try {
|
|
367
|
+
return (0, import_react9.useReducer)(reducer, initializerArg, initializer);
|
|
368
|
+
} catch {
|
|
369
|
+
return [initializerArg, () => {
|
|
370
|
+
}];
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
// src/hooks/tryUseRef.ts
|
|
375
|
+
var import_react10 = require("react");
|
|
376
|
+
var tryUseRef = (initialValue) => {
|
|
377
|
+
try {
|
|
378
|
+
return (0, import_react10.useRef)(initialValue);
|
|
379
|
+
} catch {
|
|
380
|
+
return { current: initialValue };
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
// src/hooks/tryUseState.ts
|
|
385
|
+
var import_react11 = require("react");
|
|
386
|
+
var tryUseState = (initialState) => {
|
|
387
|
+
try {
|
|
388
|
+
return (0, import_react11.useState)(initialState);
|
|
389
|
+
} catch {
|
|
390
|
+
return [isFunction_default(initialState) ? initialState() : initialState, noop];
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
// src/hooks/useUpdate.ts
|
|
395
|
+
var updateReducer = (num) => (num + 1) % 1e6;
|
|
396
|
+
function useUpdate() {
|
|
397
|
+
const [, update] = tryUseReducer(updateReducer, 0);
|
|
398
|
+
return update;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// src/hooks/tryUseUpdate.ts
|
|
402
|
+
function tryUseUpdate() {
|
|
403
|
+
try {
|
|
404
|
+
return useUpdate();
|
|
405
|
+
} catch {
|
|
406
|
+
return () => {
|
|
407
|
+
};
|
|
271
408
|
}
|
|
272
|
-
const [ref3, set] = (0, import_react7.useState)(define(value));
|
|
273
|
-
return ref3;
|
|
274
409
|
}
|
|
275
410
|
|
|
276
411
|
// src/hooks/useAsyncCallback.ts
|
|
277
|
-
var
|
|
412
|
+
var import_react12 = require("react");
|
|
278
413
|
function useAsyncCallback(fun) {
|
|
279
|
-
const [state, set] = (0,
|
|
414
|
+
const [state, set] = (0, import_react12.useState)({ loading: false });
|
|
280
415
|
async function execute(...args) {
|
|
281
416
|
set({ loading: true });
|
|
282
417
|
return fun(...args).then((value) => {
|
|
@@ -291,11 +426,11 @@ function useAsyncCallback(fun) {
|
|
|
291
426
|
}
|
|
292
427
|
|
|
293
428
|
// src/hooks/useAsyncState.ts
|
|
294
|
-
var
|
|
429
|
+
var import_react13 = require("react");
|
|
295
430
|
function useAsyncState(fun, deps = [], options) {
|
|
296
|
-
const [value, set] = (0,
|
|
431
|
+
const [value, set] = (0, import_react13.useState)(options?.initial);
|
|
297
432
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
298
|
-
(0,
|
|
433
|
+
(0, import_react13.useEffect)(
|
|
299
434
|
() => {
|
|
300
435
|
execute();
|
|
301
436
|
},
|
|
@@ -305,10 +440,10 @@ function useAsyncState(fun, deps = [], options) {
|
|
|
305
440
|
}
|
|
306
441
|
|
|
307
442
|
// src/hooks/useDebounce.ts
|
|
308
|
-
var
|
|
443
|
+
var import_react14 = require("react");
|
|
309
444
|
function useDebounce(value, delay) {
|
|
310
|
-
const [debouncedValue, setDebouncedValue] = (0,
|
|
311
|
-
(0,
|
|
445
|
+
const [debouncedValue, setDebouncedValue] = (0, import_react14.useState)(value);
|
|
446
|
+
(0, import_react14.useEffect)(() => {
|
|
312
447
|
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
313
448
|
return () => clearTimeout(handler);
|
|
314
449
|
}, [value, delay]);
|
|
@@ -317,14 +452,14 @@ function useDebounce(value, delay) {
|
|
|
317
452
|
|
|
318
453
|
// src/hooks/useEventBus.ts
|
|
319
454
|
var import_mitt = __toESM(require("mitt"), 1);
|
|
320
|
-
var
|
|
455
|
+
var import_react15 = require("react");
|
|
321
456
|
var emitter = (0, import_mitt.default)();
|
|
322
457
|
function useEventBus(key) {
|
|
323
|
-
const onRef = (0,
|
|
458
|
+
const onRef = (0, import_react15.useRef)();
|
|
324
459
|
function on(listener) {
|
|
325
460
|
emitter.on(key, listener);
|
|
326
461
|
onRef.current = listener;
|
|
327
|
-
(0,
|
|
462
|
+
(0, import_react15.useEffect)(() => {
|
|
328
463
|
if (!onRef.current)
|
|
329
464
|
return;
|
|
330
465
|
emitter.off(key, onRef.current);
|
|
@@ -347,9 +482,9 @@ function useEventBus(key) {
|
|
|
347
482
|
}
|
|
348
483
|
|
|
349
484
|
// ../../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
|
|
350
|
-
var
|
|
485
|
+
var import_react16 = require("react");
|
|
351
486
|
var useEffectOnce = function(effect) {
|
|
352
|
-
(0,
|
|
487
|
+
(0, import_react16.useEffect)(effect, []);
|
|
353
488
|
};
|
|
354
489
|
var useEffectOnce_default = useEffectOnce;
|
|
355
490
|
|
|
@@ -385,23 +520,23 @@ function fetchRequestIntercept(intercept) {
|
|
|
385
520
|
}
|
|
386
521
|
|
|
387
522
|
// src/hooks/useMounted.ts
|
|
388
|
-
var
|
|
523
|
+
var import_react17 = require("react");
|
|
389
524
|
function useMounted() {
|
|
390
|
-
const [mounted, setMounted] = (0,
|
|
391
|
-
(0,
|
|
525
|
+
const [mounted, setMounted] = (0, import_react17.useState)(false);
|
|
526
|
+
(0, import_react17.useEffect)(() => setMounted(true), []);
|
|
392
527
|
return mounted;
|
|
393
528
|
}
|
|
394
529
|
|
|
395
530
|
// src/hooks/useWatch.ts
|
|
396
|
-
var
|
|
531
|
+
var import_react18 = require("react");
|
|
397
532
|
function useWatch(source, callback, options = {}) {
|
|
398
|
-
const firstUpdate = (0,
|
|
399
|
-
const then = (0,
|
|
400
|
-
const deps = (0,
|
|
533
|
+
const firstUpdate = (0, import_react18.useRef)(false);
|
|
534
|
+
const then = (0, import_react18.useRef)();
|
|
535
|
+
const deps = (0, import_react18.useMemo)(
|
|
401
536
|
() => Array.isArray(source) ? source : [source],
|
|
402
537
|
[source]
|
|
403
538
|
);
|
|
404
|
-
(0,
|
|
539
|
+
(0, import_react18.useEffect)(() => {
|
|
405
540
|
if (!firstUpdate.current)
|
|
406
541
|
recordFirst();
|
|
407
542
|
else
|
|
@@ -423,10 +558,10 @@ function useWhenever(source, cb, options) {
|
|
|
423
558
|
}
|
|
424
559
|
|
|
425
560
|
// src/storage/defineAsyncStore.ts
|
|
426
|
-
var
|
|
561
|
+
var import_utils11 = require("valtio/utils");
|
|
427
562
|
|
|
428
563
|
// src/storage/defineStore.ts
|
|
429
|
-
var
|
|
564
|
+
var import_react19 = require("react");
|
|
430
565
|
var import_valtio4 = require("valtio");
|
|
431
566
|
|
|
432
567
|
// src/storage/persistant.ts
|
|
@@ -480,10 +615,10 @@ function defineStore(store, options = {}) {
|
|
|
480
615
|
Object.assign($state, patch);
|
|
481
616
|
}
|
|
482
617
|
function $signal(fn) {
|
|
483
|
-
return (0,
|
|
618
|
+
return (0, import_react19.createElement)(() => fn((0, import_valtio4.useSnapshot)($state)));
|
|
484
619
|
}
|
|
485
620
|
$signal.status = function(fn) {
|
|
486
|
-
return (0,
|
|
621
|
+
return (0, import_react19.createElement)(() => fn((0, import_valtio4.useSnapshot)($status)));
|
|
487
622
|
};
|
|
488
623
|
return {
|
|
489
624
|
$subscribe,
|
|
@@ -574,7 +709,7 @@ function defineAsyncStore(fetch, options = {}) {
|
|
|
574
709
|
},
|
|
575
710
|
{ persist: options.persist ? { id: options.persist, pick: ["value"] } : void 0 }
|
|
576
711
|
);
|
|
577
|
-
(0,
|
|
712
|
+
(0, import_utils11.watch)((get) => {
|
|
578
713
|
const status = get(store.$status.fetch);
|
|
579
714
|
store.$state.error = status.error;
|
|
580
715
|
store.$state.loading = status.loading;
|
|
@@ -610,8 +745,13 @@ function useStore(store) {
|
|
|
610
745
|
defineAsyncStore,
|
|
611
746
|
defineStore,
|
|
612
747
|
proxyWithPersistant,
|
|
613
|
-
ref,
|
|
614
748
|
track,
|
|
749
|
+
tryUseCallback,
|
|
750
|
+
tryUseEffect,
|
|
751
|
+
tryUseReducer,
|
|
752
|
+
tryUseRef,
|
|
753
|
+
tryUseState,
|
|
754
|
+
tryUseUpdate,
|
|
615
755
|
useAsyncCallback,
|
|
616
756
|
useAsyncState,
|
|
617
757
|
useDebounce,
|
|
@@ -621,7 +761,21 @@ function useStore(store) {
|
|
|
621
761
|
useMounted,
|
|
622
762
|
useStatus,
|
|
623
763
|
useStore,
|
|
764
|
+
useUpdate,
|
|
624
765
|
useWatch,
|
|
625
766
|
useWhenever,
|
|
626
767
|
wrapper
|
|
627
768
|
});
|
|
769
|
+
/*! Bundled license information:
|
|
770
|
+
|
|
771
|
+
lodash-es/lodash.js:
|
|
772
|
+
(**
|
|
773
|
+
* @license
|
|
774
|
+
* Lodash (Custom Build) <https://lodash.com/>
|
|
775
|
+
* Build: `lodash modularize exports="es" -o ./`
|
|
776
|
+
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
777
|
+
* Released under MIT license <https://lodash.com/license>
|
|
778
|
+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
779
|
+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
780
|
+
*)
|
|
781
|
+
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyFn, BooleanLike, Deferred, PromiseFn, PromiseType } from '@hairy/utils';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
-
import { JSX, ReactNode, PropsWithChildren, ReactElement, FC, ComponentClass,
|
|
3
|
+
import { JSX, ReactNode, PropsWithChildren, ReactElement, FC, ComponentClass, useCallback, useEffect, useReducer, useRef, useState, DetailedHTMLProps, HTMLAttributes } from 'react';
|
|
4
4
|
import * as valtio from 'valtio';
|
|
5
5
|
|
|
6
6
|
type Value = string | boolean | undefined | null;
|
|
@@ -119,25 +119,17 @@ declare namespace Trigger {
|
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
* count.value++
|
|
134
|
-
* console.log(count.value) // 1
|
|
135
|
-
* // or
|
|
136
|
-
* count.value = prev => prev + 1
|
|
137
|
-
* @param value
|
|
138
|
-
*/
|
|
139
|
-
declare function ref<T>(value: T): Ref<T>;
|
|
140
|
-
declare function ref<T>(value?: T): Ref<T | undefined>;
|
|
122
|
+
declare const tryUseCallback: typeof useCallback;
|
|
123
|
+
|
|
124
|
+
declare const tryUseEffect: typeof useEffect;
|
|
125
|
+
|
|
126
|
+
declare const tryUseReducer: typeof useReducer;
|
|
127
|
+
|
|
128
|
+
declare const tryUseRef: typeof useRef;
|
|
129
|
+
|
|
130
|
+
declare const tryUseState: typeof useState;
|
|
131
|
+
|
|
132
|
+
declare function tryUseUpdate(): () => void;
|
|
141
133
|
|
|
142
134
|
declare function useAsyncCallback<T extends PromiseFn>(fun: T): readonly [boolean, T, Error | undefined];
|
|
143
135
|
|
|
@@ -197,15 +189,17 @@ declare function useFetchRequestIntercept(intercept: FetchRequestInterceptCallba
|
|
|
197
189
|
|
|
198
190
|
declare function useMounted(): boolean;
|
|
199
191
|
|
|
200
|
-
|
|
192
|
+
declare function useUpdate(): () => void;
|
|
193
|
+
|
|
194
|
+
interface UseWatchCallback<T> {
|
|
201
195
|
(value: T): void;
|
|
202
196
|
}
|
|
203
|
-
interface
|
|
197
|
+
interface UseWatchOptions {
|
|
204
198
|
immediate?: boolean;
|
|
205
199
|
}
|
|
206
|
-
declare function useWatch<T>(source: T, callback:
|
|
200
|
+
declare function useWatch<T>(source: T, callback: UseWatchCallback<T>, options?: UseWatchOptions): void;
|
|
207
201
|
|
|
208
|
-
declare function useWhenever<T>(source: T, cb:
|
|
202
|
+
declare function useWhenever<T>(source: T, cb: UseWatchCallback<Exclude<T, null | undefined>>, options?: UseWatchOptions): void;
|
|
209
203
|
|
|
210
204
|
interface PersistantOptions {
|
|
211
205
|
id: string;
|
|
@@ -298,4 +292,4 @@ declare function useStore<S extends object, A extends Actions<S>, G extends Gett
|
|
|
298
292
|
|
|
299
293
|
type PropsWithDetailedHTML<T = HTMLDivElement> = DetailedHTMLProps<HTMLAttributes<T>, T>;
|
|
300
294
|
|
|
301
|
-
export { type Argument, type ArgumentArray, type AsyncStoreOptions, Case, type CaseProps, Default, type DefaultProps, Else, type ElseProps, type EventBusListener, type Exposer, type FetchRequestInterceptCallback, type FetchResponseInterceptCallback, If, type IfProps, type InjectComponent, Injector, type InjectorProps, type Mapping, type PersistantOptions, type PropsWithDetailedHTML, type ReadonlyArgumentArray,
|
|
295
|
+
export { type Argument, type ArgumentArray, type AsyncStoreOptions, Case, type CaseProps, Default, type DefaultProps, Else, type ElseProps, type EventBusListener, type Exposer, 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, Trigger, Unless, type UnlessProps, type UseAsyncStateOptions, type UseWatchCallback, type UseWatchOptions, type Value, type WrapperProps, type WrapperTag, cls, defineAsyncStore, defineStore, proxyWithPersistant, track, tryUseCallback, tryUseEffect, tryUseReducer, tryUseRef, tryUseState, tryUseUpdate, useAsyncCallback, useAsyncState, useDebounce, useEventBus, useFetchRequestIntercept, useFetchResponseIntercept, useMounted, useStatus, useStore, useUpdate, useWatch, useWhenever, wrapper };
|
package/dist/index.global.js
CHANGED
|
@@ -55,8 +55,13 @@ var LibReact = (() => {
|
|
|
55
55
|
defineAsyncStore: () => defineAsyncStore,
|
|
56
56
|
defineStore: () => defineStore,
|
|
57
57
|
proxyWithPersistant: () => proxyWithPersistant,
|
|
58
|
-
ref: () => ref2,
|
|
59
58
|
track: () => track,
|
|
59
|
+
tryUseCallback: () => tryUseCallback,
|
|
60
|
+
tryUseEffect: () => tryUseEffect,
|
|
61
|
+
tryUseReducer: () => tryUseReducer,
|
|
62
|
+
tryUseRef: () => tryUseRef,
|
|
63
|
+
tryUseState: () => tryUseState,
|
|
64
|
+
tryUseUpdate: () => tryUseUpdate,
|
|
60
65
|
useAsyncCallback: () => useAsyncCallback,
|
|
61
66
|
useAsyncState: () => useAsyncState,
|
|
62
67
|
useDebounce: () => useDebounce,
|
|
@@ -66,6 +71,7 @@ var LibReact = (() => {
|
|
|
66
71
|
useMounted: () => useMounted,
|
|
67
72
|
useStatus: () => useStatus,
|
|
68
73
|
useStore: () => useStore,
|
|
74
|
+
useUpdate: () => useUpdate,
|
|
69
75
|
useWatch: () => useWatch,
|
|
70
76
|
useWhenever: () => useWhenever,
|
|
71
77
|
wrapper: () => wrapper
|
|
@@ -104,6 +110,84 @@ var LibReact = (() => {
|
|
|
104
110
|
return value ? `${value} ${newClass}` : newClass;
|
|
105
111
|
};
|
|
106
112
|
|
|
113
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
|
|
114
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
115
|
+
var freeGlobal_default = freeGlobal;
|
|
116
|
+
|
|
117
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_root.js
|
|
118
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
119
|
+
var root = freeGlobal_default || freeSelf || Function("return this")();
|
|
120
|
+
var root_default = root;
|
|
121
|
+
|
|
122
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Symbol.js
|
|
123
|
+
var Symbol2 = root_default.Symbol;
|
|
124
|
+
var Symbol_default = Symbol2;
|
|
125
|
+
|
|
126
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
|
|
127
|
+
var objectProto = Object.prototype;
|
|
128
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
129
|
+
var nativeObjectToString = objectProto.toString;
|
|
130
|
+
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
131
|
+
function getRawTag(value) {
|
|
132
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
133
|
+
try {
|
|
134
|
+
value[symToStringTag] = void 0;
|
|
135
|
+
var unmasked = true;
|
|
136
|
+
} catch (e) {
|
|
137
|
+
}
|
|
138
|
+
var result = nativeObjectToString.call(value);
|
|
139
|
+
if (unmasked) {
|
|
140
|
+
if (isOwn) {
|
|
141
|
+
value[symToStringTag] = tag;
|
|
142
|
+
} else {
|
|
143
|
+
delete value[symToStringTag];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
var getRawTag_default = getRawTag;
|
|
149
|
+
|
|
150
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
|
|
151
|
+
var objectProto2 = Object.prototype;
|
|
152
|
+
var nativeObjectToString2 = objectProto2.toString;
|
|
153
|
+
function objectToString(value) {
|
|
154
|
+
return nativeObjectToString2.call(value);
|
|
155
|
+
}
|
|
156
|
+
var objectToString_default = objectToString;
|
|
157
|
+
|
|
158
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
|
|
159
|
+
var nullTag = "[object Null]";
|
|
160
|
+
var undefinedTag = "[object Undefined]";
|
|
161
|
+
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
162
|
+
function baseGetTag(value) {
|
|
163
|
+
if (value == null) {
|
|
164
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
165
|
+
}
|
|
166
|
+
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
167
|
+
}
|
|
168
|
+
var baseGetTag_default = baseGetTag;
|
|
169
|
+
|
|
170
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
|
|
171
|
+
function isObject(value) {
|
|
172
|
+
var type = typeof value;
|
|
173
|
+
return value != null && (type == "object" || type == "function");
|
|
174
|
+
}
|
|
175
|
+
var isObject_default = isObject;
|
|
176
|
+
|
|
177
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isFunction.js
|
|
178
|
+
var asyncTag = "[object AsyncFunction]";
|
|
179
|
+
var funcTag = "[object Function]";
|
|
180
|
+
var genTag = "[object GeneratorFunction]";
|
|
181
|
+
var proxyTag = "[object Proxy]";
|
|
182
|
+
function isFunction(value) {
|
|
183
|
+
if (!isObject_default(value)) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
var tag = baseGetTag_default(value);
|
|
187
|
+
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
188
|
+
}
|
|
189
|
+
var isFunction_default = isFunction;
|
|
190
|
+
|
|
107
191
|
// ../util-core/src/util/noop.ts
|
|
108
192
|
var noop = () => {
|
|
109
193
|
};
|
|
@@ -155,7 +239,7 @@ var LibReact = (() => {
|
|
|
155
239
|
var getProto = Object.getPrototypeOf;
|
|
156
240
|
var objectsToTrack = /* @__PURE__ */ new WeakMap();
|
|
157
241
|
var isObjectToTrack = (obj) => obj && (objectsToTrack.has(obj) ? objectsToTrack.get(obj) : getProto(obj) === Object.prototype || getProto(obj) === Array.prototype);
|
|
158
|
-
var
|
|
242
|
+
var isObject2 = (x) => typeof x === "object" && x !== null;
|
|
159
243
|
var needsToCopyTargetObject = (obj) => Object.values(Object.getOwnPropertyDescriptors(obj)).some((descriptor) => !descriptor.configurable && !descriptor.writable);
|
|
160
244
|
var copyTargetObject = (obj) => {
|
|
161
245
|
if (Array.isArray(obj)) {
|
|
@@ -266,7 +350,7 @@ var LibReact = (() => {
|
|
|
266
350
|
if (isEqual(prevObj, nextObj)) {
|
|
267
351
|
return false;
|
|
268
352
|
}
|
|
269
|
-
if (!
|
|
353
|
+
if (!isObject2(prevObj) || !isObject2(nextObj))
|
|
270
354
|
return true;
|
|
271
355
|
const used = affected.get(getOriginalObject(prevObj));
|
|
272
356
|
if (!used)
|
|
@@ -323,10 +407,10 @@ var LibReact = (() => {
|
|
|
323
407
|
if (seen.has(x)) {
|
|
324
408
|
return;
|
|
325
409
|
}
|
|
326
|
-
if (
|
|
410
|
+
if (isObject2(x)) {
|
|
327
411
|
seen.add(x);
|
|
328
412
|
}
|
|
329
|
-
const used =
|
|
413
|
+
const used = isObject2(x) && affected.get(getOriginalObject(x));
|
|
330
414
|
if (used) {
|
|
331
415
|
(_a = used[HAS_KEY_PROPERTY]) === null || _a === void 0 ? void 0 : _a.forEach((key) => {
|
|
332
416
|
const segment = `:has(${String(key)})`;
|
|
@@ -356,8 +440,8 @@ var LibReact = (() => {
|
|
|
356
440
|
|
|
357
441
|
// ../../node_modules/.pnpm/valtio@2.1.4_@types+react@18.3.18_react@18.3.1/node_modules/valtio/esm/vanilla.mjs
|
|
358
442
|
var import_meta = {};
|
|
359
|
-
var
|
|
360
|
-
var canProxyDefault = (x) =>
|
|
443
|
+
var isObject3 = (x) => typeof x === "object" && x !== null;
|
|
444
|
+
var canProxyDefault = (x) => isObject3(x) && !refSet.has(x) && (Array.isArray(x) || !(Symbol.iterator in x)) && !(x instanceof WeakMap) && !(x instanceof WeakSet) && !(x instanceof Error) && !(x instanceof Number) && !(x instanceof Date) && !(x instanceof String) && !(x instanceof RegExp) && !(x instanceof ArrayBuffer) && !(x instanceof Promise);
|
|
361
445
|
var createSnapshotDefault = (target, version) => {
|
|
362
446
|
const cache = snapCache.get(target);
|
|
363
447
|
if ((cache == null ? void 0 : cache[0]) === version) {
|
|
@@ -411,7 +495,7 @@ var LibReact = (() => {
|
|
|
411
495
|
return true;
|
|
412
496
|
}
|
|
413
497
|
removePropListener(prop);
|
|
414
|
-
if (
|
|
498
|
+
if (isObject3(value)) {
|
|
415
499
|
value = getUntracked(value) || value;
|
|
416
500
|
}
|
|
417
501
|
const nextValue = !proxyStateMap.has(value) && canProxy(value) ? proxy(value) : value;
|
|
@@ -432,7 +516,7 @@ var LibReact = (() => {
|
|
|
432
516
|
var createSnapshot = createSnapshotDefault;
|
|
433
517
|
var createHandler = createHandlerDefault;
|
|
434
518
|
function proxy(baseObject = {}) {
|
|
435
|
-
if (!
|
|
519
|
+
if (!isObject3(baseObject)) {
|
|
436
520
|
throw new Error("object required");
|
|
437
521
|
}
|
|
438
522
|
const found = proxyCache.get(baseObject);
|
|
@@ -970,26 +1054,77 @@ var LibReact = (() => {
|
|
|
970
1054
|
Trigger.id = 0;
|
|
971
1055
|
Trigger.tasks = pendingTasks;
|
|
972
1056
|
|
|
973
|
-
// src/hooks/
|
|
1057
|
+
// src/hooks/tryUseCallback.ts
|
|
974
1058
|
var import_react8 = __toESM(require_react(), 1);
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
return
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1059
|
+
var tryUseCallback = (callback, deps) => {
|
|
1060
|
+
try {
|
|
1061
|
+
return (0, import_react8.useCallback)(callback, deps);
|
|
1062
|
+
} catch {
|
|
1063
|
+
return callback;
|
|
1064
|
+
}
|
|
1065
|
+
};
|
|
1066
|
+
|
|
1067
|
+
// src/hooks/tryUseEffect.ts
|
|
1068
|
+
var import_react9 = __toESM(require_react(), 1);
|
|
1069
|
+
var tryUseEffect = (effect, deps) => {
|
|
1070
|
+
try {
|
|
1071
|
+
(0, import_react9.useEffect)(effect, deps);
|
|
1072
|
+
} catch {
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1076
|
+
// src/hooks/tryUseReducer.ts
|
|
1077
|
+
var import_react10 = __toESM(require_react(), 1);
|
|
1078
|
+
var tryUseReducer = (reducer, initializerArg, initializer) => {
|
|
1079
|
+
try {
|
|
1080
|
+
return (0, import_react10.useReducer)(reducer, initializerArg, initializer);
|
|
1081
|
+
} catch {
|
|
1082
|
+
return [initializerArg, () => {
|
|
1083
|
+
}];
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
|
|
1087
|
+
// src/hooks/tryUseRef.ts
|
|
1088
|
+
var import_react11 = __toESM(require_react(), 1);
|
|
1089
|
+
var tryUseRef = (initialValue) => {
|
|
1090
|
+
try {
|
|
1091
|
+
return (0, import_react11.useRef)(initialValue);
|
|
1092
|
+
} catch {
|
|
1093
|
+
return { current: initialValue };
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
|
|
1097
|
+
// src/hooks/tryUseState.ts
|
|
1098
|
+
var import_react12 = __toESM(require_react(), 1);
|
|
1099
|
+
var tryUseState = (initialState) => {
|
|
1100
|
+
try {
|
|
1101
|
+
return (0, import_react12.useState)(initialState);
|
|
1102
|
+
} catch {
|
|
1103
|
+
return [isFunction_default(initialState) ? initialState() : initialState, noop];
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1106
|
+
|
|
1107
|
+
// src/hooks/useUpdate.ts
|
|
1108
|
+
var updateReducer = (num) => (num + 1) % 1e6;
|
|
1109
|
+
function useUpdate() {
|
|
1110
|
+
const [, update] = tryUseReducer(updateReducer, 0);
|
|
1111
|
+
return update;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
// src/hooks/tryUseUpdate.ts
|
|
1115
|
+
function tryUseUpdate() {
|
|
1116
|
+
try {
|
|
1117
|
+
return useUpdate();
|
|
1118
|
+
} catch {
|
|
1119
|
+
return () => {
|
|
1120
|
+
};
|
|
984
1121
|
}
|
|
985
|
-
const [ref3, set] = (0, import_react8.useState)(define(value));
|
|
986
|
-
return ref3;
|
|
987
1122
|
}
|
|
988
1123
|
|
|
989
1124
|
// src/hooks/useAsyncCallback.ts
|
|
990
|
-
var
|
|
1125
|
+
var import_react13 = __toESM(require_react(), 1);
|
|
991
1126
|
function useAsyncCallback(fun) {
|
|
992
|
-
const [state, set] = (0,
|
|
1127
|
+
const [state, set] = (0, import_react13.useState)({ loading: false });
|
|
993
1128
|
async function execute(...args) {
|
|
994
1129
|
set({ loading: true });
|
|
995
1130
|
return fun(...args).then((value) => {
|
|
@@ -1004,11 +1139,11 @@ var LibReact = (() => {
|
|
|
1004
1139
|
}
|
|
1005
1140
|
|
|
1006
1141
|
// src/hooks/useAsyncState.ts
|
|
1007
|
-
var
|
|
1142
|
+
var import_react14 = __toESM(require_react(), 1);
|
|
1008
1143
|
function useAsyncState(fun, deps = [], options) {
|
|
1009
|
-
const [value, set] = (0,
|
|
1144
|
+
const [value, set] = (0, import_react14.useState)(options?.initial);
|
|
1010
1145
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
1011
|
-
(0,
|
|
1146
|
+
(0, import_react14.useEffect)(
|
|
1012
1147
|
() => {
|
|
1013
1148
|
execute();
|
|
1014
1149
|
},
|
|
@@ -1018,10 +1153,10 @@ var LibReact = (() => {
|
|
|
1018
1153
|
}
|
|
1019
1154
|
|
|
1020
1155
|
// src/hooks/useDebounce.ts
|
|
1021
|
-
var
|
|
1156
|
+
var import_react15 = __toESM(require_react(), 1);
|
|
1022
1157
|
function useDebounce(value, delay) {
|
|
1023
|
-
const [debouncedValue, setDebouncedValue] = (0,
|
|
1024
|
-
(0,
|
|
1158
|
+
const [debouncedValue, setDebouncedValue] = (0, import_react15.useState)(value);
|
|
1159
|
+
(0, import_react15.useEffect)(() => {
|
|
1025
1160
|
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
1026
1161
|
return () => clearTimeout(handler);
|
|
1027
1162
|
}, [value, delay]);
|
|
@@ -1047,14 +1182,14 @@ var LibReact = (() => {
|
|
|
1047
1182
|
}
|
|
1048
1183
|
|
|
1049
1184
|
// src/hooks/useEventBus.ts
|
|
1050
|
-
var
|
|
1185
|
+
var import_react16 = __toESM(require_react(), 1);
|
|
1051
1186
|
var emitter = mitt_default();
|
|
1052
1187
|
function useEventBus(key) {
|
|
1053
|
-
const onRef = (0,
|
|
1188
|
+
const onRef = (0, import_react16.useRef)();
|
|
1054
1189
|
function on(listener) {
|
|
1055
1190
|
emitter.on(key, listener);
|
|
1056
1191
|
onRef.current = listener;
|
|
1057
|
-
(0,
|
|
1192
|
+
(0, import_react16.useEffect)(() => {
|
|
1058
1193
|
if (!onRef.current)
|
|
1059
1194
|
return;
|
|
1060
1195
|
emitter.off(key, onRef.current);
|
|
@@ -1077,9 +1212,9 @@ var LibReact = (() => {
|
|
|
1077
1212
|
}
|
|
1078
1213
|
|
|
1079
1214
|
// ../../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
|
|
1080
|
-
var
|
|
1215
|
+
var import_react17 = __toESM(require_react());
|
|
1081
1216
|
var useEffectOnce = function(effect) {
|
|
1082
|
-
(0,
|
|
1217
|
+
(0, import_react17.useEffect)(effect, []);
|
|
1083
1218
|
};
|
|
1084
1219
|
var useEffectOnce_default = useEffectOnce;
|
|
1085
1220
|
|
|
@@ -1115,23 +1250,23 @@ var LibReact = (() => {
|
|
|
1115
1250
|
}
|
|
1116
1251
|
|
|
1117
1252
|
// src/hooks/useMounted.ts
|
|
1118
|
-
var
|
|
1253
|
+
var import_react18 = __toESM(require_react(), 1);
|
|
1119
1254
|
function useMounted() {
|
|
1120
|
-
const [mounted, setMounted] = (0,
|
|
1121
|
-
(0,
|
|
1255
|
+
const [mounted, setMounted] = (0, import_react18.useState)(false);
|
|
1256
|
+
(0, import_react18.useEffect)(() => setMounted(true), []);
|
|
1122
1257
|
return mounted;
|
|
1123
1258
|
}
|
|
1124
1259
|
|
|
1125
1260
|
// src/hooks/useWatch.ts
|
|
1126
|
-
var
|
|
1261
|
+
var import_react19 = __toESM(require_react(), 1);
|
|
1127
1262
|
function useWatch(source, callback, options = {}) {
|
|
1128
|
-
const firstUpdate = (0,
|
|
1129
|
-
const then = (0,
|
|
1130
|
-
const deps = (0,
|
|
1263
|
+
const firstUpdate = (0, import_react19.useRef)(false);
|
|
1264
|
+
const then = (0, import_react19.useRef)();
|
|
1265
|
+
const deps = (0, import_react19.useMemo)(
|
|
1131
1266
|
() => Array.isArray(source) ? source : [source],
|
|
1132
1267
|
[source]
|
|
1133
1268
|
);
|
|
1134
|
-
(0,
|
|
1269
|
+
(0, import_react19.useEffect)(() => {
|
|
1135
1270
|
if (!firstUpdate.current)
|
|
1136
1271
|
recordFirst();
|
|
1137
1272
|
else
|
|
@@ -1153,7 +1288,7 @@ var LibReact = (() => {
|
|
|
1153
1288
|
}
|
|
1154
1289
|
|
|
1155
1290
|
// src/storage/defineStore.ts
|
|
1156
|
-
var
|
|
1291
|
+
var import_react20 = __toESM(require_react(), 1);
|
|
1157
1292
|
|
|
1158
1293
|
// src/storage/persistant.ts
|
|
1159
1294
|
function proxyWithPersistant(keyOrOptions, initialObject) {
|
|
@@ -1205,10 +1340,10 @@ var LibReact = (() => {
|
|
|
1205
1340
|
Object.assign($state, patch);
|
|
1206
1341
|
}
|
|
1207
1342
|
function $signal(fn) {
|
|
1208
|
-
return (0,
|
|
1343
|
+
return (0, import_react20.createElement)(() => fn(useSnapshot($state)));
|
|
1209
1344
|
}
|
|
1210
1345
|
$signal.status = function(fn) {
|
|
1211
|
-
return (0,
|
|
1346
|
+
return (0, import_react20.createElement)(() => fn(useSnapshot($status)));
|
|
1212
1347
|
};
|
|
1213
1348
|
return {
|
|
1214
1349
|
$subscribe,
|
|
@@ -1320,3 +1455,16 @@ var LibReact = (() => {
|
|
|
1320
1455
|
}
|
|
1321
1456
|
return __toCommonJS(index_exports);
|
|
1322
1457
|
})();
|
|
1458
|
+
/*! Bundled license information:
|
|
1459
|
+
|
|
1460
|
+
lodash-es/lodash.js:
|
|
1461
|
+
(**
|
|
1462
|
+
* @license
|
|
1463
|
+
* Lodash (Custom Build) <https://lodash.com/>
|
|
1464
|
+
* Build: `lodash modularize exports="es" -o ./`
|
|
1465
|
+
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
1466
|
+
* Released under MIT license <https://lodash.com/license>
|
|
1467
|
+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
1468
|
+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
1469
|
+
*)
|
|
1470
|
+
*/
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,84 @@ cls.append = function(value, newClass) {
|
|
|
31
31
|
return value ? `${value} ${newClass}` : newClass;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
|
|
35
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
36
|
+
var freeGlobal_default = freeGlobal;
|
|
37
|
+
|
|
38
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_root.js
|
|
39
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
40
|
+
var root = freeGlobal_default || freeSelf || Function("return this")();
|
|
41
|
+
var root_default = root;
|
|
42
|
+
|
|
43
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Symbol.js
|
|
44
|
+
var Symbol = root_default.Symbol;
|
|
45
|
+
var Symbol_default = Symbol;
|
|
46
|
+
|
|
47
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
|
|
48
|
+
var objectProto = Object.prototype;
|
|
49
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
50
|
+
var nativeObjectToString = objectProto.toString;
|
|
51
|
+
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
52
|
+
function getRawTag(value) {
|
|
53
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
54
|
+
try {
|
|
55
|
+
value[symToStringTag] = void 0;
|
|
56
|
+
var unmasked = true;
|
|
57
|
+
} catch (e) {
|
|
58
|
+
}
|
|
59
|
+
var result = nativeObjectToString.call(value);
|
|
60
|
+
if (unmasked) {
|
|
61
|
+
if (isOwn) {
|
|
62
|
+
value[symToStringTag] = tag;
|
|
63
|
+
} else {
|
|
64
|
+
delete value[symToStringTag];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
var getRawTag_default = getRawTag;
|
|
70
|
+
|
|
71
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
|
|
72
|
+
var objectProto2 = Object.prototype;
|
|
73
|
+
var nativeObjectToString2 = objectProto2.toString;
|
|
74
|
+
function objectToString(value) {
|
|
75
|
+
return nativeObjectToString2.call(value);
|
|
76
|
+
}
|
|
77
|
+
var objectToString_default = objectToString;
|
|
78
|
+
|
|
79
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
|
|
80
|
+
var nullTag = "[object Null]";
|
|
81
|
+
var undefinedTag = "[object Undefined]";
|
|
82
|
+
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
83
|
+
function baseGetTag(value) {
|
|
84
|
+
if (value == null) {
|
|
85
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
86
|
+
}
|
|
87
|
+
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
88
|
+
}
|
|
89
|
+
var baseGetTag_default = baseGetTag;
|
|
90
|
+
|
|
91
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
|
|
92
|
+
function isObject(value) {
|
|
93
|
+
var type = typeof value;
|
|
94
|
+
return value != null && (type == "object" || type == "function");
|
|
95
|
+
}
|
|
96
|
+
var isObject_default = isObject;
|
|
97
|
+
|
|
98
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isFunction.js
|
|
99
|
+
var asyncTag = "[object AsyncFunction]";
|
|
100
|
+
var funcTag = "[object Function]";
|
|
101
|
+
var genTag = "[object GeneratorFunction]";
|
|
102
|
+
var proxyTag = "[object Proxy]";
|
|
103
|
+
function isFunction(value) {
|
|
104
|
+
if (!isObject_default(value)) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
var tag = baseGetTag_default(value);
|
|
108
|
+
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
109
|
+
}
|
|
110
|
+
var isFunction_default = isFunction;
|
|
111
|
+
|
|
34
112
|
// ../util-core/src/util/noop.ts
|
|
35
113
|
var noop = () => {
|
|
36
114
|
};
|
|
@@ -195,20 +273,71 @@ function Trigger() {
|
|
|
195
273
|
Trigger.id = 0;
|
|
196
274
|
Trigger.tasks = pendingTasks;
|
|
197
275
|
|
|
198
|
-
// src/hooks/
|
|
276
|
+
// src/hooks/tryUseCallback.ts
|
|
277
|
+
import { useCallback } from "react";
|
|
278
|
+
var tryUseCallback = (callback, deps) => {
|
|
279
|
+
try {
|
|
280
|
+
return useCallback(callback, deps);
|
|
281
|
+
} catch {
|
|
282
|
+
return callback;
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// src/hooks/tryUseEffect.ts
|
|
287
|
+
import { useEffect } from "react";
|
|
288
|
+
var tryUseEffect = (effect, deps) => {
|
|
289
|
+
try {
|
|
290
|
+
useEffect(effect, deps);
|
|
291
|
+
} catch {
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// src/hooks/tryUseReducer.ts
|
|
296
|
+
import { useReducer } from "react";
|
|
297
|
+
var tryUseReducer = (reducer, initializerArg, initializer) => {
|
|
298
|
+
try {
|
|
299
|
+
return useReducer(reducer, initializerArg, initializer);
|
|
300
|
+
} catch {
|
|
301
|
+
return [initializerArg, () => {
|
|
302
|
+
}];
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// src/hooks/tryUseRef.ts
|
|
307
|
+
import { useRef } from "react";
|
|
308
|
+
var tryUseRef = (initialValue) => {
|
|
309
|
+
try {
|
|
310
|
+
return useRef(initialValue);
|
|
311
|
+
} catch {
|
|
312
|
+
return { current: initialValue };
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// src/hooks/tryUseState.ts
|
|
199
317
|
import { useState } from "react";
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
318
|
+
var tryUseState = (initialState) => {
|
|
319
|
+
try {
|
|
320
|
+
return useState(initialState);
|
|
321
|
+
} catch {
|
|
322
|
+
return [isFunction_default(initialState) ? initialState() : initialState, noop];
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
// src/hooks/useUpdate.ts
|
|
327
|
+
var updateReducer = (num) => (num + 1) % 1e6;
|
|
328
|
+
function useUpdate() {
|
|
329
|
+
const [, update] = tryUseReducer(updateReducer, 0);
|
|
330
|
+
return update;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/hooks/tryUseUpdate.ts
|
|
334
|
+
function tryUseUpdate() {
|
|
335
|
+
try {
|
|
336
|
+
return useUpdate();
|
|
337
|
+
} catch {
|
|
338
|
+
return () => {
|
|
339
|
+
};
|
|
209
340
|
}
|
|
210
|
-
const [ref3, set] = useState(define(value));
|
|
211
|
-
return ref3;
|
|
212
341
|
}
|
|
213
342
|
|
|
214
343
|
// src/hooks/useAsyncCallback.ts
|
|
@@ -229,11 +358,11 @@ function useAsyncCallback(fun) {
|
|
|
229
358
|
}
|
|
230
359
|
|
|
231
360
|
// src/hooks/useAsyncState.ts
|
|
232
|
-
import { useEffect, useState as useState3 } from "react";
|
|
361
|
+
import { useEffect as useEffect2, useState as useState3 } from "react";
|
|
233
362
|
function useAsyncState(fun, deps = [], options) {
|
|
234
363
|
const [value, set] = useState3(options?.initial);
|
|
235
364
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
236
|
-
|
|
365
|
+
useEffect2(
|
|
237
366
|
() => {
|
|
238
367
|
execute();
|
|
239
368
|
},
|
|
@@ -243,10 +372,10 @@ function useAsyncState(fun, deps = [], options) {
|
|
|
243
372
|
}
|
|
244
373
|
|
|
245
374
|
// src/hooks/useDebounce.ts
|
|
246
|
-
import { useEffect as
|
|
375
|
+
import { useEffect as useEffect3, useState as useState4 } from "react";
|
|
247
376
|
function useDebounce(value, delay) {
|
|
248
377
|
const [debouncedValue, setDebouncedValue] = useState4(value);
|
|
249
|
-
|
|
378
|
+
useEffect3(() => {
|
|
250
379
|
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
251
380
|
return () => clearTimeout(handler);
|
|
252
381
|
}, [value, delay]);
|
|
@@ -255,14 +384,14 @@ function useDebounce(value, delay) {
|
|
|
255
384
|
|
|
256
385
|
// src/hooks/useEventBus.ts
|
|
257
386
|
import mitt from "mitt";
|
|
258
|
-
import { useEffect as
|
|
387
|
+
import { useEffect as useEffect4, useRef as useRef2 } from "react";
|
|
259
388
|
var emitter = mitt();
|
|
260
389
|
function useEventBus(key) {
|
|
261
|
-
const onRef =
|
|
390
|
+
const onRef = useRef2();
|
|
262
391
|
function on(listener) {
|
|
263
392
|
emitter.on(key, listener);
|
|
264
393
|
onRef.current = listener;
|
|
265
|
-
|
|
394
|
+
useEffect4(() => {
|
|
266
395
|
if (!onRef.current)
|
|
267
396
|
return;
|
|
268
397
|
emitter.off(key, onRef.current);
|
|
@@ -285,9 +414,9 @@ function useEventBus(key) {
|
|
|
285
414
|
}
|
|
286
415
|
|
|
287
416
|
// ../../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
|
|
288
|
-
import { useEffect as
|
|
417
|
+
import { useEffect as useEffect5 } from "react";
|
|
289
418
|
var useEffectOnce = function(effect) {
|
|
290
|
-
|
|
419
|
+
useEffect5(effect, []);
|
|
291
420
|
};
|
|
292
421
|
var useEffectOnce_default = useEffectOnce;
|
|
293
422
|
|
|
@@ -323,23 +452,23 @@ function fetchRequestIntercept(intercept) {
|
|
|
323
452
|
}
|
|
324
453
|
|
|
325
454
|
// src/hooks/useMounted.ts
|
|
326
|
-
import { useEffect as
|
|
455
|
+
import { useEffect as useEffect6, useState as useState5 } from "react";
|
|
327
456
|
function useMounted() {
|
|
328
457
|
const [mounted, setMounted] = useState5(false);
|
|
329
|
-
|
|
458
|
+
useEffect6(() => setMounted(true), []);
|
|
330
459
|
return mounted;
|
|
331
460
|
}
|
|
332
461
|
|
|
333
462
|
// src/hooks/useWatch.ts
|
|
334
|
-
import { useEffect as
|
|
463
|
+
import { useEffect as useEffect7, useMemo as useMemo2, useRef as useRef3 } from "react";
|
|
335
464
|
function useWatch(source, callback, options = {}) {
|
|
336
|
-
const firstUpdate =
|
|
337
|
-
const then =
|
|
465
|
+
const firstUpdate = useRef3(false);
|
|
466
|
+
const then = useRef3();
|
|
338
467
|
const deps = useMemo2(
|
|
339
468
|
() => Array.isArray(source) ? source : [source],
|
|
340
469
|
[source]
|
|
341
470
|
);
|
|
342
|
-
|
|
471
|
+
useEffect7(() => {
|
|
343
472
|
if (!firstUpdate.current)
|
|
344
473
|
recordFirst();
|
|
345
474
|
else
|
|
@@ -547,8 +676,13 @@ export {
|
|
|
547
676
|
defineAsyncStore,
|
|
548
677
|
defineStore,
|
|
549
678
|
proxyWithPersistant,
|
|
550
|
-
ref2 as ref,
|
|
551
679
|
track,
|
|
680
|
+
tryUseCallback,
|
|
681
|
+
tryUseEffect,
|
|
682
|
+
tryUseReducer,
|
|
683
|
+
tryUseRef,
|
|
684
|
+
tryUseState,
|
|
685
|
+
tryUseUpdate,
|
|
552
686
|
useAsyncCallback,
|
|
553
687
|
useAsyncState,
|
|
554
688
|
useDebounce,
|
|
@@ -558,7 +692,21 @@ export {
|
|
|
558
692
|
useMounted,
|
|
559
693
|
useStatus,
|
|
560
694
|
useStore,
|
|
695
|
+
useUpdate,
|
|
561
696
|
useWatch,
|
|
562
697
|
useWhenever,
|
|
563
698
|
wrapper
|
|
564
699
|
};
|
|
700
|
+
/*! Bundled license information:
|
|
701
|
+
|
|
702
|
+
lodash-es/lodash.js:
|
|
703
|
+
(**
|
|
704
|
+
* @license
|
|
705
|
+
* Lodash (Custom Build) <https://lodash.com/>
|
|
706
|
+
* Build: `lodash modularize exports="es" -o ./`
|
|
707
|
+
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
708
|
+
* Released under MIT license <https://lodash.com/license>
|
|
709
|
+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
710
|
+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
711
|
+
*)
|
|
712
|
+
*/
|
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.28.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.28.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsup",
|