@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
|
|
12
|
-
import { computed as
|
|
13
|
-
import { Array as
|
|
14
|
-
import { useForm as
|
|
15
|
-
import { makeRunPromise as
|
|
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
|
|
17
|
+
var ee = class extends S.TaggedError("FormErrors") {}, A = (e) => function(t) {
|
|
18
18
|
return { render() {
|
|
19
|
-
return
|
|
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:
|
|
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 (
|
|
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 &&
|
|
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
|
|
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 =
|
|
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
|
|
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(
|
|
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
|
-
},
|
|
86
|
-
let r, i =
|
|
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(
|
|
91
|
-
e.removeItem(
|
|
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(
|
|
98
|
-
|
|
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:
|
|
104
|
+
tanstack: h?.defaultValues || {},
|
|
105
105
|
persistency: r,
|
|
106
106
|
schema: n(e)
|
|
107
107
|
};
|
|
108
|
-
return (
|
|
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
|
-
}),
|
|
114
|
-
...
|
|
113
|
+
}), R = (e, t) => e ? a.with(o.setSpan(a.active(), e), t) : t(), z = O({
|
|
114
|
+
...h,
|
|
115
115
|
validators: {
|
|
116
|
-
onSubmit:
|
|
117
|
-
...
|
|
116
|
+
onSubmit: k,
|
|
117
|
+
...h?.validators || {}
|
|
118
118
|
},
|
|
119
|
-
onSubmit:
|
|
120
|
-
let r = await P(j(n)), i =
|
|
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 (
|
|
126
|
-
if (
|
|
125
|
+
if (w.isFiber(i)) return await s(i);
|
|
126
|
+
if (C.isEffect(i)) {
|
|
127
127
|
let e = await P(i);
|
|
128
|
-
return
|
|
128
|
+
return w.isFiber(e) ? await s(e) : e;
|
|
129
129
|
}
|
|
130
130
|
return i;
|
|
131
131
|
}) : void 0,
|
|
132
|
-
defaultValues:
|
|
133
|
-
}),
|
|
132
|
+
defaultValues: L.value
|
|
133
|
+
}), B = () => {
|
|
134
134
|
Object.keys(F).forEach((e) => {
|
|
135
|
-
|
|
135
|
+
z.setFieldValue(e, void 0);
|
|
136
136
|
});
|
|
137
|
-
},
|
|
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] =
|
|
140
|
-
}, {}),
|
|
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
|
|
144
|
-
},
|
|
145
|
-
let e =
|
|
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 =
|
|
150
|
-
return t.setItem(
|
|
149
|
+
let n = H(e);
|
|
150
|
+
return t.setItem(I.value, JSON.stringify(n));
|
|
151
151
|
}
|
|
152
|
-
},
|
|
153
|
-
let e =
|
|
152
|
+
}, W = () => {
|
|
153
|
+
let e = S?.persistency;
|
|
154
154
|
if (!(!e?.policies || e.policies.length === 0) && N(e.policies, "querystring")) {
|
|
155
|
-
let t =
|
|
156
|
-
n.set(
|
|
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
|
-
},
|
|
161
|
-
|
|
160
|
+
}, G = (e) => {
|
|
161
|
+
z.store.state.isDirty && e.preventDefault();
|
|
162
162
|
};
|
|
163
|
-
if (
|
|
164
|
-
window.addEventListener("beforeunload",
|
|
165
|
-
}),
|
|
166
|
-
window.removeEventListener("beforeunload",
|
|
167
|
-
}),
|
|
168
|
-
let e =
|
|
169
|
-
|
|
170
|
-
i && !e && t > 0 && n.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
|
|
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)))),
|
|
177
|
-
let e =
|
|
178
|
-
if (Object.keys(e.fields).length || e.form.errors.length) return yield*
|
|
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
|
-
}))) :
|
|
183
|
-
i18nNamespace:
|
|
184
|
-
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:
|
|
187
|
-
clear:
|
|
188
|
-
handleSubmit: (e) =>
|
|
186
|
+
unionMeta: te,
|
|
187
|
+
clear: B,
|
|
188
|
+
handleSubmit: (e) => J({
|
|
189
189
|
currentSpan: o.getSpan(a.active()),
|
|
190
190
|
...e
|
|
191
191
|
}),
|
|
192
|
-
handleSubmitEffect:
|
|
192
|
+
handleSubmitEffect: q,
|
|
193
193
|
registerField: (e) => {
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
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
|
-
|
|
205
|
-
|
|
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(
|
|
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(
|
|
213
|
-
Input: A(
|
|
214
|
-
TaggedUnion: A(
|
|
215
|
-
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(
|
|
218
|
-
AutoGen: A(
|
|
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.
|
|
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
|
-
"
|
|
61
|
-
"effect-app": "4.0.0-beta.
|
|
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, {
|