@effect-app/vue-components 2.7.11 → 2.9.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.
Files changed (46) hide show
  1. package/dist/types/components/OmegaForm/defaultAST.d.ts +4 -0
  2. package/dist/types/components/OmegaForm/useOmegaForm.d.ts +1 -0
  3. package/dist/vue-components.es10.js +149 -239
  4. package/dist/vue-components.es17.js +97 -5
  5. package/dist/vue-components.es20.js +2 -2
  6. package/dist/vue-components.es21.js +2 -2
  7. package/dist/vue-components.es22.js +1 -1
  8. package/dist/vue-components.es23.js +1 -1
  9. package/dist/vue-components.es31.js +4 -2
  10. package/dist/vue-components.es32.js +1 -1
  11. package/dist/vue-components.es33.js +2 -111
  12. package/dist/vue-components.es34.js +113 -0
  13. package/dist/vue-components.es36.js +7 -32
  14. package/dist/vue-components.es37.js +34 -0
  15. package/dist/vue-components.es41.js +4 -23
  16. package/dist/vue-components.es42.js +23 -5
  17. package/dist/vue-components.es43.js +5 -21
  18. package/dist/vue-components.es44.js +16 -25
  19. package/dist/vue-components.es45.js +23 -15
  20. package/dist/vue-components.es46.js +17 -7
  21. package/dist/vue-components.es47.js +12 -5
  22. package/dist/vue-components.es48.js +5 -19
  23. package/dist/vue-components.es49.js +19 -9
  24. package/dist/vue-components.es50.js +9 -31
  25. package/dist/vue-components.es51.js +25 -42
  26. package/dist/vue-components.es52.js +38 -16
  27. package/dist/vue-components.es53.js +26 -11
  28. package/dist/vue-components.es54.js +11 -65
  29. package/dist/vue-components.es55.js +54 -45
  30. package/dist/vue-components.es56.js +54 -15
  31. package/dist/vue-components.es57.js +15 -31
  32. package/dist/vue-components.es58.js +30 -26
  33. package/dist/vue-components.es59.js +29 -42
  34. package/dist/vue-components.es60.js +42 -2
  35. package/dist/vue-components.es61.js +2 -44
  36. package/dist/vue-components.es62.js +44 -2
  37. package/dist/vue-components.es63.js +4 -0
  38. package/dist/vue-components.es7.js +1 -1
  39. package/dist/vue-components.es9.js +33 -10
  40. package/package.json +23 -23
  41. package/src/components/OmegaForm/OmegaTaggedUnionInternal.vue +50 -1
  42. package/src/components/OmegaForm/defaultAST.ts +191 -0
  43. package/src/components/OmegaForm/useOmegaForm.ts +5 -187
  44. package/dist/vue-components.es35.js +0 -9
  45. package/dist/vue-components.es40.js +0 -6
  46. /package/dist/{vue-components.es38.js → vue-components.es39.js} +0 -0
@@ -5,119 +5,17 @@ import * as api from "@opentelemetry/api"
5
5
  import { type DeepKeys, DeepValue, type FormAsyncValidateOrFn, type FormValidateOrFn, type StandardSchemaV1, StandardSchemaV1Issue, useForm, ValidationError, ValidationErrorMap } from "@tanstack/vue-form"
6
6
  import { Array, Data, Effect, Fiber, Option, Order, S } from "effect-app"
7
7
  import { runtimeFiberAsPromise } from "effect-app/utils"
8
- import { isObject } from "effect/Predicate"
9
8
  import { Component, computed, ComputedRef, ConcreteComponent, h, type InjectionKey, onBeforeUnmount, onMounted, onUnmounted, Ref, ref, watch } from "vue"
9
+ import { deepMerge, extractSchemaDefaults } from "./defaultAST"
10
10
  import { MergedInputProps } from "./InputProps"
11
11
  import OmegaArray from "./OmegaArray.vue"
12
12
  import OmegaAutoGen from "./OmegaAutoGen.vue"
13
13
  import OmegaErrorsInternal from "./OmegaErrorsInternal.vue"
