@form-instant/react-resolver-zod 0.0.13-alpha → 0.0.14-alpha

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
- var react = require('react');
5
4
  var reactInputMapping = require('@form-instant/react-input-mapping');
5
+ var react = require('react');
6
6
  var zod = require('zod');
7
7
 
8
8
  function _extends() {
@@ -163,6 +163,7 @@ var FormInstantElement = function FormInstantElement(_ref) {
163
163
  var Element = InputMapping.get(props.type);
164
164
  var key = props.key,
165
165
  prop = _objectWithoutPropertiesLoose(props, _excluded);
166
+ if (!Element) return null;
166
167
  return react.createElement(Element, _extends({}, prop, {
167
168
  key: key + "-" + id
168
169
  }));
@@ -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 \"react\";\nimport { zodResolverProps } from \"./type\";\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from \"zod\";\nimport { ZodObjectOrWrapped } from \"./types\";\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from \"zod\";\nimport { FieldConfig, SuperRefineFunction } from \"./types\";\nexport const FIELD_CONFIG_SYMBOL = Symbol(\"GetFieldConfig\");\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === \"ZodEffects\") {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if (\"innerType\" in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if (\"schema\" in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from \"zod\";\nimport { FieldConfig } from \"./types\";\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig[\"fieldType\"]): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n [\"ZodObject\", \"object\"],\n [\"ZodString\", \"string\"],\n [\"ZodNumber\", \"number\"],\n [\"ZodBoolean\", \"boolean\"],\n [\"ZodDate\", \"date\"],\n [\"ZodEnum\", \"select\"],\n [\"ZodNativeEnum\", \"select\"],\n [\"ZodArray\", \"array\"],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || \"string\"; // Default to string for unknown types\n}\n","import { z } from \"zod\";\nimport { getDefaultValueInZodStack } from \"./default-values\";\nimport { getFieldConfigInZodStack } from \"./field-config\";\nimport { inferFieldType } from \"./field-type-inference\";\nimport { ParsedField, ParsedSchema, ZodObjectOrWrapped } from \"./types\";\n\nfunction parseField(key: string, schema: z.ZodTypeAny): ParsedField<any> {\n const baseSchema = getBaseSchema(schema);\n const { fieldType, ...fieldConfig } = getFieldConfigInZodStack(schema);\n const type = inferFieldType(baseSchema, fieldType);\n const defaultValue = getDefaultValueInZodStack(schema);\n\n // Enums\n const options = baseSchema._def.values;\n let optionValues: [string, string][] = [];\n if (options) {\n if (!Array.isArray(options)) {\n optionValues = Object.entries(options);\n } else {\n optionValues = options.map((value) => [value, value]);\n }\n }\n\n // Arrays and objects\n let subSchema: ParsedField<any>[] = [];\n if (baseSchema instanceof z.ZodObject) {\n subSchema = Object.entries(baseSchema.shape).map(([key, field]) =>\n parseField(key, field as z.ZodTypeAny),\n );\n }\n if (baseSchema instanceof z.ZodArray) {\n subSchema = [parseField(\"0\", baseSchema._def.type)];\n }\n\n const resp = {\n key,\n type,\n required: !schema.isOptional(),\n default: defaultValue,\n fieldConfig,\n options: optionValues,\n schema: subSchema,\n description: baseSchema.description,\n };\n\n return resp;\n}\n\nfunction getBaseSchema<ChildType extends z.ZodAny | z.ZodTypeAny | z.AnyZodObject = z.ZodAny>(\n schema: ChildType | z.ZodEffects<ChildType>,\n): ChildType {\n if (\"innerType\" in schema._def) {\n return getBaseSchema(schema._def.innerType as ChildType);\n }\n if (\"schema\" in schema._def) {\n return getBaseSchema(schema._def.schema as ChildType);\n }\n\n return schema as ChildType;\n}\n\nexport const parseSchema = (S: ZodObjectOrWrapped): ParsedSchema => {\n const objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;\n const shape = objectSchema.shape;\n\n const fields = Object.fromEntries(\n Object.entries(shape).map(([key, field]) => [key, parseField(key, field as z.ZodTypeAny)]),\n );\n\n return { fields };\n};\n","import { useContext } from \"react\";\nimport { ZodEffects, ZodObject } from \"zod\";\nimport { ZodResolverContext } from \"./context\";\nimport { parseSchema } from \"./funcs/schema-parser\";\n\nexport const useSchema = () =>\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 = useSchema();\n\n const { fields } = parseSchema(S);\n\n return fields[key as string];\n};\n","import { useInputMapping } from \"@form-instant/react-input-mapping\";\nimport { 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 InputMapping = useInputMapping();\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 const Element = InputMapping.get(props.type)!;\n\n const { key, ...prop } = props;\n\n return <Element {...prop} key={`${key}-${id}`} />;\n })}\n </>\n );\n};\n","\"use client\";\nimport { FC, ReactNode } from \"react\";\nimport { ZodResolverContext } from \"./context\";\nimport { zodResolverProps } from \"./type\";\nexport const FormInstantProvider: FC<{ schema: zodResolverProps; children: ReactNode }> = ({\n children,\n schema,\n}) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","undefined","FIELD_CONFIG_SYMBOL","Symbol","createZodSchemaFieldConfig","config","refinementFunction","getFieldConfigInZodStack","typedSchema","typeName","effect","refinement","inferFieldType","fieldType","type","zodToInputType","Map","match","get","parseField","key","baseSchema","getBaseSchema","_getFieldConfigInZodS","fieldConfig","_objectWithoutPropertiesLoose","_excluded","options","values","optionValues","Array","isArray","Object","entries","map","value","subSchema","ZodObject","shape","_ref","field","ZodArray","resp","required","isOptional","description","parseSchema","S","objectSchema","fields","fromEntries","_ref2","useSchema","useContext","useFields","_parseSchema","FormInstantElement","name","InputMapping","useInputMapping","inputs","id","useId","_jsx","props","Element","prop","_createElement","_extends","FormInst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G;AAAK8C,QAAAA,IAAI,GAAAzC,6BAAA,CAAKuC,KAAK,EAAAtC,SAAA,CAAA,CAAA;AAE9B,MAAA,OAAOyC,mBAAC,CAAAF,OAAO,EAAAG,QAAA,KAAKF,IAAI,EAAA;QAAE9C,GAAG,EAAKA,GAAG,GAAIyC,GAAAA,GAAAA,EAAAA;AAAI,OAAA,EAAI,CAAA;KACpD,CAAA;AACF,GAAA,CAAA,CAAA;AAEX;;ICvBaQ,mBAAmB,GAA0D,SAA7EA,mBAAmBA,CAAA9B,IAAA,EAG3B;AAAA,EAAA,IAFD+B,QAAQ,GAAA/B,IAAA,CAAR+B,QAAQ;IACR5E,MAAM,GAAA6C,IAAA,CAAN7C,MAAM,CAAA;AAEN,EAAA,OAAOqE,cAAA,CAACxE,kBAAkB,CAACgF,QAAQ,EAAA;AAACpC,IAAAA,KAAK,EAAEzC,MAAM;AAAA4E,IAAAA,QAAA,EAAGA,QAAAA;AAAQ,GAAA,CAA+B,CAAA;AAC/F;;;;;;;;"}
1
+ {"version":3,"file":"react-resolver-zod.cjs.development.js","sources":["../src/context.tsx","../src/funcs/default-values.ts","../src/funcs/field-config.ts","../src/funcs/field-type-inference.ts","../src/funcs/schema-parser.ts","../src/useSchema.tsx","../src/element.tsx","../src/provider.tsx"],"sourcesContent":["import { createContext } from \"react\";\nimport { zodResolverProps } from \"./type\";\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from \"zod\";\nimport { ZodObjectOrWrapped } from \"./types\";\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from \"zod\";\nimport { FieldConfig, SuperRefineFunction } from \"./types\";\nexport const FIELD_CONFIG_SYMBOL = Symbol(\"GetFieldConfig\");\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === \"ZodEffects\") {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if (\"innerType\" in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if (\"schema\" in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from \"zod\";\nimport { FieldConfig } from \"./types\";\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig[\"fieldType\"]): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n [\"ZodObject\", \"object\"],\n [\"ZodString\", \"string\"],\n [\"ZodNumber\", \"number\"],\n [\"ZodBoolean\", \"boolean\"],\n [\"ZodDate\", \"date\"],\n [\"ZodEnum\", \"select\"],\n [\"ZodNativeEnum\", \"select\"],\n [\"ZodArray\", \"array\"],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || \"string\"; // Default to string for unknown types\n}\n","import { z } from \"zod\";\nimport { getDefaultValueInZodStack } from \"./default-values\";\nimport { getFieldConfigInZodStack } from \"./field-config\";\nimport { inferFieldType } from \"./field-type-inference\";\nimport { ParsedField, ParsedSchema, ZodObjectOrWrapped } from \"./types\";\n\nfunction parseField(key: string, schema: z.ZodTypeAny): ParsedField<any> {\n const baseSchema = getBaseSchema(schema);\n const { fieldType, ...fieldConfig } = getFieldConfigInZodStack(schema);\n const type = inferFieldType(baseSchema, fieldType);\n const defaultValue = getDefaultValueInZodStack(schema);\n\n // Enums\n const options = baseSchema._def.values;\n let optionValues: [string, string][] = [];\n if (options) {\n if (!Array.isArray(options)) {\n optionValues = Object.entries(options);\n } else {\n optionValues = options.map((value) => [value, value]);\n }\n }\n\n // Arrays and objects\n let subSchema: ParsedField<any>[] = [];\n if (baseSchema instanceof z.ZodObject) {\n subSchema = Object.entries(baseSchema.shape).map(([key, field]) =>\n parseField(key, field as z.ZodTypeAny),\n );\n }\n if (baseSchema instanceof z.ZodArray) {\n subSchema = [parseField(\"0\", baseSchema._def.type)];\n }\n\n const resp = {\n key,\n type,\n required: !schema.isOptional(),\n default: defaultValue,\n fieldConfig,\n options: optionValues,\n schema: subSchema,\n description: baseSchema.description,\n };\n\n return resp;\n}\n\nfunction getBaseSchema<ChildType extends z.ZodAny | z.ZodTypeAny | z.AnyZodObject = z.ZodAny>(\n schema: ChildType | z.ZodEffects<ChildType>,\n): ChildType {\n if (\"innerType\" in schema._def) {\n return getBaseSchema(schema._def.innerType as ChildType);\n }\n if (\"schema\" in schema._def) {\n return getBaseSchema(schema._def.schema as ChildType);\n }\n\n return schema as ChildType;\n}\n\nexport const parseSchema = (S: ZodObjectOrWrapped): ParsedSchema => {\n const objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;\n const shape = objectSchema.shape;\n\n const fields = Object.fromEntries(\n Object.entries(shape).map(([key, field]) => [key, parseField(key, field as z.ZodTypeAny)]),\n );\n\n return { fields };\n};\n","import { useContext } from \"react\";\nimport { ZodEffects, ZodObject } from \"zod\";\nimport { ZodResolverContext } from \"./context\";\nimport { parseSchema } from \"./funcs/schema-parser\";\n\nexport const useSchema = () =>\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 = useSchema();\n\n const { fields } = parseSchema(S);\n\n return fields[key as string];\n};\n","import { useInputMapping } from \"@form-instant/react-input-mapping\";\nimport { createElement, 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 InputMapping = useInputMapping();\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 const Element = InputMapping.get(props.type);\n\n const { key, ...prop } = props;\n\n if (!Element) return null;\n\n return createElement(Element, { ...prop, key: `${key}-${id}` });\n })}\n </>\n );\n};\n","\"use client\";\nimport { FC, ReactNode } from \"react\";\nimport { ZodResolverContext } from \"./context\";\nimport { zodResolverProps } from \"./type\";\nexport const FormInstantProvider: FC<{ schema: zodResolverProps; children: ReactNode }> = ({\n children,\n schema,\n}) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","undefined","FIELD_CONFIG_SYMBOL","Symbol","createZodSchemaFieldConfig","config","refinementFunction","getFieldConfigInZodStack","typedSchema","typeName","effect","refinement","inferFieldType","fieldType","type","zodToInputType","Map","match","get","parseField","key","baseSchema","getBaseSchema","_getFieldConfigInZodS","fieldConfig","_objectWithoutPropertiesLoose","_excluded","options","values","optionValues","Array","isArray","Object","entries","map","value","subSchema","ZodObject","shape","_ref","field","ZodArray","resp","required","isOptional","description","parseSchema","S","objectSchema","fields","fromEntries","_ref2","useSchema","useContext","useFields","_parseSchema","FormInstantElement","name","InputMapping","useInputMapping","inputs","id","useId","_jsx","props","Element","prop","createElement","_extends","FormInstantProvider","children","Provider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAMA,kBAAkB,gBAAGC,mBAAa,CAAmB,EAAsB,CAAC;;ACAnF,SAAUC,yBAAyBA,CAACC,MAAoB,EAAA;AAC1D,EAAA,IAAIA,MAAM,YAAYC,KAAC,CAACC,UAAU,EAAE;AAChC,IAAA,OAAOF,MAAM,CAACG,IAAI,CAACC,YAAY,EAAE,CAAA;AACpC,GAAA;AAED,EAAA,IAAIJ,MAAM,YAAYC,KAAC,CAACI,UAAU,EAAE;AAChC,IAAA,OAAON,yBAAyB,CAACC,MAAM,CAACM,SAAS,EAAE,CAAC,CAAA;AACvD,GAAA;AAED,EAAA,OAAOC,SAAS,CAAA;AACpB;;ACXO,IAAMC,mBAAmB,gBAAGC,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAE9CC,IAAAA,0BAA0B,GACnC,SADSA,0BAA0BA,GAAA;EAAA,OAEnC,UAACC,MAAqD,EAAyB;AAC3E,IAAA,IAAMC,kBAAkB,GAAwB,SAA1CA,kBAAkBA,GAA6B;AACjD;KACH,CAAA;AAED;AACAA,IAAAA,kBAAkB,CAACJ,mBAAmB,CAAC,GAAGG,MAAM,CAAA;AAEhD,IAAA,OAAOC,kBAAkB,CAAA;GAC5B,CAAA;AAAA,EAAA;AAEC,SAAUC,wBAAwBA,CAACb,MAAoB,EAAA;EACzD,IAAMc,WAAW,GAAGd,MAA4D,CAAA;AAEhF,EAAA,IAAIc,WAAW,CAACX,IAAI,CAACY,QAAQ,KAAK,YAAY,EAAE;AAC5C,IAAA,IAAMC,MAAM,GAAGF,WAAW,CAACX,IAAI,CAACa,MAA+B,CAAA;AAC/D,IAAA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AM,CAAC1B,GAAG,CAAC,UAAC8B,KAAK,EAAI;MAClB,IAAMC,OAAO,GAAGP,YAAY,CAACxC,GAAG,CAAC8C,KAAK,CAAClD,IAAI,CAAC,CAAA;AAE5C,MAAA,IAAQM,GAAG,GAAc4C,KAAK,CAAtB5C,GAAG;AAAK8C,QAAAA,IAAI,GAAAzC,6BAAA,CAAKuC,KAAK,EAAAtC,SAAA,CAAA,CAAA;AAE9B,MAAA,IAAI,CAACuC,OAAO,EAAE,OAAO,IAAI,CAAA;AAEzB,MAAA,OAAOE,mBAAa,CAACF,OAAO,EAAAG,QAAA,KAAOF,IAAI,EAAA;QAAE9C,GAAG,EAAKA,GAAG,GAAIyC,GAAAA,GAAAA,EAAAA;AAAI,OAAA,CAAE,CAAC,CAAA;KAClE,CAAA;AACF,GAAA,CAAA,CAAA;AAEX;;ICzBaQ,mBAAmB,GAA0D,SAA7EA,mBAAmBA,CAAA9B,IAAA,EAG3B;AAAA,EAAA,IAFD+B,QAAQ,GAAA/B,IAAA,CAAR+B,QAAQ;IACR5E,MAAM,GAAA6C,IAAA,CAAN7C,MAAM,CAAA;AAEN,EAAA,OAAOqE,cAAA,CAACxE,kBAAkB,CAACgF,QAAQ,EAAA;AAACpC,IAAAA,KAAK,EAAEzC,MAAM;AAAA4E,IAAAA,QAAA,EAAGA,QAAAA;AAAQ,GAAA,CAA+B,CAAA;AAC/F;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react/jsx-runtime"),n=require("react"),r=require("@form-instant/react-input-mapping"),t=require("zod");function i(){return i=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},i.apply(null,arguments)}function a(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}var o=n.createContext({});function f(e){return e instanceof t.z.ZodDefault?e._def.defaultValue():e instanceof t.z.ZodEffects?f(e.innerType()):void 0}var u=Symbol("GetFieldConfig");function c(e){var n=e;if("ZodEffects"===n._def.typeName){var r=n._def.effect.refinement;if(u in r)return r[u]}return"innerType"in n._def?c(n._def.innerType):"schema"in n._def?c(n._def.schema):{}}var s=["fieldType"];function d(e,n){var r=p(n),i=c(n),o=i.fieldType,u=a(i,s),l=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"}(r,o),m=f(n),v=r._def.values,y=[];v&&(y=Array.isArray(v)?v.map((function(e){return[e,e]})):Object.entries(v));var h=[];return r instanceof t.z.ZodObject&&(h=Object.entries(r.shape).map((function(e){return d(e[0],e[1])}))),r instanceof t.z.ZodArray&&(h=[d("0",r._def.type)]),{key:e,type:l,required:!n.isOptional(),default:m,fieldConfig:u,options:y,schema:h,description:r.description}}function p(e){return"innerType"in e._def?p(e._def.innerType):"schema"in e._def?p(e._def.schema):e}var l=function(){return n.useContext(o)},m=function(e){var n,r,i=(r=(n=l())instanceof t.z.ZodEffects?n.innerType():n,{fields:Object.fromEntries(Object.entries(r.shape).map((function(e){var n=e[0];return[n,d(n,e[1])]})))});return i.fields[e]},v=["key"];exports.FormInstantElement=function(t){var o=t.name,f=r.useInputMapping(),u=m(o),c=Object.values(u.schema),s=n.useId();return e.jsx(e.Fragment,{children:c.map((function(e){var r=f.get(e.type),t=e.key,o=a(e,v);return n.createElement(r,i({},o,{key:t+"-"+s}))}))})},exports.FormInstantProvider=function(n){return e.jsx(o.Provider,{value:n.schema,children:n.children})},exports.createZodSchemaFieldConfig=function(){return function(e){var n=function(){};return n[u]=e,n}},exports.useFields=m,exports.useSchema=l;
1
+ "use strict";var e=require("react/jsx-runtime"),n=require("@form-instant/react-input-mapping"),r=require("react"),t=require("zod");function i(){return i=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},i.apply(null,arguments)}function a(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}var o=r.createContext({});function u(e){return e instanceof t.z.ZodDefault?e._def.defaultValue():e instanceof t.z.ZodEffects?u(e.innerType()):void 0}var f=Symbol("GetFieldConfig");function c(e){var n=e;if("ZodEffects"===n._def.typeName){var r=n._def.effect.refinement;if(f in r)return r[f]}return"innerType"in n._def?c(n._def.innerType):"schema"in n._def?c(n._def.schema):{}}var s=["fieldType"];function d(e,n){var r=l(n),i=c(n),o=i.fieldType,f=a(i,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"}(r,o),m=u(n),v=r._def.values,y=[];v&&(y=Array.isArray(v)?v.map((function(e){return[e,e]})):Object.entries(v));var h=[];return r instanceof t.z.ZodObject&&(h=Object.entries(r.shape).map((function(e){return d(e[0],e[1])}))),r instanceof t.z.ZodArray&&(h=[d("0",r._def.type)]),{key:e,type:p,required:!n.isOptional(),default:m,fieldConfig:f,options:y,schema:h,description:r.description}}function l(e){return"innerType"in e._def?l(e._def.innerType):"schema"in e._def?l(e._def.schema):e}var p=function(){return r.useContext(o)},m=function(e){var n,r,i=(r=(n=p())instanceof t.z.ZodEffects?n.innerType():n,{fields:Object.fromEntries(Object.entries(r.shape).map((function(e){var n=e[0];return[n,d(n,e[1])]})))});return i.fields[e]},v=["key"];exports.FormInstantElement=function(t){var o=t.name,u=n.useInputMapping(),f=m(o),c=Object.values(f.schema),s=r.useId();return e.jsx(e.Fragment,{children:c.map((function(e){var n=u.get(e.type),t=e.key,o=a(e,v);return n?r.createElement(n,i({},o,{key:t+"-"+s})):null}))})},exports.FormInstantProvider=function(n){return e.jsx(o.Provider,{value:n.schema,children:n.children})},exports.createZodSchemaFieldConfig=function(){return function(e){var n=function(){};return n[f]=e,n}},exports.useFields=m,exports.useSchema=p;
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/useSchema.tsx","../src/element.tsx","../src/provider.tsx"],"sourcesContent":["import { createContext } from \"react\";\nimport { zodResolverProps } from \"./type\";\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from \"zod\";\nimport { ZodObjectOrWrapped } from \"./types\";\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from \"zod\";\nimport { FieldConfig, SuperRefineFunction } from \"./types\";\nexport const FIELD_CONFIG_SYMBOL = Symbol(\"GetFieldConfig\");\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === \"ZodEffects\") {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if (\"innerType\" in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if (\"schema\" in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from \"zod\";\nimport { getDefaultValueInZodStack } from \"./default-values\";\nimport { getFieldConfigInZodStack } from \"./field-config\";\nimport { inferFieldType } from \"./field-type-inference\";\nimport { ParsedField, ParsedSchema, ZodObjectOrWrapped } from \"./types\";\n\nfunction parseField(key: string, schema: z.ZodTypeAny): ParsedField<any> {\n const baseSchema = getBaseSchema(schema);\n const { fieldType, ...fieldConfig } = getFieldConfigInZodStack(schema);\n const type = inferFieldType(baseSchema, fieldType);\n const defaultValue = getDefaultValueInZodStack(schema);\n\n // Enums\n const options = baseSchema._def.values;\n let optionValues: [string, string][] = [];\n if (options) {\n if (!Array.isArray(options)) {\n optionValues = Object.entries(options);\n } else {\n optionValues = options.map((value) => [value, value]);\n }\n }\n\n // Arrays and objects\n let subSchema: ParsedField<any>[] = [];\n if (baseSchema instanceof z.ZodObject) {\n subSchema = Object.entries(baseSchema.shape).map(([key, field]) =>\n parseField(key, field as z.ZodTypeAny),\n );\n }\n if (baseSchema instanceof z.ZodArray) {\n subSchema = [parseField(\"0\", baseSchema._def.type)];\n }\n\n const resp = {\n key,\n type,\n required: !schema.isOptional(),\n default: defaultValue,\n fieldConfig,\n options: optionValues,\n schema: subSchema,\n description: baseSchema.description,\n };\n\n return resp;\n}\n\nfunction getBaseSchema<ChildType extends z.ZodAny | z.ZodTypeAny | z.AnyZodObject = z.ZodAny>(\n schema: ChildType | z.ZodEffects<ChildType>,\n): ChildType {\n if (\"innerType\" in schema._def) {\n return getBaseSchema(schema._def.innerType as ChildType);\n }\n if (\"schema\" in schema._def) {\n return getBaseSchema(schema._def.schema as ChildType);\n }\n\n return schema as ChildType;\n}\n\nexport const parseSchema = (S: ZodObjectOrWrapped): ParsedSchema => {\n const objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;\n const shape = objectSchema.shape;\n\n const fields = Object.fromEntries(\n Object.entries(shape).map(([key, field]) => [key, parseField(key, field as z.ZodTypeAny)]),\n );\n\n return { fields };\n};\n","import { z } from \"zod\";\nimport { FieldConfig } from \"./types\";\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig[\"fieldType\"]): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n [\"ZodObject\", \"object\"],\n [\"ZodString\", \"string\"],\n [\"ZodNumber\", \"number\"],\n [\"ZodBoolean\", \"boolean\"],\n [\"ZodDate\", \"date\"],\n [\"ZodEnum\", \"select\"],\n [\"ZodNativeEnum\", \"select\"],\n [\"ZodArray\", \"array\"],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || \"string\"; // Default to string for unknown types\n}\n","import { useContext } from \"react\";\nimport { ZodEffects, ZodObject } from \"zod\";\nimport { ZodResolverContext } from \"./context\";\nimport { parseSchema } from \"./funcs/schema-parser\";\n\nexport const useSchema = () =>\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 = useSchema();\n\n const { fields } = parseSchema(S);\n\n return fields[key as string];\n};\n","import { useInputMapping } from \"@form-instant/react-input-mapping\";\nimport { 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 InputMapping = useInputMapping();\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 const Element = InputMapping.get(props.type)!;\n\n const { key, ...prop } = props;\n\n return <Element {...prop} key={`${key}-${id}`} />;\n })}\n </>\n );\n};\n","\"use client\";\nimport { FC, ReactNode } from \"react\";\nimport { ZodResolverContext } from \"./context\";\nimport { zodResolverProps } from \"./type\";\nexport const FormInstantProvider: FC<{ schema: zodResolverProps; children: ReactNode }> = ({\n children,\n schema,\n}) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","FIELD_CONFIG_SYMBOL","Symbol","getFieldConfigInZodStack","typedSchema","typeName","refinementFunction","effect","refinement","parseField","key","baseSchema","getBaseSchema","_getFieldConfigInZodS","fieldType","fieldConfig","_objectWithoutPropertiesLoose","_excluded","type","Map","get","inferFieldType","options","values","optionValues","Array","isArray","map","value","Object","entries","subSchema","ZodObject","shape","_ref","ZodArray","required","isOptional","default","description","useSchema","useContext","useFields","S","objectSchema","_parseSchema","fields","fromEntries","_ref2","name","InputMapping","useInputMapping","field","inputs","id","useId","_jsx","props","Element","prop","_createElement","createElement","_extends","jsx","Provider","children","config"],"mappings":"oeAGO,IAAMA,EAAqBC,EAAaA,cAAmB,ICA5D,SAAUC,EAA0BC,GACtC,OAAIA,aAAkBC,EAACA,EAACC,WACbF,EAAOG,KAAKC,eAGnBJ,aAAkBC,EAACA,EAACI,WACbN,EAA0BC,EAAOM,kBAD5C,CAKJ,CCXO,IAAMC,EAAsBC,OAAO,kBAepC,SAAUC,EAAyBT,GACrC,IAAMU,EAAcV,EAEpB,GAAkC,eAA9BU,EAAYP,KAAKQ,SAA2B,CAC5C,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AAS3B,EACLlB,GAEA,MAAI,cAAeA,EAAOG,KACfe,EAAclB,EAAOG,KAAKG,WAEjC,WAAYN,EAAOG,KACZe,EAAclB,EAAOG,KAAKH,QAG9BA,CACX,CAEO,IExDM8C,EAAY,WAAH,OAClBC,EAAAA,WAAWlD,EAAyE,EAE3EmD,EAAY,SAAiChC,GACtD,IFoDwBiC,EAClBC,EEnDNC,GFmDMD,GADkBD,EEpDdH,eFqDwB7C,EAACA,EAACI,WAAa4C,EAAE3C,YAAc2C,EAO1D,CAAEG,OAJMjB,OAAOkB,YAClBlB,OAAOC,QAHGc,EAAaX,OAGDN,KAAI,SAAAqB,GAAA,IAAEtC,EAAGsC,EAAA,GAAO,MAAM,CAACtC,EAAKD,EAAWC,EAAvBsC,EAAA,IAAmD,OErD7F,OAFcH,EAANC,OAEMpC,EAClB,uCCNkC,SAAHwB,GAAgE,IAA3Be,EAAIf,EAAJe,KAC1DC,EAAeC,EAAAA,kBACfC,EAAQV,EAAUO,GAElBI,EAASxB,OAAON,OAAO6B,EAAM1D,QAE7B4D,EAAKC,EAAAA,QAEX,OACIC,EAAAA,yBACKH,EAAO1B,KAAI,SAAC8B,GACT,IAAMC,EAAUR,EAAa9B,IAAIqC,EAAMvC,MAE/BR,EAAiB+C,EAAjB/C,IAAQiD,EAAI3C,EAAKyC,EAAKxC,GAE9B,OAAO2C,EAACC,cAAAH,EAAOI,KAAKH,EAAI,CAAEjD,IAAQA,EAAO4C,IAAAA,SAIzD,8BCvB0F,SAA1DpB,GAI5B,OAAOsB,EAAAO,IAACxE,EAAmByE,SAAQ,CAACpC,MAF9BM,EAANxC,OAEiDuE,SAHzC/B,EAAR+B,UAIJ,qCLJI,WADmC,OAEnC,SAACC,GACG,IAAM5D,EAA0C,aAOhD,OAFAA,EAAmBL,GAAuBiE,EAEnC5D,EACV"}
1
+ {"version":3,"file":"react-resolver-zod.cjs.production.min.js","sources":["../src/context.tsx","../src/funcs/default-values.ts","../src/funcs/field-config.ts","../src/funcs/schema-parser.ts","../src/funcs/field-type-inference.ts","../src/useSchema.tsx","../src/element.tsx","../src/provider.tsx"],"sourcesContent":["import { createContext } from \"react\";\nimport { zodResolverProps } from \"./type\";\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from \"zod\";\nimport { ZodObjectOrWrapped } from \"./types\";\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from \"zod\";\nimport { FieldConfig, SuperRefineFunction } from \"./types\";\nexport const FIELD_CONFIG_SYMBOL = Symbol(\"GetFieldConfig\");\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === \"ZodEffects\") {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if (\"innerType\" in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if (\"schema\" in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from \"zod\";\nimport { getDefaultValueInZodStack } from \"./default-values\";\nimport { getFieldConfigInZodStack } from \"./field-config\";\nimport { inferFieldType } from \"./field-type-inference\";\nimport { ParsedField, ParsedSchema, ZodObjectOrWrapped } from \"./types\";\n\nfunction parseField(key: string, schema: z.ZodTypeAny): ParsedField<any> {\n const baseSchema = getBaseSchema(schema);\n const { fieldType, ...fieldConfig } = getFieldConfigInZodStack(schema);\n const type = inferFieldType(baseSchema, fieldType);\n const defaultValue = getDefaultValueInZodStack(schema);\n\n // Enums\n const options = baseSchema._def.values;\n let optionValues: [string, string][] = [];\n if (options) {\n if (!Array.isArray(options)) {\n optionValues = Object.entries(options);\n } else {\n optionValues = options.map((value) => [value, value]);\n }\n }\n\n // Arrays and objects\n let subSchema: ParsedField<any>[] = [];\n if (baseSchema instanceof z.ZodObject) {\n subSchema = Object.entries(baseSchema.shape).map(([key, field]) =>\n parseField(key, field as z.ZodTypeAny),\n );\n }\n if (baseSchema instanceof z.ZodArray) {\n subSchema = [parseField(\"0\", baseSchema._def.type)];\n }\n\n const resp = {\n key,\n type,\n required: !schema.isOptional(),\n default: defaultValue,\n fieldConfig,\n options: optionValues,\n schema: subSchema,\n description: baseSchema.description,\n };\n\n return resp;\n}\n\nfunction getBaseSchema<ChildType extends z.ZodAny | z.ZodTypeAny | z.AnyZodObject = z.ZodAny>(\n schema: ChildType | z.ZodEffects<ChildType>,\n): ChildType {\n if (\"innerType\" in schema._def) {\n return getBaseSchema(schema._def.innerType as ChildType);\n }\n if (\"schema\" in schema._def) {\n return getBaseSchema(schema._def.schema as ChildType);\n }\n\n return schema as ChildType;\n}\n\nexport const parseSchema = (S: ZodObjectOrWrapped): ParsedSchema => {\n const objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;\n const shape = objectSchema.shape;\n\n const fields = Object.fromEntries(\n Object.entries(shape).map(([key, field]) => [key, parseField(key, field as z.ZodTypeAny)]),\n );\n\n return { fields };\n};\n","import { z } from \"zod\";\nimport { FieldConfig } from \"./types\";\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig[\"fieldType\"]): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n [\"ZodObject\", \"object\"],\n [\"ZodString\", \"string\"],\n [\"ZodNumber\", \"number\"],\n [\"ZodBoolean\", \"boolean\"],\n [\"ZodDate\", \"date\"],\n [\"ZodEnum\", \"select\"],\n [\"ZodNativeEnum\", \"select\"],\n [\"ZodArray\", \"array\"],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || \"string\"; // Default to string for unknown types\n}\n","import { useContext } from \"react\";\nimport { ZodEffects, ZodObject } from \"zod\";\nimport { ZodResolverContext } from \"./context\";\nimport { parseSchema } from \"./funcs/schema-parser\";\n\nexport const useSchema = () =>\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 = useSchema();\n\n const { fields } = parseSchema(S);\n\n return fields[key as string];\n};\n","import { useInputMapping } from \"@form-instant/react-input-mapping\";\nimport { createElement, 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 InputMapping = useInputMapping();\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 const Element = InputMapping.get(props.type);\n\n const { key, ...prop } = props;\n\n if (!Element) return null;\n\n return createElement(Element, { ...prop, key: `${key}-${id}` });\n })}\n </>\n );\n};\n","\"use client\";\nimport { FC, ReactNode } from \"react\";\nimport { ZodResolverContext } from \"./context\";\nimport { zodResolverProps } from \"./type\";\nexport const FormInstantProvider: FC<{ schema: zodResolverProps; children: ReactNode }> = ({\n children,\n schema,\n}) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","FIELD_CONFIG_SYMBOL","Symbol","getFieldConfigInZodStack","typedSchema","typeName","refinementFunction","effect","refinement","parseField","key","baseSchema","getBaseSchema","_getFieldConfigInZodS","fieldType","fieldConfig","_objectWithoutPropertiesLoose","_excluded","type","Map","get","inferFieldType","options","values","optionValues","Array","isArray","map","value","Object","entries","subSchema","ZodObject","shape","_ref","ZodArray","required","isOptional","default","description","useSchema","useContext","useFields","S","objectSchema","_parseSchema","fields","fromEntries","_ref2","name","InputMapping","useInputMapping","field","inputs","id","useId","_jsx","props","Element","prop","createElement","_extends","jsx","Provider","children","config"],"mappings":"oeAGO,IAAMA,EAAqBC,EAAaA,cAAmB,ICA5D,SAAUC,EAA0BC,GACtC,OAAIA,aAAkBC,EAACA,EAACC,WACbF,EAAOG,KAAKC,eAGnBJ,aAAkBC,EAACA,EAACI,WACbN,EAA0BC,EAAOM,kBAD5C,CAKJ,CCXO,IAAMC,EAAsBC,OAAO,kBAepC,SAAUC,EAAyBT,GACrC,IAAMU,EAAcV,EAEpB,GAAkC,eAA9BU,EAAYP,KAAKQ,SAA2B,CAC5C,IACMC,EADSF,EAAYP,KAAKU,OACEC,WAElC,GAAIP,KAAuBK,EACvB,OAAOA,EAAmBL,EAEjC,CAED,MAAI,cAAeG,EAAYP,KACpBM,EAAyBC,EAAYP,KAAKG,WAEjD,WAAYI,EAAYP,KACjBM,EAA0BC,EAAYP,KAAaH,QAGvD,EACX,qBC/BA,SAASe,EAAWC,EAAahB,GAC7B,IAAMiB,EAAaC,EAAclB,GACjCmB,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FqDwB7C,EAACA,EAACI,WAAa4C,EAAE3C,YAAc2C,EAO1D,CAAEG,OAJMjB,OAAOkB,YAClBlB,OAAOC,QAHGc,EAAaX,OAGDN,KAAI,SAAAqB,GAAA,IAAEtC,EAAGsC,EAAA,GAAO,MAAM,CAACtC,EAAKD,EAAWC,EAAvBsC,EAAA,IAAmD,OErD7F,OAFcH,EAANC,OAEMpC,EAClB,uCCNkC,SAAHwB,GAAgE,IAA3Be,EAAIf,EAAJe,KAC1DC,EAAeC,EAAAA,kBACfC,EAAQV,EAAUO,GAElBI,EAASxB,OAAON,OAAO6B,EAAM1D,QAE7B4D,EAAKC,EAAAA,QAEX,OACIC,EAAAA,yBACKH,EAAO1B,KAAI,SAAC8B,GACT,IAAMC,EAAUR,EAAa9B,IAAIqC,EAAMvC,MAE/BR,EAAiB+C,EAAjB/C,IAAQiD,EAAI3C,EAAKyC,EAAKxC,GAE9B,OAAKyC,EAEEE,EAAaA,cAACF,EAAOG,KAAOF,EAAI,CAAEjD,IAAQA,EAAO4C,IAAAA,KAFnC,SAMrC,8BCzB0F,SAA1DpB,GAI5B,OAAOsB,EAAAM,IAACvE,EAAmBwE,SAAQ,CAACnC,MAF9BM,EAANxC,OAEiDsE,SAHzC9B,EAAR8B,UAIJ,qCLJI,WADmC,OAEnC,SAACC,GACG,IAAM3D,EAA0C,aAOhD,OAFAA,EAAmBL,GAAuBgE,EAEnC3D,EACV"}
@@ -1,6 +1,6 @@
1
1
  import { jsx, Fragment } from 'react/jsx-runtime';
2
- import { createContext, useContext, useId, createElement } from 'react';
3
2
  import { useInputMapping } from '@form-instant/react-input-mapping';
3
+ import { createContext, useContext, useId, createElement } from 'react';
4
4
  import { z } from 'zod';
5
5
 
6
6
  function _extends() {
@@ -161,6 +161,7 @@ var FormInstantElement = function FormInstantElement(_ref) {
161
161
  var Element = InputMapping.get(props.type);
162
162
  var key = props.key,
163
163
  prop = _objectWithoutPropertiesLoose(props, _excluded);
164
+ if (!Element) return null;
164
165
  return createElement(Element, _extends({}, prop, {
165
166
  key: key + "-" + id
166
167
  }));
@@ -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 \"react\";\nimport { zodResolverProps } from \"./type\";\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from \"zod\";\nimport { ZodObjectOrWrapped } from \"./types\";\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from \"zod\";\nimport { FieldConfig, SuperRefineFunction } from \"./types\";\nexport const FIELD_CONFIG_SYMBOL = Symbol(\"GetFieldConfig\");\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === \"ZodEffects\") {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if (\"innerType\" in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if (\"schema\" in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from \"zod\";\nimport { FieldConfig } from \"./types\";\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig[\"fieldType\"]): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n [\"ZodObject\", \"object\"],\n [\"ZodString\", \"string\"],\n [\"ZodNumber\", \"number\"],\n [\"ZodBoolean\", \"boolean\"],\n [\"ZodDate\", \"date\"],\n [\"ZodEnum\", \"select\"],\n [\"ZodNativeEnum\", \"select\"],\n [\"ZodArray\", \"array\"],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || \"string\"; // Default to string for unknown types\n}\n","import { z } from \"zod\";\nimport { getDefaultValueInZodStack } from \"./default-values\";\nimport { getFieldConfigInZodStack } from \"./field-config\";\nimport { inferFieldType } from \"./field-type-inference\";\nimport { ParsedField, ParsedSchema, ZodObjectOrWrapped } from \"./types\";\n\nfunction parseField(key: string, schema: z.ZodTypeAny): ParsedField<any> {\n const baseSchema = getBaseSchema(schema);\n const { fieldType, ...fieldConfig } = getFieldConfigInZodStack(schema);\n const type = inferFieldType(baseSchema, fieldType);\n const defaultValue = getDefaultValueInZodStack(schema);\n\n // Enums\n const options = baseSchema._def.values;\n let optionValues: [string, string][] = [];\n if (options) {\n if (!Array.isArray(options)) {\n optionValues = Object.entries(options);\n } else {\n optionValues = options.map((value) => [value, value]);\n }\n }\n\n // Arrays and objects\n let subSchema: ParsedField<any>[] = [];\n if (baseSchema instanceof z.ZodObject) {\n subSchema = Object.entries(baseSchema.shape).map(([key, field]) =>\n parseField(key, field as z.ZodTypeAny),\n );\n }\n if (baseSchema instanceof z.ZodArray) {\n subSchema = [parseField(\"0\", baseSchema._def.type)];\n }\n\n const resp = {\n key,\n type,\n required: !schema.isOptional(),\n default: defaultValue,\n fieldConfig,\n options: optionValues,\n schema: subSchema,\n description: baseSchema.description,\n };\n\n return resp;\n}\n\nfunction getBaseSchema<ChildType extends z.ZodAny | z.ZodTypeAny | z.AnyZodObject = z.ZodAny>(\n schema: ChildType | z.ZodEffects<ChildType>,\n): ChildType {\n if (\"innerType\" in schema._def) {\n return getBaseSchema(schema._def.innerType as ChildType);\n }\n if (\"schema\" in schema._def) {\n return getBaseSchema(schema._def.schema as ChildType);\n }\n\n return schema as ChildType;\n}\n\nexport const parseSchema = (S: ZodObjectOrWrapped): ParsedSchema => {\n const objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;\n const shape = objectSchema.shape;\n\n const fields = Object.fromEntries(\n Object.entries(shape).map(([key, field]) => [key, parseField(key, field as z.ZodTypeAny)]),\n );\n\n return { fields };\n};\n","import { useContext } from \"react\";\nimport { ZodEffects, ZodObject } from \"zod\";\nimport { ZodResolverContext } from \"./context\";\nimport { parseSchema } from \"./funcs/schema-parser\";\n\nexport const useSchema = () =>\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 = useSchema();\n\n const { fields } = parseSchema(S);\n\n return fields[key as string];\n};\n","import { useInputMapping } from \"@form-instant/react-input-mapping\";\nimport { 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 InputMapping = useInputMapping();\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 const Element = InputMapping.get(props.type)!;\n\n const { key, ...prop } = props;\n\n return <Element {...prop} key={`${key}-${id}`} />;\n })}\n </>\n );\n};\n","\"use client\";\nimport { FC, ReactNode } from \"react\";\nimport { ZodResolverContext } from \"./context\";\nimport { zodResolverProps } from \"./type\";\nexport const FormInstantProvider: FC<{ schema: zodResolverProps; children: ReactNode }> = ({\n children,\n schema,\n}) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","undefined","FIELD_CONFIG_SYMBOL","Symbol","createZodSchemaFieldConfig","config","refinementFunction","getFieldConfigInZodStack","typedSchema","typeName","effect","refinement","inferFieldType","fieldType","type","zodToInputType","Map","match","get","parseField","key","baseSchema","getBaseSchema","_getFieldConfigInZodS","fieldConfig","_objectWithoutPropertiesLoose","_excluded","options","values","optionValues","Array","isArray","Object","entries","map","value","subSchema","ZodObject","shape","_ref","field","ZodArray","resp","required","isOptional","description","parseSchema","S","objectSchema","fields","fromEntries","_ref2","useSchema","useContext","useFields","_parseSchema","FormInstantElement","name","InputMapping","useInputMapping","inputs","id","useId","_jsx","props","Element","prop","_createElement","_extends","FormInstantProvider","children","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;A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GAAA6C,IAAA,CAAN7C,MAAM,CAAA;AAEN,EAAA,OAAOqE,GAAA,CAACxE,kBAAkB,CAACgF,QAAQ,EAAA;AAACpC,IAAAA,KAAK,EAAEzC,MAAM;AAAA4E,IAAAA,QAAA,EAAGA,QAAAA;AAAQ,GAAA,CAA+B,CAAA;AAC/F;;;;"}
1
+ {"version":3,"file":"react-resolver-zod.esm.js","sources":["../src/context.tsx","../src/funcs/default-values.ts","../src/funcs/field-config.ts","../src/funcs/field-type-inference.ts","../src/funcs/schema-parser.ts","../src/useSchema.tsx","../src/element.tsx","../src/provider.tsx"],"sourcesContent":["import { createContext } from \"react\";\nimport { zodResolverProps } from \"./type\";\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from \"zod\";\nimport { ZodObjectOrWrapped } from \"./types\";\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from \"zod\";\nimport { FieldConfig, SuperRefineFunction } from \"./types\";\nexport const FIELD_CONFIG_SYMBOL = Symbol(\"GetFieldConfig\");\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === \"ZodEffects\") {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if (\"innerType\" in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if (\"schema\" in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from \"zod\";\nimport { FieldConfig } from \"./types\";\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig[\"fieldType\"]): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n [\"ZodObject\", \"object\"],\n [\"ZodString\", \"string\"],\n [\"ZodNumber\", \"number\"],\n [\"ZodBoolean\", \"boolean\"],\n [\"ZodDate\", \"date\"],\n [\"ZodEnum\", \"select\"],\n [\"ZodNativeEnum\", \"select\"],\n [\"ZodArray\", \"array\"],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || \"string\"; // Default to string for unknown types\n}\n","import { z } from \"zod\";\nimport { getDefaultValueInZodStack } from \"./default-values\";\nimport { getFieldConfigInZodStack } from \"./field-config\";\nimport { inferFieldType } from \"./field-type-inference\";\nimport { ParsedField, ParsedSchema, ZodObjectOrWrapped } from \"./types\";\n\nfunction parseField(key: string, schema: z.ZodTypeAny): ParsedField<any> {\n const baseSchema = getBaseSchema(schema);\n const { fieldType, ...fieldConfig } = getFieldConfigInZodStack(schema);\n const type = inferFieldType(baseSchema, fieldType);\n const defaultValue = getDefaultValueInZodStack(schema);\n\n // Enums\n const options = baseSchema._def.values;\n let optionValues: [string, string][] = [];\n if (options) {\n if (!Array.isArray(options)) {\n optionValues = Object.entries(options);\n } else {\n optionValues = options.map((value) => [value, value]);\n }\n }\n\n // Arrays and objects\n let subSchema: ParsedField<any>[] = [];\n if (baseSchema instanceof z.ZodObject) {\n subSchema = Object.entries(baseSchema.shape).map(([key, field]) =>\n parseField(key, field as z.ZodTypeAny),\n );\n }\n if (baseSchema instanceof z.ZodArray) {\n subSchema = [parseField(\"0\", baseSchema._def.type)];\n }\n\n const resp = {\n key,\n type,\n required: !schema.isOptional(),\n default: defaultValue,\n fieldConfig,\n options: optionValues,\n schema: subSchema,\n description: baseSchema.description,\n };\n\n return resp;\n}\n\nfunction getBaseSchema<ChildType extends z.ZodAny | z.ZodTypeAny | z.AnyZodObject = z.ZodAny>(\n schema: ChildType | z.ZodEffects<ChildType>,\n): ChildType {\n if (\"innerType\" in schema._def) {\n return getBaseSchema(schema._def.innerType as ChildType);\n }\n if (\"schema\" in schema._def) {\n return getBaseSchema(schema._def.schema as ChildType);\n }\n\n return schema as ChildType;\n}\n\nexport const parseSchema = (S: ZodObjectOrWrapped): ParsedSchema => {\n const objectSchema = S instanceof z.ZodEffects ? S.innerType() : S;\n const shape = objectSchema.shape;\n\n const fields = Object.fromEntries(\n Object.entries(shape).map(([key, field]) => [key, parseField(key, field as z.ZodTypeAny)]),\n );\n\n return { fields };\n};\n","import { useContext } from \"react\";\nimport { ZodEffects, ZodObject } from \"zod\";\nimport { ZodResolverContext } from \"./context\";\nimport { parseSchema } from \"./funcs/schema-parser\";\n\nexport const useSchema = () =>\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 = useSchema();\n\n const { fields } = parseSchema(S);\n\n return fields[key as string];\n};\n","import { useInputMapping } from \"@form-instant/react-input-mapping\";\nimport { createElement, 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 InputMapping = useInputMapping();\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 const Element = InputMapping.get(props.type);\n\n const { key, ...prop } = props;\n\n if (!Element) return null;\n\n return createElement(Element, { ...prop, key: `${key}-${id}` });\n })}\n </>\n );\n};\n","\"use client\";\nimport { FC, ReactNode } from \"react\";\nimport { ZodResolverContext } from \"./context\";\nimport { zodResolverProps } from \"./type\";\nexport const FormInstantProvider: FC<{ schema: zodResolverProps; children: ReactNode }> = ({\n children,\n schema,\n}) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","undefined","FIELD_CONFIG_SYMBOL","Symbol","createZodSchemaFieldConfig","config","refinementFunction","getFieldConfigInZodStack","typedSchema","typeName","effect","refinement","inferFieldType","fieldType","type","zodToInputType","Map","match","get","parseField","key","baseSchema","getBaseSchema","_getFieldConfigInZodS","fieldConfig","_objectWithoutPropertiesLoose","_excluded","options","values","optionValues","Array","isArray","Object","entries","map","value","subSchema","ZodObject","shape","_ref","field","ZodArray","resp","required","isOptional","description","parseSchema","S","objectSchema","fields","fromEntries","_ref2","useSchema","useContext","useFields","_parseSchema","FormInstantElement","name","InputMapping","useInputMapping","inputs","id","useId","_jsx","props","Element","prop","createElement","_extends","FormInstantProvider","children","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,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AAAA,GAAAA,EAAAA;AAAI,OAAA,CAAE,CAAC,CAAA;KAClE,CAAA;AACF,GAAA,CAAA,CAAA;AAEX;;ICzBaQ,mBAAmB,GAA0D,SAA7EA,mBAAmBA,CAAA9B,IAAA,EAG3B;AAAA,EAAA,IAFD+B,QAAQ,GAAA/B,IAAA,CAAR+B,QAAQ;IACR5E,MAAM,GAAA6C,IAAA,CAAN7C,MAAM,CAAA;AAEN,EAAA,OAAOqE,GAAA,CAACxE,kBAAkB,CAACgF,QAAQ,EAAA;AAACpC,IAAAA,KAAK,EAAEzC,MAAM;AAAA4E,IAAAA,QAAA,EAAGA,QAAAA;AAAQ,GAAA,CAA+B,CAAA;AAC/F;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@form-instant/react-resolver-zod",
3
- "version": "0.0.13-alpha",
3
+ "version": "0.0.14-alpha",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "leomerida15",
package/src/element.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useInputMapping } from "@form-instant/react-input-mapping";
2
- import { useId } from "react";
2
+ import { createElement, useId } from "react";
3
3
  import { useFields } from "./useSchema";
4
4
 
5
5
  export interface ElementProps<Schema extends Record<string, any>> {
@@ -17,11 +17,13 @@ export const FormInstantElement = <S extends Record<string, any>>({ name }: Elem
17
17
  return (
18
18
  <>
19
19
  {inputs.map((props) => {
20
- const Element = InputMapping.get(props.type)!;
20
+ const Element = InputMapping.get(props.type);
21
21
 
22
22
  const { key, ...prop } = props;
23
23
 
24
- return <Element {...prop} key={`${key}-${id}`} />;
24
+ if (!Element) return null;
25
+
26
+ return createElement(Element, { ...prop, key: `${key}-${id}` });
25
27
  })}
26
28
  </>
27
29
  );