@effect-app/vue-components 4.0.0-beta.49 → 4.0.0-beta.51

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.
@@ -8,15 +8,15 @@ import l from "./vue-components41.es.js";
8
8
  import u from "./vue-components45.es.js";
9
9
  import d from "./vue-components52.es.js";
10
10
  import f from "./vue-components56.es.js";
11
- import ee from "./vue-components60.es.js";
12
- import { computed as p, h as m, onBeforeUnmount as h, onMounted as g, onUnmounted as _, ref as v, watch as y } from "vue";
13
- import { Array as b, Data as x, Effect as S, Fiber as C, Option as w, S as T, ServiceMap as E } from "effect-app";
14
- import { useForm as D } from "@tanstack/vue-form";
15
- import { makeRunPromise as O } from "@effect-app/vue/runtime";
11
+ import p from "./vue-components60.es.js";
12
+ import { computed as m, h, onBeforeUnmount as g, onMounted as _, onUnmounted as v, ref as y, watch as b } from "vue";
13
+ import { Array as x, Data as S, Effect as C, Fiber as w, Option as T, S as E, ServiceMap as D } from "effect-app";
14
+ import { useForm as O } from "@tanstack/vue-form";
15
+ import { makeRunPromise as k } from "@effect-app/vue/runtime";
16
16
  //#region src/components/OmegaForm/useOmegaForm.ts
