@jfdevelops/react-multi-step-form 1.0.0-alpha.3 → 1.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,14 +1,18 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("react/jsx-runtime"),N=require("react");function ve(o,...e){return()=>String.raw({raw:o},...e)}function h(o,e,t=Error){if(!o){const r=typeof e=="function"?e():ve`${e}`();throw new t(r)}}const I="MultiStepFormSchema";class ae{debug;prefix=I;includeTimestamp=!1;throwOnError=!1;constructor(e){if(this.debug=e?.debug??!1,this.debug&&e?.debug){const{includeTimestamp:t=!1,prefix:r=I,throwOnError:s=!1}=e;this.includeTimestamp=t,this.prefix=typeof r=="string"?r:r(I),this.throwOnError=s}}wrapValue(e,t){if(e==="[]")return`[${t}]`;if(e==="{}")return`{${t}}`;if(e==="none")return t;throw new Error(`The first argument ${e} is not valid. Valid options include: "[]", "{}", and "none"`)}formatPrefix(e){if(!e)return this.prefix;const{action:t,value:r,wrapWith:s}=e;if(t==="replace")return this.wrapValue(s??"[]",r);const{delimiter:n}=e;return t==="append"?`${this.wrapValue(s?.originalPrefix??"[]",this.prefix)}${n}${this.wrapValue(s?.addedPrefix??"[]",r)}`.trim():t==="prepend"?`${this.wrapValue(s?.addedPrefix??"[]",r)}${n}${this.wrapValue(s?.originalPrefix??"[]",this.prefix)}`.trim():this.prefix}formatMessage(e,t,r){const{includeTimestamp:s=this.includeTimestamp,prefix:n,logLevelOptions:i}=r??{},p=this.formatPrefix(n),y=this.wrapValue(i?.wrapWith??"[]",(i?.level??e).toUpperCase()),f=`${p} ${y} ${t}`;return s?`[${new Date().toISOString()}] ${f}`:f}info(e,t){this.debug&&console.info(this.formatMessage("info",e,t))}warn(e,t){this.debug&&console.warn(this.formatMessage("warn",e,t))}error(e,t){if(!this.debug)return;const r=this.formatMessage("error",e,t);if(console.error(r),t?.throw??this.throwOnError)throw new Error(r)}}const B='"window" in undefined. No storage is available',W="MultiStepForm";class ue{key;store;data;log;isWindowUndefined;constructor(e){const{key:t,data:r,store:s}=e;this.log=new ae({prefix:W}),this.key=t,this.data=r,s?(this.store=s,this.isWindowUndefined=!1):typeof window<"u"?(this.store=window.localStorage,this.isWindowUndefined=!1):(this.isWindowUndefined=!0,this.log.warn(B))}throwOnEmptyStore(){h(this.store,()=>this.isWindowUndefined?B:"No storage available")}resolveValue(e){if(typeof e=="object")return e;if(typeof e=="function")return e(this.data);this.log.error(`The updater value must be a function or object. Was a ${typeof e}`,{throw:!0})}hasKey(){return this.store.getItem(this.key)!==null}get(){this.throwOnEmptyStore();const e=this.store.getItem(this.key);if(e)return JSON.parse(e)}remove(){this.throwOnEmptyStore(),this.store.removeItem(this.key)}add(e){this.throwOnEmptyStore();const t=JSON.stringify(this.resolveValue(e));this.store.setItem(this.key,t)}}const _e=["sentence","title","camel","lower","upper","pascal","snake","screaming-snake","flat","kebab"],K="title";function we(o,e){const t=o.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[-_]+/g," ").trim().split(/\s+/).map(r=>r.toLowerCase());switch(e){case"sentence":return t[0].charAt(0).toUpperCase()+t[0].slice(1)+(t.length>1?" "+t.slice(1).join(" "):"");case"title":return t.map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ");case"camel":return t[0]+t.slice(1).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join("");case"pascal":return t.map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join("");case"lower":return t.join(" ");case"upper":return t.join(" ").toUpperCase();case"snake":return t.join("_");case"screaming-snake":return t.join("_").toUpperCase();case"kebab":return t.join("-");case"flat":return t.join("");default:return o}}function U(o){return typeof o!="string"?!1:_e.includes(o)}function ce(o,e=K){return U(o)?o:e}const Oe=["string","string.phone","string.email","string.time","number","number.counter","date","dateTime","boolean.switch"],z="string";function Te(o){return typeof o=="string"&&Oe.includes(o)}function le(o,e){const t=o["~standard"].validate(e);if(t instanceof Promise)throw new TypeError("Schema validation must be synchronous",{cause:o});if(t.issues)throw new Error(JSON.stringify(t.issues,null,2));return t.value}class fe{listeners=new Set;constructor(){this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}}function q(o,e,t){const r=[],s=new Set(o),n=t?t.format(o.map(i=>`${i}`)):`[${o.join(", ")}]`;for(let i=0;i<e.length;i++){const p=e[i];s.has(p)||r.push(`Extra element at index ${i}: "${p}" is not in ${n}`)}return e.some(i=>s.has(i))||r.push(`Array must contain at least one valid element from ${n}`),r.length>0?{status:"error",errors:r}:{status:"success"}}function J(o){return o.map((e,t)=>`❌ ${t+1}. ${e}`).join(`
2
- `)}function V(o){h(o.includes("step"),"Can't extract a valid step number since");const e=o.replace("step","");return h(/^\d+$/.test(e),`Invalid step format: "${o}"`),Number.parseInt(e,10)}function F(o){return function(e){const{step:t}=e,r=`step${t}`,s=o[r];return{step:t,data:s}}}function Y(o,e){return e.reduce((t,r)=>{const s=V(r),{data:n}=F(o)({step:s});for(const[i,p]of Object.entries(n))typeof p=="function"&&i!=="update"||(n[i]=p);return t[r]=n,t},{})}function A(o,e){const t=new Intl.ListFormat("en",{style:"long",type:"disjunction"}),r=Object.keys(o),s=()=>`"stepData" must be set to an array of available steps (${t.format(r)})`;if(e==="all"){let n={};for(const i of r)n={...n,[i]:F(o)({step:V(i)})};return Object.fromEntries(r.map(i=>[i,F(o)({step:V(i)})]))}if(Array.isArray(e))return h(e.every(n=>r.includes(n)),()=>{const n=q(e,r.map(i=>V(i)),t);return n.status==="error"?`${s()}. See errors:
3
- ${J(n.errors)}`:s()}),Y(o,e);if(typeof e=="object"){const n=Object.keys(e);return h(n.every(i=>r.includes(i)),()=>{const i=q(n,r,t);return i.status==="error"?`${s()}. See errors:
4
- ${J(i.errors)}`:s()}),Y(o,n)}throw new Error(`${s()} OR to "all"`)}function Z(o,e){return typeof o=="function"?o(e):o}const Ee=["string","number","array.string","array.string.untyped"],pe=/^step\d+$/i;function Q(o,e){if(typeof o!="object"||o===null)return!1;for(const t of Object.keys(e)){if(!(t in o))return!1;const r=e[t],s=o[t];if(!r(s))return!1}return!0}function X(o,e,t){return o??we(e,t)}function $e(o){const e={},{fields:t,defaultCasing:r,validateFields:s}=o;for(const[n,i]of Object.entries(t)){h(typeof n=="string",`Each key for the "fields" option must be a string. Key ${n} was a ${typeof n}`),h(typeof i=="object",`The value for key ${n} must be an object. Was ${typeof i}`);const{defaultValue:p,label:y,nameTransformCasing:f,type:d=z}=i;if(s)e[n]=p;else{const u=f??r;e[n]={...e[n],nameTransformCasing:u,type:d,defaultValue:p,label:X(y,n,u)}}}if(s){const n=le(s,e);h(typeof n=="object",`The result of the validated fields must be an object, was (${typeof n}). This is probably an internal error, so open up an issue about it`),h(!!n,"The result of the validated fields must be defined. This is probably an internal error, so open up an issue about it");for(const[i,p]of Object.entries(n)){const y=t[i];h(y,`No field found in the fields config for "${i}"`);const{label:f,type:d=z,nameTransformCasing:u}=y,l=u??r;e[i]={...e[i],nameTransformCasing:l,type:d,defaultValue:p,label:X(f,i,l)}}}return e}function de(o){const e={};h(!!o,"The steps config must be defined",TypeError),h(typeof o=="object",`The steps config must be an object, was (${typeof o})`,TypeError);for(const[t,r]of Object.entries(o)){h(typeof t=="string",`Each key for the step config must be a string. Key "${t}" was ${typeof t} `,TypeError),h(pe.test(t),`The key "${t}" isn't formatted properly. Each key in the step config must be the following format: "step{number}"`);const s=t,{fields:n,title:i,nameTransformCasing:p=K,description:y,validateFields:f}=r,d=s.toString().replace("step","");h(n,`Missing fields for step ${d} (${String(s)})`,TypeError),h(typeof n=="object","Fields must be an object",TypeError),h(Object.keys(n).length>0,`The fields config for step ${d} (${String(s)}) is empty. Please add a field`),h(typeof n=="object",`The "fields" property must be an object. Was ${typeof n}`);const u=$e({defaultCasing:p,fields:n,validateFields:f});e[s]={...e[s],title:i,nameTransformCasing:p,...typeof y=="string"?{description:y}:{},fields:u}}return e}class G extends fe{original;value;steps;defaultNameTransformationCasing;firstStep;lastStep;stepNumbers;storage;constructor(e){super();const{steps:t,nameTransformCasing:r,storage:s}=e;this.defaultNameTransformationCasing=ce(r),this.original=t,this.value=this.enrichValues(de(this.original)),this.stepNumbers=Object.keys(this.value).map(n=>Number.parseInt(n.replace("step",""))),this.storage=new ue({data:this.value,key:s?.key??W,store:s?.store}),this.firstStep=this.first(),this.lastStep=this.last(),this.steps={first:this.firstStep.step,last:this.lastStep.step,value:this.stepNumbers,as:n=>{if(h(typeof n=="string",`The type of the target transformation type must be a string, was ${typeof n}`),n==="string")return this.stepNumbers.map(i=>`'${i}'`).join(" | ");if(n==="number")return this.stepNumbers.join(" | ");if(n.includes("array.string"))return this.stepNumbers.map(i=>`${i}`);throw new Error(`Transformation type "${n}" is not supported. Available transformations include: ${Ee.map(i=>`"${i}"`).join(", ")}`)},isValidStepNumber:n=>this.stepNumbers.includes(n),isValidStepKey:n=>Object.keys(this.value).includes(n)}}getSnapshot(){return this}notify(){for(const e of this.listeners)e({defaultNameTransformationCasing:this.defaultNameTransformationCasing,original:this.original,steps:this.steps,value:this.value})}enrichValues(e,t){for(const[r,s]of Object.entries(e)){const n=Number.parseInt(r.replace("step",""));e={...e,[r]:{...s,update:this.createStepUpdaterFn(n),createHelperFn:this.createStepHelperFn(n),...t?.(n)}}}return e}get(e){return F(this.value)(e)}first(){const e=Math.min(...this.stepNumbers);return this.get({step:e})}last(){const e=Math.max(...this.stepNumbers);return this.get({step:e})}handlePostUpdate(){this.storage.add(this.value),this.notify()}createStepUpdaterFnImpl(e,t,r){const s=this.stepNumbers;h(typeof e=="number",`Type of step must be a number, was ${typeof e}`,TypeError),h(s.includes(e),`The target step ${e} is not valid. Valid steps include "${s.join(", ")}"`);const n=`step${e}`;if(typeof t=="string"){h(this.value[n],`No data found for step ${e}`),h(typeof this.value[n]=="object",`The values for step ${e} is not an object, was ${typeof this.value[n]}`),h(t in this.value[n],`The field ${t} is not a valid field. Valid fields include ${Object.keys(this.value[n]).join(", ")}`),this.value={...this.value,[n]:{...this.value[n],[t]:Z(r,this.value[n][t])}},this.handlePostUpdate();return}if(typeof t=="object"||typeof t=="function"){const i=Z(t,this.value[n]);h(typeof i=="object",`The updated data must be an object, was ${typeof i}`),this.value={...this.value,[n]:{...this.value[n],...i}},this.handlePostUpdate();return}throw new TypeError(`The second parameter must be one of the following: a specific field to update (string), an object with the updated data, or a function that returns the updated data. It was ${typeof t}`,{cause:t})}createStepUpdaterFn(e){return(t,r)=>{this.createStepUpdaterFnImpl(e,t,r)}}update(e,t,r){this.createStepUpdaterFnImpl(e,t,r)}createStepHelperFnImpl(e){return(t,r)=>{const s=A(this.value,e);if(typeof t=="function")return()=>t({ctx:s});if(typeof t=="object")return n=>"validator"in t?(h(typeof n=="object","An input is expected since you provided a validator"),le(t.validator,n.data),r({ctx:s,...n})):r({ctx:s});throw new Error(`The first argument must be a function or an object, (was ${typeof t})`)}}createStepHelperFn(e){return this.createStepHelperFnImpl([`step${e}`])}createHelperFn(e,t){const{stepData:r,...s}=e;return this.createStepHelperFnImpl(r)(s,t)}static hasData(e,t){return e===null||typeof e!="object"?!1:Q(e,{title:r=>typeof r=="string",fields:r=>{if(r===null||typeof r!="object")return!1;for(const s of Object.keys(r)){if(typeof s!="string"||!(s in r))return!1;const n=r[s];if(n===null||typeof n!="object"||!Q(n,{defaultValue:i=>i!=="undefined"&&i!==null,label:i=>typeof i=="string"||typeof i=="boolean"&&!i,nameTransformCasing:U,type:Te}))return!1}return!0},createHelperFn:r=>typeof r=="function",update:r=>typeof r=="function",nameTransformCasing:U,...t?.optionalKeysToCheck})}}class Ce extends fe{defaultNameTransformationCasing;stepSchema;storage;mountCount=0;constructor(e){super();const{steps:t,nameTransformCasing:r,storage:s}=e;this.defaultNameTransformationCasing=ce(r),this.stepSchema=new G({steps:t,nameTransformCasing:this.defaultNameTransformationCasing}),this.storage=new ue({key:s?.key??W,data:this.stepSchema.value,store:s?.store}),this.stepSchema.subscribe(()=>{this.notify()})}getSnapshot(){return this}mount(){return this.mountCount++,this.mountCount===1&&this.onMount(),()=>{this.unmount()}}unmount(){this.mountCount=Math.max(0,this.mountCount-1),this.mountCount===0&&this.onUnmount()}isMounted(){return this.mountCount>0}onMount(){}onUnmount(){}notify(){for(const e of this.listeners)e({nameTransformCasing:this.defaultNameTransformationCasing,storage:{key:this.storage.key,store:this.storage.store},steps:this.stepSchema.original})}}function je(o){function e(t){const{children:r,name:s}=t;return r(o(s))}return e}var $;(o=>{o.DEFAULT_FORM_ALIAS="Form";function e(r,s){if(Array.isArray(r)){if(s==="all")return!0;if(typeof s=="object"&&!Array.isArray(s))return Object.keys(s).some(n=>r.includes(n));if(Array.isArray(s))return s.some(n=>r.includes(n))}return!1}o.isFormAvailable=e;function t(r){return s=>R.jsx("form",{id:r,...s})}o.createDefaultForm=t})($||($={}));exports.StepSpecificComponent=void 0;(o=>{o.DEFAULT_FORM_INSTANCE_ALIAS="form"})(exports.StepSpecificComponent||(exports.StepSpecificComponent={}));function he(o,e){h(e in o,`The target step ${e} is not a valid step key`);const t=o[e];h("fields"in t,`No "fields" were found for ${e}`);let r={};for(const[s,n]of Object.entries(t.fields))r={...r,[s]:n.defaultValue};return r}class me extends G{value;constructor(e){const{form:t,...r}=e;super(r),this.value=this.enrichValues(de(this.original)),this.value=this.enrichValues(this.value,s=>{const n=`step${s}`,i=t?.id??n;return{createComponent:this.createComponentForStep([`step${s}`],{isStepSpecific:!0,defaultId:i,form:t})}})}createFormComponent(e,t){const{render:r,enabledForSteps:s="all",id:n=t}=e,i={id:n,steps:A(this.value,s)};return p=>r(i,p)}createStepSpecificComponentImpl(e,t,r,s={}){return n=>(i=>{const p={};for(const[u,l]of Object.entries(s))if(typeof l=="function")try{const a=l();p[u]=a,typeof console<"u"&&console.debug&&console.debug(`[multi-step-form] Hook "${u}" called successfully`,{result:a!==void 0?"defined":"undefined"})}catch(a){const c=a instanceof Error?a.message:String(a);throw new Error(`[multi-step-form] Error calling hook "${u}" in useFormInstance.render: ${c}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("react/jsx-runtime"),P=require("react");function we(o,...e){return()=>String.raw({raw:o},...e)}function O(o,e,t=Error){if(!o){const r=typeof e=="function"?e():we`${e}`();throw new t(r)}}const G="MultiStepFormSchema";class he{debug;prefix=G;includeTimestamp=!1;throwOnError=!1;constructor(e){if(this.debug=e?.debug??!1,this.debug&&e?.debug){const{includeTimestamp:t=!1,prefix:r=G,throwOnError:n=!1}=e;this.includeTimestamp=t,this.prefix=typeof r=="string"?r:r(G),this.throwOnError=n}}wrapValue(e,t){if(e==="[]")return`[${t}]`;if(e==="{}")return`{${t}}`;if(e==="none")return t;throw new Error(`The first argument ${e} is not valid. Valid options include: "[]", "{}", and "none"`)}formatPrefix(e){if(!e)return this.prefix;const{action:t,value:r,wrapWith:n}=e;if(t==="replace")return this.wrapValue(n??"[]",r);const{delimiter:s}=e;return t==="append"?`${this.wrapValue(n?.originalPrefix??"[]",this.prefix)}${s}${this.wrapValue(n?.addedPrefix??"[]",r)}`.trim():t==="prepend"?`${this.wrapValue(n?.addedPrefix??"[]",r)}${s}${this.wrapValue(n?.originalPrefix??"[]",this.prefix)}`.trim():this.prefix}formatMessage(e,t,r){const{includeTimestamp:n=this.includeTimestamp,prefix:s,logLevelOptions:a}=r??{},y=this.formatPrefix(s),b=this.wrapValue(a?.wrapWith??"[]",(a?.level??e).toUpperCase()),f=`${y} ${b} ${t}`;return n?`[${new Date().toISOString()}] ${f}`:f}info(e,t){this.debug&&console.info(this.formatMessage("info",e,t))}warn(e,t){this.debug&&console.warn(this.formatMessage("warn",e,t))}error(e,t){if(!this.debug)return;const r=this.formatMessage("error",e,t);if(console.error(r),t?.throw??this.throwOnError)throw new Error(r)}}const te='"window" in undefined. No storage is available',Q="MultiStepForm";class me{key;store;data;log;isWindowUndefined;constructor(e){const{key:t,data:r,store:n}=e;this.log=new he({prefix:Q}),this.key=t,this.data=r,n?(this.store=n,this.isWindowUndefined=!1):typeof window<"u"?(this.store=window.localStorage,this.isWindowUndefined=!1):(this.isWindowUndefined=!0,this.log.warn(te))}throwOnEmptyStore(){O(this.store,()=>this.isWindowUndefined?te:"No storage available")}resolveValue(e){if(typeof e=="object")return e;if(typeof e=="function")return e(this.data);this.log.error(`The updater value must be a function or object. Was a ${typeof e}`,{throw:!0})}hasKey(){return this.store.getItem(this.key)!==null}get(){this.throwOnEmptyStore();const e=this.store.getItem(this.key);if(e)return JSON.parse(e)}remove(){this.throwOnEmptyStore(),this.store.removeItem(this.key)}add(e){this.throwOnEmptyStore();const t=JSON.stringify(this.resolveValue(e));this.store.setItem(this.key,t)}}const Te=["sentence","title","camel","lower","upper","pascal","snake","screaming-snake","flat","kebab"],X="title";function Ae(o,e){const t=o.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[-_]+/g," ").trim().split(/\s+/).map(r=>r.toLowerCase());switch(e){case"sentence":return t[0].charAt(0).toUpperCase()+t[0].slice(1)+(t.length>1?" "+t.slice(1).join(" "):"");case"title":return t.map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ");case"camel":return t[0]+t.slice(1).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join("");case"pascal":return t.map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join("");case"lower":return t.join(" ");case"upper":return t.join(" ").toUpperCase();case"snake":return t.join("_");case"screaming-snake":return t.join("_").toUpperCase();case"kebab":return t.join("-");case"flat":return t.join("");default:return o}}function Y(o){return typeof o!="string"?!1:Te.includes(o)}function ye(o,e=X){return Y(o)?o:e}const Ce=["string","string.phone","string.email","string.time","number","number.counter","date","dateTime","boolean.switch"],re="string";function xe(o){return typeof o=="string"&&Ce.includes(o)}function U(o,e,t){const r=[],n=new Set(o),s=t?t.format(o.map(a=>`${a}`)):`[${o.join(", ")}]`;for(let a=0;a<e.length;a++){const y=e[a];n.has(y)||r.push(`Extra element at index ${a}: "${y}" is not in ${s}`)}return e.some(a=>n.has(a))||r.push(`Array must contain at least one valid element from ${s}`),r.length>0?{status:"error",errors:r}:{status:"success"}}function R(o,e){const t=(r,n)=>`❌ ${n+1}. ${r}`;return o.map((r,n)=>t(r,n)).join(`
2
+ `)}function ne(o){return Object.keys(o)}var C;(o=>{function e(i,l){return l.split(".").reduce((h,u)=>h?.[u],i)}function t(i,l,h){const u=l.split(".");let d=i;for(let E=0;E<u.length;E++){const _=u[E];E===u.length-1?d[_]!==void 0&&typeof d[_]=="object"&&typeof h=="object"&&h!==null?Object.assign(d[_],h):d[_]=h:((typeof d[_]!="object"||d[_]===null)&&(d[_]={}),d=d[_])}return d}o.setBy=t;function r(i){return i.filter(l=>!i.some(h=>h!==l&&l.startsWith(h+".")))}function n(i,...l){const h=r(l);if(h.length===1)return e(i,h[0]);const u={};for(const d of h){const E=e(i,d);t(u,d,E)}return u}o.pickBy=n;function s(i){const l=[];function h(u,d=""){if(u==null||typeof u!="object"||Array.isArray(u))return;const E=Object.keys(u);for(const _ of E){const T=d?`${d}.${_}`:_;l.push(T);const A=u[_];A!=null&&typeof A=="object"&&!Array.isArray(A)&&h(A,T)}}return h(i),l}o.createDeep=s;function a(i){if(i===null)return"null";if(Array.isArray(i))return"Array";const l=typeof i;if(l!=="object")return l;const h=i?.constructor?.name;return h&&h!=="Object"?h:"object"}function y(i){if(!i)return[];const l=[],h=/[^.[\]]+|\[(\d+)\]/g;let u;for(;u=h.exec(i);)l.push(u[1]??u[0]);return l}function b(i,l){if(!i)return;if(typeof i=="function")return i;const h=y(l);let u=i,d;for(const E of h){if(!u)break;if(typeof u=="function"){d=u;break}if(u=u[E],typeof u=="function"){d=u;break}}return d}function f(i,l,h){const u=b(h,l);return u?u(i,l):a(i)}function g(i){return typeof i=="object"&&i!==null}function c(i,l,h,u,d){if(i===l)return u;if(i===null||l===null||typeof i!="object"||typeof l!="object"){const _=h||"(root)";return typeof i!=typeof l?(u.push({path:_,expected:f(i,_,d.transformExpected),actual:l,reason:"type-mismatch"}),u):(d.includeValueMismatch&&u.push({path:_,expected:f(i,_,d.transformExpected),actual:l,reason:"value-mismatch"}),u)}if(Array.isArray(i)||Array.isArray(l)){if(!Array.isArray(i)||!Array.isArray(l)){const T=h||"(root)";return u.push({path:T,expected:f(i,T,d.transformExpected),actual:l,reason:"type-mismatch"}),u}const _=i.length;for(let T=0;T<_;T++){const A=i[T],x=l[T],k=h===""?`[${T}]`:`${h}[${T}]`;if(T>=l.length){u.push({path:k,expected:f(A,k,d.transformExpected),actual:void 0,reason:"missing-key"});continue}c(A,x,k,u,d)}if(l.length>i.length)for(let T=i.length;T<l.length;T++){const A=h===""?`[${T}]`:`${h}[${T}]`;u.push({path:A,expected:void 0,actual:l[T],reason:"extra-key"})}return u}if(g(i)&&g(l)){const _=Object.keys(i),T=Object.keys(l);for(const A of _){const x=i[A],k=l[A],F=h?`${h}.${A}`:A;if(!(A in l)){u.push({path:F,expected:f(x,F,d.transformExpected),actual:void 0,reason:"missing-key"});continue}c(x,k,F,u,d)}for(const A of T)if(!(A in i)){const x=h?`${h}.${A}`:A;u.push({path:x,expected:void 0,actual:l[A],reason:"extra-key"})}return u}const E=h||"(root)";return typeof i!=typeof l?u.push({path:E,expected:f(i,E,d.transformExpected),actual:l,reason:"type-mismatch"}):d.includeValueMismatch&&u.push({path:E,expected:f(i,E,d.transformExpected),actual:l,reason:"value-mismatch"}),u}function m(i,l,h,u){const d=n(i,...l),E=[],_=l.length===1?l[0]:"";return c(d,h,_,E,{transformExpected:u?.transformExpected}),{ok:E.length===0,mismatches:E}}o.equalsAtPaths=m;function p(i){if(i===void 0)return"undefined";if(typeof i=="string")return JSON.stringify(i);try{return JSON.stringify(i,null,2)}catch{return String(i)}}function v(i){switch(i.reason){case"missing-key":return"Missing key";case"extra-key":return"Extra key";case"type-mismatch":return"Type mismatch";case"value-mismatch":return"Value mismatch";default:return i.reason}}function S(i){if(i.ok||i.mismatches.length===0)return"No mismatches.";const l=[];for(const h of i.mismatches)l.push(`
3
+ ${v(h)} at "${h.path}":`,` expected: ${p(h.expected)}`,` actual: ${p(h.actual)}`,"");return l.at(-1)===""&&l.pop(),l.join(`
4
+ `)}o.formatMismatches=S;function j(i){const l=S(i);l!=="No mismatches."&&console.error(l)}o.printMismatches=j;function $(i,l,h){const u=l.split(".");function d(E,_){const T=u[_],A=Array.isArray(E)?[...E]:{...E};if(_===u.length-1){let W=E&&typeof E=="object"?A:{};return W={...W,[T]:h},W}const x=E&&typeof E=="object"?E[T]:void 0,k=d(x??{},_+1);let F=E&&typeof E=="object"?A:{};return F={...F,[T]:k},F}return d(i,0)}function w(i,l,h){const u=r(l);if(u.length===0)return i;let d=i;if(u.length===1){const E=u[0];return d=$(d,E,h),d}for(const E of u){const _=e(h,E);d=$(d,E,_)}return d}o.updateAt=w})(C||(C={}));function ge(o,e){const t=o["~standard"].validate(e);if(t instanceof Promise)throw new TypeError("Schema validation must be synchronous",{cause:o});if(t.issues)throw new Error(JSON.stringify(t.issues,null,2));return t.value}class be{listeners=new Set;constructor(){this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}}var V;(o=>{o.CATCH_ALL_MESSAGE='The chosen steps must either be set to on of the following: "all", an array of steps (["step1", "step2", ...]), or an object containing the steps to chose ({ step1: true, step2: true, ...})';function e(n){return!!(n&&typeof n=="string"&&n==="all")}o.isAll=e;function t(n,s){return Array.isArray(n)?s?n.every(a=>s.includes(a)):!0:!1}o.isTuple=t;function r(n,s){if(!n)return!1;const a=Object.keys(n);return a.length===0||s&&!a.every(y=>s.includes(y))?!1:Object.entries(n).every(([y,b])=>b===!0)}o.isObject=r})(V||(V={}));function M(o){O(o.includes("step"),"Can't extract a valid step number since");const e=o.replace("step","");return O(/^\d+$/.test(e),`Invalid step format: "${o}"`),Number.parseInt(e,10)}function H(o){return function(e){const{step:t}=e,r=`step${t}`,n=o[r];return{step:t,data:n}}}function se(o,e){return e.reduce((t,r)=>{const n=M(r),{data:s}=H(o)({step:n});for(const[a,y]of Object.entries(s))typeof y=="function"&&a!=="update"||(s[a]=y);return t[r]=s,t},{})}function D(o,e){const t=new Intl.ListFormat("en",{style:"long",type:"disjunction"}),r=Object.keys(o),n=()=>`"stepData" must be set to an array of available steps (${t.format(r)})`;if(e==="all"){let s={};for(const a of r)s={...s,[a]:H(o)({step:M(a)})};return Object.fromEntries(r.map(a=>[a,H(o)({step:M(a)})]))}if(Array.isArray(e))return O(e.every(s=>r.includes(s)),()=>{const s=U(e,r.map(a=>M(a)),t);return s.status==="error"?`${n()}. See errors:
5
+ ${R(s.errors)}`:n()}),se(o,e);if(typeof e=="object"){const s=Object.keys(e);return O(s.every(a=>r.includes(a)),()=>{const a=U(s,r,t);return a.status==="error"?`${n()}. See errors:
6
+ ${R(a.errors)}`:n()}),se(o,s)}throw new Error(`${n()} OR to "all"`)}function ke(o,e){return typeof o=="function"?o(e):o}const Fe=["string","number","array.string","array.string.untyped"],Se=/^step\d+$/i;function oe(o,e){if(typeof o!="object"||o===null)return!1;for(const t of Object.keys(e)){if(!(t in o))return!1;const r=e[t],n=o[t];if(!r(n))return!1}return!0}function ie(o,e,t){return o??Ae(e,t)}function Ve(o){const e={},{fields:t,defaultCasing:r,validateFields:n}=o;for(const[s,a]of Object.entries(t)){O(typeof s=="string",`Each key for the "fields" option must be a string. Key ${s} was a ${typeof s}`),O(typeof a=="object",`The value for key ${s} must be an object. Was ${typeof a}`);const{defaultValue:y,label:b,nameTransformCasing:f,type:g=re}=a;if(n)e[s]=y;else{const c=f??r;e[s]={...e[s],nameTransformCasing:c,type:g,defaultValue:y,label:ie(b,s,c)}}}if(n){const s=ge(n,e);O(typeof s=="object",`The result of the validated fields must be an object, was (${typeof s}). This is probably an internal error, so open up an issue about it`),O(!!s,"The result of the validated fields must be defined. This is probably an internal error, so open up an issue about it");for(const[a,y]of Object.entries(s)){const b=t[a];O(b,`No field found in the fields config for "${a}"`);const{label:f,type:g=re,nameTransformCasing:c}=b,m=c??r;e[a]={...e[a],nameTransformCasing:m,type:g,defaultValue:y,label:ie(f,a,m)}}}return e}function ve(o){const e={};O(!!o,"The steps config must be defined",TypeError),O(typeof o=="object",`The steps config must be an object, was (${typeof o})`,TypeError);for(const[t,r]of Object.entries(o)){O(typeof t=="string",`Each key for the step config must be a string. Key "${t}" was ${typeof t} `,TypeError),O(Se.test(t),`The key "${t}" isn't formatted properly. Each key in the step config must be the following format: "step{number}"`);const n=t,{fields:s,title:a,nameTransformCasing:y=X,description:b,validateFields:f}=r,g=n.toString().replace("step","");O(s,`Missing fields for step ${g} (${String(n)})`,TypeError),O(typeof s=="object","Fields must be an object",TypeError),O(Object.keys(s).length>0,`The fields config for step ${g} (${String(n)}) is empty. Please add a field`),O(typeof s=="object",`The "fields" property must be an object. Was ${typeof s}`);const c=Ve({defaultCasing:y,fields:s,validateFields:f});e[n]={...e[n],title:a,nameTransformCasing:y,...typeof b=="string"?{description:b}:{},fields:c}}return e}class ee extends be{original;value;steps;defaultNameTransformationCasing;firstStep;lastStep;stepNumbers;storage;constructor(e){super();const{steps:t,nameTransformCasing:r,storage:n}=e;this.defaultNameTransformationCasing=ye(r),this.original=t,this.value=this.enrichValues(ve(this.original)),this.stepNumbers=Object.keys(this.value).map(s=>Number.parseInt(s.replace("step",""))),this.storage=new me({data:this.value,key:n?.key??Q,store:n?.store}),this.firstStep=this.first(),this.lastStep=this.last(),this.steps={first:this.firstStep.step,last:this.lastStep.step,value:this.stepNumbers,as:s=>{if(O(typeof s=="string",`The type of the target transformation type must be a string, was ${typeof s}`),s==="string")return this.stepNumbers.map(a=>`'${a}'`).join(" | ");if(s==="number")return this.stepNumbers.join(" | ");if(s.includes("array.string"))return this.stepNumbers.map(a=>`${a}`);throw new Error(`Transformation type "${s}" is not supported. Available transformations include: ${Fe.map(a=>`"${a}"`).join(", ")}`)},isValidStepNumber:s=>this.stepNumbers.includes(s),isValidStepKey:s=>Object.keys(this.value).includes(s)}}getSnapshot(){return this}notify(){for(const e of this.listeners)e({defaultNameTransformationCasing:this.defaultNameTransformationCasing,original:this.original,steps:this.steps,value:this.value})}enrichValues(e,t){for(const[r,n]of Object.entries(e)){const s=Number.parseInt(r.replace("step",""));e={...e,[r]:{...n,update:this.createStepUpdaterFn(r),createHelperFn:this.createStepHelperFn(s),...t?.(s)}}}return e}get(e){return H(this.value)(e)}first(){const e=Math.min(...this.stepNumbers);return this.get({step:e})}last(){const e=Math.max(...this.stepNumbers);return this.get({step:e})}handlePostUpdate(){this.storage.add(this.value),this.notify()}createHelperFnInputUpdate(e){if(V.isAll(e)){const r=ne(this.value).reduce((n,s)=>(n[s]=this.createStepUpdaterFn(s),n),{});return Object.assign(this.update,r)}const t=Object.keys(this.value);if(V.isTuple(e,t)){const r=e.reduce((n,s)=>(n[s]=this.createStepUpdaterFn(s),n),{});return Object.assign(this.update,r)}if(V.isObject(e,t)){const r=ne(e).reduce((n,s)=>(n[s]=this.createStepUpdaterFn(s),n),{});return Object.assign(this.update,r)}throw new TypeError(`[update]: ${V.CATCH_ALL_MESSAGE}`)}createStepUpdaterFnImpl(e){const{targetStep:t,updater:r,ctxData:n,fields:s="all"}=e;O(this.steps.isValidStepKey(t),`[update]: The target step ${t} isn't a valid step. Please select a valid step`);const{[t]:a,...y}=this.value;let b=D(this.value,[t]);if(n){O(typeof n=="function",'[update]: "ctxData" must be a function');const c=n({ctx:y});O(typeof c=="object"&&Object.keys(c).length>0,'[update]: "ctxData" must return an object with keys'),b={...b,...c}}const f=ke(r,{ctx:b,update:this.createHelperFnInputUpdate([t])});if(!s){O(typeof f=="object",'[update]: "updater" must be an object or a function that returns an object');const c=Object.keys(this.value),m=Object.keys(f);O(m.length===c.length,()=>{const j=c.filter($=>!m.includes($));return`[update]: "updater" is missing keys ${new Intl.ListFormat("en",{style:"long",type:"conjunction"}).format(j)}`});const p=C.createDeep(this.value),{mismatches:v,ok:S}=C.equalsAtPaths(this.value,p,f);O(S&&v.length===0,`[update]: found value mismatches in ${C.printMismatches({mismatches:v,ok:S})}`),this.value={...this.value,[t]:C.updateAt(this.value,p,f)},this.handlePostUpdate();return}const g=C.createDeep(a);if(Array.isArray(s)){const c=U(g,s);O(c.status==="success",`[update]: Found errors with the provided fields
7
+ ${c.status==="error"?R(c.errors):""}`);const{mismatches:m,ok:p}=C.equalsAtPaths(a,s,f);O(p&&m.length===0,`[update]: found value mismatches in ${C.printMismatches({ok:p,mismatches:m})}`),this.value={...this.value,[t]:C.updateAt(a,s,f)},this.handlePostUpdate();return}if(typeof s=="object"&&Object.keys(s).length>0){const c=C.createDeep(s),m=U(g,c);O(m.status==="success",`[update]: Found errors with the provided fields
8
+ ${m.status==="error"?R(m.errors):""}`);const{mismatches:p,ok:v}=C.equalsAtPaths(a,c,f);O(v&&p.length===0,`[update]: found value mismatches in ${C.printMismatches({ok:v,mismatches:p})}`),this.value={...this.value,[t]:C.updateAt(a,c,f)},this.handlePostUpdate();return}throw new TypeError(`[update]: property "fields" must be set to one of the following: "all", an array of deep paths to update, or an object of paths. Was ${typeof r}`,{cause:r})}createStepUpdaterFn(e){return t=>{this.createStepUpdaterFnImpl({targetStep:e,...t})}}update(e){this.createStepUpdaterFnImpl(e)}createStepHelperFnImpl(e){return(t,r)=>{const n=D(this.value,e);if(typeof t=="function")return()=>t({ctx:n,update:this.createHelperFnInputUpdate(e)});if(typeof t=="object")return s=>{if("validator"in t){O(typeof s=="object","An input is expected since you provided a validator"),ge(t.validator,s.data);let a=n;if(t.ctxData){const y=e[0],{[y]:b,...f}=this.value;a={...a,...t.ctxData({ctx:f})}}return r({ctx:a,update:this.createHelperFnInputUpdate(e),...s})}return r({ctx:n,update:this.createHelperFnInputUpdate(e)})};throw new Error(`The first argument must be a function or an object, (was ${typeof t})`)}}createStepHelperFn(e){return this.createStepHelperFnImpl([`step${e}`])}createHelperFn(e,t){const{stepData:r,...n}=e;return this.createStepHelperFnImpl(r)(n,t)}static hasData(e,t){return e===null||typeof e!="object"?!1:oe(e,{title:r=>typeof r=="string",fields:r=>{if(r===null||typeof r!="object")return!1;for(const n of Object.keys(r)){if(typeof n!="string"||!(n in r))return!1;const s=r[n];if(s===null||typeof s!="object"||!oe(s,{defaultValue:a=>a!=="undefined"&&a!==null,label:a=>typeof a=="string"||typeof a=="boolean"&&!a,nameTransformCasing:Y,type:xe}))return!1}return!0},createHelperFn:r=>typeof r=="function",nameTransformCasing:Y,...t?.optionalKeysToCheck})}}class Ne extends be{defaultNameTransformationCasing;stepSchema;storage;mountCount=0;constructor(e){super();const{steps:t,nameTransformCasing:r,storage:n}=e;this.defaultNameTransformationCasing=ye(r),this.stepSchema=new ee({steps:t,nameTransformCasing:this.defaultNameTransformationCasing}),this.storage=new me({key:n?.key??Q,data:this.stepSchema.value,store:n?.store}),this.stepSchema.subscribe(()=>{this.notify()})}getSnapshot(){return this}mount(){return this.mountCount++,this.mountCount===1&&this.onMount(),()=>{this.unmount()}}unmount(){this.mountCount=Math.max(0,this.mountCount-1),this.mountCount===0&&this.onUnmount()}isMounted(){return this.mountCount>0}onMount(){}onUnmount(){}notify(){for(const e of this.listeners)e({nameTransformCasing:this.defaultNameTransformationCasing,storage:{key:this.storage.key,store:this.storage.store},steps:this.stepSchema.original})}}function De(o){function e(t){const{children:r,name:n}=t;return r(o(n))}return e}var N;(o=>{o.DEFAULT_FORM_ALIAS="Form";function e(r,n){if(Array.isArray(r)){if(n==="all")return!0;if(typeof n=="object"&&!Array.isArray(n))return Object.keys(n).some(s=>r.includes(s));if(Array.isArray(n))return n.some(s=>r.includes(s))}return!1}o.isFormAvailable=e;function t(r){return n=>J.jsx("form",{id:r,...n})}o.createDefaultForm=t})(N||(N={}));exports.StepSpecificComponent=void 0;(o=>{o.DEFAULT_FORM_INSTANCE_ALIAS="form"})(exports.StepSpecificComponent||(exports.StepSpecificComponent={}));function je(o,e){O(e in o,`The target step ${e} is not a valid step key`);const t=o[e];O("fields"in t,`No "fields" were found for ${e}`);let r={};for(const[n,s]of Object.entries(t.fields))r={...r,[n]:s.defaultValue};return r}class Oe extends ee{value;constructor(e){const{form:t,...r}=e;super(r),this.value=this.enrichValues(ve(this.original)),this.value=this.enrichValues(this.value,n=>{const s=`step${n}`,a=t?.id??s;return{createComponent:this.createComponentForStep([`step${n}`],{isStepSpecific:!0,defaultId:a,form:t})}})}createFormComponent(e,t){const{render:r,enabledForSteps:n="all",id:s=t}=e,a={id:s,steps:D(this.value,n)};return y=>r(a,y)}createStepSpecificComponentImpl(e,t,r,n={}){return s=>(a=>{const y={};for(const[j,$]of Object.entries(n))if(typeof $=="function")try{const w=$();y[j]=w,typeof console<"u"&&console.debug&&console.debug(`[multi-step-form] Hook "${j}" called successfully`,{result:w!==void 0?"defined":"undefined"})}catch(w){const i=w instanceof Error?w.message:String(w);throw new Error(`[multi-step-form] Error calling hook "${j}" in useFormInstance.render: ${i}
5
9
 
6
10
  This usually means:
7
11
  1. The hook is being called outside of a React component
8
12
  2. The hook has invalid dependencies or configuration
9
13
  3. There's an error in your hook implementation
10
14
 
11
- Original error: ${c}`,{cause:a})}else p[u]=l;const{defaultId:y,form:f}=t,{ctx:d}=r;if(f){const{alias:u=$.DEFAULT_FORM_ALIAS,...l}=f,a=l.enabledForSteps??"all",[c]=e;h(this.steps.isValidStepKey(c),`[createComponent]: the target step ${c} is invalid. Note, this error shouldn't appear as the target step should always be valid. If you see this error, please open an issue.`);const m=Number.parseInt(c.replace("step",""));h(!Number.isNaN(m),`[${c}:"createComponent"]: an error occurred while extracting the number`);const S=this.value[c];h("fields"in S,`[${c}:createComponent]: unable to find the "fields" for the current step`),h(typeof S.fields=="object",`[${c}:createComponent]: the "fields" property must be an object, was ${typeof S.fields}`);const _=je(b=>{h(typeof b=="string",()=>{const x=new Intl.ListFormat("en",{style:"long",type:"disjunction"});return`[${c}:Field]: the "name" prop must be a string and a valid field for ${c}. Available fields include ${x.format(Object.keys(S.fields))}`}),h(b in S.fields,`[${c}:Field]: the field "${b}" doesn't exist for the current step`);const{fields:O,update:T}=S,{defaultValue:g,label:v,nameTransformCasing:E,type:ge}=O[b];return{defaultValue:g,label:v,nameTransformCasing:E,type:ge,name:b,onInputChange:x=>T("fields",P=>({...P,[b]:{...P[b],defaultValue:x}}))}});let w={ctx:d,onInputChange:this.createStepUpdaterFn(m),Field:_,...p};return $.isFormAvailable(e,a)&&(w={...w,[u]:this.createFormComponent(l,y)}),n(w,i)}return n({ctx:d,[$.DEFAULT_FORM_ALIAS]:$.createDefaultForm(y)},i)})}createStepSpecificComponentFactory(e,t,r){const s=this.createStepSpecificComponentImpl.bind(this),n=this.createDefaultValues.bind(this),i=this.value;function p(y,f){function d(l){return l?{ctx:{...r,...l}}:{ctx:r}}function u(){return h(typeof y=="function","The first argument must be a function"),s(e,t,d(void 0))(y)}if(typeof y=="object"){const{useFormInstance:l,ctxData:a,debug:c}=y,m=e[0],S=new ae({debug:c,prefix(b){return`${b}-${String(m)}-createComponent`}});S.info("First argument is an object");const{[m]:_,...w}=i;if(h(typeof f=="function","The second argument must be a function"),l){const{render:b,alias:O=exports.StepSpecificComponent.DEFAULT_FORM_INSTANCE_ALIAS}=l,[T]=e,g=n(T),v=a?{...r,...a({ctx:w})}:r,E={ctx:v,defaultValues:g};return s(e,t,v,{[O]:()=>b(E)})(f)}if(a){S.info('Option "ctxData" is defined'),h(typeof a=="function",'Option "ctxData" must be a function');const b=a({ctx:w});S.info(`Addition context is: ${JSON.stringify(b,null,2)}`);const O={...r,...b};return S.info(`Resolved context is: ${JSON.stringify(O,null,2)}`),s(e,t,{ctx:O})(f)}return u()}return u()}return p}createComponentImpl(e,t){const r=A(this.value,e);return t.isStepSpecific?this.createStepSpecificComponentFactory(e,t,r):s=>(n=>s(r,n))}createComponentForStep(e,t){return this.createComponentImpl(e,t)}createComponent(e,t){return this.createComponentImpl(e.stepData,{isStepSpecific:!1})(t)}createDefaultValues(e){return he(this.value,e)}}class ye extends Ce{stepSchema;constructor(e){const{nameTransformCasing:t=K,storage:r,...s}=e;super({nameTransformCasing:t,storage:r,...s}),this.stepSchema=new me({nameTransformCasing:t,...s})}createComponent(e,t){const{stepData:r}=e,s=A(this.stepSchema.value,r);return(n=>t({ctx:s},n))}}function Ve(o){return new ye(o)}var C={exports:{}},L={},j={exports:{}},D={};/**
15
+ Original error: ${i}`,{cause:w})}else y[j]=$;const{defaultId:b,form:f}=t,{ctx:g}=r,[c]=e;O(this.steps.isValidStepKey(c),`[createComponent]: the target step ${c} is invalid. Note, this error shouldn't appear as the target step should always be valid. If you see this error, please open an issue.`);const m=Number.parseInt(c.replace("step",""));O(!Number.isNaN(m),`[${c}:"createComponent"]: an error occurred while extracting the number`);const p=this.value[c];O("fields"in p,`[${c}:createComponent]: unable to find the "fields" for the current step`),O(typeof p.fields=="object",`[${c}:createComponent]: the "fields" property must be an object, was ${typeof p.fields}`);const v=De(j=>{O(typeof j=="string",()=>{const d=new Intl.ListFormat("en",{style:"long",type:"disjunction"});return`[${c}:Field]: the "name" prop must be a string and a valid field for ${c}. Available fields include ${d.format(Object.keys(p.fields))}`}),O(j in p.fields,`[${c}:Field]: the field "${j}" doesn't exist for the current step`),O("update"in p,`[${c}:Field]: No "update" function was found`);const{fields:$,update:w}=p,{defaultValue:i,label:l,nameTransformCasing:h,type:u}=$[j];return{defaultValue:i,label:l,nameTransformCasing:h,type:u,name:j,onInputChange:d=>w({fields:[`fields.${j}.defaultValue`],updater:d})}});let S={ctx:g,onInputChange:this.createStepUpdaterFn(c),Field:v,...y};if(f){const{alias:j=N.DEFAULT_FORM_ALIAS,...$}=f,w=$.enabledForSteps??"all";return N.isFormAvailable(e,w)&&(S={...S,[j]:this.createFormComponent($,b)}),s(S,a)}return s({...S,[N.DEFAULT_FORM_ALIAS]:N.createDefaultForm(b)},a)})}createStepSpecificComponentFactory(e,t,r){const n=this.createStepSpecificComponentImpl.bind(this),s=this.createDefaultValues.bind(this),a=this.value;function y(b,f){function g(m){return m?{ctx:{...r,...m}}:{ctx:r}}function c(){return O(typeof b=="function","The first argument must be a function"),n(e,t,g(void 0))(b)}if(typeof b=="object"){const{useFormInstance:m,ctxData:p,debug:v}=b,S=e[0],j=new he({debug:v,prefix(i){return`${i}-${String(S)}-createComponent`}});j.info("First argument is an object");const{[S]:$,...w}=a;if(O(typeof f=="function","The second argument must be a function"),m){const{render:i,alias:l=exports.StepSpecificComponent.DEFAULT_FORM_INSTANCE_ALIAS}=m,[h]=e,u=s(h),d=p?{...r,...p({ctx:w})}:r,E={ctx:d,defaultValues:u};return n(e,t,d,{[l]:()=>i(E)})(f)}if(p){j.info('Option "ctxData" is defined'),O(typeof p=="function",'Option "ctxData" must be a function');const i=p({ctx:w});j.info(`Addition context is: ${JSON.stringify(i,null,2)}`);const l={...r,...i};return j.info(`Resolved context is: ${JSON.stringify(l,null,2)}`),n(e,t,{ctx:l})(f)}return c()}return c()}return y}createComponentImpl(e,t){const r=D(this.value,e);return t.isStepSpecific?this.createStepSpecificComponentFactory(e,t,r):n=>(s=>n(r,s))}createComponentForStep(e,t){return this.createComponentImpl(e,t)}createComponent(e,t){return this.createComponentImpl(e.stepData,{isStepSpecific:!1})(t)}createDefaultValues(e){return je(this.value,e)}}class Ee extends Ne{stepSchema;constructor(e){const{nameTransformCasing:t=X,storage:r,...n}=e;super({nameTransformCasing:t,storage:r,...n}),this.stepSchema=new Oe({nameTransformCasing:t,...n})}createComponent(e,t){const{stepData:r}=e,n=D(this.stepSchema.value,r);return(s=>t({ctx:n},s))}}function Ie(o){return new Ee(o)}var I={exports:{}},K={},L={exports:{}},B={};/**
12
16
  * @license React
13
17
  * use-sync-external-store-shim.production.js
14
18
  *
@@ -16,7 +20,7 @@ Original error: ${c}`,{cause:a})}else p[u]=l;const{defaultId:y,form:f}=t,{ctx:d}
16
20
  *
17
21
  * This source code is licensed under the MIT license found in the
18
22
  * LICENSE file in the root directory of this source tree.
19
- */var ee;function Fe(){if(ee)return D;ee=1;var o=N;function e(u,l){return u===l&&(u!==0||1/u===1/l)||u!==u&&l!==l}var t=typeof Object.is=="function"?Object.is:e,r=o.useState,s=o.useEffect,n=o.useLayoutEffect,i=o.useDebugValue;function p(u,l){var a=l(),c=r({inst:{value:a,getSnapshot:l}}),m=c[0].inst,S=c[1];return n(function(){m.value=a,m.getSnapshot=l,y(m)&&S({inst:m})},[u,a,l]),s(function(){return y(m)&&S({inst:m}),u(function(){y(m)&&S({inst:m})})},[u]),i(a),a}function y(u){var l=u.getSnapshot;u=u.value;try{var a=l();return!t(u,a)}catch{return!0}}function f(u,l){return l()}var d=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?f:p;return D.useSyncExternalStore=o.useSyncExternalStore!==void 0?o.useSyncExternalStore:d,D}var k={};/**
23
+ */var ae;function Le(){if(ae)return B;ae=1;var o=P;function e(c,m){return c===m&&(c!==0||1/c===1/m)||c!==c&&m!==m}var t=typeof Object.is=="function"?Object.is:e,r=o.useState,n=o.useEffect,s=o.useLayoutEffect,a=o.useDebugValue;function y(c,m){var p=m(),v=r({inst:{value:p,getSnapshot:m}}),S=v[0].inst,j=v[1];return s(function(){S.value=p,S.getSnapshot=m,b(S)&&j({inst:S})},[c,p,m]),n(function(){return b(S)&&j({inst:S}),c(function(){b(S)&&j({inst:S})})},[c]),a(p),p}function b(c){var m=c.getSnapshot;c=c.value;try{var p=m();return!t(c,p)}catch{return!0}}function f(c,m){return m()}var g=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?f:y;return B.useSyncExternalStore=o.useSyncExternalStore!==void 0?o.useSyncExternalStore:g,B}var q={};/**
20
24
  * @license React
21
25
  * use-sync-external-store-shim.development.js
22
26
  *
@@ -24,7 +28,7 @@ Original error: ${c}`,{cause:a})}else p[u]=l;const{defaultId:y,form:f}=t,{ctx:d}
24
28
  *
25
29
  * This source code is licensed under the MIT license found in the
26
30
  * LICENSE file in the root directory of this source tree.
27
- */var te;function Ae(){return te||(te=1,process.env.NODE_ENV!=="production"&&(function(){function o(a,c){return a===c&&(a!==0||1/a===1/c)||a!==a&&c!==c}function e(a,c){d||s.startTransition===void 0||(d=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var m=c();if(!u){var S=c();n(m,S)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}S=i({inst:{value:m,getSnapshot:c}});var _=S[0].inst,w=S[1];return y(function(){_.value=m,_.getSnapshot=c,t(_)&&w({inst:_})},[a,m,c]),p(function(){return t(_)&&w({inst:_}),a(function(){t(_)&&w({inst:_})})},[a]),f(m),m}function t(a){var c=a.getSnapshot;a=a.value;try{var m=c();return!n(a,m)}catch{return!0}}function r(a,c){return c()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var s=N,n=typeof Object.is=="function"?Object.is:o,i=s.useState,p=s.useEffect,y=s.useLayoutEffect,f=s.useDebugValue,d=!1,u=!1,l=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:e;k.useSyncExternalStore=s.useSyncExternalStore!==void 0?s.useSyncExternalStore:l,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),k}var re;function Se(){return re||(re=1,process.env.NODE_ENV==="production"?j.exports=Fe():j.exports=Ae()),j.exports}/**
31
+ */var ue;function Me(){return ue||(ue=1,process.env.NODE_ENV!=="production"&&(function(){function o(p,v){return p===v&&(p!==0||1/p===1/v)||p!==p&&v!==v}function e(p,v){g||n.startTransition===void 0||(g=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var S=v();if(!c){var j=v();s(S,j)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),c=!0)}j=a({inst:{value:S,getSnapshot:v}});var $=j[0].inst,w=j[1];return b(function(){$.value=S,$.getSnapshot=v,t($)&&w({inst:$})},[p,S,v]),y(function(){return t($)&&w({inst:$}),p(function(){t($)&&w({inst:$})})},[p]),f(S),S}function t(p){var v=p.getSnapshot;p=p.value;try{var S=v();return!s(p,S)}catch{return!0}}function r(p,v){return v()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var n=P,s=typeof Object.is=="function"?Object.is:o,a=n.useState,y=n.useEffect,b=n.useLayoutEffect,f=n.useDebugValue,g=!1,c=!1,m=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:e;q.useSyncExternalStore=n.useSyncExternalStore!==void 0?n.useSyncExternalStore:m,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),q}var ce;function $e(){return ce||(ce=1,process.env.NODE_ENV==="production"?L.exports=Le():L.exports=Me()),L.exports}/**
28
32
  * @license React
29
33
  * use-sync-external-store-shim/with-selector.production.js
30
34
  *
@@ -32,7 +36,7 @@ Original error: ${c}`,{cause:a})}else p[u]=l;const{defaultId:y,form:f}=t,{ctx:d}
32
36
  *
33
37
  * This source code is licensed under the MIT license found in the
34
38
  * LICENSE file in the root directory of this source tree.
35
- */var ne;function Ne(){if(ne)return L;ne=1;var o=N,e=Se();function t(f,d){return f===d&&(f!==0||1/f===1/d)||f!==f&&d!==d}var r=typeof Object.is=="function"?Object.is:t,s=e.useSyncExternalStore,n=o.useRef,i=o.useEffect,p=o.useMemo,y=o.useDebugValue;return L.useSyncExternalStoreWithSelector=function(f,d,u,l,a){var c=n(null);if(c.current===null){var m={hasValue:!1,value:null};c.current=m}else m=c.current;c=p(function(){function _(g){if(!w){if(w=!0,b=g,g=l(g),a!==void 0&&m.hasValue){var v=m.value;if(a(v,g))return O=v}return O=g}if(v=O,r(b,g))return v;var E=l(g);return a!==void 0&&a(v,E)?(b=g,v):(b=g,O=E)}var w=!1,b,O,T=u===void 0?null:u;return[function(){return _(d())},T===null?void 0:function(){return _(T())}]},[d,u,l,a]);var S=s(f,c[0],c[1]);return i(function(){m.hasValue=!0,m.value=S},[S]),y(S),S},L}var M={};/**
39
+ */var le;function Ue(){if(le)return K;le=1;var o=P,e=$e();function t(f,g){return f===g&&(f!==0||1/f===1/g)||f!==f&&g!==g}var r=typeof Object.is=="function"?Object.is:t,n=e.useSyncExternalStore,s=o.useRef,a=o.useEffect,y=o.useMemo,b=o.useDebugValue;return K.useSyncExternalStoreWithSelector=function(f,g,c,m,p){var v=s(null);if(v.current===null){var S={hasValue:!1,value:null};v.current=S}else S=v.current;v=y(function(){function $(u){if(!w){if(w=!0,i=u,u=m(u),p!==void 0&&S.hasValue){var d=S.value;if(p(d,u))return l=d}return l=u}if(d=l,r(i,u))return d;var E=m(u);return p!==void 0&&p(d,E)?(i=u,d):(i=u,l=E)}var w=!1,i,l,h=c===void 0?null:c;return[function(){return $(g())},h===null?void 0:function(){return $(h())}]},[g,c,m,p]);var j=n(f,v[0],v[1]);return a(function(){S.hasValue=!0,S.value=j},[j]),b(j),j},K}var z={};/**
36
40
  * @license React
37
41
  * use-sync-external-store-shim/with-selector.development.js
38
42
  *
@@ -40,5 +44,5 @@ Original error: ${c}`,{cause:a})}else p[u]=l;const{defaultId:y,form:f}=t,{ctx:d}
40
44
  *
41
45
  * This source code is licensed under the MIT license found in the
42
46
  * LICENSE file in the root directory of this source tree.
43
- */var se;function xe(){return se||(se=1,process.env.NODE_ENV!=="production"&&(function(){function o(f,d){return f===d&&(f!==0||1/f===1/d)||f!==f&&d!==d}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var e=N,t=Se(),r=typeof Object.is=="function"?Object.is:o,s=t.useSyncExternalStore,n=e.useRef,i=e.useEffect,p=e.useMemo,y=e.useDebugValue;M.useSyncExternalStoreWithSelector=function(f,d,u,l,a){var c=n(null);if(c.current===null){var m={hasValue:!1,value:null};c.current=m}else m=c.current;c=p(function(){function _(g){if(!w){if(w=!0,b=g,g=l(g),a!==void 0&&m.hasValue){var v=m.value;if(a(v,g))return O=v}return O=g}if(v=O,r(b,g))return v;var E=l(g);return a!==void 0&&a(v,E)?(b=g,v):(b=g,O=E)}var w=!1,b,O,T=u===void 0?null:u;return[function(){return _(d())},T===null?void 0:function(){return _(T())}]},[d,u,l,a]);var S=s(f,c[0],c[1]);return i(function(){m.hasValue=!0,m.value=S},[S]),y(S),S},typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),M}var oe;function Ie(){return oe||(oe=1,process.env.NODE_ENV==="production"?C.exports=Ne():C.exports=xe()),C.exports}var Le=Ie();function H(o,e){h(typeof e=="string",`The target step must be a string, was ${typeof e}`);const{as:t,isValidStepNumber:r}=o.stepSchema.steps,n=new Intl.ListFormat("en",{type:"disjunction",style:"long"}).format(t("array.string.untyped"));h(pe.test(e),`The target step must match the following format: "step{number}". Available steps are ${n}`);const i=Number.parseInt(e.replace("step",""));return h(r(i),`The step number "${i}" is not a valid step number. Valid step numbers include ${n}`,TypeError),i}function be(o){function e(t){return Le.useSyncExternalStoreWithSelector(o.subscribe,()=>o.getSnapshot(),()=>o.getSnapshot(),r=>{if(typeof t=="object"){const s=H(r,t.targetStep);return r.stepSchema.get({step:s}).data}return typeof t=="function"?t(r):r})}return e}function De(o,e){const t=be(o);return typeof e=="object"||typeof e=="function"?t(e):t()}function ie(o){return function(e){return(t=>e(o,t))}}function ke(o){const e=be(o);function t(p){const{targetStep:y,notFoundMessage:f,isDataGuaranteed:d}=p,u=e({targetStep:y}),l=f?i({targetStep:y},f):a=>R.jsxs("div",{...a,children:["No data found for step ",String(y)]});return d?{data:u,NoCurrentData:l}:G.hasData(u)?{data:u,hasData:!0,NoCurrentData:l}:{data:void 0,hasData:!1,NoCurrentData:l}}function r(p){const y=e(S=>S.stepSchema.steps.value.length),{targetStep:f,maxProgressValue:d=100,totalSteps:u=y,progressTextTransformer:l}=p,a=H(o,f),c=a/u*d,m=l?n({targetStep:f,maxProgressValue:d,totalSteps:u},l):S=>R.jsxs("div",{...S,children:["Step ",a,"/",u]});return{value:c,maxProgressValue:d,ProgressText:m}}function s(p){const f=e(u=>u.storage).get(),d=!!(f&&typeof f=="object"&&Object.keys(f).length>0);return p?p(d):d}function n(p,y){const f=o.getSnapshot().stepSchema.steps.value.length,{targetStep:d,maxProgressValue:u=100,totalSteps:l=f}=p;return ie({targetStep:d,maxProgressValue:u,totalSteps:l})(y)}function i(p,y){return H(o,p.targetStep),ie(p)(y)}return{useMultiStepFormData:e,useCurrentStepData:t,useProgress:r,useCanRestartForm:s,withProgressText:n,withNoStepDataFound:i}}exports.MultiStepFormSchema=ye;exports.MultiStepFormStepSchema=me;exports.createDefaultValues=he;exports.createMultiStepFormContext=ke;exports.createMultiStepFormSchema=Ve;exports.useMultiStepFormData=De;
47
+ */var fe;function Re(){return fe||(fe=1,process.env.NODE_ENV!=="production"&&(function(){function o(f,g){return f===g&&(f!==0||1/f===1/g)||f!==f&&g!==g}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var e=P,t=$e(),r=typeof Object.is=="function"?Object.is:o,n=t.useSyncExternalStore,s=e.useRef,a=e.useEffect,y=e.useMemo,b=e.useDebugValue;z.useSyncExternalStoreWithSelector=function(f,g,c,m,p){var v=s(null);if(v.current===null){var S={hasValue:!1,value:null};v.current=S}else S=v.current;v=y(function(){function $(u){if(!w){if(w=!0,i=u,u=m(u),p!==void 0&&S.hasValue){var d=S.value;if(p(d,u))return l=d}return l=u}if(d=l,r(i,u))return d;var E=m(u);return p!==void 0&&p(d,E)?(i=u,d):(i=u,l=E)}var w=!1,i,l,h=c===void 0?null:c;return[function(){return $(g())},h===null?void 0:function(){return $(h())}]},[g,c,m,p]);var j=n(f,v[0],v[1]);return a(function(){S.hasValue=!0,S.value=j},[j]),b(j),j},typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),z}var pe;function He(){return pe||(pe=1,process.env.NODE_ENV==="production"?I.exports=Ue():I.exports=Re()),I.exports}var Pe=He();function Z(o,e){O(typeof e=="string",`The target step must be a string, was ${typeof e}`);const{as:t,isValidStepNumber:r}=o.stepSchema.steps,s=new Intl.ListFormat("en",{type:"disjunction",style:"long"}).format(t("array.string.untyped"));O(Se.test(e),`The target step must match the following format: "step{number}". Available steps are ${s}`);const a=Number.parseInt(e.replace("step",""));return O(r(a),`The step number "${a}" is not a valid step number. Valid step numbers include ${s}`,TypeError),a}function _e(o){function e(t){return Pe.useSyncExternalStoreWithSelector(o.subscribe,()=>o.getSnapshot(),()=>o.getSnapshot(),r=>{if(typeof t=="object"){const n=Z(r,t.targetStep);return r.stepSchema.get({step:n}).data}return typeof t=="function"?t(r):r})}return e}function We(o,e){const t=_e(o);return typeof e=="object"||typeof e=="function"?t(e):t()}function de(o){return function(e){return(t=>e(o,t))}}function Ge(o){const e=_e(o);function t(y){const{targetStep:b,notFoundMessage:f,isDataGuaranteed:g}=y,c=e({targetStep:b}),m=f?a({targetStep:b},f):p=>J.jsxs("div",{...p,children:["No data found for step ",String(b)]});return g?{data:c,NoCurrentData:m}:ee.hasData(c)?{data:c,hasData:!0,NoCurrentData:m}:{data:void 0,hasData:!1,NoCurrentData:m}}function r(y){const b=e(j=>j.stepSchema.steps.value.length),{targetStep:f,maxProgressValue:g=100,totalSteps:c=b,progressTextTransformer:m}=y,p=Z(o,f),v=p/c*g,S=m?s({targetStep:f,maxProgressValue:g,totalSteps:c},m):j=>J.jsxs("div",{...j,children:["Step ",p,"/",c]});return{value:v,maxProgressValue:g,ProgressText:S}}function n(y){const f=e(c=>c.storage).get(),g=!!(f&&typeof f=="object"&&Object.keys(f).length>0);return y?y(g):g}function s(y,b){const f=o.getSnapshot().stepSchema.steps.value.length,{targetStep:g,maxProgressValue:c=100,totalSteps:m=f}=y;return de({targetStep:g,maxProgressValue:c,totalSteps:m})(b)}function a(y,b){return Z(o,y.targetStep),de(y)(b)}return{useMultiStepFormData:e,useCurrentStepData:t,useProgress:r,useCanRestartForm:n,withProgressText:s,withNoStepDataFound:a}}exports.MultiStepFormSchema=Ee;exports.MultiStepFormStepSchema=Oe;exports.createDefaultValues=je;exports.createMultiStepFormContext=Ge;exports.createMultiStepFormSchema=Ie;exports.useMultiStepFormData=We;
44
48
  //# sourceMappingURL=index.cjs.map