build revisions and layout updates for toast

This commit is contained in:
makearmy 2025-09-26 14:31:18 -04:00
parent b341a3675e
commit 39235193e6
1116 changed files with 130517 additions and 12 deletions

View file

@ -0,0 +1 @@
export * from './standard-schema';

View file

@ -0,0 +1,8 @@
import { StandardSchemaV1 } from '@standard-schema/spec';
import { FieldValues, Resolver } from 'react-hook-form';
export declare function standardSchemaResolver<Input extends FieldValues, Context, Output>(schema: StandardSchemaV1<Input, Output>, _schemaOptions?: never, resolverOptions?: {
raw?: false;
}): Resolver<Input, Context, Output>;
export declare function standardSchemaResolver<Input extends FieldValues, Context, Output>(schema: StandardSchemaV1<Input, Output>, _schemaOptions: never | undefined, resolverOptions: {
raw: true;
}): Resolver<Input, Context, Input>;

View file

@ -0,0 +1,2 @@
var e=require("@hookform/resolvers"),r=require("@standard-schema/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 s in t)({}).hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},t.apply(null,arguments)}exports.standardSchemaResolver=function(s,a,n){return void 0===n&&(n={}),function(a,i,o){try{var u=function(){if(l.issues){var s=function(e,s){for(var a={},n=0;n<e.length;n++){var i=e[n],o=r.getDotPath(i);if(o&&(a[o]||(a[o]={message:i.message,type:""}),s)){var u,l=a[o].types||{};a[o].types=t({},l,((u={})[Object.keys(l).length]=i.message,u))}}return a}(l.issues,!o.shouldUseNativeValidation&&"all"===o.criteriaMode);return{values:{},errors:e.toNestErrors(s,o)}}return o.shouldUseNativeValidation&&e.validateFieldsNatively({},o),{values:n.raw?Object.assign({},a):l.value,errors:{}}},l=s["~standard"].validate(a),v=function(){if(l instanceof Promise)return Promise.resolve(l).then(function(e){l=e})}();return Promise.resolve(v&&v.then?v.then(u):u())}catch(e){return Promise.reject(e)}}};
//# sourceMappingURL=standard-schema.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"standard-schema.js","sources":["../src/standard-schema.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { StandardSchemaV1 } from '@standard-schema/spec';\nimport { getDotPath } from '@standard-schema/utils';\nimport { FieldError, FieldValues, Resolver } from 'react-hook-form';\n\nfunction parseErrorSchema(\n issues: readonly StandardSchemaV1.Issue[],\n validateAllFieldCriteria: boolean,\n) {\n const errors: Record<string, FieldError> = {};\n\n for (let i = 0; i < issues.length; i++) {\n const error = issues[i];\n const path = getDotPath(error);\n\n if (path) {\n if (!errors[path]) {\n errors[path] = { message: error.message, type: '' };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[path].types || {};\n\n errors[path].types = {\n ...types,\n [Object.keys(types).length]: error.message,\n };\n }\n }\n }\n\n return errors;\n}\n\nexport function standardSchemaResolver<\n Input extends FieldValues,\n Context,\n Output,\n>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions?: {\n raw?: false;\n },\n): Resolver<Input, Context, Output>;\n\nexport function standardSchemaResolver<\n Input extends FieldValues,\n Context,\n Output,\n>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions: never | undefined,\n resolverOptions: {\n raw: true;\n },\n): Resolver<Input, Context, Input>;\n\n/**\n * Creates a resolver for react-hook-form that validates data using a Standard Schema.\n *\n * @param {Schema} schema - The Standard Schema to validate against\n * @param {Object} resolverOptions - Options for the resolver\n * @param {boolean} [resolverOptions.raw=false] - Whether to return raw input values instead of parsed values\n * @returns {Resolver} A resolver function compatible with react-hook-form\n *\n * @example\n * ```ts\n * const schema = z.object({\n * name: z.string().min(2),\n * age: z.number().min(18)\n * });\n *\n * useForm({\n * resolver: standardSchemaResolver(schema)\n * });\n * ```\n */\nexport function standardSchemaResolver<\n Input extends FieldValues,\n Context,\n Output,\n>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions: {\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Output | Input> {\n return async (values, _, options) => {\n let result = schema['~standard'].validate(values);\n if (result instanceof Promise) {\n result = await result;\n }\n\n if (result.issues) {\n const errors = parseErrorSchema(\n result.issues,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n );\n\n return {\n values: {},\n errors: toNestErrors(errors, options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result.value,\n errors: {},\n };\n };\n}\n"],"names":["schema","_schemaOptions","resolverOptions","values","_","options","_temp2","result","issues","errors","validateAllFieldCriteria","i","length","error","path","getDotPath","message","type","_extends2","types","_extends","Object","keys","parseErrorSchema","shouldUseNativeValidation","criteriaMode","toNestErrors","validateFieldsNatively","raw","assign","value","validate","_temp","Promise","resolve","then","_result","e","reject"],"mappings":"gUA8EM,SAKJA,EACAC,EACAC,GAIA,gBAJAA,IAAAA,EAEI,CAAE,GAEQC,SAAAA,EAAQC,EAAGC,GAAO,IAAIC,IAAAA,aAMlC,GAAIC,EAAOC,OAAQ,CACjB,IAAMC,EA3FZ,SACED,EACAE,GAIA,IAFA,IAAMD,EAAqC,GAElCE,EAAI,EAAGA,EAAIH,EAAOI,OAAQD,IAAK,CACtC,IAAME,EAAQL,EAAOG,GACfG,EAAOC,EAAAA,WAAWF,GAExB,GAAIC,IACGL,EAAOK,KACVL,EAAOK,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAM,KAG7CP,GAA0B,CAAAQ,IAAAA,EACtBC,EAAQV,EAAOK,GAAMK,OAAS,GAEpCV,EAAOK,GAAMK,MAAKC,KACbD,IAAKD,EAAA,CAAA,GACPG,OAAOC,KAAKH,GAAOP,QAASC,EAAMG,QAAOE,GAE9C,CAEJ,CAEA,OAAOT,CACT,CAgEqBc,CACbhB,EAAOC,QACNH,EAAQmB,2BAAsD,QAAzBnB,EAAQoB,cAGhD,MAAO,CACLtB,OAAQ,CAAA,EACRM,OAAQiB,eAAajB,EAAQJ,GAEjC,CAIA,OAFAA,EAAQmB,2BAA6BG,EAAAA,uBAAuB,CAAA,EAAItB,GAEzD,CACLF,OAAQD,EAAgB0B,IAAMP,OAAOQ,OAAO,CAAA,EAAI1B,GAAUI,EAAOuB,MACjErB,OAAQ,CAAA,EACR,EAtBEF,EAASP,EAAO,aAAa+B,SAAS5B,GAAQ6B,gBAC9CzB,aAAkB0B,QAAO,OAAAA,QAAAC,QACZ3B,GAAM4B,KAAA,SAAAC,GAArB7B,EAAM6B,CAAgB,EAAAH,IAAAA,OAAAA,QAAAC,QAAAF,GAAAA,EAAAG,KAAAH,EAAAG,KAAA7B,GAAAA,IAqB1B,CAAC,MAAA+B,GAAAJ,OAAAA,QAAAK,OAAAD,EACH,CAAA,CAAA"}

View file

@ -0,0 +1,2 @@
import{toNestErrors as e,validateFieldsNatively as r}from"@hookform/resolvers";import{getDotPath as t}from"@standard-schema/utils";function n(){return n=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)({}).hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},n.apply(null,arguments)}function s(s,a,i){return void 0===i&&(i={}),function(a,o,u){try{var l=function(){if(c.issues){var s=function(e,r){for(var s={},a=0;a<e.length;a++){var i=e[a],o=t(i);if(o&&(s[o]||(s[o]={message:i.message,type:""}),r)){var u,l=s[o].types||{};s[o].types=n({},l,((u={})[Object.keys(l).length]=i.message,u))}}return s}(c.issues,!u.shouldUseNativeValidation&&"all"===u.criteriaMode);return{values:{},errors:e(s,u)}}return u.shouldUseNativeValidation&&r({},u),{values:i.raw?Object.assign({},a):c.value,errors:{}}},c=s["~standard"].validate(a),f=function(){if(c instanceof Promise)return Promise.resolve(c).then(function(e){c=e})}();return Promise.resolve(f&&f.then?f.then(l):l())}catch(e){return Promise.reject(e)}}}export{s as standardSchemaResolver};
//# sourceMappingURL=standard-schema.module.js.map

