@effect-app/vue-components 2.6.1 → 2.6.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.
@@ -1,20 +1,20 @@
1
1
  import { useForm as z } from "@tanstack/vue-form";
2
- import { Data as K, S as $, Effect as c, Fiber as k, Option as x, Array as g } from "effect-app";
3
- import { runtimeFiberAsPromise as T } from "./vue-components.es16.js";
4
- import { isObject as Z } from "./vue-components.es17.js";
5
- import { computed as N, onUnmounted as W, onMounted as G, onBeforeUnmount as Q, watch as R, ref as X, h as q } from "vue";
6
- import Y from "./vue-components.es18.js";
7
- import C from "./vue-components.es19.js";
8
- import ee from "./vue-components.es20.js";
2
+ import { Data as K, S as w, Effect as c, Fiber as U, Option as A, Array as j } from "effect-app";
3
+ import { runtimeFiberAsPromise as Z } from "./vue-components.es16.js";
4
+ import { isObject as G } from "./vue-components.es17.js";
5
+ import { computed as D, onUnmounted as R, onMounted as Q, onBeforeUnmount as X, watch as T, ref as Y, h as q } 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
9
  import { generateMetaFromSchema as re } from "./vue-components.es12.js";
10
- import te from "./vue-components.es6.js";
11
- import ne from "./vue-components.es8.js";
12
- import se from "./vue-components.es21.js";
10
+ import ne from "./vue-components.es6.js";
11
+ import se from "./vue-components.es8.js";
12
+ import oe from "./vue-components.es21.js";
13
13
  import { trace as B } from "./vue-components.es22.js";
