@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 +13 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1048 -648
- package/dist/index.mjs.map +1 -1
- package/dist/types/step-schema.d.ts +6 -8
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`)}function
|
|
3
|
-
${
|
|
4
|
-
|
|
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: ${
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|