View file

@ -0,0 +1,2 @@
import{toNestErrors as e,validateFieldsNatively as s}from"@hookform/resolvers";import{getDotPath as t}from"@standard-schema/utils";function r(){return r=Object.assign?Object.assign.bind():function(e){for(var s=1;s<arguments.length;s++){var t=arguments[s];for(var r in t)({}).hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},r.apply(null,arguments)}function a(a,n,o={}){return async(n,i,l)=>{let u=a["~standard"].validate(n);if(u instanceof Promise&&(u=await u),u.issues){const s=function(e,s){const a={};for(let n=0;n<e.length;n++){const o=e[n],i=t(o);if(i&&(a[i]||(a[i]={message:o.message,type:""}),s)){const e=a[i].types||{};a[i].types=r({},e,{[Object.keys(e).length]:o.message})}}return a}(u.issues,!l.shouldUseNativeValidation&&"all"===l.criteriaMode);return{values:{},errors:e(s,l)}}return l.shouldUseNativeValidation&&s({},l),{values:o.raw?Object.assign({},n):u.value,errors:{}}}}export{a as standardSchemaResolver};
//# sourceMappingURL=standard-schema.modern.mjs.map

View file

@ -0,0 +1 @@
{"version":3,"file":"standard-schema.modern.mjs","sources":["../src/standard-schema.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { StandardSchemaV1 } from '@standard-schema/spec';\nimport { getDotPath } from '@standard-schema/utils';\nimport { FieldError, FieldValues, Resolver } from 'react-hook-form';\n\nfunction parseErrorSchema(\n issues: readonly StandardSchemaV1.Issue[],\n validateAllFieldCriteria: boolean,\n) {\n const errors: Record<string, FieldError> = {};\n\n for (let i = 0; i < issues.length; i++) {\n const error = issues[i];\n const path = getDotPath(error);\n\n if (path) {\n if (!errors[path]) {\n errors[path] = { message: error.message, type: '' };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[path].types || {};\n\n errors[path].types = {\n ...types,\n [Object.keys(types).length]: error.message,\n };\n }\n }\n }\n\n return errors;\n}\n\nexport function standardSchemaResolver<\n Input extends FieldValues,\n Context,\n Output,\n>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions?: {\n raw?: false;\n },\n): Resolver<Input, Context, Output>;\n\nexport function standardSchemaResolver<\n Input extends FieldValues,\n Context,\n Output,\n>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions: never | undefined,\n resolverOptions: {\n raw: true;\n },\n): Resolver<Input, Context, Input>;\n\n/**\n * Creates a resolver for react-hook-form that validates data using a Standard Schema.\n *\n * @param {Schema} schema - The Standard Schema to validate against\n * @param {Object} resolverOptions - Options for the resolver\n * @param {boolean} [resolverOptions.raw=false] - Whether to return raw input values instead of parsed values\n * @returns {Resolver} A resolver function compatible with react-hook-form\n *\n * @example\n * ```ts\n * const schema = z.object({\n * name: z.string().min(2),\n * age: z.number().min(18)\n * });\n *\n * useForm({\n * resolver: standardSchemaResolver(schema)\n * });\n * ```\n */\nexport function standardSchemaResolver<\n Input extends FieldValues,\n Context,\n Output,\n>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions: {\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Output | Input> {\n return async (values, _, options) => {\n let result = schema['~standard'].validate(values);\n if (result instanceof Promise) {\n result = await result;\n }\n\n if (result.issues) {\n const errors = parseErrorSchema(\n result.issues,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n );\n\n return {\n values: {},\n errors: toNestErrors(errors, options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result.value,\n errors: {},\n };\n };\n}\n"],"names":["standardSchemaResolver","schema","_schemaOptions","resolverOptions","values","_","options","result","validate","Promise","issues","errors","validateAllFieldCriteria","i","length","error","path","getDotPath","message","type","types","_extends","Object","keys","parseErrorSchema","shouldUseNativeValidation","criteriaMode","toNestErrors","validateFieldsNatively","raw","assign","value"],"mappings":"2VA8EgB,SAAAA,EAKdC,EACAC,EACAC,EAEI,CAAE,GAEN,OAAcC,MAAAA,EAAQC,EAAGC,KACvB,IAAIC,EAASN,EAAO,aAAaO,SAASJ,GAK1C,GAJIG,aAAkBE,UACpBF,QAAeA,GAGbA,EAAOG,OAAQ,CACjB,MAAMC,EA3FZ,SACED,EACAE,GAEA,MAAMD,EAAqC,CAAA,EAE3C,IAAK,IAAIE,EAAI,EAAGA,EAAIH,EAAOI,OAAQD,IAAK,CACtC,MAAME,EAAQL,EAAOG,GACfG,EAAOC,EAAWF,GAExB,GAAIC,IACGL,EAAOK,KACVL,EAAOK,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAM,KAG7CP,GAA0B,CAC5B,MAAMQ,EAAQT,EAAOK,GAAMI,OAAS,CAAA,EAEpCT,EAAOK,GAAMI,MAAKC,KACbD,EAAK,CACR,CAACE,OAAOC,KAAKH,GAAON,QAASC,EAAMG,SAEvC,CAEJ,CAEA,OAAOP,CACT,CAgEqBa,CACbjB,EAAOG,QACNJ,EAAQmB,2BAAsD,QAAzBnB,EAAQoB,cAGhD,MAAO,CACLtB,OAAQ,CAAE,EACVO,OAAQgB,EAAahB,EAAQL,GAEjC,CAIA,OAFAA,EAAQmB,2BAA6BG,EAAuB,CAAE,EAAEtB,GAEzD,CACLF,OAAQD,EAAgB0B,IAAMP,OAAOQ,OAAO,CAAA,EAAI1B,GAAUG,EAAOwB,MACjEpB,OAAQ,IAGd"}

View file

@ -0,0 +1,2 @@
import{toNestErrors as e,validateFieldsNatively as r}from"@hookform/resolvers";import{getDotPath as t}from"@standard-schema/utils";function n(){return n=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)({}).hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},n.apply(null,arguments)}function s(s,a,i){return void 0===i&&(i={}),function(a,o,u){try{var l=function(){if(c.issues){var s=function(e,r){for(var s={},a=0;a<e.length;a++){var i=e[a],o=t(i);if(o&&(s[o]||(s[o]={message:i.message,type:""}),r)){var u,l=s[o].types||{};s[o].types=n({},l,((u={})[Object.keys(l).length]=i.message,u))}}return s}(c.issues,!u.shouldUseNativeValidation&&"all"===u.criteriaMode);return{values:{},errors:e(s,u)}}return u.shouldUseNativeValidation&&r({},u),{values:i.raw?Object.assign({},a):c.value,errors:{}}},c=s["~standard"].validate(a),f=function(){if(c instanceof Promise)return Promise.resolve(c).then(function(e){c=e})}();return Promise.resolve(f&&f.then?f.then(l):l())}catch(e){return Promise.reject(e)}}}export{s as standardSchemaResolver};
//# sourceMappingURL=standard-schema.module.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"standard-schema.module.js","sources":["../src/standard-schema.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { StandardSchemaV1 } from '@standard-schema/spec';\nimport { getDotPath } from '@standard-schema/utils';\nimport { FieldError, FieldValues, Resolver } from 'react-hook-form';\n\nfunction parseErrorSchema(\n issues: readonly StandardSchemaV1.Issue[],\n validateAllFieldCriteria: boolean,\n) {\n const errors: Record<string, FieldError> = {};\n\n for (let i = 0; i < issues.length; i++) {\n const error = issues[i];\n const path = getDotPath(error);\n\n if (path) {\n if (!errors[path]) {\n errors[path] = { message: error.message, type: '' };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[path].types || {};\n\n errors[path].types = {\n ...types,\n [Object.keys(types).length]: error.message,\n };\n }\n }\n }\n\n return errors;\n}\n\nexport function standardSchemaResolver<\n Input extends FieldValues,\n Context,\n Output,\n>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions?: {\n raw?: false;\n },\n): Resolver<Input, Context, Output>;\n\nexport function standardSchemaResolver<\n Input extends FieldValues,\n Context,\n Output,\n>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions: never | undefined,\n resolverOptions: {\n raw: true;\n },\n): Resolver<Input, Context, Input>;\n\n/**\n * Creates a resolver for react-hook-form that validates data using a Standard Schema.\n *\n * @param {Schema} schema - The Standard Schema to validate against\n * @param {Object} resolverOptions - Options for the resolver\n * @param {boolean} [resolverOptions.raw=false] - Whether to return raw input values instead of parsed values\n * @returns {Resolver} A resolver function compatible with react-hook-form\n *\n * @example\n * ```ts\n * const schema = z.object({\n * name: z.string().min(2),\n * age: z.number().min(18)\n * });\n *\n * useForm({\n * resolver: standardSchemaResolver(schema)\n * });\n * ```\n */\nexport function standardSchemaResolver<\n Input extends FieldValues,\n Context,\n Output,\n>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions: {\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Output | Input> {\n return async (values, _, options) => {\n let result = schema['~standard'].validate(values);\n if (result instanceof Promise) {\n result = await result;\n }\n\n if (result.issues) {\n const errors = parseErrorSchema(\n result.issues,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n );\n\n return {\n values: {},\n errors: toNestErrors(errors, options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result.value,\n errors: {},\n };\n };\n}\n"],"names":["standardSchemaResolver","schema","_schemaOptions","resolverOptions","values","_","options","_temp2","result","issues","errors","validateAllFieldCriteria","i","length","error","path","getDotPath","message","type","_extends2","types","_extends","Object","keys","parseErrorSchema","shouldUseNativeValidation","criteriaMode","toNestErrors","validateFieldsNatively","raw","assign","value","validate","_temp","Promise","resolve","then","_result","e","reject"],"mappings":"2VA8EM,SAAUA,EAKdC,EACAC,EACAC,GAIA,gBAJAA,IAAAA,EAEI,CAAE,GAEQC,SAAAA,EAAQC,EAAGC,GAAO,IAAIC,IAAAA,aAMlC,GAAIC,EAAOC,OAAQ,CACjB,IAAMC,EA3FZ,SACED,EACAE,GAIA,IAFA,IAAMD,EAAqC,GAElCE,EAAI,EAAGA,EAAIH,EAAOI,OAAQD,IAAK,CACtC,IAAME,EAAQL,EAAOG,GACfG,EAAOC,EAAWF,GAExB,GAAIC,IACGL,EAAOK,KACVL,EAAOK,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAM,KAG7CP,GAA0B,CAAAQ,IAAAA,EACtBC,EAAQV,EAAOK,GAAMK,OAAS,GAEpCV,EAAOK,GAAMK,MAAKC,KACbD,IAAKD,EAAA,CAAA,GACPG,OAAOC,KAAKH,GAAOP,QAASC,EAAMG,QAAOE,GAE9C,CAEJ,CAEA,OAAOT,CACT,CAgEqBc,CACbhB,EAAOC,QACNH,EAAQmB,2BAAsD,QAAzBnB,EAAQoB,cAGhD,MAAO,CACLtB,OAAQ,CAAA,EACRM,OAAQiB,EAAajB,EAAQJ,GAEjC,CAIA,OAFAA,EAAQmB,2BAA6BG,EAAuB,CAAA,EAAItB,GAEzD,CACLF,OAAQD,EAAgB0B,IAAMP,OAAOQ,OAAO,CAAA,EAAI1B,GAAUI,EAAOuB,MACjErB,OAAQ,CAAA,EACR,EAtBEF,EAASP,EAAO,aAAa+B,SAAS5B,GAAQ6B,gBAC9CzB,aAAkB0B,QAAO,OAAAA,QAAAC,QACZ3B,GAAM4B,KAAA,SAAAC,GAArB7B,EAAM6B,CAAgB,EAAAH,IAAAA,OAAAA,QAAAC,QAAAF,GAAAA,EAAAG,KAAAH,EAAAG,KAAA7B,GAAAA,IAqB1B,CAAC,MAAA+B,GAAAJ,OAAAA,QAAAK,OAAAD,EACH,CAAA,CAAA"}

