@form-instant/react-resolver-zod 0.0.9-alpha → 0.0.10-alpha
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +1 -3
- package/dist/react-resolver-zod.cjs.development.js +13 -14
- 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 +13 -14
- package/dist/react-resolver-zod.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -15
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
import { FieldConfig } from "@form-instant/react-input-mapping";
|
2
|
-
import { SuperRefineFunction } from "./funcs/types";
|
3
1
|
export { Element as FormInstantElement } from "./element";
|
2
|
+
export { createZodSchemaFieldConfig } from "./funcs/field-config";
|
4
3
|
export { Provider as FormInstantProvider } from "./provider";
|
5
4
|
export * from "./type";
|
6
5
|
export { useFields, useSchema } from "./useSchema";
|
7
|
-
export declare const createZodSchemaFieldConfig: <AdditionalRenderable = null, FieldTypes = string>() => (config: FieldConfig<AdditionalRenderable, FieldTypes>) => SuperRefineFunction;
|
@@ -37,14 +37,24 @@ function getDefaultValueInZodStack(schema) {
|
|
37
37
|
return undefined;
|
38
38
|
}
|
39
39
|
|
40
|
-
var FIELD_CONFIG_SYMBOL
|
40
|
+
var FIELD_CONFIG_SYMBOL = /*#__PURE__*/Symbol("GetFieldConfig");
|
41
|
+
var createZodSchemaFieldConfig = function createZodSchemaFieldConfig() {
|
42
|
+
return function (config) {
|
43
|
+
var refinementFunction = function refinementFunction() {
|
44
|
+
// Do nothing.
|
45
|
+
};
|
46
|
+
// @ts-expect-error This is a symbol and not a real value.
|
47
|
+
refinementFunction[FIELD_CONFIG_SYMBOL] = config;
|
48
|
+
return refinementFunction;
|
49
|
+
};
|
50
|
+
};
|
41
51
|
function getFieldConfigInZodStack(schema) {
|
42
52
|
var typedSchema = schema;
|
43
53
|
if (typedSchema._def.typeName === "ZodEffects") {
|
44
54
|
var effect = typedSchema._def.effect;
|
45
55
|
var refinementFunction = effect.refinement;
|
46
|
-
if (FIELD_CONFIG_SYMBOL
|
47
|
-
return refinementFunction[FIELD_CONFIG_SYMBOL
|
56
|
+
if (FIELD_CONFIG_SYMBOL in refinementFunction) {
|
57
|
+
return refinementFunction[FIELD_CONFIG_SYMBOL];
|
48
58
|
}
|
49
59
|
}
|
50
60
|
if ("innerType" in typedSchema._def) {
|
@@ -170,17 +180,6 @@ var Provider = function Provider(_ref) {
|
|
170
180
|
});
|
171
181
|
};
|
172
182
|
|
173
|
-
var createZodSchemaFieldConfig = function createZodSchemaFieldConfig() {
|
174
|
-
return function (config) {
|
175
|
-
var refinementFunction = function refinementFunction() {
|
176
|
-
// Do nothing.
|
177
|
-
};
|
178
|
-
// @ts-expect-error This is a symbol and not a real value.
|
179
|
-
refinementFunction[FIELD_CONFIG_SYMBOL] = config;
|
180
|
-
return refinementFunction;
|
181
|
-
};
|
182
|
-
};
|
183
|
-
|
184
183
|
exports.FormInstantElement = Element;
|
185
184
|
exports.FormInstantProvider = Provider;
|
186
185
|
exports.createZodSchemaFieldConfig = createZodSchemaFieldConfig;
|
@@ -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","../src/index.ts"],"sourcesContent":["import { createContext } from \"use-context-selector\";\nimport { zodResolverProps } from \"./type\";\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from \"zod\";\nimport { ZodObjectOrWrapped } from \"./types\";\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from \"zod\";\nimport { FieldConfig, SuperRefineFunction } from \"./types\";\nexport const FIELD_CONFIG_SYMBOL = Symbol(\"GetFieldConfig\");\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === \"ZodEffects\") {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if (\"innerType\" in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if (\"schema\" in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from \"zod\";\nimport { FieldConfig } from \"./types\";\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig[\"fieldType\"]): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n [\"ZodObject\", \"object\"],\n [\"ZodString\", \"string\"],\n [\"ZodNumber\", \"number\"],\n [\"ZodBoolean\", \"boolean\"],\n [\"ZodDate\", \"date\"],\n [\"ZodEnum\", \"select\"],\n [\"ZodNativeEnum\", \"select\"],\n [\"ZodArray\", \"array\"],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || \"string\"; // Default to string for unknown types\n}\n","import { 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 \"use-context-selector\";\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 Element = <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 Provider: FC<{ schema: zodResolverProps; children: ReactNode }> = ({\n children,\n schema,\n}) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n","import { FieldConfig } from \"@form-instant/react-input-mapping\";\nimport { SuperRefineFunction } from \"./funcs/types\";\n\nexport { Element as FormInstantElement } from \"./element\";\nexport { Provider as FormInstantProvider } from \"./provider\";\nexport * from \"./type\";\nexport { useFields, useSchema } from \"./useSchema\";\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"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","undefined","FIELD_CONFIG_SYMBOL","Symbol","getFieldConfigInZodStack","typedSchema","typeName","effect","refinementFunction","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","Element","name","InputMapping","useInputMapping","inputs","id","useId","_jsx","props","prop","_createElement","_extends","Provider","children","createZodSchemaFieldConfig","config"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAMA,kBAAkB,gBAAGC,gCAAa,CAAmB,EAAsB,CAAC;;ACAnF,SAAUC,yBAAyBA,CAACC,MAAoB,EAAA;AAC1D,EAAA,IAAIA,MAAM,YAAYC,KAAC,CAACC,UAAU,EAAE;AAChC,IAAA,OAAOF,MAAM,CAACG,IAAI,CAACC,YAAY,EAAE,CAAA;AACpC,GAAA;AAED,EAAA,IAAIJ,MAAM,YAAYC,KAAC,CAACI,UAAU,EAAE;AAChC,IAAA,OAAON,yBAAyB,CAACC,MAAM,CAACM,SAAS,EAAE,CAAC,CAAA;AACvD,GAAA;AAED,EAAA,OAAOC,SAAS,CAAA;AACpB;;ACXO,IAAMC,qBAAmB,gBAAGC,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAerD,SAAUC,wB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M,CAAA;AAEhD,IAAA,OAAO7D,kBAAkB,CAAA;GAC5B,CAAA;AAAA;;;;;;;;"}
|
1
|
+
{"version":3,"file":"react-resolver-zod.cjs.development.js","sources":["../src/context.tsx","../src/funcs/default-values.ts","../src/funcs/field-config.ts","../src/funcs/field-type-inference.ts","../src/funcs/schema-parser.ts","../src/useSchema.tsx","../src/element.tsx","../src/provider.tsx"],"sourcesContent":["import { createContext } from \"use-context-selector\";\nimport { zodResolverProps } from \"./type\";\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from \"zod\";\nimport { ZodObjectOrWrapped } from \"./types\";\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from \"zod\";\nimport { FieldConfig, SuperRefineFunction } from \"./types\";\nexport const FIELD_CONFIG_SYMBOL = Symbol(\"GetFieldConfig\");\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === \"ZodEffects\") {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if (\"innerType\" in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if (\"schema\" in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from \"zod\";\nimport { FieldConfig } from \"./types\";\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig[\"fieldType\"]): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n [\"ZodObject\", \"object\"],\n [\"ZodString\", \"string\"],\n [\"ZodNumber\", \"number\"],\n [\"ZodBoolean\", \"boolean\"],\n [\"ZodDate\", \"date\"],\n [\"ZodEnum\", \"select\"],\n [\"ZodNativeEnum\", \"select\"],\n [\"ZodArray\", \"array\"],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || \"string\"; // Default to string for unknown types\n}\n","import { 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 \"use-context-selector\";\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 Element = <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 Provider: 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","Element","name","InputMapping","useInputMapping","inputs","id","useId","_jsx","props","prop","_createElement","_extends","Provider","children"],"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,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,GAAA6C,IAAA,CAAN7C,MAAM,CAAA;AAEN,EAAA,OAAOqE,cAAA,CAACxE,kBAAkB,CAAC6E,QAAQ,EAAA;AAACjC,IAAAA,KAAK,EAAEzC,MAAM;AAAA2E,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("use-context-selector"),i=require("zod");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 o(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 u=t.createContext({});function f(e){return e instanceof i.z.ZodDefault?e._def.defaultValue():e instanceof i.z.ZodEffects?f(e.innerType()):void 0}var c=Symbol("GetFieldConfig");function s(e){var n=e;if("ZodEffects"===n._def.typeName){var r=n._def.effect.refinement;if(c in r)return r[c]}return"innerType"in n._def?s(n._def.innerType):"schema"in n._def?s(n._def.schema):{}}var d=["fieldType"];function p(e,n){var r=l(n),t=s(n),a=t.fieldType,u=o(t,d),c=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,a),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 i.z.ZodObject&&(h=Object.entries(r.shape).map((function(e){return p(e[0],e[1])}))),r instanceof i.z.ZodArray&&(h=[p("0",r._def.type)]),{key:e,type:c,required:!n.isOptional(),default:m,fieldConfig:u,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 m=function(){return t.useContext(u)},v=function(e){var n,r,t=(r=(n=m())instanceof i.z.ZodEffects?n.innerType():n,{fields:Object.fromEntries(Object.entries(r.shape).map((function(e){var n=e[0];return[n,p(n,e[1])]})))});return t.fields[e]},y=["key"];exports.FormInstantElement=function(t){var i=t.name,u=r.useInputMapping(),f=v(i),c=Object.values(f.schema),s=n.useId();return e.jsx(e.Fragment,{children:c.map((function(e){var r=u.get(e.type),t=e.key,i=o(e,y);return n.createElement(r,a({},i,{key:t+"-"+s}))}))})},exports.FormInstantProvider=function(n){return e.jsx(u.Provider,{value:n.schema,children:n.children})},exports.createZodSchemaFieldConfig=function(){return function(e){var n=function(){};return n[
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),n=require("react"),r=require("@form-instant/react-input-mapping"),t=require("use-context-selector"),i=require("zod");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 o(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 u=t.createContext({});function f(e){return e instanceof i.z.ZodDefault?e._def.defaultValue():e instanceof i.z.ZodEffects?f(e.innerType()):void 0}var c=Symbol("GetFieldConfig");function s(e){var n=e;if("ZodEffects"===n._def.typeName){var r=n._def.effect.refinement;if(c in r)return r[c]}return"innerType"in n._def?s(n._def.innerType):"schema"in n._def?s(n._def.schema):{}}var d=["fieldType"];function p(e,n){var r=l(n),t=s(n),a=t.fieldType,u=o(t,d),c=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,a),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 i.z.ZodObject&&(h=Object.entries(r.shape).map((function(e){return p(e[0],e[1])}))),r instanceof i.z.ZodArray&&(h=[p("0",r._def.type)]),{key:e,type:c,required:!n.isOptional(),default:m,fieldConfig:u,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 m=function(){return t.useContext(u)},v=function(e){var n,r,t=(r=(n=m())instanceof i.z.ZodEffects?n.innerType():n,{fields:Object.fromEntries(Object.entries(r.shape).map((function(e){var n=e[0];return[n,p(n,e[1])]})))});return t.fields[e]},y=["key"];exports.FormInstantElement=function(t){var i=t.name,u=r.useInputMapping(),f=v(i),c=Object.values(f.schema),s=n.useId();return e.jsx(e.Fragment,{children:c.map((function(e){var r=u.get(e.type),t=e.key,i=o(e,y);return n.createElement(r,a({},i,{key:t+"-"+s}))}))})},exports.FormInstantProvider=function(n){return e.jsx(u.Provider,{value:n.schema,children:n.children})},exports.createZodSchemaFieldConfig=function(){return function(e){var n=function(){};return n[c]=e,n}},exports.useFields=v,exports.useSchema=m;
|
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","../src/index.ts"],"sourcesContent":["import { createContext } from \"use-context-selector\";\nimport { zodResolverProps } from \"./type\";\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from \"zod\";\nimport { ZodObjectOrWrapped } from \"./types\";\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from \"zod\";\nimport { FieldConfig, SuperRefineFunction } from \"./types\";\nexport const FIELD_CONFIG_SYMBOL = Symbol(\"GetFieldConfig\");\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === \"ZodEffects\") {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if (\"innerType\" in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if (\"schema\" in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from \"zod\";\nimport { 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 \"use-context-selector\";\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 Element = <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 Provider: FC<{ schema: zodResolverProps; children: ReactNode }> = ({\n children,\n schema,\n}) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n","import { FieldConfig } from \"@form-instant/react-input-mapping\";\nimport { SuperRefineFunction } from \"./funcs/types\";\n\nexport { Element as FormInstantElement } from \"./element\";\nexport { Provider as FormInstantProvider } from \"./provider\";\nexport * from \"./type\";\nexport { useFields, useSchema } from \"./useSchema\";\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"],"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":"sgBAGO,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,EAA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oDwBiC,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,uCCNuB,SAAHwB,GAAgE,IAA3Be,EAAIf,EAAJe,KAC/CC,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,8BCvB+E,SAA1DpB,GAIjB,OAAOsB,EAAAO,IAACxE,EAAmByE,SAAQ,CAACpC,MAF9BM,EAANxC,OAEiDuE,SAHzC/B,EAAR+B,UAIJ,qCCDI,WADmC,OAEnC,SAACC,GACG,IAAM5D,EAA0C,aAOhD,OAFAA,EAAmBL,qBAAuBiE,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 \"use-context-selector\";\nimport { zodResolverProps } from \"./type\";\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from \"zod\";\nimport { ZodObjectOrWrapped } from \"./types\";\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from \"zod\";\nimport { FieldConfig, SuperRefineFunction } from \"./types\";\nexport const FIELD_CONFIG_SYMBOL = Symbol(\"GetFieldConfig\");\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === \"ZodEffects\") {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if (\"innerType\" in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if (\"schema\" in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from \"zod\";\nimport { 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 \"use-context-selector\";\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 Element = <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 Provider: 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":"sgBAGO,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,EAAsCV,EAAyBT,GAAvDoB,EAASD,EAATC,UAAcC,EAAWC,EAAAH,EAAAI,GAC3BC,ECNM,SAAexB,EAAsBoB,GACjD,GAAIA,EACA,OAAOA,EAGX,IAAMI,EAAOxB,EAAOG,KAAKQ,SAezB,OAbuB,IAAIc,IAAI,CAC3B,CAAC,YAAa,UACd,CAAC,YAAa,UACd,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,EAANC,OAEMpC,EAClB,uCCNuB,SAAHwB,GAAgE,IAA3Be,EAAIf,EAAJe,KAC/CC,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,8BCvB+E,SAA1DpB,GAIjB,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"}
|
@@ -35,14 +35,24 @@ function getDefaultValueInZodStack(schema) {
|
|
35
35
|
return undefined;
|
36
36
|
}
|
37
37
|
|
38
|
-
var FIELD_CONFIG_SYMBOL
|
38
|
+
var FIELD_CONFIG_SYMBOL = /*#__PURE__*/Symbol("GetFieldConfig");
|
39
|
+
var createZodSchemaFieldConfig = function createZodSchemaFieldConfig() {
|
40
|
+
return function (config) {
|
41
|
+
var refinementFunction = function refinementFunction() {
|
42
|
+
// Do nothing.
|
43
|
+
};
|
44
|
+
// @ts-expect-error This is a symbol and not a real value.
|
45
|
+
refinementFunction[FIELD_CONFIG_SYMBOL] = config;
|
46
|
+
return refinementFunction;
|
47
|
+
};
|
48
|
+
};
|
39
49
|
function getFieldConfigInZodStack(schema) {
|
40
50
|
var typedSchema = schema;
|
41
51
|
if (typedSchema._def.typeName === "ZodEffects") {
|
42
52
|
var effect = typedSchema._def.effect;
|
43
53
|
var refinementFunction = effect.refinement;
|
44
|
-
if (FIELD_CONFIG_SYMBOL
|
45
|
-
return refinementFunction[FIELD_CONFIG_SYMBOL
|
54
|
+
if (FIELD_CONFIG_SYMBOL in refinementFunction) {
|
55
|
+
return refinementFunction[FIELD_CONFIG_SYMBOL];
|
46
56
|
}
|
47
57
|
}
|
48
58
|
if ("innerType" in typedSchema._def) {
|
@@ -168,16 +178,5 @@ var Provider = function Provider(_ref) {
|
|
168
178
|
});
|
169
179
|
};
|
170
180
|
|
171
|
-
var createZodSchemaFieldConfig = function createZodSchemaFieldConfig() {
|
172
|
-
return function (config) {
|
173
|
-
var refinementFunction = function refinementFunction() {
|
174
|
-
// Do nothing.
|
175
|
-
};
|
176
|
-
// @ts-expect-error This is a symbol and not a real value.
|
177
|
-
refinementFunction[FIELD_CONFIG_SYMBOL] = config;
|
178
|
-
return refinementFunction;
|
179
|
-
};
|
180
|
-
};
|
181
|
-
|
182
181
|
export { Element as FormInstantElement, Provider as FormInstantProvider, createZodSchemaFieldConfig, useFields, useSchema };
|
183
182
|
//# sourceMappingURL=react-resolver-zod.esm.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"react-resolver-zod.esm.js","sources":["../src/context.tsx","../src/funcs/default-values.ts","../src/funcs/field-config.ts","../src/funcs/field-type-inference.ts","../src/funcs/schema-parser.ts","../src/useSchema.tsx","../src/element.tsx","../src/provider.tsx","../src/index.ts"],"sourcesContent":["import { createContext } from \"use-context-selector\";\nimport { zodResolverProps } from \"./type\";\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from \"zod\";\nimport { ZodObjectOrWrapped } from \"./types\";\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from \"zod\";\nimport { FieldConfig, SuperRefineFunction } from \"./types\";\nexport const FIELD_CONFIG_SYMBOL = Symbol(\"GetFieldConfig\");\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === \"ZodEffects\") {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if (\"innerType\" in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if (\"schema\" in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from \"zod\";\nimport { FieldConfig } from \"./types\";\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig[\"fieldType\"]): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n [\"ZodObject\", \"object\"],\n [\"ZodString\", \"string\"],\n [\"ZodNumber\", \"number\"],\n [\"ZodBoolean\", \"boolean\"],\n [\"ZodDate\", \"date\"],\n [\"ZodEnum\", \"select\"],\n [\"ZodNativeEnum\", \"select\"],\n [\"ZodArray\", \"array\"],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || \"string\"; // Default to string for unknown types\n}\n","import { 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 \"use-context-selector\";\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 Element = <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 Provider: FC<{ schema: zodResolverProps; children: ReactNode }> = ({\n children,\n schema,\n}) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n","import { FieldConfig } from \"@form-instant/react-input-mapping\";\nimport { SuperRefineFunction } from \"./funcs/types\";\n\nexport { Element as FormInstantElement } from \"./element\";\nexport { Provider as FormInstantProvider } from \"./provider\";\nexport * from \"./type\";\nexport { useFields, useSchema } from \"./useSchema\";\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"],"names":["ZodResolverContext","createContext","getDefaultValueInZodStack","schema","z","ZodDefault","_def","defaultValue","ZodEffects","innerType","undefined","FIELD_CONFIG_SYMBOL","Symbol","getFieldConfigInZodStack","typedSchema","typeName","effect","refinementFunction","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","Element","name","InputMapping","useInputMapping","inputs","id","useId","_jsx","props","prop","_createElement","_extends","Provider","children","createZodSchemaFieldConfig","config"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAMA,kBAAkB,gBAAGC,aAAa,CAAmB,EAAsB,CAAC;;ACAnF,SAAUC,yBAAyBA,CAACC,MAAoB,EAAA;AAC1D,EAAA,IAAIA,MAAM,YAAYC,CAAC,CAACC,UAAU,EAAE;AAChC,IAAA,OAAOF,MAAM,CAACG,IAAI,CAACC,YAAY,EAAE,CAAA;AACpC,GAAA;AAED,EAAA,IAAIJ,MAAM,YAAYC,CAAC,CAACI,UAAU,EAAE;AAChC,IAAA,OAAON,yBAAyB,CAACC,MAAM,CAACM,SAAS,EAAE,CAAC,CAAA;AACvD,GAAA;AAED,EAAA,OAAOC,SAAS,CAAA;AACpB;;ACXO,IAAMC,qBAAmB,gBAAGC,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAerD,SAAUC,wBAAwBA,CAACV,MAAoB,EAAA;EACzD,IAAMW,WAAW,GAAGX,MAA4D,CAAA;AAEhF,EAAA,IAAIW,WAA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-resolver-zod.esm.js","sources":["../src/context.tsx","../src/funcs/default-values.ts","../src/funcs/field-config.ts","../src/funcs/field-type-inference.ts","../src/funcs/schema-parser.ts","../src/useSchema.tsx","../src/element.tsx","../src/provider.tsx"],"sourcesContent":["import { createContext } from \"use-context-selector\";\nimport { zodResolverProps } from \"./type\";\n\nexport const ZodResolverContext = createContext<zodResolverProps>({} as zodResolverProps);\n","import { z } from \"zod\";\nimport { ZodObjectOrWrapped } from \"./types\";\n\nexport function getDefaultValueInZodStack(schema: z.ZodTypeAny): any {\n if (schema instanceof z.ZodDefault) {\n return schema._def.defaultValue();\n }\n\n if (schema instanceof z.ZodEffects) {\n return getDefaultValueInZodStack(schema.innerType());\n }\n\n return undefined;\n}\n\nexport function getDefaultValues(schema: ZodObjectOrWrapped): Record<string, any> {\n const objectSchema = schema instanceof z.ZodEffects ? schema.innerType() : schema;\n const shape = objectSchema.shape;\n\n const defaultValues: Record<string, any> = {};\n\n for (const [key, field] of Object.entries(shape)) {\n const defaultValue = getDefaultValueInZodStack(field as z.ZodTypeAny);\n if (defaultValue !== undefined) {\n defaultValues[key] = defaultValue;\n }\n }\n\n return defaultValues;\n}\n","import { RefinementEffect, z } from \"zod\";\nimport { FieldConfig, SuperRefineFunction } from \"./types\";\nexport const FIELD_CONFIG_SYMBOL = Symbol(\"GetFieldConfig\");\n\nexport const createZodSchemaFieldConfig =\n <AdditionalRenderable = null, FieldTypes = string>() =>\n (config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {\n const refinementFunction: SuperRefineFunction = () => {\n // Do nothing.\n };\n\n // @ts-expect-error This is a symbol and not a real value.\n refinementFunction[FIELD_CONFIG_SYMBOL] = config;\n\n return refinementFunction;\n };\n\nexport function getFieldConfigInZodStack(schema: z.ZodTypeAny): FieldConfig {\n const typedSchema = schema as unknown as z.ZodEffects<z.ZodNumber | z.ZodString>;\n\n if (typedSchema._def.typeName === \"ZodEffects\") {\n const effect = typedSchema._def.effect as RefinementEffect<any>;\n const refinementFunction = effect.refinement;\n\n if (FIELD_CONFIG_SYMBOL in refinementFunction) {\n return refinementFunction[FIELD_CONFIG_SYMBOL] as FieldConfig;\n }\n }\n\n if (\"innerType\" in typedSchema._def) {\n return getFieldConfigInZodStack(typedSchema._def.innerType as unknown as z.ZodAny);\n }\n if (\"schema\" in typedSchema._def) {\n return getFieldConfigInZodStack((typedSchema._def as any).schema as z.ZodAny);\n }\n\n return {};\n}\n","import { z } from \"zod\";\nimport { FieldConfig } from \"./types\";\n\nexport function inferFieldType(schema: z.ZodTypeAny, fieldType?: FieldConfig[\"fieldType\"]): string {\n if (fieldType) {\n return fieldType;\n }\n\n const type = schema._def.typeName;\n\n const zodToInputType = new Map([\n [\"ZodObject\", \"object\"],\n [\"ZodString\", \"string\"],\n [\"ZodNumber\", \"number\"],\n [\"ZodBoolean\", \"boolean\"],\n [\"ZodDate\", \"date\"],\n [\"ZodEnum\", \"select\"],\n [\"ZodNativeEnum\", \"select\"],\n [\"ZodArray\", \"array\"],\n ]);\n\n const match = zodToInputType.get(type);\n\n return match || \"string\"; // Default to string for unknown types\n}\n","import { 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 \"use-context-selector\";\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 Element = <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 Provider: 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","Element","name","InputMapping","useInputMapping","inputs","id","useId","_jsx","props","prop","_createElement","_extends","Provider","children"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAMA,kBAAkB,gBAAGC,aAAa,CAAmB,EAAsB,CAAC;;ACAnF,SAAUC,yBAAyBA,CAACC,MAAoB,EAAA;AAC1D,EAAA,IAAIA,MAAM,YAAYC,CAAC,CAACC,UAAU,EAAE;AAChC,IAAA,OAAOF,MAAM,CAACG,IAAI,CAACC,YAAY,EAAE,CAAA;AACpC,GAAA;AAED,EAAA,IAAIJ,MAAM,YAAYC,CAAC,CAACI,UAAU,EAAE;AAChC,IAAA,OAAON,yBAAyB,CAACC,MAAM,CAACM,SAAS,EAAE,CAAC,CAAA;AACvD,GAAA;AAED,EAAA,OAAOC,SAAS,CAAA;AACpB;;ACXO,IAAMC,mBAAmB,gBAAGC,MAAM,CAAC,gBAAgB,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AAA,KAAK,EAAEzC,MAAM;AAAA2E,IAAAA,QAAA,EAAGA,QAAAA;AAAQ,GAAA,CAA+B,CAAA;AAC/F;;;;"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
@@ -1,19 +1,5 @@
|
|
1
|
-
import { FieldConfig } from "@form-instant/react-input-mapping";
|
2
|
-
import { SuperRefineFunction } from "./funcs/types";
|
3
|
-
|
4
1
|
export { Element as FormInstantElement } from "./element";
|
2
|
+
export { createZodSchemaFieldConfig } from "./funcs/field-config";
|
5
3
|
export { Provider as FormInstantProvider } from "./provider";
|
6
4
|
export * from "./type";
|
7
5
|
export { useFields, useSchema } from "./useSchema";
|
8
|
-
export const createZodSchemaFieldConfig =
|
9
|
-
<AdditionalRenderable = null, FieldTypes = string>() =>
|
10
|
-
(config: FieldConfig<AdditionalRenderable, FieldTypes>): SuperRefineFunction => {
|
11
|
-
const refinementFunction: SuperRefineFunction = () => {
|
12
|
-
// Do nothing.
|
13
|
-
};
|
14
|
-
|
15
|
-
// @ts-expect-error This is a symbol and not a real value.
|
16
|
-
refinementFunction[FIELD_CONFIG_SYMBOL] = config;
|
17
|
-
|
18
|
-
return refinementFunction;
|
19
|
-
};
|