@saas-ui/forms 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +19 -0
- package/ajv/package.json +11 -2
- package/dist/ajv/index.js.map +1 -1
- package/dist/ajv/{index.modern.mjs → index.modern.js} +17 -17
- package/dist/ajv/index.modern.js.map +1 -0
- package/dist/index.js.map +1 -1
- package/dist/{index.modern.mjs → index.modern.js} +2 -2
- package/dist/index.modern.js.map +1 -0
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/{index.modern.mjs → index.modern.js} +1 -1
- package/dist/yup/index.modern.js.map +1 -0
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/{index.modern.mjs → index.modern.js} +1 -1
- package/dist/zod/index.modern.js.map +1 -0
- package/package.json +15 -15
- package/yup/package.json +11 -2
- package/zod/package.json +11 -2
- package/dist/ajv/index.modern.mjs.map +0 -1
- package/dist/index.modern.mjs.map +0 -1
- package/dist/yup/index.modern.mjs.map +0 -1
- package/dist/zod/index.modern.mjs.map +0 -1
package/dist/yup/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../yup/src/yup-resolver.ts"],"sourcesContent":["import { reach, AnyObjectSchema } from 'yup'\nimport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { yupResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\n// @TODO get proper typings for the schema fields\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: AnyObjectSchema): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: AnyObjectSchema, path: string) => {\n return reach(schema, path)\n}\n\nexport const yupFieldResolver = (schema: AnyObjectSchema) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const yupForm = (\n schema: AnyObjectSchema,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: yupResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: yupFieldResolver(schema),\n }\n}\n"],"names":["getType","field","_field$spec$meta","spec","meta","type","getArrayOption","name","_step","tests","_iterator","done","_test$OPTIONS","value","test","OPTIONS","params","getFieldsFromSchema","schema","schemaFields","fields","innerType","options","min","max","push","label","path","reach","yupFieldResolver","getFields","getNestedFields","getNestedSchema","schemaOptions","resolverOptions","resolver","yupResolver","fieldResolver"],"mappings":"wYAaA,IAAMA,EAAU,SAACC,GACf,IAAAC,EAAA,GAAA,OAAAA,EAAID,EAAME,KAAKC,OAAXF,EAAiBG,KACnB,OAAOJ,EAAME,KAAKC,KAAKC,KAGzB,OAAQJ,EAAMI,MACZ,IAAK,QACH,MAAO,QACT,IAAK,SACH,MAAO,SACT,IAAK,SACH,MAAO,SACT,IAAK,OACH,MAAO,OAET,QACE,MAAO,
|
1
|
+
{"version":3,"file":"index.js","sources":["../../yup/src/yup-resolver.ts"],"sourcesContent":["import { reach, AnyObjectSchema } from 'yup'\nimport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { yupResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\n// @TODO get proper typings for the schema fields\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: AnyObjectSchema): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: AnyObjectSchema, path: string) => {\n return reach(schema, path)\n}\n\nexport const yupFieldResolver = (schema: AnyObjectSchema) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const yupForm = (\n schema: AnyObjectSchema,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: yupResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: yupFieldResolver(schema),\n }\n}\n"],"names":["getType","field","_field$spec$meta","spec","meta","type","getArrayOption","name","_step","tests","_iterator","done","_test$OPTIONS","value","test","OPTIONS","params","getFieldsFromSchema","schema","schemaFields","fields","innerType","options","min","max","push","label","path","reach","yupFieldResolver","getFields","getNestedFields","getNestedSchema","schemaOptions","resolverOptions","resolver","yupResolver","fieldResolver"],"mappings":"wYAaA,IAAMA,EAAU,SAACC,GACf,IAAAC,EAAA,GAAA,OAAAA,EAAID,EAAME,KAAKC,OAAXF,EAAiBG,KACnB,OAAOJ,EAAME,KAAKC,KAAKC,KAGzB,OAAQJ,EAAMI,MACZ,IAAK,QACH,MAAO,QACT,IAAK,SACH,MAAO,SACT,IAAK,SACH,MAAO,SACT,IAAK,OACH,MAAO,OAET,QACE,MAAO,OAEZ,EAEmBC,EAAG,SAACL,EAAYM,GAClC,QAAgCC,8qBAAbP,EAAMQ,SAAOD,EAAAE,KAAAC,MAAA,CAAA,IAAAC,IAC9BJ,EAAAK,MAAA,GAAI,OAAJD,EAAIE,EAAKC,UAALH,EAAcI,OAAOT,GAAO,OAAWO,EAACC,QAAQC,OAAOT,EAC5D,CACF,EAQYU,EAAsB,SAACC,GAClC,IAEIC,EAFEC,EAAS,GAUf,IAAK,SALHD,EAFkB,UAAhBD,EAAOb,KAEMa,EAAOG,UAAUD,OAEjBF,EAAOE,OAGS,CAC/B,MAAcD,EAAaZ,KAEF,CAAzB,EACmB,UAAfN,EAAMI,OACRiB,EAAQC,IAAMjB,EAAeL,EAAO,OACpCqB,EAAQE,IAAMlB,EAAeL,EAAO,QAGtCmB,EAAOK,QACLlB,KAAAA,EACAmB,MAAOzB,EAAME,KAAKuB,OAASnB,EAC3BF,KAAML,EAAQC,IACXqB,GAEN,CACD,QACD,IAE8B,SAACJ,EAAyBS,GACvD,OAAOC,EAAAA,MAAMV,EAAQS,EACtB,EAE4BE,EAAG,SAACX,GAC/B,MAAO,CACLY,UAAS,WACP,OAA0Bb,EAACC,EAC5B,EACDa,gBAJK,SAIWxB,GACd,OAAOU,EAAoBe,EAAgBd,EAAQX,GACpD,EAEJ,uMAEsB,SACrBW,EACAe,EACAC,GAEA,YAHAD,IAAAA,IAAAA,EAAgB,CAEd,QADFC,IAAAA,IAAAA,EAAkB,CAAA,GAEX,CACLhB,OAAAA,EACAiB,SAAUC,EAAWA,YAAClB,EAAQe,EAAeC,GAC7CG,cAAeR,EAAiBX,GAEnC"}
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import{reach as e}from"yup";import{yupResolver as r}from"@hookform/resolvers/yup";export{yupResolver}from"@hookform/resolvers/yup";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},t.apply(this,arguments)}const a=e=>{var r;if(null!=(r=e.spec.meta)&&r.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},s=(e,r)=>{for(const a of e.tests){var t;if(null!=(t=a.OPTIONS)&&t.params[r])return a.OPTIONS.params[r]}},n=e=>{const r=[];let n={};n="array"===e.type?e.innerType.fields:e.fields;for(const e in n){const o=n[e],p={};"array"===o.type&&(p.min=s(o,"min"),p.max=s(o,"max")),r.push(t({name:e,label:o.spec.label||e,type:a(o)},p))}return r},o=(r,t)=>e(r,t),p=e=>({getFields:()=>n(e),getNestedFields:r=>n(o(e,r))}),l=(e,t={},a={})=>({schema:e,resolver:r(e,t,a),fieldResolver:p(e)});export{n as getFieldsFromSchema,o as getNestedSchema,p as yupFieldResolver,l as yupForm};
|
2
|
-
//# sourceMappingURL=index.modern.
|
2
|
+
//# sourceMappingURL=index.modern.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../../yup/src/yup-resolver.ts"],"sourcesContent":["import { reach, AnyObjectSchema } from 'yup'\nimport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { yupResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\n// @TODO get proper typings for the schema fields\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: AnyObjectSchema): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: AnyObjectSchema, path: string) => {\n return reach(schema, path)\n}\n\nexport const yupFieldResolver = (schema: AnyObjectSchema) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const yupForm = (\n schema: AnyObjectSchema,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: yupResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: yupFieldResolver(schema),\n }\n}\n"],"names":["field","_field$spec$meta","spec","meta","type","getArrayOption","name","test","tests","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","schemaFields","innerType","fields","options","min","max","push","label","getType","getNestedSchema","path","reach","yupFieldResolver","getFields","getNestedFields","yupForm","schemaOptions","resolverOptions","resolver","yupResolver","fieldResolver"],"mappings":"uWAaA,QAAiBA,IACf,IAAAC,EAAA,GAAI,OAAJA,EAAID,EAAME,KAAKC,OAAXF,EAAiBG,KACnB,OAAOJ,EAAME,KAAKC,KAAKC,KAGzB,OAAQJ,EAAMI,MACZ,IAAK,QACH,MAAO,QACT,IAAK,SACH,MAAO,SACT,IAAK,SACH,MAAO,SACT,IAAK,OACH,MAAO,OAET,QACE,MAAO,OAXX,EAeIC,EAAiB,CAACL,EAAYM,KAClC,IAAK,MAAMC,KAAaP,EAACQ,MAAO,OAC9B,GAAA,OAAID,EAAAA,EAAKE,UAALC,EAAcC,OAAOL,GAAO,OAAOC,EAAKE,QAAQE,OAAOL,EAC5D,GASUM,EAAuBC,IAClC,QAAe,GAEf,MAAwC,GAGtCC,EAFkB,UAAhBD,EAAOT,KAEMS,EAAOE,UAAUC,OAEjBH,EAAOG,OAGxB,IAAK,WAAcF,EAAc,CAC/B,MAAWd,EAAGc,EAAaR,GAEdW,EAAY,CAAzB,EACmB,UAAfjB,EAAMI,OACRa,EAAQC,IAAMb,EAAeL,EAAO,OACpCiB,EAAQE,IAAMd,EAAeL,EAAO,QAGtCgB,EAAOI,KACLd,EAAAA,CAAAA,OACAe,MAAOrB,EAAME,KAAKmB,OAASf,EAC3BF,KAAMkB,EAAQtB,IACXiB,GAEN,CACD,OAAOD,GAGIO,EAAkB,CAACV,EAAyBW,IAChDC,EAAMZ,EAAQW,GAGVE,EAAoBb,IACxB,CACLc,UAAS,IACAf,EAAoBC,GAE7Be,gBAAgBtB,GACPM,EAAoBW,EAAgBV,EAAQP,MAKrCuB,EAAG,CACrBhB,EACAiB,EAAgB,CAFK,EAGrBC,EAAkB,CAAA,KAEX,CACLlB,SACAmB,SAAUC,EAAYpB,EAAQiB,EAAeC,GAC7CG,cAAeR,EAAiBb"}
|
package/dist/zod/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../zod/src/zod-resolver.ts"],"sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const zodForm = <T extends z.ZodTypeAny>(\n schema: T,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: zodResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: zodFieldResolver(schema),\n }\n}\n\nexport interface ZodMeta {\n label: string\n type?: string\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n"],"names":["getType","field","_def","typeName","getArrayOption","name","_field$_def$name","value","getFieldsFromSchema","schema","fields","schemaFields","type","shape","options","min","max","meta","description","zodParseMeta","push","label","getNestedSchema","path","get","zodFieldResolver","getFields","getNestedFields","JSON","parse","e","schemaOptions","resolverOptions","resolver","zodResolver","fieldResolver","stringify"],"mappings":"2SAYA,IAAMA,EAAU,SAACC,GACf,OAAQA,EAAMC,KAAKC,UACjB,IAAK,WACH,MAAO,QACT,IAAK,YACH,MAAO,SACT,IAAK,YACH,MAAO,SACT,IAAK,UACH,MAAO,OAET,QACE,MAAO,
|
1
|
+
{"version":3,"file":"index.js","sources":["../../zod/src/zod-resolver.ts"],"sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const zodForm = <T extends z.ZodTypeAny>(\n schema: T,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: zodResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: zodFieldResolver(schema),\n }\n}\n\nexport interface ZodMeta {\n label: string\n type?: string\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n"],"names":["getType","field","_def","typeName","getArrayOption","name","_field$_def$name","value","getFieldsFromSchema","schema","fields","schemaFields","type","shape","options","min","max","meta","description","zodParseMeta","push","label","getNestedSchema","path","get","zodFieldResolver","getFields","getNestedFields","JSON","parse","e","schemaOptions","resolverOptions","resolver","zodResolver","fieldResolver","stringify"],"mappings":"2SAYA,IAAMA,EAAU,SAACC,GACf,OAAQA,EAAMC,KAAKC,UACjB,IAAK,WACH,MAAO,QACT,IAAK,YACH,MAAO,SACT,IAAK,YACH,MAAO,SACT,IAAK,UACH,MAAO,OAET,QACE,MAAO,OAEZ,EAEKC,EAAiB,SAACH,EAAYI,GAClC,IAAAC,EAAA,OAAA,OAAAA,EAAOL,EAAMC,KAAKG,SAAlB,EAAOC,EAAkBC,KAC1B,EAQ+BC,EAAG,SAACC,GAClC,IAAYC,EAAiB,GAEbC,EAAwB,CAAA,EACxC,GAA6B,aAAzBF,EAAOP,KAAKC,SACdQ,EAAeF,EAAOP,KAAKU,KAAKC,UACvBJ,IAAyB,cAAzBA,EAAOP,KAAKC,SAGrB,OACDO,EAHCC,EAAeF,EAAOP,KAAKW,OAG5B,CAED,IAAK,SAAcF,EAAc,CAC/B,IAAMV,EAAQU,EAAaN,GAEdS,EAAY,CAAzB,EAC4B,aAAxBb,EAAMC,KAAKC,WACbW,EAAQC,IAAMX,EAAeH,EAAO,aACpCa,EAAQE,IAAMZ,EAAeH,EAAO,cAGtC,IAAMgB,EAAOhB,EAAMiB,aAAeC,EAAalB,EAAMiB,aAErDR,EAAOU,QACLf,KAAAA,EACAgB,OAAW,MAAJJ,OAAAA,EAAAA,EAAMI,QAASpB,EAAMiB,aAAeb,EAC3CO,MAAM,MAAAK,OAAA,EAAAA,EAAML,OAAQZ,EAAQC,IACzBa,GAEN,CACD,OAAOJ,CACR,EAEYY,EAAkB,SAACb,EAAsBc,GACpD,OAAOC,MAAIf,EAAOP,KAAKW,QAASU,EACjC,EAE4BE,EAAG,SAAyBhB,GACvD,MAAO,CACLiB,UAAS,WACP,OAAOlB,EAAoBC,EAC5B,EACDkB,gBAJK,SAIWtB,GACd,OAAOG,EAAoBc,EAAgBb,EAAQJ,GACpD,EAEJ,IAuB2B,SAACY,GAC3B,IACE,OAAWW,KAACC,MAAMZ,EAGnB,CAFC,MAAOa,GACP,OACDb,CAAA,CACF,uMA3BsB,SACrBR,EACAsB,EACAC,GAEA,YAHAD,IAAAA,IAAAA,EAAgB,CAAA,QAEd,IADFC,IAAAA,EAAkB,CAAA,GAEX,CACLvB,OAAAA,EACAwB,SAAUC,EAAAA,YAAYzB,EAAQsB,EAAeC,GAC7CG,cAAeV,EAAiBhB,GAEnC,kBAOsB,SAACQ,GACtB,OAAOW,KAAKQ,UAAUnB,EACvB"}
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import{zodResolver as e}from"@hookform/resolvers/zod";export{zodResolver}from"@hookform/resolvers/zod";import{get as r}from"@chakra-ui/utils";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},t.apply(this,arguments)}const o=e=>{switch(e._def.typeName){case"ZodArray":return"array";case"ZodObject":return"object";case"ZodNumber":return"number";case"ZodDate":return"date";default:return"text"}},n=(e,r)=>{var t;return null==(t=e._def[r])?void 0:t.value},a=e=>{const r=[];let a={};if("ZodArray"===e._def.typeName)a=e._def.type.shape;else{if("ZodObject"!==e._def.typeName)return r;a=e._def.shape()}for(const e in a){const s=a[e],d={};"ZodArray"===s._def.typeName&&(d.min=n(s,"minLength"),d.max=n(s,"maxLength"));const i=s.description&&c(s.description);r.push(t({name:e,label:(null==i?void 0:i.label)||s.description||e,type:(null==i?void 0:i.type)||o(s)},d))}return r},s=(e,t)=>r(e._def.shape(),t),d=e=>({getFields:()=>a(e),getNestedFields:r=>a(s(e,r))}),i=(r,t={},o={})=>({schema:r,resolver:e(r,t,o),fieldResolver:d(r)}),l=e=>JSON.stringify(e),c=e=>{try{return JSON.parse(e)}catch(r){return e}};export{a as getFieldsFromSchema,s as getNestedSchema,d as zodFieldResolver,i as zodForm,l as zodMeta,c as zodParseMeta};
|
2
|
-
//# sourceMappingURL=index.modern.
|
2
|
+
//# sourceMappingURL=index.modern.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../../zod/src/zod-resolver.ts"],"sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const zodForm = <T extends z.ZodTypeAny>(\n schema: T,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: zodResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: zodFieldResolver(schema),\n }\n}\n\nexport interface ZodMeta {\n label: string\n type?: string\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n"],"names":["field","_def","typeName","getArrayOption","name","_field$_def$name","value","getFieldsFromSchema","schema","fields","schemaFields","type","shape","options","min","max","meta","description","zodParseMeta","push","_extends","label","getType","getNestedSchema","path","get","zodFieldResolver","getFields","getNestedFields","zodForm","schemaOptions","resolverOptions","resolver","zodResolver","fieldResolver","zodMeta","JSON","stringify","parse","e"],"mappings":"kXAYA,QAAiBA,IACf,OAAQA,EAAMC,KAAKC,UACjB,IAAK,WACH,MAAO,QACT,IAAK,YACH,MAAO,SACT,IAAK,YACH,MAAO,SACT,IAAK,UACH,MAAO,OAET,QACE,MAAO,OAXX,EAekBC,EAAG,CAACH,EAAYI,KAAgB,IAAAC,EAClD,cAAOL,EAAAA,EAAMC,KAAKG,WAAXC,EAAkBC,OASKC,EAAIC,IAClC,MAAYC,EAAiB,GAE7B,IAAgBC,EAAwB,CAAxC,EACA,GAA6B,aAAzBF,EAAOP,KAAKC,SACdQ,EAAeF,EAAOP,KAAKU,KAAKC,UACvBJ,IAAyB,cAAzBA,EAAOP,KAAKC,SAGrB,SAFAQ,EAAeF,EAAOP,KAAKW,OAG5B,CAED,IAAK,MAAMR,KAAQM,EAAc,CAC/B,QAAcA,EAAaN,GAErBS,EAAmB,CAAA,EACG,aAAxBb,EAAMC,KAAKC,WACbW,EAAQC,IAAMX,EAAeH,EAAO,aACpCa,EAAQE,IAAMZ,EAAeH,EAAO,cAGtC,MAAUgB,EAAGhB,EAAMiB,aAAeC,EAAalB,EAAMiB,aAErDR,EAAOU,KAAPC,EAAA,CACEhB,OACAiB,aAAOL,OAAAA,EAAAA,EAAMK,QAASrB,EAAMiB,aAAeb,EAC3CO,MAAM,MAAAK,OAAA,EAAAA,EAAML,OAAQW,EAAQtB,IACzBa,GAEN,CACD,UAGWU,EAAkB,CAACf,EAAsBgB,IAC7CC,EAAIjB,EAAOP,KAAKW,QAASY,GAGLE,EAA4BlB,IAChD,CACLmB,UAAS,MACoBnB,GAE7BoB,gBAAgBxB,GACPG,EAAoBgB,EAAgBf,EAAQJ,MAK5CyB,EAAU,CACrBrB,EACAsB,EAAgB,CAFK,EAGrBC,EAAkB,CAAA,KAEX,CACLvB,SACAwB,SAAUC,EAAYzB,EAAQsB,EAAeC,GAC7CG,cAAeR,EAAiBlB,KAShB2B,EAAInB,GACXoB,KAACC,UAAUrB,GAGCE,EAAIF,IAC3B,IACE,YAAYsB,MAAMtB,EAGnB,CAFC,MAAOuB,GACP,OACDvB,CAAA"}
|
package/package.json
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
{
|
2
2
|
"name": "@saas-ui/forms",
|
3
|
-
"version": "1.0
|
3
|
+
"version": "1.1.0",
|
4
4
|
"description": "Fully functional forms for Chakra UI.",
|
5
5
|
"source": "src/index.ts",
|
6
6
|
"exports": {
|
7
7
|
".": {
|
8
8
|
"require": "./dist/index.js",
|
9
|
-
"
|
9
|
+
"import": "./dist/index.modern.js"
|
10
10
|
},
|
11
11
|
"./src": {
|
12
12
|
"default": "./src/index.ts"
|
13
13
|
},
|
14
14
|
"./yup": {
|
15
15
|
"require": "./dist/yup/index.js",
|
16
|
-
"
|
16
|
+
"import": "./dist/yup/index.modern.js"
|
17
17
|
},
|
18
18
|
"./yup/src": {
|
19
19
|
"default": "./yup/src/index.ts"
|
20
20
|
},
|
21
21
|
"./zod": {
|
22
22
|
"require": "./dist/zod/index.js",
|
23
|
-
"
|
23
|
+
"import": "./dist/zod/index.modern.js"
|
24
24
|
},
|
25
25
|
"./zod/src": {
|
26
26
|
"default": "./zod/src/index.ts"
|
27
27
|
},
|
28
28
|
"./ajv": {
|
29
29
|
"require": "./dist/ajv/index.js",
|
30
|
-
"
|
30
|
+
"import": "./dist/ajv/index.modern.js"
|
31
31
|
},
|
32
32
|
"./ajv/src": {
|
33
33
|
"default": "./ajv/src/index.ts"
|
34
34
|
}
|
35
35
|
},
|
36
36
|
"main": "./dist/index.js",
|
37
|
-
"module": "./dist/index.modern.
|
37
|
+
"module": "./dist/index.modern.js",
|
38
38
|
"types": "./dist/index.d.ts",
|
39
39
|
"scripts": {
|
40
40
|
"clean": "rimraf --no-glob ./dist",
|
@@ -93,15 +93,15 @@
|
|
93
93
|
"@chakra-ui/react-utils": "^2.0.1",
|
94
94
|
"@chakra-ui/utils": "^2.0.2",
|
95
95
|
"@hookform/resolvers": "^2.9.0",
|
96
|
-
"@saas-ui/button": "1.
|
97
|
-
"@saas-ui/input-right-button": "1.0
|
98
|
-
"@saas-ui/number-input": "1.
|
99
|
-
"@saas-ui/password-input": "1.0
|
100
|
-
"@saas-ui/pin-input": "1.
|
101
|
-
"@saas-ui/radio": "1.
|
102
|
-
"@saas-ui/react-utils": "1.
|
103
|
-
"@saas-ui/select": "1.
|
104
|
-
"@saas-ui/stepper": "1.
|
96
|
+
"@saas-ui/button": "1.1.0",
|
97
|
+
"@saas-ui/input-right-button": "1.1.0",
|
98
|
+
"@saas-ui/number-input": "1.1.0",
|
99
|
+
"@saas-ui/password-input": "1.1.0",
|
100
|
+
"@saas-ui/pin-input": "1.1.0",
|
101
|
+
"@saas-ui/radio": "1.1.0",
|
102
|
+
"@saas-ui/react-utils": "1.1.0",
|
103
|
+
"@saas-ui/select": "1.1.0",
|
104
|
+
"@saas-ui/stepper": "1.1.0",
|
105
105
|
"react-hook-form": "^7.33.1"
|
106
106
|
},
|
107
107
|
"peerDependencies": {
|
package/yup/package.json
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
{
|
2
|
-
"name": "yup",
|
2
|
+
"name": "yup-resolver",
|
3
3
|
"description": "Saas UI Forms field resolver: yup",
|
4
4
|
"version": "1.0.0",
|
5
5
|
"private": true,
|
6
|
+
"exports": {
|
7
|
+
".": {
|
8
|
+
"require": "./../dist/yup/index.js",
|
9
|
+
"import": "./../dist/yup/index.modern.js"
|
10
|
+
},
|
11
|
+
"./src": {
|
12
|
+
"default": "./src/index.ts"
|
13
|
+
}
|
14
|
+
},
|
6
15
|
"source": "./src/index.ts",
|
7
16
|
"main": "../dist/yup/index.js",
|
8
|
-
"module": "../dist/yup/index.modern.
|
17
|
+
"module": "../dist/yup/index.modern.js",
|
9
18
|
"types": "../dist/yup/index.d.ts",
|
10
19
|
"author": "Eelco Wiersma <eelco@appulse.nl>",
|
11
20
|
"license": "MIT",
|
package/zod/package.json
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
{
|
2
|
-
"name": "zod",
|
2
|
+
"name": "zod-resolver",
|
3
3
|
"description": "Saas UI Forms field resolver: zod",
|
4
4
|
"version": "1.0.0",
|
5
5
|
"private": true,
|
6
|
+
"exports": {
|
7
|
+
".": {
|
8
|
+
"require": "./../dist/zod/index.js",
|
9
|
+
"import": "./../dist/zod/index.modern.js"
|
10
|
+
},
|
11
|
+
"./src": {
|
12
|
+
"default": "./src/index.ts"
|
13
|
+
}
|
14
|
+
},
|
6
15
|
"source": "./src/index.ts",
|
7
16
|
"main": "../dist/zod/index.js",
|
8
|
-
"module": "../dist/zod/index.modern.
|
17
|
+
"module": "../dist/zod/index.modern.js",
|
9
18
|
"types": "../dist/zod/index.d.ts",
|
10
19
|
"author": "Eelco Wiersma <eelco@appulse.nl>",
|
11
20
|
"license": "MIT",
|