View file

@ -0,0 +1,2 @@
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("@standard-schema/utils")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","@standard-schema/utils"],r):r((e||self).hookformResolversStandardSchema={},e.hookformResolvers,e.utils)}(this,function(e,r,t){function s(){return s=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var s in t)({}).hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},s.apply(null,arguments)}e.standardSchemaResolver=function(e,o,n){return void 0===n&&(n={}),function(o,a,i){try{var l=function(){if(u.issues){var e=function(e,r){for(var o={},n=0;n<e.length;n++){var a=e[n],i=t.getDotPath(a);if(i&&(o[i]||(o[i]={message:a.message,type:""}),r)){var l,u=o[i].types||{};o[i].types=s({},u,((l={})[Object.keys(u).length]=a.message,l))}}return o}(u.issues,!i.shouldUseNativeValidation&&"all"===i.criteriaMode);return{values:{},errors:r.toNestErrors(e,i)}}return i.shouldUseNativeValidation&&r.validateFieldsNatively({},i),{values:n.raw?Object.assign({},o):u.value,errors:{}}},u=e["~standard"].validate(o),f=function(){if(u instanceof Promise)return Promise.resolve(u).then(function(e){u=e})}();return Promise.resolve(f&&f.then?f.then(l):l())}catch(e){return Promise.reject(e)}}}});
//# sourceMappingURL=standard-schema.umd.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"standard-schema.umd.js","sources":["../src/standard-schema.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { StandardSchemaV1 } from '@standard-schema/spec';\nimport { getDotPath } from '@standard-schema/utils';\nimport { FieldError, FieldValues, Resolver } from 'react-hook-form';\n\nfunction parseErrorSchema(\n issues: readonly StandardSchemaV1.Issue[],\n validateAllFieldCriteria: boolean,\n) {\n const errors: Record<string, FieldError> = {};\n\n for (let i = 0; i < issues.length; i++) {\n const error = issues[i];\n const path = getDotPath(error);\n\n if (path) {\n if (!errors[path]) {\n errors[path] = { message: error.message, type: '' };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[path].types || {};\n\n errors[path].types = {\n ...types,\n [Object.keys(types).length]: error.message,\n };\n }\n }\n }\n\n return errors;\n}\n\nexport function standardSchemaResolver<\n Input extends FieldValues,\n Context,\n Output,\n>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions?: {\n raw?: false;\n },\n): Resolver<Input, Context, Output>;\n\nexport function standardSchemaResolver<\n Input extends FieldValues,\n Context,\n Output,\n>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions: never | undefined,\n resolverOptions: {\n raw: true;\n },\n): Resolver<Input, Context, Input>;\n\n/**\n * Creates a resolver for react-hook-form that validates data using a Standard Schema.\n *\n * @param {Schema} schema - The Standard Schema to validate against\n * @param {Object} resolverOptions - Options for the resolver\n * @param {boolean} [resolverOptions.raw=false] - Whether to return raw input values instead of parsed values\n * @returns {Resolver} A resolver function compatible with react-hook-form\n *\n * @example\n * ```ts\n * const schema = z.object({\n * name: z.string().min(2),\n * age: z.number().min(18)\n * });\n *\n * useForm({\n * resolver: standardSchemaResolver(schema)\n * });\n * ```\n */\nexport function standardSchemaResolver<\n Input extends FieldValues,\n Context,\n Output,\n>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions: {\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Output | Input> {\n return async (values, _, options) => {\n let result = schema['~standard'].validate(values);\n if (result instanceof Promise) {\n result = await result;\n }\n\n if (result.issues) {\n const errors = parseErrorSchema(\n result.issues,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n );\n\n return {\n values: {},\n errors: toNestErrors(errors, options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result.value,\n errors: {},\n };\n };\n}\n"],"names":["schema","_schemaOptions","resolverOptions","values","_","options","_temp2","result","issues","errors","validateAllFieldCriteria","i","length","error","path","getDotPath","message","type","_extends2","types","_extends","Object","keys","parseErrorSchema","shouldUseNativeValidation","criteriaMode","toNestErrors","validateFieldsNatively","raw","assign","value","validate","_temp","Promise","resolve","then","_result","e","reject"],"mappings":"0nBA8EM,SAKJA,EACAC,EACAC,GAIA,gBAJAA,IAAAA,EAEI,CAAE,GAEQC,SAAAA,EAAQC,EAAGC,GAAO,IAAIC,IAAAA,aAMlC,GAAIC,EAAOC,OAAQ,CACjB,IAAMC,EA3FZ,SACED,EACAE,GAIA,IAFA,IAAMD,EAAqC,GAElCE,EAAI,EAAGA,EAAIH,EAAOI,OAAQD,IAAK,CACtC,IAAME,EAAQL,EAAOG,GACfG,EAAOC,EAAAA,WAAWF,GAExB,GAAIC,IACGL,EAAOK,KACVL,EAAOK,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAM,KAG7CP,GAA0B,CAAAQ,IAAAA,EACtBC,EAAQV,EAAOK,GAAMK,OAAS,GAEpCV,EAAOK,GAAMK,MAAKC,KACbD,IAAKD,EAAA,CAAA,GACPG,OAAOC,KAAKH,GAAOP,QAASC,EAAMG,QAAOE,GAE9C,CAEJ,CAEA,OAAOT,CACT,CAgEqBc,CACbhB,EAAOC,QACNH,EAAQmB,2BAAsD,QAAzBnB,EAAQoB,cAGhD,MAAO,CACLtB,OAAQ,CAAA,EACRM,OAAQiB,eAAajB,EAAQJ,GAEjC,CAIA,OAFAA,EAAQmB,2BAA6BG,EAAAA,uBAAuB,CAAA,EAAItB,GAEzD,CACLF,OAAQD,EAAgB0B,IAAMP,OAAOQ,OAAO,CAAA,EAAI1B,GAAUI,EAAOuB,MACjErB,OAAQ,CAAA,EACR,EAtBEF,EAASP,EAAO,aAAa+B,SAAS5B,GAAQ6B,gBAC9CzB,aAAkB0B,QAAO,OAAAA,QAAAC,QACZ3B,GAAM4B,KAAA,SAAAC,GAArB7B,EAAM6B,CAAgB,EAAAH,IAAAA,OAAAA,QAAAC,QAAAF,GAAAA,EAAAG,KAAAH,EAAAG,KAAA7B,GAAAA,IAqB1B,CAAC,MAAA+B,GAAAJ,OAAAA,QAAAK,OAAAD,EACH,CAAA,CAAA"}

