@effect-app/vue-components 2.9.2 → 2.10.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 (54) hide show
  1. package/dist/types/components/OmegaForm/OmegaFormStuff.d.ts +2 -0
  2. package/dist/types/components/OmegaForm/useOmegaForm.d.ts +1 -0
  3. package/dist/vue-components.es.js +17 -15
  4. package/dist/vue-components.es10.js +91 -93
  5. package/dist/vue-components.es12.js +282 -204
  6. package/dist/vue-components.es16.js +4 -10
  7. package/dist/vue-components.es17.js +10 -97
  8. package/dist/vue-components.es2.js +29 -27
  9. package/dist/vue-components.es20.js +2 -2
  10. package/dist/vue-components.es21.js +2 -2
  11. package/dist/vue-components.es22.js +1 -1
  12. package/dist/vue-components.es23.js +1 -1
  13. package/dist/vue-components.es30.js +191 -41
  14. package/dist/vue-components.es32.js +42 -2
  15. package/dist/vue-components.es33.js +1 -1
  16. package/dist/vue-components.es34.js +2 -111
  17. package/dist/vue-components.es35.js +113 -0
  18. package/dist/vue-components.es37.js +7 -32
  19. package/dist/vue-components.es38.js +34 -0
  20. package/dist/vue-components.es40.js +6 -0
  21. package/dist/vue-components.es41.js +23 -4
  22. package/dist/vue-components.es42.js +5 -23
  23. package/dist/vue-components.es43.js +21 -5
  24. package/dist/vue-components.es44.js +25 -16
  25. package/dist/vue-components.es45.js +15 -23
  26. package/dist/vue-components.es46.js +7 -17
  27. package/dist/vue-components.es47.js +5 -12
  28. package/dist/vue-components.es48.js +19 -5
  29. package/dist/vue-components.es49.js +9 -19
  30. package/dist/vue-components.es50.js +31 -9
  31. package/dist/vue-components.es51.js +42 -25
  32. package/dist/vue-components.es52.js +16 -38
  33. package/dist/vue-components.es53.js +11 -26
  34. package/dist/vue-components.es54.js +65 -11
  35. package/dist/vue-components.es55.js +45 -54
  36. package/dist/vue-components.es56.js +15 -54
  37. package/dist/vue-components.es57.js +31 -15
  38. package/dist/vue-components.es58.js +26 -30
  39. package/dist/vue-components.es59.js +42 -29
  40. package/dist/vue-components.es60.js +2 -42
  41. package/dist/vue-components.es61.js +44 -2
  42. package/dist/vue-components.es62.js +2 -44
  43. package/dist/vue-components.es7.js +1 -1
  44. package/dist/vue-components.es9.js +10 -33
  45. package/package.json +1 -1
  46. package/src/components/OmegaForm/OmegaFormStuff.ts +174 -11
  47. package/src/components/OmegaForm/OmegaTaggedUnionInternal.vue +0 -48
  48. package/src/components/OmegaForm/useOmegaForm.ts +16 -8
  49. package/dist/types/components/OmegaForm/defaultAST.d.ts +0 -4
  50. package/dist/vue-components.es31.js +0 -6
  51. package/dist/vue-components.es36.js +0 -9
  52. package/dist/vue-components.es39.js +0 -194
  53. package/dist/vue-components.es63.js +0 -4
  54. package/src/components/OmegaForm/defaultAST.ts +0 -191
