@form-instant/react-resolver-zod 1.0.0-rc.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/funcs/field-config.d.ts +1 -1
- package/dist/provider.d.ts +2 -2
- package/dist/react-resolver-zod.cjs.development.js +2 -1
- package/dist/react-resolver-zod.cjs.development.js.map +1 -1
- package/dist/react-resolver-zod.cjs.production.min.js +1 -1
- package/dist/react-resolver-zod.cjs.production.min.js.map +1 -1
- package/dist/react-resolver-zod.esm.js +2 -1
- package/dist/react-resolver-zod.esm.js.map +1 -1
- package/dist/useSchema.d.ts +2 -2
- package/package.json +2 -2
@@ -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
|
5
|
+
interface ZodType {
|
6
6
|
fieldConfig<AdditionalRenderable = null, FieldTypes = string>(config: FieldConfig<AdditionalRenderable, FieldTypes>): this;
|
7
7
|
}
|
8
8
|
}
|
package/dist/provider.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { FC, ReactNode } from
|
2
|
-
import { zodResolverProps } from
|
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;
|
@@ -137,9 +137,10 @@ function parseField(name, schema, history, dependecys) {
|
|
137
137
|
var baseSchema = getBaseSchema(schema);
|
138
138
|
var _getFieldConfigInZodS = getFieldConfigInZodStack(schema),
|
139
139
|
fieldType = _getFieldConfigInZodS.fieldType,
|
140
|
-
|
140
|
+
fieldConfigBase = _objectWithoutPropertiesLoose(_getFieldConfigInZodS, _excluded);
|
141
141
|
var type = inferFieldType(baseSchema, fieldType);
|
142
142
|
var defaultValue = getDefaultValueInZodStack(schema);
|
143
|
+
var fieldConfig = fieldConfigBase;
|
143
144
|
// Enums
|
144
145
|
var options = baseSchema._def.values;
|
145
146
|
var optionValues = [];
|
@@ -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,CAAA;AACrC,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BA,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 { 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,CAA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,MAAM,CAAC+B,MAAM,CAAClB,KAAK,CAACjD,MAAM,IAAI,EAAE,CAAC,CAAA;AAEhD,EAAA,IAAM8F,EAAE,GAAGC,WAAK,EAAE,CAAA;EAElB,OACIC;cACKH,MAAM,CAAC9C,GAAG,CAAC,UAACkD,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,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(){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,
|
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/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,EACAC,GAEA,IAAAC,EAAmDJ,EAAWV,KAAtDe,EAAUD,EAAVC,WAAYC,EAAaF,EAAbE,cAAeT,EAAWO,EAAXP,YAEnC,IAAKU,OAAOC,KAAKL,GAAYM,OAAQ,MAAO,CAAC,CAAA,GAE7C,IAAMC,EAAYP,EAAWG,GACvBK,EAASN,EAAWO,IAAIF,GAE9B,IAAKC,EAAQ,MAAO,CAAC,CAAA,GAErB,IAEME,EAFUN,OAAOO,QAAQH,EAAOI,OAGjCC,QAAO,SAAAC,GAAK,OAAAA,EAAA,KAAcX,CAAa,IACvCY,KAAI,SAAAC,GACD,OAAOC,EADDD,EAAA,GAAOA,EAAA,GAIT,CAACjB,EAASD,GAAMoB,KAAK,KACrBlB,EAER,IAcJ,OAZAU,EAAOS,QAAQ,CACXrB,KAAM,CACFsB,QAASjB,EACTJ,QAAS,CAACA,EAASD,EAAMK,GAAee,KAAK,MAEjDG,KAAM,gBACNC,UAAU,EACVC,QAAShB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OuB,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/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","ElementM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,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"}
|
@@ -135,9 +135,10 @@ function parseField(name, schema, history, dependecys) {
|
|
135
135
|
var baseSchema = getBaseSchema(schema);
|
136
136
|
var _getFieldConfigInZodS = getFieldConfigInZodStack(schema),
|
137
137
|
fieldType = _getFieldConfigInZodS.fieldType,
|
138
|
-
|
138
|
+
fieldConfigBase = _objectWithoutPropertiesLoose(_getFieldConfigInZodS, _excluded);
|
139
139
|
var type = inferFieldType(baseSchema, fieldType);
|
140
140
|
var defaultValue = getDefaultValueInZodStack(schema);
|
141
|
+
var fieldConfig = fieldConfigBase;
|
141
142
|
// Enums
|
142
143
|
var options = baseSchema._def.values;
|
143
144
|
var optionValues = [];
|
@@ -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,U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,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,IAAI,CAAC,UAAA1D,IAAA,EAAyB;AAAA,EAAA,IAAtBsD,QAAQ,GAAAtD,IAAA,CAARsD,QAAQ;IAAEnG,MAAM,GAAA6C,IAAA,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 { 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,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;;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;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,SAA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CAAA;AAEX;;ICvBawE,mBAAmB,gBAG3BC,IAAI,CAAC,UAAA3D,IAAA,EAAyB;AAAA,EAAA,IAAtBuD,QAAQ,GAAAvD,IAAA,CAARuD,QAAQ;IAAEpG,MAAM,GAAA6C,IAAA,CAAN7C,MAAM,CAAA;AACzB,EAAA,OAAOgG,GAAA,CAACnG,kBAAkB,CAAC4G,QAAQ,EAAA;AAACnC,IAAAA,KAAK,EAAEtE,MAAM;AAAAoG,IAAAA,QAAA,EAAGA,QAAAA;AAAQ,GAAA,CAA+B,CAAA;AAC/F,CAAC;;;;"}
|
package/dist/useSchema.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import { ZodEffects, ZodObject } from
|
2
|
-
export declare const useSchemaBase: () => ZodObject<never, never> | ZodEffects<never, never>;
|
1
|
+
import { ZodEffects, ZodObject } from 'zod';
|
2
|
+
export declare const useSchemaBase: () => ZodObject<never, never, import("zod").ZodTypeAny, never, never> | ZodEffects<never, never, never>;
|
3
3
|
export declare const useFields: <Sc extends Record<string, any>>(key: keyof Sc) => import("@form-instant/react-input-mapping").ParsedField<null, string>;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@form-instant/react-resolver-zod",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.1.0",
|
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.
|
35
|
+
"@form-instant/react-input-mapping": "^1.0.0",
|
36
36
|
"react": "^18.3.1"
|
37
37
|
},
|
38
38
|
"engines": {
|