@form-instant/react-resolver-zod 0.2.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,11 @@
1
1
  import { z } from 'zod';
2
2
  import { FieldConfig, SuperRefineFunction } from './types';
3
3
  export declare const FIELD_CONFIG_SYMBOL: unique symbol;
4
+ declare module 'zod' {
5
+ interface ZodType {
6
+ fieldConfig<AdditionalRenderable = null, FieldTypes = string>(config: FieldConfig<AdditionalRenderable, FieldTypes>): this;
7
+ }
8
+ }
9
+ export declare const extendZodWithFieldConfig: <AdditionalRenderable = null, FieldTypes = string>(zod: typeof z) => void;
4
10
  export declare const createZodSchemaFieldConfig: <AdditionalRenderable = null, FieldTypes = string>() => (config: FieldConfig<AdditionalRenderable, FieldTypes>) => SuperRefineFunction;
5
11
  export declare function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './element';
2
- export { createZodSchemaFieldConfig } from './funcs/field-config';
2
+ export * from './funcs/field-config';
3
3
  export * from './provider';
4
4
  export * from './type';
@@ -8,6 +8,15 @@ var zod = require('zod');
8
8
 
9
9
  var ZodResolverContext = /*#__PURE__*/useContextSelector.createContext({});
10
10
 
