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