@effect-app/vue-components 0.15.29 → 0.17.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 +2 -2
- package/dist/vue-components.es20.js +72 -58
- package/dist/vue-components.es22.js +1 -1
- package/dist/vue-components.es23.js +2 -90
- package/dist/vue-components.es25.js +90 -2
- package/dist/vue-components.es26.js +1 -1
- package/dist/vue-components.es7.js +1 -1
- package/package.json +3 -3
- package/src/components/OmegaForm/OmegaWrapper.vue +63 -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-34631bd6]{display:contents}fieldset[disabled][data-v-34631bd6]>*{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-34631bd6]{display:contents}fieldset[disabled][data-v-34631bd6]>*{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 m = /* @__PURE__ */ r(o, [["__scopeId", "data-v-
|
|
5
|
+
const m = /* @__PURE__ */ r(o, [["__scopeId", "data-v-34631bd6"]]);
|
|
6
6
|
export {
|
|
7
7
|
m 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 c, watch as b, onBeforeMount as B, createElementBlock as v, openBlock as g, withModifiers as C, createElementVNode as I, unref as m, renderSlot as d, 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.es24.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,113 @@ 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 = c(
|
|
27
|
+
() => ({ value: e }) => {
|
|
28
|
+
new Promise((r) => {
|
|
29
|
+
h.emit("submit", e);
|
|
30
|
+
const n = b(() => o.isLoading, (t) => {
|
|
31
|
+
t || (r(), n.stop());
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
), u = o.form || !o.schema ? void 0 : A(
|
|
36
|
+
o.schema,
|
|
37
|
+
{
|
|
38
|
+
...o,
|
|
39
|
+
onSubmit: typeof o.isLoading < "u" ? y.value : o.onSubmit
|
|
40
|
+
},
|
|
41
|
+
o.omegaConfig
|
|
42
|
+
), s = c(() => o.form ?? u);
|
|
43
|
+
B(() => {
|
|
30
44
|
if (!o.form) return;
|
|
31
|
-
const e = Object.keys(o.form.options || {}),
|
|
45
|
+
const e = Object.keys(o.form.options || {}), r = /* @__PURE__ */ new Set([
|
|
32
46
|
"omegaConfig",
|
|
33
47
|
"subscribe",
|
|
34
48
|
"showErrorsOn",
|
|
35
49
|
"asyncAlways",
|
|
36
50
|
"form",
|
|
37
51
|
"schema"
|
|
38
|
-
]),
|
|
52
|
+
]), n = Object.fromEntries(
|
|
39
53
|
Object.entries(o).filter(
|
|
40
|
-
([a,
|
|
54
|
+
([a, f]) => a === "isLoading" ? !1 : !r.has(a) && f !== void 0
|
|
41
55
|
)
|
|
42
|
-
),
|
|
43
|
-
(a) =>
|
|
56
|
+
), t = Object.keys(n), i = e.filter(
|
|
57
|
+
(a) => t.includes(a) && n[a] !== void 0
|
|
44
58
|
);
|
|
45
|
-
|
|
59
|
+
i.length > 0 && console.warn(
|
|
46
60
|
`[OmegaWrapper] Overlapping keys found between form options and filtered props:
|
|
47
|
-
${
|
|
61
|
+
${i.join(
|
|
48
62
|
`,
|
|
49
63
|
`
|
|
50
64
|
)}.
|
|
51
65
|
Props will overwrite existing form options. This might indicate a configuration issue.`
|
|
52
66
|
);
|
|
53
|
-
const
|
|
54
|
-
...
|
|
55
|
-
...
|
|
67
|
+
const j = {
|
|
68
|
+
...s.value.options,
|
|
69
|
+
...n
|
|
56
70
|
};
|
|
57
|
-
|
|
71
|
+
s.value.options = Object.fromEntries(
|
|
58
72
|
// TODO
|
|
59
|
-
Object.entries(
|
|
60
|
-
([a,
|
|
73
|
+
Object.entries(j).filter(
|
|
74
|
+
([a, f]) => f !== void 0
|
|
61
75
|
)
|
|
62
76
|
);
|
|
63
77
|
});
|
|
64
|
-
const
|
|
65
|
-
|
|
78
|
+
const w = O(
|
|
79
|
+
s.value.store,
|
|
66
80
|
(e) => e.isSubmitting
|
|
67
|
-
),
|
|
68
|
-
|
|
81
|
+
), p = k(
|
|
82
|
+
s.value,
|
|
69
83
|
o.subscribe
|
|
70
|
-
),
|
|
71
|
-
|
|
84
|
+
), E = O(
|
|
85
|
+
s.value.store,
|
|
72
86
|
(e) => e.submissionAttempts
|
|
73
|
-
), l =
|
|
74
|
-
return
|
|
75
|
-
() => [
|
|
87
|
+
), l = c(() => s.value.useStore((e) => e.errors));
|
|
88
|
+
return b(
|
|
89
|
+
() => [s.value.filterItems, l.value.value],
|
|
76
90
|
() => {
|
|
77
|
-
const e =
|
|
78
|
-
return e ?
|
|
79
|
-
(
|
|
91
|
+
const e = s.value.filterItems, r = l.value.value;
|
|
92
|
+
return e ? r ? (Object.values(r).filter(
|
|
93
|
+
(t) => !!t
|
|
80
94
|
).flatMap(
|
|
81
|
-
(
|
|
82
|
-
).some((
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
...
|
|
95
|
+
(t) => Object.values(t).flat().map((i) => i.message)
|
|
96
|
+
).some((t) => t === e.message) && e.items.forEach((t) => {
|
|
97
|
+
const i = s.value.getFieldMeta(t);
|
|
98
|
+
i && s.value.setFieldMeta(t, {
|
|
99
|
+
...i,
|
|
86
100
|
errorMap: {
|
|
87
101
|
onSubmit: [
|
|
88
|
-
{ path: [
|
|
102
|
+
{ path: [t], message: e.message }
|
|
89
103
|
]
|
|
90
104
|
}
|
|
91
105
|
});
|
|
92
106
|
}), {}) : {} : {};
|
|
93
107
|
}
|
|
94
|
-
),
|
|
108
|
+
), $(E, l.value, o.showErrorsOn), (e, r) => (g(), v("form", {
|
|
95
109
|
novalidate: "",
|
|
96
|
-
onSubmit:
|
|
110
|
+
onSubmit: r[0] || (r[0] = C((n) => s.value.handleSubmit(), ["prevent", "stop"]))
|
|
97
111
|
}, [
|
|
98
|
-
|
|
99
|
-
o.form ? (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
], 64)) : m
|
|
112
|
+
I("fieldset", { disabled: m(w) }, [
|
|
113
|
+
o.form ? (g(), v(V, { key: 0 }, [
|
|
114
|
+
d(e.$slots, "externalForm", { subscribedValues: m(p) }, void 0, !0),
|
|
115
|
+
d(e.$slots, "default", {}, void 0, !0)
|
|
116
|
+
], 64)) : m(u) ? d(e.$slots, "internalForm", {
|
|
103
117
|
key: 1,
|
|
104
|
-
form: m
|
|
105
|
-
subscribedValues:
|
|
106
|
-
}, void 0, !0) :
|
|
107
|
-
], 8,
|
|
118
|
+
form: m(u),
|
|
119
|
+
subscribedValues: m(p)
|
|
120
|
+
}, void 0, !0) : L("", !0)
|
|
121
|
+
], 8, K)
|
|
108
122
|
], 32));
|
|
109
123
|
}
|
|
110
124
|
});
|
|
111
125
|
export {
|
|
112
|
-
|
|
126
|
+
W as default
|
|
113
127
|
};
|
|
@@ -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,4 +1,92 @@
|
|
|
1
|
-
const
|
|
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
|
+
});
|
|
2
90
|
export {
|
|
3
|
-
|
|
91
|
+
J as default
|
|
4
92
|
};
|
|
@@ -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.es25.js";
|
|
4
4
|
const P = /* @__PURE__ */ d({
|
|
5
5
|
inheritAttrs: !1,
|
|
6
6
|
__name: "OmegaInput",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-app/vue-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@mdi/js": "^7.4.47",
|
|
6
6
|
"@tanstack/vue-form": "1.2.4",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"highlight.js": "^11.11.1",
|
|
55
55
|
"vue3-highlightjs": "^1.0.5",
|
|
56
|
-
"
|
|
57
|
-
"effect-app": "
|
|
56
|
+
"effect-app": "3.2.4",
|
|
57
|
+
"@effect-app/vue": "2.54.4"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "pnpm build:run",
|
|
@@ -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, type ComputedRef, 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,55 @@ 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: ComputedRef<FormProps<From, To>["onSubmit"]> = computed(
|
|
114
|
+
() => ({ value }) => {
|
|
115
|
+
new Promise<void>((resolve) => {
|
|
116
|
+
instance!.emit("submit", value)
|
|
117
|
+
// even if the emit would be immediately handled, prop changes are not published/received immediately.
|
|
118
|
+
// so we have to wait for the prop to change to true, and back to false again.
|
|
119
|
+
const handle = watch(() => props.isLoading, (v) => {
|
|
120
|
+
if (v) return
|
|
121
|
+
resolve()
|
|
122
|
+
handle.stop()
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
const localForm = props.form || !props.schema
|
|
129
|
+
? undefined
|
|
130
|
+
: useOmegaForm<From, To>(
|
|
131
|
+
props.schema,
|
|
132
|
+
{
|
|
133
|
+
...props,
|
|
134
|
+
onSubmit: typeof props.isLoading !== "undefined"
|
|
135
|
+
? eventOnSubmit.value
|
|
136
|
+
: props.onSubmit
|
|
137
|
+
},
|
|
138
|
+
props.omegaConfig
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
const formToUse = computed(() => props.form ?? localForm!)
|
|
103
142
|
|
|
104
143
|
onBeforeMount(() => {
|
|
105
144
|
if (!props.form) return
|
|
@@ -116,17 +155,22 @@ onBeforeMount(() => {
|
|
|
116
155
|
|
|
117
156
|
const filteredProps = Object.fromEntries(
|
|
118
157
|
Object.entries(props).filter(
|
|
119
|
-
([key, value]) =>
|
|
120
|
-
|
|
158
|
+
([key, value]) => {
|
|
159
|
+
if (key === "isLoading") {
|
|
160
|
+
return false
|
|
161
|
+
}
|
|
162
|
+
return !excludedKeys.has(key as keyof typeof props)
|
|
163
|
+
&& value !== undefined
|
|
164
|
+
}
|
|
121
165
|
)
|
|
122
|
-
) as
|
|
166
|
+
) as Record<string, unknown>
|
|
123
167
|
|
|
124
168
|
const propsKeys = Object.keys(filteredProps)
|
|
125
169
|
|
|
126
170
|
const overlappingKeys = formOptionsKeys.filter(
|
|
127
171
|
(key) =>
|
|
128
172
|
propsKeys.includes(key)
|
|
129
|
-
&& filteredProps[key
|
|
173
|
+
&& filteredProps[key] !== undefined
|
|
130
174
|
)
|
|
131
175
|
|
|
132
176
|
if (overlappingKeys.length > 0) {
|
|
@@ -227,5 +271,9 @@ defineSlots<{
|
|
|
227
271
|
<style scoped>
|
|
228
272
|
fieldset {
|
|
229
273
|
display: contents;
|
|
274
|
+
|
|
275
|
+
&[disabled] > * {
|
|
276
|
+
pointer-events: none;
|
|
277
|
+
}
|
|
230
278
|
}
|
|
231
279
|
</style>
|