@effect-app/vue-components 2.1.4 → 2.1.6
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/OmegaFormStuff.d.ts +1 -1
- package/dist/types/components/OmegaForm/OmegaInternalInput.vue.d.ts +2 -2
- package/dist/vue-components.es10.js +148 -145
- package/dist/vue-components.es16.js +1 -1
- package/dist/vue-components.es17.js +1 -1
- package/dist/vue-components.es20.js +2 -2
- package/dist/vue-components.es21.js +2 -2
- package/dist/vue-components.es22.js +1 -1
- package/dist/vue-components.es23.js +1 -1
- package/dist/vue-components.es30.js +41 -135
- package/dist/vue-components.es31.js +4 -0
- package/dist/vue-components.es32.js +2 -42
- package/dist/vue-components.es33.js +89 -2
- package/dist/vue-components.es35.js +7 -89
- package/dist/vue-components.es36.js +34 -0
- package/dist/vue-components.es38.js +131 -27
- package/dist/vue-components.es40.js +1 -1
- package/dist/vue-components.es41.js +22 -10
- package/dist/vue-components.es42.js +5 -23
- package/dist/vue-components.es43.js +21 -5
- package/dist/vue-components.es44.js +25 -16
- package/dist/vue-components.es45.js +15 -23
- package/dist/vue-components.es46.js +7 -17
- package/dist/vue-components.es47.js +5 -12
- package/dist/vue-components.es48.js +19 -5
- package/dist/vue-components.es49.js +9 -19
- package/dist/vue-components.es50.js +31 -9
- package/dist/vue-components.es51.js +42 -25
- package/dist/vue-components.es52.js +16 -38
- package/dist/vue-components.es53.js +11 -26
- package/dist/vue-components.es54.js +1 -1
- package/dist/vue-components.es56.js +1 -1
- package/dist/vue-components.es58.js +3 -3
- package/dist/vue-components.es59.js +1 -1
- package/dist/vue-components.es7.js +24 -32
- package/package.json +1 -1
- package/src/components/OmegaForm/OmegaFormStuff.ts +2 -1
- package/src/components/OmegaForm/OmegaInternalInput.vue +4 -31
- package/src/components/OmegaForm/useOmegaForm.ts +41 -6
- package/dist/vue-components.es34.js +0 -4
- package/dist/vue-components.es37.js +0 -9
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
(function(){"use strict";try{if(typeof document<"u"){var i=document.createElement("style");if(i.appendChild(document.createTextNode(".omega-input .v-input__details:has(.v-messages:empty){grid-template-rows:0fr;transition:all .2s}.omega-input .v-messages:empty{min-height:0}.omega-input .v-input__details:has(.v-messages){transition:all .2s;overflow:hidden;min-height:0;display:grid;grid-template-rows:1fr}.omega-input .v-messages{transition:all .2s}.omega-input .v-messages>*{transition-duration:0s!important}.omega-input [role=alert]:has(.v-messages:empty){padding:0}.omega-input .v-btn{cursor:pointer;width:auto;appearance:none;box-shadow:none;display:block;min-width:auto;height:auto;padding:.5em .5em .5em 1em}")),document.head.appendChild(i),window.customElements){const e=window.customElements.define;window.customElements.define=function(s,t){const n=t.prototype.connectedCallback;return t.prototype.connectedCallback=function(){if(n&&n.call(this),this.shadowRoot){const a=document.createElement("style");a.appendChild(document.createTextNode(".omega-input .v-input__details:has(.v-messages:empty){grid-template-rows:0fr;transition:all .2s}.omega-input .v-messages:empty{min-height:0}.omega-input .v-input__details:has(.v-messages){transition:all .2s;overflow:hidden;min-height:0;display:grid;grid-template-rows:1fr}.omega-input .v-messages{transition:all .2s}.omega-input .v-messages>*{transition-duration:0s!important}.omega-input [role=alert]:has(.v-messages:empty){padding:0}.omega-input .v-btn{cursor:pointer;width:auto;appearance:none;box-shadow:none;display:block;min-width:auto;height:auto;padding:.5em .5em .5em 1em}")),this.shadowRoot.appendChild(a)}},e.call(window.customElements,s,t)}}}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
|
|
2
|
-
import { defineComponent as
|
|
3
|
-
import { useStore as
|
|
4
|
-
import S from "./vue-components.
|
|
2
|
+
import { defineComponent as b, computed as r, getCurrentInstance as C, useId as x, renderSlot as _, normalizeProps as m, guardReactiveProps as P, createElementVNode as N, normalizeClass as $, createBlock as q, createCommentVNode as B, unref as k, openBlock as I, mergeProps as L } from "vue";
|
|
3
|
+
import { useStore as M } from "@tanstack/vue-form";
|
|
4
|
+
import S from "./vue-components.es38.js";
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const U = /* @__PURE__ */ b({
|
|
7
7
|
inheritAttrs: !1,
|
|
8
8
|
__name: "OmegaInternalInput",
|
|
9
9
|
props: {
|
|
@@ -17,59 +17,51 @@ const E = /* @__PURE__ */ C({
|
|
|
17
17
|
register: {},
|
|
18
18
|
options: { default: void 0 }
|
|
19
19
|
},
|
|
20
|
-
setup(
|
|
21
|
-
const e =
|
|
22
|
-
e.register(
|
|
23
|
-
const c =
|
|
20
|
+
setup(u) {
|
|
21
|
+
const e = u, o = r(() => e.required ?? e?.meta?.required), d = C()?.appContext.components.VTextField, l = x(), p = e.field, i = M(p.store, (t) => t), f = r(() => e.type ? e.type : e.meta?.type === "string" ? e.meta.format === "email" ? "email" : "string" : e.meta?.type || "unknown");
|
|
22
|
+
e.register(r(() => ({ name: e.field.name, label: e.label, id: l }))), r(() => i.value.value);
|
|
23
|
+
const c = r(() => i.value.meta.errors ?? []), s = r(
|
|
24
24
|
() => (
|
|
25
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
|
|
26
|
+
c.value.map((t) => t?.message).filter(Boolean)
|
|
27
27
|
)
|
|
28
|
-
),
|
|
29
|
-
|
|
28
|
+
), g = (t) => t == null || t === !1 || t === "" || Number.isNaN(t), v = (t) => {
|
|
29
|
+
g(t) && e.meta?.type !== "boolean" && e.meta?.nullableOrUndefined ? e.field.handleChange(
|
|
30
30
|
e.meta.nullableOrUndefined === "undefined" ? void 0 : null
|
|
31
31
|
) : e.field.handleChange(t), e.field.setMeta((n) => ({ ...n, errorMap: { ...n.errorMap, onSubmit: void 0 } }));
|
|
32
|
-
}
|
|
33
|
-
_(() => {
|
|
34
|
-
if (c.value === void 0) {
|
|
35
|
-
const t = s.value.meta.isDirty;
|
|
36
|
-
if (r.setMeta((n) => ({ ...n, isDirty: t })), i.value) return;
|
|
37
|
-
e.meta?.nullableOrUndefined === "null" ? r.setValue(null) : e.meta?.nullableOrUndefined === "undefined" ? r.setValue(void 0) : e.meta?.type === "string" ? r.setValue("") : e.meta?.type === "number" || e.meta?.type === "boolean" && r.setValue(!1);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
const h = (t) => {
|
|
32
|
+
}, h = (t) => {
|
|
41
33
|
const n = {
|
|
42
|
-
get(
|
|
43
|
-
return
|
|
34
|
+
get(O, y, R) {
|
|
35
|
+
return y === "handleChange" ? v : Reflect.get(...arguments);
|
|
44
36
|
}
|
|
45
37
|
};
|
|
46
38
|
return new Proxy(t, n);
|
|
47
|
-
},
|
|
39
|
+
}, a = r(() => ({
|
|
48
40
|
inputProps: {
|
|
49
|
-
id:
|
|
50
|
-
required:
|
|
41
|
+
id: l,
|
|
42
|
+
required: o.value,
|
|
51
43
|
minLength: e.meta?.type === "string" && e.meta?.minLength,
|
|
52
44
|
maxLength: e.meta?.type === "string" && e.meta?.maxLength,
|
|
53
45
|
max: e.meta?.type === "number" && e.meta?.maximum,
|
|
54
46
|
min: e.meta?.type === "number" && e.meta?.minimum,
|
|
55
|
-
errorMessages:
|
|
56
|
-
error: !!
|
|
57
|
-
type:
|
|
58
|
-
label: `${e.label}${
|
|
47
|
+
errorMessages: s.value,
|
|
48
|
+
error: !!s.value.length,
|
|
49
|
+
type: f.value,
|
|
50
|
+
label: `${e.label}${o.value ? " *" : ""}`,
|
|
59
51
|
options: e.options
|
|
60
52
|
},
|
|
61
53
|
state: e.state,
|
|
62
54
|
field: h(e.field)
|
|
63
55
|
}));
|
|
64
|
-
return (t, n) =>
|
|
56
|
+
return (t, n) => _(t.$slots, "default", m(P({ ...a.value.inputProps, field: a.value.field, state: a.value.state })), () => [
|
|
65
57
|
N("div", {
|
|
66
58
|
class: $(t.$attrs.class)
|
|
67
59
|
}, [
|
|
68
|
-
|
|
60
|
+
k(d) ? (I(), q(S, m(L({ key: 0 }, { ...t.$attrs, ...a.value })), null, 16)) : B("", !0)
|
|
69
61
|
], 2)
|
|
70
62
|
]);
|
|
71
63
|
}
|
|
72
64
|
});
|
|
73
65
|
export {
|
|
74
|
-
|
|
66
|
+
U as default
|
|
75
67
|
};
|
package/package.json
CHANGED
|
@@ -23,7 +23,8 @@ export type BaseProps<From, TName extends DeepKeys<From> = DeepKeys<From>> = {
|
|
|
23
23
|
/** Will fallback to i18n when not specified */
|
|
24
24
|
label?: string
|
|
25
25
|
validators?: FieldValidators<From>
|
|
26
|
-
|
|
26
|
+
// disabled FlexibleArrayPath as it causes excessive complexity in type resolution inside user projects
|
|
27
|
+
name: TName // & FlexibleArrayPath<Leaves<From>>
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export type TypesWithOptions = "radio" | "select" | "multiple" | "autocomplete" | "autocompletemultiple"
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
lang="ts"
|
|
15
15
|
generic="From extends Record<PropertyKey, any>, Name extends DeepKeys<From>"
|
|
16
16
|
>
|
|
17
|
-
import { type DeepKeys,
|
|
18
|
-
import { computed, type ComputedRef, getCurrentInstance,
|
|
17
|
+
import { type DeepKeys, useStore } from "@tanstack/vue-form"
|
|
18
|
+
import { computed, type ComputedRef, getCurrentInstance, useId } from "vue"
|
|
19
19
|
import type { InputProps, OmegaFieldInternalApi } from "./InputProps"
|
|
20
20
|
import type { FieldValidators, MetaRecord, NestedKeyOf, TypeOverride } from "./OmegaFormStuff"
|
|
21
21
|
import OmegaInputVuetify from "./OmegaInputVuetify.vue"
|
|
@@ -112,35 +112,8 @@ const handleChange: OmegaFieldInternalApi<From, Name>["handleChange"] = (value)
|
|
|
112
112
|
props.field.setMeta((m) => ({ ...m, errorMap: { ...m.errorMap, onSubmit: undefined } }))
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
// Initialize field value on mount if it doesn't exist
|
|
118
|
-
if (fieldValue.value === undefined) {
|
|
119
|
-
const isDirty = fieldState.value.meta.isDirty
|
|
120
|
-
// make sure we restore the previous dirty state..
|
|
121
|
-
fieldApi.setMeta((_) => ({ ..._, isDirty }))
|
|
122
|
-
|
|
123
|
-
if (isRequired.value) return
|
|
124
|
-
|
|
125
|
-
// Set appropriate default value based on field type and nullability
|
|
126
|
-
if (props.meta?.nullableOrUndefined === "null") {
|
|
127
|
-
fieldApi.setValue(null as DeepValue<From, Name>)
|
|
128
|
-
} else if (props.meta?.nullableOrUndefined === "undefined") {
|
|
129
|
-
fieldApi.setValue(undefined as DeepValue<From, Name>)
|
|
130
|
-
} else {
|
|
131
|
-
// For required fields, initialize with appropriate empty value
|
|
132
|
-
if (props.meta?.type === "string") {
|
|
133
|
-
fieldApi.setValue("" as DeepValue<From, Name>)
|
|
134
|
-
} else if (props.meta?.type === "number") {
|
|
135
|
-
// Don't initialize number fields to avoid setting them to 0
|
|
136
|
-
// Leave as undefined so validation will catch it
|
|
137
|
-
} else if (props.meta?.type === "boolean") {
|
|
138
|
-
fieldApi.setValue(false as DeepValue<From, Name>)
|
|
139
|
-
}
|
|
140
|
-
// For other types, leave undefined so validation will catch missing required fields
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
})
|
|
115
|
+
// Note: Default value normalization (converting empty strings to null/undefined for nullable fields)
|
|
116
|
+
// is now handled at the form level in useOmegaForm, not here in the component
|
|
144
117
|
|
|
145
118
|
const wrapField = (field: OmegaFieldInternalApi<From, Name>) => {
|
|
146
119
|
const handler3 = {
|
|
@@ -783,14 +783,50 @@ export const useOmegaForm = <
|
|
|
783
783
|
return target
|
|
784
784
|
}
|
|
785
785
|
|
|
786
|
+
// Normalize default values based on schema metadata
|
|
787
|
+
// Convert empty strings to null/undefined for nullable fields
|
|
788
|
+
// Also initialize missing nullable fields with null/undefined
|
|
789
|
+
const normalizeDefaultValues = (values: Partial<From>): Partial<From> => {
|
|
790
|
+
const normalized: any = { ...values }
|
|
791
|
+
|
|
792
|
+
// Process all fields in the schema metadata
|
|
793
|
+
for (const key in meta) {
|
|
794
|
+
const fieldMeta = meta[key as keyof typeof meta]
|
|
795
|
+
const value = normalized[key]
|
|
796
|
+
|
|
797
|
+
// Check if the value is falsy (but not boolean false or zero)
|
|
798
|
+
const isFalsyButNotZero = value == null || value === false || value === "" || Number.isNaN(value)
|
|
799
|
+
const isFalsy = isFalsyButNotZero && value !== false && value !== 0
|
|
800
|
+
|
|
801
|
+
if (
|
|
802
|
+
fieldMeta
|
|
803
|
+
&& !fieldMeta.required
|
|
804
|
+
&& fieldMeta.nullableOrUndefined
|
|
805
|
+
&& fieldMeta.type !== "boolean"
|
|
806
|
+
) {
|
|
807
|
+
// If value is missing or falsy, set to null or undefined based on schema
|
|
808
|
+
if (value === undefined || isFalsy) {
|
|
809
|
+
normalized[key] = fieldMeta.nullableOrUndefined === "undefined" ? undefined : null
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
return normalized
|
|
815
|
+
}
|
|
816
|
+
|
|
786
817
|
const defaultValues = computed(() => {
|
|
818
|
+
// Normalize tanstack default values at the beginning
|
|
819
|
+
const normalizedTanstackDefaults = tanstackFormOptions?.defaultValues
|
|
820
|
+
? normalizeDefaultValues(tanstackFormOptions.defaultValues)
|
|
821
|
+
: undefined
|
|
822
|
+
|
|
787
823
|
if (
|
|
788
|
-
|
|
824
|
+
normalizedTanstackDefaults
|
|
789
825
|
&& !omegaConfig?.persistency?.overrideDefaultValues
|
|
790
826
|
) {
|
|
791
827
|
// defaultValues from tanstack are not partial,
|
|
792
|
-
// so if ovverrideDefaultValues is false we
|
|
793
|
-
return
|
|
828
|
+
// so if ovverrideDefaultValues is false we return the normalized values
|
|
829
|
+
return normalizedTanstackDefaults
|
|
794
830
|
}
|
|
795
831
|
|
|
796
832
|
// we are here because there are no default values from tankstack
|
|
@@ -839,12 +875,11 @@ export const useOmegaForm = <
|
|
|
839
875
|
// to be sure we have a valid object at the end of the gathering process
|
|
840
876
|
defValuesPatch ??= {}
|
|
841
877
|
|
|
842
|
-
if (
|
|
878
|
+
if (!normalizedTanstackDefaults) {
|
|
843
879
|
// we just return what we gathered from the query/storage
|
|
844
880
|
return defValuesPatch
|
|
845
881
|
} else {
|
|
846
|
-
|
|
847
|
-
return deepMerge(startingDefValues, defValuesPatch)
|
|
882
|
+
return deepMerge(normalizedTanstackDefaults, defValuesPatch)
|
|
848
883
|
}
|
|
849
884
|
})
|
|
850
885
|
|