@effect-app/vue-components 1.8.6 → 1.8.8
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/types/components/OmegaForm/OmegaFormStuff.d.ts +0 -1
- package/dist/types/components/OmegaForm/useOmegaForm.d.ts +1 -2
- package/dist/vue-components.es16.js +2 -2
- package/dist/vue-components.es29.js +48 -38
- package/dist/vue-components.es7.js +102 -135
- package/dist/vue-components.es9.js +113 -126
- package/package.json +1 -1
- package/src/components/OmegaForm/OmegaErrorsInternal.vue +24 -6
- package/src/components/OmegaForm/OmegaFormStuff.ts +2 -19
- package/src/components/OmegaForm/useOmegaForm.ts +12 -75
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type OmegaError } from "./OmegaFormStuff";
|
|
1
|
+
import { type OmegaError, type OmegaFormApi } from "./OmegaFormStuff";
|
|
3
2
|
type __VLS_Props = {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
form: OmegaFormApi<any, any>;
|
|
4
|
+
fieldMap: Map<string, {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
}>;
|
|
6
8
|
};
|
|
7
9
|
declare var __VLS_6: {
|
|
8
|
-
errors:
|
|
10
|
+
errors: OmegaError[];
|
|
9
11
|
showedGeneralErrors: string[];
|
|
10
12
|
};
|
|
11
13
|
type __VLS_Slots = {} & {
|
|
@@ -120,7 +120,6 @@ export declare const duplicateSchema: <From, To>(schema: S.Schema<To, From, neve
|
|
|
120
120
|
export declare const generateMetaFromSchema: <From, To>(schema: S.Schema<To, From, never>) => {
|
|
121
121
|
schema: S.Schema<To, From, never>;
|
|
122
122
|
meta: MetaRecord<To>;
|
|
123
|
-
filterItems?: FilterItems;
|
|
124
123
|
};
|
|
125
124
|
export declare const generateInputStandardSchemaFromFieldMeta: (meta: FieldMeta) => StandardSchemaV1<any, any>;
|
|
126
125
|
export declare const nullableInput: <A, I, R>(schema: S.Schema<A, I, R>, defaultValue: () => A) => S.transform<import("effect/Schema").NullOr<S.Schema<A, I, R>> & {
|
|
@@ -2,7 +2,7 @@ import { type DeepKeys, DeepValue, StandardSchemaV1Issue, ValidationError, Valid
|
|
|
2
2
|
import { Effect, Order, S } from "effect-app";
|
|
3
3
|
import { ComputedRef, type InjectionKey } from "vue";
|
|
4
4
|
import { MergedInputProps } from "./InputProps";
|
|
5
|
-
import { BaseProps, DefaultTypeProps, type
|
|
5
|
+
import { BaseProps, DefaultTypeProps, type FormProps, type MetaRecord, type NestedKeyOf, OmegaAutoGenMeta, OmegaError, type OmegaFormApi, OmegaFormState, OmegaInputProps, ShowErrorsOn } from "./OmegaFormStuff";
|
|
6
6
|
type keysRule<T> = {
|
|
7
7
|
keys?: NestedKeyOf<T>[];
|
|
8
8
|
banKeys?: "You should only use one of banKeys or keys, not both, moron";
|
|
@@ -41,7 +41,6 @@ export type OmegaConfig<T> = {
|
|
|
41
41
|
};
|
|
42
42
|
export interface OF<From, To> extends OmegaFormApi<From, To> {
|
|
43
43
|
meta: MetaRecord<From>;
|
|
44
|
-
filterItems?: FilterItems;
|
|
45
44
|
clear: () => void;
|
|
46
45
|
i18nNamespace?: string;
|
|
47
46
|
registerField: (field: ComputedRef<{
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(){"use strict";try{if(typeof document<"u"){var a=document.createElement("style");if(a.appendChild(document.createTextNode(".v-enter-from[data-v-
|
|
1
|
+
(function(){"use strict";try{if(typeof document<"u"){var a=document.createElement("style");if(a.appendChild(document.createTextNode(".v-enter-from[data-v-6dbb0b00],.v-leave-to[data-v-6dbb0b00]{max-height:0px;grid-template-rows:0fr;opacity:0}.v-enter-active[data-v-6dbb0b00],.v-leave-active[data-v-6dbb0b00]{display:grid;transition:all .15s}.v-enter-to[data-v-6dbb0b00],.v-leave-from[data-v-6dbb0b00]{grid-template-rows:1fr;max-height:50vh;opacity:1}.error-alert[data-v-6dbb0b00]{transition-behavior:allow-discrete;display:grid;overflow:hidden;min-height:0}.error-alert>*[data-v-6dbb0b00]{min-height:0}.error-list[data-v-6dbb0b00]{list-style-position:inside}div.error-list[data-v-6dbb0b00]{container-type:inline-size;display:grid;grid-template-columns:auto 1fr auto;gap:1.5em;align-items:start}@container (max-width: 27.125rem){div.error-list[data-v-6dbb0b00]{grid-template-columns:auto 1fr}.error-link[data-v-6dbb0b00]{grid-column:1 / -1;justify-self:end}}@container (max-width: 17.75rem){div.error-list[data-v-6dbb0b00]{grid-template-columns:1fr}.error-message[data-v-6dbb0b00]{grid-column:1 / -1}}.error-item[data-v-6dbb0b00]{display:contents}a[data-v-6dbb0b00]{min-width:min-content}.error-link[data-v-6dbb0b00]{align-items:center;color:inherit;display:inline-flex;flex-wrap:wrap;gap:.25em;padding-bottom:1em;text-decoration:none}")),document.head.appendChild(a),window.customElements){const e=window.customElements.define;window.customElements.define=function(r,t){const i=t.prototype.connectedCallback;return t.prototype.connectedCallback=function(){if(i&&i.call(this),this.shadowRoot){const d=document.createElement("style");d.appendChild(document.createTextNode(".v-enter-from[data-v-6dbb0b00],.v-leave-to[data-v-6dbb0b00]{max-height:0px;grid-template-rows:0fr;opacity:0}.v-enter-active[data-v-6dbb0b00],.v-leave-active[data-v-6dbb0b00]{display:grid;transition:all .15s}.v-enter-to[data-v-6dbb0b00],.v-leave-from[data-v-6dbb0b00]{grid-template-rows:1fr;max-height:50vh;opacity:1}.error-alert[data-v-6dbb0b00]{transition-behavior:allow-discrete;display:grid;overflow:hidden;min-height:0}.error-alert>*[data-v-6dbb0b00]{min-height:0}.error-list[data-v-6dbb0b00]{list-style-position:inside}div.error-list[data-v-6dbb0b00]{container-type:inline-size;display:grid;grid-template-columns:auto 1fr auto;gap:1.5em;align-items:start}@container (max-width: 27.125rem){div.error-list[data-v-6dbb0b00]{grid-template-columns:auto 1fr}.error-link[data-v-6dbb0b00]{grid-column:1 / -1;justify-self:end}}@container (max-width: 17.75rem){div.error-list[data-v-6dbb0b00]{grid-template-columns:1fr}.error-message[data-v-6dbb0b00]{grid-column:1 / -1}}.error-item[data-v-6dbb0b00]{display:contents}a[data-v-6dbb0b00]{min-width:min-content}.error-link[data-v-6dbb0b00]{align-items:center;color:inherit;display:inline-flex;flex-wrap:wrap;gap:.25em;padding-bottom:1em;text-decoration:none}")),this.shadowRoot.appendChild(d)}},e.call(window.customElements,r,t)}}}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
|
|
2
2
|
import r from "./vue-components.es29.js";
|
|
3
3
|
|
|
4
4
|
import o from "./vue-components.es31.js";
|
|
5
|
-
const e = /* @__PURE__ */ o(r, [["__scopeId", "data-v-
|
|
5
|
+
const e = /* @__PURE__ */ o(r, [["__scopeId", "data-v-6dbb0b00"]]);
|
|
6
6
|
export {
|
|
7
7
|
e as default
|
|
8
8
|
};
|
|
@@ -1,53 +1,63 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { mdiLink as
|
|
3
|
-
import {
|
|
1
|
+
import { defineComponent as x, getCurrentInstance as E, computed as h, createBlock as o, openBlock as t, Transition as I, withCtx as a, createElementBlock as m, createCommentVNode as w, renderSlot as O, normalizeProps as S, guardReactiveProps as V, resolveDynamicComponent as s, unref as i, normalizeClass as N, createElementVNode as d, toDisplayString as c, Fragment as M, renderList as b, createTextVNode as k } from "vue";
|
|
2
|
+
import { mdiLink as j } from "@mdi/js";
|
|
3
|
+
import { Array as z, Option as y } from "effect-app";
|
|
4
|
+
import { useIntl as A } from "./vue-components.es3.js";
|
|
4
5
|
const D = {
|
|
5
6
|
key: 0,
|
|
6
7
|
class: "error-alert"
|
|
7
|
-
}, G = { class: "text-h6 mb-3" }, L = { class: "font-weight-medium" },
|
|
8
|
+
}, G = { class: "text-h6 mb-3" }, L = { class: "font-weight-medium" }, P = { class: "error-message" }, T = ["href"], $ = { key: 1 }, K = /* @__PURE__ */ x({
|
|
8
9
|
__name: "OmegaErrorsInternal",
|
|
9
10
|
props: {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
form: {},
|
|
12
|
+
fieldMap: {}
|
|
12
13
|
},
|
|
13
|
-
setup(
|
|
14
|
-
const
|
|
15
|
-
(
|
|
14
|
+
setup(B) {
|
|
15
|
+
const f = E()?.appContext.components.VAlert, u = B, v = u.form.useStore((e) => e.errors), C = u.form.useStore((e) => e.fieldMeta), n = h(
|
|
16
|
+
() => z.filterMap(
|
|
17
|
+
Object.entries(C.value),
|
|
18
|
+
([e, l]) => (l.errors ?? []).length && u.fieldMap.get(e)?.id ? y.some({
|
|
19
|
+
label: u.fieldMap.get(e).label,
|
|
20
|
+
inputId: u.fieldMap.get(e).id,
|
|
21
|
+
errors: (l.errors ?? []).map((r) => r.message).filter(Boolean)
|
|
22
|
+
}) : y.none()
|
|
23
|
+
)
|
|
24
|
+
), { trans: _ } = A(), p = h(() => v.value ? v.value.filter((e) => !!e).flatMap(
|
|
25
|
+
(e) => Object.values(e).filter((l) => !!l).flatMap(
|
|
16
26
|
(l) => l.filter(
|
|
17
27
|
(r) => !!r?.message
|
|
18
28
|
).map((r) => r.message)
|
|
19
29
|
)
|
|
20
30
|
) : []);
|
|
21
|
-
return (
|
|
22
|
-
default:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(
|
|
26
|
-
class:
|
|
31
|
+
return (e, l) => (t(), o(I, null, {
|
|
32
|
+
default: a(() => [
|
|
33
|
+
n.value.length || p.value.length ? (t(), m("div", D, [
|
|
34
|
+
O(e.$slots, "default", S(V({ errors: n.value, showedGeneralErrors: p.value })), () => [
|
|
35
|
+
(t(), o(s(i(f) ? "v-alert" : "div"), {
|
|
36
|
+
class: N([i(f) ? "mb-4" : "error-alert-content", "mb-4"]),
|
|
27
37
|
type: "error",
|
|
28
38
|
variant: "tonal",
|
|
29
39
|
role: "alert",
|
|
30
40
|
"aria-live": "polite"
|
|
31
41
|
}, {
|
|
32
|
-
default:
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
default: a(() => [
|
|
43
|
+
d("div", G, c(i(_)("form.includes_error")) + ": ", 1),
|
|
44
|
+
n.value.length ? (t(), o(s(n.value.length > 1 ? "ul" : "div"), {
|
|
35
45
|
key: 0,
|
|
36
46
|
class: "error-list"
|
|
37
47
|
}, {
|
|
38
|
-
default:
|
|
39
|
-
(
|
|
48
|
+
default: a(() => [
|
|
49
|
+
(t(!0), m(M, null, b(n.value, (r) => (t(), o(s(n.value.length > 1 ? "li" : "div"), {
|
|
40
50
|
key: r.inputId,
|
|
41
51
|
class: "error-item"
|
|
42
52
|
}, {
|
|
43
|
-
default:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
(
|
|
47
|
-
default:
|
|
48
|
-
(
|
|
49
|
-
default:
|
|
50
|
-
k(
|
|
53
|
+
default: a(() => [
|
|
54
|
+
d("div", L, c(r.label), 1),
|
|
55
|
+
d("div", P, [
|
|
56
|
+
(t(), o(s(r.errors.length > 1 ? "ul" : "div"), { class: "error-list" }, {
|
|
57
|
+
default: a(() => [
|
|
58
|
+
(t(!0), m(M, null, b(r.errors, (g) => (t(), o(s(r.errors.length > 1 ? "li" : "span"), { key: g }, {
|
|
59
|
+
default: a(() => [
|
|
60
|
+
k(c(g), 1)
|
|
51
61
|
]),
|
|
52
62
|
_: 2
|
|
53
63
|
}, 1024))), 128))
|
|
@@ -55,37 +65,37 @@ const D = {
|
|
|
55
65
|
_: 2
|
|
56
66
|
}, 1024))
|
|
57
67
|
]),
|
|
58
|
-
|
|
68
|
+
d("a", {
|
|
59
69
|
href: `#${r.inputId}`,
|
|
60
70
|
class: "error-link"
|
|
61
71
|
}, [
|
|
62
|
-
(
|
|
63
|
-
icon:
|
|
72
|
+
(t(), o(s(i(f) ? "v-icon" : "i"), {
|
|
73
|
+
icon: i(j),
|
|
64
74
|
"aria-hidden": "true"
|
|
65
75
|
}, {
|
|
66
|
-
default:
|
|
67
|
-
|
|
76
|
+
default: a(() => [...l[0] || (l[0] = [
|
|
77
|
+
d("i", null, "🔗", -1)
|
|
68
78
|
])]),
|
|
69
79
|
_: 1
|
|
70
80
|
}, 8, ["icon"])),
|
|
71
|
-
k(" " +
|
|
72
|
-
], 8,
|
|
81
|
+
k(" " + c(i(_)("form.fix_input")), 1)
|
|
82
|
+
], 8, T)
|
|
73
83
|
]),
|
|
74
84
|
_: 2
|
|
75
85
|
}, 1024))), 128))
|
|
76
86
|
]),
|
|
77
87
|
_: 1
|
|
78
|
-
})) : (
|
|
88
|
+
})) : (t(), m("span", $, c(p.value[0]), 1))
|
|
79
89
|
]),
|
|
80
90
|
_: 1
|
|
81
91
|
}, 8, ["class"]))
|
|
82
92
|
], !0)
|
|
83
|
-
])) :
|
|
93
|
+
])) : w("", !0)
|
|
84
94
|
]),
|
|
85
95
|
_: 3
|
|
86
96
|
}));
|
|
87
97
|
}
|
|
88
98
|
});
|
|
89
99
|
export {
|
|
90
|
-
|
|
100
|
+
K as default
|
|
91
101
|
};
|
|
@@ -1,72 +1,71 @@
|
|
|
1
|
-
import { useForm as
|
|
2
|
-
import { Data as
|
|
1
|
+
import { useForm as J } from "@tanstack/vue-form";
|
|
2
|
+
import { Data as q, S as U, Effect as a, Fiber as y, Option as K, Array as L } from "effect-app";
|
|
3
3
|
import { runtimeFiberAsPromise as k } from "./vue-components.es12.js";
|
|
4
|
-
import { isObject as
|
|
5
|
-
import { computed as
|
|
6
|
-
import { usePreventClose as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { generateMetaFromSchema as
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import { trace as
|
|
14
|
-
import { context as
|
|
15
|
-
class
|
|
4
|
+
import { isObject as B } from "./vue-components.es13.js";
|
|
5
|
+
import { computed as O, onUnmounted as M, onMounted as G, onBeforeUnmount as T, ref as W, watch as z, h as A } from "vue";
|
|
6
|
+
import { usePreventClose as Q } from "./vue-components.es8.js";
|
|
7
|
+
import X from "./vue-components.es14.js";
|
|
8
|
+
import Y from "./vue-components.es15.js";
|
|
9
|
+
import Z from "./vue-components.es16.js";
|
|
10
|
+
import { generateMetaFromSchema as C } from "./vue-components.es9.js";
|
|
11
|
+
import ee from "./vue-components.es5.js";
|
|
12
|
+
import re from "./vue-components.es17.js";
|
|
13
|
+
import { trace as $ } from "./vue-components.es18.js";
|
|
14
|
+
import { context as b } from "./vue-components.es19.js";
|
|
15
|
+
class te extends q.TaggedError("FormErrors") {
|
|
16
16
|
}
|
|
17
|
-
const
|
|
17
|
+
const p = (c) => function(n) {
|
|
18
18
|
return {
|
|
19
19
|
render() {
|
|
20
|
-
return
|
|
20
|
+
return A(n, {
|
|
21
21
|
form: c,
|
|
22
22
|
...this.$attrs
|
|
23
23
|
}, this.$slots);
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
},
|
|
26
|
+
}, se = (c) => function(n) {
|
|
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 A(n, {
|
|
35
|
+
form: S,
|
|
36
|
+
fieldMap: h,
|
|
38
37
|
...this.$attrs
|
|
39
38
|
}, this.$slots);
|
|
40
39
|
}
|
|
41
40
|
};
|
|
42
|
-
},
|
|
41
|
+
}, ve = (c, o, n) => {
|
|
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 = U.standardSchemaV1(c), S = U.decode(c), { meta: f } = C(c), d = O(() => {
|
|
44
|
+
if (n?.persistency?.id)
|
|
45
|
+
return n.persistency.id;
|
|
46
|
+
const e = window.location.pathname, r = Object.keys(f);
|
|
48
47
|
return `${e}-${r.join("-")}`;
|
|
49
|
-
}),
|
|
48
|
+
}), N = () => {
|
|
50
49
|
const e = new URLSearchParams(window.location.search);
|
|
51
|
-
e.delete(
|
|
50
|
+
e.delete(d.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 E(e, r) {
|
|
56
55
|
for (const t in r)
|
|
57
|
-
r[t] &&
|
|
56
|
+
r[t] && B(r[t]) ? (e[t] || (e[t] = {}), E(e[t], r[t])) : e[t] = r[t];
|
|
58
57
|
return e;
|
|
59
58
|
}
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
return
|
|
59
|
+
const _ = O(() => {
|
|
60
|
+
if (o?.defaultValues && !n?.persistency?.overrideDefaultValues)
|
|
61
|
+
return o?.defaultValues;
|
|
63
62
|
let e;
|
|
64
|
-
const r =
|
|
63
|
+
const r = n?.persistency;
|
|
65
64
|
if (!r?.policies || r.policies.length === 0) return {};
|
|
66
65
|
if (r.policies.includes("querystring"))
|
|
67
66
|
try {
|
|
68
|
-
const s = new URLSearchParams(window.location.search).get(
|
|
69
|
-
|
|
67
|
+
const s = new URLSearchParams(window.location.search).get(d.value);
|
|
68
|
+
N(), s && (e = JSON.parse(s));
|
|
70
69
|
} catch (t) {
|
|
71
70
|
console.error(t);
|
|
72
71
|
}
|
|
@@ -78,146 +77,114 @@ const h = (c) => function(o) {
|
|
|
78
77
|
if (t)
|
|
79
78
|
try {
|
|
80
79
|
const s = JSON.parse(
|
|
81
|
-
t.getItem(
|
|
80
|
+
t.getItem(d.value) || "{}"
|
|
82
81
|
);
|
|
83
|
-
t.removeItem(
|
|
82
|
+
t.removeItem(d.value), e = s;
|
|
84
83
|
} catch (s) {
|
|
85
84
|
console.error(s);
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
|
-
if (e ??= {},
|
|
87
|
+
if (e ??= {}, o?.defaultValues == null)
|
|
89
88
|
return e;
|
|
90
89
|
{
|
|
91
|
-
const t =
|
|
92
|
-
return
|
|
90
|
+
const t = o?.defaultValues;
|
|
91
|
+
return E(t, e);
|
|
93
92
|
}
|
|
94
|
-
}),
|
|
95
|
-
...
|
|
93
|
+
}), D = (e, r) => e ? b.with($.setSpan(b.active(), e), r) : r(), l = J({
|
|
94
|
+
...o,
|
|
96
95
|
validators: {
|
|
97
|
-
onSubmit:
|
|
98
|
-
...
|
|
96
|
+
onSubmit: h,
|
|
97
|
+
...o?.validators || {}
|
|
99
98
|
},
|
|
100
|
-
onSubmit:
|
|
101
|
-
const s = await
|
|
99
|
+
onSubmit: o?.onSubmit ? ({ formApi: e, meta: r, value: t }) => D(r?.currentSpan, async () => {
|
|
100
|
+
const s = await a.runPromise(S(t)), i = o.onSubmit({
|
|
102
101
|
formApi: e,
|
|
103
102
|
meta: r,
|
|
104
103
|
value: s
|
|
105
104
|
});
|
|
106
|
-
return
|
|
107
|
-
|
|
105
|
+
return y.isFiber(i) && y.isRuntimeFiber(i) ? await k(i) : a.isEffect(i) ? await a.runPromise(
|
|
106
|
+
i.pipe(
|
|
108
107
|
// meta?.currentSpan
|
|
109
108
|
// ? Effect.withParentSpan(meta.currentSpan)
|
|
110
109
|
// : (_) => _,
|
|
111
|
-
|
|
110
|
+
a.flatMap((m) => y.join(m))
|
|
112
111
|
)
|
|
113
|
-
) :
|
|
112
|
+
) : i;
|
|
114
113
|
}) : void 0,
|
|
115
|
-
defaultValues:
|
|
116
|
-
}),
|
|
117
|
-
Object.keys(
|
|
118
|
-
|
|
114
|
+
defaultValues: _.value
|
|
115
|
+
}), I = () => {
|
|
116
|
+
Object.keys(f).forEach((e) => {
|
|
117
|
+
l.setFieldValue(e, void 0);
|
|
119
118
|
});
|
|
120
|
-
},
|
|
119
|
+
}, g = (e) => e.reduce((r, t) => {
|
|
121
120
|
const s = t.split(".");
|
|
122
|
-
return s.reduce((
|
|
123
|
-
}, {}),
|
|
121
|
+
return s.reduce((i, m, H) => (H === s.length - 1 ? i[m] = l.getFieldValue(t) : i[m] = i[m] ?? {}, i[m]), r), r;
|
|
122
|
+
}, {}), F = (e) => {
|
|
124
123
|
if (e) {
|
|
125
|
-
if (
|
|
126
|
-
return
|
|
127
|
-
if (
|
|
128
|
-
const r = Object.keys(
|
|
129
|
-
return
|
|
124
|
+
if (L.isArray(e.keys))
|
|
125
|
+
return g(e.keys);
|
|
126
|
+
if (L.isArray(e.banKeys)) {
|
|
127
|
+
const r = Object.keys(f).filter((t) => e.banKeys?.includes(t));
|
|
128
|
+
return g(r);
|
|
130
129
|
}
|
|
131
|
-
return
|
|
130
|
+
return l.store.state.values;
|
|
132
131
|
}
|
|
133
|
-
},
|
|
134
|
-
const e =
|
|
132
|
+
}, w = () => {
|
|
133
|
+
const e = n?.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 =
|
|
139
|
-
return r.setItem(
|
|
137
|
+
const t = F(e);
|
|
138
|
+
return r.setItem(d.value, JSON.stringify(t));
|
|
140
139
|
}
|
|
141
|
-
},
|
|
142
|
-
const e =
|
|
140
|
+
}, V = () => {
|
|
141
|
+
const e = n?.persistency;
|
|
143
142
|
if (!(!e?.policies || e.policies.length === 0) && e.policies.includes("querystring")) {
|
|
144
|
-
const r =
|
|
145
|
-
t.set(
|
|
143
|
+
const r = F(e), t = new URLSearchParams(window.location.search);
|
|
144
|
+
t.set(d.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
|
+
M(w), G(() => {
|
|
150
|
+
window.addEventListener("beforeunload", w), window.addEventListener("blur", V);
|
|
151
|
+
}), T(() => {
|
|
152
|
+
window.removeEventListener("beforeunload", w), window.removeEventListener("blur", V);
|
|
154
153
|
});
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
(r) =>
|
|
154
|
+
const P = (e) => a.currentSpan.pipe(
|
|
155
|
+
a.option,
|
|
156
|
+
a.flatMap(
|
|
157
|
+
(r) => a.promise(() => l.handleSubmit(K.isSome(r) ? { currentSpan: r.value, ...e } : e))
|
|
159
158
|
)
|
|
160
|
-
),
|
|
161
|
-
const r =
|
|
159
|
+
), R = (e) => e?.checkErrors ? P(e?.meta).pipe(a.flatMap(a.fnUntraced(function* () {
|
|
160
|
+
const r = l.getAllErrors();
|
|
162
161
|
if (Object.keys(r.fields).length || r.form.errors.length)
|
|
163
|
-
return yield* new
|
|
164
|
-
}))) :
|
|
165
|
-
i18nNamespace:
|
|
166
|
-
meta:
|
|
167
|
-
|
|
168
|
-
clear: J,
|
|
162
|
+
return yield* new te({ form: r.form, fields: r.fields });
|
|
163
|
+
}))) : P(e?.meta), x = l.handleSubmit, v = W(/* @__PURE__ */ new Map()), u = Object.assign(l, {
|
|
164
|
+
i18nNamespace: n?.i18nNamespace,
|
|
165
|
+
meta: f,
|
|
166
|
+
clear: I,
|
|
169
167
|
handleSubmit: (e) => {
|
|
170
|
-
const r =
|
|
171
|
-
return
|
|
168
|
+
const r = $.getSpan(b.active());
|
|
169
|
+
return x({ currentSpan: r, ...e });
|
|
172
170
|
},
|
|
173
171
|
// /** @experimental */
|
|
174
|
-
handleSubmitEffect:
|
|
172
|
+
handleSubmitEffect: R,
|
|
175
173
|
registerField: (e) => {
|
|
176
|
-
|
|
174
|
+
z(e, (r) => v.value.set(r.name, { label: r.label, id: r.id }), { immediate: !0 }), M(() => v.value.delete(e.value.name));
|
|
177
175
|
}
|
|
178
|
-
}),
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
)
|
|
187
|
-
);
|
|
188
|
-
N(
|
|
189
|
-
() => [i.filterItems, y.value],
|
|
190
|
-
() => {
|
|
191
|
-
const e = i.filterItems, r = y.value;
|
|
192
|
-
return e ? r ? (Object.values(r).filter(
|
|
193
|
-
(s) => !!s
|
|
194
|
-
).flatMap(
|
|
195
|
-
(s) => Object.values(s).flat().map((n) => n.message)
|
|
196
|
-
).some((s) => s === e.message) && e.items.forEach((s) => {
|
|
197
|
-
const n = i.getFieldMeta(s);
|
|
198
|
-
n && i.setFieldMeta(s, {
|
|
199
|
-
...n,
|
|
200
|
-
errorMap: {
|
|
201
|
-
onSubmit: [
|
|
202
|
-
{ path: [s], message: e.message }
|
|
203
|
-
]
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}), {}) : {} : {};
|
|
207
|
-
}
|
|
208
|
-
);
|
|
209
|
-
const L = { generalErrors: y, errors: K };
|
|
210
|
-
return o?.ignorePreventCloseEvents || Y(() => i.useStore((e) => e.isDirty)), Object.assign(i, {
|
|
211
|
-
errorContext: L,
|
|
212
|
-
Form: h(i)(se),
|
|
213
|
-
Input: h(i)(o?.input ?? te),
|
|
214
|
-
Field: u.Field,
|
|
215
|
-
Errors: oe(L)(ee),
|
|
216
|
-
Array: h(i)(Z),
|
|
217
|
-
AutoGen: h(i)(C)
|
|
176
|
+
}), j = { form: u, fieldMap: v };
|
|
177
|
+
return n?.ignorePreventCloseEvents || Q(() => u.useStore((e) => e.isDirty)), Object.assign(u, {
|
|
178
|
+
errorContext: j,
|
|
179
|
+
Form: p(u)(re),
|
|
180
|
+
Input: p(u)(n?.input ?? ee),
|
|
181
|
+
Field: l.Field,
|
|
182
|
+
Errors: se(j)(Z),
|
|
183
|
+
Array: p(u)(X),
|
|
184
|
+
AutoGen: p(u)(Y)
|
|
218
185
|
});
|
|
219
186
|
};
|
|
220
187
|
export {
|
|
221
|
-
|
|
222
|
-
|
|
188
|
+
te as FormErrors,
|
|
189
|
+
ve as useOmegaForm
|
|
223
190
|
};
|
|
@@ -1,162 +1,163 @@
|
|
|
1
|
-
import { S as n, Option as
|
|
2
|
-
import { getMetadataFromSchema as
|
|
3
|
-
import { useIntl as
|
|
4
|
-
|
|
1
|
+
import { S as n, Option as L } from "effect-app";
|
|
2
|
+
import { getMetadataFromSchema as M } from "@effect-app/vue/form";
|
|
3
|
+
import { useIntl as U, getTransformationFrom as _ } from "./vue-components.es3.js";
|
|
4
|
+
n.NonEmptyArray(n.String);
|
|
5
|
+
const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKeyword" || i === n.Null.ast), f = (e) => !e || !n.AST.isUnion(e) ? !1 : e.types.find((i) => i._tag === "UndefinedKeyword") ? "undefined" : e.types.find((i) => i === n.Null.ast) ? "null" : !1, u = ({ meta: e = {}, parent: i = "", property: t, propertySignatures: d }, o = {}) => {
|
|
5
6
|
if (t && t._tag === "Transformation")
|
|
6
|
-
return
|
|
7
|
+
return u({
|
|
7
8
|
parent: i,
|
|
8
9
|
meta: e,
|
|
9
10
|
property: t.from
|
|
10
11
|
});
|
|
11
12
|
if (t?._tag === "TypeLiteral" && "propertySignatures" in t)
|
|
12
|
-
return
|
|
13
|
+
return u({
|
|
13
14
|
meta: e,
|
|
14
15
|
propertySignatures: t.propertySignatures
|
|
15
16
|
});
|
|
16
|
-
if (
|
|
17
|
-
for (const r of
|
|
18
|
-
const
|
|
17
|
+
if (d) {
|
|
18
|
+
for (const r of d) {
|
|
19
|
+
const p = i ? `${i}.${r.name.toString()}` : r.name.toString(), a = f(r.type), l = !a, O = r.type;
|
|
19
20
|
if (n.AST.isUnion(r.type)) {
|
|
20
|
-
const
|
|
21
|
+
const S = r.type.types.filter(
|
|
21
22
|
(s) => s._tag !== "UndefinedKeyword" && s !== n.Null.ast
|
|
22
|
-
).map(
|
|
23
|
-
if (
|
|
23
|
+
).map(_);
|
|
24
|
+
if (S.some(
|
|
24
25
|
(s) => "propertySignatures" in s
|
|
25
26
|
)) {
|
|
26
27
|
if (!a) {
|
|
27
|
-
const s =
|
|
28
|
-
parent:
|
|
28
|
+
const s = u({
|
|
29
|
+
parent: p,
|
|
29
30
|
property: r.type,
|
|
30
|
-
meta: { required:
|
|
31
|
+
meta: { required: l, nullableOrUndefined: a }
|
|
31
32
|
});
|
|
32
|
-
o[
|
|
33
|
+
o[p] = s;
|
|
33
34
|
}
|
|
34
|
-
for (const s of
|
|
35
|
+
for (const s of S)
|
|
35
36
|
"propertySignatures" in s && Object.assign(
|
|
36
37
|
o,
|
|
37
|
-
|
|
38
|
-
parent:
|
|
38
|
+
u({
|
|
39
|
+
parent: p,
|
|
39
40
|
propertySignatures: s.propertySignatures,
|
|
40
|
-
meta: { required:
|
|
41
|
+
meta: { required: l, nullableOrUndefined: a }
|
|
41
42
|
})
|
|
42
43
|
);
|
|
43
44
|
} else {
|
|
44
|
-
const s =
|
|
45
|
+
const s = S.filter(n.AST.isTupleType);
|
|
45
46
|
if (s.length > 0) {
|
|
46
|
-
const
|
|
47
|
-
if (o[
|
|
47
|
+
const y = s[0];
|
|
48
|
+
if (o[p] = {
|
|
48
49
|
type: "multiple",
|
|
49
|
-
members:
|
|
50
|
-
rest:
|
|
51
|
-
required:
|
|
50
|
+
members: y.elements,
|
|
51
|
+
rest: y.rest,
|
|
52
|
+
required: l,
|
|
52
53
|
nullableOrUndefined: a
|
|
53
|
-
},
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
for (const
|
|
57
|
-
const
|
|
58
|
-
parent:
|
|
59
|
-
property:
|
|
54
|
+
}, y.rest && y.rest.length > 0) {
|
|
55
|
+
const g = y.rest[0];
|
|
56
|
+
if (g.type._tag === "TypeLiteral" && "propertySignatures" in g.type)
|
|
57
|
+
for (const m of g.type.propertySignatures) {
|
|
58
|
+
const T = `${p}.${m.name.toString()}`, c = u({
|
|
59
|
+
parent: T,
|
|
60
|
+
property: m.type,
|
|
60
61
|
meta: {
|
|
61
|
-
required: !
|
|
62
|
-
nullableOrUndefined:
|
|
62
|
+
required: !f(m.type),
|
|
63
|
+
nullableOrUndefined: f(m.type)
|
|
63
64
|
}
|
|
64
65
|
});
|
|
65
|
-
if (
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
for (const
|
|
69
|
-
const
|
|
70
|
-
parent:
|
|
71
|
-
property:
|
|
66
|
+
if (c && typeof c == "object" && "type" in c && (o[T] = c, c.type === "multiple" && n.AST.isTupleType(m.type) && m.type.rest && m.type.rest.length > 0)) {
|
|
67
|
+
const v = m.type.rest[0];
|
|
68
|
+
if (v.type._tag === "TypeLiteral" && "propertySignatures" in v.type)
|
|
69
|
+
for (const h of v.type.propertySignatures) {
|
|
70
|
+
const A = `${T}.${h.name.toString()}`, x = u({
|
|
71
|
+
parent: A,
|
|
72
|
+
property: h.type,
|
|
72
73
|
meta: {
|
|
73
|
-
required: !
|
|
74
|
-
nullableOrUndefined:
|
|
74
|
+
required: !f(h.type),
|
|
75
|
+
nullableOrUndefined: f(h.type)
|
|
75
76
|
}
|
|
76
77
|
});
|
|
77
|
-
|
|
78
|
+
x && typeof x == "object" && "type" in x && (o[A] = x);
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
} else {
|
|
83
|
-
const
|
|
84
|
-
parent:
|
|
84
|
+
const y = u({
|
|
85
|
+
parent: p,
|
|
85
86
|
property: r.type,
|
|
86
|
-
meta: { required:
|
|
87
|
+
meta: { required: l, nullableOrUndefined: a }
|
|
87
88
|
});
|
|
88
|
-
o[
|
|
89
|
+
o[p] = y;
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
|
-
} else if ("propertySignatures" in
|
|
92
|
+
} else if ("propertySignatures" in O)
|
|
92
93
|
Object.assign(
|
|
93
94
|
o,
|
|
94
|
-
|
|
95
|
-
parent:
|
|
96
|
-
propertySignatures:
|
|
97
|
-
meta: { required:
|
|
95
|
+
u({
|
|
96
|
+
parent: p,
|
|
97
|
+
propertySignatures: O.propertySignatures,
|
|
98
|
+
meta: { required: l, nullableOrUndefined: a }
|
|
98
99
|
})
|
|
99
100
|
);
|
|
100
101
|
else if (n.AST.isTupleType(r.type))
|
|
101
102
|
if (r.type.rest.length > 0 && r.type.rest[0].type._tag === "TypeLiteral" && "propertySignatures" in r.type.rest[0].type) {
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
for (const s of
|
|
105
|
-
const
|
|
103
|
+
const b = r.type.rest[0].type;
|
|
104
|
+
if (b._tag === "TypeLiteral" && "propertySignatures" in b)
|
|
105
|
+
for (const s of b.propertySignatures) {
|
|
106
|
+
const y = `${p}.${s.name.toString()}`;
|
|
106
107
|
if (n.AST.isTupleType(s.type) && s.type.rest.length > 0) {
|
|
107
|
-
const
|
|
108
|
-
if (
|
|
109
|
-
for (const
|
|
110
|
-
const
|
|
111
|
-
parent:
|
|
112
|
-
property:
|
|
108
|
+
const g = s.type.rest[0].type;
|
|
109
|
+
if (g._tag === "TypeLiteral" && "propertySignatures" in g)
|
|
110
|
+
for (const m of g.propertySignatures) {
|
|
111
|
+
const T = `${y}.${m.name.toString()}`, c = u({
|
|
112
|
+
parent: T,
|
|
113
|
+
property: m.type,
|
|
113
114
|
meta: {
|
|
114
|
-
required: !
|
|
115
|
-
nullableOrUndefined:
|
|
115
|
+
required: !f(m.type),
|
|
116
|
+
nullableOrUndefined: f(m.type)
|
|
116
117
|
}
|
|
117
118
|
});
|
|
118
|
-
o[
|
|
119
|
+
o[T] = c;
|
|
119
120
|
}
|
|
120
121
|
else
|
|
121
|
-
o[
|
|
122
|
+
o[y] = {
|
|
122
123
|
type: "multiple",
|
|
123
124
|
members: s.type.elements,
|
|
124
125
|
rest: s.type.rest,
|
|
125
|
-
required: !
|
|
126
|
-
nullableOrUndefined:
|
|
126
|
+
required: !f(s.type),
|
|
127
|
+
nullableOrUndefined: f(s.type)
|
|
127
128
|
};
|
|
128
129
|
} else {
|
|
129
|
-
const
|
|
130
|
-
parent:
|
|
130
|
+
const g = u({
|
|
131
|
+
parent: y,
|
|
131
132
|
property: s.type,
|
|
132
133
|
meta: {
|
|
133
|
-
required: !
|
|
134
|
-
nullableOrUndefined:
|
|
134
|
+
required: !f(s.type),
|
|
135
|
+
nullableOrUndefined: f(s.type)
|
|
135
136
|
}
|
|
136
137
|
});
|
|
137
|
-
o[
|
|
138
|
+
o[y] = g;
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
} else
|
|
141
|
-
o[
|
|
142
|
+
o[p] = {
|
|
142
143
|
type: "multiple",
|
|
143
144
|
members: r.type.elements,
|
|
144
145
|
rest: r.type.rest,
|
|
145
|
-
required:
|
|
146
|
+
required: l,
|
|
146
147
|
nullableOrUndefined: a
|
|
147
148
|
};
|
|
148
149
|
else {
|
|
149
|
-
const
|
|
150
|
-
parent:
|
|
150
|
+
const S = u({
|
|
151
|
+
parent: p,
|
|
151
152
|
property: r.type,
|
|
152
153
|
meta: {
|
|
153
154
|
// an empty string is valid for a S.String field, so we should not mark it as required
|
|
154
155
|
// TODO: handle this better via the createMeta minLength parsing
|
|
155
|
-
required:
|
|
156
|
+
required: l && (r.type._tag !== "StringKeyword" || M(r.type).minLength),
|
|
156
157
|
nullableOrUndefined: a
|
|
157
158
|
}
|
|
158
159
|
});
|
|
159
|
-
o[
|
|
160
|
+
o[p] = S;
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
return o;
|
|
@@ -165,19 +166,19 @@ const w = n.NonEmptyArray(n.String), E = (e) => n.AST.isUnion(e) && e.types.find
|
|
|
165
166
|
const r = E(t);
|
|
166
167
|
if (Object.hasOwnProperty.call(e, "required") || (e.required = !r), n.AST.isUnion(t)) {
|
|
167
168
|
const a = t.types.find(
|
|
168
|
-
(
|
|
169
|
+
(l) => l._tag !== "UndefinedKeyword" && l !== n.Null.ast
|
|
169
170
|
);
|
|
170
|
-
return "propertySignatures" in a ?
|
|
171
|
+
return "propertySignatures" in a ? u({
|
|
171
172
|
propertySignatures: a.propertySignatures,
|
|
172
173
|
parent: i,
|
|
173
174
|
meta: e
|
|
174
175
|
}) : t.types.every(n.AST.isLiteral) ? {
|
|
175
176
|
...e,
|
|
176
177
|
type: "select",
|
|
177
|
-
members: t.types.map((
|
|
178
|
+
members: t.types.map((l) => l.literal)
|
|
178
179
|
} : {
|
|
179
180
|
...e,
|
|
180
|
-
...
|
|
181
|
+
...u({
|
|
181
182
|
parent: i,
|
|
182
183
|
meta: e,
|
|
183
184
|
property: a
|
|
@@ -191,11 +192,11 @@ const w = n.NonEmptyArray(n.String), E = (e) => n.AST.isUnion(e) && e.types.find
|
|
|
191
192
|
members: t.elements,
|
|
192
193
|
rest: t.rest
|
|
193
194
|
};
|
|
194
|
-
const
|
|
195
|
+
const p = n.AST.getAnnotation(
|
|
195
196
|
t,
|
|
196
197
|
n.AST.JSONSchemaAnnotationId
|
|
197
|
-
).pipe(
|
|
198
|
-
return e = { ...e, ...
|
|
198
|
+
).pipe(L.getOrElse(() => ({})));
|
|
199
|
+
return e = { ...e, ...p }, "from" in t ? u({
|
|
199
200
|
parent: i,
|
|
200
201
|
meta: e,
|
|
201
202
|
property: t.from
|
|
@@ -203,48 +204,34 @@ const w = n.NonEmptyArray(n.String), E = (e) => n.AST.isUnion(e) && e.types.find
|
|
|
203
204
|
t,
|
|
204
205
|
n.AST.TitleAnnotationId
|
|
205
206
|
).pipe(
|
|
206
|
-
|
|
207
|
+
L.getOrElse(() => "unknown")
|
|
207
208
|
), e);
|
|
208
209
|
}
|
|
209
210
|
return o;
|
|
210
|
-
},
|
|
211
|
+
}, q = (e) => {
|
|
211
212
|
const i = e.ast, t = {};
|
|
212
213
|
if (i._tag === "Transformation" || i._tag === "Refinement")
|
|
213
|
-
return
|
|
214
|
+
return q(n.make(i.from));
|
|
214
215
|
if ("propertySignatures" in i) {
|
|
215
|
-
const
|
|
216
|
+
const d = u({
|
|
216
217
|
propertySignatures: i.propertySignatures
|
|
217
218
|
});
|
|
218
|
-
if (Object.values(
|
|
219
|
-
return
|
|
220
|
-
const o = (r,
|
|
219
|
+
if (Object.values(d).every((r) => r && "type" in r))
|
|
220
|
+
return d;
|
|
221
|
+
const o = (r, p = "") => {
|
|
221
222
|
for (const a in r) {
|
|
222
|
-
const
|
|
223
|
-
r[a] && typeof r[a] == "object" && "type" in r[a] ? t[
|
|
223
|
+
const l = p ? `${p}.${a}` : a;
|
|
224
|
+
r[a] && typeof r[a] == "object" && "type" in r[a] ? t[l] = r[a] : r[a] && typeof r[a] == "object" && o(r[a], l);
|
|
224
225
|
}
|
|
225
226
|
};
|
|
226
|
-
o(
|
|
227
|
+
o(d);
|
|
227
228
|
}
|
|
228
229
|
return t;
|
|
229
|
-
},
|
|
230
|
-
const i =
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
c.filter((p) => "items" in p),
|
|
235
|
-
c.filterMap(({ items: p }) => n.decodeUnknownOption(w)(p)),
|
|
236
|
-
c.zipWith(
|
|
237
|
-
n.AST.getMessageAnnotation(e.ast),
|
|
238
|
-
(p, o) => ({
|
|
239
|
-
items: p,
|
|
240
|
-
message: o("")
|
|
241
|
-
})
|
|
242
|
-
),
|
|
243
|
-
c.getOrUndefined
|
|
244
|
-
);
|
|
245
|
-
return { schema: e, meta: i, filterItems: t };
|
|
246
|
-
}, j = (e) => {
|
|
247
|
-
const { trans: i } = _();
|
|
230
|
+
}, K = (e) => n.extend(e, n.Struct({})), I = (e) => {
|
|
231
|
+
const i = q(e);
|
|
232
|
+
return { schema: e, meta: i };
|
|
233
|
+
}, P = (e) => {
|
|
234
|
+
const { trans: i } = U();
|
|
248
235
|
let t;
|
|
249
236
|
switch (e.type) {
|
|
250
237
|
case "string":
|
|
@@ -326,12 +313,12 @@ const w = n.NonEmptyArray(n.String), E = (e) => n.AST.isUnion(e) && e.types.find
|
|
|
326
313
|
message: () => i("validation.empty")
|
|
327
314
|
})
|
|
328
315
|
) : t = n.NullishOr(t), n.standardSchemaV1(t);
|
|
329
|
-
},
|
|
316
|
+
}, F = (e, i) => n.NullOr(e).pipe(
|
|
330
317
|
n.transform(n.typeSchema(e), {
|
|
331
318
|
decode: (t) => t ?? i(),
|
|
332
319
|
encode: (t) => t
|
|
333
320
|
})
|
|
334
|
-
),
|
|
321
|
+
), N = [
|
|
335
322
|
"button",
|
|
336
323
|
"checkbox",
|
|
337
324
|
"color",
|
|
@@ -347,12 +334,12 @@ const w = n.NonEmptyArray(n.String), E = (e) => n.AST.isUnion(e) && e.types.find
|
|
|
347
334
|
"text",
|
|
348
335
|
"time",
|
|
349
336
|
"url"
|
|
350
|
-
],
|
|
337
|
+
], j = (e) => N.includes(e) ? e : "text";
|
|
351
338
|
export {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
339
|
+
u as createMeta,
|
|
340
|
+
K as duplicateSchema,
|
|
341
|
+
P as generateInputStandardSchemaFromFieldMeta,
|
|
342
|
+
I as generateMetaFromSchema,
|
|
343
|
+
j as getInputType,
|
|
344
|
+
F as nullableInput
|
|
358
345
|
};
|
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
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Effect, Option,
|
|
1
|
+
import { type Effect, Option, type Record, S } from "effect-app"
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
import { getMetadataFromSchema } from "@effect-app/vue/form"
|
|
4
4
|
import { type DeepKeys, type FieldAsyncValidateOrFn, type FieldValidateOrFn, type FormApi, type FormAsyncValidateOrFn, type FormOptions, type FormState, type FormValidateOrFn, type StandardSchemaV1, type VueFormApi } from "@tanstack/vue-form"
|
|
@@ -650,27 +650,10 @@ export const generateMetaFromSchema = <From, To>(
|
|
|
650
650
|
): {
|
|
651
651
|
schema: S.Schema<To, From, never>
|
|
652
652
|
meta: MetaRecord<To>
|
|
653
|
-
filterItems?: FilterItems
|
|
654
653
|
} => {
|
|
655
654
|
const meta = flattenMeta(schema)
|
|
656
655
|
|
|
657
|
-
|
|
658
|
-
schema.ast,
|
|
659
|
-
Option.liftPredicate((s) => s._tag === "Refinement" && "filter" in s),
|
|
660
|
-
Option.flatMap((s) => S.AST.getJSONSchemaAnnotation(s)),
|
|
661
|
-
Option.filter((s) => "items" in s),
|
|
662
|
-
Option.filterMap(({ items }) => S.decodeUnknownOption(isArrayOfString)(items)),
|
|
663
|
-
Option.zipWith(
|
|
664
|
-
S.AST.getMessageAnnotation(schema.ast),
|
|
665
|
-
(items, message) => ({
|
|
666
|
-
items,
|
|
667
|
-
message: message("" as unknown as S.ParseResult.ParseIssue)
|
|
668
|
-
})
|
|
669
|
-
),
|
|
670
|
-
Option.getOrUndefined
|
|
671
|
-
)
|
|
672
|
-
|
|
673
|
-
return { schema, meta, filterItems }
|
|
656
|
+
return { schema, meta }
|
|
674
657
|
}
|
|
675
658
|
|
|
676
659
|
export const generateInputStandardSchemaFromFieldMeta = (
|
|
@@ -6,13 +6,13 @@ 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"
|
|
13
13
|
import OmegaAutoGen from "./OmegaAutoGen.vue"
|
|
14
14
|
import OmegaErrorsInternal from "./OmegaErrorsInternal.vue"
|
|
15
|
-
import { BaseProps, DefaultTypeProps, type
|
|
15
|
+
import { BaseProps, DefaultTypeProps, type FormProps, generateMetaFromSchema, type MetaRecord, type NestedKeyOf, OmegaAutoGenMeta, OmegaError, type OmegaFormApi, OmegaFormState, OmegaInputProps, ShowErrorsOn } from "./OmegaFormStuff"
|
|
16
16
|
import OmegaInput from "./OmegaInput.vue"
|
|
17
17
|
import OmegaForm from "./OmegaWrapper.vue"
|
|
18
18
|
|
|
@@ -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
|
}
|
|
@@ -115,7 +109,6 @@ export type OmegaConfig<T> = {
|
|
|
115
109
|
|
|
116
110
|
export interface OF<From, To> extends OmegaFormApi<From, To> {
|
|
117
111
|
meta: MetaRecord<From>
|
|
118
|
-
filterItems?: FilterItems
|
|
119
112
|
clear: () => void
|
|
120
113
|
i18nNamespace?: string
|
|
121
114
|
registerField: (
|
|
@@ -611,7 +604,7 @@ export const useOmegaForm = <
|
|
|
611
604
|
const standardSchema = S.standardSchemaV1(schema)
|
|
612
605
|
const decode = S.decode(schema)
|
|
613
606
|
|
|
614
|
-
const {
|
|
607
|
+
const { meta } = generateMetaFromSchema(schema)
|
|
615
608
|
|
|
616
609
|
const persistencyKey = computed(() => {
|
|
617
610
|
if (omegaConfig?.persistency?.id) {
|
|
@@ -863,12 +856,11 @@ export const useOmegaForm = <
|
|
|
863
856
|
|
|
864
857
|
const handleSubmit = form.handleSubmit
|
|
865
858
|
|
|
866
|
-
const fieldMap = new Map<string, { label: string; id: string }>()
|
|
859
|
+
const fieldMap = ref(new Map<string, { label: string; id: string }>())
|
|
867
860
|
|
|
868
861
|
const formWithExtras: OF<From, To> = Object.assign(form, {
|
|
869
862
|
i18nNamespace: omegaConfig?.i18nNamespace,
|
|
870
863
|
meta,
|
|
871
|
-
filterItems,
|
|
872
864
|
clear,
|
|
873
865
|
handleSubmit: (meta?: Record<string, any>) => {
|
|
874
866
|
const span = api.trace.getSpan(api.context.active())
|
|
@@ -877,67 +869,12 @@ export const useOmegaForm = <
|
|
|
877
869
|
// /** @experimental */
|
|
878
870
|
handleSubmitEffect,
|
|
879
871
|
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)
|
|
872
|
+
watch(field, (f) => fieldMap.value.set(f.name, { label: f.label, id: f.id }), { immediate: true })
|
|
873
|
+
onUnmounted(() => fieldMap.value.delete(field.value.name)) // todo; perhap only when owned (id match)
|
|
882
874
|
}
|
|
883
875
|
})
|
|
884
876
|
|
|
885
|
-
const
|
|
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
|
-
|
|
901
|
-
watch(
|
|
902
|
-
() => [formWithExtras.filterItems, errors.value],
|
|
903
|
-
() => {
|
|
904
|
-
const filterItems: FilterItems | undefined = formWithExtras.filterItems
|
|
905
|
-
const currentErrors = errors.value
|
|
906
|
-
if (!filterItems) return {}
|
|
907
|
-
if (!currentErrors) return {}
|
|
908
|
-
const errorList = Object
|
|
909
|
-
.values(currentErrors)
|
|
910
|
-
.filter(
|
|
911
|
-
(fieldErrors): fieldErrors is Record<string, StandardSchemaV1Issue[]> => Boolean(fieldErrors)
|
|
912
|
-
)
|
|
913
|
-
.flatMap((fieldErrors) =>
|
|
914
|
-
Object
|
|
915
|
-
.values(fieldErrors)
|
|
916
|
-
.flat()
|
|
917
|
-
.map((issue: StandardSchemaV1Issue) => issue.message)
|
|
918
|
-
)
|
|
919
|
-
|
|
920
|
-
if (errorList.some((e) => e === filterItems.message)) {
|
|
921
|
-
// TODO: Investigate if filterItems.items should be typed based on DeepKeys<To>.
|
|
922
|
-
filterItems.items.forEach((item: keyof From) => {
|
|
923
|
-
const m = formWithExtras.getFieldMeta(item as any)
|
|
924
|
-
if (m) {
|
|
925
|
-
formWithExtras.setFieldMeta(item as any, {
|
|
926
|
-
...m,
|
|
927
|
-
errorMap: {
|
|
928
|
-
onSubmit: [
|
|
929
|
-
{ path: [item as string], message: filterItems.message }
|
|
930
|
-
]
|
|
931
|
-
}
|
|
932
|
-
})
|
|
933
|
-
}
|
|
934
|
-
})
|
|
935
|
-
}
|
|
936
|
-
return {}
|
|
937
|
-
}
|
|
938
|
-
)
|
|
939
|
-
|
|
940
|
-
const errorContext = { generalErrors: errors, errors: fieldErrors }
|
|
877
|
+
const errorContext = { form: formWithExtras, fieldMap }
|
|
941
878
|
|
|
942
879
|
if (!omegaConfig?.ignorePreventCloseEvents) {
|
|
943
880
|
usePreventClose(() => formWithExtras.useStore((state) => state.isDirty))
|