11
+ function _extends() {
12
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
13
+ for (var e = 1; e < arguments.length; e++) {
14
+ var t = arguments[e];
15
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
16
+ }
17
+ return n;
18
+ }, _extends.apply(null, arguments);
19
+ }
11
20
  function _objectWithoutPropertiesLoose(r, e) {
12
21
  if (null == r) return {};
13
22
  var t = {};
@@ -29,6 +38,12 @@ function getDefaultValueInZodStack(schema) {
29
38
  }
30
39
 
31
40
  var FIELD_CONFIG_SYMBOL = /*#__PURE__*/Symbol('GetFieldConfig');
41
+ var extendZodWithFieldConfig = function extendZodWithFieldConfig(zod) {
42
+ zod.ZodType.prototype.fieldConfig = function (config) {
43
+ this._def.fieldConfig = config;
44
+ return this;
45
+ };
46
+ };
32
47
  var createZodSchemaFieldConfig = function createZodSchemaFieldConfig() {
33
48
  return function (config) {
34
49
  var refinementFunction = function refinementFunction() {
@@ -40,20 +55,19 @@ var createZodSchemaFieldConfig = function createZodSchemaFieldConfig() {
40
55
  };
41
56
  };
42
57
  function getFieldConfigInZodStack(schema) {
43
- var typedSchema = schema;
44
- if (typedSchema._def.typeName === 'ZodEffects') {
45
- var effect = typedSchema._def.effect;
46
- var refinementFunction = effect.refinement;
47
- if (FIELD_CONFIG_SYMBOL in refinementFunction) {
48
- return refinementFunction[FIELD_CONFIG_SYMBOL];
49
- }
58
+ // Verifica si el esquema tiene fieldConfig directamente
59
+ if (schema._def.fieldConfig) {
60
+ return schema._def.fieldConfig;
50
61
  }
51
- if ('innerType' in typedSchema._def) {
52
- return getFieldConfigInZodStack(typedSchema._def.innerType);
62
+ // Si el esquema es un ZodEffects, busca en el innerType
63
+ if ('innerType' in schema._def) {
64
+ return getFieldConfigInZodStack(schema._def.innerType);
53
65
  }
54
- if ('schema' in typedSchema._def) {
55
- return getFieldConfigInZodStack(typedSchema._def.schema);
66
+ // Si el esquema es un ZodEffects con un schema interno, busca en el schema
67
+ if ('schema' in schema._def) {
68
+ return getFieldConfigInZodStack(schema._def.schema);
56
69
  }
70
+ // Si no se encuentra fieldConfig, retorna un objeto vacío
57
71
  return {};
58
72
  }
59
73
 
@@ -68,16 +82,65 @@ function inferFieldType(schema, fieldType) {
68
82
  }
69
83
 
70
84
  var _excluded = ["fieldType"];
71
- function parseField(name, schema, history) {
85
+ var typeMapping = {
86
+ ZodDiscriminatedUnion: function ZodDiscriminatedUnion(baseSchema, name, history, dependecys) {
87
+ var _baseSchema$_def = baseSchema._def,
88
+ optionsMap = _baseSchema$_def.optionsMap,
89
+ discriminator = _baseSchema$_def.discriminator,
90
+ fieldConfig = _baseSchema$_def.fieldConfig;
91
+ if (!Object.keys(dependecys).length) return [{}];
92
+ var optionKey = dependecys[discriminator];
93
+ var option = optionsMap.get(optionKey);
94
+ if (!option) return [{}];
95
+ var entries = Object.entries(option.shape);
96
+ var fields = entries.filter(function (_ref) {
97
+ var key = _ref[0];
98
+ return key !== discriminator;
99
+ }).map(function (_ref2) {
100
+ var key = _ref2[0],
101
+ field = _ref2[1];
102
+ return parseField(key, field, [history, name].join('.'), dependecys);
103
+ });
104
+ fields.unshift({
105
+ name: {
106
+ current: discriminator,
107
+ history: [history, name, discriminator].join('.')
108
+ },
109
+ type: 'discriminator',
110
+ required: true,
111
+ "default": optionKey,
112
+ fieldConfig: fieldConfig,
113
+ options: Array.from(optionsMap.keys()).map(function (key) {
114
+ return [String(key), String(key)];
115
+ })
116
+ });
117
+ return fields;
118
+ },
119
+ ZodObject: function ZodObject(baseSchema, name, history, dependecys) {
120
+ return Object.entries(baseSchema.shape).map(function (_ref3) {
121
+ var key = _ref3[0],
122
+ field = _ref3[1];
123
+ return parseField(key, field, [history, name].join('.'), dependecys);
124
+ });
125
+ },
126
+ ZodArray: function ZodArray(baseSchema, name, history, dependecys) {
127
+ return [parseField('0', baseSchema._def.type, [history, name].join('.'), dependecys)];
128
+ }
129
+ };
130
+ function parseField(name, schema, history, dependecys) {
72
131
  if (history === void 0) {
73
132
  history = '';
74
133
  }
134
+ if (dependecys === void 0) {
135
+ dependecys = {};
136
+ }
75
137
  var baseSchema = getBaseSchema(schema);
76
138
  var _getFieldConfigInZodS = getFieldConfigInZodStack(schema),
77
139
  fieldType = _getFieldConfigInZodS.fieldType,
78
- fieldConfig = _objectWithoutPropertiesLoose(_getFieldConfigInZodS, _excluded);
140
+ fieldConfigBase = _objectWithoutPropertiesLoose(_getFieldConfigInZodS, _excluded);
79
141
  var type = inferFieldType(baseSchema, fieldType);
80
142
  var defaultValue = getDefaultValueInZodStack(schema);
143
+ var fieldConfig = fieldConfigBase;
81
144
  // Enums
82
145
  var options = baseSchema._def.values;
83
146
  var optionValues = [];
@@ -91,16 +154,14 @@ function parseField(name, schema, history) {
91
154
  }
92
155
  }
93
156
  // Arrays and objects
94
- var subSchema = [];
95
- if (baseSchema._def.typeName === 'ZodObject') {
96
- subSchema = Object.entries(baseSchema.shape).map(function (_ref) {
97
- var key = _ref[0],
98
- field = _ref[1];
99
- return parseField(key, field, [history, name].join('.'));
100
- });
101
- }
157
+ var getSubSchema = typeMapping[baseSchema._def.typeName];
158
+ var subSchema = getSubSchema == null ? void 0 : getSubSchema(baseSchema, name, history, dependecys);
102
159
  if (baseSchema._def.typeName === 'ZodArray') {
103
- subSchema = [parseField('0', baseSchema._def.type)];
160
+ var _baseSchema$_def$minL, _baseSchema$_def$maxL;
161
+ fieldConfig = _extends({
162
+ min: ((_baseSchema$_def$minL = baseSchema._def.minLength) == null ? void 0 : _baseSchema$_def$minL.value) || 1,
163
+ max: (_baseSchema$_def$maxL = baseSchema._def.maxLength) == null ? void 0 : _baseSchema$_def$maxL.value
164
+ }, fieldConfig);
104
165
  }
105
166
  var resp = {
106
167
  name: {
@@ -129,10 +190,11 @@ function getBaseSchema(schema) {
129
190
  var parseSchema = function parseSchema(S) {
130
191
  var objectSchema = S instanceof zod.z.ZodEffects ? S.innerType() : S;
131
192
  var shape = objectSchema.shape;
132
- var fields = Object.fromEntries(Object.entries(shape).map(function (_ref2) {
133
- var key = _ref2[0],
134
- field = _ref2[1];
135
- return [key, parseField(key, field)];
193
+ var dependecys = objectSchema._def.fieldConfig;
194
+ var fields = Object.fromEntries(Object.entries(shape).map(function (_ref4) {
195
+ var key = _ref4[0],
196
+ field = _ref4[1];
197
+ return [key, parseField(key, field, '', dependecys)];
136
198
  }));
137
199
  return {
138
200
  fields: fields
@@ -152,29 +214,33 @@ var useFields = function useFields(key) {
152
214
  var FormInstantElement = function FormInstantElement(_ref) {
153
215
  var name = _ref.name;
154
216
  var field = useFields(name);
155
- var inputs = Object.values(field.schema);
217
+ var inputs = Object.values(field.schema || {});
156
218
  var id = react.useId();
157
219
  return jsxRuntime.jsx(jsxRuntime.Fragment, {
158
220
  children: inputs.map(function (props) {
221
+ var _props$name;
159
222
  return jsxRuntime.jsx(react.Fragment, {
160
223
  children: jsxRuntime.jsx(reactInputMapping.ElementMapping, {
161
224
  formProps: props
162
225
  })
163
- }, id + "-" + props.name.history);
226
+ }, id + "-" + (((_props$name = props.name) == null ? void 0 : _props$name.history) || ''));
164
227
  })
165
228
  });
166
229
  };
167
230
 
168
- var FormInstantProvider = function FormInstantProvider(_ref) {
231
+ var FormInstantProvider = /*#__PURE__*/react.memo(function (_ref) {
169
232
  var children = _ref.children,
170
233
  schema = _ref.schema;
171
234
  return jsxRuntime.jsx(ZodResolverContext.Provider, {
172
235
  value: schema,
173
236
  children: children
174
237
  });
175
- };
238
+ });
176
239
 
240
+ exports.FIELD_CONFIG_SYMBOL = FIELD_CONFIG_SYMBOL;
177
241
  exports.FormInstantElement = FormInstantElement;
178
242
  exports.FormInstantProvider = FormInstantProvider;
179
243
  exports.createZodSchemaFieldConfig = createZodSchemaFieldConfig;
244
+ exports.extendZodWithFieldConfig = extendZodWithFieldConfig;
245
+ exports.getFieldConfigInZodStack = getFieldConfigInZodStack;
180
246
  //# sourceMappingURL=react-resolver-zod.cjs.development.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-resolver-zod.cjs.development.js","sources":["../src/context.tsx","../src/funcs/default-values.ts","../src/funcs/field-config.ts","../src/funcs/field-type-inference.ts","../src/funcs/schema-parser.ts","../src/useSchema.tsx","../src/element.tsx","../src/provider.tsx"],"sourcesContent":["import { createContext } from 'use-context-selector';\nimport { zodResolverProps } from './type';\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from 'zod';\nimport { ZodObjectOrWrapped } from './types';\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from 'zod';\nimport { FieldConfig, SuperRefineFunction } from './types';\nexport const FIELD_CONFIG_SYMBOL = Symbol('GetFieldConfig');\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === 'ZodEffects') {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if ('innerType' in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if ('schema' in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from 'zod';\nimport { FieldConfig } from './types';\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig['fieldType']): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n ['ZodObject', 'object'],\n ['ZodString', 'string'],\n ['ZodNumber', 'number'],\n ['ZodBoolean', 'boolean'],\n ['ZodDate', 'date'],\n ['ZodEnum', 'select'],\n ['ZodNativeEnum', 'select'],\n ['ZodArray', 'array'],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || 'string'; // Default to string for unknown types\n}\n","import { ParsedField } from '@form-instant/react-input-mapping';\nimport { z } from 'zod';\nimport { getDefaultValueInZodStack } from './default-values';\nimport { getFieldConfigInZodStack } from './field-config';\nimport { inferFieldType } from './field-type-inference';\nimport { ParsedSchema, ZodObjectOrWrapped } from './types';\n\nfunction parseField(name: string, schema: z.ZodTypeAny, history: string = ''): ParsedField<any> {\n const baseSchema = getBaseSchema(schema);\n const { fieldType, ...fieldConfig } = getFieldConfigInZodStack(schema);\n const type = inferFieldType(baseSchema, fieldType);\n const defaultValue = getDefaultValueInZodStack(schema);\n\n // Enums\n const options = baseSchema._def.values;\n let optionValues: [string, string][] = [];\n if (options) {\n if (!Array.isArray(options)) {\n optionValues = Object.entries(options);\n } else {\n optionValues = options.map((value) => [value, value]);\n }\n }\n\n // Arrays and objects\n let subSchema: ParsedField<any>[] = [];\n if (baseSchema._def.typeName === 'ZodObject') {\n subSchema = Object.entries((baseSchema as any).shape).map(([key, field]) =>\n parseField(key, field as z.ZodTypeAny, [history, name].join('.')),\n );\n }\n if (baseSchema._def.typeName === 'ZodArray') {\n subSchema = [parseField('0', baseSchema._def.type)];\n }\n\n const resp = {\n name: { current: name, history: [history, name].join('.') },\n type,\n required: !schema.isOptional(),\n default: defaultValue,\n fieldConfig,\n options: optionValues,\n schema: subSchema,\n description: baseSchema.description,\n };\n\n return resp;\n}\n\nfunction getBaseSchema<ChildType extends z.ZodAny | z.ZodTypeAny | z.AnyZodObject = z.ZodAny>(\n schema: ChildType | z.ZodEffects<ChildType>,\n): ChildType {\n if ('innerType' in schema._def) {\n return getBaseSchema(schema._def.innerType as ChildType);\n }\n if ('schema' in schema._def) {\n return getBaseSchema(schema._def.schema as ChildType);\n }\n\n return schema as ChildType;\n}\n\nexport const parseSchema = (S: ZodObjectOrWrapped): ParsedSchema => {\n const objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;\n const shape = objectSchema.shape;\n\n const fields = Object.fromEntries(\n Object.entries(shape).map(([key, field]) => [key, parseField(key, field as z.ZodTypeAny)]),\n );\n\n return { fields };\n};\n","import { useContext } from 'use-context-selector';\nimport { ZodEffects, ZodObject } from 'zod';\nimport { ZodResolverContext } from './context';\nimport { parseSchema } from './funcs/schema-parser';\n\nexport const useSchemaBase = () =>\n useContext(ZodResolverContext) as ZodObject<never, never> | ZodEffects<never, never>;\n\nexport const useFields = <Sc extends Record<string, any>>(key: keyof Sc) => {\n const S = useSchemaBase();\n\n const { fields } = parseSchema(S);\n\n return fields[key as string];\n};\n","import { ElementMapping } from '@form-instant/react-input-mapping';\nimport { Fragment, useId } from 'react';\nimport { useFields } from './useSchema';\n\nexport interface ElementProps<Schema extends Record<string, any>> {\n name: keyof Schema;\n}\n\nexport const FormInstantElement = <S extends Record<string, any>>({ name }: ElementProps<S>) => {\n const field = useFields(name);\n\n const inputs = Object.values(field.schema!);\n\n const id = useId();\n\n return (\n <>\n {inputs.map((props) => {\n return (\n <Fragment key={`${id}-${props.name.history}`}>\n <ElementMapping formProps={props} />\n </Fragment>\n );\n })}\n </>\n );\n};\n","import { FC, ReactNode } from 'react';\nimport { ZodResolverContext } from './context';\nimport { zodResolverProps } from './type';\nexport const FormInstantProvider: FC<{ schema: zodResolverProps; children: ReactNode }> = ({\n children,\n schema,\n}) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","undefined","FIELD_CONFIG_SYMBOL","Symbol","createZodSchemaFieldConfig","config","refinementFunction","getFieldConfigInZodStack","typedSchema","typeName","effect","refinement","inferFieldType","fieldType","type","zodToInputType","Map","match","get","parseField","name","history","baseSchema","getBaseSchema","_getFieldConfigInZodS","fieldConfig","_objectWithoutPropertiesLoose","_excluded","options","values","optionValues","Array","isArray","Object","entries","map","value","subSchema","shape","_ref","key","field","join","resp","current","required","isOptional","description","parseSchema","S","objectSchema","fields","fromEntries","_ref2","useSchemaBase","useContext","useFields","_parseSchema","FormInstantElement","inputs","id","useId","_jsx","props","Fragment","children","ElementMapping","formProps","FormInstantProvider","Provider"],"mappings":";;;;;;;;AAGO,IAAMA,kBAAkB,gBAAGC,gCAAa,CAAmB,EAAsB,CAAC;;;;;;;;;;;;ACAnF,SAAUC,yBAAyBA,CAACC,MAAoB,EAAA;AAC1D,EAAA,IAAIA,MAAM,YAAYC,KAAC,CAACC,UAAU,EAAE;AAChC,IAAA,OAAOF,MAAM,CAACG,IAAI,CAACC,YAAY,EAAE,CAAA;AACpC,GAAA;AAED,EAAA,IAAIJ,MAAM,YAAYC,KAAC,CAACI,UAAU,EAAE;AAChC,IAAA,OAAON,yBAAyB,CAACC,MAAM,CAACM,SAAS,EAAE,CAAC,CAAA;AACvD,GAAA;AAED,EAAA,OAAOC,SAAS,CAAA;AACpB;;ACXO,IAAMC,mBAAmB,gBAAGC,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAE9CC,IAAAA,0BAA0B,GACnC,SADSA,0BAA0BA,GAAA;EAAA,OAEnC,UAACC,MAAqD,EAAyB;AAC3E,IAAA,IAAMC,kBAAkB,GAAwB,SAA1CA,kBAAkBA,GAA6B;AACjD;KACH,CAAA;AAED;AACAA,IAAAA,kBAAkB,CAACJ,mBAAmB,CAAC,GAAGG,MAAM,CAAA;AAEhD,IAAA,OAAOC,kBAAkB,CAAA;GAC5B,CAAA;AAAA,EAAA;AAEC,SAAUC,wBAAwBA,CAACb,MAAoB,EAAA;EACzD,IAAMc,WAAW,GAAGd,MAA4D,CAAA;AAEhF,EAAA,IAAIc,WAAW,CAACX,IAAI,CAACY,QAAQ,KAAK,YAAY,EAAE;AAC5C,IAAA,IAAMC,MAAM,GAAGF,WAAW,CAACX,IAAI,CAACa,MAA+B,CAAA;AAC/D,IAAA,IAA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,IAAI,CAAA;AACpE,EAAA,IAAMqB,KAAK,GAAGe,SAAS,CAACpC,IAAI,CAAC,CAAA;EAE7B,IAAMuC,MAAM,GAAG1B,MAAM,CAACJ,MAAM,CAACY,KAAK,CAAC/C,MAAO,CAAC,CAAA;AAE3C,EAAA,IAAMkE,EAAE,GAAGC,WAAK,EAAE,CAAA;EAElB,OACIC;cACKH,MAAM,CAACxB,GAAG,CAAC,UAAC4B,KAAK,EAAI;MAClB,OACID,eAACE,cAAQ,EAAA;AAAAC,QAAAA,QAAA,EACLH,eAACI,gCAAc,EAAA;AAACC,UAAAA,SAAS,EAAEJ,KAAAA;SAAK,CAAA;SADlBH,EAAE,GAAIG,GAAAA,GAAAA,KAAK,CAAC3C,IAAI,CAACC,OAAS,CAEjC,CAAA;KAElB,CAAA;AACF,GAAA,CAAA,CAAA;AAEX;;ICvBa+C,mBAAmB,GAA0D,SAA7EA,mBAAmBA,CAAA7B,IAAA,EAG3B;AAAA,EAAA,IAFD0B,QAAQ,GAAA1B,IAAA,CAAR0B,QAAQ;IACRvE,MAAM,GAAA6C,IAAA,CAAN7C,MAAM,CAAA;AAEN,EAAA,OAAOoE,cAAA,CAACvE,kBAAkB,CAAC8E,QAAQ,EAAA;AAACjC,IAAAA,KAAK,EAAE1C,MAAM;AAAAuE,IAAAA,QAAA,EAAGA,QAAAA;AAAQ,GAAA,CAA+B,CAAA;AAC/F;;;;;;"}
1
+ {"version":3,"file":"react-resolver-zod.cjs.development.js","sources":["../src/context.tsx","../src/funcs/default-values.ts","../src/funcs/field-config.ts","../src/funcs/field-type-inference.ts","../src/funcs/schema-parser.ts","../src/useSchema.tsx","../src/element.tsx","../src/provider.tsx"],"sourcesContent":["import { createContext } from 'use-context-selector';\nimport { zodResolverProps } from './type';\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from 'zod';\nimport { ZodObjectOrWrapped } from './types';\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { z } from 'zod';\nimport { FieldConfig, SuperRefineFunction } from './types';\nexport const FIELD_CONFIG_SYMBOL = Symbol('GetFieldConfig');\n\ndeclare module 'zod' {\n interface ZodType {\n fieldConfig<AdditionalRenderable = null, FieldTypes = string>(\n config: FieldConfig<AdditionalRenderable, FieldTypes>,\n ): this;\n }\n}\n\nexport const extendZodWithFieldConfig = <AdditionalRenderable = null, FieldTypes = string>(\n zod: typeof z,\n) => {\n (zod.ZodType.prototype as any).fieldConfig = function (\n config: FieldConfig<AdditionalRenderable, FieldTypes>,\n ) {\n this._def.fieldConfig = config;\n return this;\n };\n};\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n // Verifica si el esquema tiene fieldConfig directamente\n if (schema._def.fieldConfig) {\n return schema._def.fieldConfig as FieldConfig;\n }\n\n // Si el esquema es un ZodEffects, busca en el innerType\n if ('innerType' in schema._def) {\n return getFieldConfigInZodStack(schema._def.innerType as z.ZodAny);\n }\n\n // Si el esquema es un ZodEffects con un schema interno, busca en el schema\n if ('schema' in schema._def) {\n return getFieldConfigInZodStack(schema._def.schema as z.ZodAny);\n }\n\n // Si no se encuentra fieldConfig, retorna un objeto vacío\n return {} as FieldConfig;\n}\n","import { z } from 'zod';\nimport { FieldConfig } from './types';\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig['fieldType']): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n ['ZodObject', 'object'],\n ['ZodString', 'string'],\n ['ZodNumber', 'number'],\n ['ZodBoolean', 'boolean'],\n ['ZodDate', 'date'],\n ['ZodEnum', 'select'],\n ['ZodNativeEnum', 'select'],\n ['ZodArray', 'array'],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || 'string'; // Default to string for unknown types\n}\n","import { ParsedField } from '@form-instant/react-input-mapping';\nimport { z } from 'zod';\nimport { getDefaultValueInZodStack } from './default-values';\nimport { getFieldConfigInZodStack } from './field-config';\nimport { inferFieldType } from './field-type-inference';\nimport { ParsedSchema, ZodObjectOrWrapped } from './types';\n\nconst typeMapping = {\n ZodDiscriminatedUnion(\n baseSchema: z.ZodTypeAny,\n name: string,\n history: string,\n dependecys: Record<string, any>,\n ) {\n const { optionsMap, discriminator, fieldConfig } = baseSchema._def;\n\n if (!Object.keys(dependecys).length) return [{}] as ParsedField<any, string>[];\n\n const optionKey = dependecys[discriminator];\n const option = optionsMap.get(optionKey);\n\n if (!option) return [{}] as ParsedField<any, string>[];\n\n const entries = Object.entries(option.shape);\n\n const fields = entries\n .filter(([key]) => key !== discriminator)\n .map(([key, field]) => {\n return parseField(\n key,\n field as z.ZodTypeAny,\n [history, name].join('.'),\n dependecys,\n );\n });\n\n fields.unshift({\n name: {\n current: discriminator,\n history: [history, name, discriminator].join('.'),\n },\n type: 'discriminator',\n required: true,\n default: optionKey,\n fieldConfig,\n options: Array.from(optionsMap.keys()).map((key) => [String(key), String(key)]),\n });\n\n return fields;\n },\n\n ZodObject(\n baseSchema: z.ZodTypeAny,\n name: string,\n history: string,\n dependecys: Record<string, any>,\n ) {\n return Object.entries((baseSchema as any).shape).map(([key, field]) =>\n parseField(key, field as z.ZodTypeAny, [history, name].join('.'), dependecys),\n );\n },\n\n ZodArray(\n baseSchema: z.ZodTypeAny,\n name: string,\n history: string,\n dependecys: Record<string, any>,\n ) {\n return [parseField('0', baseSchema._def.type, [history, name].join('.'), dependecys)];\n },\n};\n\nfunction parseField(\n name: string,\n schema: z.ZodTypeAny,\n history: string = '',\n dependecys: Record<string, any> = {},\n): ParsedField<any> {\n const baseSchema = getBaseSchema(schema);\n const { fieldType, ...fieldConfigBase } = getFieldConfigInZodStack(schema);\n const type = inferFieldType(baseSchema, fieldType);\n const defaultValue = getDefaultValueInZodStack(schema);\n\n let fieldConfig = fieldConfigBase;\n\n // Enums\n const options = baseSchema._def.values;\n let optionValues: [string, string][] = [];\n if (options) {\n if (!Array.isArray(options)) {\n optionValues = Object.entries(options);\n } else {\n optionValues = options.map((value) => [value, value]);\n }\n }\n\n // Arrays and objects\n const getSubSchema = typeMapping[baseSchema._def.typeName as keyof typeof typeMapping];\n\n const subSchema = getSubSchema?.(baseSchema, name, history, dependecys);\n\n if (baseSchema._def.typeName === 'ZodArray') {\n fieldConfig = {\n min: baseSchema._def.minLength?.value || 1,\n max: baseSchema._def.maxLength?.value,\n ...fieldConfig,\n };\n }\n\n const resp = {\n name: { current: name, history: [history, name].join('.') },\n type,\n required: !schema.isOptional(),\n default: defaultValue,\n fieldConfig,\n options: optionValues,\n schema: subSchema,\n description: baseSchema.description,\n };\n\n return resp;\n}\n\nfunction getBaseSchema<ChildType extends z.ZodAny | z.ZodTypeAny | z.AnyZodObject = z.ZodAny>(\n schema: ChildType | z.ZodEffects<ChildType>,\n): ChildType {\n if ('innerType' in schema._def) {\n return getBaseSchema(schema._def.innerType as ChildType);\n }\n if ('schema' in schema._def) {\n return getBaseSchema(schema._def.schema as ChildType);\n }\n\n return schema as ChildType;\n}\n\nexport const parseSchema = (S: ZodObjectOrWrapped): ParsedSchema => {\n const objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;\n const shape = objectSchema.shape;\n\n const dependecys = (objectSchema._def as any).fieldConfig;\n\n const fields = Object.fromEntries(\n Object.entries(shape).map(([key, field]) => [\n key,\n parseField(key, field as z.ZodTypeAny, '', dependecys),\n ]),\n );\n\n return { fields };\n};\n","import { useContext } from 'use-context-selector';\nimport { ZodEffects, ZodObject } from 'zod';\nimport { ZodResolverContext } from './context';\nimport { parseSchema } from './funcs/schema-parser';\n\nexport const useSchemaBase = () =>\n useContext(ZodResolverContext) as ZodObject<never, never> | ZodEffects<never, never>;\n\nexport const useFields = <Sc extends Record<string, any>>(key: keyof Sc) => {\n const S = useSchemaBase();\n\n const { fields } = parseSchema(S);\n\n return fields[key as string];\n};\n","import { ElementMapping } from '@form-instant/react-input-mapping';\nimport { Fragment, useId } from 'react';\nimport { useFields } from './useSchema';\n\nexport interface ElementProps<Schema extends Record<string, any>> {\n name: keyof Schema;\n}\n\nexport const FormInstantElement = <S extends Record<string, any>>({ name }: ElementProps<S>) => {\n const field = useFields(name);\n\n const inputs = Object.values(field.schema || {});\n\n const id = useId();\n\n return (\n <>\n {inputs.map((props) => {\n return (\n <Fragment key={`${id}-${props.name?.history || ''}`}>\n <ElementMapping formProps={props} />\n </Fragment>\n );\n })}\n </>\n );\n};\n","import { FC, memo, ReactNode } from 'react';\nimport { ZodResolverContext } from './context';\nimport { zodResolverProps } from './type';\nexport const FormInstantProvider: FC<{\n schema: zodResolverProps;\n children: ReactNode;\n}> = memo(({ children, schema }) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n});\n"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","undefined","FIELD_CONFIG_SYMBOL","Symbol","extendZodWithFieldConfig","zod","ZodType","prototype","fieldConfig","config","createZodSchemaFieldConfig","refinementFunction","getFieldConfigInZodStack","inferFieldType","fieldType","type","typeName","zodToInputType","Map","match","get","typeMapping","ZodDiscriminatedUnion","baseSchema","name","history","dependecys","_baseSchema$_def","optionsMap","discriminator","Object","keys","length","optionKey","option","entries","shape","fields","filter","_ref","key","map","_ref2","field","parseField","join","unshift","current","required","options","Array","from","String","ZodObject","_ref3","ZodArray","getBaseSchema","_getFieldConfigInZodS","fieldConfigBase","_objectWithoutPropertiesLoose","_excluded","values","optionValues","isArray","value","getSubSchema","subSchema","_baseSchema$_def$minL","_baseSchema$_def$maxL","_extends","min","minLength","max","maxLength","resp","isOptional","description","parseSchema","S","objectSchema","fromEntries","_ref4","useSchemaBase","useContext","useFields","_parseSchema","FormInstantElement","inputs","id","useId","_jsx","props","_props$name","Fragment","children","ElementMapping","formProps","FormInstantProvider","memo","Provider"],"mappings":";;;;;;;;AAGO,IAAMA,kBAAkB,gBAAGC,gCAAa,CAAmB,EAAsB,CAAC;;;;;;;;;;;;;;;;;;;;;ACAnF,SAAUC,yBAAyBA,CAACC,MAAoB,EAAA;AAC1D,EAAA,IAAIA,MAAM,YAAYC,KAAC,CAACC,UAAU,EAAE;AAChC,IAAA,OAAOF,MAAM,CAACG,IAAI,CAACC,YAAY,EAAE,CAAA;AACpC,GAAA;AAED,EAAA,IAAIJ,MAAM,YAAYC,KAAC,CAACI,UAAU,EAAE;AAChC,IAAA,OAAON,yBAAyB,CAACC,MAAM,CAACM,SAAS,EAAE,CAAC,CAAA;AACvD,GAAA;AAED,EAAA,OAAOC,SAAS,CAAA;AACpB;;ICXaC,mBAAmB,gBAAGC,MAAM,CAAC,gBAAgB,EAAC;IAU9CC,wBAAwB,GAAG,SAA3BA,wBAAwBA,CACjCC,GAAa,EACb;EACCA,GAAG,CAACC,OAAO,CAACC,SAAiB,CAACC,WAAW,GAAG,UACzCC,MAAqD,EAAA;AAErD,IAAA,IAAI,CAACZ,IAAI,CAACW,WAAW,GAAGC,MAAM,CAAA;AAC9B,IAAA,OAAO,IAAI,CAAA;G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AAQ,EACL;AAAAC,QAAAA,QAAA,EAAAJ,cAAA,CAACK,gCAAc,EAAC;AAAAC,UAAAA,SAAS,EAAEL,KAAAA;SAAS,CAAA;AAAA,OAAA,EADtBH,EAAE,GAAA,GAAA,IAAI,CAAAI,CAAAA,WAAA,GAAAD,KAAK,CAACnE,IAAI,KAAA,IAAA,GAAA,KAAA,CAAA,GAAVoE,WAAA,CAAYnE,OAAO,KAAI,EAAE,CAAE,CAExC,CAAA;KAElB,CAAA;AACF,GAAA,CAAA,CAAA;AAEX;;ICvBawE,mBAAmB,gBAG3BC,UAAI,CAAC,UAAA3D,IAAA,EAAyB;AAAA,EAAA,IAAtBuD,QAAQ,GAAAvD,IAAA,CAARuD,QAAQ;IAAEpG,MAAM,GAAA6C,IAAA,CAAN7C,MAAM,CAAA;AACzB,EAAA,OAAOgG,cAAA,CAACnG,kBAAkB,CAAC4G,QAAQ,EAAA;AAACnC,IAAAA,KAAK,EAAEtE,MAAM;AAAAoG,IAAAA,QAAA,EAAGA,QAAAA;AAAQ,GAAA,CAA+B,CAAA;AAC/F,CAAC;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react/jsx-runtime"),n=require("@form-instant/react-input-mapping"),r=require("react"),t=require("use-context-selector"),i=require("zod"),o=t.createContext({});function a(e){return e instanceof i.z.ZodDefault?e._def.defaultValue():e instanceof i.z.ZodEffects?a(e.innerType()):void 0}var f=Symbol("GetFieldConfig");function u(e){var n=e;if("ZodEffects"===n._def.typeName){var r=n._def.effect.refinement;if(f in r)return r[f]}return"innerType"in n._def?u(n._def.innerType):"schema"in n._def?u(n._def.schema):{}}var c=["fieldType"];function d(e,n,r){void 0===r&&(r="");var t=s(n),i=u(n),o=i.fieldType,f=function(e,n){if(null==e)return{};var r={};for(var t in e)if({}.hasOwnProperty.call(e,t)){if(n.includes(t))continue;r[t]=e[t]}return r}(i,c),m=function(e,n){if(n)return n;var r=e._def.typeName;return new Map([["ZodObject","object"],["ZodString","string"],["ZodNumber","number"],["ZodBoolean","boolean"],["ZodDate","date"],["ZodEnum","select"],["ZodNativeEnum","select"],["ZodArray","array"]]).get(r)||"string"}(t,o),p=a(n),l=t._def.values,y=[];l&&(y=Array.isArray(l)?l.map((function(e){return[e,e]})):Object.entries(l));var v=[];return"ZodObject"===t._def.typeName&&(v=Object.entries(t.shape).map((function(n){return d(n[0],n[1],[r,e].join("."))}))),"ZodArray"===t._def.typeName&&(v=[d("0",t._def.type)]),{name:{current:e,history:[r,e].join(".")},type:m,required:!n.isOptional(),default:p,fieldConfig:f,options:y,schema:v,description:t.description}}function s(e){return"innerType"in e._def?s(e._def.innerType):"schema"in e._def?s(e._def.schema):e}exports.FormInstantElement=function(a){var f,u,c,s=(f=a.name,(u=t.useContext(o),c=u instanceof i.z.ZodEffects?u.innerType():u,{fields:Object.fromEntries(Object.entries(c.shape).map((function(e){var n=e[0];return[n,d(n,e[1])]})))}).fields[f]),m=Object.values(s.schema),p=r.useId();return e.jsx(e.Fragment,{children:m.map((function(t){return e.jsx(r.Fragment,{children:e.jsx(n.ElementMapping,{formProps:t})},p+"-"+t.name.history)}))})},exports.FormInstantProvider=function(n){return e.jsx(o.Provider,{value:n.schema,children:n.children})},exports.createZodSchemaFieldConfig=function(){return function(e){var n=function(){};return n[f]=e,n}};
1
+ "use strict";var e=require("react/jsx-runtime"),n=require("@form-instant/react-input-mapping"),r=require("react"),t=require("use-context-selector"),i=require("zod"),o=t.createContext({});function a(){return a=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)({}).hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},a.apply(null,arguments)}function f(e){return e instanceof i.z.ZodDefault?e._def.defaultValue():e instanceof i.z.ZodEffects?f(e.innerType()):void 0}var u=Symbol("GetFieldConfig");function d(e){return e._def.fieldConfig?e._def.fieldConfig:"innerType"in e._def?d(e._def.innerType):"schema"in e._def?d(e._def.schema):{}}var c=["fieldType"],s={ZodDiscriminatedUnion:function(e,n,r,t){var i=e._def,o=i.optionsMap,a=i.discriminator,f=i.fieldConfig;if(!Object.keys(t).length)return[{}];var u=t[a],d=o.get(u);if(!d)return[{}];var c=Object.entries(d.shape).filter((function(e){return e[0]!==a})).map((function(e){return l(e[0],e[1],[r,n].join("."),t)}));return c.unshift({name:{current:a,history:[r,n,a].join(".")},type:"discriminator",required:!0,default:u,fieldConfig:f,options:Array.from(o.keys()).map((function(e){return[String(e),String(e)]}))}),c},ZodObject:function(e,n,r,t){return Object.entries(e.shape).map((function(e){return l(e[0],e[1],[r,n].join("."),t)}))},ZodArray:function(e,n,r,t){return[l("0",e._def.type,[r,n].join("."),t)]}};function l(e,n,r,t){void 0===r&&(r=""),void 0===t&&(t={});var i=p(n),o=d(n),u=o.fieldType,l=function(e,n){if(null==e)return{};var r={};for(var t in e)if({}.hasOwnProperty.call(e,t)){if(n.includes(t))continue;r[t]=e[t]}return r}(o,c),m=function(e,n){if(n)return n;var r=e._def.typeName;return new Map([["ZodObject","object"],["ZodString","string"],["ZodNumber","number"],["ZodBoolean","boolean"],["ZodDate","date"],["ZodEnum","select"],["ZodNativeEnum","select"],["ZodArray","array"]]).get(r)||"string"}(i,u),v=f(n),y=l,g=i._def.values,h=[];g&&(h=Array.isArray(g)?g.map((function(e){return[e,e]})):Object.entries(g));var _,j,Z=s[i._def.typeName],b=null==Z?void 0:Z(i,e,r,t);return"ZodArray"===i._def.typeName&&(y=a({min:(null==(_=i._def.minLength)?void 0:_.value)||1,max:null==(j=i._def.maxLength)?void 0:j.value},y)),{name:{current:e,history:[r,e].join(".")},type:m,required:!n.isOptional(),default:v,fieldConfig:y,options:h,schema:b,description:i.description}}function p(e){return"innerType"in e._def?p(e._def.innerType):"schema"in e._def?p(e._def.schema):e}var m=r.memo((function(n){return e.jsx(o.Provider,{value:n.schema,children:n.children})}));exports.FIELD_CONFIG_SYMBOL=u,exports.FormInstantElement=function(a){var f,u,d,c,s=(f=a.name,(u=t.useContext(o),d=u instanceof i.z.ZodEffects?u.innerType():u,c=d._def.fieldConfig,{fields:Object.fromEntries(Object.entries(d.shape).map((function(e){var n=e[0];return[n,l(n,e[1],"",c)]})))}).fields[f]),p=Object.values(s.schema||{}),m=r.useId();return e.jsx(e.Fragment,{children:p.map((function(t){var i;return e.jsx(r.Fragment,{children:e.jsx(n.ElementMapping,{formProps:t})},m+"-"+((null==(i=t.name)?void 0:i.history)||""))}))})},exports.FormInstantProvider=m,exports.createZodSchemaFieldConfig=function(){return function(e){var n=function(){};return n[u]=e,n}},exports.extendZodWithFieldConfig=function(e){e.ZodType.prototype.fieldConfig=function(e){return this._def.fieldConfig=e,this}},exports.getFieldConfigInZodStack=d;
2
2
  //# sourceMappingURL=react-resolver-zod.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-resolver-zod.cjs.production.min.js","sources":["../src/context.tsx","../src/funcs/default-values.ts","../src/funcs/field-config.ts","../src/funcs/schema-parser.ts","../src/funcs/field-type-inference.ts","../src/element.tsx","../src/useSchema.tsx","../src/provider.tsx"],"sourcesContent":["import { createContext } from 'use-context-selector';\nimport { zodResolverProps } from './type';\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from 'zod';\nimport { ZodObjectOrWrapped } from './types';\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from 'zod';\nimport { FieldConfig, SuperRefineFunction } from './types';\nexport const FIELD_CONFIG_SYMBOL = Symbol('GetFieldConfig');\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === 'ZodEffects') {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if ('innerType' in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if ('schema' in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { ParsedField } from '@form-instant/react-input-mapping';\nimport { z } from 'zod';\nimport { getDefaultValueInZodStack } from './default-values';\nimport { getFieldConfigInZodStack } from './field-config';\nimport { inferFieldType } from './field-type-inference';\nimport { ParsedSchema, ZodObjectOrWrapped } from './types';\n\nfunction parseField(name: string, schema: z.ZodTypeAny, history: string = ''): ParsedField<any> {\n const baseSchema = getBaseSchema(schema);\n const { fieldType, ...fieldConfig } = getFieldConfigInZodStack(schema);\n const type = inferFieldType(baseSchema, fieldType);\n const defaultValue = getDefaultValueInZodStack(schema);\n\n // Enums\n const options = baseSchema._def.values;\n let optionValues: [string, string][] = [];\n if (options) {\n if (!Array.isArray(options)) {\n optionValues = Object.entries(options);\n } else {\n optionValues = options.map((value) => [value, value]);\n }\n }\n\n // Arrays and objects\n let subSchema: ParsedField<any>[] = [];\n if (baseSchema._def.typeName === 'ZodObject') {\n subSchema = Object.entries((baseSchema as any).shape).map(([key, field]) =>\n parseField(key, field as z.ZodTypeAny, [history, name].join('.')),\n );\n }\n if (baseSchema._def.typeName === 'ZodArray') {\n subSchema = [parseField('0', baseSchema._def.type)];\n }\n\n const resp = {\n name: { current: name, history: [history, name].join('.') },\n type,\n required: !schema.isOptional(),\n default: defaultValue,\n fieldConfig,\n options: optionValues,\n schema: subSchema,\n description: baseSchema.description,\n };\n\n return resp;\n}\n\nfunction getBaseSchema<ChildType extends z.ZodAny | z.ZodTypeAny | z.AnyZodObject = z.ZodAny>(\n schema: ChildType | z.ZodEffects<ChildType>,\n): ChildType {\n if ('innerType' in schema._def) {\n return getBaseSchema(schema._def.innerType as ChildType);\n }\n if ('schema' in schema._def) {\n return getBaseSchema(schema._def.schema as ChildType);\n }\n\n return schema as ChildType;\n}\n\nexport const parseSchema = (S: ZodObjectOrWrapped): ParsedSchema => {\n const objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;\n const shape = objectSchema.shape;\n\n const fields = Object.fromEntries(\n Object.entries(shape).map(([key, field]) => [key, parseField(key, field as z.ZodTypeAny)]),\n );\n\n return { fields };\n};\n","import { z } from 'zod';\nimport { FieldConfig } from './types';\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig['fieldType']): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n ['ZodObject', 'object'],\n ['ZodString', 'string'],\n ['ZodNumber', 'number'],\n ['ZodBoolean', 'boolean'],\n ['ZodDate', 'date'],\n ['ZodEnum', 'select'],\n ['ZodNativeEnum', 'select'],\n ['ZodArray', 'array'],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || 'string'; // Default to string for unknown types\n}\n","import { ElementMapping } from '@form-instant/react-input-mapping';\nimport { Fragment, useId } from 'react';\nimport { useFields } from './useSchema';\n\nexport interface ElementProps<Schema extends Record<string, any>> {\n name: keyof Schema;\n}\n\nexport const FormInstantElement = <S extends Record<string, any>>({ name }: ElementProps<S>) => {\n const field = useFields(name);\n\n const inputs = Object.values(field.schema!);\n\n const id = useId();\n\n return (\n <>\n {inputs.map((props) => {\n return (\n <Fragment key={`${id}-${props.name.history}`}>\n <ElementMapping formProps={props} />\n </Fragment>\n );\n })}\n </>\n );\n};\n","import { useContext } from 'use-context-selector';\nimport { ZodEffects, ZodObject } from 'zod';\nimport { ZodResolverContext } from './context';\nimport { parseSchema } from './funcs/schema-parser';\n\nexport const useSchemaBase = () =>\n useContext(ZodResolverContext) as ZodObject<never, never> | ZodEffects<never, never>;\n\nexport const useFields = <Sc extends Record<string, any>>(key: keyof Sc) => {\n const S = useSchemaBase();\n\n const { fields } = parseSchema(S);\n\n return fields[key as string];\n};\n","import { FC, ReactNode } from 'react';\nimport { ZodResolverContext } from './context';\nimport { zodResolverProps } from './type';\nexport const FormInstantProvider: FC<{ schema: zodResolverProps; children: ReactNode }> = ({\n children,\n schema,\n}) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","FIELD_CONFIG_SYMBOL","Symbol","getFieldConfigInZodStack","typedSchema","typeName","refinementFunction","effect","refinement","parseField","name","history","baseSchema","getBaseSchema","_getFieldConfigInZodS","fieldType","fieldConfig","_objectWithoutPropertiesLoose","_excluded","type","Map","get","inferFieldType","options","values","optionValues","Array","isArray","map","value","Object","entries","subSchema","shape","_ref","join","current","required","isOptional","default","description","key","S","objectSchema","field","useContext","fields","fromEntries","_ref2","inputs","id","useId","_jsx","props","Fragment","children","ElementMapping","formProps","jsx","Provider","config"],"mappings":"qKAGaA,EAAqBC,EAAaA,cAAmB,ICA5D,SAAUC,EAA0BC,GACtC,OAAIA,aAAkBC,EAACA,EAACC,WACbF,EAAOG,KAAKC,eAGnB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AmBL,GAAuB2D,EAEnCtD,EACV"}
1
+ {"version":3,"file":"react-resolver-zod.cjs.production.min.js","sources":["../src/context.tsx","../src/funcs/default-values.ts","../src/funcs/field-config.ts","../src/funcs/schema-parser.ts","../src/funcs/field-type-inference.ts","../src/provider.tsx","../src/element.tsx","../src/useSchema.tsx"],"sourcesContent":["import { createContext } from 'use-context-selector';\nimport { zodResolverProps } from './type';\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from 'zod';\nimport { ZodObjectOrWrapped } from './types';\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { z } from 'zod';\nimport { FieldConfig, SuperRefineFunction } from './types';\nexport const FIELD_CONFIG_SYMBOL = Symbol('GetFieldConfig');\n\ndeclare module 'zod' {\n interface ZodType {\n fieldConfig<AdditionalRenderable = null, FieldTypes = string>(\n config: FieldConfig<AdditionalRenderable, FieldTypes>,\n ): this;\n }\n}\n\nexport const extendZodWithFieldConfig = <AdditionalRenderable = null, FieldTypes = string>(\n zod: typeof z,\n) => {\n (zod.ZodType.prototype as any).fieldConfig = function (\n config: FieldConfig<AdditionalRenderable, FieldTypes>,\n ) {\n this._def.fieldConfig = config;\n return this;\n };\n};\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n // Verifica si el esquema tiene fieldConfig directamente\n if (schema._def.fieldConfig) {\n return schema._def.fieldConfig as FieldConfig;\n }\n\n // Si el esquema es un ZodEffects, busca en el innerType\n if ('innerType' in schema._def) {\n return getFieldConfigInZodStack(schema._def.innerType as z.ZodAny);\n }\n\n // Si el esquema es un ZodEffects con un schema interno, busca en el schema\n if ('schema' in schema._def) {\n return getFieldConfigInZodStack(schema._def.schema as z.ZodAny);\n }\n\n // Si no se encuentra fieldConfig, retorna un objeto vacío\n return {} as FieldConfig;\n}\n","import { ParsedField } from '@form-instant/react-input-mapping';\nimport { z } from 'zod';\nimport { getDefaultValueInZodStack } from './default-values';\nimport { getFieldConfigInZodStack } from './field-config';\nimport { inferFieldType } from './field-type-inference';\nimport { ParsedSchema, ZodObjectOrWrapped } from './types';\n\nconst typeMapping = {\n ZodDiscriminatedUnion(\n baseSchema: z.ZodTypeAny,\n name: string,\n history: string,\n dependecys: Record<string, any>,\n ) {\n const { optionsMap, discriminator, fieldConfig } = baseSchema._def;\n\n if (!Object.keys(dependecys).length) return [{}] as ParsedField<any, string>[];\n\n const optionKey = dependecys[discriminator];\n const option = optionsMap.get(optionKey);\n\n if (!option) return [{}] as ParsedField<any, string>[];\n\n const entries = Object.entries(option.shape);\n\n const fields = entries\n .filter(([key]) => key !== discriminator)\n .map(([key, field]) => {\n return parseField(\n key,\n field as z.ZodTypeAny,\n [history, name].join('.'),\n dependecys,\n );\n });\n\n fields.unshift({\n name: {\n current: discriminator,\n history: [history, name, discriminator].join('.'),\n },\n type: 'discriminator',\n required: true,\n default: optionKey,\n fieldConfig,\n options: Array.from(optionsMap.keys()).map((key) => [String(key), String(key)]),\n });\n\n return fields;\n },\n\n ZodObject(\n baseSchema: z.ZodTypeAny,\n name: string,\n history: string,\n dependecys: Record<string, any>,\n ) {\n return Object.entries((baseSchema as any).shape).map(([key, field]) =>\n parseField(key, field as z.ZodTypeAny, [history, name].join('.'), dependecys),\n );\n },\n\n ZodArray(\n baseSchema: z.ZodTypeAny,\n name: string,\n history: string,\n dependecys: Record<string, any>,\n ) {\n return [parseField('0', baseSchema._def.type, [history, name].join('.'), dependecys)];\n },\n};\n\nfunction parseField(\n name: string,\n schema: z.ZodTypeAny,\n history: string = '',\n dependecys: Record<string, any> = {},\n): ParsedField<any> {\n const baseSchema = getBaseSchema(schema);\n const { fieldType, ...fieldConfigBase } = getFieldConfigInZodStack(schema);\n const type = inferFieldType(baseSchema, fieldType);\n const defaultValue = getDefaultValueInZodStack(schema);\n\n let fieldConfig = fieldConfigBase;\n\n // Enums\n const options = baseSchema._def.values;\n let optionValues: [string, string][] = [];\n if (options) {\n if (!Array.isArray(options)) {\n optionValues = Object.entries(options);\n } else {\n optionValues = options.map((value) => [value, value]);\n }\n }\n\n // Arrays and objects\n const getSubSchema = typeMapping[baseSchema._def.typeName as keyof typeof typeMapping];\n\n const subSchema = getSubSchema?.(baseSchema, name, history, dependecys);\n\n if (baseSchema._def.typeName === 'ZodArray') {\n fieldConfig = {\n min: baseSchema._def.minLength?.value || 1,\n max: baseSchema._def.maxLength?.value,\n ...fieldConfig,\n };\n }\n\n const resp = {\n name: { current: name, history: [history, name].join('.') },\n type,\n required: !schema.isOptional(),\n default: defaultValue,\n fieldConfig,\n options: optionValues,\n schema: subSchema,\n description: baseSchema.description,\n };\n\n return resp;\n}\n\nfunction getBaseSchema<ChildType extends z.ZodAny | z.ZodTypeAny | z.AnyZodObject = z.ZodAny>(\n schema: ChildType | z.ZodEffects<ChildType>,\n): ChildType {\n if ('innerType' in schema._def) {\n return getBaseSchema(schema._def.innerType as ChildType);\n }\n if ('schema' in schema._def) {\n return getBaseSchema(schema._def.schema as ChildType);\n }\n\n return schema as ChildType;\n}\n\nexport const parseSchema = (S: ZodObjectOrWrapped): ParsedSchema => {\n const objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;\n const shape = objectSchema.shape;\n\n const dependecys = (objectSchema._def as any).fieldConfig;\n\n const fields = Object.fromEntries(\n Object.entries(shape).map(([key, field]) => [\n key,\n parseField(key, field as z.ZodTypeAny, '', dependecys),\n ]),\n );\n\n return { fields };\n};\n","import { z } from 'zod';\nimport { FieldConfig } from './types';\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig['fieldType']): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n ['ZodObject', 'object'],\n ['ZodString', 'string'],\n ['ZodNumber', 'number'],\n ['ZodBoolean', 'boolean'],\n ['ZodDate', 'date'],\n ['ZodEnum', 'select'],\n ['ZodNativeEnum', 'select'],\n ['ZodArray', 'array'],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || 'string'; // Default to string for unknown types\n}\n","import { FC, memo, ReactNode } from 'react';\nimport { ZodResolverContext } from './context';\nimport { zodResolverProps } from './type';\nexport const FormInstantProvider: FC<{\n schema: zodResolverProps;\n children: ReactNode;\n}> = memo(({ children, schema }) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n});\n","import { ElementMapping } from '@form-instant/react-input-mapping';\nimport { Fragment, useId } from 'react';\nimport { useFields } from './useSchema';\n\nexport interface ElementProps<Schema extends Record<string, any>> {\n name: keyof Schema;\n}\n\nexport const FormInstantElement = <S extends Record<string, any>>({ name }: ElementProps<S>) => {\n const field = useFields(name);\n\n const inputs = Object.values(field.schema || {});\n\n const id = useId();\n\n return (\n <>\n {inputs.map((props) => {\n return (\n <Fragment key={`${id}-${props.name?.history || ''}`}>\n <ElementMapping formProps={props} />\n </Fragment>\n );\n })}\n </>\n );\n};\n","import { useContext } from 'use-context-selector';\nimport { ZodEffects, ZodObject } from 'zod';\nimport { ZodResolverContext } from './context';\nimport { parseSchema } from './funcs/schema-parser';\n\nexport const useSchemaBase = () =>\n useContext(ZodResolverContext) as ZodObject<never, never> | ZodEffects<never, never>;\n\nexport const useFields = <Sc extends Record<string, any>>(key: keyof Sc) => {\n const S = useSchemaBase();\n\n const { fields } = parseSchema(S);\n\n return fields[key as string];\n};\n"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","FIELD_CONFIG_SYMBOL","Symbol","getFieldConfigInZodStack","fieldConfig","typeMapping","ZodDiscriminatedUnion","baseSchema","name","history","dependecys","_baseSchema$_def","optionsMap","discriminator","Object","keys","length","optionKey","option","get","fields","entries","shape","filter","_ref","map","_ref2","parseField","join","unshift","current","type","required","default","options","Array","from","key","String","ZodObject","_ref3","ZodArray","getBaseSchema","_getFieldConfigInZodS","fieldType","fieldConfigBase","_objectWithoutPropertiesLoose","_excluded","typeName","Map","inferFieldType","values","optionValues","isArray","value","_baseSchema$_def$minL","_baseSchema$_def$maxL","getSubSchema","subSchema","_extends","min","minLength","max","maxLength","isOptional","description","FormInstantProvider","memo","_jsx","jsx","Provider","children","S","objectSchema","field","useContext","fromEntries","_ref4","inputs","id","useId","props","_props$name","Fragment","ElementMapping","formProps","config","refinementFunction","zod","ZodType","prototype","this"],"mappings":"qKAGaA,EAAqBC,EAAaA,cAAmB,4NCA5D,SAAUC,EAA0BC,GACtC,OAAIA,aAAkBC,EAACA,EAACC,WACbF,EAAOG,KAAKC,eAGnBJ,aAAkBC,EAACA,EAACI,WACbN,EAA0BC,EAAOM,kBAD5C,CAKJ,KCXaC,EAAsBC,OAAO,kBAkCpC,SAAUC,EAAyBT,GAErC,OAAIA,EAAOG,KAAKO,YACLV,EAAOG,KAAKO,YAInB,cAAeV,EAAOG,KACfM,EAAyBT,EAAOG,KAAKG,WAI5C,WAAYN,EAAOG,KACZM,EAAyBT,EAAOG,KAAKH,QAIzC,EACX,qBC/CMW,EAAc,CAChBC,sBAA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6C,EAAchD,EAAOG,KAAKH,QAG9BA,CACX,CAEO,IErIMwE,EAGRC,EAAAA,MAAK,SAAA3C,GACN,OAAO4C,EAAAC,IAAC9E,EAAmB+E,SAAQ,CAAChB,MADX9B,EAAN9B,OAC8B6E,SADhC/C,EAAR+C,UAEb,6DCAkC,SAAH/C,GAAgE,ICArCa,EJgI9BmC,EAClBC,EAGA/D,EGnIAgE,GCDgDrC,EDAcb,EAAJhB,MHgIxCgE,EIlIxBG,EAAAA,WAAWpF,GJmILkF,EAAeD,aAAa7E,EAACA,EAACI,WAAayE,EAAExE,YAAcwE,EAG3D9D,EAAc+D,EAAa5E,KAAaO,YASvC,CAAEgB,OAPMN,OAAO8D,YAClB9D,OAAOO,QALGoD,EAAanD,OAKDG,KAAI,SAAAoD,GAAA,IAAExC,EAAGwC,EAAA,GAAO,MAAM,CACxCxC,EACAV,EAAWU,EAFuBwC,EAAA,GAEK,GAAInE,GAC9C,OIvIGU,OAEMiB,IDFRyC,EAAShE,OAAOqC,OAAOuB,EAAMhF,QAAU,CAAA,GAEvCqF,EAAKC,EAAAA,QAEX,OACIZ,EAAAA,yBACKU,EAAOrD,KAAI,SAACwD,GAAS,IAAAC,EAClB,OACId,EAAAA,IAACe,EAAAA,SACG,CAAAZ,SAAAH,EAAAC,IAACe,iBAAe,CAAAC,UAAWJ,KADbF,EAAE,MAAc,OAAVG,EAAAD,EAAMzE,WAAI,EAAV0E,EAAYzE,UAAW,SAOnE,mEJFI,WADmC,OAEnC,SAAC6E,GACG,IAAMC,EAA0C,aAOhD,OAFAA,EAAmBtF,GAAuBqF,EAEnCC,EACV,mCAtBmC,SACpCC,GAECA,EAAIC,QAAQC,UAAkBtF,YAAc,SACzCkF,GAGA,OADAK,KAAK9F,KAAKO,YAAckF,EACjBK,KAEf"}
@@ -1,11 +1,20 @@
1
1
  import { jsx, Fragment } from 'react/jsx-runtime';
2
2
  import { ElementMapping } from '@form-instant/react-input-mapping';
3
- import { useId, Fragment as Fragment$1 } from 'react';
3
+ import { useId, Fragment as Fragment$1, memo } from 'react';
4
4
  import { createContext, useContext } from 'use-context-selector';
5
5
  import { z } from 'zod';
6
6
 
7
7
  var ZodResolverContext = /*#__PURE__*/createContext({});
8
8
 
9
+ function _extends() {
10
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
11
+ for (var e = 1; e < arguments.length; e++) {
12
+ var t = arguments[e];
13
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
14
+ }
15
+ return n;
16
+ }, _extends.apply(null, arguments);
17
+ }
9
18
  function _objectWithoutPropertiesLoose(r, e) {
10
19
  if (null == r) return {};
11
20
  var t = {};
@@ -27,6 +36,12 @@ function getDefaultValueInZodStack(schema) {
27
36
  }
28
37
 
29
38
  var FIELD_CONFIG_SYMBOL = /*#__PURE__*/Symbol('GetFieldConfig');
39
+ var extendZodWithFieldConfig = function extendZodWithFieldConfig(zod) {
40
+ zod.ZodType.prototype.fieldConfig = function (config) {
41
+ this._def.fieldConfig = config;
42
+ return this;
43
+ };
44
+ };
30
45
  var createZodSchemaFieldConfig = function createZodSchemaFieldConfig() {
31
46
  return function (config) {
32
47
  var refinementFunction = function refinementFunction() {
@@ -38,20 +53,19 @@ var createZodSchemaFieldConfig = function createZodSchemaFieldConfig() {
38
53
  };
39
54
  };
40
55
  function getFieldConfigInZodStack(schema) {
41
- var typedSchema = schema;
42
- if (typedSchema._def.typeName === 'ZodEffects') {
43
- var effect = typedSchema._def.effect;
44
- var refinementFunction = effect.refinement;
45
- if (FIELD_CONFIG_SYMBOL in refinementFunction) {
46
- return refinementFunction[FIELD_CONFIG_SYMBOL];
47
- }
56
+ // Verifica si el esquema tiene fieldConfig directamente
57
+ if (schema._def.fieldConfig) {
58
+ return schema._def.fieldConfig;
48
59
  }
49
- if ('innerType' in typedSchema._def) {
50
- return getFieldConfigInZodStack(typedSchema._def.innerType);
60
+ // Si el esquema es un ZodEffects, busca en el innerType
61
+ if ('innerType' in schema._def) {
62
+ return getFieldConfigInZodStack(schema._def.innerType);
51
63
  }
52
- if ('schema' in typedSchema._def) {
53
- return getFieldConfigInZodStack(typedSchema._def.schema);
64
+ // Si el esquema es un ZodEffects con un schema interno, busca en el schema
65
+ if ('schema' in schema._def) {
66
+ return getFieldConfigInZodStack(schema._def.schema);
54
67
  }
68
+ // Si no se encuentra fieldConfig, retorna un objeto vacío
55
69
  return {};
56
70
  }
57
71
 
@@ -66,16 +80,65 @@ function inferFieldType(schema, fieldType) {
66
80
  }
67
81
 
68
82
  var _excluded = ["fieldType"];
69
- function parseField(name, schema, history) {
83
+ var typeMapping = {
84
+ ZodDiscriminatedUnion: function ZodDiscriminatedUnion(baseSchema, name, history, dependecys) {
85
+ var _baseSchema$_def = baseSchema._def,
86
+ optionsMap = _baseSchema$_def.optionsMap,
87
+ discriminator = _baseSchema$_def.discriminator,
88
+ fieldConfig = _baseSchema$_def.fieldConfig;
89
+ if (!Object.keys(dependecys).length) return [{}];
90
+ var optionKey = dependecys[discriminator];
91
+ var option = optionsMap.get(optionKey);
92
+ if (!option) return [{}];
93
+ var entries = Object.entries(option.shape);
94
+ var fields = entries.filter(function (_ref) {
95
+ var key = _ref[0];
96
+ return key !== discriminator;
97
+ }).map(function (_ref2) {
98
+ var key = _ref2[0],
99
+ field = _ref2[1];
100
+ return parseField(key, field, [history, name].join('.'), dependecys);
101
+ });
102
+ fields.unshift({
103
+ name: {
104
+ current: discriminator,
105
+ history: [history, name, discriminator].join('.')
106
+ },
107
+ type: 'discriminator',
108
+ required: true,
109
+ "default": optionKey,
110
+ fieldConfig: fieldConfig,
111
+ options: Array.from(optionsMap.keys()).map(function (key) {
112
+ return [String(key), String(key)];
113
+ })
114
+ });
115
+ return fields;
116
+ },
117
+ ZodObject: function ZodObject(baseSchema, name, history, dependecys) {
118
+ return Object.entries(baseSchema.shape).map(function (_ref3) {
119
+ var key = _ref3[0],
120
+ field = _ref3[1];
121
+ return parseField(key, field, [history, name].join('.'), dependecys);
122
+ });
123
+ },
124
+ ZodArray: function ZodArray(baseSchema, name, history, dependecys) {
125
+ return [parseField('0', baseSchema._def.type, [history, name].join('.'), dependecys)];
126
+ }
127
+ };
128
+ function parseField(name, schema, history, dependecys) {
70
129
  if (history === void 0) {
71
130
  history = '';
72
131
  }
132
+ if (dependecys === void 0) {
133
+ dependecys = {};
134
+ }
73
135
  var baseSchema = getBaseSchema(schema);
74
136
  var _getFieldConfigInZodS = getFieldConfigInZodStack(schema),
75
137
  fieldType = _getFieldConfigInZodS.fieldType,
76
- fieldConfig = _objectWithoutPropertiesLoose(_getFieldConfigInZodS, _excluded);
138
+ fieldConfigBase = _objectWithoutPropertiesLoose(_getFieldConfigInZodS, _excluded);
77
139
  var type = inferFieldType(baseSchema, fieldType);
78
140
  var defaultValue = getDefaultValueInZodStack(schema);
141
+ var fieldConfig = fieldConfigBase;
79
142
  // Enums
80
143
  var options = baseSchema._def.values;
81
144
  var optionValues = [];
@@ -89,16 +152,14 @@ function parseField(name, schema, history) {
89
152
  }
90
153
  }
91
154
  // Arrays and objects
92
- var subSchema = [];
93
- if (baseSchema._def.typeName === 'ZodObject') {
94
- subSchema = Object.entries(baseSchema.shape).map(function (_ref) {
95
- var key = _ref[0],
96
- field = _ref[1];
97
- return parseField(key, field, [history, name].join('.'));
98
- });
99
- }
155
+ var getSubSchema = typeMapping[baseSchema._def.typeName];
156
+ var subSchema = getSubSchema == null ? void 0 : getSubSchema(baseSchema, name, history, dependecys);
100
157
  if (baseSchema._def.typeName === 'ZodArray') {
101
- subSchema = [parseField('0', baseSchema._def.type)];
158
+ var _baseSchema$_def$minL, _baseSchema$_def$maxL;
159
+ fieldConfig = _extends({
160
+ min: ((_baseSchema$_def$minL = baseSchema._def.minLength) == null ? void 0 : _baseSchema$_def$minL.value) || 1,
161
+ max: (_baseSchema$_def$maxL = baseSchema._def.maxLength) == null ? void 0 : _baseSchema$_def$maxL.value
162
+ }, fieldConfig);
102
163
  }
103
164
  var resp = {
104
165
  name: {
@@ -127,10 +188,11 @@ function getBaseSchema(schema) {
127
188
  var parseSchema = function parseSchema(S) {
128
189
  var objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;
129
190
  var shape = objectSchema.shape;
130
- var fields = Object.fromEntries(Object.entries(shape).map(function (_ref2) {
131
- var key = _ref2[0],
132
- field = _ref2[1];
133
- return [key, parseField(key, field)];
191
+ var dependecys = objectSchema._def.fieldConfig;
192
+ var fields = Object.fromEntries(Object.entries(shape).map(function (_ref4) {
193
+ var key = _ref4[0],
194
+ field = _ref4[1];
195
+ return [key, parseField(key, field, '', dependecys)];
134
196
  }));
135
197
  return {
136
198
  fields: fields
@@ -150,27 +212,28 @@ var useFields = function useFields(key) {
150
212
  var FormInstantElement = function FormInstantElement(_ref) {
151
213
  var name = _ref.name;
152
214
  var field = useFields(name);
153
- var inputs = Object.values(field.schema);
215
+ var inputs = Object.values(field.schema || {});
154
216
  var id = useId();
155
217
  return jsx(Fragment, {
156
218
  children: inputs.map(function (props) {
219
+ var _props$name;
157
220
  return jsx(Fragment$1, {
158
221
  children: jsx(ElementMapping, {
159
222
  formProps: props
160
223
  })
161
- }, id + "-" + props.name.history);
224
+ }, id + "-" + (((_props$name = props.name) == null ? void 0 : _props$name.history) || ''));
162
225
  })
163
226
  });
164
227
  };
165
228
 
166
- var FormInstantProvider = function FormInstantProvider(_ref) {
229
+ var FormInstantProvider = /*#__PURE__*/memo(function (_ref) {
167
230
  var children = _ref.children,
168
231
  schema = _ref.schema;
169
232
  return jsx(ZodResolverContext.Provider, {
170
233
  value: schema,
171
234
  children: children
172
235
  });
173
- };
236
+ });
174
237
 
175
- export { FormInstantElement, FormInstantProvider, createZodSchemaFieldConfig };
238
+ export { FIELD_CONFIG_SYMBOL, FormInstantElement, FormInstantProvider, createZodSchemaFieldConfig, extendZodWithFieldConfig, getFieldConfigInZodStack };
176
239
  //# sourceMappingURL=react-resolver-zod.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-resolver-zod.esm.js","sources":["../src/context.tsx","../src/funcs/default-values.ts","../src/funcs/field-config.ts","../src/funcs/field-type-inference.ts","../src/funcs/schema-parser.ts","../src/useSchema.tsx","../src/element.tsx","../src/provider.tsx"],"sourcesContent":["import { createContext } from 'use-context-selector';\nimport { zodResolverProps } from './type';\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from 'zod';\nimport { ZodObjectOrWrapped } from './types';\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from 'zod';\nimport { FieldConfig, SuperRefineFunction } from './types';\nexport const FIELD_CONFIG_SYMBOL = Symbol('GetFieldConfig');\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === 'ZodEffects') {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if ('innerType' in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if ('schema' in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from 'zod';\nimport { FieldConfig } from './types';\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig['fieldType']): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n ['ZodObject', 'object'],\n ['ZodString', 'string'],\n ['ZodNumber', 'number'],\n ['ZodBoolean', 'boolean'],\n ['ZodDate', 'date'],\n ['ZodEnum', 'select'],\n ['ZodNativeEnum', 'select'],\n ['ZodArray', 'array'],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || 'string'; // Default to string for unknown types\n}\n","import { ParsedField } from '@form-instant/react-input-mapping';\nimport { z } from 'zod';\nimport { getDefaultValueInZodStack } from './default-values';\nimport { getFieldConfigInZodStack } from './field-config';\nimport { inferFieldType } from './field-type-inference';\nimport { ParsedSchema, ZodObjectOrWrapped } from './types';\n\nfunction parseField(name: string, schema: z.ZodTypeAny, history: string = ''): ParsedField<any> {\n const baseSchema = getBaseSchema(schema);\n const { fieldType, ...fieldConfig } = getFieldConfigInZodStack(schema);\n const type = inferFieldType(baseSchema, fieldType);\n const defaultValue = getDefaultValueInZodStack(schema);\n\n // Enums\n const options = baseSchema._def.values;\n let optionValues: [string, string][] = [];\n if (options) {\n if (!Array.isArray(options)) {\n optionValues = Object.entries(options);\n } else {\n optionValues = options.map((value) => [value, value]);\n }\n }\n\n // Arrays and objects\n let subSchema: ParsedField<any>[] = [];\n if (baseSchema._def.typeName === 'ZodObject') {\n subSchema = Object.entries((baseSchema as any).shape).map(([key, field]) =>\n parseField(key, field as z.ZodTypeAny, [history, name].join('.')),\n );\n }\n if (baseSchema._def.typeName === 'ZodArray') {\n subSchema = [parseField('0', baseSchema._def.type)];\n }\n\n const resp = {\n name: { current: name, history: [history, name].join('.') },\n type,\n required: !schema.isOptional(),\n default: defaultValue,\n fieldConfig,\n options: optionValues,\n schema: subSchema,\n description: baseSchema.description,\n };\n\n return resp;\n}\n\nfunction getBaseSchema<ChildType extends z.ZodAny | z.ZodTypeAny | z.AnyZodObject = z.ZodAny>(\n schema: ChildType | z.ZodEffects<ChildType>,\n): ChildType {\n if ('innerType' in schema._def) {\n return getBaseSchema(schema._def.innerType as ChildType);\n }\n if ('schema' in schema._def) {\n return getBaseSchema(schema._def.schema as ChildType);\n }\n\n return schema as ChildType;\n}\n\nexport const parseSchema = (S: ZodObjectOrWrapped): ParsedSchema => {\n const objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;\n const shape = objectSchema.shape;\n\n const fields = Object.fromEntries(\n Object.entries(shape).map(([key, field]) => [key, parseField(key, field as z.ZodTypeAny)]),\n );\n\n return { fields };\n};\n","import { useContext } from 'use-context-selector';\nimport { ZodEffects, ZodObject } from 'zod';\nimport { ZodResolverContext } from './context';\nimport { parseSchema } from './funcs/schema-parser';\n\nexport const useSchemaBase = () =>\n useContext(ZodResolverContext) as ZodObject<never, never> | ZodEffects<never, never>;\n\nexport const useFields = <Sc extends Record<string, any>>(key: keyof Sc) => {\n const S = useSchemaBase();\n\n const { fields } = parseSchema(S);\n\n return fields[key as string];\n};\n","import { ElementMapping } from '@form-instant/react-input-mapping';\nimport { Fragment, useId } from 'react';\nimport { useFields } from './useSchema';\n\nexport interface ElementProps<Schema extends Record<string, any>> {\n name: keyof Schema;\n}\n\nexport const FormInstantElement = <S extends Record<string, any>>({ name }: ElementProps<S>) => {\n const field = useFields(name);\n\n const inputs = Object.values(field.schema!);\n\n const id = useId();\n\n return (\n <>\n {inputs.map((props) => {\n return (\n <Fragment key={`${id}-${props.name.history}`}>\n <ElementMapping formProps={props} />\n </Fragment>\n );\n })}\n </>\n );\n};\n","import { FC, ReactNode } from 'react';\nimport { ZodResolverContext } from './context';\nimport { zodResolverProps } from './type';\nexport const FormInstantProvider: FC<{ schema: zodResolverProps; children: ReactNode }> = ({\n children,\n schema,\n}) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","undefined","FIELD_CONFIG_SYMBOL","Symbol","createZodSchemaFieldConfig","config","refinementFunction","getFieldConfigInZodStack","typedSchema","typeName","effect","refinement","inferFieldType","fieldType","type","zodToInputType","Map","match","get","parseField","name","history","baseSchema","getBaseSchema","_getFieldConfigInZodS","fieldConfig","_objectWithoutPropertiesLoose","_excluded","options","values","optionValues","Array","isArray","Object","entries","map","value","subSchema","shape","_ref","key","field","join","resp","current","required","isOptional","description","parseSchema","S","objectSchema","fields","fromEntries","_ref2","useSchemaBase","useContext","useFields","_parseSchema","FormInstantElement","inputs","id","useId","_jsx","props","Fragment","children","ElementMapping","formProps","FormInstantProvider","Provider"],"mappings":";;;;;;AAGO,IAAMA,kBAAkB,gBAAGC,aAAa,CAAmB,EAAsB,CAAC;;;;;;;;;;;;ACAnF,SAAUC,yBAAyBA,CAACC,MAAoB,EAAA;AAC1D,EAAA,IAAIA,MAAM,YAAYC,CAAC,CAACC,UAAU,EAAE;AAChC,IAAA,OAAOF,MAAM,CAACG,IAAI,CAACC,YAAY,EAAE,CAAA;AACpC,GAAA;AAED,EAAA,IAAIJ,MAAM,YAAYC,CAAC,CAACI,UAAU,EAAE;AAChC,IAAA,OAAON,yBAAyB,CAACC,MAAM,CAACM,SAAS,EAAE,CAAC,CAAA;AACvD,GAAA;AAED,EAAA,OAAOC,SAAS,CAAA;AACpB;;ACXO,IAAMC,mBAAmB,gBAAGC,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAE9CC,IAAAA,0BAA0B,GACnC,SADSA,0BAA0BA,GAAA;EAAA,OAEnC,UAACC,MAAqD,EAAyB;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C,MAAM;AAAAuE,IAAAA,QAAA,EAAGA,QAAAA;AAAQ,GAAA,CAA+B,CAAA;AAC/F;;;;"}
1
+ {"version":3,"file":"react-resolver-zod.esm.js","sources":["../src/context.tsx","../src/funcs/default-values.ts","../src/funcs/field-config.ts","../src/funcs/field-type-inference.ts","../src/funcs/schema-parser.ts","../src/useSchema.tsx","../src/element.tsx","../src/provider.tsx"],"sourcesContent":["import { createContext } from 'use-context-selector';\nimport { zodResolverProps } from './type';\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from 'zod';\nimport { ZodObjectOrWrapped } from './types';\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { z } from 'zod';\nimport { FieldConfig, SuperRefineFunction } from './types';\nexport const FIELD_CONFIG_SYMBOL = Symbol('GetFieldConfig');\n\ndeclare module 'zod' {\n interface ZodType {\n fieldConfig<AdditionalRenderable = null, FieldTypes = string>(\n config: FieldConfig<AdditionalRenderable, FieldTypes>,\n ): this;\n }\n}\n\nexport const extendZodWithFieldConfig = <AdditionalRenderable = null, FieldTypes = string>(\n zod: typeof z,\n) => {\n (zod.ZodType.prototype as any).fieldConfig = function (\n config: FieldConfig<AdditionalRenderable, FieldTypes>,\n ) {\n this._def.fieldConfig = config;\n return this;\n };\n};\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n // Verifica si el esquema tiene fieldConfig directamente\n if (schema._def.fieldConfig) {\n return schema._def.fieldConfig as FieldConfig;\n }\n\n // Si el esquema es un ZodEffects, busca en el innerType\n if ('innerType' in schema._def) {\n return getFieldConfigInZodStack(schema._def.innerType as z.ZodAny);\n }\n\n // Si el esquema es un ZodEffects con un schema interno, busca en el schema\n if ('schema' in schema._def) {\n return getFieldConfigInZodStack(schema._def.schema as z.ZodAny);\n }\n\n // Si no se encuentra fieldConfig, retorna un objeto vacío\n return {} as FieldConfig;\n}\n","import { z } from 'zod';\nimport { FieldConfig } from './types';\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig['fieldType']): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n ['ZodObject', 'object'],\n ['ZodString', 'string'],\n ['ZodNumber', 'number'],\n ['ZodBoolean', 'boolean'],\n ['ZodDate', 'date'],\n ['ZodEnum', 'select'],\n ['ZodNativeEnum', 'select'],\n ['ZodArray', 'array'],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || 'string'; // Default to string for unknown types\n}\n","import { ParsedField } from '@form-instant/react-input-mapping';\nimport { z } from 'zod';\nimport { getDefaultValueInZodStack } from './default-values';\nimport { getFieldConfigInZodStack } from './field-config';\nimport { inferFieldType } from './field-type-inference';\nimport { ParsedSchema, ZodObjectOrWrapped } from './types';\n\nconst typeMapping = {\n ZodDiscriminatedUnion(\n baseSchema: z.ZodTypeAny,\n name: string,\n history: string,\n dependecys: Record<string, any>,\n ) {\n const { optionsMap, discriminator, fieldConfig } = baseSchema._def;\n\n if (!Object.keys(dependecys).length) return [{}] as ParsedField<any, string>[];\n\n const optionKey = dependecys[discriminator];\n const option = optionsMap.get(optionKey);\n\n if (!option) return [{}] as ParsedField<any, string>[];\n\n const entries = Object.entries(option.shape);\n\n const fields = entries\n .filter(([key]) => key !== discriminator)\n .map(([key, field]) => {\n return parseField(\n key,\n field as z.ZodTypeAny,\n [history, name].join('.'),\n dependecys,\n );\n });\n\n fields.unshift({\n name: {\n current: discriminator,\n history: [history, name, discriminator].join('.'),\n },\n type: 'discriminator',\n required: true,\n default: optionKey,\n fieldConfig,\n options: Array.from(optionsMap.keys()).map((key) => [String(key), String(key)]),\n });\n\n return fields;\n },\n\n ZodObject(\n baseSchema: z.ZodTypeAny,\n name: string,\n history: string,\n dependecys: Record<string, any>,\n ) {\n return Object.entries((baseSchema as any).shape).map(([key, field]) =>\n parseField(key, field as z.ZodTypeAny, [history, name].join('.'), dependecys),\n );\n },\n\n ZodArray(\n baseSchema: z.ZodTypeAny,\n name: string,\n history: string,\n dependecys: Record<string, any>,\n ) {\n return [parseField('0', baseSchema._def.type, [history, name].join('.'), dependecys)];\n },\n};\n\nfunction parseField(\n name: string,\n schema: z.ZodTypeAny,\n history: string = '',\n dependecys: Record<string, any> = {},\n): ParsedField<any> {\n const baseSchema = getBaseSchema(schema);\n const { fieldType, ...fieldConfigBase } = getFieldConfigInZodStack(schema);\n const type = inferFieldType(baseSchema, fieldType);\n const defaultValue = getDefaultValueInZodStack(schema);\n\n let fieldConfig = fieldConfigBase;\n\n // Enums\n const options = baseSchema._def.values;\n let optionValues: [string, string][] = [];\n if (options) {\n if (!Array.isArray(options)) {\n optionValues = Object.entries(options);\n } else {\n optionValues = options.map((value) => [value, value]);\n }\n }\n\n // Arrays and objects\n const getSubSchema = typeMapping[baseSchema._def.typeName as keyof typeof typeMapping];\n\n const subSchema = getSubSchema?.(baseSchema, name, history, dependecys);\n\n if (baseSchema._def.typeName === 'ZodArray') {\n fieldConfig = {\n min: baseSchema._def.minLength?.value || 1,\n max: baseSchema._def.maxLength?.value,\n ...fieldConfig,\n };\n }\n\n const resp = {\n name: { current: name, history: [history, name].join('.') },\n type,\n required: !schema.isOptional(),\n default: defaultValue,\n fieldConfig,\n options: optionValues,\n schema: subSchema,\n description: baseSchema.description,\n };\n\n return resp;\n}\n\nfunction getBaseSchema<ChildType extends z.ZodAny | z.ZodTypeAny | z.AnyZodObject = z.ZodAny>(\n schema: ChildType | z.ZodEffects<ChildType>,\n): ChildType {\n if ('innerType' in schema._def) {\n return getBaseSchema(schema._def.innerType as ChildType);\n }\n if ('schema' in schema._def) {\n return getBaseSchema(schema._def.schema as ChildType);\n }\n\n return schema as ChildType;\n}\n\nexport const parseSchema = (S: ZodObjectOrWrapped): ParsedSchema => {\n const objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;\n const shape = objectSchema.shape;\n\n const dependecys = (objectSchema._def as any).fieldConfig;\n\n const fields = Object.fromEntries(\n Object.entries(shape).map(([key, field]) => [\n key,\n parseField(key, field as z.ZodTypeAny, '', dependecys),\n ]),\n );\n\n return { fields };\n};\n","import { useContext } from 'use-context-selector';\nimport { ZodEffects, ZodObject } from 'zod';\nimport { ZodResolverContext } from './context';\nimport { parseSchema } from './funcs/schema-parser';\n\nexport const useSchemaBase = () =>\n useContext(ZodResolverContext) as ZodObject<never, never> | ZodEffects<never, never>;\n\nexport const useFields = <Sc extends Record<string, any>>(key: keyof Sc) => {\n const S = useSchemaBase();\n\n const { fields } = parseSchema(S);\n\n return fields[key as string];\n};\n","import { ElementMapping } from '@form-instant/react-input-mapping';\nimport { Fragment, useId } from 'react';\nimport { useFields } from './useSchema';\n\nexport interface ElementProps<Schema extends Record<string, any>> {\n name: keyof Schema;\n}\n\nexport const FormInstantElement = <S extends Record<string, any>>({ name }: ElementProps<S>) => {\n const field = useFields(name);\n\n const inputs = Object.values(field.schema || {});\n\n const id = useId();\n\n return (\n <>\n {inputs.map((props) => {\n return (\n <Fragment key={`${id}-${props.name?.history || ''}`}>\n <ElementMapping formProps={props} />\n </Fragment>\n );\n })}\n </>\n );\n};\n","import { FC, memo, ReactNode } from 'react';\nimport { ZodResolverContext } from './context';\nimport { zodResolverProps } from './type';\nexport const FormInstantProvider: FC<{\n schema: zodResolverProps;\n children: ReactNode;\n}> = memo(({ children, schema }) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n});\n"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","undefined","FIELD_CONFIG_SYMBOL","Symbol","extendZodWithFieldConfig","zod","ZodType","prototype","fieldConfig","config","createZodSchemaFieldConfig","refinementFunction","getFieldConfigInZodStack","inferFieldType","fieldType","type","typeName","zodToInputType","Map","match","get","typeMapping","ZodDiscriminatedUnion","baseSchema","name","history","dependecys","_baseSchema$_def","optionsMap","discriminator","Object","keys","length","optionKey","option","entries","shape","fields","filter","_ref","key","map","_ref2","field","parseField","join","unshift","current","required","options","Array","from","String","ZodObject","_ref3","ZodArray","getBaseSchema","_getFieldConfigInZodS","fieldConfigBase","_objectWithoutPropertiesLoose","_excluded","values","optionValues","isArray","value","getSubSchema","subSchema","_baseSchema$_def$minL","_baseSchema$_def$maxL","_extends","min","minLength","max","maxLength","resp","isOptional","description","parseSchema","S","objectSchema","fromEntries","_ref4","useSchemaBase","useContext","useFields","_parseSchema","FormInstantElement","inputs","id","useId","_jsx","props","_props$name","Fragment","children","ElementMapping","formProps","FormInstantProvider","memo","Provider"],"mappings":";;;;;;AAGO,IAAMA,kBAAkB,gBAAGC,aAAa,CAAmB,EAAsB,CAAC;;;;;;;;;;;;;;;;;;;;;ACAnF,SAAUC,yBAAyBA,CAACC,MAAoB,EAAA;AAC1D,EAAA,IAAIA,MAAM,YAAYC,CAAC,CAACC,UAAU,EAAE;AAChC,IAAA,OAAOF,MAAM,CAACG,IAAI,CAACC,YAAY,EAAE,CAAA;AACpC,GAAA;AAED,EAAA,IAAIJ,MA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T",
5
5
  "author": {
6
6
  "name": "leomerida15",
@@ -32,7 +32,7 @@
32
32
  "testEnvironment": "jsdom"
33
33
  },
34
34
  "peerDependencies": {
35
- "@form-instant/react-input-mapping": "^0.2.5",
35
+ "@form-instant/react-input-mapping": "^1.0.0",
36
36
  "react": "^18.3.1"
37
37
  },
38
38
  "engines": {