@effect-app/vue-components 2.6.2 → 2.7.1

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 (51) hide show
  1. package/dist/types/components/OmegaForm/InputProps.d.ts +10 -4
  2. package/dist/types/components/OmegaForm/OmegaTaggedUnion.vue.d.ts +16 -9
  3. package/dist/types/components/OmegaForm/OmegaTaggedUnionInternal.vue.d.ts +2 -9
  4. package/dist/types/components/OmegaForm/useOmegaForm.d.ts +2 -1
  5. package/dist/vue-components.es10.js +231 -170
  6. package/dist/vue-components.es11.js +2 -2
  7. package/dist/vue-components.es12.js +137 -115
  8. package/dist/vue-components.es16.js +11 -10
  9. package/dist/vue-components.es17.js +10 -5
  10. package/dist/vue-components.es18.js +5 -55
  11. package/dist/vue-components.es19.js +50 -63
  12. package/dist/vue-components.es20.js +68 -6
  13. package/dist/vue-components.es21.js +4 -4
  14. package/dist/vue-components.es22.js +6 -3
  15. package/dist/vue-components.es23.js +3 -3
  16. package/dist/vue-components.es24.js +3 -2
  17. package/dist/vue-components.es25.js +1 -1
  18. package/dist/vue-components.es26.js +1 -1
  19. package/dist/vue-components.es27.js +1 -1
  20. package/dist/vue-components.es28.js +2 -17
  21. package/dist/vue-components.es29.js +16 -10
  22. package/dist/vue-components.es31.js +1 -1
  23. package/dist/vue-components.es32.js +1 -1
  24. package/dist/vue-components.es36.js +1 -1
  25. package/dist/vue-components.es40.js +4 -23
  26. package/dist/vue-components.es41.js +23 -5
  27. package/dist/vue-components.es42.js +5 -21
  28. package/dist/vue-components.es43.js +16 -25
  29. package/dist/vue-components.es44.js +23 -15
  30. package/dist/vue-components.es45.js +17 -7
  31. package/dist/vue-components.es46.js +12 -5
  32. package/dist/vue-components.es47.js +5 -19
  33. package/dist/vue-components.es48.js +19 -9
  34. package/dist/vue-components.es49.js +9 -31
  35. package/dist/vue-components.es5.js +1 -1
  36. package/dist/vue-components.es50.js +25 -42
  37. package/dist/vue-components.es51.js +38 -16
  38. package/dist/vue-components.es52.js +26 -11
  39. package/dist/vue-components.es53.js +11 -4
  40. package/dist/vue-components.es54.js +1 -1
  41. package/dist/vue-components.es56.js +1 -1
  42. package/dist/vue-components.es58.js +3 -3
  43. package/dist/vue-components.es59.js +1 -1
  44. package/dist/vue-components.es8.js +33 -41
  45. package/dist/vue-components.es9.js +7 -6
  46. package/package.json +3 -3
  47. package/src/components/OmegaForm/InputProps.ts +17 -8
  48. package/src/components/OmegaForm/OmegaFormStuff.ts +52 -0
  49. package/src/components/OmegaForm/OmegaTaggedUnion.vue +27 -39
  50. package/src/components/OmegaForm/OmegaTaggedUnionInternal.vue +4 -3
  51. package/src/components/OmegaForm/useOmegaForm.ts +139 -10
@@ -16,6 +16,86 @@ import OmegaInput from "./OmegaInput.vue"
16
16
  import OmegaTaggedUnion from "./OmegaTaggedUnion.vue"
17
17
  import OmegaForm from "./OmegaWrapper.vue"
18
18
 