14
- import { context as A } from "./vue-components.es23.js";
15
- class oe extends K.TaggedError("FormErrors") {
14
+ import { context as V } from "./vue-components.es23.js";
15
+ class ie extends K.TaggedError("FormErrors") {
16
16
  }
17
- const F = (a) => function(i) {
17
+ const O = (a) => function(i) {
18
18
  return {
19
19
  render() {
20
20
  return q(i, {
@@ -23,36 +23,36 @@ const F = (a) => function(i) {
23
23
  }, this.$slots);
24
24
  }
25
25
  };
26
- }, ie = (a) => function(i) {
26
+ }, ae = (a) => function(i) {
27
27
  return {
28
28
  setup() {
29
- const { fieldMap: b, form: v } = a, f = v.useStore((u) => u.errors), m = v.useStore((u) => u.fieldMeta), O = v.useStore((u) => u.errorMap), M = N(() => {
30
- const u = g.filterMap(
31
- Object.entries(m.value),
32
- ([j, h]) => {
33
- const o = h.errors ?? [];
34
- if (!o.length) return x.none();
35
- const l = b.value.get(j);
36
- return l ? x.some({
37
- label: l.label,
38
- inputId: l.id,
29
+ const { fieldMap: h, form: p } = a, f = p.useStore((u) => u.errors), d = p.useStore((u) => u.fieldMeta), k = p.useStore((u) => u.errorMap), x = D(() => {
30
+ const u = j.filterMap(
31
+ Object.entries(d.value),
32
+ ([E, v]) => {
33
+ const b = v.errors ?? [];
34
+ if (!b.length) return A.none();
35
+ const o = h.value.get(E);
36
+ return o ? A.some({
37
+ label: o.label,
38
+ inputId: o.id,
39
39
  // Only show the first error
40
- errors: [o[0]?.message].filter(Boolean)
41
- }) : x.none();
40
+ errors: [b[0]?.message].filter(Boolean)
41
+ }) : A.none();
42
42
  }
43
43
  ), y = [];
44
- if (O.value.onSubmit) {
45
- for (const [j, h] of Object.entries(O.value.onSubmit))
46
- if (g.isArray(h) && h.length)
47
- for (const o of h) {
48
- const l = o;
49
- if (l?.path && g.isArray(l.path) && l.path.length) {
50
- const w = l.path.join(".");
51
- if (!b.value.has(w)) {
44
+ if (k.value.onSubmit) {
45
+ for (const [E, v] of Object.entries(k.value.onSubmit))
46
+ if (j.isArray(v) && v.length)
47
+ for (const b of v) {
48
+ const o = b;
49
+ if (o?.path && j.isArray(o.path) && o.path.length) {
50
+ const g = o.path.join(".");
51
+ if (!h.value.has(g)) {
52
52
  y.push({
53
- label: w,
54
- inputId: w,
55
- errors: [l.message].filter(Boolean)
53
+ label: g,
54
+ inputId: g,
55
+ errors: [o.message].filter(Boolean)
56
56
  });
57
57
  break;
58
58
  }
@@ -63,187 +63,209 @@ const F = (a) => function(i) {
63
63
  });
64
64
  return {
65
65
  generalErrors: f,
66
- errors: M
66
+ errors: x
67
67
  };
68
68
  },
69
- render({ errors: b, generalErrors: v }) {
69
+ render({ errors: h, generalErrors: p }) {
70
70
  return q(i, {
71
- errors: b,
72
- generalErrors: v,
71
+ errors: h,
72
+ generalErrors: p,
73
73
  ...this.$attrs
74
74
  }, this.$slots);
75
75
  }
76
76
  };
77
- }, Ee = (a, p, i) => {
77
+ }, ge = (a, m, i) => {
78
78
  if (!a) throw new Error("Schema is required");
79
- const b = $.standardSchemaV1(a), v = $.decode(a), { meta: f } = re(a), m = N(() => {
79
+ const h = w.standardSchemaV1(a), p = w.decode(a), { meta: f } = re(a), d = D(() => {
80
80
  if (i?.persistency?.id)
81
81
  return i.persistency.id;
82
- const e = window.location.pathname, r = Object.keys(f);
83
- return `${e}-${r.join("-")}`;
84
- }), O = () => {
82
+ const e = window.location.pathname, t = Object.keys(f);
83
+ return `${e}-${t.join("-")}`;
84
+ }), k = () => {
85
85
  const e = new URLSearchParams(window.location.search);
86
- e.delete(m.value);
87
- const r = new URL(window.location.href);
88
- r.search = e.toString(), window.history.replaceState({}, "", r.toString());
86
+ e.delete(d.value);
87
+ const t = new URL(window.location.href);
88
+ t.search = e.toString(), window.history.replaceState({}, "", t.toString());
89
89
  };
90
- function M(e, r) {
91
- for (const n in r)
92
- r[n] && Z(r[n]) ? (e[n] || (e[n] = {}), M(e[n], r[n])) : e[n] = r[n];
90
+ function x(e, t) {
91
+ for (const r in t)
92
+ t[r] && G(t[r]) ? (e[r] || (e[r] = {}), x(e[r], t[r])) : e[r] = t[r];
93
93
  return e;
94
94
  }
95
95
  const u = (e) => {
96
96
  if (!e) return;
97
- const r = { ...e };
98
- for (const n in f) {
99
- const s = f[n], t = r[n], E = (t == null || t === !1 || t === "" || Number.isNaN(t)) && t !== !1 && t !== 0;
100
- s && !s.required && s.nullableOrUndefined && s.type !== "boolean" && (t === void 0 || E) && (r[n] = s.nullableOrUndefined === "undefined" ? void 0 : null);
97
+ const t = { ...e };
98
+ for (const r in f) {
99
+ const s = f[r], n = t[r], F = (n == null || n === !1 || n === "" || Number.isNaN(n)) && n !== !1 && n !== 0;
100
+ s && !s.required && s.nullableOrUndefined && s.type !== "boolean" && (n === void 0 || F) && (t[r] = s.nullableOrUndefined === "undefined" ? void 0 : null);
101
101
  }
102
- return r;
103
- }, y = (e = {}) => {
102
+ return t;
103
+ }, y = (e) => {
104
+ const t = {};
105
+ if (e?.fields && typeof e.fields == "object")
106
+ for (const [r, s] of Object.entries(e.fields)) {
107
+ if (s?.ast?.defaultValue)
108
+ try {
109
+ const l = s.ast.defaultValue();
110
+ l !== void 0 && (t[r] = l);
111
+ } catch {
112
+ }
113
+ const n = y(s);
114
+ Object.keys(n).length > 0 && (t[r] && typeof t[r] == "object" ? Object.assign(t[r], n) : t[r] || (t[r] = n));
115
+ }
116
+ return t;
117
+ }, E = (e = {}) => {
104
118
  try {
105
- if ("make" in a && typeof a.make == "function")
106
- return a.make(e, { disableValidation: !0 });
107
- } catch (r) {
108
- return console.warn("Could not extract schema constructor defaults:", r), {};
119
+ if ("make" in a && typeof a.make == "function") {
120
+ const t = a.make(e);
121
+ return w.encodeSync(a.pipe(w.partial))(t);
122
+ }
123
+ } catch (t) {
124
+ window.location.hostname === "localhost" && console.warn("schema.make() failed, extracting defaults from AST:", t);
125
+ try {
126
+ const r = y(a);
127
+ return w.encodeSync(a.pipe(w.partial))(r);
128
+ } catch (r) {
129
+ return window.location.hostname === "localhost" && console.warn("Could not extract defaults from AST:", r), {};
130
+ }
109
131
  }
110
- }, j = N(() => {
111
- const e = y(u(p?.defaultValues));
132
+ }, v = D(() => {
133
+ const e = E(u(m?.defaultValues));
112
134
  if (e && !i?.persistency?.overrideDefaultValues)
113
135
  return e;
114
- let r;
115
- const n = i?.persistency;
116
- if (!n?.policies || n.policies.length === 0) return {};
117
- if (n.policies.includes("querystring"))
136
+ let t;
137
+ const r = i?.persistency;
138
+ if (!r?.policies || r.policies.length === 0) return {};
139
+ if (r.policies.includes("querystring"))
118
140
  try {
119
- const t = new URLSearchParams(window.location.search).get(m.value);
120
- O(), t && (r = JSON.parse(t));
141
+ const n = new URLSearchParams(window.location.search).get(d.value);
142
+ k(), n && (t = JSON.parse(n));
121
143
  } catch (s) {
122
144
  console.error(s);
123
145
  }
124
146
  if (
125
147
  // query string has higher priority than local/session storage
126
- !r && (n.policies.includes("local") || n.policies.includes("session"))
148
+ !t && (r.policies.includes("local") || r.policies.includes("session"))
127
149
  ) {
128
- const s = n.policies.includes("local") ? localStorage : sessionStorage;
150
+ const s = r.policies.includes("local") ? localStorage : sessionStorage;
129
151
  if (s)
130
152
  try {
131
- const t = JSON.parse(
132
- s.getItem(m.value) || "{}"
153
+ const n = JSON.parse(
154
+ s.getItem(d.value) || "{}"
133
155
  );
134
- s.removeItem(m.value), r = t;
135
- } catch (t) {
136
- console.error(t);
156
+ s.removeItem(d.value), t = n;
157
+ } catch (n) {
158
+ console.error(n);
137
159
  }
138
160
  }
139
- return r ??= y({}), e ? M(e, r) : r;
140
- }), h = (e, r) => e ? A.with(B.setSpan(A.active(), e), r) : r(), o = z({
141
- ...p,
161
+ return t ??= E({}), e ? x(e, t) : t;
162
+ }), b = (e, t) => e ? V.with(B.setSpan(V.active(), e), t) : t(), o = z({
163
+ ...m,
142
164
  validators: {
143
- onSubmit: b,
144
- ...p?.validators || {}
165
+ onSubmit: h,
166
+ ...m?.validators || {}
145
167
  },
146
- onSubmit: p?.onSubmit ? ({ formApi: e, meta: r, value: n }) => h(r?.currentSpan, async () => {
147
- const s = await c.runPromise(v(n)), t = p.onSubmit({
168
+ onSubmit: m?.onSubmit ? ({ formApi: e, meta: t, value: r }) => b(t?.currentSpan, async () => {
169
+ const s = await c.runPromise(p(r)), n = m.onSubmit({
148
170
  formApi: e,
149
- meta: r,
171
+ meta: t,
150
172
  value: s
151
173
  });
152
- return k.isFiber(t) && k.isRuntimeFiber(t) ? await T(t) : c.isEffect(t) ? await c.runPromise(
153
- t.pipe(
174
+ return U.isFiber(n) && U.isRuntimeFiber(n) ? await Z(n) : c.isEffect(n) ? await c.runPromise(
175
+ n.pipe(
154
176
  // meta?.currentSpan
155
177
  // ? Effect.withParentSpan(meta.currentSpan)
156
178
  // : (_) => _,
157
- c.flatMap((d) => k.join(d))
179
+ c.flatMap((l) => U.join(l))
158
180
  )
159
- ) : t;
181
+ ) : n;
160
182
  }) : void 0,
161
- defaultValues: j.value
162
- }), l = () => {
183
+ defaultValues: v.value
184
+ }), g = () => {
163
185
  Object.keys(f).forEach((e) => {
164
186
  o.setFieldValue(e, void 0);
165
187
  });
166
- }, w = (e) => e.reduce((r, n) => {
167
- const s = n.split(".");
168
- return s.reduce((t, d, E) => (E === s.length - 1 ? t[d] = o.getFieldValue(n) : t[d] = t[d] ?? {}, t[d]), r), r;
188
+ }, N = (e) => e.reduce((t, r) => {
189
+ const s = r.split(".");
190
+ return s.reduce((n, l, F) => (F === s.length - 1 ? n[l] = o.getFieldValue(r) : n[l] = n[l] ?? {}, n[l]), t), t;
169
191
  }, {}), _ = (e) => {
170
192
  if (e) {
171
- if (g.isArray(e.keys))
172
- return w(e.keys);
173
- if (g.isArray(e.banKeys)) {
174
- const r = Object.keys(f).filter((n) => e.banKeys?.includes(n));
175
- return w(r);
193
+ if (j.isArray(e.keys))
194
+ return N(e.keys);
195
+ if (j.isArray(e.banKeys)) {
196
+ const t = Object.keys(f).filter((r) => e.banKeys?.includes(r));
197
+ return N(t);
176
198
  }
177
199
  return o.store.state.values;
178
200
  }
179
- }, P = () => {
201
+ }, M = () => {
180
202
  const e = i?.persistency;
181
203
  if (!(!e?.policies || e.policies.length === 0) && (e.policies.includes("local") || e.policies.includes("session"))) {
182
- const r = e.policies.includes("local") ? localStorage : sessionStorage;
183
- if (!r) return;
184
- const n = _(e);
185
- return r.setItem(m.value, JSON.stringify(n));
204
+ const t = e.policies.includes("local") ? localStorage : sessionStorage;
205
+ if (!t) return;
206
+ const r = _(e);
207
+ return t.setItem(d.value, JSON.stringify(r));
186
208
  }
187
209
  }, L = () => {
188
210
  const e = i?.persistency;
189
211
  if (!(!e?.policies || e.policies.length === 0) && e.policies.includes("querystring")) {
190
- const r = _(e), n = new URLSearchParams(window.location.search);
191
- n.set(m.value, JSON.stringify(r));
212
+ const t = _(e), r = new URLSearchParams(window.location.search);
213
+ r.set(d.value, JSON.stringify(t));
192
214
  const s = new URL(window.location.href);
193
- s.search = n.toString(), window.history.replaceState({}, "", s.toString());
215
+ s.search = r.toString(), window.history.replaceState({}, "", s.toString());
194
216
  }
195
- }, V = (e) => {
217
+ }, I = (e) => {
196
218
  o.store.state.isDirty && e.preventDefault();
197
219
  };
198
- if (W(P), G(() => {
199
- window.addEventListener("beforeunload", P), window.addEventListener("blur", L), i?.preventWindowExit && i.preventWindowExit !== "nope" && window.addEventListener("beforeunload", V);
200
- }), Q(() => {
201
- window.removeEventListener("beforeunload", P), window.removeEventListener("blur", L), i?.preventWindowExit && i.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", V);
220
+ if (R(M), Q(() => {
221
+ window.addEventListener("beforeunload", M), window.addEventListener("blur", L), i?.preventWindowExit && i.preventWindowExit !== "nope" && window.addEventListener("beforeunload", I);
222
+ }), X(() => {
223
+ window.removeEventListener("beforeunload", M), window.removeEventListener("blur", L), i?.preventWindowExit && i.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", I);
202
224
  }), i?.preventWindowExit === "prevent-and-reset") {
203
- const e = o.useStore((t) => t.isSubmitting), r = o.useStore((t) => t.submissionAttempts), n = o.useStore((t) => t.canSubmit), s = o.useStore((t) => t.values);
204
- R([e, r], ([t, d], [E]) => {
205
- E && !t && d > 0 && n.value && o.reset(s.value);
225
+ const e = o.useStore((n) => n.isSubmitting), t = o.useStore((n) => n.submissionAttempts), r = o.useStore((n) => n.canSubmit), s = o.useStore((n) => n.values);
226
+ T([e, t], ([n, l], [F]) => {
227
+ F && !n && l > 0 && r.value && o.reset(s.value);
206
228
  });
207
229
  }
208
- const D = (e) => c.currentSpan.pipe(
230
+ const $ = (e) => c.currentSpan.pipe(
209
231
  c.option,
210
232
  c.flatMap(
211
- (r) => c.promise(() => o.handleSubmit(x.isSome(r) ? { currentSpan: r.value, ...e } : e))
233
+ (t) => c.promise(() => o.handleSubmit(A.isSome(t) ? { currentSpan: t.value, ...e } : e))
212
234
  )
213
- ), H = (e) => e?.checkErrors ? D(e?.meta).pipe(c.flatMap(c.fnUntraced(function* () {
214
- const r = o.getAllErrors();
215
- if (Object.keys(r.fields).length || r.form.errors.length)
216
- return yield* new oe({ form: r.form, fields: r.fields });
217
- }))) : D(e?.meta), J = o.handleSubmit, U = X(/* @__PURE__ */ new Map()), S = Object.assign(o, {
235
+ ), H = (e) => e?.checkErrors ? $(e?.meta).pipe(c.flatMap(c.fnUntraced(function* () {
236
+ const t = o.getAllErrors();
237
+ if (Object.keys(t.fields).length || t.form.errors.length)
238
+ return yield* new ie({ form: t.form, fields: t.fields });
239
+ }))) : $(e?.meta), J = o.handleSubmit, P = Y(/* @__PURE__ */ new Map()), S = Object.assign(o, {
218
240
  i18nNamespace: i?.i18nNamespace,
219
241
  ignorePreventCloseEvents: i?.ignorePreventCloseEvents,
220
242
  meta: f,
221
- clear: l,
243
+ clear: g,
222
244
  handleSubmit: (e) => {
223
- const r = B.getSpan(A.active());
224
- return J({ currentSpan: r, ...e });
245
+ const t = B.getSpan(V.active());
246
+ return J({ currentSpan: t, ...e });
225
247
  },
226
248
  // /** @experimental */
227
249
  handleSubmitEffect: H,
228
250
  registerField: (e) => {
229
- R(e, (r) => U.value.set(r.name, { label: r.label, id: r.id }), { immediate: !0 }), W(() => U.value.delete(e.value.name));
251
+ T(e, (t) => P.value.set(t.name, { label: t.label, id: t.id }), { immediate: !0 }), R(() => P.value.delete(e.value.name));
230
252
  }
231
- }), I = { form: S, fieldMap: U };
253
+ }), W = { form: S, fieldMap: P };
232
254
  return Object.assign(S, {
233
255
  // Type-level properties for performance optimization (not used at runtime)
234
256
  _paths: void 0,
235
257
  _keys: void 0,
236
- errorContext: I,
237
- Form: F(S)(se),
238
- Input: F(S)(i?.input ?? te),
239
- TaggedUnion: F(S)(ne),
258
+ errorContext: W,
259
+ Form: O(S)(oe),
260
+ Input: O(S)(i?.input ?? ne),
261
+ TaggedUnion: O(S)(se),
240
262
  Field: o.Field,
241
- Errors: ie(I)(ee),
242
- Array: F(S)(Y),
243
- AutoGen: F(S)(C)
263
+ Errors: ae(W)(te),
264
+ Array: O(S)(C),
265
+ AutoGen: O(S)(ee)
244
266
  });
245
267
  };
246
268
  export {
247
- oe as FormErrors,
248
- Ee as useOmegaForm
269
+ ie as FormErrors,
270
+ ge as useOmegaForm
249
271
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "2.6.1",
3
+ "version": "2.6.2",
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
- "@effect-app/vue": "2.92.2",
57
- "effect-app": "3.12.0"
56
+ "effect-app": "3.12.0",
57
+ "@effect-app/vue": "2.92.2"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "pnpm build:run",
@@ -706,16 +706,66 @@ export const useOmegaForm = <
706
706
  return normalized
707
707
  }
708
708
 
709
+ // Helper function to recursively extract default values from schema AST
710
+ const extractDefaultsFromAST = (schemaObj: any): any => {
711
+ const result: Record<string, any> = {}
712
+
713
+ // Check if this schema has fields (struct)
714
+ if (schemaObj?.fields && typeof schemaObj.fields === "object") {
715
+ for (const [key, fieldSchema] of Object.entries(schemaObj.fields)) {
716
+ // Check if this field has a default value in its AST
717
+ if ((fieldSchema as any)?.ast?.defaultValue) {
718
+ try {
719
+ const defaultValue = (fieldSchema as any).ast.defaultValue()
720
+ if (defaultValue !== undefined) {
721
+ result[key] = defaultValue
722
+ }
723
+ } catch {
724
+ // Silently ignore if defaultValue() throws
725
+ }
726
+ }
727
+
728
+ // Recursively check nested fields for structs
729
+ const nestedDefaults = extractDefaultsFromAST(fieldSchema as any)
730
+ if (Object.keys(nestedDefaults).length > 0) {
731
+ // If we already have a default value for this key, merge with nested
732
+ if (result[key] && typeof result[key] === "object") {
733
+ Object.assign(result[key], nestedDefaults)
734
+ } else if (!result[key]) {
735
+ // Only set nested defaults if we don't have a default value
736
+ result[key] = nestedDefaults
737
+ }
738
+ }
739
+ }
740
+ }
741
+
742
+ return result
743
+ }
744
+
709
745
  // Extract default values from schema constructors (e.g., withDefaultConstructor)
710
746
  const extractSchemaDefaults = (defaultValues: Partial<From> = {}) => {
711
747
  try {
748
+ // First try to use schema.make() if available
712
749
  // Note: Partial schemas don't have .make() method yet (https://github.com/Effect-TS/effect/issues/4222)
713
750
  if ("make" in schema && typeof (schema as any).make === "function") {
714
- return (schema as any).make(defaultValues, { disableValidation: true })
751
+ const decoded = (schema as any).make(defaultValues)
752
+ return S.encodeSync(schema.pipe(S.partial))(decoded)
715
753
  }
716
754
  } catch (error) {
717
- console.warn("Could not extract schema constructor defaults:", error)
718
- return {}
755
+ // If make() fails, try to extract defaults from AST
756
+ if (window.location.hostname === "localhost") {
757
+ console.warn("schema.make() failed, extracting defaults from AST:", error)
758
+ }
759
+ try {
760
+ const astDefaults = extractDefaultsFromAST(schema)
761
+
762
+ return S.encodeSync(schema.pipe(S.partial))(astDefaults)
763
+ } catch (astError) {
764
+ if (window.location.hostname === "localhost") {
765
+ console.warn("Could not extract defaults from AST:", astError)
766
+ }
767
+ return {}
768
+ }
719
769
  }
720
770
  }
721
771