@hairy/react-lib 1.46.0 → 1.49.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/LICENSE.md +21 -21
- package/README.md +36 -36
- package/dist/index.cjs +411 -769
- package/dist/index.d.cts +257 -0
- package/dist/index.d.mts +257 -0
- package/dist/index.mjs +446 -0
- package/package.json +26 -21
- package/dist/index.d.ts +0 -374
- package/dist/index.global.js +0 -1550
- package/dist/index.js +0 -790
package/dist/index.cjs
CHANGED
|
@@ -1,862 +1,504 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
9
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
19
22
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Then: () => Then,
|
|
40
|
-
Trigger: () => Trigger,
|
|
41
|
-
Unless: () => Unless,
|
|
42
|
-
cls: () => cls,
|
|
43
|
-
defienAsyncStore: () => defienAsyncStore,
|
|
44
|
-
defineStore: () => defineStore,
|
|
45
|
-
defineStoreAsync: () => defineStoreAsync,
|
|
46
|
-
proxyWithPersistant: () => proxyWithPersistant,
|
|
47
|
-
track: () => track,
|
|
48
|
-
tryUseCallback: () => tryUseCallback,
|
|
49
|
-
tryUseEffect: () => tryUseEffect,
|
|
50
|
-
tryUseInsertionEffect: () => tryUseInsertionEffect,
|
|
51
|
-
tryUseReducer: () => tryUseReducer,
|
|
52
|
-
tryUseRef: () => tryUseRef,
|
|
53
|
-
tryUseState: () => tryUseState,
|
|
54
|
-
tryUseUpdate: () => tryUseUpdate,
|
|
55
|
-
useAsyncCallback: () => useAsyncCallback,
|
|
56
|
-
useAsyncState: () => useAsyncState,
|
|
57
|
-
useDebounce: () => useDebounce,
|
|
58
|
-
useEventBus: () => useEventBus,
|
|
59
|
-
useFetchRequestIntercept: () => useFetchRequestIntercept,
|
|
60
|
-
useFetchResponseIntercept: () => useFetchResponseIntercept,
|
|
61
|
-
useMounted: () => useMounted,
|
|
62
|
-
useOffsetPagination: () => useOffsetPagination,
|
|
63
|
-
useStatus: () => useStatus,
|
|
64
|
-
useStore: () => useStore,
|
|
65
|
-
useUpdate: () => useUpdate,
|
|
66
|
-
useWatch: () => useWatch,
|
|
67
|
-
useWhenever: () => useWhenever,
|
|
68
|
-
wrapper: () => wrapper
|
|
69
|
-
});
|
|
70
|
-
module.exports = __toCommonJS(index_exports);
|
|
71
|
-
|
|
72
|
-
// src/utils/cls.ts
|
|
73
|
-
var hasOwn = {}.hasOwnProperty;
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
let _hairy_utils = require("@hairy/utils");
|
|
30
|
+
let valtio = require("valtio");
|
|
31
|
+
let react = require("react");
|
|
32
|
+
let valtio_utils = require("valtio/utils");
|
|
33
|
+
let mitt = require("mitt");
|
|
34
|
+
mitt = __toESM(mitt);
|
|
35
|
+
let react_use = require("react-use");
|
|
36
|
+
|
|
37
|
+
//#region src/utils/cls.ts
|
|
38
|
+
const hasOwn = {}.hasOwnProperty;
|
|
39
|
+
/**
|
|
40
|
+
* A simple JavaScript utility for conditionally joining classNames together.
|
|
41
|
+
*/
|
|
74
42
|
function cls(...args) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return classes;
|
|
43
|
+
let classes = "";
|
|
44
|
+
for (let i = 0; i < args.length; i++) {
|
|
45
|
+
const arg = args[i];
|
|
46
|
+
if (arg) classes = cls.append(classes, cls.parse(arg));
|
|
47
|
+
}
|
|
48
|
+
return classes;
|
|
82
49
|
}
|
|
83
50
|
cls.parse = function(arg) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return cls.toString();
|
|
92
|
-
let classes = "";
|
|
93
|
-
for (const key in arg) {
|
|
94
|
-
if (hasOwn.call(arg, key) && arg[key])
|
|
95
|
-
classes = cls.append(classes, key);
|
|
96
|
-
}
|
|
97
|
-
return classes;
|
|
51
|
+
if (typeof arg === "string") return arg;
|
|
52
|
+
if (typeof arg !== "object") return "";
|
|
53
|
+
if (Array.isArray(arg)) return cls.apply(null, arg);
|
|
54
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) return cls.toString();
|
|
55
|
+
let classes = "";
|
|
56
|
+
for (const key in arg) if (hasOwn.call(arg, key) && arg[key]) classes = cls.append(classes, key);
|
|
57
|
+
return classes;
|
|
98
58
|
};
|
|
99
59
|
cls.append = function(value, newClass) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return value ? `${value} ${newClass}` : newClass;
|
|
60
|
+
if (!newClass) return value;
|
|
61
|
+
return value ? `${value} ${newClass}` : newClass;
|
|
103
62
|
};
|
|
104
63
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
|
|
119
|
-
var objectProto = Object.prototype;
|
|
120
|
-
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
121
|
-
var nativeObjectToString = objectProto.toString;
|
|
122
|
-
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
123
|
-
function getRawTag(value) {
|
|
124
|
-
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
125
|
-
try {
|
|
126
|
-
value[symToStringTag] = void 0;
|
|
127
|
-
var unmasked = true;
|
|
128
|
-
} catch (e) {
|
|
129
|
-
}
|
|
130
|
-
var result = nativeObjectToString.call(value);
|
|
131
|
-
if (unmasked) {
|
|
132
|
-
if (isOwn) {
|
|
133
|
-
value[symToStringTag] = tag;
|
|
134
|
-
} else {
|
|
135
|
-
delete value[symToStringTag];
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
var getRawTag_default = getRawTag;
|
|
141
|
-
|
|
142
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
|
|
143
|
-
var objectProto2 = Object.prototype;
|
|
144
|
-
var nativeObjectToString2 = objectProto2.toString;
|
|
145
|
-
function objectToString(value) {
|
|
146
|
-
return nativeObjectToString2.call(value);
|
|
147
|
-
}
|
|
148
|
-
var objectToString_default = objectToString;
|
|
149
|
-
|
|
150
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
|
|
151
|
-
var nullTag = "[object Null]";
|
|
152
|
-
var undefinedTag = "[object Undefined]";
|
|
153
|
-
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
154
|
-
function baseGetTag(value) {
|
|
155
|
-
if (value == null) {
|
|
156
|
-
return value === void 0 ? undefinedTag : nullTag;
|
|
157
|
-
}
|
|
158
|
-
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
159
|
-
}
|
|
160
|
-
var baseGetTag_default = baseGetTag;
|
|
161
|
-
|
|
162
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
|
|
163
|
-
function isObject(value) {
|
|
164
|
-
var type = typeof value;
|
|
165
|
-
return value != null && (type == "object" || type == "function");
|
|
166
|
-
}
|
|
167
|
-
var isObject_default = isObject;
|
|
168
|
-
|
|
169
|
-
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isFunction.js
|
|
170
|
-
var asyncTag = "[object AsyncFunction]";
|
|
171
|
-
var funcTag = "[object Function]";
|
|
172
|
-
var genTag = "[object GeneratorFunction]";
|
|
173
|
-
var proxyTag = "[object Proxy]";
|
|
174
|
-
function isFunction(value) {
|
|
175
|
-
if (!isObject_default(value)) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
var tag = baseGetTag_default(value);
|
|
179
|
-
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
180
|
-
}
|
|
181
|
-
var isFunction_default = isFunction;
|
|
182
|
-
|
|
183
|
-
// ../util-core/src/util/noop.ts
|
|
184
|
-
var noop = () => {
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
// ../util-core/src/util/deferred.ts
|
|
188
|
-
var Deferred = class extends Promise {
|
|
189
|
-
resolve;
|
|
190
|
-
reject;
|
|
191
|
-
constructor(executor = noop) {
|
|
192
|
-
let _resolve, _reject;
|
|
193
|
-
super((resolve_, reject_) => {
|
|
194
|
-
_resolve = resolve_;
|
|
195
|
-
_reject = reject_;
|
|
196
|
-
return executor(resolve_, reject_);
|
|
197
|
-
});
|
|
198
|
-
this.resolve = (value) => {
|
|
199
|
-
_resolve(value);
|
|
200
|
-
return this;
|
|
201
|
-
};
|
|
202
|
-
this.reject = (reason) => {
|
|
203
|
-
_reject(reason);
|
|
204
|
-
return this;
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
// ../util-core/src/util/json.ts
|
|
210
|
-
function tryParseJson(text) {
|
|
211
|
-
try {
|
|
212
|
-
return JSON.parse(text || "");
|
|
213
|
-
} catch {
|
|
214
|
-
return void 0;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// src/utils/track.ts
|
|
219
|
-
var import_valtio = require("valtio");
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/utils/track.ts
|
|
66
|
+
/**
|
|
67
|
+
* @requires `Trigger` component to be mounted in the tree.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```tsx
|
|
71
|
+
* // Obtain externally
|
|
72
|
+
* import { track } from '@hairy/lib-react'
|
|
73
|
+
* const context = await track(() => useContext(YourContext))
|
|
74
|
+
* console.log(context) // { ... }
|
|
75
|
+
*/
|
|
220
76
|
function track(fn, ...args) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
77
|
+
const deferred = (0, valtio.ref)(new _hairy_utils.Deferred());
|
|
78
|
+
const exposer = {
|
|
79
|
+
fn,
|
|
80
|
+
args,
|
|
81
|
+
deferred,
|
|
82
|
+
id: ++Trigger.id
|
|
83
|
+
};
|
|
84
|
+
Trigger.tasks.set(exposer.id, exposer);
|
|
85
|
+
deferred.then(() => Trigger.tasks.delete(exposer.id));
|
|
86
|
+
return deferred;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/utils/wrapper.ts
|
|
230
91
|
function wrapper(asChild, props, children) {
|
|
231
|
-
|
|
92
|
+
return asChild ? (0, react.createElement)(asChild, props, children) : children;
|
|
232
93
|
}
|
|
233
94
|
|
|
234
|
-
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/components/condition/Case.ts
|
|
235
97
|
function Case(props) {
|
|
236
|
-
|
|
237
|
-
|
|
98
|
+
const { cond, children, tag, as: asChild, ...attrs } = props;
|
|
99
|
+
return wrapper(tag || asChild, attrs, children);
|
|
238
100
|
}
|
|
239
101
|
|
|
240
|
-
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/components/condition/Default.ts
|
|
241
104
|
function Default(props) {
|
|
242
|
-
|
|
243
|
-
|
|
105
|
+
const { children, tag, as: asChild, ...attrs } = props;
|
|
106
|
+
return wrapper(tag || asChild, attrs, children);
|
|
244
107
|
}
|
|
245
108
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
// src/components/condition/Then.ts
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/components/condition/Then.ts
|
|
250
111
|
function Then(props) {
|
|
251
|
-
|
|
252
|
-
|
|
112
|
+
const { children, cond, else: _else, then, tag, as: asChild, ...attrs } = props;
|
|
113
|
+
return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag || asChild, attrs, children);
|
|
253
114
|
}
|
|
254
115
|
|
|
255
|
-
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/components/condition/If.ts
|
|
256
118
|
function If(props) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
return wrapper(tag || asChild, attrs, child);
|
|
119
|
+
const { then, cond, else: _else, children = props.then, tag, as: asChild, ...attrs } = props;
|
|
120
|
+
const elements = react.Children.toArray(children);
|
|
121
|
+
const thenChild = elements.find((c) => c.type === Then);
|
|
122
|
+
const elseChild = elements.find((c) => c.type === Else);
|
|
123
|
+
return wrapper(tag || asChild, attrs, thenChild || elseChild ? cond ? thenChild : elseChild : cond ? children : _else);
|
|
263
124
|
}
|
|
264
125
|
|
|
265
|
-
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/components/condition/Else.ts
|
|
266
128
|
function Else(props) {
|
|
267
|
-
|
|
268
|
-
|
|
129
|
+
const { children, tag, as: asChild, ...attrs } = props;
|
|
130
|
+
return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag || asChild, attrs, children);
|
|
269
131
|
}
|
|
270
132
|
|
|
271
|
-
|
|
272
|
-
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/components/condition/Switch.ts
|
|
273
135
|
function Switch(props) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
// src/components/condition/Unless.ts
|
|
294
|
-
var import_react4 = require("react");
|
|
136
|
+
const isUseValue = props.value !== void 0;
|
|
137
|
+
let matchingCase;
|
|
138
|
+
let defaultCase;
|
|
139
|
+
react.Children.forEach(props.children, (child) => {
|
|
140
|
+
if (!(0, react.isValidElement)(child) || matchingCase) return;
|
|
141
|
+
if (child.type === Case) {
|
|
142
|
+
const cond = child?.props?.cond;
|
|
143
|
+
if (isUseValue ? props.value === cond : cond) {
|
|
144
|
+
matchingCase = child;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!defaultCase && child.type === Default) defaultCase = child;
|
|
149
|
+
});
|
|
150
|
+
return matchingCase ?? defaultCase ?? null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/components/condition/Unless.ts
|
|
295
155
|
function Unless(props) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return wrapper(tag || asChild, attrs, child);
|
|
156
|
+
const { cond, then, else: _else, tag, as: asChild, children = props.then, ...attrs } = props;
|
|
157
|
+
const elements = react.Children.toArray(children);
|
|
158
|
+
const thenChild = elements.find((c) => c.type === Then);
|
|
159
|
+
const elseChild = elements.find((c) => c.type === Else);
|
|
160
|
+
return wrapper(tag || asChild, attrs, thenChild || elseChild ? !cond ? elseChild : thenChild : !cond ? children : _else);
|
|
302
161
|
}
|
|
303
162
|
|
|
304
|
-
|
|
305
|
-
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/components/utils/Injector.ts
|
|
306
165
|
function Injector(props) {
|
|
307
|
-
|
|
308
|
-
() => props.install.map(repack).reverse(),
|
|
309
|
-
[props.install]
|
|
310
|
-
);
|
|
311
|
-
return installs.reduce(
|
|
312
|
-
(child, { component: Component, props: props2 }) => (0, import_react5.createElement)(Component, props2, child),
|
|
313
|
-
props.children
|
|
314
|
-
);
|
|
166
|
+
return (0, react.useMemo)(() => props.install.map(repack).reverse(), [props.install]).reduce((child, { component: Component, props }) => (0, react.createElement)(Component, props, child), props.children);
|
|
315
167
|
}
|
|
316
168
|
function repack(c) {
|
|
317
|
-
|
|
169
|
+
return c.component ? c : { component: c };
|
|
318
170
|
}
|
|
319
171
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
var import_utils8 = require("valtio/utils");
|
|
324
|
-
var pendingTasks = (0, import_utils8.proxyMap)();
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/components/utils/Trigger.ts
|
|
174
|
+
const pendingTasks = (0, valtio_utils.proxyMap)();
|
|
325
175
|
function createTracker(exposer) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
176
|
+
const Component = () => {
|
|
177
|
+
try {
|
|
178
|
+
exposer.deferred.resolve(exposer.fn(...exposer.args));
|
|
179
|
+
} catch (error) {
|
|
180
|
+
exposer.deferred.reject(error);
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
};
|
|
184
|
+
Component.key = exposer.id;
|
|
185
|
+
return Component;
|
|
336
186
|
}
|
|
337
187
|
function renderTracker(Tracker) {
|
|
338
|
-
|
|
339
|
-
}
|
|
188
|
+
return (0, react.createElement)(Tracker, { key: Tracker.key });
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* @example
|
|
192
|
+
* ```tsx
|
|
193
|
+
* import { Trigger } from '@hairy/lib-react'
|
|
194
|
+
*
|
|
195
|
+
* // Use triggers to capture context
|
|
196
|
+
* function App() {
|
|
197
|
+
* return (
|
|
198
|
+
* <YourContext.Provider>
|
|
199
|
+
* <Trigger />
|
|
200
|
+
* </YourContext.Provider>
|
|
201
|
+
* )
|
|
202
|
+
* }
|
|
203
|
+
*
|
|
204
|
+
* // Obtain externally
|
|
205
|
+
* import { track } from '@hairy/lib-react'
|
|
206
|
+
* const context = await track(() => useContext(YourContext))
|
|
207
|
+
* console.log(context) // { ... }
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
340
210
|
function Trigger() {
|
|
341
|
-
|
|
342
|
-
return values.map(createTracker).map(renderTracker);
|
|
211
|
+
return [...(0, valtio.useSnapshot)(pendingTasks).values()].map(createTracker).map(renderTracker);
|
|
343
212
|
}
|
|
344
213
|
Trigger.id = 0;
|
|
345
214
|
Trigger.tasks = pendingTasks;
|
|
346
215
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/hooks/tryUseCallback.ts
|
|
218
|
+
const tryUseCallback = (callback, deps) => {
|
|
219
|
+
try {
|
|
220
|
+
return (0, react.useCallback)(callback, deps);
|
|
221
|
+
} catch {
|
|
222
|
+
return callback;
|
|
223
|
+
}
|
|
355
224
|
};
|
|
356
225
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/hooks/tryUseEffect.ts
|
|
228
|
+
const tryUseEffect = (effect, deps) => {
|
|
229
|
+
try {
|
|
230
|
+
(0, react.useEffect)(effect, deps);
|
|
231
|
+
} catch {}
|
|
364
232
|
};
|
|
365
233
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region src/hooks/tryUseInsertionEffect.ts
|
|
236
|
+
const tryUseInsertionEffect = (callback, deps) => {
|
|
237
|
+
try {
|
|
238
|
+
(0, react.useInsertionEffect)(callback, deps);
|
|
239
|
+
} catch {}
|
|
373
240
|
};
|
|
374
241
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region src/hooks/tryUseReducer.ts
|
|
244
|
+
const tryUseReducer = (reducer, initializerArg, initializer) => {
|
|
245
|
+
try {
|
|
246
|
+
return (0, react.useReducer)(reducer, initializerArg, initializer);
|
|
247
|
+
} catch {
|
|
248
|
+
return [initializerArg, () => {}];
|
|
249
|
+
}
|
|
384
250
|
};
|
|
385
251
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/hooks/tryUseRef.ts
|
|
254
|
+
const tryUseRef = (initialValue) => {
|
|
255
|
+
try {
|
|
256
|
+
return (0, react.useRef)(initialValue);
|
|
257
|
+
} catch {
|
|
258
|
+
return { current: initialValue };
|
|
259
|
+
}
|
|
394
260
|
};
|
|
395
261
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/hooks/tryUseState.ts
|
|
264
|
+
const tryUseState = (initialState) => {
|
|
265
|
+
try {
|
|
266
|
+
return (0, react.useState)(initialState);
|
|
267
|
+
} catch {
|
|
268
|
+
return [(0, _hairy_utils.isFunction)(initialState) ? initialState() : initialState, _hairy_utils.noop];
|
|
269
|
+
}
|
|
404
270
|
};
|
|
405
271
|
|
|
406
|
-
|
|
407
|
-
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/hooks/useUpdate.ts
|
|
274
|
+
const updateReducer = (num) => (num + 1) % 1e6;
|
|
408
275
|
function useUpdate() {
|
|
409
|
-
|
|
410
|
-
|
|
276
|
+
const [, update] = tryUseReducer(updateReducer, 0);
|
|
277
|
+
return update;
|
|
411
278
|
}
|
|
412
279
|
|
|
413
|
-
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/hooks/tryUseUpdate.ts
|
|
414
282
|
function tryUseUpdate() {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
283
|
+
try {
|
|
284
|
+
return useUpdate();
|
|
285
|
+
} catch {
|
|
286
|
+
return () => {};
|
|
287
|
+
}
|
|
421
288
|
}
|
|
422
289
|
|
|
423
|
-
|
|
424
|
-
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region src/hooks/useAsyncCallback.ts
|
|
425
292
|
function useAsyncCallback(fun) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
293
|
+
const [state, set] = (0, react.useState)({ loading: false });
|
|
294
|
+
async function refetch(...args) {
|
|
295
|
+
set({ loading: true });
|
|
296
|
+
return fun(...args).then((value) => {
|
|
297
|
+
set({ loading: false });
|
|
298
|
+
return value;
|
|
299
|
+
}).catch((err) => {
|
|
300
|
+
set({
|
|
301
|
+
loading: false,
|
|
302
|
+
error: err
|
|
303
|
+
});
|
|
304
|
+
return Promise.reject(err);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
return [
|
|
308
|
+
state.loading,
|
|
309
|
+
refetch,
|
|
310
|
+
state.error
|
|
311
|
+
];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/hooks/useAsyncState.ts
|
|
442
316
|
function useAsyncState(fun, deps = [], options) {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
317
|
+
const [value, set] = (0, react.useState)(options?.initial);
|
|
318
|
+
const [loading, refetch, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
319
|
+
(0, react.useEffect)(() => {
|
|
320
|
+
refetch();
|
|
321
|
+
}, deps);
|
|
322
|
+
return [{
|
|
323
|
+
value,
|
|
324
|
+
loading,
|
|
325
|
+
error
|
|
326
|
+
}, refetch];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region src/hooks/useDebounce.ts
|
|
456
331
|
function useDebounce(value, delay) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
332
|
+
const [debouncedValue, setDebouncedValue] = (0, react.useState)(value);
|
|
333
|
+
(0, react.useEffect)(() => {
|
|
334
|
+
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
335
|
+
return () => clearTimeout(handler);
|
|
336
|
+
}, [value, delay]);
|
|
337
|
+
return debouncedValue;
|
|
463
338
|
}
|
|
464
339
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
var emitter = (0, import_mitt.default)();
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/hooks/useEventBus.ts
|
|
342
|
+
const emitter = (0, mitt.default)();
|
|
469
343
|
function useEventBus(key) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
var import_react17 = require("react");
|
|
498
|
-
var useEffectOnce = function(effect) {
|
|
499
|
-
(0, import_react17.useEffect)(effect, []);
|
|
500
|
-
};
|
|
501
|
-
var useEffectOnce_default = useEffectOnce;
|
|
502
|
-
|
|
503
|
-
// ../../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
|
|
504
|
-
var useMount = function(fn) {
|
|
505
|
-
useEffectOnce_default(function() {
|
|
506
|
-
fn();
|
|
507
|
-
});
|
|
508
|
-
};
|
|
509
|
-
var useMount_default = useMount;
|
|
510
|
-
|
|
511
|
-
// src/hooks/useFetchIntercept.ts
|
|
344
|
+
const onRef = (0, react.useRef)(void 0);
|
|
345
|
+
function on(listener) {
|
|
346
|
+
emitter.on(key, listener);
|
|
347
|
+
onRef.current = listener;
|
|
348
|
+
(0, react.useEffect)(() => {
|
|
349
|
+
if (!onRef.current) return;
|
|
350
|
+
emitter.off(key, onRef.current);
|
|
351
|
+
emitter.on(key, listener);
|
|
352
|
+
onRef.current = listener;
|
|
353
|
+
return () => emitter.off(key, listener);
|
|
354
|
+
}, [listener]);
|
|
355
|
+
}
|
|
356
|
+
function emit(event) {
|
|
357
|
+
emitter.emit(key, event);
|
|
358
|
+
}
|
|
359
|
+
function off(listener) {
|
|
360
|
+
emitter.off(key, listener);
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
on,
|
|
364
|
+
emit,
|
|
365
|
+
off
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
//#endregion
|
|
370
|
+
//#region src/hooks/useFetchIntercept.ts
|
|
512
371
|
function useFetchResponseIntercept(intercept) {
|
|
513
|
-
|
|
372
|
+
(0, react_use.useMount)(() => fetchResponseIntercept(intercept));
|
|
514
373
|
}
|
|
515
374
|
function useFetchRequestIntercept(intercept) {
|
|
516
|
-
|
|
375
|
+
(0, react_use.useMount)(() => fetchRequestIntercept(intercept));
|
|
517
376
|
}
|
|
518
377
|
function fetchResponseIntercept(intercept) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
};
|
|
378
|
+
const { fetch: originalFetch } = window;
|
|
379
|
+
window.fetch = async (...args) => {
|
|
380
|
+
const [resource, config] = args;
|
|
381
|
+
return intercept(await originalFetch(resource, config), config);
|
|
382
|
+
};
|
|
525
383
|
}
|
|
526
384
|
function fetchRequestIntercept(intercept) {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
385
|
+
const { fetch: originalFetch } = window;
|
|
386
|
+
window.fetch = async (...args) => {
|
|
387
|
+
const [resource, config] = args;
|
|
388
|
+
return intercept(originalFetch, resource, config);
|
|
389
|
+
};
|
|
532
390
|
}
|
|
533
391
|
|
|
534
|
-
|
|
535
|
-
|
|
392
|
+
//#endregion
|
|
393
|
+
//#region src/hooks/useMounted.ts
|
|
536
394
|
function useMounted() {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
395
|
+
const [mounted, setMounted] = (0, react.useState)(false);
|
|
396
|
+
(0, react.useEffect)(() => setMounted(true), []);
|
|
397
|
+
return mounted;
|
|
540
398
|
}
|
|
541
399
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
// src/hooks/useWatch.ts
|
|
546
|
-
var import_react20 = require("react");
|
|
547
|
-
|
|
548
|
-
// src/hooks/usePrevious.ts
|
|
549
|
-
var import_react19 = require("react");
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/hooks/usePrevious.ts
|
|
550
402
|
function usePrevious(value) {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
403
|
+
const ref = (0, react.useRef)(void 0);
|
|
404
|
+
(0, react.useEffect)(() => {
|
|
405
|
+
ref.current = value;
|
|
406
|
+
});
|
|
407
|
+
return ref.current;
|
|
556
408
|
}
|
|
557
409
|
|
|
558
|
-
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region src/hooks/useWatch.ts
|
|
559
412
|
function useWatch(source, callback, options = {}) {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
then.current.then(() => firstUpdate.current = true);
|
|
578
|
-
if (options.immediate)
|
|
579
|
-
then.current.then((value) => callback(value, oldValue));
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
// src/hooks/useOffsetPagination.ts
|
|
413
|
+
const firstUpdate = (0, react.useRef)(false);
|
|
414
|
+
const then = (0, react.useRef)(void 0);
|
|
415
|
+
const oldValue = usePrevious(source);
|
|
416
|
+
(0, react.useEffect)(() => {
|
|
417
|
+
if (!firstUpdate.current) recordFirst();
|
|
418
|
+
else callback(source, oldValue);
|
|
419
|
+
}, (0, react.useMemo)(() => Array.isArray(source) ? source : [source], [source]));
|
|
420
|
+
async function recordFirst() {
|
|
421
|
+
if (then.current) return;
|
|
422
|
+
then.current = Promise.resolve(source);
|
|
423
|
+
then.current.then(() => firstUpdate.current = true);
|
|
424
|
+
if (options.immediate) then.current.then((value) => callback(value, oldValue));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/hooks/useOffsetPagination.ts
|
|
584
430
|
function useOffsetPagination(options) {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
|
|
431
|
+
const [page, setPage] = (0, react.useState)(options.page || 1);
|
|
432
|
+
const [pageSize, setPageSize] = (0, react.useState)(options.pageSize || 10);
|
|
433
|
+
const total = options.total || 0;
|
|
434
|
+
const pageCount = (0, react.useMemo)(() => Math.max(1, Math.ceil(total / pageSize)), [total, pageSize]);
|
|
435
|
+
const isFirstPage = (0, react.useMemo)(() => page === 1, [page]);
|
|
436
|
+
const isLastPage = (0, react.useMemo)(() => page === pageCount, [page, pageCount]);
|
|
437
|
+
function next() {
|
|
438
|
+
setPage((page) => Math.min(pageCount, page + 1));
|
|
439
|
+
}
|
|
440
|
+
function prev() {
|
|
441
|
+
setPage((page) => Math.max(1, page - 1));
|
|
442
|
+
}
|
|
443
|
+
function pageChange(page) {
|
|
444
|
+
setPage(() => Math.max(1, Math.min(page, pageCount)));
|
|
445
|
+
}
|
|
446
|
+
function pageSizeChange(limit) {
|
|
447
|
+
setPageSize(limit);
|
|
448
|
+
pageChange(1);
|
|
449
|
+
}
|
|
450
|
+
const pagination = {
|
|
451
|
+
next,
|
|
452
|
+
prev,
|
|
453
|
+
page,
|
|
454
|
+
pageSize,
|
|
455
|
+
isFirstPage,
|
|
456
|
+
pageSizeChange,
|
|
457
|
+
pageChange,
|
|
458
|
+
isLastPage,
|
|
459
|
+
pageCount,
|
|
460
|
+
total
|
|
461
|
+
};
|
|
462
|
+
useWatch(page, () => options.onChange?.(pagination));
|
|
463
|
+
useWatch(pageSize, () => options.onPageSizeChange?.(pagination));
|
|
464
|
+
useWatch(pageCount, () => options.onPageCountChange?.(pagination));
|
|
465
|
+
return pagination;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
//#endregion
|
|
469
|
+
//#region src/hooks/useWhenever.ts
|
|
623
470
|
function useWhenever(source, cb, options) {
|
|
624
|
-
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
const fulfilled = (value) => {
|
|
659
|
-
status.finished = true;
|
|
660
|
-
done();
|
|
661
|
-
return value;
|
|
662
|
-
};
|
|
663
|
-
const rejected = (error) => {
|
|
664
|
-
status.error = error;
|
|
665
|
-
done();
|
|
666
|
-
throw error;
|
|
667
|
-
};
|
|
668
|
-
return function(...args) {
|
|
669
|
-
tracking();
|
|
670
|
-
try {
|
|
671
|
-
const value = action(...args);
|
|
672
|
-
return value instanceof Promise ? value.then(fulfilled, rejected) : fulfilled(value);
|
|
673
|
-
} catch (error) {
|
|
674
|
-
rejected(error);
|
|
675
|
-
}
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
// src/storage/defineStore.ts
|
|
680
|
-
function defineStore(store, options = {}) {
|
|
681
|
-
const state = typeof store.state === "function" ? store.state() : store.state;
|
|
682
|
-
const getters = store.getters || {};
|
|
683
|
-
const actions = store.actions || {};
|
|
684
|
-
const status = {};
|
|
685
|
-
status.finished = false;
|
|
686
|
-
status.loading = false;
|
|
687
|
-
status.error = null;
|
|
688
|
-
const $status = (0, import_valtio4.proxy)(status);
|
|
689
|
-
const $state = options.persist ? proxyWithPersistant(options.persist, state) : (0, import_valtio4.proxy)(state);
|
|
690
|
-
const $actions = {};
|
|
691
|
-
const $getters = {};
|
|
692
|
-
setupActions($state, actions, $actions, $status);
|
|
693
|
-
setupGetters(state, $state, getters, $getters);
|
|
694
|
-
setupStatus($actions, $status);
|
|
695
|
-
function $subscribe(listener) {
|
|
696
|
-
return (0, import_valtio4.subscribe)($state, () => listener($state));
|
|
697
|
-
}
|
|
698
|
-
$subscribe.status = function(listener) {
|
|
699
|
-
return (0, import_valtio4.subscribe)($status, () => listener($status));
|
|
700
|
-
};
|
|
701
|
-
function $patch(patch) {
|
|
702
|
-
if (typeof patch === "function")
|
|
703
|
-
patch($state);
|
|
704
|
-
else
|
|
705
|
-
Object.assign($state, patch);
|
|
706
|
-
}
|
|
707
|
-
function $signal(fn) {
|
|
708
|
-
return (0, import_react22.createElement)(() => fn((0, import_valtio4.useSnapshot)($state)));
|
|
709
|
-
}
|
|
710
|
-
$signal.status = function(fn) {
|
|
711
|
-
return (0, import_react22.createElement)(() => fn((0, import_valtio4.useSnapshot)($status)));
|
|
712
|
-
};
|
|
713
|
-
return {
|
|
714
|
-
$subscribe,
|
|
715
|
-
$patch,
|
|
716
|
-
$state,
|
|
717
|
-
$status,
|
|
718
|
-
$actions,
|
|
719
|
-
$getters,
|
|
720
|
-
$signal,
|
|
721
|
-
...$actions
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
function setupActions($state, actions, $actions, $status) {
|
|
725
|
-
for (const key in actions) {
|
|
726
|
-
$status[key] = { finished: false, loading: false, error: null };
|
|
727
|
-
$actions[key] = track2(actions[key].bind($state), $status[key]);
|
|
728
|
-
Object.defineProperty($state, key, {
|
|
729
|
-
get: () => $actions[key]
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
function setupGetters(state, $state, getters, $getters) {
|
|
734
|
-
for (const key in getters) {
|
|
735
|
-
Object.defineProperty(state, key, {
|
|
736
|
-
get: () => getters[key].call($state),
|
|
737
|
-
enumerable: true
|
|
738
|
-
});
|
|
739
|
-
Object.defineProperty($getters, key, {
|
|
740
|
-
get: () => state[key],
|
|
741
|
-
enumerable: true
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
function setupStatus($actions, $status) {
|
|
746
|
-
Object.defineProperty($status, "loading", {
|
|
747
|
-
get: () => Object.keys($actions).some((key) => $status[key].loading),
|
|
748
|
-
enumerable: true
|
|
749
|
-
});
|
|
750
|
-
Object.defineProperty($status, "finished", {
|
|
751
|
-
get: () => Object.keys($actions).every((key) => $status[key].finished),
|
|
752
|
-
enumerable: true
|
|
753
|
-
});
|
|
754
|
-
Object.defineProperty($status, "error", {
|
|
755
|
-
get: () => Object.keys($actions).find((key) => $status[key].error),
|
|
756
|
-
enumerable: true
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
// src/storage/defineStoreAsync.ts
|
|
761
|
-
var import_utils12 = require("valtio/utils");
|
|
762
|
-
function defineStoreAsync(fetch, options = {}) {
|
|
763
|
-
let persist;
|
|
764
|
-
if (typeof options.persist === "string") {
|
|
765
|
-
persist = { id: options.persist, pick: ["value"] };
|
|
766
|
-
}
|
|
767
|
-
if (typeof options.persist === "object") {
|
|
768
|
-
persist = { ...options.persist, pick: ["value"] };
|
|
769
|
-
}
|
|
770
|
-
const store = defineStore(
|
|
771
|
-
{
|
|
772
|
-
state: () => ({
|
|
773
|
-
value: options.initial,
|
|
774
|
-
error: void 0,
|
|
775
|
-
loading: false,
|
|
776
|
-
finished: false
|
|
777
|
-
}),
|
|
778
|
-
actions: {
|
|
779
|
-
async refetch(...args) {
|
|
780
|
-
return this.value = await fetch(...args);
|
|
781
|
-
},
|
|
782
|
-
reset(value) {
|
|
783
|
-
this.value = value || options.initial;
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
},
|
|
787
|
-
{ persist }
|
|
788
|
-
);
|
|
789
|
-
(0, import_utils12.watch)((get) => {
|
|
790
|
-
const status = get(store.$status.refetch);
|
|
791
|
-
store.$state.error = status.error;
|
|
792
|
-
store.$state.loading = status.loading;
|
|
793
|
-
store.$state.finished = status.finished;
|
|
794
|
-
});
|
|
795
|
-
options.immediate && store.refetch();
|
|
796
|
-
return store;
|
|
797
|
-
}
|
|
798
|
-
var defienAsyncStore = defineStoreAsync;
|
|
799
|
-
|
|
800
|
-
// src/storage/useStatus.tsx
|
|
801
|
-
var import_valtio5 = require("valtio");
|
|
802
|
-
function useStatus(store) {
|
|
803
|
-
return (0, import_valtio5.useSnapshot)(store.$status);
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
// src/storage/useStore.ts
|
|
807
|
-
var import_valtio6 = require("valtio");
|
|
808
|
-
function useStore(store) {
|
|
809
|
-
return (0, import_valtio6.useSnapshot)(store.$state);
|
|
810
|
-
}
|
|
811
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
812
|
-
0 && (module.exports = {
|
|
813
|
-
Case,
|
|
814
|
-
Default,
|
|
815
|
-
Else,
|
|
816
|
-
If,
|
|
817
|
-
Injector,
|
|
818
|
-
Switch,
|
|
819
|
-
Then,
|
|
820
|
-
Trigger,
|
|
821
|
-
Unless,
|
|
822
|
-
cls,
|
|
823
|
-
defienAsyncStore,
|
|
824
|
-
defineStore,
|
|
825
|
-
defineStoreAsync,
|
|
826
|
-
proxyWithPersistant,
|
|
827
|
-
track,
|
|
828
|
-
tryUseCallback,
|
|
829
|
-
tryUseEffect,
|
|
830
|
-
tryUseInsertionEffect,
|
|
831
|
-
tryUseReducer,
|
|
832
|
-
tryUseRef,
|
|
833
|
-
tryUseState,
|
|
834
|
-
tryUseUpdate,
|
|
835
|
-
useAsyncCallback,
|
|
836
|
-
useAsyncState,
|
|
837
|
-
useDebounce,
|
|
838
|
-
useEventBus,
|
|
839
|
-
useFetchRequestIntercept,
|
|
840
|
-
useFetchResponseIntercept,
|
|
841
|
-
useMounted,
|
|
842
|
-
useOffsetPagination,
|
|
843
|
-
useStatus,
|
|
844
|
-
useStore,
|
|
845
|
-
useUpdate,
|
|
846
|
-
useWatch,
|
|
847
|
-
useWhenever,
|
|
848
|
-
wrapper
|
|
849
|
-
});
|
|
850
|
-
/*! Bundled license information:
|
|
851
|
-
|
|
852
|
-
lodash-es/lodash.js:
|
|
853
|
-
(**
|
|
854
|
-
* @license
|
|
855
|
-
* Lodash (Custom Build) <https://lodash.com/>
|
|
856
|
-
* Build: `lodash modularize exports="es" -o ./`
|
|
857
|
-
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
858
|
-
* Released under MIT license <https://lodash.com/license>
|
|
859
|
-
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
860
|
-
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
861
|
-
*)
|
|
862
|
-
*/
|
|
471
|
+
useWatch(source, (value, oldValue) => value && cb(value, oldValue), options);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
//#endregion
|
|
475
|
+
exports.Case = Case;
|
|
476
|
+
exports.Default = Default;
|
|
477
|
+
exports.Else = Else;
|
|
478
|
+
exports.If = If;
|
|
479
|
+
exports.Injector = Injector;
|
|
480
|
+
exports.Switch = Switch;
|
|
481
|
+
exports.Then = Then;
|
|
482
|
+
exports.Trigger = Trigger;
|
|
483
|
+
exports.Unless = Unless;
|
|
484
|
+
exports.cls = cls;
|
|
485
|
+
exports.track = track;
|
|
486
|
+
exports.tryUseCallback = tryUseCallback;
|
|
487
|
+
exports.tryUseEffect = tryUseEffect;
|
|
488
|
+
exports.tryUseInsertionEffect = tryUseInsertionEffect;
|
|
489
|
+
exports.tryUseReducer = tryUseReducer;
|
|
490
|
+
exports.tryUseRef = tryUseRef;
|
|
491
|
+
exports.tryUseState = tryUseState;
|
|
492
|
+
exports.tryUseUpdate = tryUseUpdate;
|
|
493
|
+
exports.useAsyncCallback = useAsyncCallback;
|
|
494
|
+
exports.useAsyncState = useAsyncState;
|
|
495
|
+
exports.useDebounce = useDebounce;
|
|
496
|
+
exports.useEventBus = useEventBus;
|
|
497
|
+
exports.useFetchRequestIntercept = useFetchRequestIntercept;
|
|
498
|
+
exports.useFetchResponseIntercept = useFetchResponseIntercept;
|
|
499
|
+
exports.useMounted = useMounted;
|
|
500
|
+
exports.useOffsetPagination = useOffsetPagination;
|
|
501
|
+
exports.useUpdate = useUpdate;
|
|
502
|
+
exports.useWatch = useWatch;
|
|
503
|
+
exports.useWhenever = useWhenever;
|
|
504
|
+
exports.wrapper = wrapper;
|