17
- var k = class extends x.TaggedError("FormErrors") {}, A = (e) => function(t) {
17
+ var ee = class extends S.TaggedError("FormErrors") {}, A = (e) => function(t) {
18
18
  return { render() {
19
- return m(t, {
19
+ return h(t, {
20
20
  form: e,
21
21
  ...this.$attrs
22
22
  }, this.$slots);
@@ -36,7 +36,7 @@ var k = class extends x.TaggedError("FormErrors") {}, A = (e) => function(t) {
36
36
  let { fieldMap: t, form: n } = e, r = n.useStore((e) => e.errors), i = n.useStore((e) => e.fieldMeta), a = n.useStore((e) => e.errorMap), o = j(n);
37
37
  return {
38
38
  generalErrors: r,
39
- errors: p(() => {
39
+ errors: m(() => {
40
40
  let e = Object.entries(i.value).reduce((e, [n, r]) => {
41
41
  let i = r?.errors ?? [];
42
42
  if (!i.length) return e;
@@ -48,9 +48,9 @@ var k = class extends x.TaggedError("FormErrors") {}, A = (e) => function(t) {
48
48
  }), e;
49
49
  }, []), n = [];
50
50
  if (a.value.onSubmit) {
51
- for (let [e, r] of Object.entries(a.value.onSubmit)) if (b.isArray(r) && r.length) for (let e of r) {
51
+ for (let [e, r] of Object.entries(a.value.onSubmit)) if (x.isArray(r) && r.length) for (let e of r) {
52
52
  let r = e;
53
- if (r?.path && b.isArray(r.path) && r.path.length) {
53
+ if (r?.path && x.isArray(r.path) && r.path.length) {
54
54
  let e = r.path.join(".");
55
55
  if (!t.value.has(e)) {
56
56
  n.push({
@@ -68,154 +68,167 @@ var k = class extends x.TaggedError("FormErrors") {}, A = (e) => function(t) {
68
68
  };
69
69
  },
70
70
  render({ errors: e, generalErrors: n }) {
71
- return m(t, {
71
+ return h(t, {
72
72
  errors: e,
73
73
  generalErrors: n,
74
74
  ...this.$attrs
75
75
  }, this.$slots);
76
76
  }
77
77
  };
78
- }, N = (e, t) => e.includes(t), P = O(E.empty()), F = (e, m, x) => {
78
+ }, N = (e, t) => e.includes(t), P = k(D.empty()), F = (e, h, S) => {
79
79
  if (!e) throw Error("Schema is required");
80
- let E = i(e), O = T.toStandardSchemaV1(E), j = T.decodeUnknownEffect(E), { meta: F, unionMeta: I } = r(e), L = p(() => x?.persistency?.id ? x.persistency.id : `${window.location.pathname}-${Object.keys(F).join("-")}`), R = () => {
80
+ let D = i(e), k = E.toStandardSchemaV1(D), j = E.decodeUnknownEffect(D), { meta: F, unionMeta: te } = r(e), I = m(() => S?.persistency?.id ? S.persistency.id : `${window.location.pathname}-${Object.keys(F).join("-")}`), ne = () => {
81
81
  let e = new URLSearchParams(window.location.search);
82
- e.delete(L.value);
82
+ e.delete(I.value);
83
83
  let t = new URL(window.location.href);
84
84
  t.search = e.toString(), window.history.replaceState({}, "", t.toString());
85
- }, z = p(() => {
86
- let r, i = x?.persistency;
85
+ }, L = m(() => {
86
+ let r, i = S?.persistency;
87
87
  if (i?.policies && !r && (N(i.policies, "local") || N(i.policies, "session"))) {
88
88
  let e = N(i.policies, "local") ? localStorage : sessionStorage;
89
89
  if (e) try {
90
- let t = JSON.parse(e.getItem(L.value) || "{}");
91
- e.removeItem(L.value), r = t;
90
+ let t = JSON.parse(e.getItem(I.value) || "{}");
91
+ e.removeItem(I.value), r = t;
92
92
  } catch (e) {
93
93
  console.error(e);
94
94
  }
95
95
  }
96
96
  if (i?.policies && N(i.policies, "querystring")) try {
97
- let e = new URLSearchParams(window.location.search).get(L.value);
98
- R(), e && (r = t(r || {}, JSON.parse(e)));
97
+ let e = new URLSearchParams(window.location.search).get(I.value);
98
+ ne(), e && (r = t(r || {}, JSON.parse(e)));
99
99
  } catch (e) {
100
100
  console.error(e);
101
101
  }
102
102
  r ??= {};
103
103
  let a = {
104
- tanstack: m?.defaultValues || {},
104
+ tanstack: h?.defaultValues || {},
105
105
  persistency: r,
106
106
  schema: n(e)
107
107
  };
108
- return (x?.defaultValuesPriority || [
108
+ return (S?.defaultValuesPriority || [
109
109
  "tanstack",
110
110
  "persistency",
111
111
  "schema"
112
112
  ]).reverse().reduce((e, n) => Object.keys(e).length ? t(e, a[n]) : a[n], {});
113
- }), B = (e, t) => e ? a.with(o.setSpan(a.active(), e), t) : t(), V = D({
114
- ...m,
113
+ }), R = (e, t) => e ? a.with(o.setSpan(a.active(), e), t) : t(), z = O({
114
+ ...h,
115
115
  validators: {
116
- onSubmit: O,
117
- ...m?.validators || {}
116
+ onSubmit: k,
117
+ ...h?.validators || {}
118
118
  },
119
- onSubmit: m?.onSubmit ? ({ formApi: e, meta: t, value: n }) => B(t?.currentSpan, async () => {
120
- let r = await P(j(n)), i = m.onSubmit({
119
+ onSubmit: h?.onSubmit ? ({ formApi: e, meta: t, value: n }) => R(t?.currentSpan, async () => {
120
+ let r = await P(j(n)), i = h.onSubmit({
121
121
  formApi: e,
122
122
  meta: t,
123
123
  value: r
124
124
  });
125
- if (C.isFiber(i)) return await s(i);
126
- if (S.isEffect(i)) {
125
+ if (w.isFiber(i)) return await s(i);
126
+ if (C.isEffect(i)) {
127
127
  let e = await P(i);
128
- return C.isFiber(e) ? await s(e) : e;
128
+ return w.isFiber(e) ? await s(e) : e;
129
129
  }
130
130
  return i;
131
131
  }) : void 0,
132
- defaultValues: z.value
133
- }), H = () => {
132
+ defaultValues: L.value
133
+ }), B = () => {
134
134
  Object.keys(F).forEach((e) => {
135
- V.setFieldValue(e, void 0);
135
+ z.setFieldValue(e, void 0);
136
136
  });
137
- }, U = (e) => e.reduce((e, t) => {
137
+ }, V = (e) => e.reduce((e, t) => {
138
138
  let n = t.split(".");
139
- return n.reduce((e, r, i) => (i === n.length - 1 ? e[r] = V.getFieldValue(t) : e[r] = e[r] ?? {}, e[r]), e), e;
140
- }, {}), W = (e) => {
139
+ return n.reduce((e, r, i) => (i === n.length - 1 ? e[r] = z.getFieldValue(t) : e[r] = e[r] ?? {}, e[r]), e), e;
140
+ }, {}), H = (e) => {
141
141
  if (!e) return;
142
142
  let { banKeys: t, keys: n } = e;
143
- return b.isArray(n) ? U(n) : b.isArray(t) ? U(Object.keys(F).filter((e) => t.includes(e))) : V.store.state.values;
144
- }, G = () => {
145
- let e = x?.persistency;
143
+ return x.isArray(n) ? V(n) : x.isArray(t) ? V(Object.keys(F).filter((e) => t.includes(e))) : z.store.state.values;
144
+ }, U = () => {
145
+ let e = S?.persistency;
146
146
  if (!(!e?.policies || e.policies.length === 0) && (N(e.policies, "local") || N(e.policies, "session"))) {
147
147
  let t = N(e.policies, "local") ? localStorage : sessionStorage;
148
148
  if (!t) return;
149
- let n = W(e);
150
- return t.setItem(L.value, JSON.stringify(n));
149
+ let n = H(e);
150
+ return t.setItem(I.value, JSON.stringify(n));
151
151
  }
152
- }, K = () => {
153
- let e = x?.persistency;
152
+ }, W = () => {
153
+ let e = S?.persistency;
154
154
  if (!(!e?.policies || e.policies.length === 0) && N(e.policies, "querystring")) {
155
- let t = W(e), n = new URLSearchParams(window.location.search);
156
- n.set(L.value, JSON.stringify(t));
155
+ let t = H(e), n = new URLSearchParams(window.location.search);
156
+ n.set(I.value, JSON.stringify(t));
157
157
  let r = new URL(window.location.href);
158
158
  r.search = n.toString(), window.history.replaceState({}, "", r.toString());
159
159
  }
160
- }, q = (e) => {
161
- V.store.state.isDirty && e.preventDefault();
160
+ }, G = (e) => {
161
+ z.store.state.isDirty && e.preventDefault();
162
162
  };
163
- if (_(G), g(() => {
164
- window.addEventListener("beforeunload", G), window.addEventListener("blur", K), x?.preventWindowExit && x.preventWindowExit !== "nope" && window.addEventListener("beforeunload", q);
165
- }), h(() => {
166
- window.removeEventListener("beforeunload", G), window.removeEventListener("blur", K), x?.preventWindowExit && x.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", q);
167
- }), x?.preventWindowExit === "prevent-and-reset") {
168
- let e = V.useStore((e) => e.isSubmitting), t = V.useStore((e) => e.submissionAttempts), n = V.useStore((e) => e.canSubmit), r = V.useStore((e) => e.values);
169
- y([e, t], ([e, t], [i]) => {
170
- i && !e && t > 0 && n.value && V.reset(r.value);
163
+ if (v(U), _(() => {
164
+ window.addEventListener("beforeunload", U), window.addEventListener("blur", W), S?.preventWindowExit && S.preventWindowExit !== "nope" && window.addEventListener("beforeunload", G);
165
+ }), g(() => {
166
+ window.removeEventListener("beforeunload", U), window.removeEventListener("blur", W), S?.preventWindowExit && S.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", G);
167
+ }), S?.preventWindowExit === "prevent-and-reset") {
168
+ let e = z.useStore((e) => e.isSubmitting), t = z.useStore((e) => e.submissionAttempts), n = z.useStore((e) => e.canSubmit), r = z.useStore((e) => e.values);
169
+ b([e, t], ([e, t], [i]) => {
170
+ i && !e && t > 0 && n.value && z.reset(r.value);
171
171
  });
172
172
  }
173
- let J = (e) => S.currentSpan.pipe(S.option, S.flatMap((t) => S.promise(() => V.handleSubmit(w.isSome(t) ? {
173
+ let K = (e) => C.currentSpan.pipe(C.option, C.flatMap((t) => C.promise(() => z.handleSubmit(T.isSome(t) ? {
174
174
  currentSpan: t.value,
175
175
  ...e
176
- } : e)))), Y = (e) => e?.checkErrors ? J(e?.meta).pipe(S.flatMap(S.fnUntraced(function* () {
177
- let e = V.getAllErrors();
178
- if (Object.keys(e.fields).length || e.form.errors.length) return yield* S.fail(new k({
176
+ } : e)))), q = (e) => e?.checkErrors ? K(e?.meta).pipe(C.flatMap(C.fnUntraced(function* () {
177
+ let e = z.getAllErrors();
178
+ if (Object.keys(e.fields).length || e.form.errors.length) return yield* C.fail(new ee({
179
179
  form: e.form,
180
180
  fields: e.fields
181
181
  }));
182
- }))) : J(e?.meta), X = V.handleSubmit, Z = v(/* @__PURE__ */ new Map()), Q = Object.assign(V, {
183
- i18nNamespace: x?.i18nNamespace,
184
- ignorePreventCloseEvents: x?.ignorePreventCloseEvents,
182
+ }))) : K(e?.meta), J = z.handleSubmit, Y = y(/* @__PURE__ */ new Map()), X = Object.assign(z, {
183
+ i18nNamespace: S?.i18nNamespace,
184
+ ignorePreventCloseEvents: S?.ignorePreventCloseEvents,
185
185
  meta: F,
186
- unionMeta: I,
187
- clear: H,
188
- handleSubmit: (e) => X({
186
+ unionMeta: te,
187
+ clear: B,
188
+ handleSubmit: (e) => J({
189
189
  currentSpan: o.getSpan(a.active()),
190
190
  ...e
191
191
  }),
192
- handleSubmitEffect: Y,
192
+ handleSubmitEffect: q,
193
193
  registerField: (e) => {
194
- y(e, (e) => {
195
- Z.value.set(e.name, {
194
+ b(e, (e) => {
195
+ Y.value.set(e.name, {
196
196
  label: e.label,
197
197
  id: e.id
198
198
  });
199
- }, { immediate: !0 }), _(() => {
200
- Z.value.get(e.value.name)?.id === e.value.id && Z.value.delete(e.value.name);
199
+ }, { immediate: !0 }), v(() => {
200
+ Y.value.get(e.value.name)?.id === e.value.id && Y.value.delete(e.value.name);
201
201
  });
202
202
  }
203
- }), $ = {
204
- form: Q,
205
- fieldMap: Z
203
+ }), Z = y(0), Q = z.useStore((e) => e.submissionAttempts);
204
+ b(z.useStore((e) => e.values), () => {
205
+ if (Z.value !== Q.value) {
206
+ Z.value = Q.value;
207
+ for (let e of Object.values(z.fieldInfo)) e?.instance?.state.meta.errorMap?.onSubmit && e.instance.setMeta((e) => ({
208
+ ...e,
209
+ errorMap: {
210
+ ...e.errorMap,
211
+ onSubmit: void 0
212
+ }
213
+ }));
214
+ }
215
+ }, { deep: !0 });
216
+ let $ = {
217
+ form: X,
218
+ fieldMap: Y
206
219
  };
207
- return Object.assign(Q, {
220
+ return Object.assign(X, {
208
221
  _paths: void 0,
209
222
  _keys: void 0,
210
223
  _schema: e,
211
224
  errorContext: $,
212
- Form: A(Q)(ee),
213
- Input: A(Q)(x?.input ?? d),
214
- TaggedUnion: A(Q)(f),
215
- Field: V.Field,
225
+ Form: A(X)(p),
226
+ Input: A(X)(S?.input ?? d),
227
+ TaggedUnion: A(X)(f),
228
+ Field: z.Field,
216
229
  Errors: M($)(u),
217
- Array: A(Q)(c),
218
- AutoGen: A(Q)(l)
230
+ Array: A(X)(c),
231
+ AutoGen: A(X)(l)
219
232
  });
220
233
  };
221
234
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "4.0.0-beta.49",
3
+ "version": "4.0.0-beta.51",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "effect": "^4.0.0-beta.43",
@@ -57,8 +57,8 @@
57
57
  "highlight.js": "^11.11.1",
58
58
  "mitt": "^3.0.1",
59
59
  "vue3-highlightjs": "^1.0.5",
60
- "@effect-app/vue": "4.0.0-beta.49",
61
- "effect-app": "4.0.0-beta.49"
60
+ "effect-app": "4.0.0-beta.51",
61
+ "@effect-app/vue": "4.0.0-beta.51"
62
62
  },
63
63
  "scripts": {
64
64
  "check": "vue-tsc",
@@ -979,6 +979,24 @@ export const useOmegaForm = <
979
979
  }
980
980
  })
981
981
 
982
+ // Clear all field onSubmit errors when any value changes after a failed submission.
983
+ // Form-level onSubmit validation (e.g. union schemas) distributes errors to individual fields.
984
+ // TanStack only clears the changed field's onSubmit error, leaving sibling fields with stale
985
+ // errors that keep isFieldsValid=false and block re-submission.
986
+ const lastSubmitAttempts = ref(0)
987
+ const submissionAttempts = form.useStore((s) => s.submissionAttempts)
988
+ const formValues = form.useStore((s) => s.values)
989
+ watch(formValues, () => {
990
+ if (lastSubmitAttempts.value === submissionAttempts.value) return
991
+ lastSubmitAttempts.value = submissionAttempts.value
992
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
993
+ for (const info of Object.values(form.fieldInfo) as any[]) {
994
+ if (info?.instance?.state.meta.errorMap?.onSubmit) {
995
+ info.instance.setMeta((prev: any) => ({ ...prev, errorMap: { ...prev.errorMap, onSubmit: undefined } }))
996
+ }
997
+ }
998
+ }, { deep: true })
999
+
982
1000
  const errorContext = { form: formWithExtras, fieldMap }
983
1001
 
984
1002
  return Object.assign(formWithExtras, {