@hairy/react-lib 1.47.0 → 1.50.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.js DELETED
@@ -1,790 +0,0 @@
1
- // src/utils/cls.ts
2
- var hasOwn = {}.hasOwnProperty;
3
- function cls(...args) {
4
- let classes = "";
5
- for (let i = 0; i < args.length; i++) {
6
- const arg = args[i];
7
- if (arg)
8
- classes = cls.append(classes, cls.parse(arg));
9
- }
10
- return classes;
11
- }
12
- cls.parse = function(arg) {
13
- if (typeof arg === "string")
14
- return arg;
15
- if (typeof arg !== "object")
16
- return "";
17
- if (Array.isArray(arg))
18
- return cls.apply(null, arg);
19
- if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]"))
20
- return cls.toString();
21
- let classes = "";
22
- for (const key in arg) {
23
- if (hasOwn.call(arg, key) && arg[key])
24
- classes = cls.append(classes, key);
25
- }
26
- return classes;
27
- };
28
- cls.append = function(value, newClass) {
29
- if (!newClass)
30
- return value;
31
- return value ? `${value} ${newClass}` : newClass;
32
- };
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
-
112
- // ../util-core/src/util/noop.ts
113
- var noop = () => {
114
- };
115
-
116
- // ../util-core/src/util/deferred.ts
117
- var Deferred = class extends Promise {
118
- resolve;
119
- reject;
120
- constructor(executor = noop) {
121
- let _resolve, _reject;
122
- super((resolve_, reject_) => {
123
- _resolve = resolve_;
124
- _reject = reject_;
125
- return executor(resolve_, reject_);
126
- });
127
- this.resolve = (value) => {
128
- _resolve(value);
129
- return this;
130
- };
131
- this.reject = (reason) => {
132
- _reject(reason);
133
- return this;
134
- };
135
- }
136
- };
137
-
138
- // ../util-core/src/util/json.ts
139
- function tryParseJson(text) {
140
- try {
141
- return JSON.parse(text || "");
142
- } catch {
143
- return void 0;
144
- }
145
- }
146
-
147
- // src/utils/track.ts
148
- import { ref } from "valtio";
149
- function track(fn, ...args) {
150
- const deferred = ref(new Deferred());
151
- const exposer = { fn, args, deferred, id: ++Trigger.id };
152
- Trigger.tasks.set(exposer.id, exposer);
153
- deferred.then(() => Trigger.tasks.delete(exposer.id));
154
- return deferred;
155
- }
156
-
157
- // src/utils/wrapper.ts
158
- import { createElement } from "react";
159
- function wrapper(asChild, props, children) {
160
- return asChild ? createElement(asChild, props, children) : children;
161
- }
162
-
163
- // src/components/condition/Case.ts
164
- function Case(props) {
165
- const { cond, children, tag, as: asChild, ...attrs } = props;
166
- return wrapper(tag || asChild, attrs, children);
167
- }
168
-
169
- // src/components/condition/Default.ts
170
- function Default(props) {
171
- const { children, tag, as: asChild, ...attrs } = props;
172
- return wrapper(tag || asChild, attrs, children);
173
- }
174
-
175
- // src/components/condition/If.ts
176
- import { Children } from "react";
177
-
178
- // src/components/condition/Then.ts
179
- function Then(props) {
180
- const { children, cond, else: _else, then, tag, as: asChild, ...attrs } = props;
181
- return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag || asChild, attrs, children);
182
- }
183
-
184
- // src/components/condition/If.ts
185
- function If(props) {
186
- const { then, cond, else: _else, children = props.then, tag, as: asChild, ...attrs } = props;
187
- const elements = Children.toArray(children);
188
- const thenChild = elements.find((c) => c.type === Then);
189
- const elseChild = elements.find((c) => c.type === Else);
190
- const child = thenChild || elseChild ? cond ? thenChild : elseChild : cond ? children : _else;
191
- return wrapper(tag || asChild, attrs, child);
192
- }
193
-
194
- // src/components/condition/Else.ts
195
- function Else(props) {
196
- const { children, tag, as: asChild, ...attrs } = props;
197
- return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag || asChild, attrs, children);
198
- }
199
-
200
- // src/components/condition/Switch.ts
201
- import { Children as Children2, isValidElement } from "react";
202
- function Switch(props) {
203
- const isUseValue = props.value !== void 0;
204
- let matchingCase;
205
- let defaultCase;
206
- Children2.forEach(props.children, (child) => {
207
- if (!isValidElement(child) || matchingCase)
208
- return;
209
- if (child.type === Case) {
210
- const cond = child?.props?.cond;
211
- if (isUseValue ? props.value === cond : cond) {
212
- matchingCase = child;
213
- return;
214
- }
215
- }
216
- if (!defaultCase && child.type === Default)
217
- defaultCase = child;
218
- });
219
- return matchingCase ?? defaultCase ?? null;
220
- }
221
-
222
- // src/components/condition/Unless.ts
223
- import { Children as Children3 } from "react";
224
- function Unless(props) {
225
- const { cond, then, else: _else, tag, as: asChild, children = props.then, ...attrs } = props;
226
- const elements = Children3.toArray(children);
227
- const thenChild = elements.find((c) => c.type === Then);
228
- const elseChild = elements.find((c) => c.type === Else);
229
- const child = thenChild || elseChild ? !cond ? elseChild : thenChild : !cond ? children : _else;
230
- return wrapper(tag || asChild, attrs, child);
231
- }
232
-
233
- // src/components/utils/Injector.ts
234
- import { createElement as createElement2, useMemo } from "react";
235
- function Injector(props) {
236
- const installs = useMemo(
237
- () => props.install.map(repack).reverse(),
238
- [props.install]
239
- );
240
- return installs.reduce(
241
- (child, { component: Component, props: props2 }) => createElement2(Component, props2, child),
242
- props.children
243
- );
244
- }
245
- function repack(c) {
246
- return c.component ? c : { component: c };
247
- }
248
-
249
- // src/components/utils/Trigger.ts
250
- import { createElement as createElement3 } from "react";
251
- import { useSnapshot } from "valtio";
252
- import { proxyMap } from "valtio/utils";
253
- var pendingTasks = proxyMap();
254
- function createTracker(exposer) {
255
- const Component = () => {
256
- try {
257
- exposer.deferred.resolve(exposer.fn(...exposer.args));
258
- } catch (error) {
259
- exposer.deferred.reject(error);
260
- }
261
- return null;
262
- };
263
- Component.key = exposer.id;
264
- return Component;
265
- }
266
- function renderTracker(Tracker) {
267
- return createElement3(Tracker, { key: Tracker.key });
268
- }
269
- function Trigger() {
270
- const values = [...useSnapshot(pendingTasks).values()];
271
- return values.map(createTracker).map(renderTracker);
272
- }
273
- Trigger.id = 0;
274
- Trigger.tasks = pendingTasks;
275
-
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
326
- import { useState } from "react";
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
- };
349
- }
350
- }
351
-
352
- // src/hooks/useAsyncCallback.ts
353
- import { useState as useState2 } from "react";
354
- function useAsyncCallback(fun) {
355
- const [state, set] = useState2({ loading: false });
356
- async function refetch(...args) {
357
- set({ loading: true });
358
- return fun(...args).then((value) => {
359
- set({ loading: false });
360
- return value;
361
- }).catch((err) => {
362
- set({ loading: false, error: err });
363
- return Promise.reject(err);
364
- });
365
- }
366
- return [state.loading, refetch, state.error];
367
- }
368
-
369
- // src/hooks/useAsyncState.ts
370
- import { useEffect as useEffect2, useState as useState3 } from "react";
371
- function useAsyncState(fun, deps = [], options) {
372
- const [value, set] = useState3(options?.initial);
373
- const [loading, refetch, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
374
- useEffect2(
375
- () => {
376
- refetch();
377
- },
378
- deps
379
- );
380
- return [{ value, loading, error }, refetch];
381
- }
382
-
383
- // src/hooks/useDebounce.ts
384
- import { useEffect as useEffect3, useState as useState4 } from "react";
385
- function useDebounce(value, delay) {
386
- const [debouncedValue, setDebouncedValue] = useState4(value);
387
- useEffect3(() => {
388
- const handler = setTimeout(() => setDebouncedValue(value), delay);
389
- return () => clearTimeout(handler);
390
- }, [value, delay]);
391
- return debouncedValue;
392
- }
393
-
394
- // src/hooks/useEventBus.ts
395
- import mitt from "mitt";
396
- import { useEffect as useEffect4, useRef as useRef2 } from "react";
397
- var emitter = mitt();
398
- function useEventBus(key) {
399
- const onRef = useRef2(void 0);
400
- function on(listener) {
401
- emitter.on(key, listener);
402
- onRef.current = listener;
403
- useEffect4(() => {
404
- if (!onRef.current)
405
- return;
406
- emitter.off(key, onRef.current);
407
- emitter.on(key, listener);
408
- onRef.current = listener;
409
- return () => emitter.off(key, listener);
410
- }, [listener]);
411
- }
412
- function emit(event) {
413
- emitter.emit(key, event);
414
- }
415
- function off(listener) {
416
- emitter.off(key, listener);
417
- }
418
- return {
419
- on,
420
- emit,
421
- off
422
- };
423
- }
424
-
425
- // ../../node_modules/.pnpm/react-use@17.6.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-use/esm/useEffectOnce.js
426
- import { useEffect as useEffect5 } from "react";
427
- var useEffectOnce = function(effect) {
428
- useEffect5(effect, []);
429
- };
430
- var useEffectOnce_default = useEffectOnce;
431
-
432
- // ../../node_modules/.pnpm/react-use@17.6.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-use/esm/useMount.js
433
- var useMount = function(fn) {
434
- useEffectOnce_default(function() {
435
- fn();
436
- });
437
- };
438
- var useMount_default = useMount;
439
-
440
- // src/hooks/useFetchIntercept.ts
441
- function useFetchResponseIntercept(intercept) {
442
- useMount_default(() => fetchResponseIntercept(intercept));
443
- }
444
- function useFetchRequestIntercept(intercept) {
445
- useMount_default(() => fetchRequestIntercept(intercept));
446
- }
447
- function fetchResponseIntercept(intercept) {
448
- const { fetch: originalFetch } = window;
449
- window.fetch = async (...args) => {
450
- const [resource, config] = args;
451
- const response = await originalFetch(resource, config);
452
- return intercept(response, config);
453
- };
454
- }
455
- function fetchRequestIntercept(intercept) {
456
- const { fetch: originalFetch } = window;
457
- window.fetch = async (...args) => {
458
- const [resource, config] = args;
459
- return intercept(originalFetch, resource, config);
460
- };
461
- }
462
-
463
- // src/hooks/useMounted.ts
464
- import { useEffect as useEffect6, useState as useState5 } from "react";
465
- function useMounted() {
466
- const [mounted, setMounted] = useState5(false);
467
- useEffect6(() => setMounted(true), []);
468
- return mounted;
469
- }
470
-
471
- // src/hooks/useOffsetPagination.ts
472
- import { useMemo as useMemo3, useState as useState6 } from "react";
473
-
474
- // src/hooks/useWatch.ts
475
- import { useEffect as useEffect8, useMemo as useMemo2, useRef as useRef4 } from "react";
476
-
477
- // src/hooks/usePrevious.ts
478
- import { useEffect as useEffect7, useRef as useRef3 } from "react";
479
- function usePrevious(value) {
480
- const ref2 = useRef3(void 0);
481
- useEffect7(() => {
482
- ref2.current = value;
483
- });
484
- return ref2.current;
485
- }
486
-
487
- // src/hooks/useWatch.ts
488
- function useWatch(source, callback, options = {}) {
489
- const firstUpdate = useRef4(false);
490
- const then = useRef4(void 0);
491
- const oldValue = usePrevious(source);
492
- const deps = useMemo2(
493
- () => Array.isArray(source) ? source : [source],
494
- [source]
495
- );
496
- useEffect8(() => {
497
- if (!firstUpdate.current)
498
- recordFirst();
499
- else
500
- callback(source, oldValue);
501
- }, deps);
502
- async function recordFirst() {
503
- if (then.current)
504
- return;
505
- then.current = Promise.resolve(source);
506
- then.current.then(() => firstUpdate.current = true);
507
- if (options.immediate)
508
- then.current.then((value) => callback(value, oldValue));
509
- }
510
- }
511
-
512
- // src/hooks/useOffsetPagination.ts
513
- function useOffsetPagination(options) {
514
- const [page, setPage] = useState6(options.page || 1);
515
- const [pageSize, setPageSize] = useState6(options.pageSize || 10);
516
- const total = options.total || 0;
517
- const pageCount = useMemo3(() => Math.max(1, Math.ceil(total / pageSize)), [total, pageSize]);
518
- const isFirstPage = useMemo3(() => page === 1, [page]);
519
- const isLastPage = useMemo3(() => page === pageCount, [page, pageCount]);
520
- function next() {
521
- setPage((page2) => Math.min(pageCount, page2 + 1));
522
- }
523
- function prev() {
524
- setPage((page2) => Math.max(1, page2 - 1));
525
- }
526
- function pageChange(page2) {
527
- setPage(() => Math.max(1, Math.min(page2, pageCount)));
528
- }
529
- function pageSizeChange(limit) {
530
- setPageSize(limit);
531
- pageChange(1);
532
- }
533
- const pagination = {
534
- next,
535
- prev,
536
- page,
537
- pageSize,
538
- isFirstPage,
539
- pageSizeChange,
540
- pageChange,
541
- isLastPage,
542
- pageCount,
543
- total
544
- };
545
- useWatch(page, () => options.onChange?.(pagination));
546
- useWatch(pageSize, () => options.onPageSizeChange?.(pagination));
547
- useWatch(pageCount, () => options.onPageCountChange?.(pagination));
548
- return pagination;
549
- }
550
-
551
- // src/hooks/useWhenever.ts
552
- function useWhenever(source, cb, options) {
553
- useWatch(source, (value, oldValue) => value && cb(value, oldValue), options);
554
- }
555
-
556
- // src/storage/defineStore.ts
557
- import { createElement as createElement4 } from "react";
558
- import { proxy as proxy2, subscribe as subscribe2, useSnapshot as useSnapshot2 } from "valtio";
559
-
560
- // src/storage/persistant.ts
561
- import { proxy, subscribe } from "valtio";
562
- function proxyWithPersistant(keyOrOptions, initialObject) {
563
- let options;
564
- if (typeof keyOrOptions === "string") {
565
- options = { id: keyOrOptions };
566
- } else {
567
- options = { ...keyOrOptions };
568
- }
569
- const storage = options.storage || (typeof localStorage !== "undefined" ? localStorage : void 0);
570
- typeof keyOrOptions === "string" && (keyOrOptions = { id: keyOrOptions });
571
- const state = proxy(tryParseJson(storage?.getItem(options.id)) || initialObject);
572
- subscribe(state, () => {
573
- const pick = options.pick || Object.keys(state);
574
- const statePick = {};
575
- for (const key of pick)
576
- statePick[key] = state[key];
577
- storage?.setItem(options.id, JSON.stringify(statePick));
578
- });
579
- return state;
580
- }
581
-
582
- // src/storage/utils/index.ts
583
- function track2(action, status) {
584
- let loadings = 0;
585
- const tracking = () => loadings++ === 0 && (status.loading = true);
586
- const done = () => !--loadings && (status.loading = false);
587
- const fulfilled = (value) => {
588
- status.finished = true;
589
- done();
590
- return value;
591
- };
592
- const rejected = (error) => {
593
- status.error = error;
594
- done();
595
- throw error;
596
- };
597
- return function(...args) {
598
- tracking();
599
- try {
600
- const value = action(...args);
601
- return value instanceof Promise ? value.then(fulfilled, rejected) : fulfilled(value);
602
- } catch (error) {
603
- rejected(error);
604
- }
605
- };
606
- }
607
-
608
- // src/storage/defineStore.ts
609
- function defineStore(store, options = {}) {
610
- const state = typeof store.state === "function" ? store.state() : store.state;
611
- const getters = store.getters || {};
612
- const actions = store.actions || {};
613
- const status = {};
614
- status.finished = false;
615
- status.loading = false;
616
- status.error = null;
617
- const $status = proxy2(status);
618
- const $state = options.persist ? proxyWithPersistant(options.persist, state) : proxy2(state);
619
- const $actions = {};
620
- const $getters = {};
621
- setupActions($state, actions, $actions, $status);
622
- setupGetters(state, $state, getters, $getters);
623
- setupStatus($actions, $status);
624
- function $subscribe(listener) {
625
- return subscribe2($state, () => listener($state));
626
- }
627
- $subscribe.status = function(listener) {
628
- return subscribe2($status, () => listener($status));
629
- };
630
- function $patch(patch) {
631
- if (typeof patch === "function")
632
- patch($state);
633
- else
634
- Object.assign($state, patch);
635
- }
636
- function $signal(fn) {
637
- return createElement4(() => fn(useSnapshot2($state)));
638
- }
639
- $signal.status = function(fn) {
640
- return createElement4(() => fn(useSnapshot2($status)));
641
- };
642
- return {
643
- $subscribe,
644
- $patch,
645
- $state,
646
- $status,
647
- $actions,
648
- $getters,
649
- $signal,
650
- ...$actions
651
- };
652
- }
653
- function setupActions($state, actions, $actions, $status) {
654
- for (const key in actions) {
655
- $status[key] = { finished: false, loading: false, error: null };
656
- $actions[key] = track2(actions[key].bind($state), $status[key]);
657
- Object.defineProperty($state, key, {
658
- get: () => $actions[key]
659
- });
660
- }
661
- }
662
- function setupGetters(state, $state, getters, $getters) {
663
- for (const key in getters) {
664
- Object.defineProperty(state, key, {
665
- get: () => getters[key].call($state),
666
- enumerable: true
667
- });
668
- Object.defineProperty($getters, key, {
669
- get: () => state[key],
670
- enumerable: true
671
- });
672
- }
673
- }
674
- function setupStatus($actions, $status) {
675
- Object.defineProperty($status, "loading", {
676
- get: () => Object.keys($actions).some((key) => $status[key].loading),
677
- enumerable: true
678
- });
679
- Object.defineProperty($status, "finished", {
680
- get: () => Object.keys($actions).every((key) => $status[key].finished),
681
- enumerable: true
682
- });
683
- Object.defineProperty($status, "error", {
684
- get: () => Object.keys($actions).find((key) => $status[key].error),
685
- enumerable: true
686
- });
687
- }
688
-
689
- // src/storage/defineStoreAsync.ts
690
- import { watch } from "valtio/utils";
691
- function defineStoreAsync(fetch, options = {}) {
692
- let persist;
693
- if (typeof options.persist === "string") {
694
- persist = { id: options.persist, pick: ["value"] };
695
- }
696
- if (typeof options.persist === "object") {
697
- persist = { ...options.persist, pick: ["value"] };
698
- }
699
- const store = defineStore(
700
- {
701
- state: () => ({
702
- value: options.initial,
703
- error: void 0,
704
- loading: false,
705
- finished: false
706
- }),
707
- actions: {
708
- async refetch(...args) {
709
- return this.value = await fetch(...args);
710
- },
711
- reset(value) {
712
- this.value = value || options.initial;
713
- }
714
- }
715
- },
716
- { persist }
717
- );
718
- watch((get) => {
719
- const status = get(store.$status.refetch);
720
- store.$state.error = status.error;
721
- store.$state.loading = status.loading;
722
- store.$state.finished = status.finished;
723
- });
724
- options.immediate && store.refetch();
725
- return store;
726
- }
727
- var defienAsyncStore = defineStoreAsync;
728
-
729
- // src/storage/useStatus.tsx
730
- import { useSnapshot as useSnapshot3 } from "valtio";
731
- function useStatus(store) {
732
- return useSnapshot3(store.$status);
733
- }
734
-
735
- // src/storage/useStore.ts
736
- import { useSnapshot as useSnapshot4 } from "valtio";
737
- function useStore(store) {
738
- return useSnapshot4(store.$state);
739
- }
740
- export {
741
- Case,
742
- Default,
743
- Else,
744
- If,
745
- Injector,
746
- Switch,
747
- Then,
748
- Trigger,
749
- Unless,
750
- cls,
751
- defienAsyncStore,
752
- defineStore,
753
- defineStoreAsync,
754
- proxyWithPersistant,
755
- track,
756
- tryUseCallback,
757
- tryUseEffect,
758
- tryUseInsertionEffect,
759
- tryUseReducer,
760
- tryUseRef,
761
- tryUseState,
762
- tryUseUpdate,
763
- useAsyncCallback,
764
- useAsyncState,
765
- useDebounce,
766
- useEventBus,
767
- useFetchRequestIntercept,
768
- useFetchResponseIntercept,
769
- useMounted,
770
- useOffsetPagination,
771
- useStatus,
772
- useStore,
773
- useUpdate,
774
- useWatch,
775
- useWhenever,
776
- wrapper
777
- };
778
- /*! Bundled license information:
779
-
780
- lodash-es/lodash.js:
781
- (**
782
- * @license
783
- * Lodash (Custom Build) <https://lodash.com/>
784
- * Build: `lodash modularize exports="es" -o ./`
785
- * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
786
- * Released under MIT license <https://lodash.com/license>
787
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
788
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
789
- *)
790
- */