19
+ /**
20
+ * Recursively makes all properties in a schema optional, including nested objects.
21
+ * Unlike S.partial which only makes top-level properties optional, this utility
22
+ * traverses the schema tree and applies partial transformation at every level.
23
+ *
24
+ * Handles:
25
+ * - TypeLiteral (structs): Makes all properties optional and recursively processes nested types
26
+ * - Union types: Recursively applies partial to each union member
27
+ * - Transformation types: Applies partial to both 'from' and 'to' sides
28
+ */
29
+ const partialRecursive = <A, I, R>(schema: S.Schema<A, I, R>): S.Schema<Partial<A>, Partial<I>, R> => {
30
+ const ast = schema.ast
31
+
32
+ // Handle Union types - recursively apply partial to each member
33
+ if (ast._tag === "Union") {
34
+ const partialMembers = (ast as any).types.map((memberAst: any) => {
35
+ const memberSchema = S.make(memberAst)
36
+ const partialMember = partialRecursive(memberSchema as any)
37
+ return partialMember.ast
38
+ })
39
+
40
+ const newAst = {
41
+ ...ast,
42
+ types: partialMembers
43
+ }
44
+
45
+ return S.make(newAst as any)
46
+ }
47
+
48
+ // Handle Transformation types (e.g., withDefaultConstructor)
49
+ if (ast._tag === "Transformation") {
50
+ // For transformations, apply partial to both the 'from' and 'to' sides
51
+ const fromSchema = S.make((ast as any).from)
52
+ const toSchema = S.make((ast as any).to)
53
+ const partialFrom = partialRecursive(fromSchema as any)
54
+ const partialTo = partialRecursive(toSchema as any)
55
+
56
+ const newAst = {
57
+ ...ast,
58
+ from: partialFrom.ast,
59
+ to: partialTo.ast
60
+ }
61
+
62
+ return S.make(newAst as any)
63
+ }
64
+
65
+ // If this is a TypeLiteral (struct), recursively apply partial to nested fields
66
+ if (ast._tag === "TypeLiteral") {
67
+ const fields = ast.propertySignatures.map((prop: any) => {
68
+ const propType = prop.type
69
+ let newType = propType
70
+
71
+ // Recursively handle nested complex types (structs, unions, transformations)
72
+ if (propType._tag === "TypeLiteral" || propType._tag === "Union" || propType._tag === "Transformation") {
73
+ const nestedSchema = S.make(propType)
74
+ const recursivePartial = partialRecursive(nestedSchema as any)
75
+ newType = recursivePartial.ast
76
+ }
77
+
78
+ // Create a new property signature with isOptional: true
79
+ return {
80
+ ...prop,
81
+ type: newType,
82
+ isOptional: true
83
+ }
84
+ })
85
+
86
+ const newAst = {
87
+ ...ast,
88
+ propertySignatures: fields
89
+ }
90
+
91
+ return S.make(newAst as any)
92
+ }
93
+
94
+ // For other schema types (primitives, refinements, etc.), return as-is
95
+ // These types don't need to be made partial, and S.partial doesn't support them anyway
96
+ return schema as any
97
+ }
98
+
19
99
  type keysRule<T> =