14
- import { BaseProps, DefaultTypeProps, FieldPath, type FormProps, generateMetaFromSchema, isNullableOrUndefined, type MetaRecord, type NestedKeyOf, OmegaArrayProps, OmegaAutoGenMeta, OmegaError, type OmegaFormApi, OmegaFormState } from "./OmegaFormStuff"
14
+ import { BaseProps, DefaultTypeProps, FieldPath, type FormProps, generateMetaFromSchema, type MetaRecord, type NestedKeyOf, OmegaArrayProps, OmegaAutoGenMeta, OmegaError, type OmegaFormApi, OmegaFormState } from "./OmegaFormStuff"
15
15
  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 Refinement types (e.g., NonEmptyArray, filters on ExtendedClass)
33
- if (ast._tag === "Refinement") {
34
- const refinementAst = ast as any
35
- // For refinements, bypass the filter and recursively apply partial to the underlying type
36
- const fromSchema = S.make(refinementAst.from)
37
- return partialRecursive(fromSchema as any)
38
- }
39
-
40
- // Handle Union types - recursively apply partial to each member
41
- if (ast._tag === "Union") {
42
- const partialMembers = (ast as any).types.map((memberAst: any) => {
43
- const memberSchema = S.make(memberAst)
44
- const partialMember = partialRecursive(memberSchema as any)
45
- return partialMember.ast
46
- })
47
-
48
- const newAst = {
49
- ...ast,
50
- types: partialMembers
51
- }
52
-
53
- return S.make(newAst as any)
54
- }
55
-
56
- // Handle Transformation types (e.g., withDefaultConstructor, ExtendedClass)
57
- if (ast._tag === "Transformation") {
58
- const transformAst = ast as any
59
-
60
- // Special handling for ExtendedClass (Declaration in 'to' side)
61
- if (transformAst.to._tag === "Declaration") {
62
- // For ExtendedClass, extract the TypeLiteral from the 'from' side
63
- // and make that partial, bypassing the Declaration entirely
64
- const fromSchema = S.make(transformAst.from)
65
- return partialRecursive(fromSchema as any)
66
- }
67
-
68
- // For other transformations, apply partial to both sides
69
- const fromSchema = S.make(transformAst.from)
70
- const toSchema = S.make(transformAst.to)
71
- const partialFrom = partialRecursive(fromSchema as any)
72
- const partialTo = partialRecursive(toSchema as any)
73
-
74
- const newAst = {
75
- ...ast,
76
- from: partialFrom.ast,
77
- to: partialTo.ast
78
- }
79
-
80
- return S.make(newAst as any)
81
- }
82
-
83
- // If this is a TypeLiteral (struct), recursively apply partial to nested fields
84
- if (ast._tag === "TypeLiteral") {
85
- const fields = ast.propertySignatures.map((prop: any) => {
86
- const propType = prop.type
87
- let newType = propType
88
-
89
- // Recursively handle nested complex types (structs, unions, transformations, refinements)
90
- if (
91
- propType._tag === "TypeLiteral" || propType._tag === "Union" || propType
92
- ._tag === "Transformation" || propType
93
- ._tag === "Refinement"
94
- ) {
95
- const nestedSchema = S.make(propType)
96
- const recursivePartial = partialRecursive(nestedSchema as any)
97
- newType = recursivePartial.ast
98
- }
99
-
100
- // Create a new property signature with isOptional: true
101
- return {
102
- ...prop,
103
- type: newType,
104
- isOptional: true
105
- }
106
- })
107
-
108
- const newAst = {
109
- ...ast,
110
- propertySignatures: fields
111
- }
112
-
113
- return S.make(newAst as any)
114
- }
115
-
116
- // For other schema types (primitives, refinements, etc.), return as-is
117
- // These types don't need to be made partial, and S.partial doesn't support them anyway
118
- return schema as any
119
- }
120
-
121
19
  type keysRule<T> =