View file

@ -0,0 +1,19 @@
{
"name": "@hookform/resolvers/standard-schema",
"amdName": "hookformResolversStandardSchema",
"version": "1.0.0",
"private": true,
"description": "React Hook Form validation resolver: standard-schema",
"main": "dist/standard-schema.js",
"module": "dist/standard-schema.module.js",
"umd:main": "dist/standard-schema.umd.js",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"license": "MIT",
"peerDependencies": {
"react-hook-form": "^7.55.0",
"@standard-schema/spec": "^1.0.0",
"@standard-schema/utils": "^0.3.0",
"@hookform/resolvers": "^2.0.0"
}
}

View file

@ -0,0 +1,82 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { type } from 'arktype';
import React from 'react';
import { useForm } from 'react-hook-form';
import { standardSchemaResolver } from '..';
const schema = type({
username: 'string>1',
password: 'string>1',
});
type FormData = typeof schema.infer;
interface Props {
onSubmit: (data: FormData) => void;
}
function TestComponent({ onSubmit }: Props) {
const { register, handleSubmit } = useForm<FormData>({
resolver: standardSchemaResolver(schema),
shouldUseNativeValidation: true,
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} placeholder="username" />
<input {...register('password')} placeholder="password" />
<button type="submit">submit</button>
</form>
);
}
test("form's native validation with arkType", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
// username
let usernameField = screen.getByPlaceholderText(
/username/i,
) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(true);
expect(usernameField.validationMessage).toBe('');
// password
let passwordField = screen.getByPlaceholderText(
/password/i,
) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(true);
expect(passwordField.validationMessage).toBe('');
await user.click(screen.getByText(/submit/i));
// username
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(false);
expect(usernameField.validationMessage).toBe(
'username must be at least length 2',
);
// password
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(false);
expect(passwordField.validationMessage).toBe(
'password must be at least length 2',
);
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
await user.type(screen.getByPlaceholderText(/password/i), 'password');
// username
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(true);
expect(usernameField.validationMessage).toBe('');
// password
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(true);
expect(passwordField.validationMessage).toBe('');
});

