@effect-app/vue-components 1.8.5 → 1.8.7
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.
- package/dist/types/components/OmegaForm/OmegaErrorsInternal.vue.d.ts +7 -5
- package/dist/vue-components.es12.js +10 -11
- package/dist/vue-components.es13.js +5 -10
- package/dist/vue-components.es14.js +54 -5
- package/dist/vue-components.es15.js +63 -49
- package/dist/vue-components.es16.js +6 -68
- package/dist/vue-components.es17.js +5 -5
- package/dist/vue-components.es18.js +3 -6
- package/dist/vue-components.es19.js +3 -3
- package/dist/vue-components.es20.js +2 -3
- package/dist/vue-components.es21.js +1 -1
- package/dist/vue-components.es22.js +17 -2
- package/dist/vue-components.es23.js +10 -16
- package/dist/vue-components.es27.js +1 -1
- package/dist/vue-components.es28.js +1 -1
- package/dist/vue-components.es29.js +48 -38
- package/dist/vue-components.es32.js +1 -1
- package/dist/vue-components.es35.js +10 -22
- package/dist/vue-components.es36.js +23 -5
- package/dist/vue-components.es37.js +5 -21
- package/dist/vue-components.es38.js +16 -25
- package/dist/vue-components.es39.js +23 -15
- package/dist/vue-components.es4.js +1 -1
- package/dist/vue-components.es40.js +17 -7
- package/dist/vue-components.es41.js +12 -5
- package/dist/vue-components.es42.js +5 -19
- package/dist/vue-components.es43.js +19 -9
- package/dist/vue-components.es44.js +9 -31
- package/dist/vue-components.es45.js +25 -42
- package/dist/vue-components.es46.js +38 -16
- package/dist/vue-components.es47.js +26 -11
- package/dist/vue-components.es48.js +1 -1
- package/dist/vue-components.es50.js +1 -1
- package/dist/vue-components.es52.js +3 -3
- package/dist/vue-components.es53.js +1 -1
- package/dist/vue-components.es6.js +13 -13
- package/dist/vue-components.es7.js +85 -95
- package/dist/vue-components.es8.js +2 -2
- package/package.json +1 -1
- package/src/components/OmegaForm/OmegaErrorsInternal.vue +24 -6
- package/src/components/OmegaForm/OmegaInternalInput.vue +4 -0
- package/src/components/OmegaForm/useOmegaForm.ts +10 -30
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(function(){"use strict";try{if(typeof document<"u"){var i=document.createElement("style");if(i.appendChild(document.createTextNode(".omega-input .v-input__details:has(.v-messages:empty){grid-template-rows:0fr;transition:all .2s}.omega-input .v-messages:empty{min-height:0}.omega-input .v-input__details:has(.v-messages){transition:all .2s;overflow:hidden;min-height:0;display:grid;grid-template-rows:1fr}.omega-input .v-messages{transition:all .2s}.omega-input .v-messages>*{transition-duration:0s!important}.omega-input [role=alert]:has(.v-messages:empty){padding:0}.omega-input .v-btn{cursor:pointer;width:auto;appearance:none;box-shadow:none;display:block;min-width:auto;height:auto;padding:.5em .5em .5em 1em}")),document.head.appendChild(i),window.customElements){const e=window.customElements.define;window.customElements.define=function(s,t){const n=t.prototype.connectedCallback;return t.prototype.connectedCallback=function(){if(n&&n.call(this),this.shadowRoot){const a=document.createElement("style");a.appendChild(document.createTextNode(".omega-input .v-input__details:has(.v-messages:empty){grid-template-rows:0fr;transition:all .2s}.omega-input .v-messages:empty{min-height:0}.omega-input .v-input__details:has(.v-messages){transition:all .2s;overflow:hidden;min-height:0;display:grid;grid-template-rows:1fr}.omega-input .v-messages{transition:all .2s}.omega-input .v-messages>*{transition-duration:0s!important}.omega-input [role=alert]:has(.v-messages:empty){padding:0}.omega-input .v-btn{cursor:pointer;width:auto;appearance:none;box-shadow:none;display:block;min-width:auto;height:auto;padding:.5em .5em .5em 1em}")),this.shadowRoot.appendChild(a)}},e.call(window.customElements,s,t)}}}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
|
|
2
|
-
import { defineComponent as b, getCurrentInstance as C, useId as x, computed as n, onMounted as P, renderSlot as _, normalizeProps as m, guardReactiveProps as $, createElementVNode as
|
|
3
|
-
import { useStore as
|
|
4
|
-
import
|
|
2
|
+
import { defineComponent as b, getCurrentInstance as C, useId as x, computed as n, onMounted as P, renderSlot as _, normalizeProps as m, guardReactiveProps as $, createElementVNode as M, normalizeClass as N, createBlock as V, createCommentVNode as k, unref as q, openBlock as B, mergeProps as F } from "vue";
|
|
3
|
+
import { useStore as I } from "@tanstack/vue-form";
|
|
4
|
+
import L from "./vue-components.es24.js";
|
|
5
5
|
|
|
6
6
|
const U = /* @__PURE__ */ b({
|
|
7
7
|
inheritAttrs: !1,
|
|
@@ -16,9 +16,9 @@ const U = /* @__PURE__ */ b({
|
|
|
16
16
|
options: {}
|
|
17
17
|
},
|
|
18
18
|
setup(u) {
|
|
19
|
-
const e = u, p = C()?.appContext.components.VTextField, i = x(), a = e.field,
|
|
19
|
+
const e = u, p = C()?.appContext.components.VTextField, i = x(), a = e.field, o = I(a.store, (t) => t), d = n(() => e.type ? e.type : e.meta?.type === "string" ? e.meta.format === "email" ? "email" : "string" : e.meta?.type || "unknown");
|
|
20
20
|
e.register(n(() => ({ name: e.field.name, label: e.label, id: i })));
|
|
21
|
-
const f = n(() =>
|
|
21
|
+
const f = n(() => o.value.value), c = n(() => o.value.meta.errors ?? []), s = n(
|
|
22
22
|
() => (
|
|
23
23
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
24
|
c.value.map((t) => t?.message).filter(Boolean)
|
|
@@ -26,22 +26,22 @@ const U = /* @__PURE__ */ b({
|
|
|
26
26
|
), g = (t) => t == null || t === !1 || t === "" || Number.isNaN(t), y = (t) => {
|
|
27
27
|
g(t) && e.meta?.type !== "boolean" ? e.field.handleChange(
|
|
28
28
|
e.meta?.nullableOrUndefined === "undefined" ? void 0 : null
|
|
29
|
-
) : e.field.handleChange(t);
|
|
29
|
+
) : e.field.handleChange(t), e.field.setMeta((r) => ({ ...r, errorMap: { ...r.errorMap, onSubmit: void 0 } }));
|
|
30
30
|
};
|
|
31
31
|
P(() => {
|
|
32
32
|
if (!f.value && !e.meta?.required && e.meta?.nullableOrUndefined === "null") {
|
|
33
|
-
const t =
|
|
33
|
+
const t = o.value.meta.isDirty;
|
|
34
34
|
a.setValue(null), a.setMeta((r) => ({ ...r, isDirty: t }));
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
const h = (t) => {
|
|
38
38
|
const r = {
|
|
39
|
-
get(
|
|
39
|
+
get(O, v, z) {
|
|
40
40
|
return v === "handleChange" ? y : Reflect.get(...arguments);
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
return new Proxy(t, r);
|
|
44
|
-
},
|
|
44
|
+
}, l = n(() => ({
|
|
45
45
|
inputProps: {
|
|
46
46
|
id: i,
|
|
47
47
|
required: e.meta?.required,
|
|
@@ -57,11 +57,11 @@ const U = /* @__PURE__ */ b({
|
|
|
57
57
|
},
|
|
58
58
|
field: h(e.field)
|
|
59
59
|
}));
|
|
60
|
-
return (t, r) => _(t.$slots, "default", m($({ ...t.$attrs, ...
|
|
61
|
-
|
|
62
|
-
class:
|
|
60
|
+
return (t, r) => _(t.$slots, "default", m($({ ...t.$attrs, ...l.value.inputProps, field: l.value.field })), () => [
|
|
61
|
+
M("div", {
|
|
62
|
+
class: N(t.$attrs.class)
|
|
63
63
|
}, [
|
|
64
|
-
|
|
64
|
+
q(p) ? (B(), V(L, m(F({ key: 0 }, { ...t.$attrs, ...l.value })), null, 16)) : k("", !0)
|
|
65
65
|
], 2)
|
|
66
66
|
]);
|
|
67
67
|
}
|
|
@@ -1,72 +1,71 @@
|
|
|
1
|
-
import { useForm as
|
|
2
|
-
import { Data as
|
|
3
|
-
import { runtimeFiberAsPromise as
|
|
4
|
-
import { isObject as
|
|
5
|
-
import { computed as
|
|
1
|
+
import { useForm as k } from "@tanstack/vue-form";
|
|
2
|
+
import { Data as B, S as L, Effect as l, Fiber as b, Option as G, Array as O } from "effect-app";
|
|
3
|
+
import { runtimeFiberAsPromise as T } from "./vue-components.es12.js";
|
|
4
|
+
import { isObject as W } from "./vue-components.es13.js";
|
|
5
|
+
import { computed as I, onUnmounted as U, onMounted as z, onBeforeUnmount as Q, ref as X, watch as $, h as N } from "vue";
|
|
6
6
|
import { usePreventClose as Y } from "./vue-components.es8.js";
|
|
7
|
-
import Z from "./vue-components.
|
|
8
|
-
import C from "./vue-components.
|
|
9
|
-
import ee from "./vue-components.
|
|
7
|
+
import Z from "./vue-components.es14.js";
|
|
8
|
+
import C from "./vue-components.es15.js";
|
|
9
|
+
import ee from "./vue-components.es16.js";
|
|
10
10
|
import { generateMetaFromSchema as re } from "./vue-components.es9.js";
|
|
11
11
|
import te from "./vue-components.es5.js";
|
|
12
|
-
import se from "./vue-components.
|
|
13
|
-
import { trace as
|
|
14
|
-
import { context as
|
|
15
|
-
class ne extends
|
|
12
|
+
import se from "./vue-components.es17.js";
|
|
13
|
+
import { trace as A } from "./vue-components.es18.js";
|
|
14
|
+
import { context as y } from "./vue-components.es19.js";
|
|
15
|
+
class ne extends B.TaggedError("FormErrors") {
|
|
16
16
|
}
|
|
17
|
-
const
|
|
17
|
+
const p = (c) => function(i) {
|
|
18
18
|
return {
|
|
19
19
|
render() {
|
|
20
|
-
return
|
|
20
|
+
return N(i, {
|
|
21
21
|
form: c,
|
|
22
22
|
...this.$attrs
|
|
23
23
|
}, this.$slots);
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
},
|
|
26
|
+
}, ie = (c) => function(i) {
|
|
27
27
|
return {
|
|
28
28
|
setup() {
|
|
29
29
|
return {
|
|
30
30
|
...c
|
|
31
31
|
};
|
|
32
32
|
},
|
|
33
|
-
render({
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
showErrors: v,
|
|
33
|
+
render({ fieldMap: h, form: S }) {
|
|
34
|
+
return N(i, {
|
|
35
|
+
form: S,
|
|
36
|
+
fieldMap: h,
|
|
38
37
|
...this.$attrs
|
|
39
38
|
}, this.$slots);
|
|
40
39
|
}
|
|
41
40
|
};
|
|
42
|
-
}, ye = (c, a,
|
|
41
|
+
}, ye = (c, a, i) => {
|
|
43
42
|
if (!c) throw new Error("Schema is required");
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
return
|
|
47
|
-
const e = window.location.pathname, r = Object.keys(
|
|
43
|
+
const h = L.standardSchemaV1(c), S = L.decode(c), { filterItems: _, meta: d } = re(c), m = I(() => {
|
|
44
|
+
if (i?.persistency?.id)
|
|
45
|
+
return i.persistency.id;
|
|
46
|
+
const e = window.location.pathname, r = Object.keys(d);
|
|
48
47
|
return `${e}-${r.join("-")}`;
|
|
49
|
-
}),
|
|
48
|
+
}), D = () => {
|
|
50
49
|
const e = new URLSearchParams(window.location.search);
|
|
51
50
|
e.delete(m.value);
|
|
52
51
|
const r = new URL(window.location.href);
|
|
53
52
|
r.search = e.toString(), window.history.replaceState({}, "", r.toString());
|
|
54
53
|
};
|
|
55
|
-
function
|
|
54
|
+
function g(e, r) {
|
|
56
55
|
for (const t in r)
|
|
57
|
-
r[t] &&
|
|
56
|
+
r[t] && W(r[t]) ? (e[t] || (e[t] = {}), g(e[t], r[t])) : e[t] = r[t];
|
|
58
57
|
return e;
|
|
59
58
|
}
|
|
60
|
-
const
|
|
61
|
-
if (a?.defaultValues && !
|
|
59
|
+
const R = I(() => {
|
|
60
|
+
if (a?.defaultValues && !i?.persistency?.overrideDefaultValues)
|
|
62
61
|
return a?.defaultValues;
|
|
63
62
|
let e;
|
|
64
|
-
const r =
|
|
63
|
+
const r = i?.persistency;
|
|
65
64
|
if (!r?.policies || r.policies.length === 0) return {};
|
|
66
65
|
if (r.policies.includes("querystring"))
|
|
67
66
|
try {
|
|
68
67
|
const s = new URLSearchParams(window.location.search).get(m.value);
|
|
69
|
-
|
|
68
|
+
D(), s && (e = JSON.parse(s));
|
|
70
69
|
} catch (t) {
|
|
71
70
|
console.error(t);
|
|
72
71
|
}
|
|
@@ -89,113 +88,104 @@ const h = (c) => function(o) {
|
|
|
89
88
|
return e;
|
|
90
89
|
{
|
|
91
90
|
const t = a?.defaultValues;
|
|
92
|
-
return
|
|
91
|
+
return g(t, e);
|
|
93
92
|
}
|
|
94
|
-
}),
|
|
93
|
+
}), x = (e, r) => e ? y.with(A.setSpan(y.active(), e), r) : r(), u = k({
|
|
95
94
|
...a,
|
|
96
95
|
validators: {
|
|
97
|
-
onSubmit:
|
|
96
|
+
onSubmit: h,
|
|
98
97
|
...a?.validators || {}
|
|
99
98
|
},
|
|
100
|
-
onSubmit: a?.onSubmit ? ({ formApi: e, meta: r, value: t }) =>
|
|
101
|
-
const s = await l.runPromise(
|
|
99
|
+
onSubmit: a?.onSubmit ? ({ formApi: e, meta: r, value: t }) => x(r?.currentSpan, async () => {
|
|
100
|
+
const s = await l.runPromise(S(t)), n = a.onSubmit({
|
|
102
101
|
formApi: e,
|
|
103
102
|
meta: r,
|
|
104
103
|
value: s
|
|
105
104
|
});
|
|
106
|
-
return
|
|
105
|
+
return b.isFiber(n) && b.isRuntimeFiber(n) ? await T(n) : l.isEffect(n) ? await l.runPromise(
|
|
107
106
|
n.pipe(
|
|
108
107
|
// meta?.currentSpan
|
|
109
108
|
// ? Effect.withParentSpan(meta.currentSpan)
|
|
110
109
|
// : (_) => _,
|
|
111
|
-
l.flatMap((
|
|
110
|
+
l.flatMap((f) => b.join(f))
|
|
112
111
|
)
|
|
113
112
|
) : n;
|
|
114
113
|
}) : void 0,
|
|
115
|
-
defaultValues:
|
|
116
|
-
}),
|
|
117
|
-
Object.keys(
|
|
114
|
+
defaultValues: R.value
|
|
115
|
+
}), H = () => {
|
|
116
|
+
Object.keys(d).forEach((e) => {
|
|
118
117
|
u.setFieldValue(e, void 0);
|
|
119
118
|
});
|
|
120
|
-
},
|
|
119
|
+
}, E = (e) => e.reduce((r, t) => {
|
|
121
120
|
const s = t.split(".");
|
|
122
|
-
return s.reduce((n,
|
|
123
|
-
}, {}),
|
|
121
|
+
return s.reduce((n, f, K) => (K === s.length - 1 ? n[f] = u.getFieldValue(t) : n[f] = n[f] ?? {}, n[f]), r), r;
|
|
122
|
+
}, {}), F = (e) => {
|
|
124
123
|
if (e) {
|
|
125
|
-
if (
|
|
126
|
-
return
|
|
127
|
-
if (
|
|
128
|
-
const r = Object.keys(
|
|
129
|
-
return
|
|
124
|
+
if (O.isArray(e.keys))
|
|
125
|
+
return E(e.keys);
|
|
126
|
+
if (O.isArray(e.banKeys)) {
|
|
127
|
+
const r = Object.keys(d).filter((t) => e.banKeys?.includes(t));
|
|
128
|
+
return E(r);
|
|
130
129
|
}
|
|
131
130
|
return u.store.state.values;
|
|
132
131
|
}
|
|
133
|
-
},
|
|
134
|
-
const e =
|
|
132
|
+
}, v = () => {
|
|
133
|
+
const e = i?.persistency;
|
|
135
134
|
if (!(!e?.policies || e.policies.length === 0) && (e.policies.includes("local") || e.policies.includes("session"))) {
|
|
136
135
|
const r = e.policies.includes("local") ? localStorage : sessionStorage;
|
|
137
136
|
if (!r) return;
|
|
138
|
-
const t =
|
|
137
|
+
const t = F(e);
|
|
139
138
|
return r.setItem(m.value, JSON.stringify(t));
|
|
140
139
|
}
|
|
141
|
-
},
|
|
142
|
-
const e =
|
|
140
|
+
}, V = () => {
|
|
141
|
+
const e = i?.persistency;
|
|
143
142
|
if (!(!e?.policies || e.policies.length === 0) && e.policies.includes("querystring")) {
|
|
144
|
-
const r =
|
|
143
|
+
const r = F(e), t = new URLSearchParams(window.location.search);
|
|
145
144
|
t.set(m.value, JSON.stringify(r));
|
|
146
145
|
const s = new URL(window.location.href);
|
|
147
146
|
s.search = t.toString(), window.history.replaceState({}, "", s.toString());
|
|
148
147
|
}
|
|
149
148
|
};
|
|
150
|
-
|
|
151
|
-
window.addEventListener("beforeunload",
|
|
152
|
-
}),
|
|
153
|
-
window.removeEventListener("beforeunload",
|
|
149
|
+
U(v), z(() => {
|
|
150
|
+
window.addEventListener("beforeunload", v), window.addEventListener("blur", V);
|
|
151
|
+
}), Q(() => {
|
|
152
|
+
window.removeEventListener("beforeunload", v), window.removeEventListener("blur", V);
|
|
154
153
|
});
|
|
155
|
-
const
|
|
154
|
+
const j = (e) => l.currentSpan.pipe(
|
|
156
155
|
l.option,
|
|
157
156
|
l.flatMap(
|
|
158
|
-
(r) => l.promise(() => u.handleSubmit(
|
|
157
|
+
(r) => l.promise(() => u.handleSubmit(G.isSome(r) ? { currentSpan: r.value, ...e } : e))
|
|
159
158
|
)
|
|
160
|
-
),
|
|
159
|
+
), J = (e) => e?.checkErrors ? j(e?.meta).pipe(l.flatMap(l.fnUntraced(function* () {
|
|
161
160
|
const r = u.getAllErrors();
|
|
162
161
|
if (Object.keys(r.fields).length || r.form.errors.length)
|
|
163
162
|
return yield* new ne({ form: r.form, fields: r.fields });
|
|
164
|
-
}))) :
|
|
165
|
-
i18nNamespace:
|
|
166
|
-
meta:
|
|
167
|
-
filterItems:
|
|
168
|
-
clear:
|
|
163
|
+
}))) : j(e?.meta), q = u.handleSubmit, w = X(/* @__PURE__ */ new Map()), o = Object.assign(u, {
|
|
164
|
+
i18nNamespace: i?.i18nNamespace,
|
|
165
|
+
meta: d,
|
|
166
|
+
filterItems: _,
|
|
167
|
+
clear: H,
|
|
169
168
|
handleSubmit: (e) => {
|
|
170
|
-
const r =
|
|
171
|
-
return
|
|
169
|
+
const r = A.getSpan(y.active());
|
|
170
|
+
return q({ currentSpan: r, ...e });
|
|
172
171
|
},
|
|
173
172
|
// /** @experimental */
|
|
174
|
-
handleSubmitEffect:
|
|
173
|
+
handleSubmitEffect: J,
|
|
175
174
|
registerField: (e) => {
|
|
176
|
-
|
|
175
|
+
$(e, (r) => w.value.set(r.name, { label: r.label, id: r.id }), { immediate: !0 }), U(() => w.value.delete(e.value.name));
|
|
177
176
|
}
|
|
178
|
-
}),
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
([r, t]) => (t.errors ?? []).length && f.get(r)?.id ? E.some({
|
|
182
|
-
label: f.get(r).label,
|
|
183
|
-
inputId: f.get(r).id,
|
|
184
|
-
errors: (t.errors ?? []).map((s) => s.message).filter(Boolean)
|
|
185
|
-
}) : E.none()
|
|
186
|
-
)
|
|
187
|
-
);
|
|
188
|
-
N(
|
|
189
|
-
() => [i.filterItems, y.value],
|
|
177
|
+
}), M = o.useStore((e) => e.errors);
|
|
178
|
+
$(
|
|
179
|
+
() => [o.filterItems, M.value],
|
|
190
180
|
() => {
|
|
191
|
-
const e =
|
|
181
|
+
const e = o.filterItems, r = M.value;
|
|
192
182
|
return e ? r ? (Object.values(r).filter(
|
|
193
183
|
(s) => !!s
|
|
194
184
|
).flatMap(
|
|
195
185
|
(s) => Object.values(s).flat().map((n) => n.message)
|
|
196
186
|
).some((s) => s === e.message) && e.items.forEach((s) => {
|
|
197
|
-
const n =
|
|
198
|
-
n &&
|
|
187
|
+
const n = o.getFieldMeta(s);
|
|
188
|
+
n && o.setFieldMeta(s, {
|
|
199
189
|
...n,
|
|
200
190
|
errorMap: {
|
|
201
191
|
onSubmit: [
|
|
@@ -206,15 +196,15 @@ const h = (c) => function(o) {
|
|
|
206
196
|
}), {}) : {} : {};
|
|
207
197
|
}
|
|
208
198
|
);
|
|
209
|
-
const
|
|
210
|
-
return
|
|
211
|
-
errorContext:
|
|
212
|
-
Form:
|
|
213
|
-
Input:
|
|
199
|
+
const P = { form: o, fieldMap: w };
|
|
200
|
+
return i?.ignorePreventCloseEvents || Y(() => o.useStore((e) => e.isDirty)), Object.assign(o, {
|
|
201
|
+
errorContext: P,
|
|
202
|
+
Form: p(o)(se),
|
|
203
|
+
Input: p(o)(i?.input ?? te),
|
|
214
204
|
Field: u.Field,
|
|
215
|
-
Errors:
|
|
216
|
-
Array:
|
|
217
|
-
AutoGen:
|
|
205
|
+
Errors: ie(P)(ee),
|
|
206
|
+
Array: p(o)(Z),
|
|
207
|
+
AutoGen: p(o)(C)
|
|
218
208
|
});
|
|
219
209
|
};
|
|
220
210
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import r from "./vue-components.
|
|
1
|
+
import r from "./vue-components.es22.js";
|
|
2
2
|
import { inject as c, provide as l } from "vue";
|
|
3
|
-
import { onMountedWithCleanup as u } from "./vue-components.
|
|
3
|
+
import { onMountedWithCleanup as u } from "./vue-components.es23.js";
|
|
4
4
|
const f = () => r(), i = Symbol("DialogBus"), p = () => c(i, null), g = () => {
|
|
5
5
|
const e = f();
|
|
6
6
|
return l(i, e), e;
|
package/package.json
CHANGED
|
@@ -74,27 +74,45 @@
|
|
|
74
74
|
<script setup lang="ts">
|
|
75
75
|
import { mdiLink } from "@mdi/js"
|
|
76
76
|
import type { StandardSchemaV1Issue } from "@tanstack/vue-form"
|
|
77
|
+
import { Array as Array$, Option } from "effect-app"
|
|
77
78
|
import { computed, getCurrentInstance } from "vue"
|
|
78
79
|
import { useIntl } from "../../utils"
|
|
79
|
-
import { type OmegaError } from "./OmegaFormStuff"
|
|
80
|
+
import { type OmegaError, type OmegaFormApi } from "./OmegaFormStuff"
|
|
80
81
|
|
|
81
82
|
const instance = getCurrentInstance()
|
|
82
83
|
const vuetified = instance?.appContext.components["VAlert"]
|
|
83
84
|
|
|
84
85
|
const props = defineProps<
|
|
85
86
|
{
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
form: OmegaFormApi<any, any>
|
|
88
|
+
fieldMap: Map<string, { id: string; label: string }>
|
|
88
89
|
}
|
|
89
90
|
>()
|
|
90
91
|
|
|
92
|
+
const generalErrors = props.form.useStore((state) => state.errors)
|
|
93
|
+
const fieldMeta = props.form.useStore((state) => state.fieldMeta)
|
|
94
|
+
const errors = computed(() =>
|
|
95
|
+
Array$.filterMap(
|
|
96
|
+
Object
|
|
97
|
+
.entries(fieldMeta.value),
|
|
98
|
+
([key, m]): Option.Option<OmegaError> =>
|
|
99
|
+
((m as any).errors ?? []).length && props.fieldMap.get(key)?.id
|
|
100
|
+
? Option.some({
|
|
101
|
+
label: props.fieldMap.get(key)!.label,
|
|
102
|
+
inputId: props.fieldMap.get(key)!.id,
|
|
103
|
+
errors: ((m as any).errors ?? []).map((e: any) => e.message).filter(Boolean)
|
|
104
|
+
})
|
|
105
|
+
: Option.none()
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
|
|
91
109
|
const { trans } = useIntl()
|
|
92
110
|
|
|
93
111
|
const showedGeneralErrors = computed(() => {
|
|
94
|
-
if (!
|
|
112
|
+
if (!generalErrors.value) return []
|
|
95
113
|
|
|
96
|
-
return
|
|
97
|
-
.
|
|
114
|
+
return generalErrors
|
|
115
|
+
.value
|
|
98
116
|
.filter((record): record is Record<string, StandardSchemaV1Issue[]> => Boolean(record))
|
|
99
117
|
.flatMap((errorRecord) =>
|
|
100
118
|
Object
|
|
@@ -88,6 +88,10 @@ const handleChange: OmegaFieldInternalApi<From, Name>["handleChange"] = (value)
|
|
|
88
88
|
} else {
|
|
89
89
|
props.field.handleChange(value)
|
|
90
90
|
}
|
|
91
|
+
|
|
92
|
+
// whenever we change the field, regardless if we set it to null, we should reset onSubmit.
|
|
93
|
+
// not sure why this is not the case in tanstack form.
|
|
94
|
+
props.field.setMeta((m) => ({ ...m, errorMap: { ...m.errorMap, onSubmit: undefined } }))
|
|
91
95
|
}
|
|
92
96
|
|
|
93
97
|
// TODO: it would be cleaner when default values are handled in the form initialization via Schema or by the one using the form component..
|
|
@@ -6,7 +6,7 @@ import { type DeepKeys, DeepValue, type FormAsyncValidateOrFn, type FormValidate
|
|
|
6
6
|
import { Array, Data, Effect, Fiber, Option, Order, S } from "effect-app"
|
|
7
7
|
import { runtimeFiberAsPromise } from "effect-app/utils"
|
|
8
8
|
import { isObject } from "effect/Predicate"
|
|
9
|
-
import { Component, computed, ComputedRef, ConcreteComponent, h, type InjectionKey, onBeforeUnmount, onMounted, onUnmounted, Ref, watch } from "vue"
|
|
9
|
+
import { Component, computed, ComputedRef, ConcreteComponent, h, type InjectionKey, onBeforeUnmount, onMounted, onUnmounted, Ref, ref, watch } from "vue"
|
|
10
10
|
import { usePreventClose } from "./blockDialog"
|
|
11
11
|
import { MergedInputProps } from "./InputProps"
|
|
12
12
|
import OmegaArray from "./OmegaArray.vue"
|
|
@@ -65,13 +65,8 @@ const fHoc = (form: OF<any, any>) => {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
const eHoc = (errorProps: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
(Record<string, StandardSchemaV1Issue[]> | undefined)[],
|
|
71
|
-
(Record<string, StandardSchemaV1Issue[]> | undefined)[]
|
|
72
|
-
>
|
|
73
|
-
>
|
|
74
|
-
errors: Readonly<Ref<(OmegaError | undefined)[], (OmegaError | undefined)[]>>
|
|
68
|
+
form: OF<any, any>
|
|
69
|
+
fieldMap: Ref<Map<string, { id: string; label: string }>>
|
|
75
70
|
}) => {
|
|
76
71
|
return function FormHoc<P>(
|
|
77
72
|
WrappedComponent: Component<P>
|
|
@@ -82,11 +77,10 @@ const eHoc = (errorProps: {
|
|
|
82
77
|
...errorProps
|
|
83
78
|
}
|
|
84
79
|
},
|
|
85
|
-
render({
|
|
80
|
+
render({ fieldMap, form }: any) {
|
|
86
81
|
return h(WrappedComponent, {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
showErrors,
|
|
82
|
+
form,
|
|
83
|
+
fieldMap,
|
|
90
84
|
...this.$attrs
|
|
91
85
|
} as any, this.$slots)
|
|
92
86
|
}
|
|
@@ -863,7 +857,7 @@ export const useOmegaForm = <
|
|
|
863
857
|
|
|
864
858
|
const handleSubmit = form.handleSubmit
|
|
865
859
|
|
|
866
|
-
const fieldMap = new Map<string, { label: string; id: string }>()
|
|
860
|
+
const fieldMap = ref(new Map<string, { label: string; id: string }>())
|
|
867
861
|
|
|
868
862
|
const formWithExtras: OF<From, To> = Object.assign(form, {
|
|
869
863
|
i18nNamespace: omegaConfig?.i18nNamespace,
|
|
@@ -877,26 +871,12 @@ export const useOmegaForm = <
|
|
|
877
871
|
// /** @experimental */
|
|
878
872
|
handleSubmitEffect,
|
|
879
873
|
registerField: (field: ComputedRef<{ name: string; label: string; id: string }>) => {
|
|
880
|
-
watch(field, (f) => fieldMap.set(f.name, { label: f.label, id: f.id }), { immediate: true })
|
|
881
|
-
onUnmounted(() => fieldMap.delete(field.value.name)) // todo; perhap only when owned (id match)
|
|
874
|
+
watch(field, (f) => fieldMap.value.set(f.name, { label: f.label, id: f.id }), { immediate: true })
|
|
875
|
+
onUnmounted(() => fieldMap.value.delete(field.value.name)) // todo; perhap only when owned (id match)
|
|
882
876
|
}
|
|
883
877
|
})
|
|
884
878
|
|
|
885
879
|
const errors = formWithExtras.useStore((state) => state.errors)
|
|
886
|
-
const fieldErrors = formWithExtras.useStore((state) =>
|
|
887
|
-
Array.filterMap(
|
|
888
|
-
Object
|
|
889
|
-
.entries(state.fieldMeta),
|
|
890
|
-
([key, m]): Option.Option<OmegaError> =>
|
|
891
|
-
((m as any).errors ?? []).length && fieldMap.get(key)?.id
|
|
892
|
-
? Option.some({
|
|
893
|
-
label: fieldMap.get(key)!.label,
|
|
894
|
-
inputId: fieldMap.get(key)!.id,
|
|
895
|
-
errors: ((m as any).errors ?? []).map((e: any) => e.message).filter(Boolean)
|
|
896
|
-
})
|
|
897
|
-
: Option.none()
|
|
898
|
-
)
|
|
899
|
-
)
|
|
900
880
|
|
|
901
881
|
watch(
|
|
902
882
|
() => [formWithExtras.filterItems, errors.value],
|
|
@@ -937,7 +917,7 @@ export const useOmegaForm = <
|
|
|
937
917
|
}
|
|
938
918
|
)
|
|
939
919
|
|
|
940
|
-
const errorContext = {
|
|
920
|
+
const errorContext = { form: formWithExtras, fieldMap }
|
|
941
921
|
|
|
942
922
|
if (!omegaConfig?.ignorePreventCloseEvents) {
|
|
943
923
|
usePreventClose(() => formWithExtras.useStore((state) => state.isDirty))
|