@tempots/beatui 0.77.0 → 0.78.2
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/{ar-CefikVG3.cjs → ar-DNoFBb9J.cjs} +1 -1
- package/dist/{ar-BbgpGwJp.js → ar-D__6gR_P.js} +1 -1
- package/dist/auth/index.cjs.js +1 -1
- package/dist/auth/index.es.js +5 -5
- package/dist/{colors-B9fcMxa_.cjs → colors-B2yrgHSW.cjs} +1 -1
- package/dist/{colors-pQZlNrwM.js → colors-DPo9GEJR.js} +6 -6
- package/dist/{de-ZRnkggf5.cjs → de-AwUkK0rS.cjs} +1 -1
- package/dist/{de-R7lPfyZ4.js → de-DmKpCTuQ.js} +1 -1
- package/dist/{deep-merge-E6b9KE6l.js → deep-merge-Bsqkvp9-.js} +5 -5
- package/dist/{deep-merge-DBUbjJYt.cjs → deep-merge-cQgRrtGF.cjs} +1 -1
- package/dist/{duration-input-j7bVks-S.js → duration-input-DcZf0Dyd.js} +3 -3
- package/dist/{duration-input-CsygvJJ_.cjs → duration-input-Dt6riwzu.cjs} +1 -1
- package/dist/{es-DV0Jr_BZ.js → es-BDZ5UJLS.js} +1 -1
- package/dist/{es-IkNtVSp2.cjs → es-D-d2AIlX.cjs} +1 -1
- package/dist/{fa-DXvHejs9.js → fa-CuPgy1cj.js} +1 -1
- package/dist/{fa-B-byOhgU.cjs → fa-D7rRdG8c.cjs} +1 -1
- package/dist/{fr-F0ZegdR2.cjs → fr-0er_BWMt.cjs} +1 -1
- package/dist/{fr-D8FOMX0o.js → fr-DmyMO3lB.js} +1 -1
- package/dist/{he-B19Qsx-u.js → he-C3RHfs6R.js} +1 -1
- package/dist/{he-BcEFNuYz.cjs → he-R2veUyP3.cjs} +1 -1
- package/dist/{hi-CarXvOJD.cjs → hi-C9UP7NGG.cjs} +1 -1
- package/dist/{hi-DozFnE3b.js → hi-YnvrXBht.js} +1 -1
- package/dist/hls.light.min-Bhrf47iR.cjs +27 -0
- package/dist/{hls.light.min-BHW1Af0w.js → hls.light.min-C6VwviEa.js} +1095 -1087
- package/dist/{index-B7lXSIXm.cjs → index-BGwNJNop.cjs} +19 -19
- package/dist/{index-DKl26ILa.js → index-CCMjK4fD.js} +1 -1
- package/dist/{index-gSTSk9KZ.cjs → index-CdVc1Y2V.cjs} +1 -1
- package/dist/{index-CyyNsVT9.cjs → index-DE2tjivA.cjs} +1 -1
- package/dist/{index-DdpYvBeh.js → index-Dbu1ZPpw.js} +1095 -1044
- package/dist/{index-wPyoqxuj.js → index-DiEcd7ZV.js} +2 -6
- package/dist/{index-CpZh_Snx.js → index-DklKfzD4.js} +1 -1
- package/dist/{index-CYb1YxDX.js → index-mPVib4v9.js} +1 -1
- package/dist/index.cjs.js +2 -2
- package/dist/index.es.js +21 -21
- package/dist/index.esm-C6lZ02yY.cjs +1 -0
- package/dist/{index.esm-DPNh6inz.js → index.esm-ChUrm4xR.js} +80 -80
- package/dist/{it-But8uzNi.js → it-CWLwlDXe.js} +1 -1
- package/dist/{it-ops3Czzi.cjs → it-Cxt1_D4h.cjs} +1 -1
- package/dist/{ja-2dzONSkh.cjs → ja-CpDovHPb.cjs} +1 -1
- package/dist/{ja-DkwTnFdU.js → ja-DthjgDtM.js} +1 -1
- package/dist/json-schema/index.cjs.js +8 -8
- package/dist/json-schema/index.es.js +3970 -3923
- package/dist/json-structure/index.cjs.js +1 -1
- package/dist/json-structure/index.es.js +5 -5
- package/dist/{ko-uVJEhtyQ.cjs → ko-M_MCTNuN.cjs} +1 -1
- package/dist/{ko-Cqv-IjhX.js → ko-joDK7ONT.js} +1 -1
- package/dist/markdown/index.es.js +1 -1
- package/dist/{modal-rLbLQYhb.cjs → modal-D3NQ6ZgO.cjs} +1 -1
- package/dist/{modal--5-j6x0s.js → modal-oWbT46Rc.js} +28 -28
- package/dist/monaco/index.cjs.js +2 -2
- package/dist/monaco/index.es.js +11 -11
- package/dist/{nl-DXnbYulJ.cjs → nl-DGhIOGxN.cjs} +1 -1
- package/dist/{nl-YSiU3rFI.js → nl-DmoWeXUt.js} +1 -1
- package/dist/{notice-BvS1_9Va.js → notice-C0Brmeyi.js} +2 -2
- package/dist/{notice-BGaJ4k0O.cjs → notice-DYBLXglS.cjs} +1 -1
- package/dist/{pl-DXmHc2Nh.js → pl-8hl5VXnm.js} +1 -1
- package/dist/{pl-RbiIBA3C.cjs → pl-DocnXix_.cjs} +1 -1
- package/dist/prosemirror/index.cjs.js +1 -1
- package/dist/prosemirror/index.es.js +1 -1
- package/dist/{pt-Bf3z_-26.js → pt-BfYK9Rl3.js} +1 -1
- package/dist/{pt-BAecyAv-.cjs → pt-DO2Zcuqv.cjs} +1 -1
- package/dist/{ru-DZ4gJ6yr.cjs → ru-D9KCOBqN.cjs} +1 -1
- package/dist/{ru-Sy00qUeG.js → ru-eA_dNkJz.js} +1 -1
- package/dist/tailwind/index.cjs.js +1 -1
- package/dist/tailwind/index.es.js +1 -1
- package/dist/tailwind/preset.cjs.js +1 -1
- package/dist/tailwind/preset.es.js +2 -2
- package/dist/tailwind/vite-plugin.cjs.js +1 -1
- package/dist/tailwind/vite-plugin.es.js +1 -1
- package/dist/timer-BJHOsuS6.cjs +1 -0
- package/dist/timer-Rd2sKnvH.js +65 -0
- package/dist/{toolbar-C_Ec0_XC.js → toolbar-CdY5huSG.js} +1 -1
- package/dist/{toolbar-wEm8iNet.cjs → toolbar-DoRPrs-s.cjs} +1 -1
- package/dist/{tr-7jGF_acJ.cjs → tr-BBmQvRSa.cjs} +1 -1
- package/dist/{tr-BDxG3qd6.js → tr-CdqbnopM.js} +1 -1
- package/dist/{translations-DQxouiBG.js → translations-BEMKy6-W.js} +19 -19
- package/dist/{translations-BmsRhth7.js → translations-CVfr2JXG.js} +1 -1
- package/dist/{translations-C7HVMcOQ.cjs → translations-D_Vu2mbd.cjs} +1 -1
- package/dist/{translations-hMQlZmD4.cjs → translations-eUtMHN9s.cjs} +1 -1
- package/dist/{ur-55zdT2TQ.js → ur-D9sr_I1M.js} +1 -1
- package/dist/{ur-ZT6fZFId.cjs → ur-u5qjZsKM.cjs} +1 -1
- package/dist/use-form-DMiCxK26.js +1731 -0
- package/dist/use-form-pSErMD6z.cjs +2 -0
- package/dist/{vi-C7K7W0hM.js → vi-0f97dtZb.js} +1 -1
- package/dist/{vi-tNs62pgs.cjs → vi-_w5RE8el.cjs} +1 -1
- package/dist/{widget-customization-DKlfR6Qb.cjs → widget-customization-WNWmH_gX.cjs} +1 -1
- package/dist/{widget-customization-DfBf7gGp.js → widget-customization-nxbAoCx5.js} +4 -4
- package/dist/{zh-CBnP8_Lf.cjs → zh-6cQcHbf6.cjs} +1 -1
- package/dist/{zh-DvJBV9D8.js → zh-C7HcUKhE.js} +1 -1
- package/package.json +7 -4
- package/dist/hls.light.min-D3hUMpII.cjs +0 -27
- package/dist/index.esm-DJRz9AE-.cjs +0 -1
- package/dist/timer-DK_yKNwE.cjs +0 -1
- package/dist/timer-DzWb416P.js +0 -51
- package/dist/use-form-B4D58mxd.cjs +0 -2
- package/dist/use-form-DzA1RSrN.js +0 -1325
|
@@ -0,0 +1,1731 @@
|
|
|
1
|
+
import { Use as X, coalesce as Y, aria as L, attr as d, html as y, on as V, Value as F, Empty as D, computedOf as S, When as N, dataAttr as B, TextNode as Z, prop as w, Fragment as q, emitValue as ee, emitValueAsNumber as se } from "@tempots/dom";
|
|
2
|
+
import { a as te, B as re, c as R, b as ie } from "./translations-BEMKy6-W.js";
|
|
3
|
+
const H = /* @__PURE__ */ new Map();
|
|
4
|
+
function x(e) {
|
|
5
|
+
const s = H.get(e) ?? 0;
|
|
6
|
+
return H.set(e, s + 1), `${e}-${s}`;
|
|
7
|
+
}
|
|
8
|
+
const a = {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a loading state.
|
|
11
|
+
* @param previousValue - The previous value.
|
|
12
|
+
* @returns A loading state.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
notAsked: { type: "NotAsked" },
|
|
16
|
+
/**
|
|
17
|
+
* Creates a loading state.
|
|
18
|
+
* @param previousValue - The previous value.
|
|
19
|
+
* @returns A loading state.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
loading(e = void 0) {
|
|
23
|
+
return { type: "Loading", previousValue: e };
|
|
24
|
+
},
|
|
25
|
+
/**
|
|
26
|
+
* Creates a successful state.
|
|
27
|
+
* @param value - The value.
|
|
28
|
+
* @returns A successful state.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
success(e) {
|
|
32
|
+
return { type: "AsyncSuccess", value: e };
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Creates a failure state.
|
|
36
|
+
* @param error - The error.
|
|
37
|
+
* @returns A failure state.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
failure(e) {
|
|
41
|
+
return { type: "AsyncFailure", error: e };
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* Checks if the result is a success.
|
|
45
|
+
* @param r - The result.
|
|
46
|
+
* @returns `true` if the result is a success; otherwise, `false`.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
isSuccess(e) {
|
|
50
|
+
return e.type === "AsyncSuccess";
|
|
51
|
+
},
|
|
52
|
+
/**
|
|
53
|
+
* Checks if the result is a failure.
|
|
54
|
+
* @param r - The result.
|
|
55
|
+
* @returns `true` if the result is a failure; otherwise, `false`.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
isFailure(e) {
|
|
59
|
+
return e.type === "AsyncFailure";
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Checks if the result is a not-asked.
|
|
63
|
+
* @param r - The result.
|
|
64
|
+
* @returns `true` if the result is not-asked; otherwise, `false`.
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
isNotAsked(e) {
|
|
68
|
+
return e.type === "NotAsked";
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* Checks if the result is a loading.
|
|
72
|
+
* @param r - The result.
|
|
73
|
+
* @returns `true` if the result is loading; otherwise, `false`.
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
isLoading(e) {
|
|
77
|
+
return e.type === "Loading";
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* Gets the value if the result is a success; otherwise, returns the alternative value.
|
|
81
|
+
* @param r - The result.
|
|
82
|
+
* @param alt - The alternative value.
|
|
83
|
+
* @returns The value if the result is a success; otherwise, the alternative value.
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
getOrElse(e, s) {
|
|
87
|
+
return a.isSuccess(e) ? e.value : s;
|
|
88
|
+
},
|
|
89
|
+
/**
|
|
90
|
+
* Gets the value if the result is a success; otherwise, returns the value from the alternative function.
|
|
91
|
+
* @param r - The result.
|
|
92
|
+
* @param altf - The alternative function.
|
|
93
|
+
* @returns The value if the result is a success; otherwise, the value from the alternative
|
|
94
|
+
* @public
|
|
95
|
+
* function.
|
|
96
|
+
*/
|
|
97
|
+
getOrElseLazy(e, s) {
|
|
98
|
+
return a.isSuccess(e) ? e.value : s();
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Gets the value if the result is a success; otherwise, returns `null`.
|
|
102
|
+
* @param r - The result.
|
|
103
|
+
* @returns The value if the result is a success; otherwise, `null`.
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
getOrNull(e) {
|
|
107
|
+
return a.isSuccess(e) ? e.value : null;
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* Gets the value if the result is a success; otherwise, returns `undefined`.
|
|
111
|
+
* @param r - The result.
|
|
112
|
+
* @returns The value if the result is a success; otherwise, `undefined`.
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
getOrUndefined(e) {
|
|
116
|
+
return a.isSuccess(e) ? e.value : void 0;
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Gets the value of a `AsyncResult` if it is a `Success`, otherwise it throws the error contained in the `Failure`.
|
|
120
|
+
* @param r - The `AsyncResult` to get the value from.
|
|
121
|
+
* @returns The value of the `AsyncResult` if it is a `Success`.
|
|
122
|
+
*/
|
|
123
|
+
getUnsafe: (e) => {
|
|
124
|
+
if (a.isSuccess(e))
|
|
125
|
+
return e.value;
|
|
126
|
+
throw a.isFailure(e) ? e.error : new Error("Cannot get value from a not-asked or loading result");
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* Based on the state of the result, it picks the appropriate function to call and returns the result.
|
|
130
|
+
* @param success - The function to call if the result is a success.
|
|
131
|
+
* @param failure - The function to call if the result is a failure.
|
|
132
|
+
* @param loading - The function to call if the result is loading.
|
|
133
|
+
* @param notAsked - The function to call if the result is not-asked.
|
|
134
|
+
* @returns The result of calling the appropriate function based on the state of the result.
|
|
135
|
+
* @public
|
|
136
|
+
*/
|
|
137
|
+
match: (e, {
|
|
138
|
+
success: s,
|
|
139
|
+
failure: t,
|
|
140
|
+
loading: r,
|
|
141
|
+
notAsked: i = r
|
|
142
|
+
}) => a.isSuccess(e) ? s(e.value) : a.isFailure(e) ? t(e.error) : a.isNotAsked(e) ? i() : r(e.previousValue),
|
|
143
|
+
/**
|
|
144
|
+
* Executes side effects based on the state of the result.
|
|
145
|
+
* Unlike `match`, all handlers are optional, allowing you to react only to specific states.
|
|
146
|
+
* The `else` handler is called when no specific handler is provided for the current state.
|
|
147
|
+
* @param r - The result.
|
|
148
|
+
* @param handlers - An object with optional handlers for each state and an optional `else` fallback.
|
|
149
|
+
* @returns The result that was passed in, allowing for chaining.
|
|
150
|
+
* @public
|
|
151
|
+
*/
|
|
152
|
+
effect: (e, s) => {
|
|
153
|
+
switch (e.type) {
|
|
154
|
+
case "AsyncSuccess":
|
|
155
|
+
s.success ? s.success(e.value) : s.else?.();
|
|
156
|
+
break;
|
|
157
|
+
case "AsyncFailure":
|
|
158
|
+
s.failure ? s.failure(e.error) : s.else?.();
|
|
159
|
+
break;
|
|
160
|
+
case "Loading":
|
|
161
|
+
s.loading ? s.loading(e.previousValue) : s.else?.();
|
|
162
|
+
break;
|
|
163
|
+
case "NotAsked":
|
|
164
|
+
s.notAsked ? s.notAsked() : s.else?.();
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
return e;
|
|
168
|
+
},
|
|
169
|
+
/**
|
|
170
|
+
* When the result is a success, it applies the function to the value.
|
|
171
|
+
*
|
|
172
|
+
* @param r - The result.
|
|
173
|
+
* @param apply - The function to apply.
|
|
174
|
+
* @returns The result that was passed in.
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
whenSuccess: (e, s) => (a.isSuccess(e) && s(e.value), e),
|
|
178
|
+
/**
|
|
179
|
+
* When the result is a failure, it applies the function to the error.
|
|
180
|
+
*
|
|
181
|
+
* @param r - The result.
|
|
182
|
+
* @param apply - The function to apply.
|
|
183
|
+
* @returns The result that was passed in.
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
whenFailure: (e, s) => (a.isFailure(e) && s(e.error), e),
|
|
187
|
+
/**
|
|
188
|
+
* Compares two results for equality.
|
|
189
|
+
* @param r1 - The first result.
|
|
190
|
+
* @param r2 - The second result.
|
|
191
|
+
* @param options - The options to use for comparison. By default, uses strict equality.
|
|
192
|
+
* @returns `true` if the results are equal, `false` otherwise.
|
|
193
|
+
*/
|
|
194
|
+
equals: (e, s, t = {
|
|
195
|
+
valueEquals: (r, i) => r === i,
|
|
196
|
+
errorEquals: (r, i) => r === i
|
|
197
|
+
}) => e.type === "AsyncSuccess" && s.type === "AsyncSuccess" ? t.valueEquals(e.value, s.value) : e.type === "AsyncFailure" && s.type === "AsyncFailure" ? t.errorEquals(e.error, s.error) : e.type === "Loading" && s.type === "Loading" ? t.valueEquals(e.previousValue, s.previousValue) : e.type === "NotAsked" && s.type === "NotAsked",
|
|
198
|
+
/**
|
|
199
|
+
* Combines multiple results into a single result.
|
|
200
|
+
* @param results - The results to combine.
|
|
201
|
+
* @returns A single result that is a success if all the input results are successes, otherwise a failure.
|
|
202
|
+
*/
|
|
203
|
+
all: (e) => {
|
|
204
|
+
const s = [];
|
|
205
|
+
for (const t of e)
|
|
206
|
+
if (a.isSuccess(t))
|
|
207
|
+
s.push(t.value);
|
|
208
|
+
else
|
|
209
|
+
return t;
|
|
210
|
+
return a.success(s);
|
|
211
|
+
},
|
|
212
|
+
/**
|
|
213
|
+
* Converts a Promise to an AsyncResult.
|
|
214
|
+
* @param p - The Promise to convert.
|
|
215
|
+
* @returns A Promise that resolves to an AsyncResult.
|
|
216
|
+
*/
|
|
217
|
+
ofPromise: async (e) => {
|
|
218
|
+
try {
|
|
219
|
+
const s = await e;
|
|
220
|
+
return a.success(s);
|
|
221
|
+
} catch (s) {
|
|
222
|
+
return a.failure(s instanceof Error ? s : new Error(String(s)));
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
/**
|
|
226
|
+
* Maps the value of a successful `AsyncResult` to a new value using the provided function.
|
|
227
|
+
* For other states (NotAsked, Loading, Failure), the state is preserved.
|
|
228
|
+
* When mapping a Loading state with a previous value, the previous value is also mapped.
|
|
229
|
+
* @param result - The `AsyncResult` to map.
|
|
230
|
+
* @param fn - The mapping function to apply to the success value.
|
|
231
|
+
* @returns A new `AsyncResult` with the mapped value if successful, otherwise the original state.
|
|
232
|
+
* @public
|
|
233
|
+
*/
|
|
234
|
+
map: (e, s) => {
|
|
235
|
+
switch (e.type) {
|
|
236
|
+
case "AsyncSuccess":
|
|
237
|
+
return a.success(s(e.value));
|
|
238
|
+
case "NotAsked":
|
|
239
|
+
return a.notAsked;
|
|
240
|
+
case "AsyncFailure":
|
|
241
|
+
return a.failure(e.error);
|
|
242
|
+
case "Loading":
|
|
243
|
+
return a.loading(
|
|
244
|
+
e.previousValue != null ? s(e.previousValue) : void 0
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
/**
|
|
249
|
+
* Maps the value of a successful `AsyncResult` to a new `AsyncResult` using the provided function.
|
|
250
|
+
* This is useful for chaining operations that may also fail.
|
|
251
|
+
* @param result - The `AsyncResult` to flat map.
|
|
252
|
+
* @param fn - The mapping function that returns a new `AsyncResult`.
|
|
253
|
+
* @returns The result of the mapping function if successful, otherwise the original state.
|
|
254
|
+
* @public
|
|
255
|
+
*/
|
|
256
|
+
flatMap: (e, s) => {
|
|
257
|
+
switch (e.type) {
|
|
258
|
+
case "AsyncSuccess":
|
|
259
|
+
return s(e.value);
|
|
260
|
+
case "NotAsked":
|
|
261
|
+
return a.notAsked;
|
|
262
|
+
case "AsyncFailure":
|
|
263
|
+
return a.failure(e.error);
|
|
264
|
+
case "Loading":
|
|
265
|
+
return a.loading();
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
/**
|
|
269
|
+
* Maps the error of a failed `AsyncResult` to a new error using the provided function.
|
|
270
|
+
* For other states, the state is preserved.
|
|
271
|
+
* @param result - The `AsyncResult` to map the error of.
|
|
272
|
+
* @param fn - The mapping function to apply to the error.
|
|
273
|
+
* @returns A new `AsyncResult` with the mapped error if failed, otherwise the original state.
|
|
274
|
+
* @public
|
|
275
|
+
*/
|
|
276
|
+
mapError: (e, s) => {
|
|
277
|
+
switch (e.type) {
|
|
278
|
+
case "AsyncSuccess":
|
|
279
|
+
return a.success(e.value);
|
|
280
|
+
case "NotAsked":
|
|
281
|
+
return a.notAsked;
|
|
282
|
+
case "AsyncFailure":
|
|
283
|
+
return a.failure(s(e.error));
|
|
284
|
+
case "Loading":
|
|
285
|
+
return a.loading(e.previousValue);
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
/**
|
|
289
|
+
* Maps the error of a failed `AsyncResult` to a new `AsyncResult` using the provided function.
|
|
290
|
+
* This allows recovery from errors by returning a new successful result.
|
|
291
|
+
* @param result - The `AsyncResult` to recover from.
|
|
292
|
+
* @param fn - The recovery function that returns a new `AsyncResult`.
|
|
293
|
+
* @returns The result of the recovery function if failed, otherwise the original state.
|
|
294
|
+
* @public
|
|
295
|
+
*/
|
|
296
|
+
flatMapError: (e, s) => {
|
|
297
|
+
switch (e.type) {
|
|
298
|
+
case "AsyncSuccess":
|
|
299
|
+
return a.success(e.value);
|
|
300
|
+
case "NotAsked":
|
|
301
|
+
return a.notAsked;
|
|
302
|
+
case "AsyncFailure":
|
|
303
|
+
return s(e.error);
|
|
304
|
+
case "Loading":
|
|
305
|
+
return a.loading(e.previousValue);
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
/**
|
|
309
|
+
* Converts an `AsyncResult` to a `Result`, discarding the loading and not-asked states.
|
|
310
|
+
* Returns `undefined` if the result is not settled (i.e., NotAsked or Loading).
|
|
311
|
+
* @param result - The `AsyncResult` to convert.
|
|
312
|
+
* @returns A `Result` if the `AsyncResult` is settled, otherwise `undefined`.
|
|
313
|
+
* @public
|
|
314
|
+
*/
|
|
315
|
+
toResult: (e) => {
|
|
316
|
+
switch (e.type) {
|
|
317
|
+
case "AsyncSuccess":
|
|
318
|
+
return { type: "Success", value: e.value };
|
|
319
|
+
case "AsyncFailure":
|
|
320
|
+
return { type: "Failure", error: e.error };
|
|
321
|
+
case "NotAsked":
|
|
322
|
+
case "Loading":
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
/**
|
|
327
|
+
* Checks if the result is settled (either success or failure).
|
|
328
|
+
* @param r - The result.
|
|
329
|
+
* @returns `true` if the result is settled; otherwise, `false`.
|
|
330
|
+
* @public
|
|
331
|
+
*/
|
|
332
|
+
isSettled(e) {
|
|
333
|
+
return e.type === "AsyncSuccess" || e.type === "AsyncFailure";
|
|
334
|
+
},
|
|
335
|
+
/**
|
|
336
|
+
* Recovers from a failure by providing an alternative value.
|
|
337
|
+
* @param result - The `AsyncResult` to recover from.
|
|
338
|
+
* @param fn - The function that provides an alternative value given the error.
|
|
339
|
+
* @returns A successful `AsyncResult` with the alternative value if failed, otherwise the original state.
|
|
340
|
+
* @public
|
|
341
|
+
*/
|
|
342
|
+
recover: (e, s) => {
|
|
343
|
+
switch (e.type) {
|
|
344
|
+
case "AsyncSuccess":
|
|
345
|
+
return a.success(e.value);
|
|
346
|
+
case "NotAsked":
|
|
347
|
+
return a.notAsked;
|
|
348
|
+
case "AsyncFailure":
|
|
349
|
+
return a.success(s(e.error));
|
|
350
|
+
case "Loading":
|
|
351
|
+
return a.loading(e.previousValue);
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
/**
|
|
355
|
+
* Applies a function wrapped in an `AsyncResult` to a value wrapped in an `AsyncResult`.
|
|
356
|
+
* Useful for applying multiple arguments to a function in a safe way.
|
|
357
|
+
* @param resultFn - The `AsyncResult` containing the function.
|
|
358
|
+
* @param resultVal - The `AsyncResult` containing the value.
|
|
359
|
+
* @returns A new `AsyncResult` with the result of applying the function to the value.
|
|
360
|
+
* @public
|
|
361
|
+
*/
|
|
362
|
+
ap: (e, s) => a.isSuccess(e) && a.isSuccess(s) ? a.success(e.value(s.value)) : a.isFailure(e) ? a.failure(e.error) : a.isFailure(s) ? a.failure(s.error) : a.isLoading(e) || a.isLoading(s) ? a.loading() : a.notAsked,
|
|
363
|
+
/**
|
|
364
|
+
* Maps two `AsyncResult` values using a function.
|
|
365
|
+
* @param r1 - The first `AsyncResult`.
|
|
366
|
+
* @param r2 - The second `AsyncResult`.
|
|
367
|
+
* @param fn - The function to apply to both values.
|
|
368
|
+
* @returns A new `AsyncResult` with the result of applying the function to both values.
|
|
369
|
+
* @public
|
|
370
|
+
*/
|
|
371
|
+
map2: (e, s, t) => a.isSuccess(e) && a.isSuccess(s) ? a.success(t(e.value, s.value)) : a.isFailure(e) ? a.failure(e.error) : a.isFailure(s) ? a.failure(s.error) : a.isLoading(e) || a.isLoading(s) ? a.loading() : a.notAsked,
|
|
372
|
+
/**
|
|
373
|
+
* Maps three `AsyncResult` values using a function.
|
|
374
|
+
* @param r1 - The first `AsyncResult`.
|
|
375
|
+
* @param r2 - The second `AsyncResult`.
|
|
376
|
+
* @param r3 - The third `AsyncResult`.
|
|
377
|
+
* @param fn - The function to apply to all three values.
|
|
378
|
+
* @returns A new `AsyncResult` with the result of applying the function to all three values.
|
|
379
|
+
* @public
|
|
380
|
+
*/
|
|
381
|
+
map3: (e, s, t, r) => a.isSuccess(e) && a.isSuccess(s) && a.isSuccess(t) ? a.success(r(e.value, s.value, t.value)) : a.isFailure(e) ? a.failure(e.error) : a.isFailure(s) ? a.failure(s.error) : a.isFailure(t) ? a.failure(t.error) : a.isLoading(e) || a.isLoading(s) || a.isLoading(t) ? a.loading() : a.notAsked
|
|
382
|
+
}, T = (e, s) => e === s || e !== e && s !== s, h = {
|
|
383
|
+
/**
|
|
384
|
+
* Creates a valid `Validation`.
|
|
385
|
+
* @returns A `Validation` that is `Valid`.
|
|
386
|
+
*/
|
|
387
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
388
|
+
valid: { type: "valid" },
|
|
389
|
+
/**
|
|
390
|
+
* Creates an invalid `Validation`.
|
|
391
|
+
* @param error - The error associated with the invalid value.
|
|
392
|
+
* @returns A `Validation` that is `Invalid`.
|
|
393
|
+
*/
|
|
394
|
+
invalid(e) {
|
|
395
|
+
return { type: "invalid", error: e };
|
|
396
|
+
},
|
|
397
|
+
/**
|
|
398
|
+
* Checks if a `Validation` is `Valid`.
|
|
399
|
+
* @param r - The `Validation` to check.
|
|
400
|
+
* @returns `true` if the `Validation` is `Valid`, otherwise `false`.
|
|
401
|
+
*/
|
|
402
|
+
isValid(e) {
|
|
403
|
+
return e.type === "valid";
|
|
404
|
+
},
|
|
405
|
+
/**
|
|
406
|
+
* Checks if a `Validation` is `Invalid`.
|
|
407
|
+
* @param r - The `Validation` to check.
|
|
408
|
+
* @returns `true` if the `Validation` is `Invalid`, otherwise `false`.
|
|
409
|
+
*/
|
|
410
|
+
isInvalid(e) {
|
|
411
|
+
return e.type === "invalid";
|
|
412
|
+
},
|
|
413
|
+
/**
|
|
414
|
+
* Maps the value of a `Validation` to a new value.
|
|
415
|
+
* @param r - The `Validation` to map.
|
|
416
|
+
* @param valid - The mapping function for a valid value.
|
|
417
|
+
* @param invalid - The mapping function for an invalid value.
|
|
418
|
+
* @returns The mapped value.
|
|
419
|
+
*/
|
|
420
|
+
match: (e, s, t) => h.isValid(e) ? s() : t(e.error),
|
|
421
|
+
/**
|
|
422
|
+
* Maps the value of a `Validation` to a new `Validation`.
|
|
423
|
+
* @param validation - The `Validation` to map.
|
|
424
|
+
* @param value - The value to map.
|
|
425
|
+
* @returns A new `Validation` with the mapped value.
|
|
426
|
+
*/
|
|
427
|
+
toResult: (e, s) => h.match(
|
|
428
|
+
e,
|
|
429
|
+
() => c.success(s),
|
|
430
|
+
(t) => c.failure(t)
|
|
431
|
+
),
|
|
432
|
+
/**
|
|
433
|
+
* Executes side effects based on the state of the validation.
|
|
434
|
+
* Unlike `match`, all handlers are optional, allowing you to react only to specific states.
|
|
435
|
+
* The `else` handler is called when no specific handler is provided for the current state.
|
|
436
|
+
* @param v - The validation.
|
|
437
|
+
* @param handlers - An object with optional handlers for each state and an optional `else` fallback.
|
|
438
|
+
* @returns The validation that was passed in, allowing for chaining.
|
|
439
|
+
* @public
|
|
440
|
+
*/
|
|
441
|
+
effect: (e, s) => (e.type === "valid" ? s.valid ? s.valid() : s.else?.() : s.invalid ? s.invalid(e.error) : s.else?.(), e),
|
|
442
|
+
/**
|
|
443
|
+
* Execute a function when the `Validation` is valid.
|
|
444
|
+
*
|
|
445
|
+
* @param r - The `Validation` to check.
|
|
446
|
+
* @param apply - The function to execute when the `Validation` is valid.
|
|
447
|
+
* @returns The `Validation` object.
|
|
448
|
+
*/
|
|
449
|
+
whenValid: (e, s) => (h.isValid(e) && s(), e),
|
|
450
|
+
/**
|
|
451
|
+
* Execute a function when the `Validation` is invalid.
|
|
452
|
+
*
|
|
453
|
+
* @param r - The `Validation` to check.
|
|
454
|
+
* @param apply - The function to execute when the `Validation` is invalid.
|
|
455
|
+
* @returns The `Validation` object.
|
|
456
|
+
*/
|
|
457
|
+
whenInvalid: (e, s) => (h.isInvalid(e) && s(e.error), e),
|
|
458
|
+
/**
|
|
459
|
+
* Maps the error of an invalid `Validation` to a new error using the provided function.
|
|
460
|
+
* For valid validations, the validation is preserved unchanged.
|
|
461
|
+
* @param v - The `Validation` to map the error of.
|
|
462
|
+
* @param f - The mapping function to apply to the error.
|
|
463
|
+
* @returns A new `Validation` with the mapped error if invalid, otherwise the original valid.
|
|
464
|
+
* @public
|
|
465
|
+
*/
|
|
466
|
+
mapError: (e, s) => e.type === "invalid" ? h.invalid(s(e.error)) : e,
|
|
467
|
+
/**
|
|
468
|
+
* Maps the error of an invalid `Validation` to a new `Validation` using the provided function.
|
|
469
|
+
* This allows recovery from errors by returning a valid validation.
|
|
470
|
+
* @param v - The `Validation` to recover from.
|
|
471
|
+
* @param f - The recovery function that returns a new `Validation`.
|
|
472
|
+
* @returns The result of the recovery function if invalid, otherwise the original valid.
|
|
473
|
+
* @public
|
|
474
|
+
*/
|
|
475
|
+
flatMapError: (e, s) => e.type === "invalid" ? s(e.error) : e,
|
|
476
|
+
/**
|
|
477
|
+
* Combines two validations. Both must be valid for the result to be valid.
|
|
478
|
+
* If both are invalid, errors are combined using the provided function.
|
|
479
|
+
* @param v1 - The first validation.
|
|
480
|
+
* @param v2 - The second validation.
|
|
481
|
+
* @param combineErrors - The function to combine two errors.
|
|
482
|
+
* @returns A combined validation.
|
|
483
|
+
* @public
|
|
484
|
+
*/
|
|
485
|
+
combine: (e, s, t) => h.isValid(e) && h.isValid(s) ? h.valid : h.isInvalid(e) && h.isInvalid(s) ? h.invalid(t(e.error, s.error)) : h.isInvalid(e) ? e : s,
|
|
486
|
+
/**
|
|
487
|
+
* Combines multiple validations into a single validation.
|
|
488
|
+
* All must be valid for the result to be valid.
|
|
489
|
+
* Returns the first invalid validation if any.
|
|
490
|
+
* @param validations - The validations to combine.
|
|
491
|
+
* @returns A single validation that is valid only if all inputs are valid.
|
|
492
|
+
* @public
|
|
493
|
+
*/
|
|
494
|
+
all: (e) => {
|
|
495
|
+
for (const s of e)
|
|
496
|
+
if (h.isInvalid(s))
|
|
497
|
+
return s;
|
|
498
|
+
return h.valid;
|
|
499
|
+
},
|
|
500
|
+
/**
|
|
501
|
+
* Combines multiple validations, accumulating all errors.
|
|
502
|
+
* All must be valid for the result to be valid.
|
|
503
|
+
* If any are invalid, all errors are collected into an array.
|
|
504
|
+
* @param validations - The validations to combine.
|
|
505
|
+
* @returns A validation that is valid only if all inputs are valid, otherwise contains all errors.
|
|
506
|
+
* @public
|
|
507
|
+
*/
|
|
508
|
+
allErrors: (e) => {
|
|
509
|
+
const s = [];
|
|
510
|
+
for (const t of e)
|
|
511
|
+
h.isInvalid(t) && s.push(t.error);
|
|
512
|
+
return s.length > 0 ? h.invalid(s) : h.valid;
|
|
513
|
+
},
|
|
514
|
+
/**
|
|
515
|
+
* Compares two validations for equality.
|
|
516
|
+
* @param v1 - The first validation.
|
|
517
|
+
* @param v2 - The second validation.
|
|
518
|
+
* @param errorEquals - Optional custom equality function for errors. Defaults to strict equality.
|
|
519
|
+
* @returns `true` if the validations are equal, `false` otherwise.
|
|
520
|
+
* @public
|
|
521
|
+
*/
|
|
522
|
+
equals: (e, s, t = (r, i) => r === i) => e.type === "valid" && s.type === "valid" ? !0 : e.type === "invalid" && s.type === "invalid" ? t(e.error, s.error) : !1,
|
|
523
|
+
/**
|
|
524
|
+
* Recovers from an invalid validation by returning a valid validation.
|
|
525
|
+
* @param v - The `Validation` to recover from.
|
|
526
|
+
* @returns A valid validation regardless of the input.
|
|
527
|
+
* @public
|
|
528
|
+
*/
|
|
529
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
530
|
+
recover: (e) => h.valid,
|
|
531
|
+
/**
|
|
532
|
+
* Gets the error if the validation is invalid, otherwise returns undefined.
|
|
533
|
+
* @param v - The validation to get the error from.
|
|
534
|
+
* @returns The error if invalid, otherwise undefined.
|
|
535
|
+
* @public
|
|
536
|
+
*/
|
|
537
|
+
getError: (e) => {
|
|
538
|
+
if (h.isInvalid(e))
|
|
539
|
+
return e.error;
|
|
540
|
+
},
|
|
541
|
+
/**
|
|
542
|
+
* Gets the error if the validation is invalid, otherwise returns the default value.
|
|
543
|
+
* @param v - The validation to get the error from.
|
|
544
|
+
* @param defaultError - The default error to return if valid.
|
|
545
|
+
* @returns The error if invalid, otherwise the default error.
|
|
546
|
+
* @public
|
|
547
|
+
*/
|
|
548
|
+
getErrorOrElse: (e, s) => h.isInvalid(e) ? e.error : s
|
|
549
|
+
}, c = {
|
|
550
|
+
/**
|
|
551
|
+
* Creates a successful `Result`.
|
|
552
|
+
* @param value - The value to wrap in a `Success` type.
|
|
553
|
+
* @returns A `Result` that is a `Success`.
|
|
554
|
+
* @public
|
|
555
|
+
*/
|
|
556
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
557
|
+
success(e) {
|
|
558
|
+
return { type: "Success", value: e };
|
|
559
|
+
},
|
|
560
|
+
/**
|
|
561
|
+
* Creates a failure `Result`.
|
|
562
|
+
* @param error - The error to wrap in a `Failure` type.
|
|
563
|
+
* @returns A `Result` that is a `Failure`.
|
|
564
|
+
* @public
|
|
565
|
+
*/
|
|
566
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
567
|
+
failure(e) {
|
|
568
|
+
return { type: "Failure", error: e };
|
|
569
|
+
},
|
|
570
|
+
/**
|
|
571
|
+
* Maps the value of a `Result` to a new value.
|
|
572
|
+
* @param r - The `Result` to map.
|
|
573
|
+
* @param f - The mapping function.
|
|
574
|
+
* @returns A new `Result` with the mapped value.
|
|
575
|
+
* @public
|
|
576
|
+
*/
|
|
577
|
+
map: (e, s) => e.type === "Success" ? c.success(s(e.value)) : e,
|
|
578
|
+
/**
|
|
579
|
+
* Maps the value of a `Result` to a new `Result`.
|
|
580
|
+
* @param r - The `Result` to map.
|
|
581
|
+
* @param f - The mapping function.
|
|
582
|
+
* @returns A new `Result` with the mapped value.
|
|
583
|
+
* @public
|
|
584
|
+
*/
|
|
585
|
+
flatMap: (e, s) => e.type === "Success" ? s(e.value) : e,
|
|
586
|
+
/**
|
|
587
|
+
* Converts a `Result` to an `AsyncResult`.
|
|
588
|
+
* @param r - The `Result` to convert.
|
|
589
|
+
* @returns An `AsyncResult` that is equivalent to the input `Result`.
|
|
590
|
+
* @public
|
|
591
|
+
*/
|
|
592
|
+
toAsync(e) {
|
|
593
|
+
return c.match(
|
|
594
|
+
e,
|
|
595
|
+
(s) => a.success(s),
|
|
596
|
+
(s) => a.failure(s)
|
|
597
|
+
);
|
|
598
|
+
},
|
|
599
|
+
/**
|
|
600
|
+
* Converts a `Result` to a `Validation`.
|
|
601
|
+
* @param r - The `Result` to convert.
|
|
602
|
+
* @returns A `Validation` that is equivalent to the input `Result`.
|
|
603
|
+
* @public
|
|
604
|
+
*/
|
|
605
|
+
toValidation(e) {
|
|
606
|
+
return c.match(
|
|
607
|
+
e,
|
|
608
|
+
() => h.valid,
|
|
609
|
+
(s) => h.invalid(s)
|
|
610
|
+
);
|
|
611
|
+
},
|
|
612
|
+
/**
|
|
613
|
+
* Checks if a `Result` is a success.
|
|
614
|
+
* @param r - The `Result` to check.
|
|
615
|
+
* @returns `true` if the `Result` is a `Success`, `false` otherwise.
|
|
616
|
+
* @public
|
|
617
|
+
*/
|
|
618
|
+
isSuccess(e) {
|
|
619
|
+
return e.type === "Success";
|
|
620
|
+
},
|
|
621
|
+
/**
|
|
622
|
+
* Checks if a `Result` is a failure.
|
|
623
|
+
* @param r - The `Result` to check.
|
|
624
|
+
* @returns `true` if the `Result` is a `Failure`, `false` otherwise.
|
|
625
|
+
* @public
|
|
626
|
+
*/
|
|
627
|
+
isFailure(e) {
|
|
628
|
+
return e.type === "Failure";
|
|
629
|
+
},
|
|
630
|
+
/**
|
|
631
|
+
* Gets the value of a `Result` if it is a `Success`, otherwise returns the provided default value.
|
|
632
|
+
* @param r - The `Result` to get the value from.
|
|
633
|
+
* @param alt - The default value to return if the `Result` is a `Failure`.
|
|
634
|
+
* @returns The value of the `Result` if it is a `Success`, otherwise the default value.
|
|
635
|
+
* @public
|
|
636
|
+
*/
|
|
637
|
+
getOrElse(e, s) {
|
|
638
|
+
return c.isSuccess(e) ? e.value : s;
|
|
639
|
+
},
|
|
640
|
+
/**
|
|
641
|
+
* Gets the value of a `Result` if it is a `Success`, otherwise returns the result of the provided function.
|
|
642
|
+
* @param r - The `Result` to get the value from.
|
|
643
|
+
* @param altf - The function to call if the `Result` is a `Failure`.
|
|
644
|
+
* @returns The value of the `Result` if it is a `Success`, otherwise the result of the function.
|
|
645
|
+
* @public
|
|
646
|
+
*/
|
|
647
|
+
getOrElseLazy(e, s) {
|
|
648
|
+
return c.isSuccess(e) ? e.value : s();
|
|
649
|
+
},
|
|
650
|
+
/**
|
|
651
|
+
* Gets the value of a `Result` if it is a `Success`, otherwise returns `null`.
|
|
652
|
+
* @param r - The `Result` to get the value from.
|
|
653
|
+
* @returns The value of the `Result` if it is a `Success`, otherwise `null`.
|
|
654
|
+
* @public
|
|
655
|
+
*/
|
|
656
|
+
getOrNull(e) {
|
|
657
|
+
return c.isSuccess(e) ? e.value : null;
|
|
658
|
+
},
|
|
659
|
+
/**
|
|
660
|
+
* Gets the value of a `Result` if it is a `Success`, otherwise returns `undefined`.
|
|
661
|
+
* @param r - The `Result` to get the value from.
|
|
662
|
+
* @returns The value of the `Result` if it is a `Success`, otherwise `undefined`.
|
|
663
|
+
* @public
|
|
664
|
+
*/
|
|
665
|
+
getOrUndefined(e) {
|
|
666
|
+
return c.isSuccess(e) ? e.value : void 0;
|
|
667
|
+
},
|
|
668
|
+
/**
|
|
669
|
+
* Gets the value of a `Result` if it is a `Success`, otherwise it throws the error contained in the `Failure`.
|
|
670
|
+
* @param r - The `Result` to get the value from.
|
|
671
|
+
* @returns The value of the `Result` if it is a `Success`.
|
|
672
|
+
*/
|
|
673
|
+
getUnsafe: (e) => {
|
|
674
|
+
if (c.isSuccess(e))
|
|
675
|
+
return e.value;
|
|
676
|
+
throw e.error;
|
|
677
|
+
},
|
|
678
|
+
/**
|
|
679
|
+
* Based on the state of the result, it picks the appropriate function to call and returns the result.
|
|
680
|
+
* @param success - The function to call if the result is a success.
|
|
681
|
+
* @param failure - The function to call if the result is a failure.
|
|
682
|
+
* @returns The result of calling the appropriate function based on the state of the result.
|
|
683
|
+
* @public
|
|
684
|
+
*/
|
|
685
|
+
match: (e, s, t) => c.isSuccess(e) ? s(e.value) : t(e.error),
|
|
686
|
+
/**
|
|
687
|
+
* Executes side effects based on the state of the result.
|
|
688
|
+
* Unlike `match`, all handlers are optional, allowing you to react only to specific states.
|
|
689
|
+
* The `else` handler is called when no specific handler is provided for the current state.
|
|
690
|
+
* @param r - The result.
|
|
691
|
+
* @param handlers - An object with optional handlers for each state and an optional `else` fallback.
|
|
692
|
+
* @returns The result that was passed in, allowing for chaining.
|
|
693
|
+
* @public
|
|
694
|
+
*/
|
|
695
|
+
effect: (e, s) => (e.type === "Success" ? s.success ? s.success(e.value) : s.else?.() : s.failure ? s.failure(e.error) : s.else?.(), e),
|
|
696
|
+
/**
|
|
697
|
+
* Calls the provided function if the result is a success.
|
|
698
|
+
* @param apply - The function to call if the result is a success.
|
|
699
|
+
* @returns A function that takes a `Result` and calls the provided function if the result is a success.
|
|
700
|
+
* @public
|
|
701
|
+
*/
|
|
702
|
+
whenSuccess: (e, s) => (c.isSuccess(e) && s(e.value), e),
|
|
703
|
+
/**
|
|
704
|
+
* Calls the provided function if the result is a failure.
|
|
705
|
+
* @param apply - The function to call if the result is a failure.
|
|
706
|
+
* @returns The result that was passed in.
|
|
707
|
+
* @public
|
|
708
|
+
*/
|
|
709
|
+
whenFailure: (e, s) => (c.isFailure(e) && s(e.error), e),
|
|
710
|
+
/**
|
|
711
|
+
* Combines two results into a single result.
|
|
712
|
+
* @param r1 - The first result.
|
|
713
|
+
* @param r2 - The second result.
|
|
714
|
+
* @param combineV - The function to combine two values.
|
|
715
|
+
* @param combineE - The function to combine two errors.
|
|
716
|
+
* @returns The combined result.
|
|
717
|
+
* @public
|
|
718
|
+
*/
|
|
719
|
+
combine: (e, s, t, r) => c.match(
|
|
720
|
+
e,
|
|
721
|
+
(i) => c.match(
|
|
722
|
+
s,
|
|
723
|
+
(n) => c.success(t(i, n)),
|
|
724
|
+
(n) => c.failure(n)
|
|
725
|
+
),
|
|
726
|
+
(i) => c.match(
|
|
727
|
+
s,
|
|
728
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
729
|
+
(n) => c.failure(i),
|
|
730
|
+
(n) => c.failure(r(i, n))
|
|
731
|
+
)
|
|
732
|
+
),
|
|
733
|
+
/**
|
|
734
|
+
* Compares two results for equality.
|
|
735
|
+
* @param r1 - The first result.
|
|
736
|
+
* @param r2 - The second result.
|
|
737
|
+
* @param options - The options to use for comparison. By default, uses strict equality.
|
|
738
|
+
* @returns `true` if the results are equal, `false` otherwise.
|
|
739
|
+
*/
|
|
740
|
+
equals: (e, s, t = {
|
|
741
|
+
valueEquals: (r, i) => r === i,
|
|
742
|
+
errorEquals: (r, i) => r === i
|
|
743
|
+
}) => e.type === "Success" && s.type === "Success" ? t.valueEquals(e.value, s.value) : e.type === "Failure" && s.type === "Failure" ? t.errorEquals(e.error, s.error) : !1,
|
|
744
|
+
/**
|
|
745
|
+
* Combines multiple results into a single result.
|
|
746
|
+
* @param results - The results to combine.
|
|
747
|
+
* @returns A single result that is a success if all the input results are successes, otherwise a failure.
|
|
748
|
+
*/
|
|
749
|
+
all: (e) => {
|
|
750
|
+
const s = [];
|
|
751
|
+
for (const t of e)
|
|
752
|
+
if (c.isSuccess(t))
|
|
753
|
+
s.push(t.value);
|
|
754
|
+
else
|
|
755
|
+
return t;
|
|
756
|
+
return c.success(s);
|
|
757
|
+
},
|
|
758
|
+
/**
|
|
759
|
+
* Maps the error of a failed `Result` to a new error using the provided function.
|
|
760
|
+
* For success results, the result is preserved unchanged.
|
|
761
|
+
* @param r - The `Result` to map the error of.
|
|
762
|
+
* @param f - The mapping function to apply to the error.
|
|
763
|
+
* @returns A new `Result` with the mapped error if failed, otherwise the original success.
|
|
764
|
+
* @public
|
|
765
|
+
*/
|
|
766
|
+
mapError: (e, s) => e.type === "Failure" ? c.failure(s(e.error)) : e,
|
|
767
|
+
/**
|
|
768
|
+
* Maps the error of a failed `Result` to a new `Result` using the provided function.
|
|
769
|
+
* This allows recovery from errors by returning a new successful result.
|
|
770
|
+
* @param r - The `Result` to recover from.
|
|
771
|
+
* @param f - The recovery function that returns a new `Result`.
|
|
772
|
+
* @returns The result of the recovery function if failed, otherwise the original success.
|
|
773
|
+
* @public
|
|
774
|
+
*/
|
|
775
|
+
flatMapError: (e, s) => e.type === "Failure" ? s(e.error) : e,
|
|
776
|
+
/**
|
|
777
|
+
* Recovers from a failure by providing an alternative value.
|
|
778
|
+
* @param r - The `Result` to recover from.
|
|
779
|
+
* @param f - The function that provides an alternative value given the error.
|
|
780
|
+
* @returns A successful `Result` with the alternative value if failed, otherwise the original success.
|
|
781
|
+
* @public
|
|
782
|
+
*/
|
|
783
|
+
recover: (e, s) => e.type === "Failure" ? { type: "Success", value: s(e.error) } : e,
|
|
784
|
+
/**
|
|
785
|
+
* Applies a function wrapped in a `Result` to a value wrapped in a `Result`.
|
|
786
|
+
* Useful for applying multiple arguments to a function in a safe way.
|
|
787
|
+
* @param resultFn - The `Result` containing the function.
|
|
788
|
+
* @param resultVal - The `Result` containing the value.
|
|
789
|
+
* @returns A new `Result` with the result of applying the function to the value.
|
|
790
|
+
* @public
|
|
791
|
+
*/
|
|
792
|
+
ap: (e, s) => c.isSuccess(e) && c.isSuccess(s) ? c.success(e.value(s.value)) : c.isFailure(e) ? c.failure(e.error) : c.failure(s.error),
|
|
793
|
+
/**
|
|
794
|
+
* Maps two `Result` values using a function.
|
|
795
|
+
* @param r1 - The first `Result`.
|
|
796
|
+
* @param r2 - The second `Result`.
|
|
797
|
+
* @param f - The function to apply to both values.
|
|
798
|
+
* @returns A new `Result` with the result of applying the function to both values.
|
|
799
|
+
* @public
|
|
800
|
+
*/
|
|
801
|
+
map2: (e, s, t) => c.isSuccess(e) && c.isSuccess(s) ? c.success(t(e.value, s.value)) : c.isFailure(e) ? c.failure(e.error) : c.failure(s.error),
|
|
802
|
+
/**
|
|
803
|
+
* Maps three `Result` values using a function.
|
|
804
|
+
* @param r1 - The first `Result`.
|
|
805
|
+
* @param r2 - The second `Result`.
|
|
806
|
+
* @param r3 - The third `Result`.
|
|
807
|
+
* @param f - The function to apply to all three values.
|
|
808
|
+
* @returns A new `Result` with the result of applying the function to all three values.
|
|
809
|
+
* @public
|
|
810
|
+
*/
|
|
811
|
+
map3: (e, s, t, r) => c.isSuccess(e) && c.isSuccess(s) && c.isSuccess(t) ? c.success(r(e.value, s.value, t.value)) : c.isFailure(e) ? c.failure(e.error) : c.isFailure(s) ? c.failure(s.error) : c.failure(t.error),
|
|
812
|
+
/**
|
|
813
|
+
* Converts a Promise to a Result.
|
|
814
|
+
* @param p - The Promise to convert.
|
|
815
|
+
* @returns A Promise that resolves to a Result.
|
|
816
|
+
* @public
|
|
817
|
+
*/
|
|
818
|
+
ofPromise: async (e) => {
|
|
819
|
+
try {
|
|
820
|
+
const s = await e;
|
|
821
|
+
return c.success(s);
|
|
822
|
+
} catch (s) {
|
|
823
|
+
return c.failure(s instanceof Error ? s : new Error(String(s)));
|
|
824
|
+
}
|
|
825
|
+
},
|
|
826
|
+
/**
|
|
827
|
+
* Swaps the success and failure values of a Result.
|
|
828
|
+
* A success becomes a failure with the value as the error,
|
|
829
|
+
* and a failure becomes a success with the error as the value.
|
|
830
|
+
* @param r - The Result to swap.
|
|
831
|
+
* @returns A new Result with swapped success and failure.
|
|
832
|
+
* @public
|
|
833
|
+
*/
|
|
834
|
+
swap: (e) => c.isSuccess(e) ? c.failure(e.value) : c.success(e.error),
|
|
835
|
+
/**
|
|
836
|
+
* Converts a nullable value to a Result.
|
|
837
|
+
* @param value - The nullable value.
|
|
838
|
+
* @param error - The error to use if the value is null or undefined.
|
|
839
|
+
* @returns A Result containing the value if not null/undefined, otherwise a failure.
|
|
840
|
+
* @public
|
|
841
|
+
*/
|
|
842
|
+
fromNullable: (e, s) => e == null ? c.failure(s) : c.success(e),
|
|
843
|
+
/**
|
|
844
|
+
* Converts a nullable value to a Result using a lazy error function.
|
|
845
|
+
* @param value - The nullable value.
|
|
846
|
+
* @param errorFn - The function to call to get the error if the value is null or undefined.
|
|
847
|
+
* @returns A Result containing the value if not null/undefined, otherwise a failure.
|
|
848
|
+
* @public
|
|
849
|
+
*/
|
|
850
|
+
fromNullableLazy: (e, s) => e == null ? c.failure(s()) : c.success(e),
|
|
851
|
+
/**
|
|
852
|
+
* Wraps a function that may throw into a function that returns a Result.
|
|
853
|
+
* @param f - The function that may throw.
|
|
854
|
+
* @returns A function that returns a Result instead of throwing.
|
|
855
|
+
* @public
|
|
856
|
+
*/
|
|
857
|
+
tryCatch: (e) => {
|
|
858
|
+
try {
|
|
859
|
+
return c.success(e());
|
|
860
|
+
} catch (s) {
|
|
861
|
+
return c.failure(s instanceof Error ? s : new Error(String(s)));
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
function we({
|
|
866
|
+
size: e = "sm",
|
|
867
|
+
icon: s = "line-md:close",
|
|
868
|
+
disabled: t,
|
|
869
|
+
roundedness: r = "full",
|
|
870
|
+
color: i = "base",
|
|
871
|
+
onClick: n,
|
|
872
|
+
label: o
|
|
873
|
+
}, ...l) {
|
|
874
|
+
return X(te, (u) => {
|
|
875
|
+
const v = Y(o, u.$.closeModal);
|
|
876
|
+
return re(
|
|
877
|
+
{
|
|
878
|
+
variant: "text",
|
|
879
|
+
size: e,
|
|
880
|
+
roundedness: r,
|
|
881
|
+
disabled: t,
|
|
882
|
+
color: i,
|
|
883
|
+
onClick: n
|
|
884
|
+
},
|
|
885
|
+
d.title(v),
|
|
886
|
+
L.label(v),
|
|
887
|
+
...l,
|
|
888
|
+
R({ icon: s, size: e ?? "sm" })
|
|
889
|
+
);
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
function $(e) {
|
|
893
|
+
return `bc-label bc-label--${e}`;
|
|
894
|
+
}
|
|
895
|
+
const Ae = (...e) => y.span(d.class($("emphasis")), ...e), ae = (...e) => y.span(d.class($("default")), ...e), ne = (...e) => y.span(d.class($("muted")), ...e), Ee = (...e) => y.span(d.class($("danger")), ...e), Fe = (e) => {
|
|
896
|
+
const {
|
|
897
|
+
value: s,
|
|
898
|
+
onBlur: t,
|
|
899
|
+
onChange: r,
|
|
900
|
+
placeholder: i,
|
|
901
|
+
disabled: n,
|
|
902
|
+
id: o,
|
|
903
|
+
checkedIcon: l,
|
|
904
|
+
uncheckedIcon: u,
|
|
905
|
+
iconSize: v = "lg"
|
|
906
|
+
} = e, p = o ?? x("checkbox"), g = `${p}-label`, k = () => {
|
|
907
|
+
if (F.get(n ?? !1)) return;
|
|
908
|
+
const f = F.get(s);
|
|
909
|
+
r?.(!f);
|
|
910
|
+
}, A = (f) => {
|
|
911
|
+
F.get(n ?? !1) || (f.key === " " || f.key === "Enter") && (f.preventDefault(), k());
|
|
912
|
+
};
|
|
913
|
+
return ie(
|
|
914
|
+
{
|
|
915
|
+
baseContainer: !0,
|
|
916
|
+
growInput: !1,
|
|
917
|
+
...e,
|
|
918
|
+
input: y.span(
|
|
919
|
+
d.class("bc-checkbox-input"),
|
|
920
|
+
y.span(
|
|
921
|
+
d.class("bc-checkbox-input__checkbox"),
|
|
922
|
+
d.class(
|
|
923
|
+
F.map(
|
|
924
|
+
s,
|
|
925
|
+
(f) => f ? "bc-checkbox-input__checkbox--checked" : "bc-checkbox-input__checkbox--unchecked"
|
|
926
|
+
)
|
|
927
|
+
),
|
|
928
|
+
d.class(
|
|
929
|
+
F.map(
|
|
930
|
+
n ?? !1,
|
|
931
|
+
(f) => f ? "bc-checkbox-input__checkbox--disabled" : ""
|
|
932
|
+
)
|
|
933
|
+
),
|
|
934
|
+
d.id(p),
|
|
935
|
+
d.role("checkbox"),
|
|
936
|
+
d.tabindex(
|
|
937
|
+
F.map(
|
|
938
|
+
n ?? !1,
|
|
939
|
+
(f) => f ? -1 : 0
|
|
940
|
+
)
|
|
941
|
+
),
|
|
942
|
+
L.checked(s),
|
|
943
|
+
L.disabled(n),
|
|
944
|
+
i != null ? L.labelledby(g) : D,
|
|
945
|
+
V.keydown(A),
|
|
946
|
+
t != null ? V.blur(t) : D,
|
|
947
|
+
R({
|
|
948
|
+
icon: S(
|
|
949
|
+
s,
|
|
950
|
+
l,
|
|
951
|
+
u
|
|
952
|
+
)(
|
|
953
|
+
(f, m, E) => f ? m ?? "akar-icons/check-box-fill" : E ?? "akar-icons/box"
|
|
954
|
+
),
|
|
955
|
+
accessibility: "decorative",
|
|
956
|
+
size: v
|
|
957
|
+
})
|
|
958
|
+
),
|
|
959
|
+
i != null ? y.label(
|
|
960
|
+
d.class("bc-checkbox-input__label"),
|
|
961
|
+
d.id(g),
|
|
962
|
+
d.for(p),
|
|
963
|
+
ne(i)
|
|
964
|
+
) : D
|
|
965
|
+
)
|
|
966
|
+
},
|
|
967
|
+
V.click(k)
|
|
968
|
+
);
|
|
969
|
+
}, le = y.span(
|
|
970
|
+
d.class("bc-input-wrapper__required"),
|
|
971
|
+
" *"
|
|
972
|
+
);
|
|
973
|
+
function ce(e) {
|
|
974
|
+
const s = ["bc-input-wrapper"];
|
|
975
|
+
return e !== "vertical" && s.push(`bc-input-wrapper--${e}`), s.join(" ");
|
|
976
|
+
}
|
|
977
|
+
function oe(e, s) {
|
|
978
|
+
const t = ["bc-input-wrapper__label-text"];
|
|
979
|
+
return e ? t.push("bc-input-wrapper__label-text--error") : s ? t.push("bc-input-wrapper__label-text--disabled") : t.push("bc-input-wrapper__label-text--default"), t.join(" ");
|
|
980
|
+
}
|
|
981
|
+
function ue(e, s) {
|
|
982
|
+
if (e === "horizontal-fixed" && s != null)
|
|
983
|
+
return `--input-wrapper-label-width: ${s}`;
|
|
984
|
+
}
|
|
985
|
+
const W = ({
|
|
986
|
+
fullWidth: e = !1,
|
|
987
|
+
required: s,
|
|
988
|
+
label: t,
|
|
989
|
+
labelChildren: r,
|
|
990
|
+
context: i,
|
|
991
|
+
description: n,
|
|
992
|
+
content: o,
|
|
993
|
+
error: l,
|
|
994
|
+
labelFor: u,
|
|
995
|
+
hasError: v,
|
|
996
|
+
disabled: p,
|
|
997
|
+
layout: g,
|
|
998
|
+
labelWidth: k
|
|
999
|
+
}, ...A) => {
|
|
1000
|
+
const f = v ?? l != null, m = p ?? !1, E = g ?? "vertical", _ = x("input-wrapper"), M = n ? `${_}-description` : void 0, j = l != null ? `${_}-error` : void 0, P = S(E)((b) => b !== "vertical"), Q = S(
|
|
1001
|
+
E,
|
|
1002
|
+
k ?? void 0
|
|
1003
|
+
)((b, I) => ue(b, I));
|
|
1004
|
+
return y.div(
|
|
1005
|
+
d.class(F.map(E, (b) => ce(b))),
|
|
1006
|
+
d.class(
|
|
1007
|
+
F.map(
|
|
1008
|
+
e,
|
|
1009
|
+
(b) => b ? "bc-input-wrapper--full-width" : ""
|
|
1010
|
+
)
|
|
1011
|
+
),
|
|
1012
|
+
d.style(Q),
|
|
1013
|
+
t != null || i != null ? y.div(
|
|
1014
|
+
d.class("bc-input-wrapper__header"),
|
|
1015
|
+
y.div(
|
|
1016
|
+
d.class("bc-input-wrapper__label-section"),
|
|
1017
|
+
y.label(
|
|
1018
|
+
d.class("bc-input-wrapper__label"),
|
|
1019
|
+
u != null ? d.for(u) : D,
|
|
1020
|
+
y.span(
|
|
1021
|
+
d.class(
|
|
1022
|
+
S(
|
|
1023
|
+
f,
|
|
1024
|
+
m
|
|
1025
|
+
)(
|
|
1026
|
+
(b, I) => oe(
|
|
1027
|
+
b ?? !1,
|
|
1028
|
+
I ?? !1
|
|
1029
|
+
)
|
|
1030
|
+
)
|
|
1031
|
+
),
|
|
1032
|
+
t
|
|
1033
|
+
),
|
|
1034
|
+
t != null && s ? le : D
|
|
1035
|
+
),
|
|
1036
|
+
// Show description under label when horizontal
|
|
1037
|
+
N(
|
|
1038
|
+
S(
|
|
1039
|
+
P,
|
|
1040
|
+
n
|
|
1041
|
+
)((b, I) => b && I != null),
|
|
1042
|
+
() => y.div(
|
|
1043
|
+
d.class(
|
|
1044
|
+
"bc-input-wrapper__description bc-input-wrapper__description--under-label"
|
|
1045
|
+
),
|
|
1046
|
+
d.id(M),
|
|
1047
|
+
n
|
|
1048
|
+
)
|
|
1049
|
+
)
|
|
1050
|
+
),
|
|
1051
|
+
i != null ? ae(i) : D,
|
|
1052
|
+
r
|
|
1053
|
+
) : D,
|
|
1054
|
+
y.div(
|
|
1055
|
+
d.class("bc-input-wrapper__content"),
|
|
1056
|
+
// Add data attributes to help inputs inherit accessibility information
|
|
1057
|
+
[M, j].filter(Boolean).length > 0 ? B.describedby(
|
|
1058
|
+
[M, j].filter(Boolean).join(" ")
|
|
1059
|
+
) : D,
|
|
1060
|
+
s ? B.required("true") : D,
|
|
1061
|
+
N(f, () => B.invalid("true")),
|
|
1062
|
+
o
|
|
1063
|
+
),
|
|
1064
|
+
// Show description at bottom only when not horizontal
|
|
1065
|
+
N(
|
|
1066
|
+
S(P, n)((b, I) => !b && I != null),
|
|
1067
|
+
() => y.div(
|
|
1068
|
+
d.class("bc-input-wrapper__description"),
|
|
1069
|
+
d.id(M),
|
|
1070
|
+
n
|
|
1071
|
+
)
|
|
1072
|
+
),
|
|
1073
|
+
N(
|
|
1074
|
+
f,
|
|
1075
|
+
() => y.div(
|
|
1076
|
+
d.class("bc-input-wrapper__error"),
|
|
1077
|
+
d.id(j),
|
|
1078
|
+
L.live("polite"),
|
|
1079
|
+
// Announce errors to screen readers
|
|
1080
|
+
d.role("alert"),
|
|
1081
|
+
// Mark as alert for immediate attention
|
|
1082
|
+
l
|
|
1083
|
+
)
|
|
1084
|
+
),
|
|
1085
|
+
...A
|
|
1086
|
+
);
|
|
1087
|
+
};
|
|
1088
|
+
function De(...e) {
|
|
1089
|
+
return y.div(d.class("bc-stack"), ...e);
|
|
1090
|
+
}
|
|
1091
|
+
const de = (
|
|
1092
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1093
|
+
((e, s) => () => {
|
|
1094
|
+
e.markTouched(), s?.();
|
|
1095
|
+
})
|
|
1096
|
+
), z = (e, s) => (t) => {
|
|
1097
|
+
e.change(t), s?.(t);
|
|
1098
|
+
};
|
|
1099
|
+
function K(e, s) {
|
|
1100
|
+
const { controller: t, onBlur: r, onChange: i, id: n, triggerOn: o, ...l } = s;
|
|
1101
|
+
return e({
|
|
1102
|
+
id: n ?? t.name,
|
|
1103
|
+
disabled: t.disabled,
|
|
1104
|
+
value: t.signal,
|
|
1105
|
+
hasError: t.errorVisible,
|
|
1106
|
+
name: t.name,
|
|
1107
|
+
...l,
|
|
1108
|
+
onInput: o === "input" ? z(t, i) : void 0,
|
|
1109
|
+
onChange: o !== "input" ? z(t, i) : void 0,
|
|
1110
|
+
onBlur: de(t, r)
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
function Ce(e, { id: s, labelFor: t, ...r }, ...i) {
|
|
1114
|
+
const n = s ?? r.controller.name ?? x("control"), o = t ?? n;
|
|
1115
|
+
return W(
|
|
1116
|
+
{
|
|
1117
|
+
...r,
|
|
1118
|
+
hasError: r.controller.errorVisible,
|
|
1119
|
+
error: Z(r.controller.error.map((l) => l ?? "")),
|
|
1120
|
+
labelFor: o,
|
|
1121
|
+
content: K(
|
|
1122
|
+
(l) => e({ ...l, id: n }),
|
|
1123
|
+
r
|
|
1124
|
+
)
|
|
1125
|
+
},
|
|
1126
|
+
...i
|
|
1127
|
+
);
|
|
1128
|
+
}
|
|
1129
|
+
function he(e, s) {
|
|
1130
|
+
const { toInput: t, fromInput: r, controller: i, ...n } = s, o = i.transform(t, r);
|
|
1131
|
+
return K(e, {
|
|
1132
|
+
...n,
|
|
1133
|
+
controller: o
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
function Ie(e, {
|
|
1137
|
+
id: s,
|
|
1138
|
+
labelFor: t,
|
|
1139
|
+
...r
|
|
1140
|
+
}, ...i) {
|
|
1141
|
+
const n = s ?? r.controller.name ?? x("control");
|
|
1142
|
+
return W(
|
|
1143
|
+
{
|
|
1144
|
+
...r,
|
|
1145
|
+
labelFor: t ?? n,
|
|
1146
|
+
content: he(e, {
|
|
1147
|
+
...r,
|
|
1148
|
+
id: n
|
|
1149
|
+
})
|
|
1150
|
+
},
|
|
1151
|
+
...i
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
function Ve(e) {
|
|
1155
|
+
return e.split(".").map((t) => {
|
|
1156
|
+
const r = t.match(/^\[(\d+)\]$/);
|
|
1157
|
+
return r ? Number(r[1]) : t;
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
function pe(e) {
|
|
1161
|
+
return typeof e == "number" ? `[${e}]` : `.${e}`;
|
|
1162
|
+
}
|
|
1163
|
+
function fe(e) {
|
|
1164
|
+
if (e.length === 0) return "";
|
|
1165
|
+
const [s, ...t] = e;
|
|
1166
|
+
return [
|
|
1167
|
+
typeof s == "number" ? `[${s}]` : s,
|
|
1168
|
+
...t.map(pe)
|
|
1169
|
+
].join("");
|
|
1170
|
+
}
|
|
1171
|
+
const Te = {
|
|
1172
|
+
/** A valid validation result */
|
|
1173
|
+
valid: h.valid,
|
|
1174
|
+
/**
|
|
1175
|
+
* Create an invalid validation with a message
|
|
1176
|
+
*/
|
|
1177
|
+
invalid(e) {
|
|
1178
|
+
return h.invalid({ message: e });
|
|
1179
|
+
},
|
|
1180
|
+
/**
|
|
1181
|
+
* Create an invalid validation with field-specific errors.
|
|
1182
|
+
* Values can be error messages (strings) or full ControllerError objects.
|
|
1183
|
+
*/
|
|
1184
|
+
invalidFields(e) {
|
|
1185
|
+
const s = {};
|
|
1186
|
+
for (const [t, r] of Object.entries(e))
|
|
1187
|
+
s[t] = typeof r == "string" ? { message: r } : r;
|
|
1188
|
+
return h.invalid({ dependencies: s });
|
|
1189
|
+
},
|
|
1190
|
+
/**
|
|
1191
|
+
* Create an invalid validation from a ControllerError object
|
|
1192
|
+
*/
|
|
1193
|
+
fromError(e) {
|
|
1194
|
+
return h.invalid(e);
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
1197
|
+
function O(e) {
|
|
1198
|
+
return function(t) {
|
|
1199
|
+
if (t.type === "valid") return t;
|
|
1200
|
+
let r = t.error;
|
|
1201
|
+
for (const i of e)
|
|
1202
|
+
if (r = r?.dependencies?.[i], r == null) return h.valid;
|
|
1203
|
+
return h.invalid(r);
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
class C {
|
|
1207
|
+
path;
|
|
1208
|
+
change;
|
|
1209
|
+
signal;
|
|
1210
|
+
status;
|
|
1211
|
+
error;
|
|
1212
|
+
hasError;
|
|
1213
|
+
touched;
|
|
1214
|
+
errorVisible;
|
|
1215
|
+
dirty;
|
|
1216
|
+
dependencyErrors;
|
|
1217
|
+
#e = {
|
|
1218
|
+
disabled: w(!1),
|
|
1219
|
+
touched: w(!1)
|
|
1220
|
+
};
|
|
1221
|
+
#t;
|
|
1222
|
+
#s = w(void 0);
|
|
1223
|
+
parent;
|
|
1224
|
+
disabled;
|
|
1225
|
+
#r = [];
|
|
1226
|
+
disabledOrHasErrors;
|
|
1227
|
+
constructor(s, t, r, i, n, o = T) {
|
|
1228
|
+
this.path = s, this.change = t, this.signal = r, this.status = i, this.#t = o, this.#s.set(r.value), this.error = i.map(
|
|
1229
|
+
(l) => l?.type === "invalid" ? l.error?.message : void 0
|
|
1230
|
+
), this.hasError = this.error.map((l) => l != null), this.touched = this.#e.touched, n.validationMode ? this.errorVisible = S(
|
|
1231
|
+
this.hasError,
|
|
1232
|
+
this.touched,
|
|
1233
|
+
n.validationMode
|
|
1234
|
+
)((l, u, v) => v === "eager" ? !!l : !!l && !!u) : this.errorVisible = S(
|
|
1235
|
+
this.hasError,
|
|
1236
|
+
this.touched
|
|
1237
|
+
)((l, u) => !!l && !!u), this.dirty = S(
|
|
1238
|
+
this.signal,
|
|
1239
|
+
this.#s
|
|
1240
|
+
)((l, u) => !this.#t(l, u)), this.dependencyErrors = i.map(
|
|
1241
|
+
(l) => l?.type === "invalid" ? l.error?.dependencies : void 0
|
|
1242
|
+
), this.parent = n, this.disabled = S(
|
|
1243
|
+
this.#e.disabled,
|
|
1244
|
+
n.disabled
|
|
1245
|
+
)((l, u) => l || u), this.disabledOrHasErrors = S(
|
|
1246
|
+
this.disabled,
|
|
1247
|
+
this.hasError
|
|
1248
|
+
)((l, u) => l || u), this.onDispose(() => {
|
|
1249
|
+
this.#e.disabled.dispose(), this.#e.touched.dispose(), this.disabled.dispose(), this.error.dispose(), this.errorVisible.dispose(), this.dirty.dispose(), this.#s.dispose(), this.dependencyErrors.dispose(), this.disabledOrHasErrors.dispose();
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
get name() {
|
|
1253
|
+
return fe(this.path);
|
|
1254
|
+
}
|
|
1255
|
+
onDispose = (s) => {
|
|
1256
|
+
this.#r.push(s);
|
|
1257
|
+
};
|
|
1258
|
+
dispose = () => {
|
|
1259
|
+
for (const s of this.#r)
|
|
1260
|
+
try {
|
|
1261
|
+
s();
|
|
1262
|
+
} catch (t) {
|
|
1263
|
+
console.error("Error in dispose callback:", t);
|
|
1264
|
+
}
|
|
1265
|
+
this.#r.length = 0;
|
|
1266
|
+
};
|
|
1267
|
+
setDisabled = (s) => {
|
|
1268
|
+
this.#e.disabled.set(s);
|
|
1269
|
+
};
|
|
1270
|
+
disable = () => this.setDisabled(!0);
|
|
1271
|
+
enable = () => this.setDisabled(!1);
|
|
1272
|
+
markTouched = () => {
|
|
1273
|
+
this.#e.touched.set(!0);
|
|
1274
|
+
};
|
|
1275
|
+
resetTouched = () => {
|
|
1276
|
+
this.#e.touched.set(!1);
|
|
1277
|
+
};
|
|
1278
|
+
markPristine = () => {
|
|
1279
|
+
this.#s.set(this.signal.value);
|
|
1280
|
+
};
|
|
1281
|
+
reset = () => {
|
|
1282
|
+
this.change(this.#s.value);
|
|
1283
|
+
};
|
|
1284
|
+
array = (s = T) => new ye(
|
|
1285
|
+
this.path,
|
|
1286
|
+
this.change,
|
|
1287
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1288
|
+
this.signal,
|
|
1289
|
+
this.status,
|
|
1290
|
+
this.parent,
|
|
1291
|
+
s
|
|
1292
|
+
);
|
|
1293
|
+
object = (s = T) => new ve(
|
|
1294
|
+
this.path,
|
|
1295
|
+
this.change,
|
|
1296
|
+
this.signal,
|
|
1297
|
+
this.status,
|
|
1298
|
+
this.parent,
|
|
1299
|
+
s
|
|
1300
|
+
);
|
|
1301
|
+
transform = (s, t, r = [], i = T) => new C(
|
|
1302
|
+
[...this.path, ...r],
|
|
1303
|
+
(n) => this.change(t(n)),
|
|
1304
|
+
this.signal.map(s, i),
|
|
1305
|
+
this.status.map(O(r)),
|
|
1306
|
+
this.parent,
|
|
1307
|
+
i
|
|
1308
|
+
);
|
|
1309
|
+
asyncTransform = (s, t, r, i = [], n = T) => new C(
|
|
1310
|
+
[...this.path, ...i],
|
|
1311
|
+
(o) => {
|
|
1312
|
+
t(o).then((l) => this.change(l));
|
|
1313
|
+
},
|
|
1314
|
+
this.signal.mapAsync(s, r, void 0, n),
|
|
1315
|
+
this.status.map(O(i)),
|
|
1316
|
+
this.parent,
|
|
1317
|
+
n
|
|
1318
|
+
);
|
|
1319
|
+
}
|
|
1320
|
+
class ve extends C {
|
|
1321
|
+
#e = /* @__PURE__ */ new Map();
|
|
1322
|
+
#t = /* @__PURE__ */ new Map();
|
|
1323
|
+
#s = /* @__PURE__ */ new Map();
|
|
1324
|
+
#r = w(!1);
|
|
1325
|
+
touchedDeep = this.#r;
|
|
1326
|
+
#a = /* @__PURE__ */ new Map();
|
|
1327
|
+
#i = /* @__PURE__ */ new Map();
|
|
1328
|
+
#l = w(!1);
|
|
1329
|
+
dirtyDeep = this.#l;
|
|
1330
|
+
#o;
|
|
1331
|
+
#u;
|
|
1332
|
+
#c = () => {
|
|
1333
|
+
let s = !1;
|
|
1334
|
+
for (const t of this.#t.values())
|
|
1335
|
+
if (t) {
|
|
1336
|
+
s = !0;
|
|
1337
|
+
break;
|
|
1338
|
+
}
|
|
1339
|
+
this.#r.set(this.touched.value || s);
|
|
1340
|
+
};
|
|
1341
|
+
constructor(s, t, r, i, n, o) {
|
|
1342
|
+
super(
|
|
1343
|
+
s,
|
|
1344
|
+
t,
|
|
1345
|
+
r.map((u) => u ?? {}, o),
|
|
1346
|
+
i,
|
|
1347
|
+
n,
|
|
1348
|
+
o
|
|
1349
|
+
), this.#o = this.touched.on(() => {
|
|
1350
|
+
this.#c();
|
|
1351
|
+
}), this.#u = this.dirty.on(() => {
|
|
1352
|
+
this.#n();
|
|
1353
|
+
});
|
|
1354
|
+
const l = this.signal.on(() => this.#n());
|
|
1355
|
+
this.onDispose(() => {
|
|
1356
|
+
for (const u of this.#e.values())
|
|
1357
|
+
u.dispose();
|
|
1358
|
+
this.#e.clear();
|
|
1359
|
+
for (const u of this.#s.values()) u();
|
|
1360
|
+
this.#s.clear(), this.#t.clear(), this.#r.dispose();
|
|
1361
|
+
for (const u of this.#i.values()) u();
|
|
1362
|
+
this.#i.clear(), this.#a.clear(), this.#l.dispose(), this.#o(), this.#u(), l();
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
field = (s) => {
|
|
1366
|
+
if (this.#e.has(s))
|
|
1367
|
+
return this.#e.get(s);
|
|
1368
|
+
const t = async (o) => {
|
|
1369
|
+
this.change({
|
|
1370
|
+
...this.signal.value,
|
|
1371
|
+
[s]: o
|
|
1372
|
+
});
|
|
1373
|
+
}, r = new C(
|
|
1374
|
+
[...this.path, s],
|
|
1375
|
+
t,
|
|
1376
|
+
this.signal.map((o) => o[s]),
|
|
1377
|
+
this.status.map(O([s])),
|
|
1378
|
+
{
|
|
1379
|
+
disabled: this.disabled,
|
|
1380
|
+
// propagate validationMode to children if present
|
|
1381
|
+
validationMode: this.parent.validationMode
|
|
1382
|
+
}
|
|
1383
|
+
);
|
|
1384
|
+
this.#e.set(s, r);
|
|
1385
|
+
const i = r.touched.on((o) => {
|
|
1386
|
+
this.#t.set(s, o), this.#c();
|
|
1387
|
+
});
|
|
1388
|
+
this.#s.set(s, i);
|
|
1389
|
+
const n = r.dirty.on((o) => {
|
|
1390
|
+
this.#a.set(s, o), this.#n();
|
|
1391
|
+
});
|
|
1392
|
+
return this.#i.set(s, n), r;
|
|
1393
|
+
};
|
|
1394
|
+
markAllTouched = () => {
|
|
1395
|
+
this.markTouched();
|
|
1396
|
+
const s = this.signal.value;
|
|
1397
|
+
for (const t of Object.keys(s))
|
|
1398
|
+
this.field(t).markTouched();
|
|
1399
|
+
for (const t of this.#e.values())
|
|
1400
|
+
t.markTouched();
|
|
1401
|
+
};
|
|
1402
|
+
markAllPristine = () => {
|
|
1403
|
+
this.markPristine();
|
|
1404
|
+
const s = this.signal.value;
|
|
1405
|
+
for (const t of Object.keys(s))
|
|
1406
|
+
this.field(t).markPristine?.();
|
|
1407
|
+
for (const t of this.#e.values())
|
|
1408
|
+
t.markPristine?.();
|
|
1409
|
+
};
|
|
1410
|
+
#n = () => {
|
|
1411
|
+
let s = !1;
|
|
1412
|
+
for (const t of this.#a.values())
|
|
1413
|
+
if (t) {
|
|
1414
|
+
s = !0;
|
|
1415
|
+
break;
|
|
1416
|
+
}
|
|
1417
|
+
this.#l.set(this.dirty.value || s);
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
class ye extends C {
|
|
1421
|
+
#e = new Array();
|
|
1422
|
+
length;
|
|
1423
|
+
#t = /* @__PURE__ */ new Map();
|
|
1424
|
+
#s = /* @__PURE__ */ new Map();
|
|
1425
|
+
#r = w(!1);
|
|
1426
|
+
touchedDeep = this.#r;
|
|
1427
|
+
#a = /* @__PURE__ */ new Map();
|
|
1428
|
+
#i = /* @__PURE__ */ new Map();
|
|
1429
|
+
#l = w(!1);
|
|
1430
|
+
dirtyDeep = this.#l;
|
|
1431
|
+
#o;
|
|
1432
|
+
#u;
|
|
1433
|
+
#c = () => {
|
|
1434
|
+
let s = !1;
|
|
1435
|
+
for (const t of this.#t.values())
|
|
1436
|
+
if (t) {
|
|
1437
|
+
s = !0;
|
|
1438
|
+
break;
|
|
1439
|
+
}
|
|
1440
|
+
this.#r.set(this.touched.value || s);
|
|
1441
|
+
};
|
|
1442
|
+
constructor(s, t, r, i, n, o) {
|
|
1443
|
+
const l = r.map((p) => p ?? [], o);
|
|
1444
|
+
super(s, t, l, i, n, o);
|
|
1445
|
+
const u = l.on((p) => {
|
|
1446
|
+
const g = this.#e.length - p.length;
|
|
1447
|
+
g > 0 && (this.#e.splice(p.length, g).forEach((k, A) => {
|
|
1448
|
+
const f = p.length + A;
|
|
1449
|
+
k.dispose(), this.#s.get(f)?.(), this.#s.delete(f), this.#t.delete(f), this.#i.get(f)?.(), this.#i.delete(f), this.#a.delete(f);
|
|
1450
|
+
}), this.#c(), this.#n());
|
|
1451
|
+
});
|
|
1452
|
+
this.length = l.map((p) => p.length), this.#o = this.touched.on(() => {
|
|
1453
|
+
this.#c();
|
|
1454
|
+
}), this.#u = this.dirty.on(() => {
|
|
1455
|
+
this.#n();
|
|
1456
|
+
});
|
|
1457
|
+
const v = this.signal.on(() => this.#n());
|
|
1458
|
+
this.onDispose(() => {
|
|
1459
|
+
for (const p of this.#e)
|
|
1460
|
+
p.dispose();
|
|
1461
|
+
this.length.dispose(), this.#e.length = 0, u(), l.dispose();
|
|
1462
|
+
for (const p of this.#s.values()) p();
|
|
1463
|
+
this.#s.clear(), this.#t.clear(), this.#r.dispose();
|
|
1464
|
+
for (const p of this.#i.values()) p();
|
|
1465
|
+
this.#i.clear(), this.#a.clear(), this.#l.dispose(), this.#o(), this.#u(), v();
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
item = (s) => {
|
|
1469
|
+
if (this.#e[s])
|
|
1470
|
+
return this.#e[s];
|
|
1471
|
+
const t = async (o) => {
|
|
1472
|
+
const l = this.signal.value.slice();
|
|
1473
|
+
l[s] = o, this.change(l);
|
|
1474
|
+
}, r = new C(
|
|
1475
|
+
[...this.path, s],
|
|
1476
|
+
t,
|
|
1477
|
+
this.signal.map((o) => o[s]),
|
|
1478
|
+
this.status.map(O([s])),
|
|
1479
|
+
{
|
|
1480
|
+
disabled: this.disabled,
|
|
1481
|
+
validationMode: this.parent.validationMode
|
|
1482
|
+
}
|
|
1483
|
+
);
|
|
1484
|
+
this.#e[s] = r;
|
|
1485
|
+
const i = r.touched.on((o) => {
|
|
1486
|
+
this.#t.set(s, o), this.#c();
|
|
1487
|
+
});
|
|
1488
|
+
this.#s.set(s, i);
|
|
1489
|
+
const n = r.dirty.on((o) => {
|
|
1490
|
+
this.#a.set(s, o), this.#n();
|
|
1491
|
+
});
|
|
1492
|
+
return this.#i.set(s, n), r;
|
|
1493
|
+
};
|
|
1494
|
+
push = (...s) => {
|
|
1495
|
+
this.change([...this.signal.value, ...s]);
|
|
1496
|
+
};
|
|
1497
|
+
pop = () => {
|
|
1498
|
+
this.splice(this.signal.value.length - 1, 1);
|
|
1499
|
+
};
|
|
1500
|
+
shift = () => {
|
|
1501
|
+
this.splice(0, 1);
|
|
1502
|
+
};
|
|
1503
|
+
unshift = (...s) => {
|
|
1504
|
+
this.change([...s, ...this.signal.value]);
|
|
1505
|
+
};
|
|
1506
|
+
removeAt = (s) => {
|
|
1507
|
+
this.splice(s, 1);
|
|
1508
|
+
};
|
|
1509
|
+
splice = (s, t) => {
|
|
1510
|
+
const r = this.signal.value.slice();
|
|
1511
|
+
r.splice(s, t), this.change(r);
|
|
1512
|
+
};
|
|
1513
|
+
move = (s, t, r = 1) => {
|
|
1514
|
+
if (r < 1 || s === t) return;
|
|
1515
|
+
const i = this.signal.value.slice(), n = i.splice(s, r);
|
|
1516
|
+
i.splice(t, 0, ...n), this.change(i);
|
|
1517
|
+
};
|
|
1518
|
+
markAllTouched = () => {
|
|
1519
|
+
this.markTouched();
|
|
1520
|
+
const s = this.signal.value.length;
|
|
1521
|
+
for (let t = 0; t < s; t++)
|
|
1522
|
+
this.item(t).markTouched();
|
|
1523
|
+
};
|
|
1524
|
+
markAllPristine = () => {
|
|
1525
|
+
this.markPristine();
|
|
1526
|
+
const s = this.signal.value.length;
|
|
1527
|
+
for (let t = 0; t < s; t++)
|
|
1528
|
+
this.item(t).markPristine?.();
|
|
1529
|
+
};
|
|
1530
|
+
#n = () => {
|
|
1531
|
+
let s = !1;
|
|
1532
|
+
for (const t of this.#a.values())
|
|
1533
|
+
if (t) {
|
|
1534
|
+
s = !0;
|
|
1535
|
+
break;
|
|
1536
|
+
}
|
|
1537
|
+
this.#l.set(this.dirty.value || s);
|
|
1538
|
+
};
|
|
1539
|
+
}
|
|
1540
|
+
function ge(e) {
|
|
1541
|
+
function s(t) {
|
|
1542
|
+
return typeof t == "number" ? t : t.toString();
|
|
1543
|
+
}
|
|
1544
|
+
return e.map(
|
|
1545
|
+
(t) => typeof t == "object" && t.key != null ? s(t.key) : s(t)
|
|
1546
|
+
);
|
|
1547
|
+
}
|
|
1548
|
+
function me(e) {
|
|
1549
|
+
const s = e.filter((i) => i.path == null || i.path.length === 0).map((i) => i.message), t = e.filter((i) => i.path != null && i.path.length > 0).reduce((i, n) => {
|
|
1550
|
+
const o = ge(n.path), l = o.pop();
|
|
1551
|
+
let u = i;
|
|
1552
|
+
for (const v of o)
|
|
1553
|
+
u.dependencies == null && (u.dependencies = {}), u.dependencies[v] == null && (u.dependencies[v] = {}), u = u.dependencies[v];
|
|
1554
|
+
return u.dependencies == null && (u.dependencies = {}), u.dependencies[l] = { message: n.message }, i;
|
|
1555
|
+
}, {}), r = s.join(`
|
|
1556
|
+
`);
|
|
1557
|
+
return {
|
|
1558
|
+
...t,
|
|
1559
|
+
message: r != "" ? r : void 0
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
function be({
|
|
1563
|
+
initialValue: e,
|
|
1564
|
+
onChange: s,
|
|
1565
|
+
validate: t,
|
|
1566
|
+
equals: r,
|
|
1567
|
+
validationMode: i,
|
|
1568
|
+
validateDebounceMs: n
|
|
1569
|
+
}) {
|
|
1570
|
+
const o = F.deriveProp(e), l = w(h.valid), u = w(!1), v = w(i ?? "onTouched"), p = (m) => {
|
|
1571
|
+
l.set(m);
|
|
1572
|
+
};
|
|
1573
|
+
let g;
|
|
1574
|
+
const k = async (m) => {
|
|
1575
|
+
if (t != null) {
|
|
1576
|
+
const E = await t(m);
|
|
1577
|
+
p(E);
|
|
1578
|
+
}
|
|
1579
|
+
}, A = async (m) => {
|
|
1580
|
+
o.set(m), s?.(m);
|
|
1581
|
+
const E = v.value;
|
|
1582
|
+
if (t != null) {
|
|
1583
|
+
if (E === "onSubmit")
|
|
1584
|
+
return;
|
|
1585
|
+
const _ = n ?? 0;
|
|
1586
|
+
_ > 0 ? (g && clearTimeout(g), g = setTimeout(() => {
|
|
1587
|
+
k(m);
|
|
1588
|
+
}, _)) : await k(m);
|
|
1589
|
+
}
|
|
1590
|
+
}, f = new C(
|
|
1591
|
+
[],
|
|
1592
|
+
A,
|
|
1593
|
+
o,
|
|
1594
|
+
l,
|
|
1595
|
+
{
|
|
1596
|
+
disabled: u,
|
|
1597
|
+
validationMode: v
|
|
1598
|
+
},
|
|
1599
|
+
r ?? T
|
|
1600
|
+
);
|
|
1601
|
+
return f.onDispose(() => {
|
|
1602
|
+
u.dispose(), o.dispose(), l.dispose(), v.dispose(), g && clearTimeout(g);
|
|
1603
|
+
}), { controller: f, setStatus: p };
|
|
1604
|
+
}
|
|
1605
|
+
function G(e) {
|
|
1606
|
+
return q(d.disabled(e.disabled), d.name(e.name));
|
|
1607
|
+
}
|
|
1608
|
+
function _e(e, {
|
|
1609
|
+
triggerOn: s = "change"
|
|
1610
|
+
} = {}) {
|
|
1611
|
+
return q(
|
|
1612
|
+
G(e),
|
|
1613
|
+
d.value(e.signal),
|
|
1614
|
+
(s === "input" ? V.input : V.change)(ee(e.change))
|
|
1615
|
+
);
|
|
1616
|
+
}
|
|
1617
|
+
function Le(e, {
|
|
1618
|
+
triggerOn: s = "change"
|
|
1619
|
+
} = {}) {
|
|
1620
|
+
return q(
|
|
1621
|
+
G(e),
|
|
1622
|
+
d.valueAsNumber(e.signal),
|
|
1623
|
+
(s === "input" ? V.input : V.change)(
|
|
1624
|
+
se(e.change)
|
|
1625
|
+
)
|
|
1626
|
+
);
|
|
1627
|
+
}
|
|
1628
|
+
function U(e) {
|
|
1629
|
+
return e.issues != null ? h.invalid(me(e.issues)) : h.valid;
|
|
1630
|
+
}
|
|
1631
|
+
async function Me({
|
|
1632
|
+
task: e,
|
|
1633
|
+
errorMessage: s,
|
|
1634
|
+
errorPath: t = ["root"],
|
|
1635
|
+
validation: r
|
|
1636
|
+
}) {
|
|
1637
|
+
try {
|
|
1638
|
+
const i = await e();
|
|
1639
|
+
return r != null ? r(i) : h.valid;
|
|
1640
|
+
} catch (i) {
|
|
1641
|
+
const n = s ?? (i instanceof Error ? i.message : "Operation failed");
|
|
1642
|
+
return t.length === 1 && t[0] === "root" ? h.invalid({
|
|
1643
|
+
message: n
|
|
1644
|
+
}) : h.invalid({
|
|
1645
|
+
dependencies: J(t, n)
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
function J(e, s) {
|
|
1650
|
+
if (e.length === 1)
|
|
1651
|
+
return {
|
|
1652
|
+
[e[0]]: { message: s }
|
|
1653
|
+
};
|
|
1654
|
+
const [t, ...r] = e;
|
|
1655
|
+
return {
|
|
1656
|
+
[t]: {
|
|
1657
|
+
dependencies: J(r, s)
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
}
|
|
1661
|
+
function Ne({
|
|
1662
|
+
initialValue: e = {},
|
|
1663
|
+
schema: s,
|
|
1664
|
+
onSubmit: t = async () => h.valid,
|
|
1665
|
+
validationMode: r,
|
|
1666
|
+
validateDebounceMs: i
|
|
1667
|
+
}) {
|
|
1668
|
+
const { controller: n, setStatus: o } = be({
|
|
1669
|
+
initialValue: e,
|
|
1670
|
+
validationMode: r ?? "onTouched",
|
|
1671
|
+
validateDebounceMs: i,
|
|
1672
|
+
validate: (r ?? "onTouched") === "onSubmit" || s == null ? void 0 : async (p) => U(
|
|
1673
|
+
await s["~standard"].validate(p)
|
|
1674
|
+
)
|
|
1675
|
+
}), l = w(!1), u = n.object();
|
|
1676
|
+
return u.onDispose(l.dispose), {
|
|
1677
|
+
controller: u,
|
|
1678
|
+
setStatus: o,
|
|
1679
|
+
submit: async (p) => {
|
|
1680
|
+
if (l.set(!0), p?.preventDefault(), u.markAllTouched(), s != null) {
|
|
1681
|
+
const k = u.signal.value, A = U(
|
|
1682
|
+
await s["~standard"].validate(k)
|
|
1683
|
+
);
|
|
1684
|
+
if (o(A), A.type === "invalid") {
|
|
1685
|
+
l.set(!1);
|
|
1686
|
+
return;
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
const g = await t(u.signal.value);
|
|
1690
|
+
l.set(!1), g.type === "invalid" && o(g);
|
|
1691
|
+
},
|
|
1692
|
+
submitting: l
|
|
1693
|
+
};
|
|
1694
|
+
}
|
|
1695
|
+
export {
|
|
1696
|
+
ye as A,
|
|
1697
|
+
K as B,
|
|
1698
|
+
we as C,
|
|
1699
|
+
Ee as D,
|
|
1700
|
+
Ae as E,
|
|
1701
|
+
W as I,
|
|
1702
|
+
ae as L,
|
|
1703
|
+
ne as M,
|
|
1704
|
+
T as O,
|
|
1705
|
+
le as R,
|
|
1706
|
+
De as S,
|
|
1707
|
+
Fe as a,
|
|
1708
|
+
Ce as b,
|
|
1709
|
+
z as c,
|
|
1710
|
+
C as d,
|
|
1711
|
+
O as e,
|
|
1712
|
+
ve as f,
|
|
1713
|
+
be as g,
|
|
1714
|
+
he as h,
|
|
1715
|
+
h as i,
|
|
1716
|
+
Ie as j,
|
|
1717
|
+
fe as k,
|
|
1718
|
+
Te as l,
|
|
1719
|
+
de as m,
|
|
1720
|
+
ge as n,
|
|
1721
|
+
me as o,
|
|
1722
|
+
Ve as p,
|
|
1723
|
+
G as q,
|
|
1724
|
+
_e as r,
|
|
1725
|
+
x as s,
|
|
1726
|
+
Me as t,
|
|
1727
|
+
Ne as u,
|
|
1728
|
+
Le as v,
|
|
1729
|
+
pe as w,
|
|
1730
|
+
U as x
|
|
1731
|
+
};
|