View file

@ -0,0 +1,54 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { type } from 'arktype';
import React from 'react';
import { useForm } from 'react-hook-form';
import { standardSchemaResolver } from '..';
const schema = type({
username: 'string>1',
password: 'string>1',
});
function TestComponent({
onSubmit,
}: {
onSubmit: (data: typeof schema.infer) => void;
}) {
const {
register,
handleSubmit,
formState: { errors },
} = useForm({
resolver: standardSchemaResolver(schema), // Useful to check TypeScript regressions
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} />
{errors.username && <span role="alert">{errors.username.message}</span>}
<input {...register('password')} />
{errors.password && <span role="alert">{errors.password.message}</span>}
<button type="submit">submit</button>
</form>
);
}
test("form's validation with arkType and TypeScript's integration", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
expect(screen.queryAllByRole('alert')).toHaveLength(0);
await user.click(screen.getByText(/submit/i));
expect(
screen.getByText('username must be at least length 2'),
).toBeInTheDocument();
expect(
screen.getByText('password must be at least length 2'),
).toBeInTheDocument();
expect(handleSubmit).not.toHaveBeenCalled();
});

View file

@ -0,0 +1,111 @@
import { StandardSchemaV1 } from '@standard-schema/spec';
import { Field, InternalFieldName } from 'react-hook-form';
import { z } from 'zod/v3';
export const schema = z
.object({
username: z.string().regex(/^\w+$/).min(3).max(30),
password: z
.string()
.regex(new RegExp('.*[A-Z].*'), 'One uppercase character')
.regex(new RegExp('.*[a-z].*'), 'One lowercase character')
.regex(new RegExp('.*\\d.*'), 'One number')
.regex(
new RegExp('.*[`~<>?,./!@#$%^&*()\\-_+="\'|{}\\[\\];:\\\\].*'),
'One special character',
)
.min(8, 'Must be at least 8 characters in length'),
repeatPassword: z.string(),
accessToken: z.union([z.string(), z.number()]),
birthYear: z.number().min(1900).max(2013).optional(),
email: z.string().email().optional(),
tags: z.array(z.string()),
enabled: z.boolean(),
url: z.string().url('Custom error url').or(z.literal('')),
like: z
.array(
z.object({
id: z.number(),
name: z.string().length(4),
}),
)
.optional(),
dateStr: z
.string()
.transform((value) => new Date(value))
.refine((value) => !isNaN(value.getTime()), {
message: 'Invalid date',
}),
})
.refine((obj) => obj.password === obj.repeatPassword, {
message: 'Passwords do not match',
path: ['confirm'],
});
export const validData = {
username: 'Doe',
password: 'Password123_',
repeatPassword: 'Password123_',
birthYear: 2000,
email: 'john@doe.com',
tags: ['tag1', 'tag2'],
enabled: true,
accessToken: 'accessToken',
url: 'https://react-hook-form.com/',
like: [
{
id: 1,
name: 'name',
},
],
dateStr: '2020-01-01T00:00:00.000Z',
} satisfies z.input<typeof schema>;
export const invalidData = {
password: '___',
email: '',
birthYear: 'birthYear',
like: [{ id: 'z' }],
url: 'abc',
} as unknown as z.input<typeof schema>;
export const fields: Record<InternalFieldName, Field['_f']> = {
username: {
ref: { name: 'username' },
name: 'username',
},
password: {
ref: { name: 'password' },
name: 'password',
},
email: {
ref: { name: 'email' },
name: 'email',
},
birthday: {
ref: { name: 'birthday' },
name: 'birthday',
},
};
export const customSchema: StandardSchemaV1<
StandardSchemaV1.InferInput<typeof schema>,
StandardSchemaV1.InferOutput<typeof schema>
> = {
'~standard': {
version: 1,
vendor: 'custom',
validate: () => ({
issues: [
{
path: [{ key: 'username' }],
message: 'Custom error',
},
{
path: [{ key: 'like' }, { key: 0 }, { key: 'id' }],
message: 'Custom error',
},
],
}),
},
};

