@effect-app/vue-components 0.15.29 → 0.16.0
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/README.md +21 -0
- package/dist/types/components/OmegaForm/OmegaWrapper.vue.d.ts +8 -8
- package/dist/vue-components.es12.js +3 -3
- package/dist/vue-components.es20.js +70 -58
- package/dist/vue-components.es22.js +1 -1
- package/dist/vue-components.es23.js +2 -90
- package/dist/vue-components.es24.js +90 -11
- package/dist/vue-components.es25.js +11 -2
- package/dist/vue-components.es26.js +1 -1
- package/dist/vue-components.es7.js +1 -1
- package/package.json +1 -1
- package/src/components/OmegaForm/OmegaWrapper.vue +61 -15
package/README.md
CHANGED
|
@@ -182,3 +182,24 @@ In [tsconfig.json](tsconfig.js), set the following to address [Issue #32](https:
|
|
|
182
182
|
]
|
|
183
183
|
}
|
|
184
184
|
```
|
|
185
|
+
|
|
186
|
+
### On Submit event
|
|
187
|
+
The :on-submit event could be tricky in `<OmegaForm />` component.
|
|
188
|
+
This is a prop that is basically a map of Tanstack Form `onSubmit` option and accept a function that return a Promise. If you want to use it as an event, you have to manage the state of loading yourself with `@submit` with a function returning `void`
|
|
189
|
+
|
|
190
|
+
E.g.
|
|
191
|
+
|
|
192
|
+
to use it as a Promise based Tanstack way:
|
|
193
|
+
```html
|
|
194
|
+
<OmegaForm :schema="schema" :on-submit="onSubmit" :subscribe="['values']">
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
to use it as an event:
|
|
198
|
+
```html
|
|
199
|
+
<OmegaForm :schema="schema" @submit="onSubmit" :is-loading="false" :subscribe="['values']">
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
this will give you a type error instead, because `:is-loading` is only accepted in event mode
|
|
203
|
+
```html
|
|
204
|
+
<OmegaForm :schema="schema" :on-submit="onSubmit" :is-loading="false" :subscribe="['values']">
|
|
205
|
+
```
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { type S } from "effect-app";
|
|
2
|
-
import { type OmegaFormState, type ShowErrorsOn } from "./OmegaFormStuff";
|
|
2
|
+
import { type FormProps, type OmegaFormState, type ShowErrorsOn } from "./OmegaFormStuff";
|
|
3
3
|
import { type OmegaConfig, type OmegaFormReturn } from "./useOmegaForm";
|
|
4
4
|
declare const _default: <From extends Record<PropertyKey, any>, To extends Record<PropertyKey, any>, K extends keyof OmegaFormState<From, To> = keyof OmegaFormState<From, To>>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
5
5
|
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, never> & ({
|
|
6
6
|
omegaConfig?: OmegaConfig<From>;
|
|
7
7
|
subscribe?: K[];
|
|
8
8
|
showErrorsOn?: ShowErrorsOn;
|
|
9
|
-
} & Omit<
|
|
10
|
-
onSubmit?: ((props: {
|
|
11
|
-
formApi: import("./OmegaFormStuff").OmegaFormParams<From, To>;
|
|
12
|
-
meta: any;
|
|
13
|
-
value: To;
|
|
14
|
-
}) => Promise<any> | any) | undefined;
|
|
15
|
-
} & ({
|
|
9
|
+
} & Omit<FormProps<From, To>, "onSubmit"> & (({
|
|
16
10
|
form: OmegaFormReturn<From, To>;
|
|
17
11
|
schema?: undefined;
|
|
18
12
|
} | {
|
|
19
13
|
form?: undefined;
|
|
20
14
|
schema: S.Schema<To, From, never>;
|
|
15
|
+
}) & ({
|
|
16
|
+
isLoading?: undefined;
|
|
17
|
+
onSubmit?: FormProps<From, To>["onSubmit"];
|
|
18
|
+
} | {
|
|
19
|
+
isLoading: boolean;
|
|
20
|
+
onSubmit: (data: To) => void;
|
|
21
21
|
}))) & {}> & import("vue").PublicProps;
|
|
22
22
|
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
|
|
23
23
|
attrs: any;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(){"use strict";try{if(typeof document<"u"){var n=document.createElement("style");if(n.appendChild(document.createTextNode("fieldset[data-v-
|
|
1
|
+
(function(){"use strict";try{if(typeof document<"u"){var n=document.createElement("style");if(n.appendChild(document.createTextNode("fieldset[data-v-57a15ff7]{display:contents}fieldset[disabled][data-v-57a15ff7]>*{pointer-events:none}")),document.head.appendChild(n),window.customElements){const e=window.customElements.define;window.customElements.define=function(i,t){const d=t.prototype.connectedCallback;return t.prototype.connectedCallback=function(){if(d&&d.call(this),this.shadowRoot){const o=document.createElement("style");o.appendChild(document.createTextNode("fieldset[data-v-57a15ff7]{display:contents}fieldset[disabled][data-v-57a15ff7]>*{pointer-events:none}")),this.shadowRoot.appendChild(o)}},e.call(window.customElements,i,t)}}}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
|
|
2
2
|
import o from "./vue-components.es20.js";
|
|
3
3
|
|
|
4
4
|
import r from "./vue-components.es17.js";
|
|
5
|
-
const
|
|
5
|
+
const f = /* @__PURE__ */ r(o, [["__scopeId", "data-v-57a15ff7"]]);
|
|
6
6
|
export {
|
|
7
|
-
|
|
7
|
+
f as default
|
|
8
8
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { useStore as
|
|
3
|
-
import { getOmegaStore as
|
|
4
|
-
import { provideOmegaErrors as
|
|
5
|
-
import { useOmegaForm as
|
|
6
|
-
const
|
|
1
|
+
import { defineComponent as M, getCurrentInstance as F, computed as p, onBeforeMount as B, watch as b, createElementBlock as v, openBlock as g, withModifiers as C, createElementVNode as I, unref as m, renderSlot as c, createCommentVNode as L, Fragment as V } from "vue";
|
|
2
|
+
import { useStore as O } from "@tanstack/vue-form";
|
|
3
|
+
import { getOmegaStore as k } from "./vue-components.es25.js";
|
|
4
|
+
import { provideOmegaErrors as $ } from "./vue-components.es8.js";
|
|
5
|
+
import { useOmegaForm as A } from "./vue-components.es9.js";
|
|
6
|
+
const K = ["disabled"], W = /* @__PURE__ */ M({
|
|
7
7
|
__name: "OmegaWrapper",
|
|
8
8
|
props: {
|
|
9
9
|
omegaConfig: {},
|
|
@@ -15,99 +15,111 @@ const $ = ["disabled"], N = /* @__PURE__ */ w({
|
|
|
15
15
|
asyncDebounceMs: {},
|
|
16
16
|
validators: {},
|
|
17
17
|
onSubmitMeta: {},
|
|
18
|
-
onSubmitInvalid: {
|
|
18
|
+
onSubmitInvalid: {},
|
|
19
19
|
transform: {},
|
|
20
|
-
onSubmit: { type: Function },
|
|
21
20
|
form: {},
|
|
22
|
-
schema: {}
|
|
21
|
+
schema: {},
|
|
22
|
+
isLoading: { type: Boolean, default: void 0 },
|
|
23
|
+
onSubmit: {}
|
|
23
24
|
},
|
|
24
|
-
setup(
|
|
25
|
-
const o =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
setup(S) {
|
|
26
|
+
const o = S, h = F(), y = ({ value: e }) => {
|
|
27
|
+
new Promise((r) => {
|
|
28
|
+
h.emit("submit", e);
|
|
29
|
+
const n = b(() => o.isLoading, (t) => {
|
|
30
|
+
t || (r(), n.stop());
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}, u = o.form || !o.schema ? void 0 : A(
|
|
34
|
+
o.schema,
|
|
35
|
+
{
|
|
36
|
+
...o,
|
|
37
|
+
onSubmit: typeof o.isLoading < "u" ? y : o.onSubmit
|
|
38
|
+
},
|
|
39
|
+
o.omegaConfig
|
|
40
|
+
), s = p(() => o.form ?? u);
|
|
41
|
+
B(() => {
|
|
30
42
|
if (!o.form) return;
|
|
31
|
-
const e = Object.keys(o.form.options || {}),
|
|
43
|
+
const e = Object.keys(o.form.options || {}), r = /* @__PURE__ */ new Set([
|
|
32
44
|
"omegaConfig",
|
|
33
45
|
"subscribe",
|
|
34
46
|
"showErrorsOn",
|
|
35
47
|
"asyncAlways",
|
|
36
48
|
"form",
|
|
37
49
|
"schema"
|
|
38
|
-
]),
|
|
50
|
+
]), n = Object.fromEntries(
|
|
39
51
|
Object.entries(o).filter(
|
|
40
|
-
([a,
|
|
52
|
+
([a, f]) => a === "isLoading" ? !1 : !r.has(a) && f !== void 0
|
|
41
53
|
)
|
|
42
|
-
),
|
|
43
|
-
(a) =>
|
|
54
|
+
), t = Object.keys(n), i = e.filter(
|
|
55
|
+
(a) => t.includes(a) && n[a] !== void 0
|
|
44
56
|
);
|
|
45
|
-
|
|
57
|
+
i.length > 0 && console.warn(
|
|
46
58
|
`[OmegaWrapper] Overlapping keys found between form options and filtered props:
|
|
47
|
-
${
|
|
59
|
+
${i.join(
|
|
48
60
|
`,
|
|
49
61
|
`
|
|
50
62
|
)}.
|
|
51
63
|
Props will overwrite existing form options. This might indicate a configuration issue.`
|
|
52
64
|
);
|
|
53
|
-
const
|
|
54
|
-
...
|
|
55
|
-
...
|
|
65
|
+
const j = {
|
|
66
|
+
...s.value.options,
|
|
67
|
+
...n
|
|
56
68
|
};
|
|
57
|
-
|
|
69
|
+
s.value.options = Object.fromEntries(
|
|
58
70
|
// TODO
|
|
59
|
-
Object.entries(
|
|
60
|
-
([a,
|
|
71
|
+
Object.entries(j).filter(
|
|
72
|
+
([a, f]) => f !== void 0
|
|
61
73
|
)
|
|
62
74
|
);
|
|
63
75
|
});
|
|
64
|
-
const
|
|
65
|
-
|
|
76
|
+
const w = O(
|
|
77
|
+
s.value.store,
|
|
66
78
|
(e) => e.isSubmitting
|
|
67
|
-
), d =
|
|
68
|
-
|
|
79
|
+
), d = k(
|
|
80
|
+
s.value,
|
|
69
81
|
o.subscribe
|
|
70
|
-
),
|
|
71
|
-
|
|
82
|
+
), E = O(
|
|
83
|
+
s.value.store,
|
|
72
84
|
(e) => e.submissionAttempts
|
|
73
|
-
), l =
|
|
74
|
-
return
|
|
75
|
-
() => [
|
|
85
|
+
), l = p(() => s.value.useStore((e) => e.errors));
|
|
86
|
+
return b(
|
|
87
|
+
() => [s.value.filterItems, l.value.value],
|
|
76
88
|
() => {
|
|
77
|
-
const e =
|
|
78
|
-
return e ?
|
|
79
|
-
(
|
|
89
|
+
const e = s.value.filterItems, r = l.value.value;
|
|
90
|
+
return e ? r ? (Object.values(r).filter(
|
|
91
|
+
(t) => !!t
|
|
80
92
|
).flatMap(
|
|
81
|
-
(
|
|
82
|
-
).some((
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
...
|
|
93
|
+
(t) => Object.values(t).flat().map((i) => i.message)
|
|
94
|
+
).some((t) => t === e.message) && e.items.forEach((t) => {
|
|
95
|
+
const i = s.value.getFieldMeta(t);
|
|
96
|
+
i && s.value.setFieldMeta(t, {
|
|
97
|
+
...i,
|
|
86
98
|
errorMap: {
|
|
87
99
|
onSubmit: [
|
|
88
|
-
{ path: [
|
|
100
|
+
{ path: [t], message: e.message }
|
|
89
101
|
]
|
|
90
102
|
}
|
|
91
103
|
});
|
|
92
104
|
}), {}) : {} : {};
|
|
93
105
|
}
|
|
94
|
-
),
|
|
106
|
+
), $(E, l.value, o.showErrorsOn), (e, r) => (g(), v("form", {
|
|
95
107
|
novalidate: "",
|
|
96
|
-
onSubmit:
|
|
108
|
+
onSubmit: r[0] || (r[0] = C((n) => s.value.handleSubmit(), ["prevent", "stop"]))
|
|
97
109
|
}, [
|
|
98
|
-
|
|
99
|
-
o.form ? (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
], 64)) : m
|
|
110
|
+
I("fieldset", { disabled: m(w) }, [
|
|
111
|
+
o.form ? (g(), v(V, { key: 0 }, [
|
|
112
|
+
c(e.$slots, "externalForm", { subscribedValues: m(d) }, void 0, !0),
|
|
113
|
+
c(e.$slots, "default", {}, void 0, !0)
|
|
114
|
+
], 64)) : m(u) ? c(e.$slots, "internalForm", {
|
|
103
115
|
key: 1,
|
|
104
|
-
form: m
|
|
105
|
-
subscribedValues:
|
|
106
|
-
}, void 0, !0) :
|
|
107
|
-
], 8,
|
|
116
|
+
form: m(u),
|
|
117
|
+
subscribedValues: m(d)
|
|
118
|
+
}, void 0, !0) : L("", !0)
|
|
119
|
+
], 8, K)
|
|
108
120
|
], 32));
|
|
109
121
|
}
|
|
110
122
|
});
|
|
111
123
|
export {
|
|
112
|
-
|
|
124
|
+
W as default
|
|
113
125
|
};
|
|
@@ -1,92 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { defineComponent as w, getCurrentInstance as x, useId as C, computed as a, watch as f, nextTick as N, onMounted as d, ref as $, watchEffect as k, renderSlot as B, normalizeProps as I, guardReactiveProps as O, createElementVNode as _, normalizeClass as q, createBlock as L, createCommentVNode as P, unref as F, openBlock as S, mergeProps as T } from "vue";
|
|
3
|
-
import { useStore as z } from "@tanstack/vue-form";
|
|
4
|
-
import { useOmegaErrors as A } from "./vue-components.es8.js";
|
|
5
|
-
import D from "./vue-components.es27.js";
|
|
6
|
-
|
|
7
|
-
const J = /* @__PURE__ */ w({
|
|
8
|
-
inheritAttrs: !1,
|
|
9
|
-
__name: "OmegaInternalInput",
|
|
10
|
-
props: {
|
|
11
|
-
field: {},
|
|
12
|
-
meta: {},
|
|
13
|
-
label: {},
|
|
14
|
-
options: {},
|
|
15
|
-
type: {},
|
|
16
|
-
validators: {}
|
|
17
|
-
},
|
|
18
|
-
setup(c) {
|
|
19
|
-
const e = c, v = x()?.appContext.components.VTextField, l = C(), o = e.field, r = z(o.store, (t) => t), m = a(() => e.type ? e.type : e.meta?.type === "string" ? e.meta.format === "email" ? "email" : "string" : e.meta?.type || "unknown"), n = a(() => r.value.value), g = a(
|
|
20
|
-
() => (
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
r.value.meta.errors.map((t) => t?.message).filter(Boolean)
|
|
23
|
-
)
|
|
24
|
-
), y = (t) => t == null || t === !1 || t === "" || Number.isNaN(t);
|
|
25
|
-
f(
|
|
26
|
-
() => !!n.value,
|
|
27
|
-
() => {
|
|
28
|
-
y(n.value) && e.meta?.type !== "boolean" && N(() => {
|
|
29
|
-
o.setValue(
|
|
30
|
-
e.meta?.nullableOrUndefined === "undefined" ? void 0 : null
|
|
31
|
-
);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
), d(() => {
|
|
35
|
-
!n.value && !e.meta?.required && e.meta?.nullableOrUndefined === "null" && o.setValue(null);
|
|
36
|
-
});
|
|
37
|
-
const { addError: h, removeError: b, showErrors: E, showErrorsOn: V } = A(), s = $(!1);
|
|
38
|
-
k(() => {
|
|
39
|
-
(E.value || V === "onChange") && (s.value = !0);
|
|
40
|
-
});
|
|
41
|
-
const u = () => {
|
|
42
|
-
s.value = !0;
|
|
43
|
-
};
|
|
44
|
-
d(() => {
|
|
45
|
-
n.value && u();
|
|
46
|
-
});
|
|
47
|
-
const p = a(() => !s.value && m.value !== "select" ? [] : g.value);
|
|
48
|
-
f(
|
|
49
|
-
() => r.value.meta.errors,
|
|
50
|
-
() => {
|
|
51
|
-
r.value.meta.errors.length ? h({
|
|
52
|
-
inputId: l,
|
|
53
|
-
errors: r.value.meta.errors.map((t) => t.message).filter(Boolean),
|
|
54
|
-
label: e.label
|
|
55
|
-
}) : b(l);
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
const i = a(() => ({
|
|
59
|
-
id: l,
|
|
60
|
-
required: e.meta?.required,
|
|
61
|
-
minLength: e.meta?.type === "string" && e.meta?.minLength,
|
|
62
|
-
maxLength: e.meta?.type === "string" && e.meta?.maxLength,
|
|
63
|
-
max: e.meta?.type === "number" && e.meta?.maximum,
|
|
64
|
-
min: e.meta?.type === "number" && e.meta?.minimum,
|
|
65
|
-
name: e.field.name,
|
|
66
|
-
modelValue: e.field.state.value,
|
|
67
|
-
errorMessages: p.value,
|
|
68
|
-
error: !!p.value.length,
|
|
69
|
-
field: e.field,
|
|
70
|
-
setRealDirty: u,
|
|
71
|
-
type: m.value,
|
|
72
|
-
label: `${e.label}${e.meta?.required ? " *" : ""}`,
|
|
73
|
-
options: e.options
|
|
74
|
-
}));
|
|
75
|
-
return (t, R) => B(t.$slots, "default", I(O(i.value)), () => [
|
|
76
|
-
_("div", {
|
|
77
|
-
class: q(t.$attrs.class),
|
|
78
|
-
onFocusout: u
|
|
79
|
-
}, [
|
|
80
|
-
F(v) ? (S(), L(D, T({
|
|
81
|
-
key: 0,
|
|
82
|
-
"input-props": i.value
|
|
83
|
-
}, t.$attrs, {
|
|
84
|
-
"vuetify-value": i.value.field.state.value
|
|
85
|
-
}), null, 16, ["input-props", "vuetify-value"])) : P("", !0)
|
|
86
|
-
], 34)
|
|
87
|
-
]);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
1
|
+
const o = (n) => typeof n == "function";
|
|
90
2
|
export {
|
|
91
|
-
|
|
3
|
+
o as isFunction
|
|
92
4
|
};
|
|
@@ -1,13 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
import { computed as f } from "vue";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 w, getCurrentInstance as x, useId as C, computed as a, watch as f, nextTick as N, onMounted as d, ref as $, watchEffect as k, renderSlot as B, normalizeProps as I, guardReactiveProps as O, createElementVNode as _, normalizeClass as q, createBlock as L, createCommentVNode as P, unref as F, openBlock as S, mergeProps as T } from "vue";
|
|
3
|
+
import { useStore as z } from "@tanstack/vue-form";
|
|
4
|
+
import { useOmegaErrors as A } from "./vue-components.es8.js";
|
|
5
|
+
import D from "./vue-components.es27.js";
|
|
6
|
+
|
|
7
|
+
const J = /* @__PURE__ */ w({
|
|
8
|
+
inheritAttrs: !1,
|
|
9
|
+
__name: "OmegaInternalInput",
|
|
10
|
+
props: {
|
|
11
|
+
field: {},
|
|
12
|
+
meta: {},
|
|
13
|
+
label: {},
|
|
14
|
+
options: {},
|
|
15
|
+
type: {},
|
|
16
|
+
validators: {}
|
|
17
|
+
},
|
|
18
|
+
setup(c) {
|
|
19
|
+
const e = c, v = x()?.appContext.components.VTextField, l = C(), o = e.field, r = z(o.store, (t) => t), m = a(() => e.type ? e.type : e.meta?.type === "string" ? e.meta.format === "email" ? "email" : "string" : e.meta?.type || "unknown"), n = a(() => r.value.value), g = a(
|
|
20
|
+
() => (
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
r.value.meta.errors.map((t) => t?.message).filter(Boolean)
|
|
23
|
+
)
|
|
24
|
+
), y = (t) => t == null || t === !1 || t === "" || Number.isNaN(t);
|
|
25
|
+
f(
|
|
26
|
+
() => !!n.value,
|
|
27
|
+
() => {
|
|
28
|
+
y(n.value) && e.meta?.type !== "boolean" && N(() => {
|
|
29
|
+
o.setValue(
|
|
30
|
+
e.meta?.nullableOrUndefined === "undefined" ? void 0 : null
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
), d(() => {
|
|
35
|
+
!n.value && !e.meta?.required && e.meta?.nullableOrUndefined === "null" && o.setValue(null);
|
|
36
|
+
});
|
|
37
|
+
const { addError: h, removeError: b, showErrors: E, showErrorsOn: V } = A(), s = $(!1);
|
|
38
|
+
k(() => {
|
|
39
|
+
(E.value || V === "onChange") && (s.value = !0);
|
|
40
|
+
});
|
|
41
|
+
const u = () => {
|
|
42
|
+
s.value = !0;
|
|
43
|
+
};
|
|
44
|
+
d(() => {
|
|
45
|
+
n.value && u();
|
|
46
|
+
});
|
|
47
|
+
const p = a(() => !s.value && m.value !== "select" ? [] : g.value);
|
|
48
|
+
f(
|
|
49
|
+
() => r.value.meta.errors,
|
|
50
|
+
() => {
|
|
51
|
+
r.value.meta.errors.length ? h({
|
|
52
|
+
inputId: l,
|
|
53
|
+
errors: r.value.meta.errors.map((t) => t.message).filter(Boolean),
|
|
54
|
+
label: e.label
|
|
55
|
+
}) : b(l);
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
const i = a(() => ({
|
|
59
|
+
id: l,
|
|
60
|
+
required: e.meta?.required,
|
|
61
|
+
minLength: e.meta?.type === "string" && e.meta?.minLength,
|
|
62
|
+
maxLength: e.meta?.type === "string" && e.meta?.maxLength,
|
|
63
|
+
max: e.meta?.type === "number" && e.meta?.maximum,
|
|
64
|
+
min: e.meta?.type === "number" && e.meta?.minimum,
|
|
65
|
+
name: e.field.name,
|
|
66
|
+
modelValue: e.field.state.value,
|
|
67
|
+
errorMessages: p.value,
|
|
68
|
+
error: !!p.value.length,
|
|
69
|
+
field: e.field,
|
|
70
|
+
setRealDirty: u,
|
|
71
|
+
type: m.value,
|
|
72
|
+
label: `${e.label}${e.meta?.required ? " *" : ""}`,
|
|
73
|
+
options: e.options
|
|
74
|
+
}));
|
|
75
|
+
return (t, R) => B(t.$slots, "default", I(O(i.value)), () => [
|
|
76
|
+
_("div", {
|
|
77
|
+
class: q(t.$attrs.class),
|
|
78
|
+
onFocusout: u
|
|
79
|
+
}, [
|
|
80
|
+
F(v) ? (S(), L(D, T({
|
|
81
|
+
key: 0,
|
|
82
|
+
"input-props": i.value
|
|
83
|
+
}, t.$attrs, {
|
|
84
|
+
"vuetify-value": i.value.field.state.value
|
|
85
|
+
}), null, 16, ["input-props", "vuetify-value"])) : P("", !0)
|
|
86
|
+
], 34)
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
11
90
|
export {
|
|
12
|
-
|
|
91
|
+
J as default
|
|
13
92
|
};
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { useStore as u } from "@tanstack/vue-form";
|
|
2
|
+
import { computed as f } from "vue";
|
|
3
|
+
function c(o, t) {
|
|
4
|
+
return f(() => t ? u(o.store, (n) => {
|
|
5
|
+
const r = {};
|
|
6
|
+
for (const e of t)
|
|
7
|
+
r[e] = n[e];
|
|
8
|
+
return r;
|
|
9
|
+
}).value : {});
|
|
10
|
+
}
|
|
2
11
|
export {
|
|
3
|
-
|
|
12
|
+
c as getOmegaStore
|
|
4
13
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineComponent as d, inject as f, computed as r, createBlock as n, openBlock as m, resolveDynamicComponent as c, withCtx as l, createCommentVNode as v, mergeProps as y, renderSlot as g, normalizeProps as h, guardReactiveProps as b } from "vue";
|
|
2
2
|
import { generateInputStandardSchemaFromFieldMeta as C } from "./vue-components.es10.js";
|
|
3
|
-
import F from "./vue-components.
|
|
3
|
+
import F from "./vue-components.es24.js";
|
|
4
4
|
const P = /* @__PURE__ */ d({
|
|
5
5
|
inheritAttrs: !1,
|
|
6
6
|
__name: "OmegaInput",
|
package/package.json
CHANGED
|
@@ -66,20 +66,20 @@
|
|
|
66
66
|
*/
|
|
67
67
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
68
68
|
import { type StandardSchemaV1Issue, useStore } from "@tanstack/vue-form"
|
|
69
|
-
import { type S } from "effect-app"
|
|
70
|
-
import { computed, onBeforeMount, watch } from "vue"
|
|
69
|
+
import { type Record, type S } from "effect-app"
|
|
70
|
+
import { computed, getCurrentInstance, onBeforeMount, watch } from "vue"
|
|
71
71
|
import { getOmegaStore } from "./getOmegaStore"
|
|
72
72
|
import { provideOmegaErrors } from "./OmegaErrorsContext"
|
|
73
73
|
import { type FilterItems, type FormProps, type OmegaFormApi, type OmegaFormState, type ShowErrorsOn } from "./OmegaFormStuff"
|
|
74
74
|
import { type OmegaConfig, type OmegaFormReturn, useOmegaForm } from "./useOmegaForm"
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
type OmegaWrapperProps =
|
|
77
77
|
& {
|
|
78
78
|
omegaConfig?: OmegaConfig<From>
|
|
79
79
|
subscribe?: K[]
|
|
80
80
|
showErrorsOn?: ShowErrorsOn
|
|
81
81
|
}
|
|
82
|
-
& FormProps<From, To>
|
|
82
|
+
& Omit<FormProps<From, To>, "onSubmit">
|
|
83
83
|
& (
|
|
84
84
|
| {
|
|
85
85
|
form: OmegaFormReturn<From, To>
|
|
@@ -90,16 +90,53 @@ const props = defineProps<
|
|
|
90
90
|
schema: S.Schema<To, From, never>
|
|
91
91
|
}
|
|
92
92
|
)
|
|
93
|
-
|
|
93
|
+
& (
|
|
94
|
+
| {
|
|
95
|
+
isLoading?: undefined
|
|
96
|
+
onSubmit?: FormProps<From, To>["onSubmit"]
|
|
97
|
+
}
|
|
98
|
+
| {
|
|
99
|
+
isLoading: boolean
|
|
100
|
+
onSubmit: (data: To) => void
|
|
101
|
+
}
|
|
102
|
+
)
|
|
94
103
|
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
return undefined
|
|
98
|
-
}
|
|
99
|
-
return useOmegaForm<From, To>(props.schema, props, props.omegaConfig)
|
|
104
|
+
const props = withDefaults(defineProps<OmegaWrapperProps>(), {
|
|
105
|
+
isLoading: undefined
|
|
100
106
|
})
|
|
101
107
|
|
|
102
|
-
const
|
|
108
|
+
const instance = getCurrentInstance()
|
|
109
|
+
|
|
110
|
+
// we prefer to use the standard abstraction in Vue which separates props (going down) and event emits (going back up)
|
|
111
|
+
// so if isLoading + @submit are provided, we wrap them into a Promise, so that TanStack Form can properly track the submitting state.
|
|
112
|
+
// we use this approach because it means we can keep relying on the built-in beaviour of TanStack Form, and we dont have to re-implement/keep in sync/break any internals.
|
|
113
|
+
const eventOnSubmit: FormProps<From, To>["onSubmit"] = ({ value }) => {
|
|
114
|
+
new Promise<void>((resolve) => {
|
|
115
|
+
instance!.emit("submit", value)
|
|
116
|
+
// even if the emit would be immediately handled, prop changes are not published/received immediately.
|
|
117
|
+
// so we have to wait for the prop to change to true, and back to false again.
|
|
118
|
+
const handle = watch(() => props.isLoading, (v) => {
|
|
119
|
+
if (v) return
|
|
120
|
+
resolve()
|
|
121
|
+
handle.stop()
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const localForm = props.form || !props.schema
|
|
127
|
+
? undefined
|
|
128
|
+
: useOmegaForm<From, To>(
|
|
129
|
+
props.schema,
|
|
130
|
+
{
|
|
131
|
+
...props,
|
|
132
|
+
onSubmit: typeof props.isLoading !== "undefined"
|
|
133
|
+
? eventOnSubmit
|
|
134
|
+
: props.onSubmit
|
|
135
|
+
},
|
|
136
|
+
props.omegaConfig
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
const formToUse = computed(() => props.form ?? localForm!)
|
|
103
140
|
|
|
104
141
|
onBeforeMount(() => {
|
|
105
142
|
if (!props.form) return
|
|
@@ -116,17 +153,22 @@ onBeforeMount(() => {
|
|
|
116
153
|
|
|
117
154
|
const filteredProps = Object.fromEntries(
|
|
118
155
|
Object.entries(props).filter(
|
|
119
|
-
([key, value]) =>
|
|
120
|
-
|
|
156
|
+
([key, value]) => {
|
|
157
|
+
if (key === "isLoading") {
|
|
158
|
+
return false
|
|
159
|
+
}
|
|
160
|
+
return !excludedKeys.has(key as keyof typeof props)
|
|
161
|
+
&& value !== undefined
|
|
162
|
+
}
|
|
121
163
|
)
|
|
122
|
-
) as
|
|
164
|
+
) as Record<string, unknown>
|
|
123
165
|
|
|
124
166
|
const propsKeys = Object.keys(filteredProps)
|
|
125
167
|
|
|
126
168
|
const overlappingKeys = formOptionsKeys.filter(
|
|
127
169
|
(key) =>
|
|
128
170
|
propsKeys.includes(key)
|
|
129
|
-
&& filteredProps[key
|
|
171
|
+
&& filteredProps[key] !== undefined
|
|
130
172
|
)
|
|
131
173
|
|
|
132
174
|
if (overlappingKeys.length > 0) {
|
|
@@ -227,5 +269,9 @@ defineSlots<{
|
|
|
227
269
|
<style scoped>
|
|
228
270
|
fieldset {
|
|
229
271
|
display: contents;
|
|
272
|
+
|
|
273
|
+
&[disabled] > * {
|
|
274
|
+
pointer-events: none;
|
|
275
|
+
}
|
|
230
276
|
}
|
|
231
277
|
</style>
|