@form-instant/react-resolver-zod 1.0.0-rc.1 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { FieldConfig, SuperRefineFunction } from './types';
3
3
  export declare const FIELD_CONFIG_SYMBOL: unique symbol;
4
4
  declare module 'zod' {
5
- interface ZodType<Output = any, Def = any, Input = Output> {
5
+ interface ZodType {
6
6
  fieldConfig<AdditionalRenderable = null, FieldTypes = string>(config: FieldConfig<AdditionalRenderable, FieldTypes>): this;
7
7
  }
8
8
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
+ export * from './context';
1
2
  export * from './element';
2
- export * from './funcs/field-config';
3
3
  export * from './provider';
4
4
  export * from './type';
5
+ export * from './useSchema';
@@ -1,5 +1,5 @@
1
- import { FC, ReactNode } from "react";
2
- import { zodResolverProps } from "./type";
1
+ import { FC, ReactNode } from 'react';
2
+ import { zodResolverProps } from './type';
3
3
  export declare const FormInstantProvider: FC<{
4
4
  schema: zodResolverProps;
5
5
  children: ReactNode;
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ var useContextSelector = require('use-context-selector');
3
4
  var jsxRuntime = require('react/jsx-runtime');
4
5
  var reactInputMapping = require('@form-instant/react-input-mapping');
5
6
  var react = require('react');
6
- var useContextSelector = require('use-context-selector');
7
7
  var zod = require('zod');
8
8
 
9
9
  var ZodResolverContext = /*#__PURE__*/useContextSelector.createContext({});
@@ -37,23 +37,6 @@ function getDefaultValueInZodStack(schema) {
37
37
  return undefined;
38
38
  }
39
39
 
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
- };
47
- var createZodSchemaFieldConfig = function createZodSchemaFieldConfig() {
48
- return function (config) {
49
- var refinementFunction = function refinementFunction() {
50
- // Do nothing.
51
- };
52
- // @ts-expect-error This is a symbol and not a real value.
53
- refinementFunction[FIELD_CONFIG_SYMBOL] = config;
54
- return refinementFunction;
55
- };
56
- };
57
40
  function getFieldConfigInZodStack(schema) {
58
41
  // Verifica si el esquema tiene fieldConfig directamente
59
42
  if (schema._def.fieldConfig) {
@@ -137,9 +120,10 @@ function parseField(name, schema, history, dependecys) {
137
120
  var baseSchema = getBaseSchema(schema);
138
121
  var _getFieldConfigInZodS = getFieldConfigInZodStack(schema),
139
122
  fieldType = _getFieldConfigInZodS.fieldType,
140
- fieldConfig = _objectWithoutPropertiesLoose(_getFieldConfigInZodS, _excluded);
123
+ fieldConfigBase = _objectWithoutPropertiesLoose(_getFieldConfigInZodS, _excluded);
141
124
  var type = inferFieldType(baseSchema, fieldType);
142
125
  var defaultValue = getDefaultValueInZodStack(schema);
126
+ var fieldConfig = fieldConfigBase;
143
127
  // Enums
144
128
  var options = baseSchema._def.values;
145
129
  var optionValues = [];
@@ -209,6 +193,14 @@ var useFields = function useFields(key) {
209
193
  fields = _parseSchema.fields;
210
194
  return fields[key];
211
195
  };
196
+ var useSchema = function useSchema(cbP, dp) {
197
+ var schema = react.useMemo(function () {
198
+ return cbP(dp).fieldConfig(dp);
199
+ }, [dp]);
200
+ return {
201
+ schema: schema
202
+ };
203
+ };
212
204
 
213
205
  var FormInstantElement = function FormInstantElement(_ref) {
214
206
  var name = _ref.name;
@@ -236,10 +228,9 @@ var FormInstantProvider = /*#__PURE__*/react.memo(function (_ref) {
236
228
  });
237
229
  });
238
230
 
239
- exports.FIELD_CONFIG_SYMBOL = FIELD_CONFIG_SYMBOL;
240
231
  exports.FormInstantElement = FormInstantElement;
241
232
  exports.FormInstantProvider = FormInstantProvider;
242
- exports.createZodSchemaFieldConfig = createZodSchemaFieldConfig;
243
- exports.extendZodWithFieldConfig = extendZodWithFieldConfig;
244
- exports.getFieldConfigInZodStack = getFieldConfigInZodStack;
233
+ exports.ZodResolverContext = ZodResolverContext;
234
+ exports.useFields = useFields;
235
+ exports.useSchema = useSchema;
245
236
  //# 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 { z } from 'zod';\nimport { FieldConfig, SuperRefineFunction } from './types';\nexport const FIELD_CONFIG_SYMBOL = Symbol('GetFieldConfig');\n\ndeclare module 'zod' {\n // @ts-expect-error\n interface ZodType<Output = any, Def = any, Input = Output> {\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 let { 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 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\n | ZodObject<never, never>\n | 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 (\n <ZodResolverContext.Provider value={schema}>\n {children}\n </ZodResolverContext.Provider>\n );\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","_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,CAA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A,kBAAkBA,CAAA9C,IAAA,EAAgE;AAAA,EAAA,IAA3Bf,IAAI,GAAAe,IAAA,CAAJf,IAAI,CAAA;AACpE,EAAA,IAAMmB,KAAK,GAAGwC,SAAS,CAAC3D,IAAI,CAAC,CAAA;AAE7B,EAAA,IAAM8D,MAAM,GAAGxD,MAAM,CAAC8B,MAAM,CAACjB,KAAK,CAACjD,MAAM,IAAI,EAAE,CAAC,CAAA;AAEhD,EAAA,IAAM6F,EAAE,GAAGC,WAAK,EAAE,CAAA;EAElB,OACIC;cACKH,MAAM,CAAC7C,GAAG,CAAC,UAACiD,KAAK,EAAI;AAAA,MAAA,IAAAC,WAAA,CAAA;MAClB,OACIF,cAAC,CAAAG,cAAQ,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,CAAClE,IAAI,KAAA,IAAA,GAAA,KAAA,CAAA,GAAVmE,WAAA,CAAYlE,OAAO,KAAI,EAAE,CAAE,CAExC,CAAA;KAElB,CAAA;AACF,GAAA,CAAA,CAAA;AAEX;;ICvBauE,mBAAmB,gBAG3BC,UAAI,CAAC,UAAA1D,IAAA,EAAyB;AAAA,EAAA,IAAtBsD,QAAQ,GAAAtD,IAAA,CAARsD,QAAQ;IAAEnG,MAAM,GAAA6C,IAAA,CAAN7C,MAAM,CAAA;AAC3B,EAAA,OACE+F,cAAA,CAAClG,kBAAkB,CAAC2G,QAAQ,EAAA;AAACnC,IAAAA,KAAK,EAAErE,MAAM;AAAAmG,IAAAA,QAAA,EACvCA,QAAAA;AAAQ,GAAA,CACmB,CAAA;AAElC,CAAC;;;;;;;;;"}
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 { useMemo } from 'react';\nimport { useContext } from 'use-context-selector';\nimport { ZodEffects, ZodObject } from 'zod';\nimport { ZodResolverContext } from './context';\nimport { parseSchema } from './funcs/schema-parser';\n\nconst 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\ntype Data =\n | Zod.AnyZodObject\n | Zod.ZodEffects<Zod.AnyZodObject>\n | Zod.ZodDiscriminatedUnion<any, any>;\n\ntype DP = Record<string, any>;\n\nexport const useSchema = (cbP: (dp: DP, preData?: Data) => Data, dp: DP) => {\n const schema = useMemo(() => cbP(dp).fieldConfig(dp), [dp]);\n\n return { schema };\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","getFieldConfigInZodStack","fieldConfig","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","useSchema","cbP","dp","useMemo","FormInstantElement","inputs","id","useId","_jsx","props","_props$name","Fragment","children","ElementMapping","formProps","FormInstantProvider","memo","Provider"],"mappings":";;;;;;;;IAGaA,kBAAkB,gBAAGC,gCAAa,CAAmB,EAAsB;;;;;;;;;;;;;;;;;;;;;ACAlF,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,U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,CAAC,UAACsD,KAAK,EAAI;AAAA,MAAA,IAAAC,WAAA,CAAA;MAClB,OACIF,cAAC,CAAAG,cAAQ,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,CAACvE,IAAI,KAAA,IAAA,GAAA,KAAA,CAAA,GAAVwE,WAAA,CAAYvE,OAAO,KAAI,EAAE,CAAE,CAExC,CAAA;KAElB,CAAA;AACF,GAAA,CAAA,CAAA;AAEX;;ICvBa4E,mBAAmB,gBAG3BC,UAAI,CAAC,UAAA/D,IAAA,EAAyB;AAAA,EAAA,IAAtB2D,QAAQ,GAAA3D,IAAA,CAAR2D,QAAQ;IAAE/F,MAAM,GAAAoC,IAAA,CAANpC,MAAM,CAAA;AACzB,EAAA,OAAO2F,cAAA,CAAC9F,kBAAkB,CAACuG,QAAQ,EAAA;AAACvC,IAAAA,KAAK,EAAE7D,MAAM;AAAA+F,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(){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=i._def.values,g=[];y&&(g=Array.isArray(y)?y.map((function(e){return[e,e]})):Object.entries(y));var h,_,j=s[i._def.typeName],Z=null==j?void 0:j(i,e,r,t);return"ZodArray"===i._def.typeName&&(l=a({min:(null==(h=i._def.minLength)?void 0:h.value)||1,max:null==(_=i._def.maxLength)?void 0:_.value},l)),{name:{current:e,history:[r,e].join(".")},type:m,required:!n.isOptional(),default:v,fieldConfig:l,options:g,schema:Z,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;
1
+ "use strict";var e=require("use-context-selector"),n=require("react/jsx-runtime"),r=require("@form-instant/react-input-mapping"),t=require("react"),i=require("zod"),o=e.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 u(e){return e instanceof i.z.ZodDefault?e._def.defaultValue():e instanceof i.z.ZodEffects?u(e.innerType()):void 0}function f(e){return e._def.fieldConfig?e._def.fieldConfig:"innerType"in e._def?f(e._def.innerType):"schema"in e._def?f(e._def.schema):{}}var s=["fieldType"],d={ZodDiscriminatedUnion:function(e,n,r,t){var i=e._def,o=i.optionsMap,a=i.discriminator,u=i.fieldConfig;if(!Object.keys(t).length)return[{}];var f=t[a],s=o.get(f);if(!s)return[{}];var d=Object.entries(s.shape).filter((function(e){return e[0]!==a})).map((function(e){return c(e[0],e[1],[r,n].join("."),t)}));return d.unshift({name:{current:a,history:[r,n,a].join(".")},type:"discriminator",required:!0,default:f,fieldConfig:u,options:Array.from(o.keys()).map((function(e){return[String(e),String(e)]}))}),d},ZodObject:function(e,n,r,t){return Object.entries(e.shape).map((function(e){return c(e[0],e[1],[r,n].join("."),t)}))},ZodArray:function(e,n,r,t){return[c("0",e._def.type,[r,n].join("."),t)]}};function c(e,n,r,t){void 0===r&&(r=""),void 0===t&&(t={});var i=l(n),o=f(n),c=o.fieldType,m=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,s),p=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,c),v=u(n),y=m,h=i._def.values,g=[];h&&(g=Array.isArray(h)?h.map((function(e){return[e,e]})):Object.entries(h));var j,_,b=d[i._def.typeName],x=null==b?void 0:b(i,e,r,t);return"ZodArray"===i._def.typeName&&(y=a({min:(null==(j=i._def.minLength)?void 0:j.value)||1,max:null==(_=i._def.maxLength)?void 0:_.value},y)),{name:{current:e,history:[r,e].join(".")},type:p,required:!n.isOptional(),default:v,fieldConfig:y,options:g,schema:x,description:i.description}}function l(e){return"innerType"in e._def?l(e._def.innerType):"schema"in e._def?l(e._def.schema):e}var m=function(n){var r,t,a,u=(t=(r=e.useContext(o))instanceof i.z.ZodEffects?r.innerType():r,a=t._def.fieldConfig,{fields:Object.fromEntries(Object.entries(t.shape).map((function(e){var n=e[0];return[n,c(n,e[1],"",a)]})))});return u.fields[n]},p=t.memo((function(e){return n.jsx(o.Provider,{value:e.schema,children:e.children})}));exports.FormInstantElement=function(e){var i=m(e.name),o=Object.values(i.schema||{}),a=t.useId();return n.jsx(n.Fragment,{children:o.map((function(e){var i;return n.jsx(t.Fragment,{children:n.jsx(r.ElementMapping,{formProps:e})},a+"-"+((null==(i=e.name)?void 0:i.history)||""))}))})},exports.FormInstantProvider=p,exports.ZodResolverContext=o,exports.useFields=m,exports.useSchema=function(e,n){return{schema:t.useMemo((function(){return e(n).fieldConfig(n)}),[n])}};
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/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 // @ts-expect-error\n interface ZodType<Output = any, Def = any, Input = Output> {\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 let { 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 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 (\n <ZodResolverContext.Provider value={schema}>\n {children}\n </ZodResolverContext.Provider>\n );\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\n | ZodObject<never, never>\n | 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","_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,kBAmCpC,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,qBChDMW,EAAc,CAChBC,sBAAqB,SACjBC,EACAC,EACAC,EAC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CAEO,IEnIMuE,EAGRC,EAAAA,MAAK,SAAA1C,GACR,OACE2C,EAAAC,IAAC7E,EAAmB8E,SAAQ,CAAChB,MAFJ7B,EAAN9B,OAEuB4E,SAFzB9C,EAAR8C,UAMb,6DCJkC,SAAH9C,GAAgE,ICErCa,EJ4H9BkC,EAClBC,EAGA9D,EGjIA+D,GCCgDpC,EDFcb,EAAJhB,MH8HxC+D,EIhI1BG,EAAAA,WAAWnF,GJiIHiF,EAAeD,aAAa5E,EAACA,EAACI,WAAawE,EAAEvE,YAAcuE,EAG3D7D,EAAc8D,EAAa3E,KAAaO,YASvC,CAAEgB,OAPMN,OAAO6D,YAClB7D,OAAOO,QALGmD,EAAalD,OAKDG,KAAI,SAAAmD,GAAA,IAAEvC,EAAGuC,EAAA,GAAO,MAAM,CACxCvC,EACAV,EAAWU,EAFuBuC,EAAA,GAEK,GAAIlE,GAC9C,OInICU,OAEMiB,IDJNwC,EAAS/D,OAAOoC,OAAOuB,EAAM/E,QAAU,CAAA,GAEvCoF,EAAKC,EAAAA,QAEX,OACIZ,EAAAA,yBACKU,EAAOpD,KAAI,SAACuD,GAAS,IAAAC,EAClB,OACId,EAAAA,IAACe,EAAAA,SACG,CAAAZ,SAAAH,EAAAC,IAACe,iBAAe,CAAAC,UAAWJ,KADbF,EAAE,MAAc,OAAVG,EAAAD,EAAMxE,WAAI,EAAVyE,EAAYxE,UAAW,SAOnE,mEJDI,WADmC,OAEnC,SAAC4E,GACG,IAAMC,EAA0C,aAOhD,OAFAA,EAAmBrF,GAAuBoF,EAEnCC,EACV,mCAtBmC,SACpCC,GAECA,EAAIC,QAAQC,UAAkBrF,YAAc,SACzCiF,GAGA,OADAK,KAAK7F,KAAKO,YAAciF,EACjBK,KAEf"}
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/useSchema.tsx","../src/provider.tsx","../src/element.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 { useMemo } from 'react';\nimport { useContext } from 'use-context-selector';\nimport { ZodEffects, ZodObject } from 'zod';\nimport { ZodResolverContext } from './context';\nimport { parseSchema } from './funcs/schema-parser';\n\nconst 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\ntype Data =\n | Zod.AnyZodObject\n | Zod.ZodEffects<Zod.AnyZodObject>\n | Zod.ZodDiscriminatedUnion<any, any>;\n\ntype DP = Record<string, any>;\n\nexport const useSchema = (cbP: (dp: DP, preData?: Data) => Data, dp: DP) => {\n const schema = useMemo(() => cbP(dp).fieldConfig(dp), [dp]);\n\n return { schema };\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"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","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","useFields","S","objectSchema","_parseSchema","useContext","fromEntries","_ref4","FormInstantProvider","memo","_jsx","jsx","Provider","children","field","inputs","id","useId","props","_props$name","Fragment","ElementMapping","formProps","cbP","dp","useMemo"],"mappings":"qKAGaA,EAAqBC,EAAaA,cAAmB,CAAsB,2NCAlF,SAAUC,EAA0BC,GACtC,OAAIA,aAAkBC,EAACA,EAACC,WACbF,EAAOG,KAAKC,eAGnBJ,aAAkBC,EAACA,EAACI,WACbN,EAA0BC,EAAOM,kBAD5C,CAKJ,CCuBM,SAAUC,EAAyBP,GAErC,OAAIA,EAAOG,KAAKK,YACLR,EAAOG,KAAKK,YAInB,cAAeR,EAAOG,KACfI,EAAyBP,EAAOG,KAAKG,WAI5C,WAAYN,EAAOG,KACZI,EAAyBP,EAAOG,KAAKH,QAIzC,EACX,qBC/CMS,EAAc,CACh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YN,EAAOG,KACZ2C,EAAc9C,EAAOG,KAAKH,QAG9BA,CACX,CAEO,IE/HMsE,EAAY,SAAiC7B,GACtD,IF8HwB8B,EAClBC,EAGA1D,EEhIN2D,GF6HMD,GADkBD,EEjIxBG,EAAAA,WAAW7E,cFkIuBI,EAACA,EAACI,WAAakE,EAAEjE,YAAciE,EAG3DzD,EAAc0D,EAAarE,KAAaK,YASvC,CAAEgB,OAPMN,OAAOyD,YAClBzD,OAAOO,QALG+C,EAAa9C,OAKDG,KAAI,SAAA+C,GAAA,IAAEnC,EAAGmC,EAAA,GAAO,MAAM,CACxCnC,EACAV,EAAWU,EAFuBmC,EAAA,GAEK,GAAI9D,GAC9C,OEpIL,OAFc2D,EAANjD,OAEMiB,EAClB,ECZaoC,EAGRC,EAAAA,MAAK,SAAAlD,GACN,OAAOmD,EAAAC,IAACnF,EAAmBoF,SAAQ,CAACvB,MADX9B,EAAN5B,OAC8BkF,SADhCtD,EAARsD,UAEb,+BCAkC,SAAHtD,GAAgE,IACrFuD,EAAQb,EADsD1C,EAAJhB,MAG1DwE,EAASlE,OAAOqC,OAAO4B,EAAMnF,QAAU,CAAA,GAEvCqF,EAAKC,EAAAA,QAEX,OACIP,EAAAA,yBACKK,EAAOvD,KAAI,SAAC0D,GAAS,IAAAC,EAClB,OACIT,EAAAA,IAACU,EAAAA,SACG,CAAAP,SAAAH,EAAAC,IAACU,iBAAe,CAAAC,UAAWJ,KADbF,EAAE,MAAc,OAAVG,EAAAD,EAAM3E,WAAI,EAAV4E,EAAY3E,UAAW,SAOnE,mGFFyB,SAAC+E,EAAuCC,GAG7D,MAAO,CAAE7F,OAFM8F,EAAAA,SAAQ,WAAA,OAAMF,EAAIC,GAAIrF,YAAYqF,KAAK,CAACA,IAG3D"}
@@ -1,7 +1,7 @@
1
+ import { createContext, useContext } from 'use-context-selector';
1
2
  import { jsx, Fragment } from 'react/jsx-runtime';
2
3
  import { ElementMapping } from '@form-instant/react-input-mapping';
3
- import { useId, Fragment as Fragment$1, memo } from 'react';
4
- import { createContext, useContext } from 'use-context-selector';
4
+ import { useMemo, useId, Fragment as Fragment$1, memo } from 'react';
5
5
  import { z } from 'zod';
6
6
 
7
7
  var ZodResolverContext = /*#__PURE__*/createContext({});
@@ -35,23 +35,6 @@ function getDefaultValueInZodStack(schema) {
35
35
  return undefined;
36
36
  }
37
37
 
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
- };
45
- var createZodSchemaFieldConfig = function createZodSchemaFieldConfig() {
46
- return function (config) {
47
- var refinementFunction = function refinementFunction() {
48
- // Do nothing.
49
- };
50
- // @ts-expect-error This is a symbol and not a real value.
51
- refinementFunction[FIELD_CONFIG_SYMBOL] = config;
52
- return refinementFunction;
53
- };
54
- };
55
38
  function getFieldConfigInZodStack(schema) {
56
39
  // Verifica si el esquema tiene fieldConfig directamente
57
40
  if (schema._def.fieldConfig) {
@@ -135,9 +118,10 @@ function parseField(name, schema, history, dependecys) {
135
118
  var baseSchema = getBaseSchema(schema);
136
119
  var _getFieldConfigInZodS = getFieldConfigInZodStack(schema),
137
120
  fieldType = _getFieldConfigInZodS.fieldType,
138
- fieldConfig = _objectWithoutPropertiesLoose(_getFieldConfigInZodS, _excluded);
121
+ fieldConfigBase = _objectWithoutPropertiesLoose(_getFieldConfigInZodS, _excluded);
139
122
  var type = inferFieldType(baseSchema, fieldType);
140
123
  var defaultValue = getDefaultValueInZodStack(schema);
124
+ var fieldConfig = fieldConfigBase;
141
125
  // Enums
142
126
  var options = baseSchema._def.values;
143
127
  var optionValues = [];
@@ -207,6 +191,14 @@ var useFields = function useFields(key) {
207
191
  fields = _parseSchema.fields;
208
192
  return fields[key];
209
193
  };
194
+ var useSchema = function useSchema(cbP, dp) {
195
+ var schema = useMemo(function () {
196
+ return cbP(dp).fieldConfig(dp);
197
+ }, [dp]);
198
+ return {
199
+ schema: schema
200
+ };
201
+ };
210
202
 
211
203
  var FormInstantElement = function FormInstantElement(_ref) {
212
204
  var name = _ref.name;
@@ -234,5 +226,5 @@ var FormInstantProvider = /*#__PURE__*/memo(function (_ref) {
234
226
  });
235
227
  });
236
228
 
237
- export { FIELD_CONFIG_SYMBOL, FormInstantElement, FormInstantProvider, createZodSchemaFieldConfig, extendZodWithFieldConfig, getFieldConfigInZodStack };
229
+ export { FormInstantElement, FormInstantProvider, ZodResolverContext, useFields, useSchema };
238
230
  //# 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 { z } from 'zod';\nimport { FieldConfig, SuperRefineFunction } from './types';\nexport const FIELD_CONFIG_SYMBOL = Symbol('GetFieldConfig');\n\ndeclare module 'zod' {\n // @ts-expect-error\n interface ZodType<Output = any, Def = any, Input = Output> {\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 let { 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 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\n | ZodObject<never, never>\n | 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 (\n <ZodResolverContext.Provider value={schema}>\n {children}\n </ZodResolverContext.Provider>\n );\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","_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;AACrC,GAAA;AAEA,EAAA,IAAIJ,MAAM,YAAYC,CAAC,CAACI,UAAU,EAAE;AAChC,IAAA,OAAON,yBAAyB,CAACC,MAAM,CAACM,SAAS,EAAE,CAAC,CAAA;AACxD,GAAA;AAEA,EAAA,OAAOC,SAAS,CAAA;AACpB;;ICXaC,mBAAmB,gBAAGC,MAAM,CAAC,gBAAgB,EAAC;IAW9CC,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;GACd,CAAA;AACL,EAAC;AAEYC,IAAAA,0BAA0B,GACnC,SADSA,0BAA0BA,GAAA;EAAA,OAEnC,UAACD,MAAqD,EAAyB;AAC3E,IAAA,IAAME,kBAAkB,GAAwB,SAA1CA,kBAAkBA,GAA6B;AACjD;KACH,CAAA;AAED;AACAA,IAAAA,kBAAkB,CAACT,mBAAmB,CAAC,GAAGO,MAAM,CAAA;AAEhD,IAAA,OAAOE,kBAAkB,CAAA;GAC5B,CAAA;AAAA,EAAA;AAEC,SAAUC,wBAAwBA,CAAClB,MAAoB,EAAA;AACzD;AACA,EAAA,IAAIA,MAAM,CAACG,IAAI,CAACW,WAAW,EAAE;AACzB,IAAA,OAAOd,MAAM,CAACG,IAA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A,CAAN7C,MAAM,CAAA;AAC3B,EAAA,OACE+F,GAAA,CAAClG,kBAAkB,CAAC2G,QAAQ,EAAA;AAACnC,IAAAA,KAAK,EAAErE,MAAM;AAAAmG,IAAAA,QAAA,EACvCA,QAAAA;AAAQ,GAAA,CACmB,CAAA;AAElC,CAAC;;;;"}
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 { useMemo } from 'react';\nimport { useContext } from 'use-context-selector';\nimport { ZodEffects, ZodObject } from 'zod';\nimport { ZodResolverContext } from './context';\nimport { parseSchema } from './funcs/schema-parser';\n\nconst 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\ntype Data =\n | Zod.AnyZodObject\n | Zod.ZodEffects<Zod.AnyZodObject>\n | Zod.ZodDiscriminatedUnion<any, any>;\n\ntype DP = Record<string, any>;\n\nexport const useSchema = (cbP: (dp: DP, preData?: Data) => Data, dp: DP) => {\n const schema = useMemo(() => cbP(dp).fieldConfig(dp), [dp]);\n\n return { schema };\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","getFieldConfigInZodStack","fieldConfig","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","useSchema","cbP","dp","useMemo","FormInstantElement","inputs","id","useId","_jsx","props","_props$name","Fragment","children","ElementMapping","formProps","FormInstantProvider","memo","Provider"],"mapp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,GAAAe,IAAA,CAAJf,IAAI,CAAA;AACpE,EAAA,IAAMmB,KAAK,GAAGyC,SAAS,CAAC5D,IAAI,CAAC,CAAA;AAE7B,EAAA,IAAMmE,MAAM,GAAG7D,MAAM,CAAC+B,MAAM,CAAClB,KAAK,CAACxC,MAAM,IAAI,EAAE,CAAC,CAAA;AAEhD,EAAA,IAAMyF,EAAE,GAAGC,KAAK,EAAE,CAAA;EAElB,OACIC;cACKH,MAAM,CAAClD,GAAG,CAAC,UAACsD,KAAK,EAAI;AAAA,MAAA,IAAAC,WAAA,CAAA;MAClB,OACIF,GAAC,CAAAG,UAAQ,EACL;AAAAC,QAAAA,QAAA,EAAAJ,GAAA,CAACK,cAAc,EAAC;AAAAC,UAAAA,SAAS,EAAEL,KAAAA;SAAS,CAAA;AAAA,OAAA,EADtBH,EAAE,GAAA,GAAA,IAAI,CAAAI,CAAAA,WAAA,GAAAD,KAAK,CAACvE,IAAI,KAAA,IAAA,GAAA,KAAA,CAAA,GAAVwE,WAAA,CAAYvE,OAAO,KAAI,EAAE,CAAE,CAExC,CAAA;KAElB,CAAA;AACF,GAAA,CAAA,CAAA;AAEX;;ICvBa4E,mBAAmB,gBAG3BC,IAAI,CAAC,UAAA/D,IAAA,EAAyB;AAAA,EAAA,IAAtB2D,QAAQ,GAAA3D,IAAA,CAAR2D,QAAQ;IAAE/F,MAAM,GAAAoC,IAAA,CAANpC,MAAM,CAAA;AACzB,EAAA,OAAO2F,GAAA,CAAC9F,kBAAkB,CAACuG,QAAQ,EAAA;AAACvC,IAAAA,KAAK,EAAE7D,MAAM;AAAA+F,IAAAA,QAAA,EAAGA,QAAAA;AAAQ,GAAA,CAA+B,CAAA;AAC/F,CAAC;;;;"}
@@ -1,3 +1,12 @@
1
- import { ZodEffects, ZodObject } from "zod";
2
- export declare const useSchemaBase: () => ZodObject<never, never> | ZodEffects<never, never>;
1
+ import { ZodEffects } from 'zod';
3
2
  export declare const useFields: <Sc extends Record<string, any>>(key: keyof Sc) => import("@form-instant/react-input-mapping").ParsedField<null, string>;
3
+ type Data = Zod.AnyZodObject | Zod.ZodEffects<Zod.AnyZodObject> | Zod.ZodDiscriminatedUnion<any, any>;
4
+ type DP = Record<string, any>;
5
+ export declare const useSchema: (cbP: (dp: DP, preData?: Data) => Data, dp: DP) => {
6
+ schema: import("zod").AnyZodObject | ZodEffects<import("zod").AnyZodObject, {
7
+ [x: string]: any;
8
+ }, {
9
+ [x: string]: any;
10
+ }> | import("zod").ZodDiscriminatedUnion<any, any>;
11
+ };
12
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@form-instant/react-resolver-zod",
3
- "version": "1.0.0-rc.1",
3
+ "version": "1.5.1",
4
4
  "license": "MIT",
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": {