@jfdevelops/react-multi-step-form 1.0.0-alpha.2 → 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,16 +1,18 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("react/jsx-runtime"),I=require("react");function N(o,e,t){const r=[],s=new Set(o),n=t?t.format(o.map(a=>`${a}`)):`[${o.join(", ")}]`;for(let a=0;a<e.length;a++){const c=e[a];s.has(c)||r.push(`Extra element at index ${a}: "${c}" is not in ${n}`)}return e.some(a=>s.has(a))||r.push(`Array must contain at least one valid element from ${n}`),r.length>0?{status:"error",errors:r}:{status:"success"}}function V(o){return o.map((e,t)=>`❌ ${t+1}. ${e}`).join(`
2
- `)}function Se(o,...e){return()=>String.raw({raw:o},...e)}function h(o,e,t=Error){if(!o){const r=typeof e=="function"?e():Se`${e}`();throw new t(r)}}function G(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}function j(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 C(o){return function(e){const{step:t}=e,r=`step${t}`,s=o[r];return{step:t,data:s}}}function q(o,e){return e.reduce((t,r)=>{const s=j(r),{data:n}=C(o)({step:s});for(const[a,c]of Object.entries(n))typeof c=="function"&&a!=="update"||(n[a]=c);return t[r]=n,t},{})}function U(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 a of r)n={...n,[a]:C(o)({step:j(a)})};return Object.fromEntries(r.map(a=>[a,C(o)({step:j(a)})]))}if(Array.isArray(e))return h(e.every(n=>r.includes(n)),()=>{const n=N(e,r.map(a=>j(a)),t);return n.status==="error"?`${s()}. See errors:
3
- ${V(n.errors)}`:s()}),q(o,e);if(typeof e=="object"){const n=Object.keys(e);return h(n.every(a=>r.includes(a)),()=>{const a=N(n,r,t);return a.status==="error"?`${s()}. See errors:
4
- ${V(a.errors)}`:s()}),q(o,n)}throw new Error(`${s()} OR to "all"`)}function J(o,e){return typeof o=="function"?o(e):o}class be{values;stepNumbers;constructor(e,t){this.stepNumbers=t,this.values=e}createCtxHelper(e){return e.reduce((t,r)=>{const s=j(r),{data:n}=C(this.values)({step:s});for(const[a,c]of Object.entries(n))typeof c=="function"&&a!=="update"||(n[a]=c);return t[r]=n,t},{})}createCtx(e){const t=new Intl.ListFormat("en",{style:"long",type:"disjunction"}),r=this.stepNumbers.map(n=>`step${n}`),s=()=>`"stepData" must be set to an array of available steps (${t.format(r)})`;if(e==="all")return this.stepNumbers.reduce((n,a)=>{const c=`step${a}`;return n[c]=C(this.values)({step:a}).data,n},{});if(Array.isArray(e))return h(e.every(n=>r.includes(n)),()=>{const n=N(e,this.stepNumbers,t);return n.status==="error"?`${s()}. See errors:
5
- ${V(n.errors)}`:s()}),this.createCtxHelper(e);if(typeof e=="object"){const n=Object.keys(e);return h(n.every(a=>r.includes(a)),()=>{const a=N(n,r,t);return a.status==="error"?`${s()}. See errors:
6
- ${V(a.errors)}`:s()}),this.createCtxHelper(n)}throw new Error(`${s()} OR to "all"`)}createStepHelperFnImpl(e){return(t,r)=>{const s=this.createCtx(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"),G(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})`)}}}class ve{prefix;includeTimestamp;throwOnError;constructor(e){const{includeTimestamp:t,prefix:r,throwOnError:s}=e??{};this.prefix=r??"MultiStepFormSchema",this.includeTimestamp=t??!1,this.throwOnError=s??!1}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:a}=r??{},c=this.formatPrefix(n),y=this.wrapValue(a?.wrapWith??"[]",(a?.level??e).toUpperCase()),p=`${c} ${y} ${t}`;return s?`[${new Date().toISOString()}] ${p}`:p}info(e,t){console.info(this.formatMessage("info",e,t))}warn(e,t){console.warn(this.formatMessage("warn",e,t))}error(e,t){const r=this.formatMessage("error",e,t);if(console.error(r),t?.throw??this.throwOnError)throw new Error(r)}}const Y='"window" in undefined. No storage is available',K="MultiStepForm";class ie{key;store;data;log;isWindowUndefined;constructor(e){const{key:t,data:r,store:s}=e;this.log=new ve({prefix:K}),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(Y))}throwOnEmptyStore(){h(this.store,()=>this.isWindowUndefined?Y:"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 ge=["sentence","title","camel","lower","upper","pascal","snake","screaming-snake","flat","kebab"],P="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 H(o){return typeof o!="string"?!1:ge.includes(o)}function ue(o,e=P){return H(o)?o:e}const _e=["string","string.phone","string.email","string.time","number","number.counter","date","dateTime","boolean.switch"],Z="string";function Te(o){return typeof o=="string"&&_e.includes(o)}class ce{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(){}}const Ee=["string","number","array.string","array.string.untyped"],le=/^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 Oe(o){const e={},{fields:t,defaultCasing:r,validateFields:s}=o;for(const[n,a]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 a=="object",`The value for key ${n} must be an object. Was ${typeof a}`);const{defaultValue:c,label:y,nameTransformCasing:p,type:l=Z}=a;if(s)e[n]=c;else{const u=p??r;e[n]={...e[n],nameTransformCasing:u,type:l,defaultValue:c,label:X(y,n,u)}}}if(s){const n=G(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[a,c]of Object.entries(n)){const y=t[a];h(y,`No field found in the fields config for "${a}"`);const{label:p,type:l=Z,nameTransformCasing:u}=y,f=u??r;e[a]={...e[a],nameTransformCasing:f,type:l,defaultValue:c,label:X(p,a,f)}}}return e}function fe(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(le.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:a,nameTransformCasing:c=P,description:y,validateFields:p}=r,l=s.toString().replace("step","");h(n,`Missing fields for step ${l} (${String(s)})`,TypeError),h(typeof n=="object","Fields must be an object",TypeError),h(Object.keys(n).length>0,`The fields config for step ${l} (${String(s)}) is empty. Please add a field`),h(typeof n=="object",`The "fields" property must be an object. Was ${typeof n}`);const u=Oe({defaultCasing:c,fields:n,validateFields:p});e[s]={...e[s],title:a,nameTransformCasing:c,...typeof y=="string"?{description:y}:{},fields:u}}return e}class B extends ce{original;value;steps;defaultNameTransformationCasing;firstStep;lastStep;stepNumbers;storage;constructor(e){super();const{steps:t,nameTransformCasing:r,storage:s}=e;this.defaultNameTransformationCasing=ue(r),this.original=t,this.value=this.enrichValues(fe(this.original)),this.stepNumbers=Object.keys(this.value).map(n=>Number.parseInt(n.replace("step",""))),this.storage=new ie({data:this.value,key:s?.key??K,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(a=>`'${a}'`).join(" | ");if(n==="number")return this.stepNumbers.join(" | ");if(n.includes("array.string"))return this.stepNumbers.map(a=>`${a}`);throw new Error(`Transformation type "${n}" is not supported. Available transformations include: ${Ee.map(a=>`"${a}"`).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 C(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]:J(r,this.value[n][t])}},this.handlePostUpdate();return}if(typeof t=="object"||typeof t=="function"){const a=J(t,this.value[n]);h(typeof a=="object",`The updated data must be an object, was ${typeof a}`),this.value={...this.value,[n]:{...this.value[n],...a}},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=U(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"),G(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:a=>a!=="undefined"&&a!==null,label:a=>typeof a=="string"||typeof a=="boolean"&&!a,nameTransformCasing:H,type:Te}))return!1}return!0},createHelperFn:r=>typeof r=="function",update:r=>typeof r=="function",nameTransformCasing:H,...t?.optionalKeysToCheck})}}class $e extends ce{stepHelper;defaultNameTransformationCasing;stepSchema;storage;mountCount=0;constructor(e){super();const{steps:t,nameTransformCasing:r,storage:s}=e;this.defaultNameTransformationCasing=ue(r),this.stepSchema=new B({steps:t,nameTransformCasing:this.defaultNameTransformationCasing}),this.stepHelper=new be(this.stepSchema.value,this.stepSchema.steps.value),this.storage=new ie({key:s?.key??K,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 Ce(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 pe(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 de extends B{value;constructor(e){const{form:t,...r}=e;super(r),this.value=this.enrichValues(fe(this.original)),this.value=this.enrichValues(this.value,s=>{const n=`step${s}`,a=t?.id??n;return{createComponent:this.createComponentForStep([`step${s}`],{isStepSpecific:!0,defaultId:a,form:t})}})}createFormComponent(e,t){const{render:r,enabledForSteps:s="all",id:n=t}=e,a={id:n,steps:U(this.value,s)};return c=>r(a,c)}createStepSpecificComponentImpl(e,t,r,s={}){return n=>(a=>{const c={};for(const[l,u]of Object.entries(s))if(typeof u=="function")try{const f=u();c[l]=f,typeof console<"u"&&console.debug&&console.debug(`[multi-step-form] Hook "${l}" called successfully`,{result:f!==void 0?"defined":"undefined"})}catch(f){const i=f instanceof Error?f.message:String(f);throw new Error(`[multi-step-form] Error calling hook "${l}" in useFormInstance.render: ${i}
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}
7
9
 
8
10
  This usually means:
9
11
  1. The hook is being called outside of a React component
10
12
  2. The hook has invalid dependencies or configuration
11
13
  3. There's an error in your hook implementation
12
14
 
13
- Original error: ${i}`,{cause:f})}else c[l]=u;const{defaultId:y,form:p}=t;if(p){const{alias:l=$.DEFAULT_FORM_ALIAS,...u}=p,f=u.enabledForSteps??"all",[i]=e;h(this.steps.isValidStepKey(i),`[createComponent]: the target step ${i} 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(i.replace("step",""));h(!Number.isNaN(m),`[${i}:"createComponent"]: an error occurred while extracting the number`);const d=this.value[i];h("fields"in d,`[${i}:createComponent]: unable to find the "fields" for the current step`),h(typeof d.fields=="object",`[${i}:createComponent]: the "fields" property must be an object, was ${typeof d.fields}`);const S=Ce(g=>{h(typeof g=="string",()=>{const L=new Intl.ListFormat("en",{style:"long",type:"disjunction"});return`[${i}:Field]: the "name" prop must be a string and a valid field for ${i}. Available fields include ${L.format(Object.keys(d.fields))}`}),h(g in d.fields,`[${i}:Field]: the field "${g}" doesn't exist for the current step`);const{fields:_,update:T}=d,{defaultValue:E,label:b,nameTransformCasing:w,type:O}=_[g];return{defaultValue:E,label:b,nameTransformCasing:w,type:O,name:g,onInputChange:L=>T("fields",z=>({...z,[g]:{...z[g],defaultValue:L}}))}});let v={ctx:r,onInputChange:this.createStepUpdaterFn(m),Field:S,...c};return $.isFormAvailable(e,f)&&(v={...v,[l]:this.createFormComponent(u,y)}),n(v,a)}return n({ctx:r,[$.DEFAULT_FORM_ALIAS]:$.createDefaultForm(y)},a)})}createStepSpecificComponentFactory(e,t,r){const s=this.createStepSpecificComponentImpl.bind(this),n=this.createDefaultValues.bind(this);function a(c,y){function p(){return h(typeof c=="function","The first argument must be a function"),s(e,t,r)(c)}if(typeof c=="object"){const{useFormInstance:l}=c;if(l){const{render:u,alias:f=exports.StepSpecificComponent.DEFAULT_FORM_INSTANCE_ALIAS}=l;h(typeof y=="function","The second argument must be a function");const[i]=e,m=n(i),d={ctx:r,defaultValues:m};return s(e,t,r,{[f]:()=>u(d)})(y)}return p()}return p()}return a}createComponentImpl(e,t){const r=U(this.value,e);return t.isStepSpecific?this.createStepSpecificComponentFactory(e,t,r):s=>(n=>s({ctx:r},n))}createComponentForStep(e,t){return this.createComponentImpl(e,t)}createComponent(e,t){return this.createComponentImpl(e.stepData,{isStepSpecific:!1})(t)}createDefaultValues(e){return pe(this.value,e)}}class he extends $e{stepSchema;constructor(e){const{nameTransformCasing:t=P,storage:r,...s}=e;super({nameTransformCasing:t,storage:r,...s}),this.stepSchema=new de({nameTransformCasing:t,...s})}createComponent(e,t){const{stepData:r}=e,s=this.stepHelper.createCtx(r);return(n=>t({ctx:s},n))}}function je(o){return new he(o)}var A={exports:{}},x={},F={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={};/**
14
16
  * @license React
15
17
  * use-sync-external-store-shim.production.js
16
18
  *
@@ -18,7 +20,7 @@ Original error: ${i}`,{cause:f})}else c[l]=u;const{defaultId:y,form:p}=t;if(p){c
18
20
  *
19
21
  * This source code is licensed under the MIT license found in the
20
22
  * LICENSE file in the root directory of this source tree.
21
- */var ee;function Ae(){if(ee)return D;ee=1;var o=I;function e(u,f){return u===f&&(u!==0||1/u===1/f)||u!==u&&f!==f}var t=typeof Object.is=="function"?Object.is:e,r=o.useState,s=o.useEffect,n=o.useLayoutEffect,a=o.useDebugValue;function c(u,f){var i=f(),m=r({inst:{value:i,getSnapshot:f}}),d=m[0].inst,S=m[1];return n(function(){d.value=i,d.getSnapshot=f,y(d)&&S({inst:d})},[u,i,f]),s(function(){return y(d)&&S({inst:d}),u(function(){y(d)&&S({inst:d})})},[u]),a(i),i}function y(u){var f=u.getSnapshot;u=u.value;try{var i=f();return!t(u,i)}catch{return!0}}function p(u,f){return f()}var l=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?p:c;return D.useSyncExternalStore=o.useSyncExternalStore!==void 0?o.useSyncExternalStore:l,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={};/**
22
24
  * @license React
23
25
  * use-sync-external-store-shim.development.js
24
26
  *
@@ -26,7 +28,7 @@ Original error: ${i}`,{cause:f})}else c[l]=u;const{defaultId:y,form:p}=t;if(p){c
26
28
  *
27
29
  * This source code is licensed under the MIT license found in the
28
30
  * LICENSE file in the root directory of this source tree.
29
- */var te;function Fe(){return te||(te=1,process.env.NODE_ENV!=="production"&&(function(){function o(i,m){return i===m&&(i!==0||1/i===1/m)||i!==i&&m!==m}function e(i,m){l||s.startTransition===void 0||(l=!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 d=m();if(!u){var S=m();n(d,S)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}S=a({inst:{value:d,getSnapshot:m}});var v=S[0].inst,g=S[1];return y(function(){v.value=d,v.getSnapshot=m,t(v)&&g({inst:v})},[i,d,m]),c(function(){return t(v)&&g({inst:v}),i(function(){t(v)&&g({inst:v})})},[i]),p(d),d}function t(i){var m=i.getSnapshot;i=i.value;try{var d=m();return!n(i,d)}catch{return!0}}function r(i,m){return m()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var s=I,n=typeof Object.is=="function"?Object.is:o,a=s.useState,c=s.useEffect,y=s.useLayoutEffect,p=s.useDebugValue,l=!1,u=!1,f=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:e;k.useSyncExternalStore=s.useSyncExternalStore!==void 0?s.useSyncExternalStore:f,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),k}var re;function me(){return re||(re=1,process.env.NODE_ENV==="production"?F.exports=Ae():F.exports=Fe()),F.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}/**
30
32
  * @license React
31
33
  * use-sync-external-store-shim/with-selector.production.js
32
34
  *
@@ -34,7 +36,7 @@ Original error: ${i}`,{cause:f})}else c[l]=u;const{defaultId:y,form:p}=t;if(p){c
34
36
  *
35
37
  * This source code is licensed under the MIT license found in the
36
38
  * LICENSE file in the root directory of this source tree.
37
- */var ne;function Ne(){if(ne)return x;ne=1;var o=I,e=me();function t(p,l){return p===l&&(p!==0||1/p===1/l)||p!==p&&l!==l}var r=typeof Object.is=="function"?Object.is:t,s=e.useSyncExternalStore,n=o.useRef,a=o.useEffect,c=o.useMemo,y=o.useDebugValue;return x.useSyncExternalStoreWithSelector=function(p,l,u,f,i){var m=n(null);if(m.current===null){var d={hasValue:!1,value:null};m.current=d}else d=m.current;m=c(function(){function v(b){if(!g){if(g=!0,_=b,b=f(b),i!==void 0&&d.hasValue){var w=d.value;if(i(w,b))return T=w}return T=b}if(w=T,r(_,b))return w;var O=f(b);return i!==void 0&&i(w,O)?(_=b,w):(_=b,T=O)}var g=!1,_,T,E=u===void 0?null:u;return[function(){return v(l())},E===null?void 0:function(){return v(E())}]},[l,u,f,i]);var S=s(p,m[0],m[1]);return a(function(){d.hasValue=!0,d.value=S},[S]),y(S),S},x}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={};/**
38
40
  * @license React
39
41
  * use-sync-external-store-shim/with-selector.development.js
40
42
  *
@@ -42,5 +44,5 @@ Original error: ${i}`,{cause:f})}else c[l]=u;const{defaultId:y,form:p}=t;if(p){c
42
44
  *
43
45
  * This source code is licensed under the MIT license found in the
44
46
  * LICENSE file in the root directory of this source tree.
45
- */var se;function Ve(){return se||(se=1,process.env.NODE_ENV!=="production"&&(function(){function o(p,l){return p===l&&(p!==0||1/p===1/l)||p!==p&&l!==l}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var e=I,t=me(),r=typeof Object.is=="function"?Object.is:o,s=t.useSyncExternalStore,n=e.useRef,a=e.useEffect,c=e.useMemo,y=e.useDebugValue;M.useSyncExternalStoreWithSelector=function(p,l,u,f,i){var m=n(null);if(m.current===null){var d={hasValue:!1,value:null};m.current=d}else d=m.current;m=c(function(){function v(b){if(!g){if(g=!0,_=b,b=f(b),i!==void 0&&d.hasValue){var w=d.value;if(i(w,b))return T=w}return T=b}if(w=T,r(_,b))return w;var O=f(b);return i!==void 0&&i(w,O)?(_=b,w):(_=b,T=O)}var g=!1,_,T,E=u===void 0?null:u;return[function(){return v(l())},E===null?void 0:function(){return v(E())}]},[l,u,f,i]);var S=s(p,m[0],m[1]);return a(function(){d.hasValue=!0,d.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"?A.exports=Ne():A.exports=Ve()),A.exports}var Le=Ie();function W(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(le.test(e),`The target step must match the following format: "step{number}". Available steps are ${n}`);const a=Number.parseInt(e.replace("step",""));return h(r(a),`The step number "${a}" is not a valid step number. Valid step numbers include ${n}`,TypeError),a}function ye(o){function e(t){return Le.useSyncExternalStoreWithSelector(o.subscribe,()=>o.getSnapshot(),()=>o.getSnapshot(),r=>{if(typeof t=="object"){const s=W(r,t.targetStep);return r.stepSchema.get({step:s}).data}return typeof t=="function"?t(r):r})}return e}function xe(o,e){const t=ye(o);return typeof e=="object"||typeof e=="function"?t(e):t()}function ae(o){return function(e){return(t=>e(o,t))}}function De(o){const e=ye(o);function t(c){const{targetStep:y,notFoundMessage:p,isDataGuaranteed:l}=c,u=e({targetStep:y}),f=p?a({targetStep:y},p):i=>R.jsxs("div",{...i,children:["No data found for step ",String(y)]});return l?{data:u,NoCurrentData:f}:B.hasData(u)?{data:u,hasData:!0,NoCurrentData:f}:{data:void 0,hasData:!1,NoCurrentData:f}}function r(c){const y=e(S=>S.stepSchema.steps.value.length),{targetStep:p,maxProgressValue:l=100,totalSteps:u=y,progressTextTransformer:f}=c,i=W(o,p),m=i/u*l,d=f?n({targetStep:p,maxProgressValue:l,totalSteps:u},f):S=>R.jsxs("div",{...S,children:["Step ",i,"/",u]});return{value:m,maxProgressValue:l,ProgressText:d}}function s(c){const p=e(u=>u.storage).get(),l=!!(p&&typeof p=="object"&&Object.keys(p).length>0);return c?c(l):l}function n(c,y){const p=o.getSnapshot().stepSchema.steps.value.length,{targetStep:l,maxProgressValue:u=100,totalSteps:f=p}=c;return ae({targetStep:l,maxProgressValue:u,totalSteps:f})(y)}function a(c,y){return W(o,c.targetStep),ae(c)(y)}return{useMultiStepFormData:e,useCurrentStepData:t,useProgress:r,useCanRestartForm:s,withProgressText:n,withNoStepDataFound:a}}exports.MultiStepFormSchema=he;exports.MultiStepFormStepSchema=de;exports.createDefaultValues=pe;exports.createMultiStepFormContext=De;exports.createMultiStepFormSchema=je;exports.useMultiStepFormData=xe;
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;
46
48
  //# sourceMappingURL=index.cjs.map