122
20
  | {
123
21
  keys?: NestedKeyOf<T>[]
@@ -458,6 +356,7 @@ export interface OmegaFormReturn<
458
356
  // Pre-computed type aliases - computed ONCE for performance
459
357
  _paths: FieldPath<From>
460
358
  _keys: DeepKeys<From>
359
+ _schema: S.Schema<To, From, never>
461
360
 
462
361
  // this crazy thing here is copied from the OmegaFormInput.vue.d.ts, with `From` removed as Generic, instead closed over from the From generic above..
463
362
  Input: <Name extends OmegaFormReturn<From, To, TypeProps>["_paths"]>(
@@ -763,89 +662,6 @@ export const useOmegaForm = <
763
662
  window.history.replaceState({}, "", url.toString())
764
663
  }
765
664
 
766
- function deepMerge(target: any, source: any) {
767
- for (const key in source) {
768
- if (Array.isArray(source[key])) {
769
- // Arrays should be copied directly, not deep merged
770
- target[key] = source[key]
771
- } else if (source[key] && isObject(source[key])) {
772
- if (!target[key]) {
773
- target[key] = {}
774
- }
775
- deepMerge(target[key], source[key])
776
- } else {
777
- target[key] = source[key]
778
- }
779
- }
780
- return target
781
- }
782
-
783
- // Helper function to recursively extract default values from schema AST
784
- const extractDefaultsFromAST = (schemaObj: any): any => {
785
- const result: Record<string, any> = {}
786
-
787
- // Check if this schema has fields (struct)
788
- if (schemaObj?.fields && typeof schemaObj.fields === "object") {
789
- for (const [key, fieldSchema] of Object.entries(schemaObj.fields)) {
790
- // Check if this field has a default value in its AST
791
- if ((fieldSchema as any)?.ast?.defaultValue) {
792
- try {
793
- const defaultValue = (fieldSchema as any).ast.defaultValue()
794
- result[key] = defaultValue
795
- } catch {
796
- // Silently ignore if defaultValue() throws
797
- }
798
- } else {
799
- // TODO Should we put to null/undefined only leaves?
800
- const ast = (fieldSchema as any)?.ast
801
- const nullableOrUndefined = isNullableOrUndefined(ast)
802
- switch (nullableOrUndefined) {
803
- case "null":
804
- result[key] = null
805
- break
806
- case "undefined":
807
- result[key] = undefined
808
- break
809
- }
810
- }
811
-
812
- // Recursively check nested fields for structs and unions
813
- const nestedDefaults = extractDefaultsFromAST(fieldSchema as any)
814
- if (Object.keys(nestedDefaults).length > 0) {
815
- // If we already have a default value for this key, merge with nested
816
- if (result[key] && typeof result[key] === "object") {
817
- Object.assign(result[key], nestedDefaults)
818
- } else if (!result[key]) {
819
- // Only set nested defaults if we don't have a default value
820
- result[key] = nestedDefaults
821
- }
822
- }
823
- }
824
- } else {
825
- if (schemaObj?.from?.fields && typeof schemaObj?.from?.fields === "object") {
826
- return extractDefaultsFromAST(schemaObj.from)
827
- }
828
- }
829
-
830
- return result
831
- }
832
-
833
- // Extract default values from schema constructors (e.g., withDefaultConstructor)
834
- const extractSchemaDefaults = (defaultValues: Partial<From> = {}) => {
835
- let result: Partial<From> = {}
836
-
837
- try {
838
- const astDefaults = extractDefaultsFromAST(schema)
839
- result = S.encodeSync(partialRecursive(schema))(astDefaults)
840
- } catch (astError) {
841
- if (window.location.hostname === "localhost") {
842
- console.warn("Could not extract defaults from AST:", astError)
843
- }
844
- }
845
-
846
- return deepMerge(result, defaultValues)
847
- }
848
-
849
665
  const defaultValues = computed(() => {
850
666
  // will contain what we get from querystring or local/session storage
851
667
  let defValuesPatch
@@ -892,6 +708,7 @@ export const useOmegaForm = <
892
708
 
893
709
  // we just return what we gathered from the query/storage
894
710
  return extractSchemaDefaults(
711
+ schema,
895
712
  omegaConfig?.persistency?.overrideDefaultValues
896
713
  ? deepMerge(tanstackFormOptions?.defaultValues || {}, defValuesPatch)
897
714
  : deepMerge(defValuesPatch, tanstackFormOptions?.defaultValues || {})
@@ -1107,6 +924,7 @@ export const useOmegaForm = <
1107
924
  // Type-level properties for performance optimization (not used at runtime)
1108
925
  _paths: undefined as any,
1109
926
  _keys: undefined as any,
927
+ _schema: schema,
1110
928
  errorContext,
1111
929
  Form: fHoc(formWithExtras)(OmegaForm as any) as any,
1112
930
  Input: fHoc(formWithExtras)(omegaConfig?.input ?? OmegaInput) as any,
@@ -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
- };
@@ -1,6 +0,0 @@
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 o from "./vue-components.es38.js";
3
-
4
- export {
5
- o as default
6
- };