View file

@ -0,0 +1,274 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`standardSchemaResolver > should correctly handle path segments that are objects 1`] = `
{
"errors": {
"like": [
{
"id": {
"message": "Custom error",
"ref": undefined,
"type": "",
},
},
],
"username": {
"message": "Custom error",
"ref": {
"name": "username",
},
"type": "",
},
},
"values": {},
}
`;
exports[`standardSchemaResolver > should return a single error from standardSchemaResolver when validation fails 1`] = `
{
"errors": {
"accessToken": {
"message": "Invalid input",
"ref": undefined,
"type": "",
},
"birthYear": {
"message": "Expected number, received string",
"ref": undefined,
"type": "",
},
"dateStr": {
"message": "Required",
"ref": undefined,
"type": "",
},
"email": {
"message": "Invalid email",
"ref": {
"name": "email",
},
"type": "",
},
"enabled": {
"message": "Required",
"ref": undefined,
"type": "",
},
"like": [
{
"id": {
"message": "Expected number, received string",
"ref": undefined,
"type": "",
},
"name": {
"message": "Required",
"ref": undefined,
"type": "",
},
},
],
"password": {
"message": "One uppercase character",
"ref": {
"name": "password",
},
"type": "",
},
"repeatPassword": {
"message": "Required",
"ref": undefined,
"type": "",
},
"tags": {
"message": "Required",
"ref": undefined,
"type": "",
},
"url": {
"message": "Custom error url",
"ref": undefined,
"type": "",
},
"username": {
"message": "Required",
"ref": {
"name": "username",
},
"type": "",
},
},
"values": {},
}
`;
exports[`standardSchemaResolver > should return all the errors from standardSchemaResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
{
"errors": {
"accessToken": {
"message": "Invalid input",
"ref": undefined,
"type": "",
"types": {
"0": "Invalid input",
},
},
"birthYear": {
"message": "Expected number, received string",
"ref": undefined,
"type": "",
"types": {
"0": "Expected number, received string",
},
},
"dateStr": {
"message": "Required",
"ref": undefined,
"type": "",
"types": {
"0": "Required",
},
},
"email": {
"message": "Invalid email",
"ref": {
"name": "email",
},
"type": "",
"types": {
"0": "Invalid email",
},
},
"enabled": {
"message": "Required",
"ref": undefined,
"type": "",
"types": {
"0": "Required",
},
},
"like": [
{
"id": {
"message": "Expected number, received string",
"ref": undefined,
"type": "",
"types": {
"0": "Expected number, received string",
},
},
"name": {
"message": "Required",
"ref": undefined,
"type": "",
"types": {
"0": "Required",
},
},
},
],
"password": {
"message": "One uppercase character",
"ref": {
"name": "password",
},
"type": "",
"types": {
"0": "One uppercase character",
"1": "One lowercase character",
"2": "One number",
"3": "Must be at least 8 characters in length",
},
},
"repeatPassword": {
"message": "Required",
"ref": undefined,
"type": "",
"types": {
"0": "Required",
},
},
"tags": {
"message": "Required",
"ref": undefined,
"type": "",
"types": {
"0": "Required",
},
},
"url": {
"message": "Custom error url",
"ref": undefined,
"type": "",
"types": {
"0": "Custom error url",
},
},
"username": {
"message": "Required",
"ref": {
"name": "username",
},
"type": "",
"types": {
"0": "Required",
},
},
},
"values": {},
}
`;
exports[`standardSchemaResolver > should return values from standardSchemaResolver when validation pass & raw=true 1`] = `
{
"errors": {},
"values": {
"accessToken": "accessToken",
"birthYear": 2000,
"dateStr": "2020-01-01T00:00:00.000Z",
"email": "john@doe.com",
"enabled": true,
"like": [
{
"id": 1,
"name": "name",
},
],
"password": "Password123_",
"repeatPassword": "Password123_",
"tags": [
"tag1",
"tag2",
],
"url": "https://react-hook-form.com/",
"username": "Doe",
},
}
`;
exports[`standardSchemaResolver > should return values from standardSchemaResolver when validation pass 1`] = `
{
"errors": {},
"values": {
"accessToken": "accessToken",
"birthYear": 2000,
"dateStr": 2020-01-01T00:00:00.000Z,
"email": "john@doe.com",
"enabled": true,
"like": [
{
"id": 1,
"name": "name",
},
],
"password": "Password123_",
"repeatPassword": "Password123_",
"tags": [
"tag1",
"tag2",
],
"url": "https://react-hook-form.com/",
"username": "Doe",
},
}
`;

View file

@ -0,0 +1,151 @@
import { Resolver, SubmitHandler, useForm } from 'react-hook-form';
import { z } from 'zod/v3';
import { standardSchemaResolver } from '..';
import {
customSchema,
fields,
invalidData,
schema,
validData,
} from './__fixtures__/data';
const shouldUseNativeValidation = false;
describe('standardSchemaResolver', () => {
it('should return values from standardSchemaResolver when validation pass', async () => {
const result = await standardSchemaResolver(schema)(validData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(result).toMatchSnapshot();
});
it('should return a single error from standardSchemaResolver when validation fails', async () => {
const result = await standardSchemaResolver(schema)(
invalidData,
undefined,
{
fields,
shouldUseNativeValidation,
},
);
expect(result).toMatchSnapshot();
});
it('should return all the errors from standardSchemaResolver when validation fails with `validateAllFieldCriteria` set to true', async () => {
const result = await standardSchemaResolver(schema)(
invalidData,
undefined,
{
fields,
criteriaMode: 'all',
shouldUseNativeValidation,
},
);
expect(result).toMatchSnapshot();
});
it('should return values from standardSchemaResolver when validation pass & raw=true', async () => {
const validateSpy = vi.spyOn(schema['~standard'], 'validate');
const result = await standardSchemaResolver(schema, undefined, {
raw: true,
})(validData, undefined, {
fields,
shouldUseNativeValidation,
});
expect(validateSpy).toHaveBeenCalledTimes(1);
expect(result).toMatchSnapshot();
});
it('should correctly handle path segments that are objects', async () => {
const result = await standardSchemaResolver(customSchema)(
validData,
undefined,
{
fields,
shouldUseNativeValidation,
},
);
expect(result).toMatchSnapshot();
});
/**
* Type inference tests
*/
it('should correctly infer the output type from a standardSchema schema', () => {
const resolver = standardSchemaResolver(z.object({ id: z.number() }));
expectTypeOf(resolver).toEqualTypeOf<
Resolver<{ id: number }, unknown, { id: number }>
>();
});
it('should correctly infer the output type from a standardSchema schema using a transform', () => {
const resolver = standardSchemaResolver(
z.object({ id: z.number().transform((val) => String(val)) }),
);
expectTypeOf(resolver).toEqualTypeOf<
Resolver<{ id: number }, unknown, { id: string }>
>();
});
it('should correctly infer the output type from a standardSchema schema when a different input type is specified', () => {
const schema = z.object({ id: z.number() }).transform(({ id }) => {
return { id: String(id) };
});
const resolver = standardSchemaResolver<
{ id: number },
any,
z.output<typeof schema>
>(schema);
expectTypeOf(resolver).toEqualTypeOf<
Resolver<{ id: number }, any, { id: string }>
>();
});
it('should correctly infer the output type from a standardSchema schema for the handleSubmit function in useForm', () => {
const schema = z.object({ id: z.number() });
const form = useForm({
resolver: standardSchemaResolver(schema),
defaultValues: {
id: 3,
},
});
expectTypeOf(form.watch('id')).toEqualTypeOf<number>();
expectTypeOf(form.handleSubmit).parameter(0).toEqualTypeOf<
SubmitHandler<{
id: number;
}>
>();
});
it('should correctly infer the output type from a standardSchema schema with a transform for the handleSubmit function in useForm', () => {
const schema = z.object({ id: z.number().transform((val) => String(val)) });
const form = useForm({
resolver: standardSchemaResolver(schema),
defaultValues: {
id: 3,
},
});
expectTypeOf(form.watch('id')).toEqualTypeOf<number>();
expectTypeOf(form.handleSubmit).parameter(0).toEqualTypeOf<
SubmitHandler<{
id: string;
}>
>();
});
});

View file

@ -0,0 +1 @@
export * from './standard-schema';

View file

@ -0,0 +1,115 @@
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import { StandardSchemaV1 } from '@standard-schema/spec';
import { getDotPath } from '@standard-schema/utils';
import { FieldError, FieldValues, Resolver } from 'react-hook-form';
function parseErrorSchema(
issues: readonly StandardSchemaV1.Issue[],
validateAllFieldCriteria: boolean,
) {
const errors: Record<string, FieldError> = {};
for (let i = 0; i < issues.length; i++) {
const error = issues[i];
const path = getDotPath(error);
if (path) {
if (!errors[path]) {
errors[path] = { message: error.message, type: '' };
}
if (validateAllFieldCriteria) {
const types = errors[path].types || {};
errors[path].types = {
...types,
[Object.keys(types).length]: error.message,
};
}
}
}
return errors;
}
export function standardSchemaResolver<
Input extends FieldValues,
Context,
Output,
>(
schema: StandardSchemaV1<Input, Output>,
_schemaOptions?: never,
resolverOptions?: {
raw?: false;
},
): Resolver<Input, Context, Output>;
export function standardSchemaResolver<
Input extends FieldValues,
Context,
Output,
>(
schema: StandardSchemaV1<Input, Output>,
_schemaOptions: never | undefined,
resolverOptions: {
raw: true;
},
): Resolver<Input, Context, Input>;
/**
* Creates a resolver for react-hook-form that validates data using a Standard Schema.
*
* @param {Schema} schema - The Standard Schema to validate against
* @param {Object} resolverOptions - Options for the resolver
* @param {boolean} [resolverOptions.raw=false] - Whether to return raw input values instead of parsed values
* @returns {Resolver} A resolver function compatible with react-hook-form
*
* @example
* ```ts
* const schema = z.object({
* name: z.string().min(2),
* age: z.number().min(18)
* });
*
* useForm({
* resolver: standardSchemaResolver(schema)
* });
* ```
*/
export function standardSchemaResolver<
Input extends FieldValues,
Context,
Output,
>(
schema: StandardSchemaV1<Input, Output>,
_schemaOptions?: never,
resolverOptions: {
raw?: boolean;
} = {},
): Resolver<Input, Context, Output | Input> {
return async (values, _, options) => {
let result = schema['~standard'].validate(values);
if (result instanceof Promise) {
result = await result;
}
if (result.issues) {
const errors = parseErrorSchema(
result.issues,
!options.shouldUseNativeValidation && options.criteriaMode === 'all',
);
return {
values: {},
errors: toNestErrors(errors, options),
};
}
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
return {
values: resolverOptions.raw ? Object.assign({}, values) : result.value,
errors: {},
};
};
}