@lehnihon/bit-form 2.0.0 → 2.0.1

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.
@@ -1,4 +1,4 @@
1
- var N=typeof globalThis<"u"?globalThis:typeof global<"u"?global:window;N.__BIT_FORM__||(N.__BIT_FORM__={stores:{},listeners:new Set,dispatch(n,t){this.listeners.forEach(e=>e(n,t))},subscribe(n){return this.listeners.add(n),()=>{this.listeners.delete(n)}}});var m=N.__BIT_FORM__;function f(n){if(n===null||typeof n!="object")return n;if(n instanceof Date)return new Date(n.getTime());if(n instanceof RegExp)return new RegExp(n.source,n.flags);if(Array.isArray(n))return n.map(e=>f(e));let t={};for(let e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=f(n[e]));return t}function x(n,t){return n===t?!0:n===null||typeof n!="object"||t===null||typeof t!="object"?!1:T(n,t)}function T(n,t){if(n===t)return!0;if(n===null||typeof n!="object"||t===null||typeof t!="object")return!1;if(n instanceof Date&&t instanceof Date)return n.getTime()===t.getTime();if(n instanceof RegExp&&t instanceof RegExp)return n.toString()===t.toString();let e=Object.keys(n),s=Object.keys(t);if(e.length!==s.length)return!1;for(let r of e)if(!Object.prototype.hasOwnProperty.call(t,r)||!T(n[r],t[r]))return!1;return!0}function j(n,t,e="",s=new Set){if(x(n,t))return s;if(n===null||typeof n!="object"||t===null||typeof t!="object")return e&&s.add(e),s;if(Array.isArray(n)||Array.isArray(t))return!x(n,t)&&e&&s.add(e),s;let r=new Set([...Object.keys(n||{}),...Object.keys(t||{})]);for(let i of r){let o=e?`${e}.${i}`:i;j(n?.[i],t?.[i],o,s)}return s}var k=new Map;function u(n,t){if(!t)return n;let e=k.get(t)||t.split(".");k.has(t)||k.set(t,e);let s=n;for(let r of e){if(s==null)return;s=s[r]}return s}function y(n,t,e){if(!t)return e;let s=k.get(t)||t.split(".");k.has(t)||k.set(t,s);let r=Array.isArray(n)?[...n]:{...n},i=r;for(let o=0;o<s.length-1;o++){let a=s[o],l=s[o+1],c=/^\d+$/.test(l),d=i[a];d==null?i[a]=c?[]:{}:i[a]=Array.isArray(d)?[...d]:{...d},i=i[a]}return i[s[s.length-1]]=e,r}function Pt(n,t){let e={},s=`${t}.`;for(let r in n)r!==t&&!r.startsWith(s)&&(e[r]=n[r]);return e}var q=(n,t,e)=>{let s={},r=`${t}.`;return Object.keys(n).forEach(i=>{if(!i.startsWith(r)){s[i]=n[i];return}let a=i.substring(r.length).split("."),l=parseInt(a[0],10),c=a.slice(1).join(".");if(l!==e)if(l>e){let d=l-1,p=c?`${r}${d}.${c}`:`${r}${d}`;s[p]=n[i]}else s[i]=n[i]}),s},_=(n,t,e,s)=>{let r={},i=`${t}.`;return Object.keys(n).forEach(o=>{if(!o.startsWith(i)){r[o]=n[o];return}let l=o.substring(i.length).split("."),c=parseInt(l[0],10),d=l.slice(1).join(".");if(c===e){let p=d?`${i}${s}.${d}`:`${i}${s}`;r[p]=n[o]}else if(c===s){let p=d?`${i}${e}.${d}`:`${i}${e}`;r[p]=n[o]}else r[o]=n[o]}),r},X=(n,t,e,s)=>{let r={},i=`${t}.`;return Object.keys(n).forEach(o=>{if(!o.startsWith(i)){r[o]=n[o];return}let l=o.substring(i.length).split("."),c=parseInt(l[0],10),d=l.slice(1).join("."),p=c;c===e?p=s:e<s&&c>e&&c<=s?p=c-1:e>s&&c>=s&&c<e&&(p=c+1);let h=d?`${i}${p}.${d}`:`${i}${p}`;r[h]=n[o]}),r};function bt(n){if(typeof n!="object"||n===null||Array.isArray(n))return!1;let t=n.errors??n;return typeof t!="object"||t===null||Array.isArray(t)?!1:Object.values(t).every(e=>typeof e=="string"||Array.isArray(e)&&e.every(s=>typeof s=="string"))}function Ct(n){return bt(n)?n.errors??n:{}}var vt={"#":/\d/,A:/[a-zA-Z]/,X:/[a-zA-Z0-9]/,H:/[0-9a-fA-F]/,U:/[A-Z]/,L:/[a-z]/,"*":/./},M=(n,t)=>{if(n==null||n==="")return"";let e=String(n),s=e.startsWith("-"),r=t?t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):"",i=new RegExp(`[^a-zA-Z0-9${r}]`,"g"),o=e.replace(i,"");return s&&o&&!o.startsWith("-")?`-${o}`:o},xt=(n,t=2)=>{if(typeof n=="number")return n;if(!n)return 0;let e=String(n),s=e.includes("-"),r=e.replace(/\D/g,"");if(!r)return 0;let i=parseInt(r,10)/Math.pow(10,t);return s?-i:i},g=(n,t)=>{let e=s=>s.split("").filter(r=>vt[r]).length;return{format:s=>{let r=M(s,t?.allowChars);if(!r&&!t?.guide)return"";let o=[...Array.isArray(n)?n:[n]].sort((h,v)=>e(h)-e(v)),a=o[o.length-1];for(let h of o)if(r.length<=e(h)){a=h;break}let l="",c=0,d=t?.guide||!1,p=t?.placeholderChar||"_";for(let h=0;h<a.length;h++){let v=a[h],P=vt[v];if(c<r.length){let S=r[c];if(P)if(v==="U"&&(S=S.toUpperCase()),v==="L"&&(S=S.toLowerCase()),P.test(S))l+=S,c++;else if(d)l+=p;else break;else l+=v,S===v&&c++}else if(d)l+=P?p:v;else break}return l},parse:s=>{if(t?.customParse)return t.customParse(s);let i=g(n,t).format(s);if(t?.saveRaw){if(t?.guide){let a=(t.placeholderChar||"_").replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),l=new RegExp(a,"g");return i.replace(l,"")}return i}return M(i,t?.allowChars)}}},b=({prefix:n="",suffix:t="",thousand:e,decimal:s,precision:r=2,allowNegative:i=!0,saveRaw:o=!1})=>{let a=l=>{if(l==null||l==="")return"";let c="";if(typeof l=="number"?c=Math.abs(l).toFixed(r).replace(/\D/g,""):c=String(l).replace(/\D/g,""),!c&&String(l).includes("-")&&i)return"-";if(!c)return"";c=c.padStart(r+1,"0");let d=c.slice(0,-r).replace(/^0+(?=\d)/,"")||"0",p=c.slice(-r),h=d.replace(/\B(?=(\d{3})+(?!\d))/g,e);return`${(typeof l=="number"?l<0:String(l).includes("-"))&&i?"-":""}${n}${h}${s}${p}${t}`};return{format:a,parse:l=>{let c=xt(l,r),d=i?c:Math.abs(c);return o?a(d):d}}},z=n=>{let t=e=>/^3[47]/.test(e)?"#### ###### #####":/^3(?:0[0-5]|[68])/.test(e)?"#### ###### ####":"#### #### #### ####";return{format:e=>{let s=M(e,n?.allowChars),r=t(s);return g(r,n).format(e)},parse:e=>{let s=M(e,n?.allowChars),r=t(s);return g(r,n).parse(e)}}},C=n=>{let e=(n?.format||"DD/MM/YYYY")==="YYYY-MM-DD",s=g(e?"####-##-##":"##/##/####",n);return{format:r=>{let i=M(r);if(!i)return"";let o="",a="",l="";if(e?(l=i.substring(0,4),a=i.substring(4,6),o=i.substring(6,8)):(o=i.substring(0,2),a=i.substring(2,4),l=i.substring(4,8)),o.length===2){let d=parseInt(o,10);d>31&&(o="31"),d===0&&(o="01")}if(a.length===2){let d=parseInt(a,10);d>12&&(a="12"),d===0&&(a="01")}let c=e?`${l}${a}${o}`:`${o}${a}${l}`;return s.format(c)},parse:r=>s.parse(r)}};var W=b({prefix:"R$ ",thousand:".",decimal:",",precision:2}),Y=b({prefix:"$",thousand:",",decimal:".",precision:2}),J=b({suffix:" \u20AC",thousand:".",decimal:",",precision:2}),K=b({prefix:"\xA3",thousand:",",decimal:".",precision:2}),G=b({prefix:"\xA5",thousand:",",decimal:".",precision:0}),Z=b({suffix:"%",thousand:".",decimal:",",precision:1}),Q=b({thousand:".",decimal:",",precision:2}),tt=b({thousand:".",decimal:",",precision:0}),et=g("###.###.###-##"),st=g("##.###.###/####-##"),rt=g(["(##) ####-####","(##) #####-####"]),it=g("(##) ####-####"),nt=g("#####-###"),ot=C({format:"DD/MM/YYYY",guide:!0,customParse:n=>{let t=n.replace(/_/g,""),e=t.split("/");return e.length===3&&e[2].length===4?`${e[2]}-${e[1]}-${e[0]}`:t.replace(/\D/g,"")}}),at=g("##:##"),lt=g("###########"),ct=g("##.###.###-X"),Vt=g("(###) ###-####"),Dt=g("#####-####"),Rt=g("##/##/####"),wt=g("###-##-####"),dt=z(),ut=g("####"),It=C({format:"YYYY-MM-DD",saveRaw:!0,guide:!0}),gt=g("HH:HH:HH:HH:HH:HH"),pt=g("#HHHHHH"),ft=g("###.###.###.###"),ht=g("HHHH:HHHH:HHHH:HHHH:HHHH:HHHH:HHHH:HHHH"),Ht=g("UU## XXXX XXXX XXXX XXXX XXXX XXXX XXXX XX",{allowChars:" "});var mt={brl:W,usd:Y,eur:J,gbp:K,jpy:G,cpf:et,cnpj:st,rg:ct,cep:nt,cnh:lt,phone:rt,landline:it,date:ot,time:at,ip:ft,ipv6:ht,mac:gt,color:pt,cc:dt,cvv:ut,percent:Z,decimal:Q,int:tt};function Ft(n){let t={},e={},s={};if(!n)return{computed:t,transform:e,scopes:s};for(let[r,i]of Object.entries(n))i?.computed&&(t[r]=i.computed),i?.transform&&(e[r]=i.transform),i?.scope&&(s[i.scope]||(s[i.scope]=[]),s[i.scope].push(r));return{computed:Object.keys(t).length?t:void 0,transform:Object.keys(e).length?e:void 0,scopes:Object.keys(s).length?s:void 0}}function Tt(n={}){let t=n.initialValues||{},e=n.validation,s=n.history,{computed:r,transform:i,scopes:o}=Ft(n.fields);return{name:n.name,initialValues:f(t),resolver:e?.resolver,validationDelay:e?.delay??300,enableHistory:s?.enabled??!1,historyLimit:s?.limit??15,computed:r,transform:i,scopes:o,masks:mt,fields:n.fields,devTools:n.devTools}}var V=class{fieldConfigs=new Map;dependencies=new Map;hiddenFields=new Set;register(t,e,s){this.fieldConfigs.set(t,e);let r=e.conditional?.dependsOn;r&&r.forEach(i=>{this.dependencies.has(i)||this.dependencies.set(i,new Set),this.dependencies.get(i).add(t)}),this.evaluateFieldCondition(t,s)}isHidden(t){return this.hiddenFields.has(t)}isRequired(t,e){let s=this.fieldConfigs.get(t);return!s||this.isHidden(t)?!1:!!s.conditional?.requiredIf?.(e)}getRequiredErrors(t){let e={};return this.fieldConfigs.forEach((s,r)=>{if(this.isRequired(r,t)){let i=u(t,r);this.isEmpty(i)&&(e[r]=s.conditional?.requiredMessage??"required field")}}),e}evaluateAll(t){this.fieldConfigs.forEach((e,s)=>{this.evaluateFieldCondition(s,t)})}updateDependencies(t,e){let s=[],r=this.dependencies.get(t);return r&&r.forEach(i=>{let o=this.isHidden(i);this.evaluateFieldCondition(i,e);let a=this.isHidden(i);o!==a&&s.push(i)}),s}unregister(t){this.fieldConfigs.delete(t),this.hiddenFields.delete(t),this.dependencies.delete(t),this.dependencies.forEach(e=>{e.delete(t)})}unregisterPrefix(t){let e=[];this.fieldConfigs.forEach((s,r)=>{r.startsWith(t)&&e.push(r)}),e.forEach(s=>this.unregister(s))}evaluateFieldCondition(t,e){let r=this.fieldConfigs.get(t)?.conditional?.showIf;r&&(r(e)?this.hiddenFields.delete(t):this.hiddenFields.add(t))}isEmpty(t){return t==null||typeof t=="string"&&t.trim()===""||Array.isArray(t)&&t.length===0}};var D=class{constructor(t,e=15){this.enableHistory=t;this.maxHistory=e}history=[];historyIndex=-1;saveSnapshot(t){if(!this.enableHistory)return;let e=this.history[this.historyIndex];e&&T(e,t)||(this.historyIndex<this.history.length-1&&(this.history=this.history.slice(0,this.historyIndex+1)),this.history.push(f(t)),this.history.length>this.maxHistory?this.history.shift():this.historyIndex++)}get canUndo(){return this.enableHistory?this.historyIndex>0:!1}get canRedo(){return this.enableHistory?this.historyIndex<this.history.length-1:!1}undo(){return this.canUndo?(this.historyIndex--,f(this.history[this.historyIndex])):null}redo(){return this.canRedo?(this.historyIndex++,f(this.history[this.historyIndex])):null}reset(t){this.history=[],this.historyIndex=-1,this.saveSnapshot(t)}getMetadata(){return{enabled:this.enableHistory,canUndo:this.canUndo,canRedo:this.canRedo,historyIndex:this.historyIndex,historySize:this.history.length}}};var R=class{constructor(t){this.store=t}pushItem(t,e){let s=u(this.store.getState().values,t)||[];this.store.setField(t,[...s,e]),this.store.internalSaveSnapshot()}prependItem(t,e){let s=u(this.store.getState().values,t)||[];this.store.setField(t,[e,...s]),this.store.internalSaveSnapshot()}insertItem(t,e,s){let r=[...u(this.store.getState().values,t)||[]];r.splice(e,0,s),this.store.setField(t,r),this.store.internalSaveSnapshot()}removeItem(t,e){let s=this.store.getState(),r=u(s.values,t);if(!Array.isArray(r))return;this.store.unregisterPrefix&&this.store.unregisterPrefix(`${t}.${e}.`);let i=r.filter((l,c)=>c!==e),o=y(s.values,t,i),a=this.store.dirtyMg.updateForPath(t,o,this.store.getConfig().initialValues);this.store.internalUpdateState({values:o,errors:q(s.errors,t,e),touched:q(s.touched,t,e),isDirty:a}),this.store.internalSaveSnapshot(),this.revalidate(t)}swapItems(t,e,s){let r=this.store.getState(),i=[...u(r.values,t)||[]];[i[e],i[s]]=[i[s],i[e]];let o=y(r.values,t,i),a=this.store.dirtyMg.updateForPath(t,o,this.store.getConfig().initialValues);this.store.internalUpdateState({values:o,errors:_(r.errors,t,e,s),touched:_(r.touched,t,e,s),isDirty:a}),this.store.internalSaveSnapshot(),this.revalidate(t)}moveItem(t,e,s){let r=this.store.getState(),i=[...u(r.values,t)||[]],[o]=i.splice(e,1);i.splice(s,0,o);let a=y(r.values,t,i),l=this.store.dirtyMg.updateForPath(t,a,this.store.getConfig().initialValues);this.store.internalUpdateState({values:a,errors:X(r.errors,t,e,s),touched:X(r.touched,t,e,s),isDirty:l}),this.store.internalSaveSnapshot(),this.revalidate(t)}revalidate(t){let e=this.store;typeof e.triggerValidation=="function"?e.triggerValidation([t]):typeof this.store.validate=="function"&&this.store.validate()}};var w=class{constructor(t){this.config=t}apply(t){if(!this.config.computed)return t;let e=t,s=Object.entries(this.config.computed);for(let r=0;r<2;r++){let i=!1;for(let[o,a]of s){let l=a(e),c=u(e,o);T(c,l)||(e=y(e,o,l),i=!0)}if(!i)break}return e}};var I=class{constructor(t){this.store=t}validationTimeout;currentValidationId=0;asyncTimers={};asyncRequests={};asyncErrors={};handleAsync(t,e){let s=this.store.depsMg.fieldConfigs.get(t)||this.store.config.fields?.[t],r=s?.validation?.asyncValidate;if(!r)return;this.asyncTimers[t]&&clearTimeout(this.asyncTimers[t]);let i=s.validation?.asyncValidateDelay??500;this.asyncTimers[t]=setTimeout(async()=>{let o=(this.asyncRequests[t]||0)+1;this.asyncRequests[t]=o,this.store.internalUpdateState({isValidating:{...this.store.getState().isValidating,[t]:!0}});try{let a=await r(e,this.store.getState().values);if(this.asyncRequests[t]!==o)return;if(a)this.asyncErrors[t]=a,this.store.setError(t,a);else{delete this.asyncErrors[t];let l=this.store;if(l.validate)await l.validate({scopeFields:[t]});else{let c={...this.store.getState().errors};delete c[t],this.store.internalUpdateState({errors:c,isValid:Object.keys(c).length===0})}}}finally{this.asyncRequests[t]===o&&this.store.internalUpdateState({isValidating:{...this.store.getState().isValidating,[t]:!1}})}},i)}trigger(t){this.validationTimeout&&clearTimeout(this.validationTimeout);let e=this.store.config.validationDelay??300;e>0?this.validationTimeout=setTimeout(()=>{this.validate({scopeFields:t})},e):this.validate({scopeFields:t})}async validate(t){let e=++this.currentValidationId,s=this.store.getState(),r=t?.scopeFields;t?.scope&&this.store.config.scopes?.[t.scope]&&(r=this.store.config.scopes[t.scope]);let i=this.store.config.resolver?await this.store.config.resolver(s.values,{scopeFields:r}):{},o=this.store.depsMg.getRequiredErrors(s.values);if(i={...i,...o},this.store.depsMg.hiddenFields.forEach(l=>{delete i[l],delete this.asyncErrors[l]}),e!==this.currentValidationId)return s.isValid;if(r){let l={...s.errors};r.forEach(d=>{i[d]?l[d]=i[d]:this.asyncErrors[d]?l[d]=this.asyncErrors[d]:delete l[d]});let c=Object.keys(l).length===0;return this.store.internalUpdateState({errors:l,isValid:c}),r.every(d=>!i[d]&&!this.asyncErrors[d])}i={...this.asyncErrors,...i};let a=Object.keys(i).length===0;return this.store.internalUpdateState({errors:i,isValid:a}),a}clear(t){this.asyncTimers[t]&&clearTimeout(this.asyncTimers[t]),delete this.asyncErrors[t]}cancelAll(){this.validationTimeout&&clearTimeout(this.validationTimeout),Object.values(this.asyncTimers).forEach(t=>clearTimeout(t))}};var H=class{constructor(t){this.store=t}updateField(t,e){let s=this.store.getState(),r=y(s.values,t,e),i={...s.errors};delete i[t],this.store.validatorMg.clear(t);let o=this.store.depsMg.updateDependencies(t,r);o.forEach(l=>{this.store.depsMg.isHidden(l)&&(delete i[l],this.store.validatorMg.clear(l))});let a=this.store.dirtyMg.updateForPath(t,r,this.store.config.initialValues);return this.store.internalUpdateState({values:r,errors:i,isValid:Object.keys(i).length===0,isDirty:a}),this.store.config.resolver&&this.store.validatorMg.trigger([t]),this.store.validatorMg.handleAsync(t,e),{visibilitiesChanged:o.length>0}}updateAll(t){let e=f(t);this.store.config.initialValues=f(e),this.store.validatorMg.cancelAll(),this.store.depsMg.evaluateAll(e),this.store.dirtyMg.clear(),this.store.internalUpdateState({values:e,errors:{},touched:{},isValidating:{},isValid:!0,isDirty:!1,isSubmitting:!1}),this.store.internalSaveSnapshot(),this.store.validatorMg.validate()}async submit(t){if(this.store.getState().isSubmitting)return;if(this.store.validatorMg.cancelAll(),this.store.internalUpdateState({isSubmitting:!0}),await this.store.validatorMg.validate())try{let r=f(this.store.getState().values);if(this.store.depsMg.hiddenFields.forEach(o=>{r=y(r,o,void 0)}),this.store.config.transform)for(let o in this.store.config.transform){let a=this.store.config.transform[o];if(a){let l=u(r,o);r=y(r,o,a(l,this.store.getState().values))}}let i=this.store.dirtyMg.buildDirtyValues(r);await t(r,i)}catch(r){console.error(r)}else{let r=this.store.getState().errors,i={...this.store.getState().touched};Object.keys(r).forEach(o=>{i[o]=!0}),this.store.internalUpdateState({touched:i})}this.store.internalUpdateState({isSubmitting:!1})}reset(){this.store.validatorMg.cancelAll();let t=f(this.store.config.initialValues);this.store.depsMg.evaluateAll(t),this.store.dirtyMg.clear(),this.store.internalUpdateState({values:t,errors:{},touched:{},isValidating:{},isValid:!0,isDirty:!1,isSubmitting:!1}),this.store.historyMg.reset(t)}};function St(){return`
1
+ var N=typeof globalThis<"u"?globalThis:typeof global<"u"?global:window;N.__BIT_FORM__||(N.__BIT_FORM__={stores:{},listeners:new Set,dispatch(o,t){this.listeners.forEach(e=>e(o,t))},subscribe(o){return this.listeners.add(o),()=>{this.listeners.delete(o)}}});var m=N.__BIT_FORM__;function f(o){if(o===null||typeof o!="object")return o;if(o instanceof Date)return new Date(o.getTime());if(o instanceof RegExp)return new RegExp(o.source,o.flags);if(Array.isArray(o))return o.map(e=>f(e));let t={};for(let e in o)Object.prototype.hasOwnProperty.call(o,e)&&(t[e]=f(o[e]));return t}function x(o,t){return o===t?!0:o===null||typeof o!="object"||t===null||typeof t!="object"?!1:T(o,t)}function T(o,t){if(o===t)return!0;if(o===null||typeof o!="object"||t===null||typeof t!="object")return!1;if(o instanceof Date&&t instanceof Date)return o.getTime()===t.getTime();if(o instanceof RegExp&&t instanceof RegExp)return o.toString()===t.toString();let e=Object.keys(o),s=Object.keys(t);if(e.length!==s.length)return!1;for(let r of e)if(!Object.prototype.hasOwnProperty.call(t,r)||!T(o[r],t[r]))return!1;return!0}function j(o,t,e="",s=new Set){if(x(o,t))return s;if(o===null||typeof o!="object"||t===null||typeof t!="object")return e&&s.add(e),s;if(Array.isArray(o)||Array.isArray(t))return!x(o,t)&&e&&s.add(e),s;let r=new Set([...Object.keys(o||{}),...Object.keys(t||{})]);for(let i of r){let n=e?`${e}.${i}`:i;j(o?.[i],t?.[i],n,s)}return s}var k=new Map;function u(o,t){if(!t)return o;let e=k.get(t)||t.split(".");k.has(t)||k.set(t,e);let s=o;for(let r of e){if(s==null)return;s=s[r]}return s}function y(o,t,e){if(!t)return e;let s=k.get(t)||t.split(".");k.has(t)||k.set(t,s);let r=Array.isArray(o)?[...o]:{...o},i=r;for(let n=0;n<s.length-1;n++){let a=s[n],l=s[n+1],c=/^\d+$/.test(l),d=i[a];d==null?i[a]=c?[]:{}:i[a]=Array.isArray(d)?[...d]:{...d},i=i[a]}return i[s[s.length-1]]=e,r}function Pt(o,t){let e={},s=`${t}.`;for(let r in o)r!==t&&!r.startsWith(s)&&(e[r]=o[r]);return e}var q=(o,t,e)=>{let s={},r=`${t}.`;return Object.keys(o).forEach(i=>{if(!i.startsWith(r)){s[i]=o[i];return}let a=i.substring(r.length).split("."),l=parseInt(a[0],10),c=a.slice(1).join(".");if(l!==e)if(l>e){let d=l-1,p=c?`${r}${d}.${c}`:`${r}${d}`;s[p]=o[i]}else s[i]=o[i]}),s},_=(o,t,e,s)=>{let r={},i=`${t}.`;return Object.keys(o).forEach(n=>{if(!n.startsWith(i)){r[n]=o[n];return}let l=n.substring(i.length).split("."),c=parseInt(l[0],10),d=l.slice(1).join(".");if(c===e){let p=d?`${i}${s}.${d}`:`${i}${s}`;r[p]=o[n]}else if(c===s){let p=d?`${i}${e}.${d}`:`${i}${e}`;r[p]=o[n]}else r[n]=o[n]}),r},X=(o,t,e,s)=>{let r={},i=`${t}.`;return Object.keys(o).forEach(n=>{if(!n.startsWith(i)){r[n]=o[n];return}let l=n.substring(i.length).split("."),c=parseInt(l[0],10),d=l.slice(1).join("."),p=c;c===e?p=s:e<s&&c>e&&c<=s?p=c-1:e>s&&c>=s&&c<e&&(p=c+1);let h=d?`${i}${p}.${d}`:`${i}${p}`;r[h]=o[n]}),r};function bt(o){if(typeof o!="object"||o===null||Array.isArray(o))return!1;let t=o.errors??o;return typeof t!="object"||t===null||Array.isArray(t)?!1:Object.values(t).every(e=>typeof e=="string"||Array.isArray(e)&&e.every(s=>typeof s=="string"))}function Ct(o){return bt(o)?o.errors??o:{}}var vt={"#":/\d/,A:/[a-zA-Z]/,X:/[a-zA-Z0-9]/,H:/[0-9a-fA-F]/,U:/[A-Z]/,L:/[a-z]/,"*":/./},M=(o,t)=>{if(o==null||o==="")return"";let e=String(o),s=e.startsWith("-"),r=t?t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):"",i=new RegExp(`[^a-zA-Z0-9${r}]`,"g"),n=e.replace(i,"");return s&&n&&!n.startsWith("-")?`-${n}`:n},xt=(o,t=2)=>{if(typeof o=="number")return o;if(!o)return 0;let e=String(o),s=e.includes("-"),r=e.replace(/\D/g,"");if(!r)return 0;let i=parseInt(r,10)/Math.pow(10,t);return s?-i:i},g=(o,t)=>{let e=s=>s.split("").filter(r=>vt[r]).length;return{format:s=>{let r=M(s,t?.allowChars);if(!r&&!t?.guide)return"";let n=[...Array.isArray(o)?o:[o]].sort((h,v)=>e(h)-e(v)),a=n[n.length-1];for(let h of n)if(r.length<=e(h)){a=h;break}let l="",c=0,d=t?.guide||!1,p=t?.placeholderChar||"_";for(let h=0;h<a.length;h++){let v=a[h],E=vt[v];if(c<r.length){let S=r[c];if(E)if(v==="U"&&(S=S.toUpperCase()),v==="L"&&(S=S.toLowerCase()),E.test(S))l+=S,c++;else if(d)l+=p;else break;else l+=v,S===v&&c++}else if(d)l+=E?p:v;else break}return l},parse:s=>{if(t?.customParse)return t.customParse(s);let i=g(o,t).format(s);if(t?.saveRaw){if(t?.guide){let a=(t.placeholderChar||"_").replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),l=new RegExp(a,"g");return i.replace(l,"")}return i}return M(i,t?.allowChars)}}},b=({prefix:o="",suffix:t="",thousand:e,decimal:s,precision:r=2,allowNegative:i=!0,saveRaw:n=!1})=>{let a=l=>{if(l==null||l==="")return"";let c="";if(typeof l=="number"?c=Math.abs(l).toFixed(r).replace(/\D/g,""):c=String(l).replace(/\D/g,""),!c&&String(l).includes("-")&&i)return"-";if(!c)return"";c=c.padStart(r+1,"0");let d=c.slice(0,-r).replace(/^0+(?=\d)/,"")||"0",p=c.slice(-r),h=d.replace(/\B(?=(\d{3})+(?!\d))/g,e);return`${(typeof l=="number"?l<0:String(l).includes("-"))&&i?"-":""}${o}${h}${s}${p}${t}`};return{format:a,parse:l=>{let c=xt(l,r),d=i?c:Math.abs(c);return n?a(d):d}}},z=o=>{let t=e=>/^3[47]/.test(e)?"#### ###### #####":/^3(?:0[0-5]|[68])/.test(e)?"#### ###### ####":"#### #### #### ####";return{format:e=>{let s=M(e,o?.allowChars),r=t(s);return g(r,o).format(e)},parse:e=>{let s=M(e,o?.allowChars),r=t(s);return g(r,o).parse(e)}}},P=o=>{let e=(o?.format||"DD/MM/YYYY")==="YYYY-MM-DD",s=g(e?"####-##-##":"##/##/####",o);return{format:r=>{let i=M(r);if(!i)return"";let n="",a="",l="";if(e?(l=i.substring(0,4),a=i.substring(4,6),n=i.substring(6,8)):(n=i.substring(0,2),a=i.substring(2,4),l=i.substring(4,8)),n.length===2){let d=parseInt(n,10);d>31&&(n="31"),d===0&&(n="01")}if(a.length===2){let d=parseInt(a,10);d>12&&(a="12"),d===0&&(a="01")}let c=e?`${l}${a}${n}`:`${n}${a}${l}`;return s.format(c)},parse:r=>s.parse(r)}};var W=b({prefix:"R$ ",thousand:".",decimal:",",precision:2}),Y=b({prefix:"$",thousand:",",decimal:".",precision:2}),J=b({suffix:" \u20AC",thousand:".",decimal:",",precision:2}),K=b({prefix:"\xA3",thousand:",",decimal:".",precision:2}),G=b({prefix:"\xA5",thousand:",",decimal:".",precision:0}),Z=b({suffix:"%",thousand:".",decimal:",",precision:1}),Q=b({thousand:".",decimal:",",precision:2}),tt=b({thousand:".",decimal:",",precision:0}),et=g("###.###.###-##"),st=g("##.###.###/####-##"),rt=g(["(##) ####-####","(##) #####-####"]),it=g("(##) ####-####"),ot=g("#####-###"),nt=P({format:"DD/MM/YYYY",guide:!0,customParse:o=>{let t=o.replace(/_/g,""),e=t.split("/");return e.length===3&&e[2].length===4?`${e[2]}-${e[1]}-${e[0]}`:t.replace(/\D/g,"")}}),at=g("##:##"),lt=g("###########"),ct=g("##.###.###-X"),Vt=g("(###) ###-####"),Dt=g("#####-####"),Rt=g("##/##/####"),wt=g("###-##-####"),dt=z(),ut=g("####"),It=P({format:"YYYY-MM-DD",saveRaw:!0,guide:!0}),gt=g("HH:HH:HH:HH:HH:HH"),pt=g("#HHHHHH"),ft=g("###.###.###.###"),ht=g("HHHH:HHHH:HHHH:HHHH:HHHH:HHHH:HHHH:HHHH"),Ht=g("UU## XXXX XXXX XXXX XXXX XXXX XXXX XXXX XX",{allowChars:" "});var mt={brl:W,usd:Y,eur:J,gbp:K,jpy:G,cpf:et,cnpj:st,rg:ct,cep:ot,cnh:lt,phone:rt,landline:it,date:nt,time:at,ip:ft,ipv6:ht,mac:gt,color:pt,cc:dt,cvv:ut,percent:Z,decimal:Q,int:tt};function Ft(o){let t={},e={},s={};if(!o)return{computed:t,transform:e,scopes:s};for(let[r,i]of Object.entries(o))i?.computed&&(t[r]=i.computed),i?.transform&&(e[r]=i.transform),i?.scope&&(s[i.scope]||(s[i.scope]=[]),s[i.scope].push(r));return{computed:Object.keys(t).length?t:void 0,transform:Object.keys(e).length?e:void 0,scopes:Object.keys(s).length?s:void 0}}function Tt(o={}){let t=o.initialValues||{},e=o.validation,s=o.history,{computed:r,transform:i,scopes:n}=Ft(o.fields);return{name:o.name,initialValues:f(t),resolver:e?.resolver,validationDelay:e?.delay??300,enableHistory:s?.enabled??!1,historyLimit:s?.limit??15,computed:r,transform:i,scopes:n,masks:mt,fields:o.fields,devTools:o.devTools}}var C=class{fieldConfigs=new Map;dependencies=new Map;hiddenFields=new Set;register(t,e,s){this.fieldConfigs.set(t,e);let r=e.conditional?.dependsOn;r&&r.forEach(i=>{this.dependencies.has(i)||this.dependencies.set(i,new Set),this.dependencies.get(i).add(t)}),this.evaluateFieldCondition(t,s)}isHidden(t){return this.hiddenFields.has(t)}isRequired(t,e){let s=this.fieldConfigs.get(t);return!s||this.isHidden(t)?!1:!!s.conditional?.requiredIf?.(e)}getRequiredErrors(t){let e={};return this.fieldConfigs.forEach((s,r)=>{if(this.isRequired(r,t)){let i=u(t,r);this.isEmpty(i)&&(e[r]=s.conditional?.requiredMessage??"required field")}}),e}evaluateAll(t){this.fieldConfigs.forEach((e,s)=>{this.evaluateFieldCondition(s,t)})}updateDependencies(t,e){let s=[],r=this.dependencies.get(t);return r&&r.forEach(i=>{let n=this.isHidden(i);this.evaluateFieldCondition(i,e);let a=this.isHidden(i);n!==a&&s.push(i)}),s}unregister(t){this.fieldConfigs.delete(t),this.hiddenFields.delete(t),this.dependencies.delete(t),this.dependencies.forEach(e=>{e.delete(t)})}unregisterPrefix(t){let e=[];this.fieldConfigs.forEach((s,r)=>{r.startsWith(t)&&e.push(r)}),e.forEach(s=>this.unregister(s))}evaluateFieldCondition(t,e){let r=this.fieldConfigs.get(t)?.conditional?.showIf;r&&(r(e)?this.hiddenFields.delete(t):this.hiddenFields.add(t))}isEmpty(t){return t==null||typeof t=="string"&&t.trim()===""||Array.isArray(t)&&t.length===0}};var V=class{constructor(t,e=15){this.enableHistory=t;this.maxHistory=e}history=[];historyIndex=-1;saveSnapshot(t){if(!this.enableHistory)return;let e=this.history[this.historyIndex];e&&T(e,t)||(this.historyIndex<this.history.length-1&&(this.history=this.history.slice(0,this.historyIndex+1)),this.history.push(f(t)),this.history.length>this.maxHistory?this.history.shift():this.historyIndex++)}get canUndo(){return this.enableHistory?this.historyIndex>0:!1}get canRedo(){return this.enableHistory?this.historyIndex<this.history.length-1:!1}undo(){return this.canUndo?(this.historyIndex--,f(this.history[this.historyIndex])):null}redo(){return this.canRedo?(this.historyIndex++,f(this.history[this.historyIndex])):null}reset(t){this.history=[],this.historyIndex=-1,this.saveSnapshot(t)}getMetadata(){return{enabled:this.enableHistory,canUndo:this.canUndo,canRedo:this.canRedo,historyIndex:this.historyIndex,historySize:this.history.length}}};var D=class{constructor(t){this.store=t}pushItem(t,e){let s=u(this.store.getState().values,t)||[];this.store.setField(t,[...s,e]),this.store.internalSaveSnapshot()}prependItem(t,e){let s=u(this.store.getState().values,t)||[];this.store.setField(t,[e,...s]),this.store.internalSaveSnapshot()}insertItem(t,e,s){let r=[...u(this.store.getState().values,t)||[]];r.splice(e,0,s),this.store.setField(t,r),this.store.internalSaveSnapshot()}removeItem(t,e){let s=this.store.getState(),r=u(s.values,t);if(!Array.isArray(r))return;this.store.unregisterPrefix&&this.store.unregisterPrefix(`${t}.${e}.`);let i=r.filter((l,c)=>c!==e),n=y(s.values,t,i),a=this.store.dirtyMg.updateForPath(t,n,this.store.getConfig().initialValues);this.store.internalUpdateState({values:n,errors:q(s.errors,t,e),touched:q(s.touched,t,e),isDirty:a}),this.store.internalSaveSnapshot(),this.revalidate(t)}swapItems(t,e,s){let r=this.store.getState(),i=[...u(r.values,t)||[]];[i[e],i[s]]=[i[s],i[e]];let n=y(r.values,t,i),a=this.store.dirtyMg.updateForPath(t,n,this.store.getConfig().initialValues);this.store.internalUpdateState({values:n,errors:_(r.errors,t,e,s),touched:_(r.touched,t,e,s),isDirty:a}),this.store.internalSaveSnapshot(),this.revalidate(t)}moveItem(t,e,s){let r=this.store.getState(),i=[...u(r.values,t)||[]],[n]=i.splice(e,1);i.splice(s,0,n);let a=y(r.values,t,i),l=this.store.dirtyMg.updateForPath(t,a,this.store.getConfig().initialValues);this.store.internalUpdateState({values:a,errors:X(r.errors,t,e,s),touched:X(r.touched,t,e,s),isDirty:l}),this.store.internalSaveSnapshot(),this.revalidate(t)}revalidate(t){let e=this.store;typeof e.triggerValidation=="function"?e.triggerValidation([t]):typeof this.store.validate=="function"&&this.store.validate()}};var R=class{constructor(t){this.config=t}apply(t){if(!this.config.computed)return t;let e=t,s=Object.entries(this.config.computed);for(let r=0;r<2;r++){let i=!1;for(let[n,a]of s){let l=a(e),c=u(e,n);T(c,l)||(e=y(e,n,l),i=!0)}if(!i)break}return e}};var w=class{constructor(t){this.store=t}validationTimeout;currentValidationId=0;asyncTimers={};asyncRequests={};asyncErrors={};handleAsync(t,e){let s=this.store.depsMg.fieldConfigs.get(t)||this.store.config.fields?.[t],r=s?.validation?.asyncValidate;if(!r)return;this.asyncTimers[t]&&clearTimeout(this.asyncTimers[t]);let i=s.validation?.asyncValidateDelay??500;this.asyncTimers[t]=setTimeout(async()=>{let n=(this.asyncRequests[t]||0)+1;this.asyncRequests[t]=n,this.store.internalUpdateState({isValidating:{...this.store.getState().isValidating,[t]:!0}});try{let a=await r(e,this.store.getState().values);if(this.asyncRequests[t]!==n)return;if(a)this.asyncErrors[t]=a,this.store.setError(t,a);else{delete this.asyncErrors[t];let l=this.store;if(l.validate)await l.validate({scopeFields:[t]});else{let c={...this.store.getState().errors};delete c[t],this.store.internalUpdateState({errors:c,isValid:Object.keys(c).length===0})}}}finally{this.asyncRequests[t]===n&&this.store.internalUpdateState({isValidating:{...this.store.getState().isValidating,[t]:!1}})}},i)}trigger(t){this.validationTimeout&&clearTimeout(this.validationTimeout);let e=this.store.config.validationDelay??300;e>0?this.validationTimeout=setTimeout(()=>{this.validate({scopeFields:t})},e):this.validate({scopeFields:t})}async validate(t){let e=++this.currentValidationId,s=this.store.getState(),r=t?.scopeFields;t?.scope&&this.store.config.scopes?.[t.scope]&&(r=this.store.config.scopes[t.scope]);let i=this.store.config.resolver?await this.store.config.resolver(s.values,{scopeFields:r}):{},n=this.store.depsMg.getRequiredErrors(s.values);if(i={...i,...n},this.store.depsMg.hiddenFields.forEach(l=>{delete i[l],delete this.asyncErrors[l]}),e!==this.currentValidationId)return s.isValid;if(r){let l={...s.errors};r.forEach(d=>{i[d]?l[d]=i[d]:this.asyncErrors[d]?l[d]=this.asyncErrors[d]:delete l[d]});let c=Object.keys(l).length===0;return this.store.internalUpdateState({errors:l,isValid:c}),r.every(d=>!i[d]&&!this.asyncErrors[d])}i={...this.asyncErrors,...i};let a=Object.keys(i).length===0;return this.store.internalUpdateState({errors:i,isValid:a}),a}clear(t){this.asyncTimers[t]&&clearTimeout(this.asyncTimers[t]),delete this.asyncErrors[t]}cancelAll(){this.validationTimeout&&clearTimeout(this.validationTimeout),Object.values(this.asyncTimers).forEach(t=>clearTimeout(t))}};var I=class{constructor(t){this.store=t}updateField(t,e){let s=this.store.getState(),r=y(s.values,t,e),i={...s.errors};delete i[t],this.store.validatorMg.clear(t);let n=this.store.depsMg.updateDependencies(t,r);n.forEach(l=>{this.store.depsMg.isHidden(l)&&(delete i[l],this.store.validatorMg.clear(l))});let a=this.store.dirtyMg.updateForPath(t,r,this.store.config.initialValues);return this.store.internalUpdateState({values:r,errors:i,isValid:Object.keys(i).length===0,isDirty:a}),this.store.config.resolver&&this.store.validatorMg.trigger([t]),this.store.validatorMg.handleAsync(t,e),{visibilitiesChanged:n.length>0}}updateAll(t){let e=f(t);this.store.config.initialValues=f(e),this.store.validatorMg.cancelAll(),this.store.depsMg.evaluateAll(e),this.store.dirtyMg.clear(),this.store.internalUpdateState({values:e,errors:{},touched:{},isValidating:{},isValid:!0,isDirty:!1,isSubmitting:!1}),this.store.internalSaveSnapshot(),this.store.validatorMg.validate()}async submit(t){if(this.store.getState().isSubmitting)return;if(this.store.validatorMg.cancelAll(),this.store.internalUpdateState({isSubmitting:!0}),await this.store.validatorMg.validate())try{let r=f(this.store.getState().values);if(this.store.depsMg.hiddenFields.forEach(n=>{r=y(r,n,void 0)}),this.store.config.transform)for(let n in this.store.config.transform){let a=this.store.config.transform[n];if(a){let l=u(r,n);r=y(r,n,a(l,this.store.getState().values))}}let i=this.store.dirtyMg.buildDirtyValues(r);await t(r,i)}catch(r){console.error(r)}else{let r=this.store.getState().errors,i={...this.store.getState().touched};Object.keys(r).forEach(n=>{i[n]=!0}),this.store.internalUpdateState({touched:i})}this.store.internalUpdateState({isSubmitting:!1})}reset(){this.store.validatorMg.cancelAll();let t=f(this.store.config.initialValues);this.store.depsMg.evaluateAll(t),this.store.dirtyMg.clear(),this.store.internalUpdateState({values:t,errors:{},touched:{},isValidating:{},isValid:!0,isDirty:!1,isSubmitting:!1}),this.store.historyMg.reset(t)}};function St(){return`
2
2
  .bit-devtools-container {
3
3
  position: fixed;
4
4
  bottom: 20px;
@@ -86,13 +86,13 @@ var N=typeof globalThis<"u"?globalThis:typeof global<"u"?global:window;N.__BIT_F
86
86
 
87
87
  pre.bit-pre { background: #020617; padding: 10px; border-radius: 4px; font-size: 11px; overflow-x: auto; border: 1px solid #1e293b; margin: 0; color: #e2e8f0; }
88
88
  pre.bit-error-box { background: rgba(239, 68, 68, 0.05); padding: 10px; border-radius: 4px; font-size: 11px; border: 1px dashed #ef4444; color: #fca5a5; margin: 0; overflow-x: auto; }
89
- `}var B=class{container;actions;rootElement;currentStoresState={};isOpen=!1;constructor(t,e){if(this.container=t,this.actions=e,!document.getElementById("bit-devtools-styles")){let s=document.createElement("style");s.id="bit-devtools-styles",s.textContent=St(),document.head.appendChild(s)}this.rootElement=document.createElement("div"),this.rootElement.className="bit-devtools-container",this.container.appendChild(this.rootElement),this.rootElement.addEventListener("click",s=>{let r=s.target;if(r.closest(".bit-devtools-trigger")){this.isOpen=!this.isOpen,this.render();return}let i=r.closest(".bit-action-btn");if(i&&!i.hasAttribute("disabled")){let o=i.getAttribute("data-action"),a=i.getAttribute("data-store");o&&a&&(o==="undo"&&this.actions.onUndo(a),o==="redo"&&this.actions.onRedo(a),o==="reset"&&this.actions.onReset(a))}})}updateState(t){this.currentStoresState=t,this.render()}render(){let t=Object.entries(this.currentStoresState);if(t.length===0){this.rootElement.innerHTML="";return}let e="";if(this.isOpen){e=`
89
+ `}var B=class{container;actions;rootElement;currentStoresState={};isOpen=!1;constructor(t,e){if(this.container=t,this.actions=e,!document.getElementById("bit-devtools-styles")){let s=document.createElement("style");s.id="bit-devtools-styles",s.textContent=St(),document.head.appendChild(s)}this.rootElement=document.createElement("div"),this.rootElement.className="bit-devtools-container",this.container.appendChild(this.rootElement),this.rootElement.addEventListener("click",s=>{let r=s.target;if(r.closest(".bit-devtools-trigger")){this.isOpen=!this.isOpen,this.render();return}let i=r.closest(".bit-action-btn");if(i&&!i.hasAttribute("disabled")){let n=i.getAttribute("data-action"),a=i.getAttribute("data-store");n&&a&&(n==="undo"&&this.actions.onUndo(a),n==="redo"&&this.actions.onRedo(a),n==="reset"&&this.actions.onReset(a))}})}updateState(t){this.currentStoresState=t,this.render()}render(){let t=Object.entries(this.currentStoresState);if(t.length===0){this.rootElement.innerHTML="";return}let e="";if(this.isOpen){e=`
90
90
  <div class="bit-devtools-panel">
91
91
  <div class="bit-devtools-header">
92
92
  <h2><span style="font-size: 20px;">\u{1F6E0}</span> Bit-Form DevTools</h2>
93
93
  <span style="font-size: 11px; color: #64748b;">v1.0.0</span>
94
94
  </div>
95
- `;for(let[r,i]of t){let o=Object.keys(i.errors||{}).length>0,a=i._meta||{totalSteps:0,currentIndex:-1,canUndo:!1,canRedo:!1},l=a.currentIndex+1,c=a.totalSteps;e+=`
95
+ `;for(let[r,i]of t){let n=Object.keys(i.errors||{}).length>0,a=i._meta||{totalSteps:0,currentIndex:-1,canUndo:!1,canRedo:!1},l=a.currentIndex+1,c=a.totalSteps;e+=`
96
96
  <div class="bit-store-block">
97
97
  <div class="bit-store-header">
98
98
  <h3 class="bit-store-title">${r}</h3>
@@ -118,7 +118,7 @@ var N=typeof globalThis<"u"?globalThis:typeof global<"u"?global:window;N.__BIT_F
118
118
  <span>\u{1F5D1}</span> Reset
119
119
  </button>
120
120
  </div>
121
- `,o&&(e+=`
121
+ `,n&&(e+=`
122
122
  <span class="bit-section-title" style="color: #f87171;">\u26A0\uFE0F Validations Failing</span>
123
123
  <pre class="bit-error-box">${JSON.stringify(i.errors,null,2)}</pre>
124
124
  `),e+=`
@@ -129,5 +129,5 @@ var N=typeof globalThis<"u"?globalThis:typeof global<"u"?global:window;N.__BIT_F
129
129
  <button class="bit-devtools-trigger" style="transform: ${this.isOpen?"scale(0.9)":"scale(1)"};" title="Abrir DevTools">
130
130
  ${this.isOpen?"\u2716":"Bit"}
131
131
  </button>
132
- `;this.rootElement.innerHTML=e+s}};function kt(n){let t=new B(n,{onUndo:r=>m.stores[r]?.undo(),onRedo:r=>m.stores[r]?.redo(),onReset:r=>m.stores[r]?.reset()}),e=()=>{let r={};for(let[i,o]of Object.entries(m.stores)){let a=o,l=a.getState(),c=a?.getHistoryMetadata?.()||{enabled:!1,canUndo:!1,canRedo:!1,historyIndex:-1,historySize:0};r[i]={...l,_meta:{canUndo:c.canUndo,canRedo:c.canRedo,totalSteps:c.historySize,currentIndex:c.historyIndex}}}return r};t.updateState(e());let s=m.subscribe(()=>{t.updateState(e())});return{ui:t,destroy:()=>{s(),n.innerHTML=""}}}function Mt(n,t="ws://localhost:3000"){let e=new WebSocket(t),s=new B(n,{onUndo:i=>r("ACTION",{storeId:i,action:"undo"}),onRedo:i=>r("ACTION",{storeId:i,action:"redo"}),onReset:i=>r("ACTION",{storeId:i,action:"reset"})}),r=(i,o)=>{e.readyState===WebSocket.OPEN?e.send(JSON.stringify({type:i,payload:o})):console.warn("[bit-form] Tentativa de envio falhou. WebSocket n\xE3o est\xE1 aberto.")};return e.addEventListener("open",()=>{console.log(`[bit-form] Conectado ao DevTools remoto em ${t}`)}),e.addEventListener("message",i=>{try{let o=JSON.parse(i.data);o.type==="STATE_UPDATE"&&s.updateState(o.payload)}catch(o){console.error("[bit-form] Erro ao processar mensagem do WebSocket:",o)}}),e.addEventListener("error",i=>{console.error("[bit-form] Erro na conex\xE3o do DevTools remoto:",i)}),s}function yt(n={}){let{mode:t="local",url:e}=n,s,r=!1;if(typeof n.container=="string"){let o=document.querySelector(n.container);if(!o)throw new Error(`[bit-form] Container '${n.container}' n\xE3o encontrado na p\xE1gina.`);s=o}else n.container instanceof HTMLElement?s=n.container:(s=document.createElement("div"),s.id="bit-form-devtools-root",s.style.position="fixed",s.style.bottom="20px",s.style.right="20px",s.style.zIndex="9999",s.style.maxHeight="80vh",s.style.overflowY="auto",s.style.boxShadow="0 10px 25px rgba(0,0,0,0.1)",document.body.appendChild(s),r=!0);let i;if(t==="local")console.log("[bit-form] DevTools iniciado em modo Local."),i=kt(s);else if(t==="remote")console.log("[bit-form] DevTools iniciado em modo Remote."),i=Mt(s,e);else throw new Error(`[bit-form] Modo DevTools inv\xE1lido: ${t}`);return{...i,destroy:()=>{i&&typeof i.destroy=="function"&&i.destroy(),r&&s.parentNode?s.parentNode.removeChild(s):s.innerHTML=""}}}var A=class{store;cleanupFn=null;constructor(t){this.store=t,this.setup()}setup(){let t=this.store.config.devTools;if(!t)return;let e=typeof t=="boolean"?{enabled:t,mode:"local"}:{enabled:!0,...t};if(e.enabled)if(e.mode==="remote"){let s=e.url||"ws://localhost:3000";this.cleanupFn=Bt(s)}else{let s=yt();s&&typeof s.destroy=="function"&&(this.cleanupFn=s.destroy)}}destroy(){this.cleanupFn&&this.cleanupFn()}};var F=class{dirtyPaths=new Set;updateForPath(t,e,s){for(let o of this.dirtyPaths)o.startsWith(t+".")&&this.dirtyPaths.delete(o);let r=u(e,t),i=u(s,t);return x(r,i)?this.dirtyPaths.delete(t):this.dirtyPaths.add(t),this.dirtyPaths.size>0}rebuild(t,e){return this.dirtyPaths=j(t,e),this.dirtyPaths.size>0}clear(){this.dirtyPaths.clear()}get isDirty(){return this.dirtyPaths.size>0}getDirtyPaths(){return this.dirtyPaths}buildDirtyValues(t){if(this.dirtyPaths.size===0)return{};let e={},s=new Set;for(let r of this.dirtyPaths){let i=r.match(/^(.+)\.(\d+)/);if(i){let o=i[1];if(s.has(o))continue;s.add(o),this.setNestedValue(e,o,this.getNestedValue(t,o))}else this.setNestedValue(e,r,this.getNestedValue(t,r))}return e}getNestedValue(t,e){let s=e.split("."),r=t;for(let i of s){if(r==null)return;r=r[i]}return r}setNestedValue(t,e,s){let r=e.split("."),i=t;for(let o=0;o<r.length-1;o++){let a=r[o];a in i||(i[a]={}),i=i[a]}i[r[r.length-1]]=s}};var O=class{constructor(t,e){this.getState=t;this.getConfig=e}getStepStatus(t){let e=this.getConfig().scopes?.[t]||[],s=this.getState(),r=e.some(a=>!!s.errors[a]),i=e.some(a=>{let l=u(s.values,a),c=u(this.getConfig().initialValues,a);return!x(l,c)}),o=this.getStepErrors(t);return{hasErrors:r,isDirty:i,errors:o}}getStepErrors(t){let e=this.getConfig().scopes?.[t]||[],s=this.getState(),r={};for(let i of e){let o=s.errors[i];o&&(r[i]=o)}return r}};var $=class{constructor(t,e,s){this.depsMg=t;this.getState=e;this.getConfig=s}isHidden(t){return this.depsMg.isHidden(t)}isRequired(t){return this.depsMg.isRequired(t,this.getState().values)}isFieldDirty(t){let e=u(this.getState().values,t),s=u(this.getConfig().initialValues,t);return!x(e,s)}isFieldValidating(t){return!!this.getState().isValidating[t]}};var U=class{constructor(t,e){this.getState=t;this.internalUpdateState=e}setError(t,e){let s={...this.getState().errors,[t]:e};e||delete s[t],this.internalUpdateState({errors:s})}setErrors(t){this.internalUpdateState({errors:{...this.getState().errors,...t}})}setServerErrors(t){let e={};for(let[s,r]of Object.entries(t))e[s]=Array.isArray(r)?r[0]:r;this.setErrors(e)}};var E=class{state;listeners=new Set;config;storeId;depsMg;validatorMg;computedMg;dirtyMg;lifecycleMg;historyMg;arraysMg;scopeMg;devtoolsMg;queryMg;errorMg;constructor(t={}){this.config=Tt(t),this.depsMg=new V,this.computedMg=new w(this.config),this.validatorMg=new I(this),this.dirtyMg=new F,this.lifecycleMg=new H(this),this.historyMg=new D(!!this.config.enableHistory,this.config.historyLimit??15),this.arraysMg=new R(this),this.devtoolsMg=new A(this),this.scopeMg=new O(()=>this.state,()=>this.config),this.queryMg=new $(this.depsMg,()=>this.state,()=>this.config),this.errorMg=new U(()=>this.state,r=>this.internalUpdateState(r));let e=f(this.config.initialValues),s=this.computedMg.apply(e);this.state={values:s,errors:{},touched:{},isValidating:{},isValid:!0,isSubmitting:!1,isDirty:!1},this.config.fields&&Object.entries(this.config.fields).forEach(([r,i])=>{this.depsMg.register(r,i,e)}),this.internalSaveSnapshot(),this.storeId=this.config.name||`bit-form-${Math.random().toString(36).substring(2,9)}`,m.stores[this.storeId]=this}getConfig(){return this.config}getState(){return this.state}get isValid(){return this.state.isValid}get isSubmitting(){return this.state.isSubmitting}get isDirty(){return this.state.isDirty}registerField(t,e){this.depsMg.register(t,e,this.state.values),this.depsMg.isHidden(t)&&this.notify()}unregisterField(t){if(this.config.fields?.[t])return;this.depsMg.unregister(t);let e={...this.state.errors},s={...this.state.touched},r=!1;e[t]&&(delete e[t],r=!0),s[t]&&(delete s[t],r=!0),r&&this.internalUpdateState({errors:e,touched:s})}unregisterPrefix(t){this.depsMg.unregisterPrefix(t)}isHidden(t){return this.queryMg.isHidden(t)}isRequired(t){return this.queryMg.isRequired(t)}isFieldDirty(t){return this.queryMg.isFieldDirty(t)}isFieldValidating(t){return this.queryMg.isFieldValidating(t)}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}watch(t,e){let s=f(u(this.state.values,t));return this.subscribe(()=>{let r=u(this.state.values,t);T(r,s)||(s=f(r),e(r))})}setField(t,e){let{visibilitiesChanged:s}=this.lifecycleMg.updateField(t,e);(!this.config.resolver||s)&&this.notify()}blurField(t){this.internalSaveSnapshot(),this.state.touched[t]||this.internalUpdateState({touched:{...this.state.touched,[t]:!0}}),this.validatorMg.trigger([t])}markFieldsTouched(t){if(t.length===0)return;let e={...this.state.touched};t.forEach(s=>e[s]=!0),this.internalUpdateState({touched:e})}setValues(t){this.lifecycleMg.updateAll(t)}setError(t,e){this.errorMg.setError(t,e)}setErrors(t){this.errorMg.setErrors(t)}setServerErrors(t){this.errorMg.setServerErrors(t)}reset(){this.lifecycleMg.reset()}async submit(t){return this.lifecycleMg.submit(t)}registerMask(t,e){this.config.masks[t]=e}getDirtyValues(){return this.dirtyMg.buildDirtyValues(this.state.values)}pushItem(t,e){this.arraysMg.pushItem(t,e)}prependItem(t,e){this.arraysMg.prependItem(t,e)}insertItem(t,e,s){this.arraysMg.insertItem(t,e,s)}removeItem(t,e){this.arraysMg.removeItem(t,e)}swapItems(t,e,s){this.arraysMg.swapItems(t,e,s)}moveItem(t,e,s){this.arraysMg.moveItem(t,e,s)}get canUndo(){return this.historyMg.canUndo}get canRedo(){return this.historyMg.canRedo}undo(){let t=this.historyMg.undo();if(t){let e=this.dirtyMg.rebuild(t,this.config.initialValues);this.internalUpdateState({values:t,isDirty:e}),this.validatorMg.validate()}}redo(){let t=this.historyMg.redo();if(t){let e=this.dirtyMg.rebuild(t,this.config.initialValues);this.internalUpdateState({values:t,isDirty:e}),this.validatorMg.validate()}}getHistoryMetadata(){return this.historyMg.getMetadata()}validate(t){return this.validatorMg.validate(t)}getStepStatus(t){return this.scopeMg.getStepStatus(t)}getStepErrors(t){return this.scopeMg.getStepErrors(t)}internalUpdateState(t){let e={...this.state,...t};t.values&&(e.values=this.computedMg.apply(t.values)),t.errors&&(e.isValid=Object.keys(e.errors).length===0),this.state=e,this.notify(),m.dispatch(this.storeId,this.state)}internalSaveSnapshot(){this.historyMg.saveSnapshot(this.state.values)}cleanup(){this.listeners.clear(),this.validatorMg.cancelAll(),delete m.stores[this.storeId]}notify(){this.listeners.forEach(t=>t())}};function Ot(n={}){let t=new E(n);return{getConfig:()=>t.getConfig(),getState:()=>t.getState(),subscribe:t.subscribe.bind(t),setField:t.setField.bind(t),blurField:t.blurField.bind(t),setValues:t.setValues.bind(t),setError:t.setError.bind(t),setErrors:t.setErrors.bind(t),setServerErrors:t.setServerErrors.bind(t),validate:t.validate.bind(t),reset:t.reset.bind(t),submit:t.submit.bind(t),registerMask:t.registerMask.bind(t),getDirtyValues:t.getDirtyValues.bind(t),cleanup:t.cleanup.bind(t)}}function $t(n={}){return new E(n)}var Et=n=>{let t=typeof n.getState=="function"?n.getState():n,e=n?.getHistoryMetadata?.()||{canUndo:!1,canRedo:!1,historyIndex:-1,historySize:0};return{...t,_meta:{canUndo:e.canUndo,canRedo:e.canRedo,totalSteps:e.historySize,currentIndex:e.historyIndex}}},L=null;function Bt(n){L&&(console.warn("[bit-form] Reiniciando ponte do DevTools (Fast Refresh detectado)."),L());let t=null,e=null,s,r=!1,i=()=>{r=!1,t=new WebSocket(n),t.onopen=()=>{console.log("[bit-form] \u{1F50C} Conectado ao CLI DevTools via WebSocket.");let a=Object.entries(m.stores);if(a.length>0){let l=a.reduce((c,[d,p])=>(c[d]=Et(p),c),{});t?.send(JSON.stringify({type:"STATE_UPDATE",payload:l}))}e=m.subscribe((l,c)=>{if(t?.readyState===WebSocket.OPEN){let d=m.stores[l];d&&t.send(JSON.stringify({type:"STATE_UPDATE",payload:{[l]:Et(d)}}))}}),s=setInterval(()=>{t?.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:"PING"}))},3e4)},t.onmessage=a=>{try{let{type:l,payload:c}=JSON.parse(a.data);if(l==="ACTION"){let{storeId:d,action:p}=c,h=m.stores[d];h&&typeof h[p]=="function"&&h[p]()}}catch(l){console.warn("[bit-form] Erro ao processar comando do CLI:",l)}},t.onclose=()=>{e&&e(),clearInterval(s),r?console.log("[bit-form] Ponte antiga encerrada com sucesso."):(console.log("[bit-form] Conex\xE3o perdida. Reconectando em 3s..."),setTimeout(i,3e3))}};i();let o=()=>{r=!0,e&&e(),clearInterval(s),t&&(t.readyState===WebSocket.OPEN||t.readyState===WebSocket.CONNECTING)&&t.close(),L=null};return L=o,o}export{m as a,f as b,x as c,T as d,u as e,y as f,Pt as g,bt as h,Ct as i,M as j,xt as k,g as l,b as m,z as n,C as o,W as p,Y as q,J as r,K as s,G as t,Z as u,Q as v,tt as w,et as x,st as y,rt as z,it as A,nt as B,ot as C,at as D,lt as E,ct as F,Vt as G,Dt as H,Rt as I,wt as J,dt as K,ut as L,It as M,gt as N,pt as O,ft as P,ht as Q,Ht as R,mt as S,Bt as T,yt as U,Ot as V,$t as W};
133
- //# sourceMappingURL=chunk-4KRTZKIQ.js.map
132
+ `;this.rootElement.innerHTML=e+s}};function kt(o){let t=new B(o,{onUndo:r=>m.stores[r]?.undo(),onRedo:r=>m.stores[r]?.redo(),onReset:r=>m.stores[r]?.reset()}),e=()=>{let r={};for(let[i,n]of Object.entries(m.stores)){let a=n,l=a.getState(),c=a?.getHistoryMetadata?.()||{enabled:!1,canUndo:!1,canRedo:!1,historyIndex:-1,historySize:0};r[i]={...l,_meta:{canUndo:c.canUndo,canRedo:c.canRedo,totalSteps:c.historySize,currentIndex:c.historyIndex}}}return r};t.updateState(e());let s=m.subscribe(()=>{t.updateState(e())});return{ui:t,destroy:()=>{s(),o.innerHTML=""}}}function Mt(o,t="ws://localhost:3000"){let e=new WebSocket(t),s=new B(o,{onUndo:i=>r("ACTION",{storeId:i,action:"undo"}),onRedo:i=>r("ACTION",{storeId:i,action:"redo"}),onReset:i=>r("ACTION",{storeId:i,action:"reset"})}),r=(i,n)=>{e.readyState===WebSocket.OPEN?e.send(JSON.stringify({type:i,payload:n})):console.warn("[bit-form] Tentativa de envio falhou. WebSocket n\xE3o est\xE1 aberto.")};return e.addEventListener("open",()=>{console.log(`[bit-form] Conectado ao DevTools remoto em ${t}`)}),e.addEventListener("message",i=>{try{let n=JSON.parse(i.data);n.type==="STATE_UPDATE"&&s.updateState(n.payload)}catch(n){console.error("[bit-form] Erro ao processar mensagem do WebSocket:",n)}}),e.addEventListener("error",i=>{console.error("[bit-form] Erro na conex\xE3o do DevTools remoto:",i)}),s}function yt(o={}){let{mode:t="local",url:e}=o,s,r=!1;if(typeof o.container=="string"){let n=document.querySelector(o.container);if(!n)throw new Error(`[bit-form] Container '${o.container}' n\xE3o encontrado na p\xE1gina.`);s=n}else o.container instanceof HTMLElement?s=o.container:(s=document.createElement("div"),s.id="bit-form-devtools-root",s.style.position="fixed",s.style.bottom="20px",s.style.right="20px",s.style.zIndex="9999",s.style.maxHeight="80vh",s.style.overflowY="auto",s.style.boxShadow="0 10px 25px rgba(0,0,0,0.1)",document.body.appendChild(s),r=!0);let i;if(t==="local")console.log("[bit-form] DevTools iniciado em modo Local."),i=kt(s);else if(t==="remote")console.log("[bit-form] DevTools iniciado em modo Remote."),i=Mt(s,e);else throw new Error(`[bit-form] Modo DevTools inv\xE1lido: ${t}`);return{...i,destroy:()=>{i&&typeof i.destroy=="function"&&i.destroy(),r&&s.parentNode?s.parentNode.removeChild(s):s.innerHTML=""}}}var H=class{store;cleanupFn=null;constructor(t){this.store=t,this.setup()}setup(){let t=this.store.config.devTools;if(!t)return;let e=typeof t=="boolean"?{enabled:t,mode:"local"}:{enabled:!0,...t};if(e.enabled)if(e.mode==="remote"){let s=e.url||"ws://localhost:3000";this.cleanupFn=Bt(s)}else{let s=yt();s&&typeof s.destroy=="function"&&(this.cleanupFn=s.destroy)}}destroy(){this.cleanupFn&&this.cleanupFn()}};var A=class{dirtyPaths=new Set;updateForPath(t,e,s){for(let n of this.dirtyPaths)n.startsWith(t+".")&&this.dirtyPaths.delete(n);let r=u(e,t),i=u(s,t);return x(r,i)?this.dirtyPaths.delete(t):this.dirtyPaths.add(t),this.dirtyPaths.size>0}rebuild(t,e){return this.dirtyPaths=j(t,e),this.dirtyPaths.size>0}clear(){this.dirtyPaths.clear()}get isDirty(){return this.dirtyPaths.size>0}getDirtyPaths(){return this.dirtyPaths}buildDirtyValues(t){if(this.dirtyPaths.size===0)return{};let e={},s=new Set;for(let r of this.dirtyPaths){let i=r.match(/^(.+)\.(\d+)/);if(i){let n=i[1];if(s.has(n))continue;s.add(n),this.setNestedValue(e,n,this.getNestedValue(t,n))}else this.setNestedValue(e,r,this.getNestedValue(t,r))}return e}getNestedValue(t,e){let s=e.split("."),r=t;for(let i of s){if(r==null)return;r=r[i]}return r}setNestedValue(t,e,s){let r=e.split("."),i=t;for(let n=0;n<r.length-1;n++){let a=r[n];a in i||(i[a]={}),i=i[a]}i[r[r.length-1]]=s}};var F=class{constructor(t,e){this.getState=t;this.getConfig=e}getStepStatus(t){let e=this.getConfig().scopes?.[t]||[],s=this.getState(),r=e.some(a=>!!s.errors[a]),i=e.some(a=>{let l=u(s.values,a),c=u(this.getConfig().initialValues,a);return!x(l,c)}),n=this.getStepErrors(t);return{hasErrors:r,isDirty:i,errors:n}}getStepErrors(t){let e=this.getConfig().scopes?.[t]||[],s=this.getState(),r={};for(let i of e){let n=s.errors[i];n&&(r[i]=n)}return r}};var O=class{constructor(t,e,s){this.depsMg=t;this.getState=e;this.getConfig=s}isHidden(t){return this.depsMg.isHidden(t)}isRequired(t){return this.depsMg.isRequired(t,this.getState().values)}isFieldDirty(t){let e=u(this.getState().values,t),s=u(this.getConfig().initialValues,t);return!x(e,s)}isFieldValidating(t){return!!this.getState().isValidating[t]}};var $=class{constructor(t,e){this.getState=t;this.internalUpdateState=e}setError(t,e){let s={...this.getState().errors,[t]:e};e||delete s[t],this.internalUpdateState({errors:s})}setErrors(t){this.internalUpdateState({errors:{...this.getState().errors,...t}})}setServerErrors(t){let e={};for(let[s,r]of Object.entries(t))e[s]=Array.isArray(r)?r[0]:r;this.setErrors(e)}};var U=class{state;listeners=new Set;config;storeId;depsMg;validatorMg;computedMg;dirtyMg;lifecycleMg;historyMg;arraysMg;scopeMg;devtoolsMg;queryMg;errorMg;constructor(t={}){this.config=Tt(t),this.depsMg=new C,this.computedMg=new R(this.config),this.validatorMg=new w(this),this.dirtyMg=new A,this.lifecycleMg=new I(this),this.historyMg=new V(!!this.config.enableHistory,this.config.historyLimit??15),this.arraysMg=new D(this),this.devtoolsMg=new H(this),this.scopeMg=new F(()=>this.state,()=>this.config),this.queryMg=new O(this.depsMg,()=>this.state,()=>this.config),this.errorMg=new $(()=>this.state,r=>this.internalUpdateState(r));let e=f(this.config.initialValues),s=this.computedMg.apply(e);this.state={values:s,errors:{},touched:{},isValidating:{},isValid:!0,isSubmitting:!1,isDirty:!1},this.config.fields&&Object.entries(this.config.fields).forEach(([r,i])=>{this.depsMg.register(r,i,e)}),this.internalSaveSnapshot(),this.storeId=this.config.name||`bit-form-${Math.random().toString(36).substring(2,9)}`,m.stores[this.storeId]=this}getConfig(){return this.config}getState(){return this.state}get isValid(){return this.state.isValid}get isSubmitting(){return this.state.isSubmitting}get isDirty(){return this.state.isDirty}registerField(t,e){this.depsMg.register(t,e,this.state.values),this.depsMg.isHidden(t)&&this.notify()}unregisterField(t){if(this.config.fields?.[t])return;this.depsMg.unregister(t);let e={...this.state.errors},s={...this.state.touched},r=!1;e[t]&&(delete e[t],r=!0),s[t]&&(delete s[t],r=!0),r&&this.internalUpdateState({errors:e,touched:s})}unregisterPrefix(t){this.depsMg.unregisterPrefix(t)}isHidden(t){return this.queryMg.isHidden(t)}isRequired(t){return this.queryMg.isRequired(t)}isFieldDirty(t){return this.queryMg.isFieldDirty(t)}isFieldValidating(t){return this.queryMg.isFieldValidating(t)}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}watch(t,e){let s=f(u(this.state.values,t));return this.subscribe(()=>{let r=u(this.state.values,t);T(r,s)||(s=f(r),e(r))})}setField(t,e){let{visibilitiesChanged:s}=this.lifecycleMg.updateField(t,e);(!this.config.resolver||s)&&this.notify()}blurField(t){this.internalSaveSnapshot(),this.state.touched[t]||this.internalUpdateState({touched:{...this.state.touched,[t]:!0}}),this.validatorMg.trigger([t])}markFieldsTouched(t){if(t.length===0)return;let e={...this.state.touched};t.forEach(s=>e[s]=!0),this.internalUpdateState({touched:e})}setValues(t){this.lifecycleMg.updateAll(t)}setError(t,e){this.errorMg.setError(t,e)}setErrors(t){this.errorMg.setErrors(t)}setServerErrors(t){this.errorMg.setServerErrors(t)}reset(){this.lifecycleMg.reset()}async submit(t){return this.lifecycleMg.submit(t)}registerMask(t,e){this.config.masks[t]=e}getDirtyValues(){return this.dirtyMg.buildDirtyValues(this.state.values)}pushItem(t,e){this.arraysMg.pushItem(t,e)}prependItem(t,e){this.arraysMg.prependItem(t,e)}insertItem(t,e,s){this.arraysMg.insertItem(t,e,s)}removeItem(t,e){this.arraysMg.removeItem(t,e)}swapItems(t,e,s){this.arraysMg.swapItems(t,e,s)}moveItem(t,e,s){this.arraysMg.moveItem(t,e,s)}get canUndo(){return this.historyMg.canUndo}get canRedo(){return this.historyMg.canRedo}undo(){let t=this.historyMg.undo();if(t){let e=this.dirtyMg.rebuild(t,this.config.initialValues);this.internalUpdateState({values:t,isDirty:e}),this.validatorMg.validate()}}redo(){let t=this.historyMg.redo();if(t){let e=this.dirtyMg.rebuild(t,this.config.initialValues);this.internalUpdateState({values:t,isDirty:e}),this.validatorMg.validate()}}getHistoryMetadata(){return this.historyMg.getMetadata()}validate(t){return this.validatorMg.validate(t)}getStepStatus(t){return this.scopeMg.getStepStatus(t)}getStepErrors(t){return this.scopeMg.getStepErrors(t)}internalUpdateState(t){let e={...this.state,...t};t.values&&(e.values=this.computedMg.apply(t.values)),t.errors&&(e.isValid=Object.keys(e.errors).length===0),this.state=e,this.notify(),m.dispatch(this.storeId,this.state)}internalSaveSnapshot(){this.historyMg.saveSnapshot(this.state.values)}cleanup(){this.listeners.clear(),this.validatorMg.cancelAll(),delete m.stores[this.storeId]}notify(){this.listeners.forEach(t=>t())}};function Ot(o={}){let t=new U(o);return{getConfig:()=>t.getConfig(),getState:()=>t.getState(),subscribe:t.subscribe.bind(t),setField:t.setField.bind(t),blurField:t.blurField.bind(t),setValues:t.setValues.bind(t),setError:t.setError.bind(t),setErrors:t.setErrors.bind(t),setServerErrors:t.setServerErrors.bind(t),validate:t.validate.bind(t),reset:t.reset.bind(t),submit:t.submit.bind(t),registerMask:t.registerMask.bind(t),getDirtyValues:t.getDirtyValues.bind(t),cleanup:t.cleanup.bind(t)}}var Et=o=>{let t=typeof o.getState=="function"?o.getState():o,e=o?.getHistoryMetadata?.()||{canUndo:!1,canRedo:!1,historyIndex:-1,historySize:0};return{...t,_meta:{canUndo:e.canUndo,canRedo:e.canRedo,totalSteps:e.historySize,currentIndex:e.historyIndex}}},L=null;function Bt(o){L&&(console.warn("[bit-form] Reiniciando ponte do DevTools (Fast Refresh detectado)."),L());let t=null,e=null,s,r=!1,i=()=>{r=!1,t=new WebSocket(o),t.onopen=()=>{console.log("[bit-form] \u{1F50C} Conectado ao CLI DevTools via WebSocket.");let a=Object.entries(m.stores);if(a.length>0){let l=a.reduce((c,[d,p])=>(c[d]=Et(p),c),{});t?.send(JSON.stringify({type:"STATE_UPDATE",payload:l}))}e=m.subscribe((l,c)=>{if(t?.readyState===WebSocket.OPEN){let d=m.stores[l];d&&t.send(JSON.stringify({type:"STATE_UPDATE",payload:{[l]:Et(d)}}))}}),s=setInterval(()=>{t?.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:"PING"}))},3e4)},t.onmessage=a=>{try{let{type:l,payload:c}=JSON.parse(a.data);if(l==="ACTION"){let{storeId:d,action:p}=c,h=m.stores[d];h&&typeof h[p]=="function"&&h[p]()}}catch(l){console.warn("[bit-form] Erro ao processar comando do CLI:",l)}},t.onclose=()=>{e&&e(),clearInterval(s),r?console.log("[bit-form] Ponte antiga encerrada com sucesso."):(console.log("[bit-form] Conex\xE3o perdida. Reconectando em 3s..."),setTimeout(i,3e3))}};i();let n=()=>{r=!0,e&&e(),clearInterval(s),t&&(t.readyState===WebSocket.OPEN||t.readyState===WebSocket.CONNECTING)&&t.close(),L=null};return L=n,n}export{m as a,f as b,x as c,T as d,u as e,y as f,Pt as g,bt as h,Ct as i,M as j,xt as k,g as l,b as m,z as n,P as o,W as p,Y as q,J as r,K as s,G as t,Z as u,Q as v,tt as w,et as x,st as y,rt as z,it as A,ot as B,nt as C,at as D,lt as E,ct as F,Vt as G,Dt as H,Rt as I,wt as J,dt as K,ut as L,It as M,gt as N,pt as O,ft as P,ht as Q,Ht as R,mt as S,Bt as T,yt as U,Ot as V};
133
+ //# sourceMappingURL=chunk-ZWLZ4XDF.js.map