@effect-app/vue-components 2.7.7 → 2.7.9
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.
|
@@ -1,99 +1,108 @@
|
|
|
1
|
-
import { useForm as
|
|
2
|
-
import { Data as
|
|
3
|
-
import { runtimeFiberAsPromise as
|
|
4
|
-
import { isObject as
|
|
5
|
-
import { computed as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { generateMetaFromSchema as
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import { trace as
|
|
14
|
-
import { context as
|
|
15
|
-
const
|
|
16
|
-
const i =
|
|
1
|
+
import { useForm as K } from "@tanstack/vue-form";
|
|
2
|
+
import { Data as G, S as p, Effect as b, Array as A, Fiber as x, Option as O } from "effect-app";
|
|
3
|
+
import { runtimeFiberAsPromise as z } from "./vue-components.es16.js";
|
|
4
|
+
import { isObject as Q } from "./vue-components.es17.js";
|
|
5
|
+
import { computed as V, onUnmounted as N, onMounted as X, onBeforeUnmount as Y, watch as W, ref as Z, h as J } from "vue";
|
|
6
|
+
import C from "./vue-components.es18.js";
|
|
7
|
+
import ee from "./vue-components.es19.js";
|
|
8
|
+
import te from "./vue-components.es20.js";
|
|
9
|
+
import { generateMetaFromSchema as re, isNullableOrUndefined as ne } from "./vue-components.es12.js";
|
|
10
|
+
import se from "./vue-components.es6.js";
|
|
11
|
+
import oe from "./vue-components.es8.js";
|
|
12
|
+
import ie from "./vue-components.es21.js";
|
|
13
|
+
import { trace as H } from "./vue-components.es22.js";
|
|
14
|
+
import { context as L } from "./vue-components.es23.js";
|
|
15
|
+
const g = (c) => {
|
|
16
|
+
const i = c.ast;
|
|
17
|
+
if (i._tag === "Refinement") {
|
|
18
|
+
const n = i, u = p.make(n.from);
|
|
19
|
+
return g(u);
|
|
20
|
+
}
|
|
17
21
|
if (i._tag === "Union") {
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
return
|
|
21
|
-
}),
|
|
22
|
+
const n = i.types.map((f) => {
|
|
23
|
+
const l = p.make(f);
|
|
24
|
+
return g(l).ast;
|
|
25
|
+
}), u = {
|
|
22
26
|
...i,
|
|
23
|
-
types:
|
|
27
|
+
types: n
|
|
24
28
|
};
|
|
25
|
-
return
|
|
29
|
+
return p.make(u);
|
|
26
30
|
}
|
|
27
31
|
if (i._tag === "Transformation") {
|
|
28
|
-
const
|
|
32
|
+
const n = i;
|
|
33
|
+
if (n.to._tag === "Declaration") {
|
|
34
|
+
const h = p.make(n.from);
|
|
35
|
+
return g(h);
|
|
36
|
+
}
|
|
37
|
+
const u = p.make(n.from), f = p.make(n.to), l = g(u), d = g(f), w = {
|
|
29
38
|
...i,
|
|
30
|
-
from:
|
|
31
|
-
to:
|
|
39
|
+
from: l.ast,
|
|
40
|
+
to: d.ast
|
|
32
41
|
};
|
|
33
|
-
return
|
|
42
|
+
return p.make(w);
|
|
34
43
|
}
|
|
35
44
|
if (i._tag === "TypeLiteral") {
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
let d =
|
|
39
|
-
if (
|
|
40
|
-
const
|
|
41
|
-
d =
|
|
45
|
+
const n = i.propertySignatures.map((f) => {
|
|
46
|
+
const l = f.type;
|
|
47
|
+
let d = l;
|
|
48
|
+
if (l._tag === "TypeLiteral" || l._tag === "Union" || l._tag === "Transformation" || l._tag === "Refinement") {
|
|
49
|
+
const w = p.make(l);
|
|
50
|
+
d = g(w).ast;
|
|
42
51
|
}
|
|
43
52
|
return {
|
|
44
53
|
...f,
|
|
45
54
|
type: d,
|
|
46
55
|
isOptional: !0
|
|
47
56
|
};
|
|
48
|
-
}),
|
|
57
|
+
}), u = {
|
|
49
58
|
...i,
|
|
50
|
-
propertySignatures:
|
|
59
|
+
propertySignatures: n
|
|
51
60
|
};
|
|
52
|
-
return
|
|
61
|
+
return p.make(u);
|
|
53
62
|
}
|
|
54
|
-
return
|
|
63
|
+
return c;
|
|
55
64
|
};
|
|
56
|
-
class
|
|
65
|
+
class ae extends G.TaggedError("FormErrors") {
|
|
57
66
|
}
|
|
58
|
-
const
|
|
67
|
+
const k = (c) => function(n) {
|
|
59
68
|
return {
|
|
60
69
|
render() {
|
|
61
|
-
return
|
|
62
|
-
form:
|
|
70
|
+
return J(n, {
|
|
71
|
+
form: c,
|
|
63
72
|
...this.$attrs
|
|
64
73
|
}, this.$slots);
|
|
65
74
|
}
|
|
66
75
|
};
|
|
67
|
-
},
|
|
76
|
+
}, le = (c) => function(n) {
|
|
68
77
|
return {
|
|
69
78
|
setup() {
|
|
70
|
-
const { fieldMap:
|
|
71
|
-
const S =
|
|
79
|
+
const { fieldMap: u, form: f } = c, l = f.useStore((S) => S.errors), d = f.useStore((S) => S.fieldMeta), w = f.useStore((S) => S.errorMap), h = V(() => {
|
|
80
|
+
const S = A.filterMap(
|
|
72
81
|
Object.entries(d.value),
|
|
73
|
-
([
|
|
74
|
-
const a =
|
|
75
|
-
if (!a.length) return
|
|
76
|
-
const
|
|
77
|
-
return
|
|
78
|
-
label:
|
|
79
|
-
inputId:
|
|
82
|
+
([M, y]) => {
|
|
83
|
+
const a = y.errors ?? [];
|
|
84
|
+
if (!a.length) return O.none();
|
|
85
|
+
const v = u.value.get(M);
|
|
86
|
+
return v ? O.some({
|
|
87
|
+
label: v.label,
|
|
88
|
+
inputId: v.id,
|
|
80
89
|
// Only show the first error
|
|
81
90
|
errors: [a[0]?.message].filter(Boolean)
|
|
82
|
-
}) :
|
|
91
|
+
}) : O.none();
|
|
83
92
|
}
|
|
84
93
|
), F = [];
|
|
85
|
-
if (
|
|
86
|
-
for (const [
|
|
87
|
-
if (
|
|
88
|
-
for (const a of
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
const
|
|
92
|
-
if (!
|
|
94
|
+
if (w.value.onSubmit) {
|
|
95
|
+
for (const [M, y] of Object.entries(w.value.onSubmit))
|
|
96
|
+
if (A.isArray(y) && y.length)
|
|
97
|
+
for (const a of y) {
|
|
98
|
+
const v = a;
|
|
99
|
+
if (v?.path && A.isArray(v.path) && v.path.length) {
|
|
100
|
+
const _ = v.path.join(".");
|
|
101
|
+
if (!u.value.has(_)) {
|
|
93
102
|
F.push({
|
|
94
|
-
label:
|
|
95
|
-
inputId:
|
|
96
|
-
errors: [
|
|
103
|
+
label: _,
|
|
104
|
+
inputId: _,
|
|
105
|
+
errors: [v.message].filter(Boolean)
|
|
97
106
|
});
|
|
98
107
|
break;
|
|
99
108
|
}
|
|
@@ -103,103 +112,75 @@ const U = (l) => function(o) {
|
|
|
103
112
|
return [...S, ...F];
|
|
104
113
|
});
|
|
105
114
|
return {
|
|
106
|
-
generalErrors:
|
|
107
|
-
errors:
|
|
115
|
+
generalErrors: l,
|
|
116
|
+
errors: h
|
|
108
117
|
};
|
|
109
118
|
},
|
|
110
|
-
render({ errors:
|
|
111
|
-
return
|
|
112
|
-
errors:
|
|
119
|
+
render({ errors: u, generalErrors: f }) {
|
|
120
|
+
return J(n, {
|
|
121
|
+
errors: u,
|
|
113
122
|
generalErrors: f,
|
|
114
123
|
...this.$attrs
|
|
115
124
|
}, this.$slots);
|
|
116
125
|
}
|
|
117
126
|
};
|
|
118
|
-
},
|
|
119
|
-
if (!
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
122
|
-
return
|
|
123
|
-
const e = window.location.pathname, t = Object.keys(
|
|
127
|
+
}, _e = (c, i, n) => {
|
|
128
|
+
if (!c) throw new Error("Schema is required");
|
|
129
|
+
const u = p.standardSchemaV1(c), f = p.decode(c), { meta: l } = re(c), d = V(() => {
|
|
130
|
+
if (n?.persistency?.id)
|
|
131
|
+
return n.persistency.id;
|
|
132
|
+
const e = window.location.pathname, t = Object.keys(l);
|
|
124
133
|
return `${e}-${t.join("-")}`;
|
|
125
|
-
}),
|
|
134
|
+
}), w = () => {
|
|
126
135
|
const e = new URLSearchParams(window.location.search);
|
|
127
136
|
e.delete(d.value);
|
|
128
137
|
const t = new URL(window.location.href);
|
|
129
138
|
t.search = e.toString(), window.history.replaceState({}, "", t.toString());
|
|
130
139
|
};
|
|
131
|
-
function
|
|
140
|
+
function h(e, t) {
|
|
132
141
|
for (const r in t)
|
|
133
|
-
|
|
142
|
+
A.isArray(t[r]) ? e[r] = t[r] : t[r] && Q(t[r]) ? (e[r] || (e[r] = {}), h(e[r], t[r])) : e[r] = t[r];
|
|
134
143
|
return e;
|
|
135
144
|
}
|
|
136
145
|
const S = (e) => {
|
|
137
146
|
const t = {};
|
|
138
|
-
if (typeof e?.make == "function")
|
|
139
|
-
try {
|
|
140
|
-
const n = e.make({});
|
|
141
|
-
if (e?.fields && typeof e.fields == "object") {
|
|
142
|
-
for (const [s, u] of Object.entries(e.fields))
|
|
143
|
-
if (n[s] === void 0) {
|
|
144
|
-
const m = u.ast, M = J(m);
|
|
145
|
-
M === "null" ? n[s] = null : M === "undefined" && (n[s] = void 0);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return n;
|
|
149
|
-
} catch {
|
|
150
|
-
}
|
|
151
|
-
const r = e?.members || (e?.ast?._tag === "Union" && e.ast.types ? e.ast.types.map((n) => v.make(n)) : null);
|
|
152
|
-
if (r && g.isArray(r)) {
|
|
153
|
-
for (const n of r) {
|
|
154
|
-
const s = S(n);
|
|
155
|
-
if (Object.keys(s).length > 0 && n?.fields && Object.entries(n.fields).some(
|
|
156
|
-
([m, M]) => m === "_tag" || m === "type" || m === "kind" ? M?.ast?.defaultValue !== void 0 : !1
|
|
157
|
-
))
|
|
158
|
-
return s;
|
|
159
|
-
}
|
|
160
|
-
return {};
|
|
161
|
-
}
|
|
162
147
|
if (e?.fields && typeof e.fields == "object")
|
|
163
|
-
for (const [
|
|
164
|
-
if (
|
|
148
|
+
for (const [r, o] of Object.entries(e.fields)) {
|
|
149
|
+
if (o?.ast?.defaultValue)
|
|
165
150
|
try {
|
|
166
|
-
const m =
|
|
167
|
-
t[
|
|
151
|
+
const m = o.ast.defaultValue();
|
|
152
|
+
t[r] = m;
|
|
168
153
|
} catch {
|
|
169
154
|
}
|
|
170
155
|
else {
|
|
171
|
-
const m =
|
|
172
|
-
switch (
|
|
156
|
+
const m = o?.ast;
|
|
157
|
+
switch (ne(m)) {
|
|
173
158
|
case "null":
|
|
174
|
-
t[
|
|
159
|
+
t[r] = null;
|
|
175
160
|
break;
|
|
176
161
|
case "undefined":
|
|
177
|
-
t[
|
|
162
|
+
t[r] = void 0;
|
|
178
163
|
break;
|
|
179
164
|
}
|
|
180
165
|
}
|
|
181
|
-
const
|
|
182
|
-
Object.keys(
|
|
166
|
+
const s = S(o);
|
|
167
|
+
Object.keys(s).length > 0 && (t[r] && typeof t[r] == "object" ? Object.assign(t[r], s) : t[r] || (t[r] = s));
|
|
183
168
|
}
|
|
169
|
+
else if (e?.from?.fields && typeof e?.from?.fields == "object")
|
|
170
|
+
return S(e.from);
|
|
184
171
|
return t;
|
|
185
172
|
}, F = (e = {}) => {
|
|
186
173
|
let t = {};
|
|
187
174
|
try {
|
|
188
|
-
const r =
|
|
189
|
-
t =
|
|
175
|
+
const r = S(c);
|
|
176
|
+
t = p.encodeSync(g(c))(r);
|
|
190
177
|
} catch (r) {
|
|
191
|
-
window.location.hostname === "localhost" && console.warn("
|
|
192
|
-
try {
|
|
193
|
-
const n = S(l);
|
|
194
|
-
t = v.encodeSync(_(l))(n);
|
|
195
|
-
} catch (n) {
|
|
196
|
-
window.location.hostname === "localhost" && console.warn("Could not extract defaults from AST:", n);
|
|
197
|
-
}
|
|
178
|
+
window.location.hostname === "localhost" && console.warn("Could not extract defaults from AST:", r);
|
|
198
179
|
}
|
|
199
|
-
return
|
|
200
|
-
},
|
|
180
|
+
return h(t, e);
|
|
181
|
+
}, M = V(() => {
|
|
201
182
|
let e;
|
|
202
|
-
const t =
|
|
183
|
+
const t = n?.persistency;
|
|
203
184
|
if (
|
|
204
185
|
// query string has higher priority than local/session storage
|
|
205
186
|
t?.policies && !e && (t.policies.includes("local") || t.policies.includes("session"))
|
|
@@ -207,131 +188,131 @@ const U = (l) => function(o) {
|
|
|
207
188
|
const r = t.policies.includes("local") ? localStorage : sessionStorage;
|
|
208
189
|
if (r)
|
|
209
190
|
try {
|
|
210
|
-
const
|
|
191
|
+
const o = JSON.parse(
|
|
211
192
|
r.getItem(d.value) || "{}"
|
|
212
193
|
);
|
|
213
|
-
r.removeItem(d.value), e =
|
|
214
|
-
} catch (
|
|
215
|
-
console.error(
|
|
194
|
+
r.removeItem(d.value), e = o;
|
|
195
|
+
} catch (o) {
|
|
196
|
+
console.error(o);
|
|
216
197
|
}
|
|
217
198
|
}
|
|
218
199
|
if (t?.policies && t.policies.includes("querystring"))
|
|
219
200
|
try {
|
|
220
|
-
const
|
|
221
|
-
|
|
201
|
+
const o = new URLSearchParams(window.location.search).get(d.value);
|
|
202
|
+
w(), o && (e = h(e || {}, JSON.parse(o)));
|
|
222
203
|
} catch (r) {
|
|
223
204
|
console.error(r);
|
|
224
205
|
}
|
|
225
206
|
return e ??= {}, F(
|
|
226
|
-
|
|
207
|
+
n?.persistency?.overrideDefaultValues ? h(i?.defaultValues || {}, e) : h(e, i?.defaultValues || {})
|
|
227
208
|
);
|
|
228
|
-
}),
|
|
209
|
+
}), y = (e, t) => e ? L.with(H.setSpan(L.active(), e), t) : t(), a = K({
|
|
229
210
|
...i,
|
|
230
211
|
validators: {
|
|
231
|
-
onSubmit:
|
|
212
|
+
onSubmit: u,
|
|
232
213
|
...i?.validators || {}
|
|
233
214
|
},
|
|
234
|
-
onSubmit: i?.onSubmit ? ({ formApi: e, meta: t, value: r }) =>
|
|
235
|
-
const
|
|
215
|
+
onSubmit: i?.onSubmit ? ({ formApi: e, meta: t, value: r }) => y(t?.currentSpan, async () => {
|
|
216
|
+
const o = await b.runPromise(f(r)), s = i.onSubmit({
|
|
236
217
|
formApi: e,
|
|
237
218
|
meta: t,
|
|
238
|
-
value:
|
|
219
|
+
value: o
|
|
239
220
|
});
|
|
240
|
-
return
|
|
221
|
+
return x.isFiber(s) && x.isRuntimeFiber(s) ? await z(s) : b.isEffect(s) ? await b.runPromise(
|
|
241
222
|
s.pipe(
|
|
242
223
|
// meta?.currentSpan
|
|
243
224
|
// ? Effect.withParentSpan(meta.currentSpan)
|
|
244
225
|
// : (_) => _,
|
|
245
|
-
b.flatMap((
|
|
226
|
+
b.flatMap((m) => x.join(m))
|
|
246
227
|
)
|
|
247
228
|
) : s;
|
|
248
229
|
}) : void 0,
|
|
249
|
-
defaultValues:
|
|
250
|
-
}),
|
|
251
|
-
Object.keys(
|
|
230
|
+
defaultValues: M.value
|
|
231
|
+
}), v = () => {
|
|
232
|
+
Object.keys(l).forEach((e) => {
|
|
252
233
|
a.setFieldValue(e, void 0);
|
|
253
234
|
});
|
|
254
|
-
},
|
|
255
|
-
const
|
|
256
|
-
return
|
|
257
|
-
}, {}),
|
|
235
|
+
}, _ = (e) => e.reduce((t, r) => {
|
|
236
|
+
const o = r.split(".");
|
|
237
|
+
return o.reduce((s, m, U) => (U === o.length - 1 ? s[m] = a.getFieldValue(r) : s[m] = s[m] ?? {}, s[m]), t), t;
|
|
238
|
+
}, {}), D = (e) => {
|
|
258
239
|
if (e) {
|
|
259
|
-
if (
|
|
260
|
-
return
|
|
261
|
-
if (
|
|
262
|
-
const t = Object.keys(
|
|
263
|
-
return
|
|
240
|
+
if (A.isArray(e.keys))
|
|
241
|
+
return _(e.keys);
|
|
242
|
+
if (A.isArray(e.banKeys)) {
|
|
243
|
+
const t = Object.keys(l).filter((r) => e.banKeys?.includes(r));
|
|
244
|
+
return _(t);
|
|
264
245
|
}
|
|
265
246
|
return a.store.state.values;
|
|
266
247
|
}
|
|
267
248
|
}, P = () => {
|
|
268
|
-
const e =
|
|
249
|
+
const e = n?.persistency;
|
|
269
250
|
if (!(!e?.policies || e.policies.length === 0) && (e.policies.includes("local") || e.policies.includes("session"))) {
|
|
270
251
|
const t = e.policies.includes("local") ? localStorage : sessionStorage;
|
|
271
252
|
if (!t) return;
|
|
272
|
-
const r =
|
|
253
|
+
const r = D(e);
|
|
273
254
|
return t.setItem(d.value, JSON.stringify(r));
|
|
274
255
|
}
|
|
275
|
-
},
|
|
276
|
-
const e =
|
|
256
|
+
}, T = () => {
|
|
257
|
+
const e = n?.persistency;
|
|
277
258
|
if (!(!e?.policies || e.policies.length === 0) && e.policies.includes("querystring")) {
|
|
278
|
-
const t =
|
|
259
|
+
const t = D(e), r = new URLSearchParams(window.location.search);
|
|
279
260
|
r.set(d.value, JSON.stringify(t));
|
|
280
|
-
const
|
|
281
|
-
|
|
261
|
+
const o = new URL(window.location.href);
|
|
262
|
+
o.search = r.toString(), window.history.replaceState({}, "", o.toString());
|
|
282
263
|
}
|
|
283
|
-
},
|
|
264
|
+
}, I = (e) => {
|
|
284
265
|
a.store.state.isDirty && e.preventDefault();
|
|
285
266
|
};
|
|
286
|
-
if (
|
|
287
|
-
window.addEventListener("beforeunload", P), window.addEventListener("blur",
|
|
288
|
-
}),
|
|
289
|
-
window.removeEventListener("beforeunload", P), window.removeEventListener("blur",
|
|
290
|
-
}),
|
|
291
|
-
const e = a.useStore((s) => s.isSubmitting), t = a.useStore((s) => s.submissionAttempts), r = a.useStore((s) => s.canSubmit),
|
|
292
|
-
|
|
293
|
-
|
|
267
|
+
if (N(P), X(() => {
|
|
268
|
+
window.addEventListener("beforeunload", P), window.addEventListener("blur", T), n?.preventWindowExit && n.preventWindowExit !== "nope" && window.addEventListener("beforeunload", I);
|
|
269
|
+
}), Y(() => {
|
|
270
|
+
window.removeEventListener("beforeunload", P), window.removeEventListener("blur", T), n?.preventWindowExit && n.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", I);
|
|
271
|
+
}), n?.preventWindowExit === "prevent-and-reset") {
|
|
272
|
+
const e = a.useStore((s) => s.isSubmitting), t = a.useStore((s) => s.submissionAttempts), r = a.useStore((s) => s.canSubmit), o = a.useStore((s) => s.values);
|
|
273
|
+
W([e, t], ([s, m], [U]) => {
|
|
274
|
+
U && !s && m > 0 && r.value && a.reset(o.value);
|
|
294
275
|
});
|
|
295
276
|
}
|
|
296
|
-
const
|
|
277
|
+
const R = (e) => b.currentSpan.pipe(
|
|
297
278
|
b.option,
|
|
298
279
|
b.flatMap(
|
|
299
|
-
(t) => b.promise(() => a.handleSubmit(
|
|
280
|
+
(t) => b.promise(() => a.handleSubmit(O.isSome(t) ? { currentSpan: t.value, ...e } : e))
|
|
300
281
|
)
|
|
301
|
-
),
|
|
282
|
+
), q = (e) => e?.checkErrors ? R(e?.meta).pipe(b.flatMap(b.fnUntraced(function* () {
|
|
302
283
|
const t = a.getAllErrors();
|
|
303
284
|
if (Object.keys(t.fields).length || t.form.errors.length)
|
|
304
|
-
return yield* new
|
|
305
|
-
}))) :
|
|
306
|
-
i18nNamespace:
|
|
307
|
-
ignorePreventCloseEvents:
|
|
308
|
-
meta:
|
|
309
|
-
clear:
|
|
285
|
+
return yield* new ae({ form: t.form, fields: t.fields });
|
|
286
|
+
}))) : R(e?.meta), B = a.handleSubmit, j = Z(/* @__PURE__ */ new Map()), E = Object.assign(a, {
|
|
287
|
+
i18nNamespace: n?.i18nNamespace,
|
|
288
|
+
ignorePreventCloseEvents: n?.ignorePreventCloseEvents,
|
|
289
|
+
meta: l,
|
|
290
|
+
clear: v,
|
|
310
291
|
handleSubmit: (e) => {
|
|
311
|
-
const t =
|
|
312
|
-
return
|
|
292
|
+
const t = H.getSpan(L.active());
|
|
293
|
+
return B({ currentSpan: t, ...e });
|
|
313
294
|
},
|
|
314
295
|
// /** @experimental */
|
|
315
|
-
handleSubmitEffect:
|
|
296
|
+
handleSubmitEffect: q,
|
|
316
297
|
registerField: (e) => {
|
|
317
|
-
|
|
298
|
+
W(e, (t) => j.value.set(t.name, { label: t.label, id: t.id }), { immediate: !0 }), N(() => j.value.delete(e.value.name));
|
|
318
299
|
}
|
|
319
|
-
}),
|
|
300
|
+
}), $ = { form: E, fieldMap: j };
|
|
320
301
|
return Object.assign(E, {
|
|
321
302
|
// Type-level properties for performance optimization (not used at runtime)
|
|
322
303
|
_paths: void 0,
|
|
323
304
|
_keys: void 0,
|
|
324
|
-
errorContext:
|
|
325
|
-
Form:
|
|
326
|
-
Input:
|
|
327
|
-
TaggedUnion:
|
|
305
|
+
errorContext: $,
|
|
306
|
+
Form: k(E)(ie),
|
|
307
|
+
Input: k(E)(n?.input ?? se),
|
|
308
|
+
TaggedUnion: k(E)(oe),
|
|
328
309
|
Field: a.Field,
|
|
329
|
-
Errors:
|
|
330
|
-
Array:
|
|
331
|
-
AutoGen:
|
|
310
|
+
Errors: le($)(te),
|
|
311
|
+
Array: k(E)(C),
|
|
312
|
+
AutoGen: k(E)(ee)
|
|
332
313
|
});
|
|
333
314
|
};
|
|
334
315
|
export {
|
|
335
|
-
|
|
336
|
-
|
|
316
|
+
ae as FormErrors,
|
|
317
|
+
_e as useOmegaForm
|
|
337
318
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { S as n, Option as L } from "effect-app";
|
|
2
|
-
import { getMetadataFromSchema as
|
|
3
|
-
import { useIntl as N, getTransformationFrom as
|
|
4
|
-
const
|
|
2
|
+
import { getMetadataFromSchema as q } from "@effect-app/vue/form";
|
|
3
|
+
import { useIntl as N, getTransformationFrom as w } from "./vue-components.es3.js";
|
|
4
|
+
const k = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKeyword" || i === n.Null.ast), g = (e) => !e || !n.AST.isUnion(e) ? !1 : e.types.find((i) => i._tag === "UndefinedKeyword") ? "undefined" : e.types.find((i) => i === n.Null.ast) ? "null" : !1, _ = (e) => {
|
|
5
5
|
const i = [];
|
|
6
6
|
for (const t of e)
|
|
7
7
|
if (n.AST.isUnion(t)) {
|
|
@@ -24,14 +24,14 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
24
24
|
});
|
|
25
25
|
if (c) {
|
|
26
26
|
for (const r of c) {
|
|
27
|
-
const p = i ? `${i}.${r.name.toString()}` : r.name.toString(), s =
|
|
27
|
+
const p = i ? `${i}.${r.name.toString()}` : r.name.toString(), s = g(r.type);
|
|
28
28
|
let a;
|
|
29
29
|
e._isNullableDiscriminatedUnion && r.name.toString() === "_tag" || e.required === !1 ? a = !1 : a = !s;
|
|
30
30
|
const f = r.type;
|
|
31
31
|
if (n.AST.isUnion(r.type)) {
|
|
32
32
|
const S = _(r.type.types).filter(
|
|
33
33
|
(l) => l._tag !== "UndefinedKeyword" && l !== n.Null.ast
|
|
34
|
-
).map(
|
|
34
|
+
).map(w);
|
|
35
35
|
if (S.some(
|
|
36
36
|
(l) => "propertySignatures" in l
|
|
37
37
|
)) {
|
|
@@ -68,28 +68,28 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
68
68
|
}, m.rest && m.rest.length > 0) {
|
|
69
69
|
const T = m.rest[0];
|
|
70
70
|
if (T.type._tag === "TypeLiteral" && "propertySignatures" in T.type)
|
|
71
|
-
for (const
|
|
72
|
-
const h = `${p}.${
|
|
71
|
+
for (const d of T.type.propertySignatures) {
|
|
72
|
+
const h = `${p}.${d.name.toString()}`, v = u({
|
|
73
73
|
parent: h,
|
|
74
|
-
property:
|
|
74
|
+
property: d.type,
|
|
75
75
|
meta: {
|
|
76
|
-
required: !d
|
|
77
|
-
nullableOrUndefined: d
|
|
76
|
+
required: !g(d.type),
|
|
77
|
+
nullableOrUndefined: g(d.type)
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
|
-
if (v && typeof v == "object" && "type" in v && (o[h] = v, v.type === "multiple" && n.AST.isTupleType(
|
|
81
|
-
const
|
|
82
|
-
if (
|
|
83
|
-
for (const x of
|
|
84
|
-
const A = `${h}.${x.name.toString()}`,
|
|
80
|
+
if (v && typeof v == "object" && "type" in v && (o[h] = v, v.type === "multiple" && n.AST.isTupleType(d.type) && d.type.rest && d.type.rest.length > 0)) {
|
|
81
|
+
const O = d.type.rest[0];
|
|
82
|
+
if (O.type._tag === "TypeLiteral" && "propertySignatures" in O.type)
|
|
83
|
+
for (const x of O.type.propertySignatures) {
|
|
84
|
+
const A = `${h}.${x.name.toString()}`, U = u({
|
|
85
85
|
parent: A,
|
|
86
86
|
property: x.type,
|
|
87
87
|
meta: {
|
|
88
|
-
required: !
|
|
89
|
-
nullableOrUndefined:
|
|
88
|
+
required: !g(x.type),
|
|
89
|
+
nullableOrUndefined: g(x.type)
|
|
90
90
|
}
|
|
91
91
|
});
|
|
92
|
-
|
|
92
|
+
U && typeof U == "object" && "type" in U && (o[A] = U);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -122,31 +122,31 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
122
122
|
const m = y.type.rest[0].type;
|
|
123
123
|
if (m._tag === "TypeLiteral" && "propertySignatures" in m)
|
|
124
124
|
for (const T of m.propertySignatures) {
|
|
125
|
-
const
|
|
126
|
-
parent:
|
|
125
|
+
const d = `${l}.${T.name.toString()}`, h = u({
|
|
126
|
+
parent: d,
|
|
127
127
|
property: T.type,
|
|
128
128
|
meta: {
|
|
129
|
-
required: !
|
|
130
|
-
nullableOrUndefined:
|
|
129
|
+
required: !g(T.type),
|
|
130
|
+
nullableOrUndefined: g(T.type)
|
|
131
131
|
}
|
|
132
132
|
});
|
|
133
|
-
o[
|
|
133
|
+
o[d] = h;
|
|
134
134
|
}
|
|
135
135
|
else
|
|
136
136
|
o[l] = {
|
|
137
137
|
type: "multiple",
|
|
138
138
|
members: y.type.elements,
|
|
139
139
|
rest: y.type.rest,
|
|
140
|
-
required: !
|
|
141
|
-
nullableOrUndefined:
|
|
140
|
+
required: !g(y.type),
|
|
141
|
+
nullableOrUndefined: g(y.type)
|
|
142
142
|
};
|
|
143
143
|
} else {
|
|
144
144
|
const m = u({
|
|
145
145
|
parent: l,
|
|
146
146
|
property: y.type,
|
|
147
147
|
meta: {
|
|
148
|
-
required: !
|
|
149
|
-
nullableOrUndefined:
|
|
148
|
+
required: !g(y.type),
|
|
149
|
+
nullableOrUndefined: g(y.type)
|
|
150
150
|
}
|
|
151
151
|
});
|
|
152
152
|
o[l] = m;
|
|
@@ -167,7 +167,7 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
167
167
|
meta: {
|
|
168
168
|
// an empty string is valid for a S.String field, so we should not mark it as required
|
|
169
169
|
// TODO: handle this better via the createMeta minLength parsing
|
|
170
|
-
required: a && (r.type._tag !== "StringKeyword" ||
|
|
170
|
+
required: a && (r.type._tag !== "StringKeyword" || q(r.type).minLength),
|
|
171
171
|
nullableOrUndefined: s
|
|
172
172
|
}
|
|
173
173
|
});
|
|
@@ -177,7 +177,7 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
177
177
|
return o;
|
|
178
178
|
}
|
|
179
179
|
if (t) {
|
|
180
|
-
const r =
|
|
180
|
+
const r = k(t);
|
|
181
181
|
if (Object.hasOwnProperty.call(e, "required") || (e.required = !r), n.AST.isUnion(t)) {
|
|
182
182
|
const s = _(t.types), a = s.find(
|
|
183
183
|
(f) => f._tag !== "UndefinedKeyword" && f !== n.Null.ast
|
|
@@ -222,12 +222,12 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
222
222
|
), e);
|
|
223
223
|
}
|
|
224
224
|
return o;
|
|
225
|
-
},
|
|
225
|
+
}, M = (e) => {
|
|
226
226
|
const i = e.ast, t = {};
|
|
227
227
|
if (i._tag === "Transformation" || i._tag === "Refinement")
|
|
228
|
-
return
|
|
228
|
+
return M(n.make(i.from));
|
|
229
229
|
if (i._tag === "Union") {
|
|
230
|
-
const r = (i.types || []).filter((s) => s._tag !== "UndefinedKeyword" && s !== n.Null.ast).map(
|
|
230
|
+
const r = (i.types || []).filter((s) => s._tag !== "UndefinedKeyword" && s !== n.Null.ast).map(w);
|
|
231
231
|
if (r.every((s) => s._tag === "TypeLiteral" && "propertySignatures" in s) && r.length > 0) {
|
|
232
232
|
const s = [];
|
|
233
233
|
for (const a of r)
|
|
@@ -264,7 +264,7 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
264
264
|
}
|
|
265
265
|
return t;
|
|
266
266
|
}, P = (e) => n.extend(e, n.Struct({})), j = (e) => {
|
|
267
|
-
const i =
|
|
267
|
+
const i = M(e);
|
|
268
268
|
return { schema: e, meta: i };
|
|
269
269
|
}, F = (e) => {
|
|
270
270
|
const { trans: i } = N();
|
|
@@ -341,10 +341,12 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
341
341
|
case "boolean":
|
|
342
342
|
t = n.Boolean;
|
|
343
343
|
break;
|
|
344
|
-
// todo: switch must be exhaustive or have default case, otherwise falls through with schema undefined.
|
|
345
344
|
case "unknown":
|
|
346
345
|
t = n.Unknown;
|
|
347
346
|
break;
|
|
347
|
+
default:
|
|
348
|
+
console.warn(`Unhandled field type: ${e}`), t = n.Unknown;
|
|
349
|
+
break;
|
|
348
350
|
}
|
|
349
351
|
return e.required ? t.pipe(
|
|
350
352
|
n.annotations({
|
|
@@ -356,7 +358,7 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
356
358
|
decode: (t) => t ?? i(),
|
|
357
359
|
encode: (t) => t
|
|
358
360
|
})
|
|
359
|
-
),
|
|
361
|
+
), E = [
|
|
360
362
|
"button",
|
|
361
363
|
"checkbox",
|
|
362
364
|
"color",
|
|
@@ -372,13 +374,13 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
372
374
|
"text",
|
|
373
375
|
"time",
|
|
374
376
|
"url"
|
|
375
|
-
], R = (e) =>
|
|
377
|
+
], R = (e) => E.includes(e) ? e : "text";
|
|
376
378
|
export {
|
|
377
379
|
u as createMeta,
|
|
378
380
|
P as duplicateSchema,
|
|
379
381
|
F as generateInputStandardSchemaFromFieldMeta,
|
|
380
382
|
j as generateMetaFromSchema,
|
|
381
383
|
R as getInputType,
|
|
382
|
-
|
|
384
|
+
g as isNullableOrUndefined,
|
|
383
385
|
D as nullableInput
|
|
384
386
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-app/vue-components",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.9",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@mdi/js": "^7.4.47",
|
|
6
6
|
"effect": "^3.18.0",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"highlight.js": "^11.11.1",
|
|
54
54
|
"mitt": "^3.0.1",
|
|
55
55
|
"vue3-highlightjs": "^1.0.5",
|
|
56
|
-
"
|
|
57
|
-
"effect-app": "
|
|
56
|
+
"effect-app": "3.12.0",
|
|
57
|
+
"@effect-app/vue": "2.92.2"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "pnpm build:run",
|
|
@@ -915,11 +915,16 @@ export const generateInputStandardSchemaFromFieldMeta = (
|
|
|
915
915
|
case "boolean":
|
|
916
916
|
schema = S.Boolean
|
|
917
917
|
break
|
|
918
|
-
// todo: switch must be exhaustive or have default case, otherwise falls through with schema undefined.
|
|
919
918
|
|
|
920
919
|
case "unknown":
|
|
921
920
|
schema = S.Unknown
|
|
922
921
|
break
|
|
922
|
+
|
|
923
|
+
default:
|
|
924
|
+
// For any unhandled types, use Unknown schema to prevent undefined errors
|
|
925
|
+
console.warn(`Unhandled field type: ${meta}`)
|
|
926
|
+
schema = S.Unknown
|
|
927
|
+
break
|
|
923
928
|
}
|
|
924
929
|
if (!meta.required) {
|
|
925
930
|
schema = S.NullishOr(schema)
|
|
@@ -29,6 +29,14 @@ import OmegaForm from "./OmegaWrapper.vue"
|
|
|
29
29
|
const partialRecursive = <A, I, R>(schema: S.Schema<A, I, R>): S.Schema<Partial<A>, Partial<I>, R> => {
|
|
30
30
|
const ast = schema.ast
|
|
31
31
|
|
|
32
|
+
// Handle Refinement types (e.g., NonEmptyArray, filters on ExtendedClass)
|
|
33
|
+
if (ast._tag === "Refinement") {
|
|
34
|
+
const refinementAst = ast as any
|
|
35
|
+
// For refinements, bypass the filter and recursively apply partial to the underlying type
|
|
36
|
+
const fromSchema = S.make(refinementAst.from)
|
|
37
|
+
return partialRecursive(fromSchema as any)
|
|
38
|
+
}
|
|
39
|
+
|
|
32
40
|
// Handle Union types - recursively apply partial to each member
|
|
33
41
|
if (ast._tag === "Union") {
|
|
34
42
|
const partialMembers = (ast as any).types.map((memberAst: any) => {
|
|
@@ -45,11 +53,21 @@ const partialRecursive = <A, I, R>(schema: S.Schema<A, I, R>): S.Schema<Partial<
|
|
|
45
53
|
return S.make(newAst as any)
|
|
46
54
|
}
|
|
47
55
|
|
|
48
|
-
// Handle Transformation types (e.g., withDefaultConstructor)
|
|
56
|
+
// Handle Transformation types (e.g., withDefaultConstructor, ExtendedClass)
|
|
49
57
|
if (ast._tag === "Transformation") {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
const transformAst = ast as any
|
|
59
|
+
|
|
60
|
+
// Special handling for ExtendedClass (Declaration in 'to' side)
|
|
61
|
+
if (transformAst.to._tag === "Declaration") {
|
|
62
|
+
// For ExtendedClass, extract the TypeLiteral from the 'from' side
|
|
63
|
+
// and make that partial, bypassing the Declaration entirely
|
|
64
|
+
const fromSchema = S.make(transformAst.from)
|
|
65
|
+
return partialRecursive(fromSchema as any)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// For other transformations, apply partial to both sides
|
|
69
|
+
const fromSchema = S.make(transformAst.from)
|
|
70
|
+
const toSchema = S.make(transformAst.to)
|
|
53
71
|
const partialFrom = partialRecursive(fromSchema as any)
|
|
54
72
|
const partialTo = partialRecursive(toSchema as any)
|
|
55
73
|
|
|
@@ -68,8 +86,12 @@ const partialRecursive = <A, I, R>(schema: S.Schema<A, I, R>): S.Schema<Partial<
|
|
|
68
86
|
const propType = prop.type
|
|
69
87
|
let newType = propType
|
|
70
88
|
|
|
71
|
-
// Recursively handle nested complex types (structs, unions, transformations)
|
|
72
|
-
if (
|
|
89
|
+
// Recursively handle nested complex types (structs, unions, transformations, refinements)
|
|
90
|
+
if (
|
|
91
|
+
propType._tag === "TypeLiteral" || propType._tag === "Union" || propType
|
|
92
|
+
._tag === "Transformation" || propType
|
|
93
|
+
._tag === "Refinement"
|
|
94
|
+
) {
|
|
73
95
|
const nestedSchema = S.make(propType)
|
|
74
96
|
const recursivePartial = partialRecursive(nestedSchema as any)
|
|
75
97
|
newType = recursivePartial.ast
|
|
@@ -762,66 +784,6 @@ export const useOmegaForm = <
|
|
|
762
784
|
const extractDefaultsFromAST = (schemaObj: any): any => {
|
|
763
785
|
const result: Record<string, any> = {}
|
|
764
786
|
|
|
765
|
-
// If this schema has a .make() method (like ExtendedClass), use it to get complete defaults
|
|
766
|
-
// This is more reliable than manually extracting fields, especially for classes
|
|
767
|
-
if (typeof schemaObj?.make === "function") {
|
|
768
|
-
try {
|
|
769
|
-
const instance = schemaObj.make({})
|
|
770
|
-
// For ExtendedClass, the instance is already in the correct encoded format
|
|
771
|
-
// But we need to check for nullable fields that may have been set to undefined
|
|
772
|
-
// instead of null, and fix them
|
|
773
|
-
if (schemaObj?.fields && typeof schemaObj.fields === "object") {
|
|
774
|
-
for (const [key, fieldSchema] of Object.entries(schemaObj.fields)) {
|
|
775
|
-
// Only fix fields that are undefined in the instance
|
|
776
|
-
if (instance[key] === undefined) {
|
|
777
|
-
const ast = (fieldSchema as any).ast
|
|
778
|
-
const nullableOrUndefined = isNullableOrUndefined(ast)
|
|
779
|
-
if (nullableOrUndefined === "null") {
|
|
780
|
-
instance[key] = null
|
|
781
|
-
} else if (nullableOrUndefined === "undefined") {
|
|
782
|
-
instance[key] = undefined
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
return instance
|
|
788
|
-
} catch {
|
|
789
|
-
// If make() fails, fall through to manual extraction
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
// Check if this schema is a union - check both direct property and AST
|
|
794
|
-
const unionMembers = schemaObj?.members
|
|
795
|
-
|| (schemaObj?.ast?._tag === "Union" && schemaObj.ast.types
|
|
796
|
-
? schemaObj.ast.types.map((t: any) => S.make(t))
|
|
797
|
-
: null)
|
|
798
|
-
if (unionMembers && Array.isArray(unionMembers)) {
|
|
799
|
-
// For unions, we try to find the first member that has a complete set of defaults
|
|
800
|
-
// Priority is given to members with default values for discriminator fields
|
|
801
|
-
for (const member of unionMembers as any[]) {
|
|
802
|
-
const memberDefaults = extractDefaultsFromAST(member)
|
|
803
|
-
if (Object.keys(memberDefaults).length > 0) {
|
|
804
|
-
// Check if this member has a default value for a discriminator field (like _tag)
|
|
805
|
-
// If it does, use this member's defaults
|
|
806
|
-
const hasDiscriminatorDefault = member?.fields && Object.entries(member.fields).some(
|
|
807
|
-
([key, fieldSchema]: [string, any]) => {
|
|
808
|
-
// Common discriminator field names
|
|
809
|
-
if (key === "_tag" || key === "type" || key === "kind") {
|
|
810
|
-
return fieldSchema?.ast?.defaultValue !== undefined
|
|
811
|
-
}
|
|
812
|
-
return false
|
|
813
|
-
}
|
|
814
|
-
)
|
|
815
|
-
|
|
816
|
-
if (hasDiscriminatorDefault) {
|
|
817
|
-
return memberDefaults
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
// If no member has a discriminator default, return empty
|
|
822
|
-
return {}
|
|
823
|
-
}
|
|
824
|
-
|
|
825
787
|
// Check if this schema has fields (struct)
|
|
826
788
|
if (schemaObj?.fields && typeof schemaObj.fields === "object") {
|
|
827
789
|
for (const [key, fieldSchema] of Object.entries(schemaObj.fields)) {
|
|
@@ -835,7 +797,7 @@ export const useOmegaForm = <
|
|
|
835
797
|
}
|
|
836
798
|
} else {
|
|
837
799
|
// TODO Should we put to null/undefined only leaves?
|
|
838
|
-
const ast = (fieldSchema as any)
|
|
800
|
+
const ast = (fieldSchema as any)?.ast
|
|
839
801
|
const nullableOrUndefined = isNullableOrUndefined(ast)
|
|
840
802
|
switch (nullableOrUndefined) {
|
|
841
803
|
case "null":
|
|
@@ -859,6 +821,10 @@ export const useOmegaForm = <
|
|
|
859
821
|
}
|
|
860
822
|
}
|
|
861
823
|
}
|
|
824
|
+
} else {
|
|
825
|
+
if (schemaObj?.from?.fields && typeof schemaObj?.from?.fields === "object") {
|
|
826
|
+
return extractDefaultsFromAST(schemaObj.from)
|
|
827
|
+
}
|
|
862
828
|
}
|
|
863
829
|
|
|
864
830
|
return result
|
|
@@ -869,25 +835,14 @@ export const useOmegaForm = <
|
|
|
869
835
|
let result: Partial<From> = {}
|
|
870
836
|
|
|
871
837
|
try {
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
const decoded = (schema as any).make(defaultValues)
|
|
876
|
-
result = S.encodeSync(partialRecursive(extractDefaultsFromAST(schema)))(decoded)
|
|
877
|
-
} catch (error) {
|
|
878
|
-
// If make() fails, try to extract defaults from AST
|
|
838
|
+
const astDefaults = extractDefaultsFromAST(schema)
|
|
839
|
+
result = S.encodeSync(partialRecursive(schema))(astDefaults)
|
|
840
|
+
} catch (astError) {
|
|
879
841
|
if (window.location.hostname === "localhost") {
|
|
880
|
-
console.warn("
|
|
881
|
-
}
|
|
882
|
-
try {
|
|
883
|
-
const astDefaults = extractDefaultsFromAST(schema)
|
|
884
|
-
result = S.encodeSync(partialRecursive(schema))(astDefaults)
|
|
885
|
-
} catch (astError) {
|
|
886
|
-
if (window.location.hostname === "localhost") {
|
|
887
|
-
console.warn("Could not extract defaults from AST:", astError)
|
|
888
|
-
}
|
|
842
|
+
console.warn("Could not extract defaults from AST:", astError)
|
|
889
843
|
}
|
|
890
844
|
}
|
|
845
|
+
|
|
891
846
|
return deepMerge(result, defaultValues)
|
|
892
847
|
}
|
|
893
848
|
|