@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/{LICENSE.md → LICENSE} +21 -21
- package/README.md +258 -36
- package/dist/index.cjs +412 -769
- package/dist/index.d.cts +258 -0
- package/dist/index.d.mts +258 -0
- package/dist/index.mjs +447 -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,505 @@
|
|
|
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
|
+
* ```
|
|
76
|
+
*/
|
|
220
77
|
function track(fn, ...args) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
78
|
+
const deferred = (0, valtio.ref)(new _hairy_utils.Deferred());
|
|
79
|
+
const exposer = {
|
|
80
|
+
fn,
|
|
81
|
+
args,
|
|
82
|
+
deferred,
|
|
83
|
+
id: ++Trigger.id
|
|
84
|
+
};
|
|
85
|
+
Trigger.tasks.set(exposer.id, exposer);
|
|
86
|
+
deferred.then(() => Trigger.tasks.delete(exposer.id));
|
|
87
|
+
return deferred;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/utils/wrapper.ts
|
|
230
92
|
function wrapper(asChild, props, children) {
|
|
231
|
-
|
|
93
|
+
return asChild ? (0, react.createElement)(asChild, props, children) : children;
|
|
232
94
|
}
|
|
233
95
|
|
|
234
|
-
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/components/condition/Case.ts
|
|
235
98
|
function Case(props) {
|
|
236
|
-
|
|
237
|
-
|
|
99
|
+
const { cond, children, tag, as: asChild, ...attrs } = props;
|
|
100
|
+
return wrapper(tag || asChild, attrs, children);
|
|
238
101
|
}
|
|
239
102
|
|
|
240
|
-
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/components/condition/Default.ts
|
|
241
105
|
function Default(props) {
|
|
242
|
-
|
|
243
|
-
|
|
106
|
+
const { children, tag, as: asChild, ...attrs } = props;
|
|
107
|
+
return wrapper(tag || asChild, attrs, children);
|
|
244
108
|
}
|
|
245
109
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
// src/components/condition/Then.ts
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/components/condition/Then.ts
|
|
250
112
|
function Then(props) {
|
|
251
|
-
|
|
252
|
-
|
|
113
|
+
const { children, cond, else: _else, then, tag, as: asChild, ...attrs } = props;
|
|
114
|
+
return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag || asChild, attrs, children);
|
|
253
115
|
}
|
|
254
116
|
|
|
255
|
-
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/components/condition/If.ts
|
|
256
119
|
function If(props) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
return wrapper(tag || asChild, attrs, child);
|
|
120
|
+
const { then, cond, else: _else, children = props.then, tag, as: asChild, ...attrs } = props;
|
|
121
|
+
const elements = react.Children.toArray(children);
|
|
122
|
+
const thenChild = elements.find((c) => c.type === Then);
|
|
123
|
+
const elseChild = elements.find((c) => c.type === Else);
|
|
124
|
+
return wrapper(tag || asChild, attrs, thenChild || elseChild ? cond ? thenChild : elseChild : cond ? children : _else);
|
|
263
125
|
}
|
|
264
126
|
|
|
265
|
-
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/components/condition/Else.ts
|
|
266
129
|
function Else(props) {
|
|
267
|
-
|
|
268
|
-
|
|
130
|
+
const { children, tag, as: asChild, ...attrs } = props;
|
|
131
|
+
return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag || asChild, attrs, children);
|
|
269
132
|
}
|
|
270
133
|
|
|
271
|
-
|
|
272
|
-
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/components/condition/Switch.ts
|
|
273
136
|
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");
|
|
137
|
+
const isUseValue = props.value !== void 0;
|
|
138
|
+
let matchingCase;
|
|
139
|
+
let defaultCase;
|
|
140
|
+
react.Children.forEach(props.children, (child) => {
|
|
141
|
+
if (!(0, react.isValidElement)(child) || matchingCase) return;
|
|
142
|
+
if (child.type === Case) {
|
|
143
|
+
const cond = child?.props?.cond;
|
|
144
|
+
if (isUseValue ? props.value === cond : cond) {
|
|
145
|
+
matchingCase = child;
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!defaultCase && child.type === Default) defaultCase = child;
|
|
150
|
+
});
|
|
151
|
+
return matchingCase ?? defaultCase ?? null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/components/condition/Unless.ts
|
|
295
156
|
function Unless(props) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return wrapper(tag || asChild, attrs, child);
|
|
157
|
+
const { cond, then, else: _else, tag, as: asChild, children = props.then, ...attrs } = props;
|
|
158
|
+
const elements = react.Children.toArray(children);
|
|
159
|
+
const thenChild = elements.find((c) => c.type === Then);
|
|
160
|
+
const elseChild = elements.find((c) => c.type === Else);
|
|
161
|
+
return wrapper(tag || asChild, attrs, thenChild || elseChild ? !cond ? elseChild : thenChild : !cond ? children : _else);
|
|
302
162
|
}
|
|
303
163
|
|
|
304
|
-
|
|
305
|
-
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/components/utils/Injector.ts
|
|
306
166
|
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
|
-
);
|
|
167
|
+
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
168
|
}
|
|
316
169
|
function repack(c) {
|
|
317
|
-
|
|
170
|
+
return c.component ? c : { component: c };
|
|
318
171
|
}
|
|
319
172
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
var import_utils8 = require("valtio/utils");
|
|
324
|
-
var pendingTasks = (0, import_utils8.proxyMap)();
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/components/utils/Trigger.ts
|
|
175
|
+
const pendingTasks = (0, valtio_utils.proxyMap)();
|
|
325
176
|
function createTracker(exposer) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
177
|
+
const Component = () => {
|
|
178
|
+
try {
|
|
179
|
+
exposer.deferred.resolve(exposer.fn(...exposer.args));
|
|
180
|
+
} catch (error) {
|
|
181
|
+
exposer.deferred.reject(error);
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
};
|
|
185
|
+
Component.key = exposer.id;
|
|
186
|
+
return Component;
|
|
336
187
|
}
|
|
337
188
|
function renderTracker(Tracker) {
|
|
338
|
-
|
|
339
|
-
}
|
|
189
|
+
return (0, react.createElement)(Tracker, { key: Tracker.key });
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* @example
|
|
193
|
+
* ```tsx
|
|
194
|
+
* import { Trigger } from '@hairy/lib-react'
|
|
195
|
+
*
|
|
196
|
+
* // Use triggers to capture context
|
|
197
|
+
* function App() {
|
|
198
|
+
* return (
|
|
199
|
+
* <YourContext.Provider>
|
|
200
|
+
* <Trigger />
|
|
201
|
+
* </YourContext.Provider>
|
|
202
|
+
* )
|
|
203
|
+
* }
|
|
204
|
+
*
|
|
205
|
+
* // Obtain externally
|
|
206
|
+
* import { track } from '@hairy/lib-react'
|
|
207
|
+
* const context = await track(() => useContext(YourContext))
|
|
208
|
+
* console.log(context) // { ... }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
340
211
|
function Trigger() {
|
|
341
|
-
|
|
342
|
-
return values.map(createTracker).map(renderTracker);
|
|
212
|
+
return [...(0, valtio.useSnapshot)(pendingTasks).values()].map(createTracker).map(renderTracker);
|
|
343
213
|
}
|
|
344
214
|
Trigger.id = 0;
|
|
345
215
|
Trigger.tasks = pendingTasks;
|
|
346
216
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/hooks/tryUseCallback.ts
|
|
219
|
+
const tryUseCallback = (callback, deps) => {
|
|
220
|
+
try {
|
|
221
|
+
return (0, react.useCallback)(callback, deps);
|
|
222
|
+
} catch {
|
|
223
|
+
return callback;
|
|
224
|
+
}
|
|
355
225
|
};
|
|
356
226
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/hooks/tryUseEffect.ts
|
|
229
|
+
const tryUseEffect = (effect, deps) => {
|
|
230
|
+
try {
|
|
231
|
+
(0, react.useEffect)(effect, deps);
|
|
232
|
+
} catch {}
|
|
364
233
|
};
|
|
365
234
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/hooks/tryUseInsertionEffect.ts
|
|
237
|
+
const tryUseInsertionEffect = (callback, deps) => {
|
|
238
|
+
try {
|
|
239
|
+
(0, react.useInsertionEffect)(callback, deps);
|
|
240
|
+
} catch {}
|
|
373
241
|
};
|
|
374
242
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/hooks/tryUseReducer.ts
|
|
245
|
+
const tryUseReducer = (reducer, initializerArg, initializer) => {
|
|
246
|
+
try {
|
|
247
|
+
return (0, react.useReducer)(reducer, initializerArg, initializer);
|
|
248
|
+
} catch {
|
|
249
|
+
return [initializerArg, () => {}];
|
|
250
|
+
}
|
|
384
251
|
};
|
|
385
252
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/hooks/tryUseRef.ts
|
|
255
|
+
const tryUseRef = (initialValue) => {
|
|
256
|
+
try {
|
|
257
|
+
return (0, react.useRef)(initialValue);
|
|
258
|
+
} catch {
|
|
259
|
+
return { current: initialValue };
|
|
260
|
+
}
|
|
394
261
|
};
|
|
395
262
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/hooks/tryUseState.ts
|
|
265
|
+
const tryUseState = (initialState) => {
|
|
266
|
+
try {
|
|
267
|
+
return (0, react.useState)(initialState);
|
|
268
|
+
} catch {
|
|
269
|
+
return [(0, _hairy_utils.isFunction)(initialState) ? initialState() : initialState, _hairy_utils.noop];
|
|
270
|
+
}
|
|
404
271
|
};
|
|
405
272
|
|
|
406
|
-
|
|
407
|
-
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/hooks/useUpdate.ts
|
|
275
|
+
const updateReducer = (num) => (num + 1) % 1e6;
|
|
408
276
|
function useUpdate() {
|
|
409
|
-
|
|
410
|
-
|
|
277
|
+
const [, update] = tryUseReducer(updateReducer, 0);
|
|
278
|
+
return update;
|
|
411
279
|
}
|
|
412
280
|
|
|
413
|
-
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/hooks/tryUseUpdate.ts
|
|
414
283
|
function tryUseUpdate() {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
284
|
+
try {
|
|
285
|
+
return useUpdate();
|
|
286
|
+
} catch {
|
|
287
|
+
return () => {};
|
|
288
|
+
}
|
|
421
289
|
}
|
|
422
290
|
|
|
423
|
-
|
|
424
|
-
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region src/hooks/useAsyncCallback.ts
|
|
425
293
|
function useAsyncCallback(fun) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
294
|
+
const [state, set] = (0, react.useState)({ loading: false });
|
|
295
|
+
async function refetch(...args) {
|
|
296
|
+
set({ loading: true });
|
|
297
|
+
return fun(...args).then((value) => {
|
|
298
|
+
set({ loading: false });
|
|
299
|
+
return value;
|
|
300
|
+
}).catch((err) => {
|
|
301
|
+
set({
|
|
302
|
+
loading: false,
|
|
303
|
+
error: err
|
|
304
|
+
});
|
|
305
|
+
return Promise.reject(err);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
return [
|
|
309
|
+
state.loading,
|
|
310
|
+
refetch,
|
|
311
|
+
state.error
|
|
312
|
+
];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/hooks/useAsyncState.ts
|
|
442
317
|
function useAsyncState(fun, deps = [], options) {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
318
|
+
const [value, set] = (0, react.useState)(options?.initial);
|
|
319
|
+
const [loading, refetch, error] = useAsyncCallback(async (...args) => fun(...args).then(set));
|
|
320
|
+
(0, react.useEffect)(() => {
|
|
321
|
+
refetch();
|
|
322
|
+
}, deps);
|
|
323
|
+
return [{
|
|
324
|
+
value,
|
|
325
|
+
loading,
|
|
326
|
+
error
|
|
327
|
+
}, refetch];
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/hooks/useDebounce.ts
|
|
456
332
|
function useDebounce(value, delay) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
333
|
+
const [debouncedValue, setDebouncedValue] = (0, react.useState)(value);
|
|
334
|
+
(0, react.useEffect)(() => {
|
|
335
|
+
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
336
|
+
return () => clearTimeout(handler);
|
|
337
|
+
}, [value, delay]);
|
|
338
|
+
return debouncedValue;
|
|
463
339
|
}
|
|
464
340
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
var emitter = (0, import_mitt.default)();
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/hooks/useEventBus.ts
|
|
343
|
+
const emitter = (0, mitt.default)();
|
|
469
344
|
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
|
|
345
|
+
const onRef = (0, react.useRef)(void 0);
|
|
346
|
+
function on(listener) {
|
|
347
|
+
emitter.on(key, listener);
|
|
348
|
+
onRef.current = listener;
|
|
349
|
+
(0, react.useEffect)(() => {
|
|
350
|
+
if (!onRef.current) return;
|
|
351
|
+
emitter.off(key, onRef.current);
|
|
352
|
+
emitter.on(key, listener);
|
|
353
|
+
onRef.current = listener;
|
|
354
|
+
return () => emitter.off(key, listener);
|
|
355
|
+
}, [listener]);
|
|
356
|
+
}
|
|
357
|
+
function emit(event) {
|
|
358
|
+
emitter.emit(key, event);
|
|
359
|
+
}
|
|
360
|
+
function off(listener) {
|
|
361
|
+
emitter.off(key, listener);
|
|
362
|
+
}
|
|
363
|
+
return {
|
|
364
|
+
on,
|
|
365
|
+
emit,
|
|
366
|
+
off
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
//#endregion
|
|
371
|
+
//#region src/hooks/useFetchIntercept.ts
|
|
512
372
|
function useFetchResponseIntercept(intercept) {
|
|
513
|
-
|
|
373
|
+
(0, react_use.useMount)(() => fetchResponseIntercept(intercept));
|
|
514
374
|
}
|
|
515
375
|
function useFetchRequestIntercept(intercept) {
|
|
516
|
-
|
|
376
|
+
(0, react_use.useMount)(() => fetchRequestIntercept(intercept));
|
|
517
377
|
}
|
|
518
378
|
function fetchResponseIntercept(intercept) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
};
|
|
379
|
+
const { fetch: originalFetch } = window;
|
|
380
|
+
window.fetch = async (...args) => {
|
|
381
|
+
const [resource, config] = args;
|
|
382
|
+
return intercept(await originalFetch(resource, config), config);
|
|
383
|
+
};
|
|
525
384
|
}
|
|
526
385
|
function fetchRequestIntercept(intercept) {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
386
|
+
const { fetch: originalFetch } = window;
|
|
387
|
+
window.fetch = async (...args) => {
|
|
388
|
+
const [resource, config] = args;
|
|
389
|
+
return intercept(originalFetch, resource, config);
|
|
390
|
+
};
|
|
532
391
|
}
|
|
533
392
|
|
|
534
|
-
|
|
535
|
-
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/hooks/useMounted.ts
|
|
536
395
|
function useMounted() {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
396
|
+
const [mounted, setMounted] = (0, react.useState)(false);
|
|
397
|
+
(0, react.useEffect)(() => setMounted(true), []);
|
|
398
|
+
return mounted;
|
|
540
399
|
}
|
|
541
400
|
|
|
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");
|
|
401
|
+
//#endregion
|
|
402
|
+
//#region src/hooks/usePrevious.ts
|
|
550
403
|
function usePrevious(value) {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
404
|
+
const ref = (0, react.useRef)(void 0);
|
|
405
|
+
(0, react.useEffect)(() => {
|
|
406
|
+
ref.current = value;
|
|
407
|
+
});
|
|
408
|
+
return ref.current;
|
|
556
409
|
}
|
|
557
410
|
|
|
558
|
-
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/hooks/useWatch.ts
|
|
559
413
|
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
|
|
414
|
+
const firstUpdate = (0, react.useRef)(false);
|
|
415
|
+
const then = (0, react.useRef)(void 0);
|
|
416
|
+
const oldValue = usePrevious(source);
|
|
417
|
+
(0, react.useEffect)(() => {
|
|
418
|
+
if (!firstUpdate.current) recordFirst();
|
|
419
|
+
else callback(source, oldValue);
|
|
420
|
+
}, (0, react.useMemo)(() => Array.isArray(source) ? source : [source], [source]));
|
|
421
|
+
async function recordFirst() {
|
|
422
|
+
if (then.current) return;
|
|
423
|
+
then.current = Promise.resolve(source);
|
|
424
|
+
then.current.then(() => firstUpdate.current = true);
|
|
425
|
+
if (options.immediate) then.current.then((value) => callback(value, oldValue));
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/hooks/useOffsetPagination.ts
|
|
584
431
|
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
|
-
|
|
432
|
+
const [page, setPage] = (0, react.useState)(options.page || 1);
|
|
433
|
+
const [pageSize, setPageSize] = (0, react.useState)(options.pageSize || 10);
|
|
434
|
+
const total = options.total || 0;
|
|
435
|
+
const pageCount = (0, react.useMemo)(() => Math.max(1, Math.ceil(total / pageSize)), [total, pageSize]);
|
|
436
|
+
const isFirstPage = (0, react.useMemo)(() => page === 1, [page]);
|
|
437
|
+
const isLastPage = (0, react.useMemo)(() => page === pageCount, [page, pageCount]);
|
|
438
|
+
function next() {
|
|
439
|
+
setPage((page) => Math.min(pageCount, page + 1));
|
|
440
|
+
}
|
|
441
|
+
function prev() {
|
|
442
|
+
setPage((page) => Math.max(1, page - 1));
|
|
443
|
+
}
|
|
444
|
+
function pageChange(page) {
|
|
445
|
+
setPage(() => Math.max(1, Math.min(page, pageCount)));
|
|
446
|
+
}
|
|
447
|
+
function pageSizeChange(limit) {
|
|
448
|
+
setPageSize(limit);
|
|
449
|
+
pageChange(1);
|
|
450
|
+
}
|
|
451
|
+
const pagination = {
|
|
452
|
+
next,
|
|
453
|
+
prev,
|
|
454
|
+
page,
|
|
455
|
+
pageSize,
|
|
456
|
+
isFirstPage,
|
|
457
|
+
pageSizeChange,
|
|
458
|
+
pageChange,
|
|
459
|
+
isLastPage,
|
|
460
|
+
pageCount,
|
|
461
|
+
total
|
|
462
|
+
};
|
|
463
|
+
useWatch(page, () => options.onChange?.(pagination));
|
|
464
|
+
useWatch(pageSize, () => options.onPageSizeChange?.(pagination));
|
|
465
|
+
useWatch(pageCount, () => options.onPageCountChange?.(pagination));
|
|
466
|
+
return pagination;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/hooks/useWhenever.ts
|
|
623
471
|
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
|
-
*/
|
|
472
|
+
useWatch(source, (value, oldValue) => value && cb(value, oldValue), options);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
//#endregion
|
|
476
|
+
exports.Case = Case;
|
|
477
|
+
exports.Default = Default;
|
|
478
|
+
exports.Else = Else;
|
|
479
|
+
exports.If = If;
|
|
480
|
+
exports.Injector = Injector;
|
|
481
|
+
exports.Switch = Switch;
|
|
482
|
+
exports.Then = Then;
|
|
483
|
+
exports.Trigger = Trigger;
|
|
484
|
+
exports.Unless = Unless;
|
|
485
|
+
exports.cls = cls;
|
|
486
|
+
exports.track = track;
|
|
487
|
+
exports.tryUseCallback = tryUseCallback;
|
|
488
|
+
exports.tryUseEffect = tryUseEffect;
|
|
489
|
+
exports.tryUseInsertionEffect = tryUseInsertionEffect;
|
|
490
|
+
exports.tryUseReducer = tryUseReducer;
|
|
491
|
+
exports.tryUseRef = tryUseRef;
|
|
492
|
+
exports.tryUseState = tryUseState;
|
|
493
|
+
exports.tryUseUpdate = tryUseUpdate;
|
|
494
|
+
exports.useAsyncCallback = useAsyncCallback;
|
|
495
|
+
exports.useAsyncState = useAsyncState;
|
|
496
|
+
exports.useDebounce = useDebounce;
|
|
497
|
+
exports.useEventBus = useEventBus;
|
|
498
|
+
exports.useFetchRequestIntercept = useFetchRequestIntercept;
|
|
499
|
+
exports.useFetchResponseIntercept = useFetchResponseIntercept;
|
|
500
|
+
exports.useMounted = useMounted;
|
|
501
|
+
exports.useOffsetPagination = useOffsetPagination;
|
|
502
|
+
exports.useUpdate = useUpdate;
|
|
503
|
+
exports.useWatch = useWatch;
|
|
504
|
+
exports.useWhenever = useWhenever;
|
|
505
|
+
exports.wrapper = wrapper;
|