20
100
  | {
21
101
  keys?: NestedKeyOf<T>[]
@@ -433,9 +513,10 @@ export interface OmegaFormReturn<
433
513
  never
434
514
  >
435
515
  & {
436
- name: Name
516
+ name?: Name
437
517
  type?: "select" | "radio"
438
518
  options: import("./InputProps").TaggedUnionOptionsArray<From, Name>
519
+ _debugName?: [NoInfer<Name>]
439
520
  label?: string
440
521
  }
441
522
  & {}
@@ -710,6 +791,50 @@ export const useOmegaForm = <
710
791
  const extractDefaultsFromAST = (schemaObj: any): any => {
711
792
  const result: Record<string, any> = {}
712
793
 
794
+ // If this schema has a .make() method (like ExtendedClass), use it to get complete defaults
795
+ // This is more reliable than manually extracting fields, especially for classes
796
+ if (typeof schemaObj?.make === "function") {
797
+ try {
798
+ const instance = schemaObj.make({})
799
+ // For ExtendedClass, the instance is already in the correct encoded format
800
+ return instance
801
+ } catch {
802
+ // If make() fails, fall through to manual extraction
803
+ }
804
+ }
805
+
806
+ // Check if this schema is a union - check both direct property and AST
807
+ const unionMembers = schemaObj?.members
808
+ || (schemaObj?.ast?._tag === "Union" && schemaObj.ast.types
809
+ ? schemaObj.ast.types.map((t: any) => S.make(t))
810
+ : null)
811
+ if (unionMembers && Array.isArray(unionMembers)) {
812
+ // For unions, we try to find the first member that has a complete set of defaults
813
+ // Priority is given to members with default values for discriminator fields
814
+ for (const member of unionMembers as any[]) {
815
+ const memberDefaults = extractDefaultsFromAST(member)
816
+ if (Object.keys(memberDefaults).length > 0) {
817
+ // Check if this member has a default value for a discriminator field (like _tag)
818
+ // If it does, use this member's defaults
819
+ const hasDiscriminatorDefault = member?.fields && Object.entries(member.fields).some(
820
+ ([key, fieldSchema]: [string, any]) => {
821
+ // Common discriminator field names
822
+ if (key === "_tag" || key === "type" || key === "kind") {
823
+ return fieldSchema?.ast?.defaultValue !== undefined
824
+ }
825
+ return false
826
+ }
827
+ )
828
+
829
+ if (hasDiscriminatorDefault) {
830
+ return memberDefaults
831
+ }
832
+ }
833
+ }
834
+ // If no member has a discriminator default, return empty
835
+ return {}
836
+ }
837
+
713
838
  // Check if this schema has fields (struct)
714
839
  if (schemaObj?.fields && typeof schemaObj.fields === "object") {
715
840
  for (const [key, fieldSchema] of Object.entries(schemaObj.fields)) {
@@ -725,7 +850,7 @@ export const useOmegaForm = <
725
850
  }
726
851
  }
727
852
 
728
- // Recursively check nested fields for structs
853
+ // Recursively check nested fields for structs and unions
729
854
  const nestedDefaults = extractDefaultsFromAST(fieldSchema as any)
730
855
  if (Object.keys(nestedDefaults).length > 0) {
731
856
  // If we already have a default value for this key, merge with nested
@@ -744,13 +869,14 @@ export const useOmegaForm = <
744
869
 
745
870
  // Extract default values from schema constructors (e.g., withDefaultConstructor)
746
871
  const extractSchemaDefaults = (defaultValues: Partial<From> = {}) => {
872
+ let result: Partial<From> = {}
873
+
747
874
  try {
875
+ // First try to use schema.make() if available
748
876
  // First try to use schema.make() if available
749
877
  // Note: Partial schemas don't have .make() method yet (https://github.com/Effect-TS/effect/issues/4222)
750
- if ("make" in schema && typeof (schema as any).make === "function") {
751
- const decoded = (schema as any).make(defaultValues)
752
- return S.encodeSync(schema.pipe(S.partial))(decoded)
753
- }
878
+ const decoded = (schema as any).make(defaultValues)
879
+ result = S.encodeSync(partialRecursive(schema))(decoded)
754
880
  } catch (error) {
755
881
  // If make() fails, try to extract defaults from AST
756
882
  if (window.location.hostname === "localhost") {
@@ -758,20 +884,23 @@ export const useOmegaForm = <
758
884
  }
759
885
  try {
760
886
  const astDefaults = extractDefaultsFromAST(schema)
761
-
762
- return S.encodeSync(schema.pipe(S.partial))(astDefaults)
887
+ result = S.encodeSync(partialRecursive(schema))(astDefaults)
763
888
  } catch (astError) {
764
889
  if (window.location.hostname === "localhost") {
765
890
  console.warn("Could not extract defaults from AST:", astError)
766
891
  }
767
- return {}
768
892
  }
769
893
  }
894
+ return deepMerge(result, defaultValues)
770
895
  }
771
896
 
772
897
  const defaultValues = computed(() => {
773
898
  // Normalize tanstack default values at the beginning
774
- const normalizedTanstackDefaults = extractSchemaDefaults(normalizeDefaultValues(tanstackFormOptions?.defaultValues))
899
+ const normalizedTanstackDefaults = extractSchemaDefaults(
900
+ normalizeDefaultValues(
901
+ tanstackFormOptions?.defaultValues
902
+ )
903
+ )
775
904
 
776
905
  if (
777
906
  normalizedTanstackDefaults