@effect-app/vue-components 4.0.0-beta.151 → 4.0.0-beta.152
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.
|
@@ -9,12 +9,12 @@ 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
11
|
import p from "./vue-components60.es.js";
|
|
12
|
-
import { computed as m, h, onBeforeUnmount as
|
|
13
|
-
import { Array as
|
|
14
|
-
import { useForm as
|
|
15
|
-
import { makeRunPromise as
|
|
12
|
+
import { computed as m, h, onBeforeUnmount as ee, onMounted as te, onUnmounted as g, ref as _, watch as v } from "vue";
|
|
13
|
+
import { Array as y, Context as b, Data as x, Effect as S, Fiber as C, Option as w, S as T } from "effect-app";
|
|
14
|
+
import { useForm as E } from "@tanstack/vue-form";
|
|
15
|
+
import { makeRunPromise as D } from "@effect-app/vue/runtime";
|
|
16
16
|
//#region src/components/OmegaForm/useOmegaForm.ts
|
|
17
|
-
var
|
|
17
|
+
var O = class extends x.TaggedError("FormErrors") {}, k = (e) => function(t) {
|
|
18
18
|
return { render() {
|
|
19
19
|
return h(t, {
|
|
20
20
|
form: e,
|
|
@@ -48,9 +48,9 @@ var te = class extends S.TaggedError("FormErrors") {}, k = (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 (y.isArray(r) && r.length) for (let e of r) {
|
|
52
52
|
let r = e;
|
|
53
|
-
if (r?.path &&
|
|
53
|
+
if (r?.path && y.isArray(r.path) && r.path.length) {
|
|
54
54
|
let e = r.path.join(".");
|
|
55
55
|
if (!t.value.has(e)) {
|
|
56
56
|
n.push({
|
|
@@ -75,15 +75,15 @@ var te = class extends S.TaggedError("FormErrors") {}, k = (e) => function(t) {
|
|
|
75
75
|
}, this.$slots);
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
-
}, M = (e, t) => e.includes(t), N =
|
|
78
|
+
}, M = (e, t) => e.includes(t), N = D(b.empty()), P = (e, h, b) => {
|
|
79
79
|
if (!e) throw Error("Schema is required");
|
|
80
|
-
let
|
|
80
|
+
let x = i(e), D = T.toStandardSchemaV1(x), A = T.decodeUnknownEffect(x), { meta: P, unionMeta: ne } = r(x), F = m(() => b?.persistency?.id ? b.persistency.id : `${window.location.pathname}-${Object.keys(P).join("-")}`), re = () => {
|
|
81
81
|
let e = new URLSearchParams(window.location.search);
|
|
82
82
|
e.delete(F.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
|
+
}, I = m(() => {
|
|
86
|
+
let r, i = b?.persistency;
|
|
87
87
|
if (i?.policies && !r && (M(i.policies, "local") || M(i.policies, "session"))) {
|
|
88
88
|
let e = M(i.policies, "local") ? localStorage : sessionStorage;
|
|
89
89
|
if (e) try {
|
|
@@ -95,7 +95,7 @@ var te = class extends S.TaggedError("FormErrors") {}, k = (e) => function(t) {
|
|
|
95
95
|
}
|
|
96
96
|
if (i?.policies && M(i.policies, "querystring")) try {
|
|
97
97
|
let e = new URLSearchParams(window.location.search).get(F.value);
|
|
98
|
-
|
|
98
|
+
re(), e && (r = t(r || {}, JSON.parse(e)));
|
|
99
99
|
} catch (e) {
|
|
100
100
|
console.error(e);
|
|
101
101
|
}
|
|
@@ -105,106 +105,106 @@ var te = class extends S.TaggedError("FormErrors") {}, k = (e) => function(t) {
|
|
|
105
105
|
persistency: r,
|
|
106
106
|
schema: n(e)
|
|
107
107
|
};
|
|
108
|
-
return (
|
|
108
|
+
return (b?.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
|
-
}),
|
|
113
|
+
}), L = (e, t) => e ? a.with(o.setSpan(a.active(), e), t) : t(), R = E({
|
|
114
114
|
...h,
|
|
115
115
|
validators: {
|
|
116
|
-
onSubmit:
|
|
116
|
+
onSubmit: D,
|
|
117
117
|
...h?.validators || {}
|
|
118
118
|
},
|
|
119
|
-
onSubmit: h?.onSubmit ? ({ formApi: e, meta: t, value: n }) =>
|
|
119
|
+
onSubmit: h?.onSubmit ? ({ formApi: e, meta: t, value: n }) => L(t?.currentSpan, async () => {
|
|
120
120
|
let r = await N(A(n)), i = h.onSubmit({
|
|
121
121
|
formApi: e,
|
|
122
122
|
meta: t,
|
|
123
123
|
value: r
|
|
124
124
|
});
|
|
125
|
-
if (
|
|
126
|
-
if (
|
|
125
|
+
if (C.isFiber(i)) return await s(i);
|
|
126
|
+
if (S.isEffect(i)) {
|
|
127
127
|
let e = await N(i);
|
|
128
|
-
return
|
|
128
|
+
return C.isFiber(e) ? await s(e) : e;
|
|
129
129
|
}
|
|
130
130
|
return i;
|
|
131
131
|
}) : void 0,
|
|
132
|
-
defaultValues:
|
|
133
|
-
}),
|
|
132
|
+
defaultValues: I.value
|
|
133
|
+
}), z = () => {
|
|
134
134
|
Object.keys(P).forEach((e) => {
|
|
135
|
-
|
|
135
|
+
R.setFieldValue(e, void 0);
|
|
136
136
|
});
|
|
137
|
-
},
|
|
137
|
+
}, B = (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] = R.getFieldValue(t) : e[r] = e[r] ?? {}, e[r]), e), e;
|
|
140
|
+
}, {}), V = (e) => {
|
|
141
141
|
if (!e) return;
|
|
142
142
|
let { banKeys: t, keys: n } = e;
|
|
143
|
-
return
|
|
144
|
-
},
|
|
145
|
-
let e =
|
|
143
|
+
return y.isArray(n) ? B(n) : y.isArray(t) ? B(Object.keys(P).filter((e) => t.includes(e))) : R.store.state.values;
|
|
144
|
+
}, H = () => {
|
|
145
|
+
let e = b?.persistency;
|
|
146
146
|
if (!(!e?.policies || e.policies.length === 0) && (M(e.policies, "local") || M(e.policies, "session"))) {
|
|
147
147
|
let t = M(e.policies, "local") ? localStorage : sessionStorage;
|
|
148
148
|
if (!t) return;
|
|
149
|
-
let n =
|
|
149
|
+
let n = V(e);
|
|
150
150
|
return t.setItem(F.value, JSON.stringify(n));
|
|
151
151
|
}
|
|
152
|
-
},
|
|
153
|
-
let e =
|
|
152
|
+
}, U = () => {
|
|
153
|
+
let e = b?.persistency;
|
|
154
154
|
if (!(!e?.policies || e.policies.length === 0) && M(e.policies, "querystring")) {
|
|
155
|
-
let t =
|
|
155
|
+
let t = V(e), n = new URLSearchParams(window.location.search);
|
|
156
156
|
n.set(F.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
|
+
}, W = (e) => {
|
|
161
|
+
R.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 (g(H), te(() => {
|
|
164
|
+
window.addEventListener("beforeunload", H), window.addEventListener("blur", U), b?.preventWindowExit && b.preventWindowExit !== "nope" && window.addEventListener("beforeunload", W);
|
|
165
|
+
}), ee(() => {
|
|
166
|
+
window.removeEventListener("beforeunload", H), window.removeEventListener("blur", U), b?.preventWindowExit && b.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", W);
|
|
167
|
+
}), b?.preventWindowExit === "prevent-and-reset") {
|
|
168
|
+
let e = R.useStore((e) => e.isSubmitting), t = R.useStore((e) => e.submissionAttempts), n = R.useStore((e) => e.canSubmit), r = R.useStore((e) => e.values);
|
|
169
|
+
v([e, t], ([e, t], [i]) => {
|
|
170
|
+
i && !e && t > 0 && n.value && R.reset(r.value);
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
|
-
let K = (e) =>
|
|
173
|
+
let G = R.handleSubmit, K = async (e) => (await R.validateAllFields("blur"), await G(e)), q = (e) => S.currentSpan.pipe(S.option, S.flatMap((t) => S.promise(() => K(w.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)))), J = (e) => e?.checkErrors ? q(e?.meta).pipe(S.flatMap(S.fnUntraced(function* () {
|
|
177
|
+
let e = R.getAllErrors();
|
|
178
|
+
if (Object.keys(e.fields).length || e.form.errors.length) return yield* S.fail(new O({
|
|
179
179
|
form: e.form,
|
|
180
180
|
fields: e.fields
|
|
181
181
|
}));
|
|
182
|
-
}))) :
|
|
183
|
-
i18nNamespace:
|
|
184
|
-
ignorePreventCloseEvents:
|
|
182
|
+
}))) : q(e?.meta), Y = _(/* @__PURE__ */ new Map()), X = Object.assign(R, {
|
|
183
|
+
i18nNamespace: b?.i18nNamespace,
|
|
184
|
+
ignorePreventCloseEvents: b?.ignorePreventCloseEvents,
|
|
185
185
|
meta: P,
|
|
186
186
|
unionMeta: ne,
|
|
187
|
-
clear:
|
|
188
|
-
handleSubmit: (e) =>
|
|
187
|
+
clear: z,
|
|
188
|
+
handleSubmit: (e) => K({
|
|
189
189
|
currentSpan: o.getSpan(a.active()),
|
|
190
190
|
...e
|
|
191
191
|
}),
|
|
192
|
-
handleSubmitEffect:
|
|
192
|
+
handleSubmitEffect: J,
|
|
193
193
|
registerField: (e) => {
|
|
194
|
-
|
|
194
|
+
v(e, (e) => {
|
|
195
195
|
Y.value.set(e.name, {
|
|
196
196
|
label: e.label,
|
|
197
197
|
id: e.id
|
|
198
198
|
});
|
|
199
|
-
}, { immediate: !0 }),
|
|
199
|
+
}, { immediate: !0 }), g(() => {
|
|
200
200
|
Y.value.get(e.value.name)?.id === e.value.id && Y.value.delete(e.value.name);
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
|
-
}), Z =
|
|
204
|
-
|
|
203
|
+
}), Z = _(0), Q = R.useStore((e) => e.submissionAttempts);
|
|
204
|
+
v(R.useStore((e) => e.values), () => {
|
|
205
205
|
if (Z.value !== Q.value) {
|
|
206
206
|
Z.value = Q.value;
|
|
207
|
-
for (let e of Object.values(
|
|
207
|
+
for (let e of Object.values(R.fieldInfo)) e?.instance?.state.meta.errorMap?.onSubmit && e.instance.setMeta((e) => ({
|
|
208
208
|
...e,
|
|
209
209
|
errorMap: {
|
|
210
210
|
...e.errorMap,
|
|
@@ -223,9 +223,9 @@ var te = class extends S.TaggedError("FormErrors") {}, k = (e) => function(t) {
|
|
|
223
223
|
_schema: e,
|
|
224
224
|
errorContext: $,
|
|
225
225
|
Form: k(X)(p),
|
|
226
|
-
Input: k(X)(
|
|
226
|
+
Input: k(X)(b?.input ?? d),
|
|
227
227
|
TaggedUnion: k(X)(f),
|
|
228
|
-
Field:
|
|
228
|
+
Field: R.Field,
|
|
229
229
|
Errors: j($)(u),
|
|
230
230
|
Array: k(X)(c),
|
|
231
231
|
AutoGen: k(X)(l)
|
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.152",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@mdi/js": "^7.4.47",
|
|
6
6
|
"effect": "^4.0.0-beta.56",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"highlight.js": "^11.11.1",
|
|
59
59
|
"mitt": "^3.0.1",
|
|
60
60
|
"vue3-highlightjs": "^1.0.5",
|
|
61
|
-
"
|
|
62
|
-
"effect-app": "4.0.0-beta.
|
|
61
|
+
"effect-app": "4.0.0-beta.152",
|
|
62
|
+
"@effect-app/vue": "4.0.0-beta.152"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"check": "vue-tsc",
|
|
@@ -923,12 +923,20 @@ export const useOmegaForm = <
|
|
|
923
923
|
})
|
|
924
924
|
}
|
|
925
925
|
|
|
926
|
+
const hs = form.handleSubmit
|
|
927
|
+
|
|
928
|
+
const handleSubmit: typeof form.handleSubmit = async (meta?: Record<string, any>) => {
|
|
929
|
+
// workaround for not revealing all form errors on submit
|
|
930
|
+
await form.validateAllFields("blur")
|
|
931
|
+
return await hs(meta)
|
|
932
|
+
}
|
|
933
|
+
|
|
926
934
|
const handleSubmitEffect_ = (meta?: Record<string, any>) =>
|
|
927
935
|
Effect.currentSpan.pipe(
|
|
928
936
|
Effect.option,
|
|
929
937
|
Effect
|
|
930
938
|
.flatMap((span) =>
|
|
931
|
-
Effect.promise(() =>
|
|
939
|
+
Effect.promise(() => handleSubmit(Option.isSome(span) ? { currentSpan: span.value, ...meta } : meta))
|
|
932
940
|
)
|
|
933
941
|
)
|
|
934
942
|
|
|
@@ -947,8 +955,6 @@ export const useOmegaForm = <
|
|
|
947
955
|
})))
|
|
948
956
|
: handleSubmitEffect_(options?.meta)
|
|
949
957
|
|
|
950
|
-
const handleSubmit = form.handleSubmit
|
|
951
|
-
|
|
952
958
|
const fieldMap = ref(new Map<string, { label: string; id: string }>())
|
|
953
959
|
|
|
954
960
|
const formWithExtras: OF<From, To> = Object.assign(form, {
|