@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.
Files changed (41) hide show
  1. package/dist/types/components/OmegaForm/OmegaFormStuff.d.ts +1 -1
  2. package/dist/types/components/OmegaForm/OmegaInternalInput.vue.d.ts +2 -2
  3. package/dist/vue-components.es10.js +148 -145
  4. package/dist/vue-components.es16.js +1 -1
  5. package/dist/vue-components.es17.js +1 -1
  6. package/dist/vue-components.es20.js +2 -2
  7. package/dist/vue-components.es21.js +2 -2
  8. package/dist/vue-components.es22.js +1 -1
  9. package/dist/vue-components.es23.js +1 -1
  10. package/dist/vue-components.es30.js +41 -135
  11. package/dist/vue-components.es31.js +4 -0
  12. package/dist/vue-components.es32.js +2 -42
  13. package/dist/vue-components.es33.js +89 -2
  14. package/dist/vue-components.es35.js +7 -89
  15. package/dist/vue-components.es36.js +34 -0
  16. package/dist/vue-components.es38.js +131 -27
  17. package/dist/vue-components.es40.js +1 -1
  18. package/dist/vue-components.es41.js +22 -10
  19. package/dist/vue-components.es42.js +5 -23
  20. package/dist/vue-components.es43.js +21 -5
  21. package/dist/vue-components.es44.js +25 -16
  22. package/dist/vue-components.es45.js +15 -23
  23. package/dist/vue-components.es46.js +7 -17
  24. package/dist/vue-components.es47.js +5 -12
  25. package/dist/vue-components.es48.js +19 -5
  26. package/dist/vue-components.es49.js +9 -19
  27. package/dist/vue-components.es50.js +31 -9
  28. package/dist/vue-components.es51.js +42 -25
  29. package/dist/vue-components.es52.js +16 -38
  30. package/dist/vue-components.es53.js +11 -26
  31. package/dist/vue-components.es54.js +1 -1
  32. package/dist/vue-components.es56.js +1 -1
  33. package/dist/vue-components.es58.js +3 -3
  34. package/dist/vue-components.es59.js +1 -1
  35. package/dist/vue-components.es7.js +24 -32
  36. package/package.json +1 -1
  37. package/src/components/OmegaForm/OmegaFormStuff.ts +2 -1
  38. package/src/components/OmegaForm/OmegaInternalInput.vue +4 -31
  39. package/src/components/OmegaForm/useOmegaForm.ts +41 -6
  40. package/dist/vue-components.es34.js +0 -4
  41. 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 C, computed as a, getCurrentInstance as x, useId as V, onMounted as _, renderSlot as P, normalizeProps as m, guardReactiveProps as M, createElementVNode as N, normalizeClass as $, createBlock as q, createCommentVNode as B, unref as O, openBlock as k, mergeProps as I } from "vue";
3
- import { useStore as L } from "@tanstack/vue-form";
4
- import S from "./vue-components.es30.js";
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 E = /* @__PURE__ */ C({
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(d) {
21
- const e = d, i = a(() => e.required ?? e?.meta?.required), f = x()?.appContext.components.VTextField, o = V(), r = e.field, s = L(r.store, (t) => t), p = a(() => e.type ? e.type : e.meta?.type === "string" ? e.meta.format === "email" ? "email" : "string" : e.meta?.type || "unknown");
22
- e.register(a(() => ({ name: e.field.name, label: e.label, id: o })));
23
- const c = a(() => s.value.value), g = a(() => s.value.meta.errors ?? []), u = a(
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
- g.value.map((t) => t?.message).filter(Boolean)
26
+ c.value.map((t) => t?.message).filter(Boolean)
27
27
  )
28
- ), v = (t) => t == null || t === !1 || t === "" || Number.isNaN(t), y = (t) => {
29
- v(t) && e.meta?.type !== "boolean" && e.meta?.nullableOrUndefined ? e.field.handleChange(
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(F, b, R) {
43
- return b === "handleChange" ? y : Reflect.get(...arguments);
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
- }, l = a(() => ({
39
+ }, a = r(() => ({
48
40
  inputProps: {
49
- id: o,
50
- required: i.value,
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: u.value,
56
- error: !!u.value.length,
57
- type: p.value,
58
- label: `${e.label}${i.value ? " *" : ""}`,
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) => P(t.$slots, "default", m(M({ ...l.value.inputProps, field: l.value.field, state: l.value.state })), () => [
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
- O(f) ? (k(), q(S, m(I({ key: 0 }, { ...t.$attrs, ...l.value })), null, 16)) : B("", !0)
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
- E as default
66
+ U as default
75
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "effect": "^3.18.0",
@@ -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
- name: TName & FlexibleArrayPath<Leaves<From>>
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, type DeepValue, useStore } from "@tanstack/vue-form"
18
- import { computed, type ComputedRef, getCurrentInstance, onMounted, useId } from "vue"
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
- // TODO: it would be cleaner when default values are handled in the form initialization via Schema or by the one using the form component..
116
- onMounted(() => {
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
- tanstackFormOptions?.defaultValues
824
+ normalizedTanstackDefaults
789
825
  && !omegaConfig?.persistency?.overrideDefaultValues
790
826
  ) {
791
827
  // defaultValues from tanstack are not partial,
792
- // so if ovverrideDefaultValues is false we simply return them
793
- return tanstackFormOptions?.defaultValues
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 (tanstackFormOptions?.defaultValues == undefined) {
878
+ if (!normalizedTanstackDefaults) {
843
879
  // we just return what we gathered from the query/storage
844
880
  return defValuesPatch
845
881
  } else {
846
- const startingDefValues = tanstackFormOptions?.defaultValues
847
- return deepMerge(startingDefValues, defValuesPatch)
882
+ return deepMerge(normalizedTanstackDefaults, defValuesPatch)
848
883
  }
849
884
  })
850
885
 
@@ -1,4 +0,0 @@
1
- import f from "./vue-components.es19.js";
2
- export {
3
- f as default
4
- };
@@ -1,9 +0,0 @@
1
- const s = (t, e) => {
2
- const o = t.__vccOpts || t;
3
- for (const [r, c] of e)
4
- o[r] = c;
5
- return o;
6
- };
7
- export {
8
- s as default
9
- };