@hairy/react-lib 1.27.0 → 1.29.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 +205 -40
- package/dist/index.d.ts +21 -25
- package/dist/index.global.js +203 -45
- package/dist/index.js +186 -28
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -43,8 +43,14 @@ __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
|
+
tryUseInsertionEffect: () => tryUseInsertionEffect,
|
|
50
|
+
tryUseReducer: () => tryUseReducer,
|
|
51
|
+
tryUseRef: () => tryUseRef,
|
|
52
|
+
tryUseState: () => tryUseState,
|
|
53
|
+
tryUseUpdate: () => tryUseUpdate,
|
|
48
54
|
useAsyncCallback: () => useAsyncCallback,
|
|
49
55
|
useAsyncState: () => useAsyncState,
|
|
50
56
|
useDebounce: () => useDebounce,
|
|
@@ -54,6 +60,7 @@ __export(index_exports, {
|
|
|
54
60
|
useMounted: () => useMounted,
|
|
55
61
|
useStatus: () => useStatus,
|
|
56
62
|
useStore: () => useStore,
|
|
63
|
+
useUpdate: () => useUpdate,
|
|
57
64
|
useWatch: () => useWatch,
|
|
58
65
|
useWhenever: () => useWhenever,
|
|
59
66
|
wrapper: () => wrapper
|
|
@@ -93,6 +100,84 @@ cls.append = function(value, newClass) {
|
|
|
93
100
|
return value ? `${value} ${newClass}` : newClass;
|
|
94
101
|
};
|
|
95
102
|
|
|
103
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
|
|
104
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
105
|
+
var freeGlobal_default = freeGlobal;
|
|
106
|
+
|
|
107
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_root.js
|
|
108
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
109
|
+
var root = freeGlobal_default || freeSelf || Function("return this")();
|
|
110
|
+
var root_default = root;
|
|
111
|
+
|
|
112
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Symbol.js
|
|
113
|
+
var Symbol2 = root_default.Symbol;
|
|
114
|
+
var Symbol_default = Symbol2;
|
|
115
|
+
|
|
116
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
|
|
117
|
+
var objectProto = Object.prototype;
|
|
118
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
119
|
+
var nativeObjectToString = objectProto.toString;
|
|
120
|
+
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
121
|
+
function getRawTag(value) {
|
|
122
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
123
|
+
try {
|
|
124
|
+
value[symToStringTag] = void 0;
|
|
125
|
+
var unmasked = true;
|
|
126
|
+
} catch (e) {
|
|
127
|
+
}
|
|
128
|
+
var result = nativeObjectToString.call(value);
|
|
129
|
+
if (unmasked) {
|
|
130
|
+
if (isOwn) {
|
|
131
|
+
value[symToStringTag] = tag;
|
|
132
|
+
} else {
|
|
133
|
+
delete value[symToStringTag];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
var getRawTag_default = getRawTag;
|
|
139
|
+
|
|
140
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
|
|
141
|
+
var objectProto2 = Object.prototype;
|
|
142
|
+
var nativeObjectToString2 = objectProto2.toString;
|
|
143
|
+
function objectToString(value) {
|
|
144
|
+
return nativeObjectToString2.call(value);
|
|
145
|
+
}
|
|
146
|
+
var objectToString_default = objectToString;
|
|
147
|
+
|
|
148
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
|
|
149
|
+
var nullTag = "[object Null]";
|
|
150
|
+
var undefinedTag = "[object Undefined]";
|
|
151
|
+
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
152
|
+
function baseGetTag(value) {
|
|
153
|
+
if (value == null) {
|
|
154
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
155
|
+
}
|
|
156
|
+
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
157
|
+
}
|
|
158
|
+
var baseGetTag_default = baseGetTag;
|
|
159
|
+
|
|
160
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
|
|
161
|
+
function isObject(value) {
|
|
162
|
+
var type = typeof value;
|
|
163
|
+
return value != null && (type == "object" || type == "function");
|
|
164
|
+
}
|
|
165
|
+
var isObject_default = isObject;
|
|
166
|
+
|
|
167
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isFunction.js
|
|
168
|
+
var asyncTag = "[object AsyncFunction]";
|
|
169
|
+
var funcTag = "[object Function]";
|
|
170
|
+
var genTag = "[object GeneratorFunction]";
|
|
171
|
+
var proxyTag = "[object Proxy]";
|
|
172
|
+
function isFunction(value) {
|
|
173
|
+
if (!isObject_default(value)) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
var tag = baseGetTag_default(value);
|
|
177
|
+
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
178
|
+
}
|
|
179
|
+
var isFunction_default = isFunction;
|
|
180
|
+
|
|
96
181
|
// ../util-core/src/util/noop.ts
|
|
97
182
|
var noop = () => {
|
|
98
183
|
};
|
|
@@ -257,26 +342,86 @@ function Trigger() {
|
|
|
257
342
|
Trigger.id = 0;
|
|
258
343
|
Trigger.tasks = pendingTasks;
|
|
259
344
|
|
|
260
|
-
// src/hooks/
|
|
345
|
+
// src/hooks/tryUseCallback.ts
|
|
261
346
|
var import_react7 = require("react");
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
347
|
+
var tryUseCallback = (callback, deps) => {
|
|
348
|
+
try {
|
|
349
|
+
return (0, import_react7.useCallback)(callback, deps);
|
|
350
|
+
} catch {
|
|
351
|
+
return callback;
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// src/hooks/tryUseEffect.ts
|
|
356
|
+
var import_react8 = require("react");
|
|
357
|
+
var tryUseEffect = (effect, deps) => {
|
|
358
|
+
try {
|
|
359
|
+
(0, import_react8.useEffect)(effect, deps);
|
|
360
|
+
} catch {
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
// src/hooks/tryUseInsertionEffect.ts
|
|
365
|
+
var import_react9 = require("react");
|
|
366
|
+
var tryUseInsertionEffect = (callback, deps) => {
|
|
367
|
+
try {
|
|
368
|
+
(0, import_react9.useInsertionEffect)(callback, deps);
|
|
369
|
+
} catch {
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
// src/hooks/tryUseReducer.ts
|
|
374
|
+
var import_react10 = require("react");
|
|
375
|
+
var tryUseReducer = (reducer, initializerArg, initializer) => {
|
|
376
|
+
try {
|
|
377
|
+
return (0, import_react10.useReducer)(reducer, initializerArg, initializer);
|
|
378
|
+
} catch {
|
|
379
|
+
return [initializerArg, () => {
|
|
380
|
+
}];
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
// src/hooks/tryUseRef.ts
|
|
385
|
+
var import_react11 = require("react");
|
|
386
|
+
var tryUseRef = (initialValue) => {
|
|
387
|
+
try {
|
|
388
|
+
return (0, import_react11.useRef)(initialValue);
|
|
389
|
+
} catch {
|
|
390
|
+
return { current: initialValue };
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
// src/hooks/tryUseState.ts
|
|
395
|
+
var import_react12 = require("react");
|
|
396
|
+
var tryUseState = (initialState) => {
|
|
397
|
+
try {
|
|
398
|
+
return (0, import_react12.useState)(initialState);
|
|
399
|
+
} catch {
|
|
400
|
+
return [isFunction_default(initialState) ? initialState() : initialState, noop];
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
// src/hooks/useUpdate.ts
|
|
405
|
+
var updateReducer = (num) => (num + 1) % 1e6;
|
|
406
|
+
function useUpdate() {
|
|
407
|
+
const [, update] = tryUseReducer(updateReducer, 0);
|
|
408
|
+
return update;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// src/hooks/tryUseUpdate.ts
|
|
412
|
+
function tryUseUpdate() {
|
|
413
|
+
try {
|
|
414
|
+
return useUpdate();
|
|
415
|
+
} catch {
|
|
416
|
+
return () => {
|
|
417
|
+
};
|
|
271
418
|
}
|
|
272
|
-
const [ref3, set] = (0, import_react7.useState)(define(value));
|
|
273
|
-
return ref3;
|
|
274
419
|
}
|
|
275
420
|
|
|
276
421
|
// src/hooks/useAsyncCallback.ts
|
|
277
|
-
var
|
|
422
|
+
var import_react13 = require("react");
|
|
278
423
|
function useAsyncCallback(fun) {
|
|
279
|
-
const [state, set] = (0,
|
|
424
|
+
const [state, set] = (0, import_react13.useState)({ loading: false });
|
|
280
425
|
async function execute(...args) {
|
|
281
426
|
set({ loading: true });
|
|
282
427
|
return fun(...args).then((value) => {
|
|
@@ -291,11 +436,11 @@ function useAsyncCallback(fun) {
|
|
|
291
436
|
}
|
|
292
437
|
|
|
293
438
|
// src/hooks/useAsyncState.ts
|
|
294
|
-
var
|
|
439
|
+
var import_react14 = require("react");
|
|
295
440
|
function useAsyncState(fun, deps = [], options) {
|
|
296
|
-
const [value, set] = (0,
|
|
441
|
+
const [value, set] = (0, import_react14.useState)(options?.initial);
|
|
297
442
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
298
|
-
(0,
|
|
443
|
+
(0, import_react14.useEffect)(
|
|
299
444
|
() => {
|
|
300
445
|
execute();
|
|
301
446
|
},
|
|
@@ -305,10 +450,10 @@ function useAsyncState(fun, deps = [], options) {
|
|
|
305
450
|
}
|
|
306
451
|
|
|
307
452
|
// src/hooks/useDebounce.ts
|
|
308
|
-
var
|
|
453
|
+
var import_react15 = require("react");
|
|
309
454
|
function useDebounce(value, delay) {
|
|
310
|
-
const [debouncedValue, setDebouncedValue] = (0,
|
|
311
|
-
(0,
|
|
455
|
+
const [debouncedValue, setDebouncedValue] = (0, import_react15.useState)(value);
|
|
456
|
+
(0, import_react15.useEffect)(() => {
|
|
312
457
|
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
313
458
|
return () => clearTimeout(handler);
|
|
314
459
|
}, [value, delay]);
|
|
@@ -317,14 +462,14 @@ function useDebounce(value, delay) {
|
|
|
317
462
|
|
|
318
463
|
// src/hooks/useEventBus.ts
|
|
319
464
|
var import_mitt = __toESM(require("mitt"), 1);
|
|
320
|
-
var
|
|
465
|
+
var import_react16 = require("react");
|
|
321
466
|
var emitter = (0, import_mitt.default)();
|
|
322
467
|
function useEventBus(key) {
|
|
323
|
-
const onRef = (0,
|
|
468
|
+
const onRef = (0, import_react16.useRef)();
|
|
324
469
|
function on(listener) {
|
|
325
470
|
emitter.on(key, listener);
|
|
326
471
|
onRef.current = listener;
|
|
327
|
-
(0,
|
|
472
|
+
(0, import_react16.useEffect)(() => {
|
|
328
473
|
if (!onRef.current)
|
|
329
474
|
return;
|
|
330
475
|
emitter.off(key, onRef.current);
|
|
@@ -347,9 +492,9 @@ function useEventBus(key) {
|
|
|
347
492
|
}
|
|
348
493
|
|
|
349
494
|
// ../../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
|
|
495
|
+
var import_react17 = require("react");
|
|
351
496
|
var useEffectOnce = function(effect) {
|
|
352
|
-
(0,
|
|
497
|
+
(0, import_react17.useEffect)(effect, []);
|
|
353
498
|
};
|
|
354
499
|
var useEffectOnce_default = useEffectOnce;
|
|
355
500
|
|
|
@@ -385,23 +530,23 @@ function fetchRequestIntercept(intercept) {
|
|
|
385
530
|
}
|
|
386
531
|
|
|
387
532
|
// src/hooks/useMounted.ts
|
|
388
|
-
var
|
|
533
|
+
var import_react18 = require("react");
|
|
389
534
|
function useMounted() {
|
|
390
|
-
const [mounted, setMounted] = (0,
|
|
391
|
-
(0,
|
|
535
|
+
const [mounted, setMounted] = (0, import_react18.useState)(false);
|
|
536
|
+
(0, import_react18.useEffect)(() => setMounted(true), []);
|
|
392
537
|
return mounted;
|
|
393
538
|
}
|
|
394
539
|
|
|
395
540
|
// src/hooks/useWatch.ts
|
|
396
|
-
var
|
|
541
|
+
var import_react19 = require("react");
|
|
397
542
|
function useWatch(source, callback, options = {}) {
|
|
398
|
-
const firstUpdate = (0,
|
|
399
|
-
const then = (0,
|
|
400
|
-
const deps = (0,
|
|
543
|
+
const firstUpdate = (0, import_react19.useRef)(false);
|
|
544
|
+
const then = (0, import_react19.useRef)();
|
|
545
|
+
const deps = (0, import_react19.useMemo)(
|
|
401
546
|
() => Array.isArray(source) ? source : [source],
|
|
402
547
|
[source]
|
|
403
548
|
);
|
|
404
|
-
(0,
|
|
549
|
+
(0, import_react19.useEffect)(() => {
|
|
405
550
|
if (!firstUpdate.current)
|
|
406
551
|
recordFirst();
|
|
407
552
|
else
|
|
@@ -423,10 +568,10 @@ function useWhenever(source, cb, options) {
|
|
|
423
568
|
}
|
|
424
569
|
|
|
425
570
|
// src/storage/defineAsyncStore.ts
|
|
426
|
-
var
|
|
571
|
+
var import_utils11 = require("valtio/utils");
|
|
427
572
|
|
|
428
573
|
// src/storage/defineStore.ts
|
|
429
|
-
var
|
|
574
|
+
var import_react20 = require("react");
|
|
430
575
|
var import_valtio4 = require("valtio");
|
|
431
576
|
|
|
432
577
|
// src/storage/persistant.ts
|
|
@@ -480,10 +625,10 @@ function defineStore(store, options = {}) {
|
|
|
480
625
|
Object.assign($state, patch);
|
|
481
626
|
}
|
|
482
627
|
function $signal(fn) {
|
|
483
|
-
return (0,
|
|
628
|
+
return (0, import_react20.createElement)(() => fn((0, import_valtio4.useSnapshot)($state)));
|
|
484
629
|
}
|
|
485
630
|
$signal.status = function(fn) {
|
|
486
|
-
return (0,
|
|
631
|
+
return (0, import_react20.createElement)(() => fn((0, import_valtio4.useSnapshot)($status)));
|
|
487
632
|
};
|
|
488
633
|
return {
|
|
489
634
|
$subscribe,
|
|
@@ -574,7 +719,7 @@ function defineAsyncStore(fetch, options = {}) {
|
|
|
574
719
|
},
|
|
575
720
|
{ persist: options.persist ? { id: options.persist, pick: ["value"] } : void 0 }
|
|
576
721
|
);
|
|
577
|
-
(0,
|
|
722
|
+
(0, import_utils11.watch)((get) => {
|
|
578
723
|
const status = get(store.$status.fetch);
|
|
579
724
|
store.$state.error = status.error;
|
|
580
725
|
store.$state.loading = status.loading;
|
|
@@ -610,8 +755,14 @@ function useStore(store) {
|
|
|
610
755
|
defineAsyncStore,
|
|
611
756
|
defineStore,
|
|
612
757
|
proxyWithPersistant,
|
|
613
|
-
ref,
|
|
614
758
|
track,
|
|
759
|
+
tryUseCallback,
|
|
760
|
+
tryUseEffect,
|
|
761
|
+
tryUseInsertionEffect,
|
|
762
|
+
tryUseReducer,
|
|
763
|
+
tryUseRef,
|
|
764
|
+
tryUseState,
|
|
765
|
+
tryUseUpdate,
|
|
615
766
|
useAsyncCallback,
|
|
616
767
|
useAsyncState,
|
|
617
768
|
useDebounce,
|
|
@@ -621,7 +772,21 @@ function useStore(store) {
|
|
|
621
772
|
useMounted,
|
|
622
773
|
useStatus,
|
|
623
774
|
useStore,
|
|
775
|
+
useUpdate,
|
|
624
776
|
useWatch,
|
|
625
777
|
useWhenever,
|
|
626
778
|
wrapper
|
|
627
779
|
});
|
|
780
|
+
/*! Bundled license information:
|
|
781
|
+
|
|
782
|
+
lodash-es/lodash.js:
|
|
783
|
+
(**
|
|
784
|
+
* @license
|
|
785
|
+
* Lodash (Custom Build) <https://lodash.com/>
|
|
786
|
+
* Build: `lodash modularize exports="es" -o ./`
|
|
787
|
+
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
788
|
+
* Released under MIT license <https://lodash.com/license>
|
|
789
|
+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
790
|
+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
791
|
+
*)
|
|
792
|
+
*/
|
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, useInsertionEffect, 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,19 @@ declare namespace Trigger {
|
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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 tryUseInsertionEffect: typeof useInsertionEffect;
|
|
127
|
+
|
|
128
|
+
declare const tryUseReducer: typeof useReducer;
|
|
129
|
+
|
|
130
|
+
declare const tryUseRef: typeof useRef;
|
|
131
|
+
|
|
132
|
+
declare const tryUseState: typeof useState;
|
|
133
|
+
|
|
134
|
+
declare function tryUseUpdate(): () => void;
|
|
141
135
|
|
|
142
136
|
declare function useAsyncCallback<T extends PromiseFn>(fun: T): readonly [boolean, T, Error | undefined];
|
|
143
137
|
|
|
@@ -197,15 +191,17 @@ declare function useFetchRequestIntercept(intercept: FetchRequestInterceptCallba
|
|
|
197
191
|
|
|
198
192
|
declare function useMounted(): boolean;
|
|
199
193
|
|
|
200
|
-
|
|
194
|
+
declare function useUpdate(): () => void;
|
|
195
|
+
|
|
196
|
+
interface UseWatchCallback<T> {
|
|
201
197
|
(value: T): void;
|
|
202
198
|
}
|
|
203
|
-
interface
|
|
199
|
+
interface UseWatchOptions {
|
|
204
200
|
immediate?: boolean;
|
|
205
201
|
}
|
|
206
|
-
declare function useWatch<T>(source: T, callback:
|
|
202
|
+
declare function useWatch<T>(source: T, callback: UseWatchCallback<T>, options?: UseWatchOptions): void;
|
|
207
203
|
|
|
208
|
-
declare function useWhenever<T>(source: T, cb:
|
|
204
|
+
declare function useWhenever<T>(source: T, cb: UseWatchCallback<Exclude<T, null | undefined>>, options?: UseWatchOptions): void;
|
|
209
205
|
|
|
210
206
|
interface PersistantOptions {
|
|
211
207
|
id: string;
|
|
@@ -298,4 +294,4 @@ declare function useStore<S extends object, A extends Actions<S>, G extends Gett
|
|
|
298
294
|
|
|
299
295
|
type PropsWithDetailedHTML<T = HTMLDivElement> = DetailedHTMLProps<HTMLAttributes<T>, T>;
|
|
300
296
|
|
|
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,
|
|
297
|
+
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, tryUseInsertionEffect, 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,14 @@ 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
|
+
tryUseInsertionEffect: () => tryUseInsertionEffect,
|
|
62
|
+
tryUseReducer: () => tryUseReducer,
|
|
63
|
+
tryUseRef: () => tryUseRef,
|
|
64
|
+
tryUseState: () => tryUseState,
|
|
65
|
+
tryUseUpdate: () => tryUseUpdate,
|
|
60
66
|
useAsyncCallback: () => useAsyncCallback,
|
|
61
67
|
useAsyncState: () => useAsyncState,
|
|
62
68
|
useDebounce: () => useDebounce,
|
|
@@ -66,6 +72,7 @@ var LibReact = (() => {
|
|
|
66
72
|
useMounted: () => useMounted,
|
|
67
73
|
useStatus: () => useStatus,
|
|
68
74
|
useStore: () => useStore,
|
|
75
|
+
useUpdate: () => useUpdate,
|
|
69
76
|
useWatch: () => useWatch,
|
|
70
77
|
useWhenever: () => useWhenever,
|
|
71
78
|
wrapper: () => wrapper
|
|
@@ -104,6 +111,84 @@ var LibReact = (() => {
|
|
|
104
111
|
return value ? `${value} ${newClass}` : newClass;
|
|
105
112
|
};
|
|
106
113
|
|
|
114
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
|
|
115
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
116
|
+
var freeGlobal_default = freeGlobal;
|
|
117
|
+
|
|
118
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_root.js
|
|
119
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
120
|
+
var root = freeGlobal_default || freeSelf || Function("return this")();
|
|
121
|
+
var root_default = root;
|
|
122
|
+
|
|
123
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Symbol.js
|
|
124
|
+
var Symbol2 = root_default.Symbol;
|
|
125
|
+
var Symbol_default = Symbol2;
|
|
126
|
+
|
|
127
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
|
|
128
|
+
var objectProto = Object.prototype;
|
|
129
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
130
|
+
var nativeObjectToString = objectProto.toString;
|
|
131
|
+
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
132
|
+
function getRawTag(value) {
|
|
133
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
134
|
+
try {
|
|
135
|
+
value[symToStringTag] = void 0;
|
|
136
|
+
var unmasked = true;
|
|
137
|
+
} catch (e) {
|
|
138
|
+
}
|
|
139
|
+
var result = nativeObjectToString.call(value);
|
|
140
|
+
if (unmasked) {
|
|
141
|
+
if (isOwn) {
|
|
142
|
+
value[symToStringTag] = tag;
|
|
143
|
+
} else {
|
|
144
|
+
delete value[symToStringTag];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
var getRawTag_default = getRawTag;
|
|
150
|
+
|
|
151
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
|
|
152
|
+
var objectProto2 = Object.prototype;
|
|
153
|
+
var nativeObjectToString2 = objectProto2.toString;
|
|
154
|
+
function objectToString(value) {
|
|
155
|
+
return nativeObjectToString2.call(value);
|
|
156
|
+
}
|
|
157
|
+
var objectToString_default = objectToString;
|
|
158
|
+
|
|
159
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
|
|
160
|
+
var nullTag = "[object Null]";
|
|
161
|
+
var undefinedTag = "[object Undefined]";
|
|
162
|
+
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
163
|
+
function baseGetTag(value) {
|
|
164
|
+
if (value == null) {
|
|
165
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
166
|
+
}
|
|
167
|
+
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
168
|
+
}
|
|
169
|
+
var baseGetTag_default = baseGetTag;
|
|
170
|
+
|
|
171
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
|
|
172
|
+
function isObject(value) {
|
|
173
|
+
var type = typeof value;
|
|
174
|
+
return value != null && (type == "object" || type == "function");
|
|
175
|
+
}
|
|
176
|
+
var isObject_default = isObject;
|
|
177
|
+
|
|
178
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isFunction.js
|
|
179
|
+
var asyncTag = "[object AsyncFunction]";
|
|
180
|
+
var funcTag = "[object Function]";
|
|
181
|
+
var genTag = "[object GeneratorFunction]";
|
|
182
|
+
var proxyTag = "[object Proxy]";
|
|
183
|
+
function isFunction(value) {
|
|
184
|
+
if (!isObject_default(value)) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
var tag = baseGetTag_default(value);
|
|
188
|
+
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
189
|
+
}
|
|
190
|
+
var isFunction_default = isFunction;
|
|
191
|
+
|
|
107
192
|
// ../util-core/src/util/noop.ts
|
|
108
193
|
var noop = () => {
|
|
109
194
|
};
|
|
@@ -155,7 +240,7 @@ var LibReact = (() => {
|
|
|
155
240
|
var getProto = Object.getPrototypeOf;
|
|
156
241
|
var objectsToTrack = /* @__PURE__ */ new WeakMap();
|
|
157
242
|
var isObjectToTrack = (obj) => obj && (objectsToTrack.has(obj) ? objectsToTrack.get(obj) : getProto(obj) === Object.prototype || getProto(obj) === Array.prototype);
|
|
158
|
-
var
|
|
243
|
+
var isObject2 = (x) => typeof x === "object" && x !== null;
|
|
159
244
|
var needsToCopyTargetObject = (obj) => Object.values(Object.getOwnPropertyDescriptors(obj)).some((descriptor) => !descriptor.configurable && !descriptor.writable);
|
|
160
245
|
var copyTargetObject = (obj) => {
|
|
161
246
|
if (Array.isArray(obj)) {
|
|
@@ -266,7 +351,7 @@ var LibReact = (() => {
|
|
|
266
351
|
if (isEqual(prevObj, nextObj)) {
|
|
267
352
|
return false;
|
|
268
353
|
}
|
|
269
|
-
if (!
|
|
354
|
+
if (!isObject2(prevObj) || !isObject2(nextObj))
|
|
270
355
|
return true;
|
|
271
356
|
const used = affected.get(getOriginalObject(prevObj));
|
|
272
357
|
if (!used)
|
|
@@ -323,10 +408,10 @@ var LibReact = (() => {
|
|
|
323
408
|
if (seen.has(x)) {
|
|
324
409
|
return;
|
|
325
410
|
}
|
|
326
|
-
if (
|
|
411
|
+
if (isObject2(x)) {
|
|
327
412
|
seen.add(x);
|
|
328
413
|
}
|
|
329
|
-
const used =
|
|
414
|
+
const used = isObject2(x) && affected.get(getOriginalObject(x));
|
|
330
415
|
if (used) {
|
|
331
416
|
(_a = used[HAS_KEY_PROPERTY]) === null || _a === void 0 ? void 0 : _a.forEach((key) => {
|
|
332
417
|
const segment = `:has(${String(key)})`;
|
|
@@ -356,8 +441,8 @@ var LibReact = (() => {
|
|
|
356
441
|
|
|
357
442
|
// ../../node_modules/.pnpm/valtio@2.1.4_@types+react@18.3.18_react@18.3.1/node_modules/valtio/esm/vanilla.mjs
|
|
358
443
|
var import_meta = {};
|
|
359
|
-
var
|
|
360
|
-
var canProxyDefault = (x) =>
|
|
444
|
+
var isObject3 = (x) => typeof x === "object" && x !== null;
|
|
445
|
+
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
446
|
var createSnapshotDefault = (target, version) => {
|
|
362
447
|
const cache = snapCache.get(target);
|
|
363
448
|
if ((cache == null ? void 0 : cache[0]) === version) {
|
|
@@ -411,7 +496,7 @@ var LibReact = (() => {
|
|
|
411
496
|
return true;
|
|
412
497
|
}
|
|
413
498
|
removePropListener(prop);
|
|
414
|
-
if (
|
|
499
|
+
if (isObject3(value)) {
|
|
415
500
|
value = getUntracked(value) || value;
|
|
416
501
|
}
|
|
417
502
|
const nextValue = !proxyStateMap.has(value) && canProxy(value) ? proxy(value) : value;
|
|
@@ -432,7 +517,7 @@ var LibReact = (() => {
|
|
|
432
517
|
var createSnapshot = createSnapshotDefault;
|
|
433
518
|
var createHandler = createHandlerDefault;
|
|
434
519
|
function proxy(baseObject = {}) {
|
|
435
|
-
if (!
|
|
520
|
+
if (!isObject3(baseObject)) {
|
|
436
521
|
throw new Error("object required");
|
|
437
522
|
}
|
|
438
523
|
const found = proxyCache.get(baseObject);
|
|
@@ -970,26 +1055,86 @@ var LibReact = (() => {
|
|
|
970
1055
|
Trigger.id = 0;
|
|
971
1056
|
Trigger.tasks = pendingTasks;
|
|
972
1057
|
|
|
973
|
-
// src/hooks/
|
|
1058
|
+
// src/hooks/tryUseCallback.ts
|
|
974
1059
|
var import_react8 = __toESM(require_react(), 1);
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
return
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1060
|
+
var tryUseCallback = (callback, deps) => {
|
|
1061
|
+
try {
|
|
1062
|
+
return (0, import_react8.useCallback)(callback, deps);
|
|
1063
|
+
} catch {
|
|
1064
|
+
return callback;
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
// src/hooks/tryUseEffect.ts
|
|
1069
|
+
var import_react9 = __toESM(require_react(), 1);
|
|
1070
|
+
var tryUseEffect = (effect, deps) => {
|
|
1071
|
+
try {
|
|
1072
|
+
(0, import_react9.useEffect)(effect, deps);
|
|
1073
|
+
} catch {
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1077
|
+
// src/hooks/tryUseInsertionEffect.ts
|
|
1078
|
+
var import_react10 = __toESM(require_react(), 1);
|
|
1079
|
+
var tryUseInsertionEffect = (callback, deps) => {
|
|
1080
|
+
try {
|
|
1081
|
+
(0, import_react10.useInsertionEffect)(callback, deps);
|
|
1082
|
+
} catch {
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
// src/hooks/tryUseReducer.ts
|
|
1087
|
+
var import_react11 = __toESM(require_react(), 1);
|
|
1088
|
+
var tryUseReducer = (reducer, initializerArg, initializer) => {
|
|
1089
|
+
try {
|
|
1090
|
+
return (0, import_react11.useReducer)(reducer, initializerArg, initializer);
|
|
1091
|
+
} catch {
|
|
1092
|
+
return [initializerArg, () => {
|
|
1093
|
+
}];
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
|
|
1097
|
+
// src/hooks/tryUseRef.ts
|
|
1098
|
+
var import_react12 = __toESM(require_react(), 1);
|
|
1099
|
+
var tryUseRef = (initialValue) => {
|
|
1100
|
+
try {
|
|
1101
|
+
return (0, import_react12.useRef)(initialValue);
|
|
1102
|
+
} catch {
|
|
1103
|
+
return { current: initialValue };
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1106
|
+
|
|
1107
|
+
// src/hooks/tryUseState.ts
|
|
1108
|
+
var import_react13 = __toESM(require_react(), 1);
|
|
1109
|
+
var tryUseState = (initialState) => {
|
|
1110
|
+
try {
|
|
1111
|
+
return (0, import_react13.useState)(initialState);
|
|
1112
|
+
} catch {
|
|
1113
|
+
return [isFunction_default(initialState) ? initialState() : initialState, noop];
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
|
|
1117
|
+
// src/hooks/useUpdate.ts
|
|
1118
|
+
var updateReducer = (num) => (num + 1) % 1e6;
|
|
1119
|
+
function useUpdate() {
|
|
1120
|
+
const [, update] = tryUseReducer(updateReducer, 0);
|
|
1121
|
+
return update;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// src/hooks/tryUseUpdate.ts
|
|
1125
|
+
function tryUseUpdate() {
|
|
1126
|
+
try {
|
|
1127
|
+
return useUpdate();
|
|
1128
|
+
} catch {
|
|
1129
|
+
return () => {
|
|
1130
|
+
};
|
|
984
1131
|
}
|
|
985
|
-
const [ref3, set] = (0, import_react8.useState)(define(value));
|
|
986
|
-
return ref3;
|
|
987
1132
|
}
|
|
988
1133
|
|
|
989
1134
|
// src/hooks/useAsyncCallback.ts
|
|
990
|
-
var
|
|
1135
|
+
var import_react14 = __toESM(require_react(), 1);
|
|
991
1136
|
function useAsyncCallback(fun) {
|
|
992
|
-
const [state, set] = (0,
|
|
1137
|
+
const [state, set] = (0, import_react14.useState)({ loading: false });
|
|
993
1138
|
async function execute(...args) {
|
|
994
1139
|
set({ loading: true });
|
|
995
1140
|
return fun(...args).then((value) => {
|
|
@@ -1004,11 +1149,11 @@ var LibReact = (() => {
|
|
|
1004
1149
|
}
|
|
1005
1150
|
|
|
1006
1151
|
// src/hooks/useAsyncState.ts
|
|
1007
|
-
var
|
|
1152
|
+
var import_react15 = __toESM(require_react(), 1);
|
|
1008
1153
|
function useAsyncState(fun, deps = [], options) {
|
|
1009
|
-
const [value, set] = (0,
|
|
1154
|
+
const [value, set] = (0, import_react15.useState)(options?.initial);
|
|
1010
1155
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
1011
|
-
(0,
|
|
1156
|
+
(0, import_react15.useEffect)(
|
|
1012
1157
|
() => {
|
|
1013
1158
|
execute();
|
|
1014
1159
|
},
|
|
@@ -1018,10 +1163,10 @@ var LibReact = (() => {
|
|
|
1018
1163
|
}
|
|
1019
1164
|
|
|
1020
1165
|
// src/hooks/useDebounce.ts
|
|
1021
|
-
var
|
|
1166
|
+
var import_react16 = __toESM(require_react(), 1);
|
|
1022
1167
|
function useDebounce(value, delay) {
|
|
1023
|
-
const [debouncedValue, setDebouncedValue] = (0,
|
|
1024
|
-
(0,
|
|
1168
|
+
const [debouncedValue, setDebouncedValue] = (0, import_react16.useState)(value);
|
|
1169
|
+
(0, import_react16.useEffect)(() => {
|
|
1025
1170
|
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
1026
1171
|
return () => clearTimeout(handler);
|
|
1027
1172
|
}, [value, delay]);
|
|
@@ -1047,14 +1192,14 @@ var LibReact = (() => {
|
|
|
1047
1192
|
}
|
|
1048
1193
|
|
|
1049
1194
|
// src/hooks/useEventBus.ts
|
|
1050
|
-
var
|
|
1195
|
+
var import_react17 = __toESM(require_react(), 1);
|
|
1051
1196
|
var emitter = mitt_default();
|
|
1052
1197
|
function useEventBus(key) {
|
|
1053
|
-
const onRef = (0,
|
|
1198
|
+
const onRef = (0, import_react17.useRef)();
|
|
1054
1199
|
function on(listener) {
|
|
1055
1200
|
emitter.on(key, listener);
|
|
1056
1201
|
onRef.current = listener;
|
|
1057
|
-
(0,
|
|
1202
|
+
(0, import_react17.useEffect)(() => {
|
|
1058
1203
|
if (!onRef.current)
|
|
1059
1204
|
return;
|
|
1060
1205
|
emitter.off(key, onRef.current);
|
|
@@ -1077,9 +1222,9 @@ var LibReact = (() => {
|
|
|
1077
1222
|
}
|
|
1078
1223
|
|
|
1079
1224
|
// ../../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
|
|
1225
|
+
var import_react18 = __toESM(require_react());
|
|
1081
1226
|
var useEffectOnce = function(effect) {
|
|
1082
|
-
(0,
|
|
1227
|
+
(0, import_react18.useEffect)(effect, []);
|
|
1083
1228
|
};
|
|
1084
1229
|
var useEffectOnce_default = useEffectOnce;
|
|
1085
1230
|
|
|
@@ -1115,23 +1260,23 @@ var LibReact = (() => {
|
|
|
1115
1260
|
}
|
|
1116
1261
|
|
|
1117
1262
|
// src/hooks/useMounted.ts
|
|
1118
|
-
var
|
|
1263
|
+
var import_react19 = __toESM(require_react(), 1);
|
|
1119
1264
|
function useMounted() {
|
|
1120
|
-
const [mounted, setMounted] = (0,
|
|
1121
|
-
(0,
|
|
1265
|
+
const [mounted, setMounted] = (0, import_react19.useState)(false);
|
|
1266
|
+
(0, import_react19.useEffect)(() => setMounted(true), []);
|
|
1122
1267
|
return mounted;
|
|
1123
1268
|
}
|
|
1124
1269
|
|
|
1125
1270
|
// src/hooks/useWatch.ts
|
|
1126
|
-
var
|
|
1271
|
+
var import_react20 = __toESM(require_react(), 1);
|
|
1127
1272
|
function useWatch(source, callback, options = {}) {
|
|
1128
|
-
const firstUpdate = (0,
|
|
1129
|
-
const then = (0,
|
|
1130
|
-
const deps = (0,
|
|
1273
|
+
const firstUpdate = (0, import_react20.useRef)(false);
|
|
1274
|
+
const then = (0, import_react20.useRef)();
|
|
1275
|
+
const deps = (0, import_react20.useMemo)(
|
|
1131
1276
|
() => Array.isArray(source) ? source : [source],
|
|
1132
1277
|
[source]
|
|
1133
1278
|
);
|
|
1134
|
-
(0,
|
|
1279
|
+
(0, import_react20.useEffect)(() => {
|
|
1135
1280
|
if (!firstUpdate.current)
|
|
1136
1281
|
recordFirst();
|
|
1137
1282
|
else
|
|
@@ -1153,7 +1298,7 @@ var LibReact = (() => {
|
|
|
1153
1298
|
}
|
|
1154
1299
|
|
|
1155
1300
|
// src/storage/defineStore.ts
|
|
1156
|
-
var
|
|
1301
|
+
var import_react21 = __toESM(require_react(), 1);
|
|
1157
1302
|
|
|
1158
1303
|
// src/storage/persistant.ts
|
|
1159
1304
|
function proxyWithPersistant(keyOrOptions, initialObject) {
|
|
@@ -1205,10 +1350,10 @@ var LibReact = (() => {
|
|
|
1205
1350
|
Object.assign($state, patch);
|
|
1206
1351
|
}
|
|
1207
1352
|
function $signal(fn) {
|
|
1208
|
-
return (0,
|
|
1353
|
+
return (0, import_react21.createElement)(() => fn(useSnapshot($state)));
|
|
1209
1354
|
}
|
|
1210
1355
|
$signal.status = function(fn) {
|
|
1211
|
-
return (0,
|
|
1356
|
+
return (0, import_react21.createElement)(() => fn(useSnapshot($status)));
|
|
1212
1357
|
};
|
|
1213
1358
|
return {
|
|
1214
1359
|
$subscribe,
|
|
@@ -1320,3 +1465,16 @@ var LibReact = (() => {
|
|
|
1320
1465
|
}
|
|
1321
1466
|
return __toCommonJS(index_exports);
|
|
1322
1467
|
})();
|
|
1468
|
+
/*! Bundled license information:
|
|
1469
|
+
|
|
1470
|
+
lodash-es/lodash.js:
|
|
1471
|
+
(**
|
|
1472
|
+
* @license
|
|
1473
|
+
* Lodash (Custom Build) <https://lodash.com/>
|
|
1474
|
+
* Build: `lodash modularize exports="es" -o ./`
|
|
1475
|
+
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
1476
|
+
* Released under MIT license <https://lodash.com/license>
|
|
1477
|
+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
1478
|
+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
1479
|
+
*)
|
|
1480
|
+
*/
|
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,80 @@ 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/tryUseInsertionEffect.ts
|
|
296
|
+
import { useInsertionEffect } from "react";
|
|
297
|
+
var tryUseInsertionEffect = (callback, deps) => {
|
|
298
|
+
try {
|
|
299
|
+
useInsertionEffect(callback, deps);
|
|
300
|
+
} catch {
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// src/hooks/tryUseReducer.ts
|
|
305
|
+
import { useReducer } from "react";
|
|
306
|
+
var tryUseReducer = (reducer, initializerArg, initializer) => {
|
|
307
|
+
try {
|
|
308
|
+
return useReducer(reducer, initializerArg, initializer);
|
|
309
|
+
} catch {
|
|
310
|
+
return [initializerArg, () => {
|
|
311
|
+
}];
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
// src/hooks/tryUseRef.ts
|
|
316
|
+
import { useRef } from "react";
|
|
317
|
+
var tryUseRef = (initialValue) => {
|
|
318
|
+
try {
|
|
319
|
+
return useRef(initialValue);
|
|
320
|
+
} catch {
|
|
321
|
+
return { current: initialValue };
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
// src/hooks/tryUseState.ts
|
|
199
326
|
import { useState } from "react";
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
327
|
+
var tryUseState = (initialState) => {
|
|
328
|
+
try {
|
|
329
|
+
return useState(initialState);
|
|
330
|
+
} catch {
|
|
331
|
+
return [isFunction_default(initialState) ? initialState() : initialState, noop];
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// src/hooks/useUpdate.ts
|
|
336
|
+
var updateReducer = (num) => (num + 1) % 1e6;
|
|
337
|
+
function useUpdate() {
|
|
338
|
+
const [, update] = tryUseReducer(updateReducer, 0);
|
|
339
|
+
return update;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/hooks/tryUseUpdate.ts
|
|
343
|
+
function tryUseUpdate() {
|
|
344
|
+
try {
|
|
345
|
+
return useUpdate();
|
|
346
|
+
} catch {
|
|
347
|
+
return () => {
|
|
348
|
+
};
|
|
209
349
|
}
|
|
210
|
-
const [ref3, set] = useState(define(value));
|
|
211
|
-
return ref3;
|
|
212
350
|
}
|
|
213
351
|
|
|
214
352
|
// src/hooks/useAsyncCallback.ts
|
|
@@ -229,11 +367,11 @@ function useAsyncCallback(fun) {
|
|
|
229
367
|
}
|
|
230
368
|
|
|
231
369
|
// src/hooks/useAsyncState.ts
|
|
232
|
-
import { useEffect, useState as useState3 } from "react";
|
|
370
|
+
import { useEffect as useEffect2, useState as useState3 } from "react";
|
|
233
371
|
function useAsyncState(fun, deps = [], options) {
|
|
234
372
|
const [value, set] = useState3(options?.initial);
|
|
235
373
|
const [loading, execute, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
236
|
-
|
|
374
|
+
useEffect2(
|
|
237
375
|
() => {
|
|
238
376
|
execute();
|
|
239
377
|
},
|
|
@@ -243,10 +381,10 @@ function useAsyncState(fun, deps = [], options) {
|
|
|
243
381
|
}
|
|
244
382
|
|
|
245
383
|
// src/hooks/useDebounce.ts
|
|
246
|
-
import { useEffect as
|
|
384
|
+
import { useEffect as useEffect3, useState as useState4 } from "react";
|
|
247
385
|
function useDebounce(value, delay) {
|
|
248
386
|
const [debouncedValue, setDebouncedValue] = useState4(value);
|
|
249
|
-
|
|
387
|
+
useEffect3(() => {
|
|
250
388
|
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
251
389
|
return () => clearTimeout(handler);
|
|
252
390
|
}, [value, delay]);
|
|
@@ -255,14 +393,14 @@ function useDebounce(value, delay) {
|
|
|
255
393
|
|
|
256
394
|
// src/hooks/useEventBus.ts
|
|
257
395
|
import mitt from "mitt";
|
|
258
|
-
import { useEffect as
|
|
396
|
+
import { useEffect as useEffect4, useRef as useRef2 } from "react";
|
|
259
397
|
var emitter = mitt();
|
|
260
398
|
function useEventBus(key) {
|
|
261
|
-
const onRef =
|
|
399
|
+
const onRef = useRef2();
|
|
262
400
|
function on(listener) {
|
|
263
401
|
emitter.on(key, listener);
|
|
264
402
|
onRef.current = listener;
|
|
265
|
-
|
|
403
|
+
useEffect4(() => {
|
|
266
404
|
if (!onRef.current)
|
|
267
405
|
return;
|
|
268
406
|
emitter.off(key, onRef.current);
|
|
@@ -285,9 +423,9 @@ function useEventBus(key) {
|
|
|
285
423
|
}
|
|
286
424
|
|
|
287
425
|
// ../../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
|
|
426
|
+
import { useEffect as useEffect5 } from "react";
|
|
289
427
|
var useEffectOnce = function(effect) {
|
|
290
|
-
|
|
428
|
+
useEffect5(effect, []);
|
|
291
429
|
};
|
|
292
430
|
var useEffectOnce_default = useEffectOnce;
|
|
293
431
|
|
|
@@ -323,23 +461,23 @@ function fetchRequestIntercept(intercept) {
|
|
|
323
461
|
}
|
|
324
462
|
|
|
325
463
|
// src/hooks/useMounted.ts
|
|
326
|
-
import { useEffect as
|
|
464
|
+
import { useEffect as useEffect6, useState as useState5 } from "react";
|
|
327
465
|
function useMounted() {
|
|
328
466
|
const [mounted, setMounted] = useState5(false);
|
|
329
|
-
|
|
467
|
+
useEffect6(() => setMounted(true), []);
|
|
330
468
|
return mounted;
|
|
331
469
|
}
|
|
332
470
|
|
|
333
471
|
// src/hooks/useWatch.ts
|
|
334
|
-
import { useEffect as
|
|
472
|
+
import { useEffect as useEffect7, useMemo as useMemo2, useRef as useRef3 } from "react";
|
|
335
473
|
function useWatch(source, callback, options = {}) {
|
|
336
|
-
const firstUpdate =
|
|
337
|
-
const then =
|
|
474
|
+
const firstUpdate = useRef3(false);
|
|
475
|
+
const then = useRef3();
|
|
338
476
|
const deps = useMemo2(
|
|
339
477
|
() => Array.isArray(source) ? source : [source],
|
|
340
478
|
[source]
|
|
341
479
|
);
|
|
342
|
-
|
|
480
|
+
useEffect7(() => {
|
|
343
481
|
if (!firstUpdate.current)
|
|
344
482
|
recordFirst();
|
|
345
483
|
else
|
|
@@ -547,8 +685,14 @@ export {
|
|
|
547
685
|
defineAsyncStore,
|
|
548
686
|
defineStore,
|
|
549
687
|
proxyWithPersistant,
|
|
550
|
-
ref2 as ref,
|
|
551
688
|
track,
|
|
689
|
+
tryUseCallback,
|
|
690
|
+
tryUseEffect,
|
|
691
|
+
tryUseInsertionEffect,
|
|
692
|
+
tryUseReducer,
|
|
693
|
+
tryUseRef,
|
|
694
|
+
tryUseState,
|
|
695
|
+
tryUseUpdate,
|
|
552
696
|
useAsyncCallback,
|
|
553
697
|
useAsyncState,
|
|
554
698
|
useDebounce,
|
|
@@ -558,7 +702,21 @@ export {
|
|
|
558
702
|
useMounted,
|
|
559
703
|
useStatus,
|
|
560
704
|
useStore,
|
|
705
|
+
useUpdate,
|
|
561
706
|
useWatch,
|
|
562
707
|
useWhenever,
|
|
563
708
|
wrapper
|
|
564
709
|
};
|
|
710
|
+
/*! Bundled license information:
|
|
711
|
+
|
|
712
|
+
lodash-es/lodash.js:
|
|
713
|
+
(**
|
|
714
|
+
* @license
|
|
715
|
+
* Lodash (Custom Build) <https://lodash.com/>
|
|
716
|
+
* Build: `lodash modularize exports="es" -o ./`
|
|
717
|
+
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
718
|
+
* Released under MIT license <https://lodash.com/license>
|
|
719
|
+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
720
|
+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
721
|
+
*)
|
|
722
|
+
*/
|
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.29.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.29.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsup",
|