@@ -1,4 +1,46 @@
1
- var r = "1.9.0";
1
+ import { VERSION as d } from "./vue-components.es60.js";
2
+ var h = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
3
+ function s(c) {
4
+ var m = /* @__PURE__ */ new Set([c]), f = /* @__PURE__ */ new Set(), t = c.match(h);
5
+ if (!t)
6
+ return function() {
7
+ return !1;
8
+ };
9
+ var e = {
10
+ major: +t[1],
11
+ minor: +t[2],
12
+ patch: +t[3],
13
+ prerelease: t[4]
14
+ };
15
+ if (e.prerelease != null)
16
+ return function(r) {
17
+ return r === c;
18
+ };
19
+ function a(n) {
20
+ return f.add(n), !1;
21
+ }
22
+ function p(n) {
23
+ return m.add(n), !0;
24
+ }
25
+ return function(r) {
26
+ if (m.has(r))
27
+ return !0;
28
+ if (f.has(r))
29
+ return !1;
30
+ var i = r.match(h);
31
+ if (!i)
32
+ return a(r);
33
+ var u = {
34
+ major: +i[1],
35
+ minor: +i[2],
36
+ patch: +i[3],
37
+ prerelease: i[4]
38
+ };
39
+ return u.prerelease != null || e.major !== u.major ? a(r) : e.major === 0 ? e.minor === u.minor && e.patch <= u.patch ? p(r) : a(r) : e.minor <= u.minor ? p(r) : a(r);
40
+ };
41
+ }
42
+ var v = s(d);
2
43
  export {
3
- r as VERSION
44
+ s as _makeCompatibilityCheck,
45
+ v as isCompatible
4
46
  };
@@ -1,46 +1,4 @@
1
- import { VERSION as d } from "./vue-components.es61.js";
2
- var h = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
3
- function s(c) {
4
- var m = /* @__PURE__ */ new Set([c]), f = /* @__PURE__ */ new Set(), t = c.match(h);
5
- if (!t)
6
- return function() {
7
- return !1;
8
- };
9
- var e = {
10
- major: +t[1],
11
- minor: +t[2],
12
- patch: +t[3],
13
- prerelease: t[4]
14
- };
15
- if (e.prerelease != null)
16
- return function(r) {
17
- return r === c;
18
- };
19
- function a(n) {
20
- return f.add(n), !1;
21
- }
22
- function p(n) {
23
- return m.add(n), !0;
24
- }
25
- return function(r) {
26
- if (m.has(r))
27
- return !0;
28
- if (f.has(r))
29
- return !1;
30
- var i = r.match(h);
31
- if (!i)
32
- return a(r);
33
- var u = {
34
- major: +i[1],
35
- minor: +i[2],
36
- patch: +i[3],
37
- prerelease: i[4]
38
- };
39
- return u.prerelease != null || e.major !== u.major ? a(r) : e.major === 0 ? e.minor === u.minor && e.patch <= u.patch ? p(r) : a(r) : e.minor <= u.minor ? p(r) : a(r);
40
- };
41
- }
42
- var v = s(d);
1
+ var o = typeof globalThis == "object" ? globalThis : typeof self == "object" ? self : typeof window == "object" ? window : typeof global == "object" ? global : {};
43
2
  export {
44
- s as _makeCompatibilityCheck,
45
- v as isCompatible
3
+ o as _globalThis
46
4
  };
@@ -1,7 +1,7 @@
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
2
  import { defineComponent as $, computed as n, getCurrentInstance as N, useAttrs as S, useSlots as k, useId as q, renderSlot as u, normalizeProps as s, guardReactiveProps as d, createElementVNode as B, normalizeClass as w, createBlock as I, createCommentVNode as L, unref as A, openBlock as F, mergeProps as O, createSlots as R, withCtx as V } from "vue";
3
3
  import { useStore as z } from "@tanstack/vue-form";
4
- import T from "./vue-components.es39.js";
4
+ import T from "./vue-components.es30.js";
5
5
 
