@effect-app/vue-components 0.8.1 → 0.8.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.
@@ -71,7 +71,7 @@ const b = /* @__PURE__ */ P({
71
71
  }, e.$attrs, {
72
72
  "model-value": e.vuetifyValue,
73
73
  "onUpdate:modelValue": r[1] || (r[1] = (p) => {
74
- e.inputProps.field.handleChange(Number(p));
74
+ p || p === 0 ? e.inputProps.field.handleChange(Number(p)) : e.inputProps.field.handleChange(void 0);
75
75
  })
76
76
  }), null, 16, ["id", "required", "min", "max", "type", "name", "label", "error-messages", "error", "model-value"])) : l("", !0),
77
77
  e.inputProps.type === "select" || e.inputProps.type === "multiple" ? (o(), n(m, i({
@@ -1,38 +1,31 @@
1
1
  import { ref as l, computed as p, readonly as v, provide as E, inject as f } from "vue";
2
- const u = Symbol();
3
- function h(e, a, t = "onSubmit") {
4
- const r = l([]), n = (o) => {
5
- r.value = r.value.filter((d) => d.inputId !== o);
6
- }, c = (o) => {
7
- n(o.inputId), r.value.push(o);
8
- }, i = () => {
2
+ const s = Symbol();
3
+ function g(o, i, t = "onSubmit") {
4
+ const r = l([]), n = (e) => {
5
+ r.value = r.value.filter((d) => d.inputId !== e);
6
+ }, c = (e) => {
7
+ n(e.inputId), r.value.push(e);
8
+ }, m = () => {
9
9
  r.value = [];
10
- }, m = p(() => {
11
- switch (t) {
12
- case "onChange":
13
- return !0;
14
- default:
15
- return e.value > 0;
16
- }
17
- }), s = {
10
+ }, a = p(() => t === "onSubmit" ? o.value > 0 : !0), u = {
18
11
  errors: v(r),
19
12
  addError: c,
20
13
  removeError: n,
21
- clearErrors: i,
22
- showErrors: m,
23
- generalErrors: a,
14
+ clearErrors: m,
15
+ showErrors: a,
16
+ generalErrors: i,
24
17
  showErrorsOn: t ?? "onSubmit"
25
18
  };
26
- return E(u, s), s;
19
+ return E(s, u), u;
27
20
  }
28
- function w() {
29
- const e = f(u);
30
- if (!e)
21
+ function O() {
22
+ const o = f(s);
23
+ if (!o)
31
24
  throw new Error("useOmegaErrors must be used within an OmegaForm provider");
32
- return e;
25
+ return o;
33
26
  }
34
27
  export {
35
- u as OmegaErrorsKey,
36
- h as provideOmegaErrors,
37
- w as useOmegaErrors
28
+ s as OmegaErrorsKey,
29
+ g as provideOmegaErrors,
30
+ O as useOmegaErrors
38
31
  };
@@ -1,6 +1,6 @@
1
- import { S as i, Option as f, pipe as p } from "effect-app";
2
- import { useIntl as S } from "./vue-components.es3.js";
3
- const y = i.NonEmptyArray(i.String), v = (e) => i.AST.isUnion(e) && e.types.find((t) => t._tag === "UndefinedKeyword" || t === i.Null.ast), x = (e) => !e || !i.AST.isUnion(e) ? !1 : e.types.find((t) => t._tag === "UndefinedKeyword") ? "undefined" : e.types.find((t) => t === i.Null.ast) ? "null" : !1, m = ({ meta: e = {}, parent: t = "", property: n, propertySignatures: a }, l = {}) => {
1
+ import { S as i, Option as g, pipe as y } from "effect-app";
2
+ import { useIntl as v } from "./vue-components.es3.js";
3
+ const x = i.NonEmptyArray(i.String), T = (e) => i.AST.isUnion(e) && e.types.find((t) => t._tag === "UndefinedKeyword" || t === i.Null.ast), h = (e) => !e || !i.AST.isUnion(e) ? !1 : e.types.find((t) => t._tag === "UndefinedKeyword") ? "undefined" : e.types.find((t) => t === i.Null.ast) ? "null" : !1, m = ({ meta: e = {}, parent: t = "", property: n, propertySignatures: r }, u = {}) => {
4
4
  if (n && n._tag === "Transformation")
5
5
  return m({
6
6
  parent: t,
@@ -12,52 +12,80 @@ const y = i.NonEmptyArray(i.String), v = (e) => i.AST.isUnion(e) && e.types.find
12
12
  meta: e,
13
13
  propertySignatures: n.propertySignatures
14
14
  });
15
- if (a) {
16
- for (const s of a) {
17
- const u = t ? `${t}.${s.name.toString()}` : s.name.toString(), r = x(s.type), o = !r;
18
- let d = s.type;
19
- if (i.AST.isUnion(s.type) && (d = s.type.types.find(
20
- (g) => g._tag !== "UndefinedKeyword" && g !== i.Null.ast
21
- )), "propertySignatures" in d)
15
+ if (r) {
16
+ for (const s of r) {
17
+ const o = t ? `${t}.${s.name.toString()}` : s.name.toString(), a = h(s.type), l = !a, p = s.type;
18
+ if (i.AST.isUnion(s.type)) {
19
+ const d = s.type.types.filter(
20
+ (f) => f._tag !== "UndefinedKeyword" && f !== i.Null.ast
21
+ );
22
+ if (d.some(
23
+ (f) => "propertySignatures" in f
24
+ )) {
25
+ const f = m({
26
+ parent: o,
27
+ property: s.type,
28
+ meta: { required: l, nullableOrUndefined: a }
29
+ });
30
+ u[o] = f;
31
+ for (const c of d)
32
+ "propertySignatures" in c && Object.assign(
33
+ u,
34
+ m({
35
+ parent: o,
36
+ propertySignatures: c.propertySignatures,
37
+ meta: { required: l, nullableOrUndefined: a }
38
+ })
39
+ );
40
+ } else {
41
+ const f = m({
42
+ parent: o,
43
+ property: s.type,
44
+ meta: { required: l, nullableOrUndefined: a }
45
+ });
46
+ u[o] = f;
47
+ }
48
+ }
49
+ if ("propertySignatures" in p)
22
50
  Object.assign(
23
- l,
51
+ u,
24
52
  m({
25
- parent: u,
26
- propertySignatures: d.propertySignatures,
27
- meta: { required: o, nullableOrUndefined: r }
53
+ parent: o,
54
+ propertySignatures: p.propertySignatures,
55
+ meta: { required: l, nullableOrUndefined: a }
28
56
  })
29
57
  );
30
58
  else {
31
- const g = m({
32
- parent: u,
59
+ const d = m({
60
+ parent: o,
33
61
  property: s.type,
34
- meta: { required: o, nullableOrUndefined: r }
62
+ meta: { required: l, nullableOrUndefined: a }
35
63
  });
36
- l[u] = g;
64
+ u[o] = d;
37
65
  }
38
66
  }
39
- return l;
67
+ return u;
40
68
  }
41
69
  if (n) {
42
- const s = v(n);
70
+ const s = T(n);
43
71
  if (Object.hasOwnProperty.call(e, "required") || (e.required = !s), i.AST.isUnion(n)) {
44
- const r = n.types.find(
45
- (o) => o._tag !== "UndefinedKeyword" && o !== i.Null.ast
72
+ const a = n.types.find(
73
+ (l) => l._tag !== "UndefinedKeyword" && l !== i.Null.ast
46
74
  );
47
- return "propertySignatures" in r ? m({
48
- propertySignatures: r.propertySignatures,
75
+ return "propertySignatures" in a ? m({
76
+ propertySignatures: a.propertySignatures,
49
77
  parent: t,
50
78
  meta: e
51
79
  }) : n.types.every(i.AST.isLiteral) ? {
52
80
  ...e,
53
81
  type: "select",
54
- members: n.types.map((o) => o.literal)
82
+ members: n.types.map((l) => l.literal)
55
83
  } : {
56
84
  ...e,
57
85
  ...m({
58
86
  parent: t,
59
87
  meta: e,
60
- property: r
88
+ property: a
61
89
  })
62
90
  };
63
91
  }
@@ -68,11 +96,11 @@ const y = i.NonEmptyArray(i.String), v = (e) => i.AST.isUnion(e) && e.types.find
68
96
  members: n.elements,
69
97
  rest: n.rest
70
98
  };
71
- const u = i.AST.getAnnotation(
99
+ const o = i.AST.getAnnotation(
72
100
  n,
73
101
  i.AST.JSONSchemaAnnotationId
74
- ).pipe(f.getOrElse(() => ({})));
75
- return e = { ...e, ...u }, "from" in n ? m({
102
+ ).pipe(g.getOrElse(() => ({})));
103
+ return e = { ...e, ...o }, "from" in n ? m({
76
104
  parent: t,
77
105
  meta: e,
78
106
  property: n.from
@@ -80,50 +108,50 @@ const y = i.NonEmptyArray(i.String), v = (e) => i.AST.isUnion(e) && e.types.find
80
108
  n,
81
109
  i.AST.TitleAnnotationId
82
110
  ).pipe(
83
- f.getOrElse(() => "unknown")
111
+ g.getOrElse(() => "unknown")
84
112
  ), e);
85
113
  }
86
- return l;
87
- }, c = (e) => {
114
+ return u;
115
+ }, S = (e) => {
88
116
  const t = e.ast, n = {};
89
117
  if (t._tag === "Transformation" || t._tag === "Refinement")
90
- return c(i.make(t.from));
118
+ return S(i.make(t.from));
91
119
  if ("propertySignatures" in t) {
92
- const a = m({
120
+ const r = m({
93
121
  propertySignatures: t.propertySignatures
94
122
  });
95
- if (Object.values(a).every((s) => s && "type" in s))
96
- return a;
97
- const l = (s, u = "") => {
98
- for (const r in s) {
99
- const o = u ? `${u}.${r}` : r;
100
- s[r] && typeof s[r] == "object" && "type" in s[r] ? n[o] = s[r] : s[r] && typeof s[r] == "object" && l(s[r], o);
123
+ if (Object.values(r).every((s) => s && "type" in s))
124
+ return r;
125
+ const u = (s, o = "") => {
126
+ for (const a in s) {
127
+ const l = o ? `${o}.${a}` : a;
128
+ s[a] && typeof s[a] == "object" && "type" in s[a] ? n[l] = s[a] : s[a] && typeof s[a] == "object" && u(s[a], l);
101
129
  }
102
130
  };
103
- l(a);
131
+ u(r);
104
132
  }
105
133
  return n;
106
- }, b = (e) => i.extend(e, i.Struct({})), A = (e) => {
107
- const t = c(e), n = p(
134
+ }, M = (e) => i.extend(e, i.Struct({})), N = (e) => {
135
+ const t = S(e), n = y(
108
136
  e.ast,
109
- f.liftPredicate((a) => a._tag === "Refinement" && "filter" in a),
110
- f.flatMap((a) => i.AST.getJSONSchemaAnnotation(a)),
111
- f.filter((a) => "items" in a),
112
- f.filterMap(
113
- ({ items: a }) => i.decodeUnknownOption(y)(a)
137
+ g.liftPredicate((r) => r._tag === "Refinement" && "filter" in r),
138
+ g.flatMap((r) => i.AST.getJSONSchemaAnnotation(r)),
139
+ g.filter((r) => "items" in r),
140
+ g.filterMap(
141
+ ({ items: r }) => i.decodeUnknownOption(x)(r)
114
142
  ),
115
- f.zipWith(
143
+ g.zipWith(
116
144
  i.AST.getMessageAnnotation(e.ast),
117
- (a, l) => ({
118
- items: a,
119
- message: l("")
145
+ (r, u) => ({
146
+ items: r,
147
+ message: u("")
120
148
  })
121
149
  ),
122
- f.getOrUndefined
150
+ g.getOrUndefined
123
151
  );
124
152
  return { schema: e, meta: t, filterItems: n };
125
- }, O = (e) => {
126
- const { trans: t } = S();
153
+ }, L = (e) => {
154
+ const { trans: t } = v();
127
155
  let n;
128
156
  switch (e.type) {
129
157
  case "string":
@@ -205,7 +233,7 @@ const y = i.NonEmptyArray(i.String), v = (e) => i.AST.isUnion(e) && e.types.find
205
233
  message: () => t("validation.empty")
206
234
  })
207
235
  ) : n = i.NullishOr(n), i.standardSchemaV1(n);
208
- }, L = (e, t) => i.NullOr(e).pipe(
236
+ }, U = (e, t) => i.NullOr(e).pipe(
209
237
  i.transform(i.typeSchema(e), {
210
238
  decode: (n) => n ?? t(),
211
239
  encode: (n) => n
@@ -213,8 +241,8 @@ const y = i.NonEmptyArray(i.String), v = (e) => i.AST.isUnion(e) && e.types.find
213
241
  );
214
242
  export {
215
243
  m as createMeta,
216
- b as duplicateSchema,
217
- O as generateInputStandardSchemaFromFieldMeta,
218
- A as generateMetaFromSchema,
219
- L as nullableInput
244
+ M as duplicateSchema,
245
+ L as generateInputStandardSchemaFromFieldMeta,
246
+ N as generateMetaFromSchema,
247
+ U as nullableInput
220
248
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "@tanstack/vue-form": "^1.2.4",
@@ -45,12 +45,8 @@ export function provideOmegaErrors(
45
45
  }
46
46
 
47
47
  const showErrors = computed(() => {
48
- switch (showErrorsOn) {
49
- case "onChange":
50
- return true
51
- default:
52
- return formSubmissionAttempts.value > 0
53
- }
48
+ if (showErrorsOn === "onSubmit") return formSubmissionAttempts.value > 0
49
+ return true
54
50
  })
55
51
 
56
52
  const context = {
@@ -257,13 +257,48 @@ export const createMeta = <T = any>(
257
257
  const nullableOrUndefined = isNullableOrUndefined(p.type)
258
258
  const isRequired = !nullableOrUndefined
259
259
 
260
- let typeToProcess = p.type
260
+ const typeToProcess = p.type
261
261
  if (S.AST.isUnion(p.type)) {
262
- typeToProcess = p.type.types.find(
262
+ const nonNullTypes = p.type.types.filter(
263
263
  t => t._tag !== "UndefinedKeyword" && t !== S.Null.ast,
264
- )!
265
- }
264
+ )
266
265
 
266
+ const hasStructMembers = nonNullTypes.some(
267
+ t => "propertySignatures" in t,
268
+ )
269
+
270
+ if (hasStructMembers) {
271
+ // Create metadata for the parent level (the union itself)
272
+ const parentMeta = createMeta<T>({
273
+ parent: key,
274
+ property: p.type,
275
+ meta: { required: isRequired, nullableOrUndefined },
276
+ })
277
+ acc[key as NestedKeyOf<T>] = parentMeta as FieldMeta
278
+
279
+ // Process each non-null type and merge their metadata
280
+ for (const nonNullType of nonNullTypes) {
281
+ if ("propertySignatures" in nonNullType) {
282
+ Object.assign(
283
+ acc,
284
+ createMeta<T>({
285
+ parent: key,
286
+ propertySignatures: nonNullType.propertySignatures,
287
+ meta: { required: isRequired, nullableOrUndefined },
288
+ }),
289
+ )
290
+ }
291
+ }
292
+ } else {
293
+ // If no struct members, process as regular union
294
+ const newMeta = createMeta<T>({
295
+ parent: key,
296
+ property: p.type,
297
+ meta: { required: isRequired, nullableOrUndefined },
298
+ })
299
+ acc[key as NestedKeyOf<T>] = newMeta as FieldMeta
300
+ }
301
+ }
267
302
  if ("propertySignatures" in typeToProcess) {
268
303
  Object.assign(
269
304
  acc,
@@ -63,7 +63,11 @@
63
63
  :model-value="vuetifyValue"
64
64
  @update:model-value="
65
65
  (e: any) => {
66
- inputProps.field.handleChange(Number(e))
66
+ if (e || e === 0) {
67
+ inputProps.field.handleChange(Number(e))
68
+ } else {
69
+ inputProps.field.handleChange(undefined)
70
+ }
67
71
  }
68
72
  "
69
73
  />