6
6
  const H = /* @__PURE__ */ $({
7
7
  inheritAttrs: !1,
@@ -1,8 +1,5 @@
1
- import { defineComponent as l, watch as f, renderSlot as d, createCommentVNode as u, normalizeProps as c, mergeProps as p } from "vue";
2
- import { S as i } from "effect-app";
3
- import { getTransformationFrom as h } from "./vue-components.es3.js";
4
- import { extractSchemaDefaults as S } from "./vue-components.es17.js";
5
- const b = /* @__PURE__ */ l({
1
+ import { defineComponent as m, watch as r, renderSlot as s, createCommentVNode as o, normalizeProps as i, mergeProps as f } from "vue";
2
+ const d = /* @__PURE__ */ m({
6
3
  __name: "OmegaTaggedUnionInternal",
7
4
  props: {
8
5
  state: {},
@@ -10,35 +7,15 @@ const b = /* @__PURE__ */ l({
10
7
  name: {},
11
8
  form: {}
12
9
  },
13
- setup(r) {
14
- const e = r, s = e.form.useStore(({ values: t }) => t);
15
- return f(() => e.state, (t, o) => {
16
- if (t === null && e.field.setValue(null), t !== o) {
17
- if (e.name === void 0 && i.AST.isUnion(e.form._schema.ast)) {
18
- const n = e.form._schema.ast.types.map((a, m) => ({ original: m, unwrapped: h(a) })).flatMap(
19
- (a) => i.AST.isTypeLiteral(a.unwrapped) || i.AST.isTransformation(a.unwrapped) ? a.unwrapped.propertySignatures.filter((m) => i.AST.isLiteral(m.type) && m.type.literal === t).length > 0 ? [a.original] : [] : []
20
- )[0];
21
- if (n != null && "members" in e.form._schema && Array.isArray(e.form._schema.members)) {
22
- const a = Object.assign(
23
- S(
24
- e.form._schema.members[n],
25
- s.value
26
- ),
27
- { _tag: t }
28
- );
29
- e.form.reset(a), setTimeout(() => {
30
- e.field.validate("change");
31
- }, 0);
32
- return;
33
- }
34
- }
35
- e.form.reset(s.value), setTimeout(() => {
36
- e.field.validate("change");
37
- }, 0);
38
- }
39
- }, { immediate: !0 }), (t, o) => r.state ? d(t.$slots, `${r.name ? `${r.name}.` : ""}${r.state}`, c(p({ key: 0 }, { field: r.field, state: r.state }))) : u("", !0);
10
+ setup(e) {
11
+ const a = e, l = a.form.useStore(({ values: t }) => t);
12
+ return r(() => a.state, (t, n) => {
13
+ t === null && a.field.setValue(null), t !== n && (a.form.reset(l.value), setTimeout(() => {
14
+ a.field.validate("change");
15
+ }, 0));
16
+ }, { immediate: !0 }), (t, n) => e.state ? s(t.$slots, `${e.name ? `${e.name}.` : ""}${e.state}`, i(f({ key: 0 }, { field: e.field, state: e.state }))) : o("", !0);
40
17
  }
41
18
  });
42
19
  export {
43
- b as default
20
+ d as default
44
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "2.9.2",
3
+ "version": "2.10.0",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "effect": "^3.19.3",
@@ -2,6 +2,7 @@ import { type Effect, Option, type Record, S } from "effect-app"
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
  import { getMetadataFromSchema } from "@effect-app/vue/form"
4
4
  import { type DeepKeys, type DeepValue, type FieldAsyncValidateOrFn, type FieldValidateOrFn, type FormApi, type FormAsyncValidateOrFn, type FormOptions, type FormState, type FormValidateOrFn, type StandardSchemaV1, type VueFormApi } from "@tanstack/vue-form"
5
+ import { isObject } from "@vueuse/core"
5
6
  import { type RuntimeFiber } from "effect/Fiber"
6
7
  import { getTransformationFrom, useIntl } from "../../utils"
7
8
  import { type OmegaFieldInternalApi } from "./InputProps"
@@ -685,14 +686,15 @@ export const createMeta = <T = any>(
685
686
  return acc
686
687
  }
687
688
 
688
- const flattenMeta = <From, To>(
689
+ const metadataFromAst = <From, To>(
689
690
  schema: S.Schema<To, From, never>
690
- ): MetaRecord<To> => {
691
+ ): { meta: MetaRecord<To>; defaultValues: Record<string, any> } => {
691
692
  const ast = schema.ast
692
- const result: MetaRecord<To> = {}
693
+ const newMeta: MetaRecord<To> = {}
694
+ const defaultValues: Record<string, any> = {}
693
695
 
694
696
  if (ast._tag === "Transformation" || ast._tag === "Refinement") {
695
- return flattenMeta(S.make(ast.from))
697
+ return metadataFromAst(S.make(ast.from))
696
698
  }
697
699
 
698
700
  // Handle root-level Union types (discriminated unions)
@@ -730,20 +732,20 @@ const flattenMeta = <From, To>(
730
732
  })
731
733
 
732
734
  // Merge into result
733
- Object.assign(result, memberMeta)
735
+ Object.assign(newMeta, memberMeta)
734
736
  }
735
737
  }
736
738
 
737
739
  // Create metadata for the discriminator field
738
740
  if (discriminatorValues.length > 0) {
739
- result["_tag" as DeepKeys<To>] = {
741
+ newMeta["_tag" as DeepKeys<To>] = {
740
742
  type: "select",
741
743
  members: discriminatorValues,
742
744
  required: true
743
745
  } as FieldMeta
744
746
  }
745
747
 
746
- return result
748
+ return { meta: newMeta, defaultValues }
747
749
  }
748
750
  }
749
751
 
@@ -753,7 +755,7 @@ const flattenMeta = <From, To>(
753
755
  })
754
756
 
755
757
  if (Object.values(meta).every((value) => value && "type" in value)) {
756
- return meta as MetaRecord<To>
758
+ return { meta: meta as MetaRecord<To>, defaultValues }
757
759
  }
758
760
 
759
761
  const flattenObject = (
@@ -763,7 +765,7 @@ const flattenMeta = <From, To>(
763
765
  for (const key in obj) {
764
766
  const newKey = parentKey ? `${parentKey}.${key}` : key
765
767
  if (obj[key] && typeof obj[key] === "object" && "type" in obj[key]) {
766
- result[newKey as DeepKeys<To>] = obj[key] as FieldMeta
768
+ newMeta[newKey as DeepKeys<To>] = obj[key] as FieldMeta
767
769
  } else if (obj[key] && typeof obj[key] === "object") {
768
770
  flattenObject(obj[key], newKey)
769
771
  }
@@ -773,7 +775,7 @@ const flattenMeta = <From, To>(
773
775
  flattenObject(meta)
774
776
  }
775
777
 
776
- return result
778
+ return { meta: newMeta, defaultValues }
777
779
  }
778
780
 
779
781
  export const duplicateSchema = <From, To>(
@@ -788,7 +790,7 @@ export const generateMetaFromSchema = <From, To>(
788
790
  schema: S.Schema<To, From, never>
789
791
  meta: MetaRecord<To>
790
792
  } => {
791
- const meta = flattenMeta(schema)
793
+ const { meta } = metadataFromAst(schema)
792
794
 
793
795
  return { schema, meta }
794
796
  }
@@ -976,3 +978,164 @@ const supportedInputs = [
976
978
  export type SupportedInputs = typeof supportedInputs[number]
977
979
  export const getInputType = (input: string): SupportedInputs =>
978
980
  (supportedInputs as readonly string[]).includes(input) ? input as SupportedInputs : "text"
981
+
982
+ export function deepMerge(target: any, source: any) {
983
+ const result = { ...target }
984
+ for (const key in source) {
985
+ if (Array.isArray(source[key])) {
986
+ // Arrays should be copied directly, not deep merged
987
+ result[key] = source[key]
988
+ } else if (source[key] && isObject(source[key])) {
989
+ result[key] = deepMerge(result[key], source[key])
990
+ } else {
991
+ result[key] = source[key]
992
+ }
993
+ }
994
+ return result
995
+ }
996
+
997
+ // Type definitions for schemas with fields and members
998
+ type SchemaWithFields = {
999
+ fields: Record<string, S.Schema<any>>
1000
+ }
1001
+
1002
+ type SchemaWithMembers = {
1003
+ members: readonly S.Schema<any>[]
1004
+ }
1005
+
1006
+ // Type guards to check schema types
1007
+ function hasFields(schema: any): schema is SchemaWithFields {
1008
+ return schema && "fields" in schema && typeof schema.fields === "object"
1009
+ }
1010
+
1011
+ function hasMembers(schema: any): schema is SchemaWithMembers {
1012
+ return schema && "members" in schema && Array.isArray(schema.members)
1013
+ }
1014
+
1015
+ // Internal implementation with WeakSet tracking
1016
+ export const defaultsValueFromSchema = (
1017
+ schema: S.Schema<any>,
1018
+ record: Record<string, any> = {}
1019
+ ): any => {
1020
+ const ast: any = schema.ast
1021
+
1022
+ if (ast?.defaultValue) {
1023
+ return ast.defaultValue()
1024
+ }
1025
+
1026
+ if (isNullableOrUndefined(schema.ast) === "null") {
1027
+ return null
1028
+ }
1029
+ if (isNullableOrUndefined(schema.ast) === "undefined") {
1030
+ return undefined
1031
+ }
1032
+
1033
+ // Check if schema has fields directly
1034
+ if (hasFields(schema)) {
1035
+ // Process fields and extract default values
1036
+ const result: Record<string, any> = {}
1037
+
1038
+ for (const [key, fieldSchema] of Object.entries(schema.fields)) {
1039
+ // Check if this field has a defaultValue in its AST
1040
+ const fieldAst = (fieldSchema as any)?.ast
1041
+ if (fieldAst?.defaultValue) {
1042
+ try {
1043
+ result[key] = fieldAst.defaultValue()
1044
+ continue
1045
+ } catch {
1046
+ // If defaultValue() throws, fall through to recursive processing
1047
+ }
1048
+ }
1049
+
1050
+ // Recursively process the field
1051
+ const fieldValue = defaultsValueFromSchema(fieldSchema as any, record[key] || {})
1052
+ if (fieldValue !== undefined) {
1053
+ result[key] = fieldValue
1054
+ }
1055
+ }
1056
+
1057
+ return { ...result, ...record }
1058
+ }
1059
+
1060
+ // Check if schema has fields in from (for ExtendedClass and similar transformations)
1061
+ if ((schema as any)?.from && hasFields((schema as any).from)) {
1062
+ return defaultsValueFromSchema((schema as any).from, record)
1063
+ }
1064
+
1065
+ if (hasMembers(schema)) {
1066
+ // Merge all member fields, giving precedence to fields with default values
1067
+ const mergedMembers = schema.members.reduce((acc, member) => {
1068
+ if (hasFields(member)) {
1069
+ // Check each field and give precedence to ones with default values
1070
+ Object.entries(member.fields).forEach(([key, fieldSchema]) => {
1071
+ const fieldAst: any = fieldSchema.ast
1072
+ const existingFieldAst: any = acc[key]?.ast
1073
+
1074
+ // If field doesn't exist yet, or new field has default and existing doesn't, use new field
1075
+ if (!acc[key] || (fieldAst?.defaultValue && !existingFieldAst?.defaultValue)) {
1076
+ acc[key] = fieldSchema
1077
+ }
1078
+ // If both have defaults or neither have defaults, keep the first one (existing)
1079
+ })
1080
+ return acc
1081
+ }
1082
+ return acc
1083
+ }, {} as Record<string, any>)
1084
+
1085
+ // Use reduce to properly accumulate the merged fields
1086
+ return Object.entries(mergedMembers).reduce((acc, [key, value]) => {
1087
+ acc[key] = defaultsValueFromSchema(value, record[key] || {})
1088
+ return acc
1089
+ }, record)
1090
+ }
1091
+
1092
+ if (Object.keys(record).length === 0) {
1093
+ switch (schema.ast._tag) {
1094
+ case "Refinement":
1095
+ return defaultsValueFromSchema(S.make(schema.ast.from), record)
1096
+ case "Transformation": {
1097
+ // For all transformations, just process the 'from' side to get the base defaults
1098
+ const fromSchema = S.make(schema.ast.from)
1099
+ return defaultsValueFromSchema(fromSchema, record)
1100
+ }
1101
+ case "TypeLiteral": {
1102
+ // Process TypeLiteral fields directly to build the result object
1103
+ const result: Record<string, any> = { ...record }
1104
+
1105
+ for (const prop of ast.propertySignatures) {
1106
+ const key = prop.name.toString()
1107
+ const propType = prop.type
1108
+
1109
+ // Check if the property type itself is a Transformation with defaultValue
1110
+ if (propType._tag === "Transformation" && propType.defaultValue) {
1111
+ result[key] = propType.defaultValue()
1112
+ continue
1113
+ }
1114
+
1115
+ // Check if property type has defaultValue directly on the AST
1116
+ if (propType.defaultValue) {
1117
+ result[key] = propType.defaultValue()
1118
+ continue
1119
+ }
1120
+
1121
+ // Create a schema from the property type and get its defaults
1122
+ const propSchema = S.make(propType)
1123
+
1124
+ // Recursively process the property - don't pas for prop processing
1125
+ // to allow proper unwrapping of nested structures
1126
+ const propValue = defaultsValueFromSchema(propSchema, record[key] || {})
1127
+
1128
+ if (propValue !== undefined) {
1129
+ result[key] = propValue
1130
+ }
1131
+ }
1132
+
1133
+ return result
1134
+ }
1135
+ case "StringKeyword":
1136
+ return ""
1137
+ case "BooleanKeyword":
1138
+ return false
1139
+ }
1140
+ }
1141
+ }
@@ -12,10 +12,7 @@
12
12
  generic="From extends Record<PropertyKey, any>, To extends Record<PropertyKey, any>, Name extends DeepKeys<From>"
13
13
  >
14
14
  import { type DeepKeys, type DeepValue } from "@tanstack/vue-form"
15
- import { S } from "effect-app"
16
15
  import { watch } from "vue"
17
- import { getTransformationFrom } from "../../utils"
18
- import { extractSchemaDefaults } from "./defaultAST"
19
16
  import { type OmegaFieldInternalApi } from "./InputProps"
20
17
  import { type useOmegaForm } from "./useOmegaForm"
21
18
 
@@ -35,51 +32,6 @@ watch(() => props.state, (newTag, oldTag) => {
35
32
  }
36
33
 
37
34
  if (newTag !== oldTag) {
38
- // get default values from AST for the new tag (only for root level tagged unions)
39
- if (props.name === void 0 && S.AST.isUnion(props.form._schema.ast)) {
40
- const indexOfSelectedMember = props
41
- .form
42
- ._schema
43
- .ast
44
- .types
45
- .map((t, i) => ({ original: i, unwrapped: getTransformationFrom(t) }))
46
- .flatMap((x) =>
47
- S.AST.isTypeLiteral(x.unwrapped) || S.AST.isTransformation(x.unwrapped)
48
- ? x
49
- .unwrapped
50
- .propertySignatures
51
- .filter((ps) => S.AST.isLiteral(ps.type) && ps.type.literal === newTag)
52
- .length > 0
53
- ? [x.original]
54
- : []
55
- : []
56
- )[0]
57
-
58
- // even if the type doesn't say so, indexOfSelectedMember may be undefined
59
- if (
60
- indexOfSelectedMember != void 0
61
- && "members" in props.form._schema
62
- && Array.isArray(props.form._schema.members)
63
- ) {
64
- const defaultsOfSelectedMember = Object.assign(
65
- extractSchemaDefaults(
66
- props
67
- .form
68
- ._schema
69
- .members[indexOfSelectedMember],
70
- values.value
71
- ),
72
- { _tag: newTag }
73
- )
74
-
75
- props.form.reset(defaultsOfSelectedMember)
76
- setTimeout(() => {
77
- props.field.validate("change")
78
- }, 0)
79
- return
80
- }
81
- }
82
-
83
35
  props.form.reset(values.value)
84
36
  setTimeout(() => {
85
37
  props.field.validate("change")
@@ -6,12 +6,11 @@ import { type DeepKeys, DeepValue, type FormAsyncValidateOrFn, type FormValidate
6
6
  import { Array, Data, Effect, Fiber, Option, Order, S } from "effect-app"
7
7
  import { runtimeFiberAsPromise } from "effect-app/utils"
8
8
  import { Component, computed, ComputedRef, ConcreteComponent, h, type InjectionKey, onBeforeUnmount, onMounted, onUnmounted, Ref, ref, watch } from "vue"
9
- import { deepMerge, extractSchemaDefaults } from "./defaultAST"
10
9
  import { MergedInputProps } from "./InputProps"
11
10
  import OmegaArray from "./OmegaArray.vue"
12
11
  import OmegaAutoGen from "./OmegaAutoGen.vue"
13
12
  import OmegaErrorsInternal from "./OmegaErrorsInternal.vue"
14
- import { BaseProps, DefaultTypeProps, FieldPath, type FormProps, generateMetaFromSchema, type MetaRecord, type NestedKeyOf, OmegaArrayProps, OmegaAutoGenMeta, OmegaError, type OmegaFormApi, OmegaFormState } from "./OmegaFormStuff"
13
+ import { BaseProps, deepMerge, defaultsValueFromSchema, DefaultTypeProps, FieldPath, type FormProps, generateMetaFromSchema, type MetaRecord, type NestedKeyOf, OmegaArrayProps, OmegaAutoGenMeta, OmegaError, type OmegaFormApi, OmegaFormState } from "./OmegaFormStuff"
15
14
  import OmegaInput from "./OmegaInput.vue"
16
15
  import OmegaTaggedUnion from "./OmegaTaggedUnion.vue"
17
16
  import OmegaForm from "./OmegaWrapper.vue"
@@ -174,6 +173,8 @@ export type OmegaConfig<T> = {
174
173
  preventWindowExit?: "prevent" | "prevent-and-reset" | "nope"
175
174
 
176
175
  input?: any
176
+
177
+ defaultFromSchema?: "only" | "nope" | "merge"
177
178
  }
178
179
 
179
180
  export interface OF<From, To> extends OmegaFormApi<From, To> {
@@ -706,13 +707,20 @@ export const useOmegaForm = <
706
707
  // to be sure we have a valid object at the end of the gathering process
707
708
  defValuesPatch ??= {}
708
709
 
710
+ const defaultValuesFromSchema = (() => {
711
+ if (omegaConfig?.defaultFromSchema === "only") {
712
+ return defaultsValueFromSchema(schema)
713
+ }
714
+ if (omegaConfig?.defaultFromSchema === "nope") {
715
+ return tanstackFormOptions?.defaultValues || {}
716
+ }
717
+ return deepMerge(defaultsValueFromSchema(schema), tanstackFormOptions?.defaultValues || {})
718
+ })()
719
+
709
720
  // we just return what we gathered from the query/storage
710
- return extractSchemaDefaults(
711
- schema,
712
- omegaConfig?.persistency?.overrideDefaultValues
713
- ? deepMerge(tanstackFormOptions?.defaultValues || {}, defValuesPatch)
714
- : deepMerge(defValuesPatch, tanstackFormOptions?.defaultValues || {})
715
- )
721
+ return omegaConfig?.persistency?.overrideDefaultValues
722
+ ? deepMerge(defaultValuesFromSchema, defValuesPatch)
723
+ : deepMerge(defValuesPatch, defaultValuesFromSchema)
716
724
  })
717
725
 
718
726
  const wrapWithSpan = (span: api.Span | undefined, toWrap: () => any) => {
@@ -1,4 +0,0 @@
1
- import { S } from "effect-app";
2
- export declare function deepMerge(target: any, source: any): any;
3
- export declare const extractDefaultsFromAST: (schemaObj: any) => any;
4
- export declare const extractSchemaDefaults: <From, To>(schema: S.Schema<To, From, never>, defaultValues?: Partial<From>) => any;
@@ -1,6 +0,0 @@
1
- import "vue";
2
- typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
3
- const t = Object.prototype.toString, c = (o) => t.call(o) === "[object Object]";
4
- export {
5
- c as isObject
6
- };
@@ -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
- };