@lehnihon/bit-form 1.0.6 → 1.0.8
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/README.md +42 -1
- package/dist/angular/index.cjs +1 -1
- package/dist/angular/index.cjs.map +1 -1
- package/dist/angular/index.d.cts +44 -41
- package/dist/angular/index.d.ts +44 -41
- package/dist/angular/index.js +1 -1
- package/dist/angular/index.js.map +1 -1
- package/dist/{bus-DAwKIiMY.d.cts → bus-BtKUu_9m.d.cts} +42 -7
- package/dist/{bus-DAwKIiMY.d.ts → bus-BtKUu_9m.d.ts} +42 -7
- package/dist/chunk-4SZ2BOTW.js +2 -0
- package/dist/chunk-4SZ2BOTW.js.map +1 -0
- package/dist/chunk-IUDMKNON.cjs +2 -0
- package/dist/chunk-IUDMKNON.cjs.map +1 -0
- package/dist/chunk-MVDS4KAD.js +133 -0
- package/dist/chunk-MVDS4KAD.js.map +1 -0
- package/dist/chunk-QB7MQ6ZB.cjs +133 -0
- package/dist/{chunk-6VDQSKUN.cjs.map → chunk-QB7MQ6ZB.cjs.map} +1 -1
- package/dist/cli/index.cjs +404 -4
- package/dist/devtools/bridge.cjs +1 -1
- package/dist/devtools/bridge.js +1 -1
- package/dist/devtools/index.cjs +1 -1
- package/dist/devtools/index.js +1 -1
- package/dist/{index-BD_l3aH5.d.cts → index-C4HaSh5W.d.ts} +102 -15
- package/dist/{index-CPKnWBVv.d.ts → index-CH9ZdEkZ.d.cts} +102 -15
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +23 -22
- package/dist/react/index.d.ts +23 -22
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-native/index.cjs +1 -1
- package/dist/react-native/index.cjs.map +1 -1
- package/dist/react-native/index.d.cts +24 -14
- package/dist/react-native/index.d.ts +24 -14
- package/dist/react-native/index.js +1 -1
- package/dist/react-native/index.js.map +1 -1
- package/dist/resolvers/joi.d.cts +1 -1
- package/dist/resolvers/joi.d.ts +1 -1
- package/dist/resolvers/yup.d.cts +1 -1
- package/dist/resolvers/yup.d.ts +1 -1
- package/dist/resolvers/zod.d.cts +1 -1
- package/dist/resolvers/zod.d.ts +1 -1
- package/dist/{use-bit-watch-CoCFwS-F.d.ts → use-bit-watch-Bdwj9l_g.d.ts} +32 -27
- package/dist/{use-bit-watch-BSWy9rG7.d.cts → use-bit-watch-ClvBxm6Z.d.cts} +32 -27
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.cts +48 -42
- package/dist/vue/index.d.ts +48 -42
- package/dist/vue/index.js +1 -1
- package/dist/vue/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-6VDQSKUN.cjs +0 -133
- package/dist/chunk-KA4FAGIX.js +0 -133
- package/dist/chunk-KA4FAGIX.js.map +0 -1
- package/dist/chunk-UFYHEI6S.js +0 -2
- package/dist/chunk-UFYHEI6S.js.map +0 -1
- package/dist/chunk-Z6ITPS2B.cjs +0 -2
- package/dist/chunk-Z6ITPS2B.cjs.map +0 -1
package/dist/chunk-6VDQSKUN.cjs
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6;var F=typeof globalThis<"u"?globalThis:typeof global<"u"?global:window;F.__BIT_FORM__||(F.__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=F.__BIT_FORM__;function g(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=>g(e));let t={};for(let e in o)Object.prototype.hasOwnProperty.call(o,e)&&(t[e]=g(o[e]));return t}function S(o,t){return o===t?!0:o===null||typeof o!="object"||t===null||typeof t!="object"?!1:x(o,t)}function x(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)||!x(o[r],t[r]))return!1;return!0}function O(o,t,e="",s=new Set){if(S(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!S(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;O(_optionalChain([o, 'optionalAccess', _2 => _2[i]]),_optionalChain([t, 'optionalAccess', _3 => _3[i]]),n,s)}return s}var k=new Map;function p(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 l=s[n],a=s[n+1],c=/^\d+$/.test(a),d=i[l];d==null?i[l]=c?[]:{}:i[l]=Array.isArray(d)?[...d]:{...d},i=i[l]}return i[s[s.length-1]]=e,r}function kt(o,t){let e={},s=`${t}.`;for(let r in o)r!==t&&!r.startsWith(s)&&(e[r]=o[r]);return e}var $=(o,t,e)=>{let s={},r=`${t}.`;return Object.keys(o).forEach(i=>{if(!i.startsWith(r)){s[i]=o[i];return}let l=i.substring(r.length).split("."),a=parseInt(l[0],10),c=l.slice(1).join(".");if(a!==e)if(a>e){let d=a-1,f=c?`${r}${d}.${c}`:`${r}${d}`;s[f]=o[i]}else s[i]=o[i]}),s},U=(o,t,e,s)=>{let r={},i=`${t}.`;return Object.keys(o).forEach(n=>{if(!n.startsWith(i)){r[n]=o[n];return}let a=n.substring(i.length).split("."),c=parseInt(a[0],10),d=a.slice(1).join(".");if(c===e){let f=d?`${i}${s}.${d}`:`${i}${s}`;r[f]=o[n]}else if(c===s){let f=d?`${i}${e}.${d}`:`${i}${e}`;r[f]=o[n]}else r[n]=o[n]}),r},L=(o,t,e,s)=>{let r={},i=`${t}.`;return Object.keys(o).forEach(n=>{if(!n.startsWith(i)){r[n]=o[n];return}let a=n.substring(i.length).split("."),c=parseInt(a[0],10),d=a.slice(1).join("."),f=c;c===e?f=s:e<s&&c>e&&c<=s?f=c-1:e>s&&c>=s&&c<e&&(f=c+1);let h=d?`${i}${f}.${d}`:`${i}${f}`;r[h]=o[n]}),r};function gt(o){if(typeof o!="object"||o===null||Array.isArray(o))return!1;let t=_nullishCoalesce(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 Bt(o){return gt(o)?_nullishCoalesce(o.errors, () => (o)):{}}var ht={"#":/\d/,A:/[a-zA-Z]/,X:/[a-zA-Z0-9]/,H:/[0-9a-fA-F]/,U:/[A-Z]/,L:/[a-z]/,"*":/./},B= exports.j =(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},mt= exports.k =(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},u= exports.l =(o,t)=>{let e=s=>s.split("").filter(r=>ht[r]).length;return{format:s=>{let r=B(s,_optionalChain([t, 'optionalAccess', _4 => _4.allowChars]));if(!r&&!_optionalChain([t, 'optionalAccess', _5 => _5.guide]))return"";let n=[...Array.isArray(o)?o:[o]].sort((h,v)=>e(h)-e(v)),l=n[n.length-1];for(let h of n)if(r.length<=e(h)){l=h;break}let a="",c=0,d=_optionalChain([t, 'optionalAccess', _6 => _6.guide])||!1,f=_optionalChain([t, 'optionalAccess', _7 => _7.placeholderChar])||"_";for(let h=0;h<l.length;h++){let v=l[h],E=ht[v];if(c<r.length){let T=r[c];if(E)if(v==="U"&&(T=T.toUpperCase()),v==="L"&&(T=T.toLowerCase()),E.test(T))a+=T,c++;else if(d)a+=f;else break;else a+=v,T===v&&c++}else if(d)a+=E?f:v;else break}return a},parse:s=>{if(_optionalChain([t, 'optionalAccess', _8 => _8.customParse]))return t.customParse(s);let i=u(o,t).format(s);if(_optionalChain([t, 'optionalAccess', _9 => _9.saveRaw])){if(_optionalChain([t, 'optionalAccess', _10 => _10.guide])){let l=(t.placeholderChar||"_").replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=new RegExp(l,"g");return i.replace(a,"")}return i}return B(i,_optionalChain([t, 'optionalAccess', _11 => _11.allowChars]))}}},b= exports.m =({prefix:o="",suffix:t="",thousand:e,decimal:s,precision:r=2,allowNegative:i=!0,saveRaw:n=!1})=>{let l=a=>{if(a==null||a==="")return"";let c="";if(typeof a=="number"?c=Math.abs(a).toFixed(r).replace(/\D/g,""):c=String(a).replace(/\D/g,""),!c&&String(a).includes("-")&&i)return"-";if(!c)return"";c=c.padStart(r+1,"0");let d=c.slice(0,-r).replace(/^0+(?=\d)/,"")||"0",f=c.slice(-r),h=d.replace(/\B(?=(\d{3})+(?!\d))/g,e);return`${(typeof a=="number"?a<0:String(a).includes("-"))&&i?"-":""}${o}${h}${s}${f}${t}`};return{format:l,parse:a=>{let c=mt(a,r),d=i?c:Math.abs(c);return n?l(d):d}}},N= exports.n =o=>{let t=e=>/^3[47]/.test(e)?"#### ###### #####":/^3(?:0[0-5]|[68])/.test(e)?"#### ###### ####":"#### #### #### ####";return{format:e=>{let s=B(e,_optionalChain([o, 'optionalAccess', _12 => _12.allowChars])),r=t(s);return u(r,o).format(e)},parse:e=>{let s=B(e,_optionalChain([o, 'optionalAccess', _13 => _13.allowChars])),r=t(s);return u(r,o).parse(e)}}},P= exports.o =o=>{let e=(_optionalChain([o, 'optionalAccess', _14 => _14.format])||"DD/MM/YYYY")==="YYYY-MM-DD",s=u(e?"####-##-##":"##/##/####",o);return{format:r=>{let i=B(r);if(!i)return"";let n="",l="",a="";if(e?(a=i.substring(0,4),l=i.substring(4,6),n=i.substring(6,8)):(n=i.substring(0,2),l=i.substring(2,4),a=i.substring(4,8)),n.length===2){let d=parseInt(n,10);d>31&&(n="31"),d===0&&(n="01")}if(l.length===2){let d=parseInt(l,10);d>12&&(l="12"),d===0&&(l="01")}let c=e?`${a}${l}${n}`:`${n}${l}${a}`;return s.format(c)},parse:r=>s.parse(r)}};var _=b({prefix:"R$ ",thousand:".",decimal:",",precision:2}),j= exports.q =b({prefix:"$",thousand:",",decimal:".",precision:2}),X= exports.r =b({suffix:" \u20AC",thousand:".",decimal:",",precision:2}),q= exports.s =b({prefix:"\xA3",thousand:",",decimal:".",precision:2}),W= exports.t =b({prefix:"\xA5",thousand:",",decimal:".",precision:0}),z= exports.u =b({suffix:"%",thousand:".",decimal:",",precision:1}),Y= exports.v =b({thousand:".",decimal:",",precision:2}),J= exports.w =b({thousand:".",decimal:",",precision:0}),K= exports.x =u("###.###.###-##"),G= exports.y =u("##.###.###/####-##"),Z= exports.z =u(["(##) ####-####","(##) #####-####"]),Q= exports.A =u("(##) ####-####"),tt= exports.B =u("#####-###"),et= exports.C =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,"")}}),st= exports.D =u("##:##"),rt= exports.E =u("###########"),it= exports.F =u("##.###.###-X"),Mt= exports.G =u("(###) ###-####"),Et= exports.H =u("#####-####"),Pt= exports.I =u("##/##/####"),Ct= exports.J =u("###-##-####"),ot= exports.K =N(),nt= exports.L =u("####"),Dt= exports.M =P({format:"YYYY-MM-DD",saveRaw:!0,guide:!0}),at= exports.N =u("HH:HH:HH:HH:HH:HH"),lt= exports.O =u("#HHHHHH"),ct= exports.P =u("###.###.###.###"),dt= exports.Q =u("HHHH:HHHH:HHHH:HHHH:HHHH:HHHH:HHHH:HHHH"),wt= exports.R =u("UU## XXXX XXXX XXXX XXXX XXXX XXXX XXXX XX",{allowChars:" "});var ut={brl:_,usd:j,eur:X,gbp:q,jpy:W,cpf:K,cnpj:G,rg:it,cep:tt,cnh:rt,phone:Z,landline:Q,date:et,time:st,ip:ct,ipv6:dt,mac:at,color:lt,cc:ot,cvv:nt,percent:z,decimal:Y,int:J};function Rt(o){let t={},e={},s={};if(!o)return{computed:t,transform:e,scopes:s};for(let[r,i]of Object.entries(o))_optionalChain([i, 'optionalAccess', _15 => _15.computed])&&(t[r]=i.computed),_optionalChain([i, 'optionalAccess', _16 => _16.transform])&&(e[r]=i.transform),_optionalChain([i, 'optionalAccess', _17 => _17.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 yt(o={}){let t=o.initialValues||{},e=o.validation,s=o.history,{computed:r,transform:i,scopes:n}=Rt(o.fields);return{name:o.name,initialValues:g(t),resolver:_optionalChain([e, 'optionalAccess', _18 => _18.resolver]),validationDelay:_nullishCoalesce(_optionalChain([e, 'optionalAccess', _19 => _19.delay]), () => (300)),defaultRequiredMessage:_optionalChain([e, 'optionalAccess', _20 => _20.defaultRequiredMessage]),enableHistory:_nullishCoalesce(_optionalChain([s, 'optionalAccess', _21 => _21.enabled]), () => (!1)),historyLimit:_nullishCoalesce(_optionalChain([s, 'optionalAccess', _22 => _22.limit]), () => (15)),computed:r,transform:i,scopes:n,masks:ut,fields:o.fields,devTools:o.devTools}}var C= (_class =class{constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this); }__init() {this.fieldConfigs=new Map}__init2() {this.dependencies=new Map}__init3() {this.hiddenFields=new Set}register(t,e,s){this.fieldConfigs.set(t,e);let r=_optionalChain([e, 'access', _23 => _23.conditional, 'optionalAccess', _24 => _24.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:!!_optionalChain([s, 'access', _25 => _25.conditional, 'optionalAccess', _26 => _26.requiredIf, 'optionalCall', _27 => _27(e)])}getRequiredErrors(t,e="Este campo \xE9 obrigat\xF3rio"){let s={};return this.fieldConfigs.forEach((r,i)=>{if(this.isRequired(i,t)){let n=p(t,i);this.isEmpty(n)&&(s[i]=_nullishCoalesce(_optionalChain([r, 'access', _28 => _28.validation, 'optionalAccess', _29 => _29.requiredMessage]), () => (e)))}}),s}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 l=this.isHidden(i);n!==l&&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=_optionalChain([this, 'access', _30 => _30.fieldConfigs, 'access', _31 => _31.get, 'call', _32 => _32(t), 'optionalAccess', _33 => _33.conditional, 'optionalAccess', _34 => _34.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}}, _class);var D= (_class2 =class{constructor(t,e=15){;_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);this.enableHistory=t;this.maxHistory=e}__init4() {this.history=[]}__init5() {this.historyIndex=-1}saveSnapshot(t){if(!this.enableHistory)return;let e=this.history[this.historyIndex];e&&x(e,t)||(this.historyIndex<this.history.length-1&&(this.history=this.history.slice(0,this.historyIndex+1)),this.history.push(g(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--,g(this.history[this.historyIndex])):null}redo(){return this.canRedo?(this.historyIndex++,g(this.history[this.historyIndex])):null}reset(t){this.history=[],this.historyIndex=-1,this.saveSnapshot(t)}}, _class2);var w=class{constructor(t){this.store=t}pushItem(t,e){let s=p(this.store.getState().values,t)||[];this.store.setField(t,[...s,e]),this.store.internalSaveSnapshot()}prependItem(t,e){let s=p(this.store.getState().values,t)||[];this.store.setField(t,[e,...s]),this.store.internalSaveSnapshot()}insertItem(t,e,s){let r=[...p(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=p(s.values,t);if(!Array.isArray(r))return;this.store.unregisterPrefix&&this.store.unregisterPrefix(`${t}.${e}.`);let i=r.filter((a,c)=>c!==e),n=y(s.values,t,i),l=this.store.updateDirtyForPath(t,n,this.store.getConfig().initialValues);this.store.internalUpdateState({values:n,errors:$(s.errors,t,e),touched:$(s.touched,t,e),isDirty:l}),this.store.internalSaveSnapshot(),this.revalidate(t)}swapItems(t,e,s){let r=this.store.getState(),i=[...p(r.values,t)||[]];[i[e],i[s]]=[i[s],i[e]];let n=y(r.values,t,i),l=this.store.updateDirtyForPath(t,n,this.store.getConfig().initialValues);this.store.internalUpdateState({values:n,errors:U(r.errors,t,e,s),touched:U(r.touched,t,e,s),isDirty:l}),this.store.internalSaveSnapshot(),this.revalidate(t)}moveItem(t,e,s){let r=this.store.getState(),i=[...p(r.values,t)||[]],[n]=i.splice(e,1);i.splice(s,0,n);let l=y(r.values,t,i),a=this.store.updateDirtyForPath(t,l,this.store.getConfig().initialValues);this.store.internalUpdateState({values:l,errors:L(r.errors,t,e,s),touched:L(r.touched,t,e,s),isDirty:a}),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 I=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,l]of s){let a=l(e),c=p(e,n);x(c,a)||(e=y(e,n,a),i=!0)}if(!i)break}return e}};var R= (_class3 =class{constructor(t){;_class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this);_class3.prototype.__init9.call(this);this.store=t}__init6() {this.currentValidationId=0}__init7() {this.asyncTimers={}}__init8() {this.asyncRequests={}}__init9() {this.asyncErrors={}}handleAsync(t,e){let s=this.store.depsMg.fieldConfigs.get(t)||_optionalChain([this, 'access', _35 => _35.store, 'access', _36 => _36.config, 'access', _37 => _37.fields, 'optionalAccess', _38 => _38[t]]),r=_optionalChain([s, 'optionalAccess', _39 => _39.validation, 'optionalAccess', _40 => _40.asyncValidate]);if(!r)return;this.asyncTimers[t]&&clearTimeout(this.asyncTimers[t]);let i=_nullishCoalesce(_optionalChain([s, 'access', _41 => _41.validation, 'optionalAccess', _42 => _42.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 l=await r(e,this.store.getState().values);if(this.asyncRequests[t]!==n)return;if(l)this.asyncErrors[t]=l,this.store.setError(t,l);else{delete this.asyncErrors[t];let a=this.store;if(a.validate)await a.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=_nullishCoalesce(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=_optionalChain([t, 'optionalAccess', _43 => _43.scopeFields]);_optionalChain([t, 'optionalAccess', _44 => _44.scope])&&_optionalChain([this, 'access', _45 => _45.store, 'access', _46 => _46.config, 'access', _47 => _47.scopes, 'optionalAccess', _48 => _48[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,this.store.config.defaultRequiredMessage);if(i={...i,...n},this.store.depsMg.hiddenFields.forEach(a=>{delete i[a],delete this.asyncErrors[a]}),e!==this.currentValidationId)return s.isValid;if(r){let a={...s.errors};r.forEach(d=>{i[d]?a[d]=i[d]:this.asyncErrors[d]?a[d]=this.asyncErrors[d]:delete a[d]});let c=Object.keys(a).length===0;return this.store.internalUpdateState({errors:a,isValid:c}),r.every(d=>!i[d]&&!this.asyncErrors[d])}i={...this.asyncErrors,...i};let l=Object.keys(i).length===0;return this.store.internalUpdateState({errors:i,isValid:l}),l}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))}}, _class3);var V=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(a=>{this.store.depsMg.isHidden(a)&&(delete i[a],this.store.validatorMg.clear(a))});let l=this.store.updateDirtyForPath(t,r,this.store.config.initialValues);return this.store.internalUpdateState({values:r,errors:i,isValid:Object.keys(i).length===0,isDirty:l}),this.store.config.resolver&&this.store.validatorMg.trigger([t]),this.store.validatorMg.handleAsync(t,e),{visibilitiesChanged:n.length>0}}updateAll(t){let e=g(t);this.store.config.initialValues=g(e),this.store.validatorMg.cancelAll(),this.store.depsMg.evaluateAll(e),this.store.clearDirtyPaths(),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=g(this.store.getState().values);if(this.store.depsMg.hiddenFields.forEach(i=>{r=y(r,i,void 0)}),this.store.config.transform)for(let i in this.store.config.transform){let n=this.store.config.transform[i];if(n){let l=p(r,i);r=y(r,i,n(l,this.store.getState().values))}}await t(r)}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=g(this.store.config.initialValues);this.store.depsMg.evaluateAll(t),this.store.clearDirtyPaths(),this.store.internalUpdateState({values:t,errors:{},touched:{},isValidating:{},isValid:!0,isDirty:!1,isSubmitting:!1}),this.store.historyMg.reset(t)}};function bt(){return`
|
|
2
|
-
.bit-devtools-container {
|
|
3
|
-
position: fixed;
|
|
4
|
-
bottom: 20px;
|
|
5
|
-
right: 20px;
|
|
6
|
-
z-index: 9999;
|
|
7
|
-
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
8
|
-
display: flex;
|
|
9
|
-
flex-direction: column;
|
|
10
|
-
align-items: flex-end;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.bit-devtools-trigger {
|
|
14
|
-
background: #10b981;
|
|
15
|
-
color: #fff;
|
|
16
|
-
border: none;
|
|
17
|
-
border-radius: 50%;
|
|
18
|
-
width: 48px;
|
|
19
|
-
height: 48px;
|
|
20
|
-
cursor: pointer;
|
|
21
|
-
box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
|
|
22
|
-
font-weight: bold;
|
|
23
|
-
display: flex;
|
|
24
|
-
align-items: center;
|
|
25
|
-
justify-content: center;
|
|
26
|
-
transition: transform 0.2s;
|
|
27
|
-
font-size: 16px;
|
|
28
|
-
margin-top: 16px;
|
|
29
|
-
}
|
|
30
|
-
.bit-devtools-trigger:hover { transform: scale(1.05); }
|
|
31
|
-
|
|
32
|
-
.bit-devtools-panel {
|
|
33
|
-
width: 450px;
|
|
34
|
-
max-height: 80vh;
|
|
35
|
-
background: #0f172a;
|
|
36
|
-
color: #f8fafc;
|
|
37
|
-
border-radius: 8px;
|
|
38
|
-
padding: 16px;
|
|
39
|
-
overflow-y: auto;
|
|
40
|
-
box-shadow: 0 20px 25px -5px rgba(0,0,0,0.5), 0 8px 10px -6px rgba(0,0,0,0.5);
|
|
41
|
-
border: 1px solid #334155;
|
|
42
|
-
display: flex;
|
|
43
|
-
flex-direction: column;
|
|
44
|
-
gap: 16px;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.bit-devtools-header {
|
|
48
|
-
display: flex;
|
|
49
|
-
justify-content: space-between;
|
|
50
|
-
align-items: center;
|
|
51
|
-
padding-bottom: 12px;
|
|
52
|
-
border-bottom: 1px solid #1e293b;
|
|
53
|
-
}
|
|
54
|
-
.bit-devtools-header h2 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
|
|
55
|
-
|
|
56
|
-
.bit-store-block {
|
|
57
|
-
background: #1e293b;
|
|
58
|
-
border-radius: 6px;
|
|
59
|
-
padding: 12px;
|
|
60
|
-
border: 1px solid #334155;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.bit-store-header {
|
|
64
|
-
display: flex;
|
|
65
|
-
justify-content: space-between;
|
|
66
|
-
align-items: center;
|
|
67
|
-
margin-bottom: 12px;
|
|
68
|
-
}
|
|
69
|
-
.bit-store-title { margin: 0; color: #38bdf8; font-size: 14px; font-weight: bold; }
|
|
70
|
-
|
|
71
|
-
.bit-badge-group { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
72
|
-
.bit-badge { font-size: 10px; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; font-weight: bold; }
|
|
73
|
-
.badge-success { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.2); }
|
|
74
|
-
.badge-error { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.2); }
|
|
75
|
-
.badge-warn { background: rgba(245, 158, 11, 0.2); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.2); }
|
|
76
|
-
.badge-info { background: rgba(56, 189, 248, 0.2); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.2); }
|
|
77
|
-
|
|
78
|
-
.bit-section-title { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; margin: 12px 0 4px 0; display: block; }
|
|
79
|
-
|
|
80
|
-
.bit-controls { display: flex; gap: 6px; margin-bottom: 12px; background: #0f172a; padding: 8px; border-radius: 6px; }
|
|
81
|
-
.bit-action-btn { flex: 1; background: #334155; color: #e2e8f0; border: 1px solid #475569; padding: 6px 0; border-radius: 4px; cursor: pointer; font-size: 11px; display: flex; align-items: center; justify-content: center; gap: 4px; transition: all 0.2s; }
|
|
82
|
-
.bit-action-btn:hover:not(:disabled) { background: #475569; }
|
|
83
|
-
.bit-action-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
84
|
-
.bit-btn-reset { color: #fca5a5; border-color: rgba(239,68,68,0.3); }
|
|
85
|
-
.bit-btn-reset:hover { background: rgba(239,68,68,0.1) !important; }
|
|
86
|
-
|
|
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
|
-
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 M= (_class4 =class{__init10() {this.currentStoresState={}}__init11() {this.isOpen=!1}constructor(t,e){;_class4.prototype.__init10.call(this);_class4.prototype.__init11.call(this);if(this.container=t,this.actions=e,!document.getElementById("bit-devtools-styles")){let s=document.createElement("style");s.id="bit-devtools-styles",s.textContent=bt(),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"),l=i.getAttribute("data-store");n&&l&&(n==="undo"&&this.actions.onUndo(l),n==="redo"&&this.actions.onRedo(l),n==="reset"&&this.actions.onReset(l))}})}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
|
-
<div class="bit-devtools-panel">
|
|
91
|
-
<div class="bit-devtools-header">
|
|
92
|
-
<h2><span style="font-size: 20px;">\u{1F6E0}</span> Bit-Form DevTools</h2>
|
|
93
|
-
<span style="font-size: 11px; color: #64748b;">v1.0.0</span>
|
|
94
|
-
</div>
|
|
95
|
-
`;for(let[r,i]of t){let n=Object.keys(i.errors||{}).length>0,l=i._meta||{totalSteps:0,currentIndex:-1,canUndo:!1,canRedo:!1},a=l.currentIndex+1,c=l.totalSteps;e+=`
|
|
96
|
-
<div class="bit-store-block">
|
|
97
|
-
<div class="bit-store-header">
|
|
98
|
-
<h3 class="bit-store-title">${r}</h3>
|
|
99
|
-
<div class="bit-badge-group">
|
|
100
|
-
<span class="bit-badge ${i.isValid?"badge-success":"badge-error"}">
|
|
101
|
-
${i.isValid?"\u2713 Valid":"\u2715 Invalid"}
|
|
102
|
-
</span>
|
|
103
|
-
${i.isDirty?'<span class="bit-badge badge-warn">Dirty</span>':""}
|
|
104
|
-
${i.isSubmitting?'<span class="bit-badge badge-info">\u23F3 Submitting</span>':""}
|
|
105
|
-
</div>
|
|
106
|
-
</div>
|
|
107
|
-
|
|
108
|
-
<span class="bit-section-title">Time Travel (${a}/${c})</span>
|
|
109
|
-
|
|
110
|
-
<div class="bit-controls">
|
|
111
|
-
<button class="bit-action-btn" data-action="undo" data-store="${r}" ${l.canUndo?"":"disabled"}>
|
|
112
|
-
<span>\u21BA</span> Undo
|
|
113
|
-
</button>
|
|
114
|
-
<button class="bit-action-btn" data-action="redo" data-store="${r}" ${l.canRedo?"":"disabled"}>
|
|
115
|
-
<span>\u21BB</span> Redo
|
|
116
|
-
</button>
|
|
117
|
-
<button class="bit-action-btn bit-btn-reset" data-action="reset" data-store="${r}">
|
|
118
|
-
<span>\u{1F5D1}</span> Reset
|
|
119
|
-
</button>
|
|
120
|
-
</div>
|
|
121
|
-
`,n&&(e+=`
|
|
122
|
-
<span class="bit-section-title" style="color: #f87171;">\u26A0\uFE0F Validations Failing</span>
|
|
123
|
-
<pre class="bit-error-box">${JSON.stringify(i.errors,null,2)}</pre>
|
|
124
|
-
`),e+=`
|
|
125
|
-
<span class="bit-section-title">Values</span>
|
|
126
|
-
<pre class="bit-pre">${JSON.stringify(i.values,null,2)}</pre>
|
|
127
|
-
</div>
|
|
128
|
-
`}e+="</div>"}let s=`
|
|
129
|
-
<button class="bit-devtools-trigger" style="transform: ${this.isOpen?"scale(0.9)":"scale(1)"};" title="Abrir DevTools">
|
|
130
|
-
${this.isOpen?"\u2716":"Bit"}
|
|
131
|
-
</button>
|
|
132
|
-
`;this.rootElement.innerHTML=e+s}}, _class4);function vt(o){let t=new M(o,{onUndo:r=>_optionalChain([m, 'access', _49 => _49.stores, 'access', _50 => _50[r], 'optionalAccess', _51 => _51.undo, 'call', _52 => _52()]),onRedo:r=>_optionalChain([m, 'access', _53 => _53.stores, 'access', _54 => _54[r], 'optionalAccess', _55 => _55.redo, 'call', _56 => _56()]),onReset:r=>_optionalChain([m, 'access', _57 => _57.stores, 'access', _58 => _58[r], 'optionalAccess', _59 => _59.reset, 'call', _60 => _60()])}),e=()=>{let r={};for(let[i,n]of Object.entries(m.stores)){let l=n,a=l.getState(),c=_optionalChain([l, 'optionalAccess', _61 => _61.historyMg]),d=_optionalChain([c, 'optionalAccess', _62 => _62.history])||[],f=_nullishCoalesce(_optionalChain([c, 'optionalAccess', _63 => _63.historyIndex]), () => (-1));r[i]={...a,_meta:{canUndo:_optionalChain([l, 'optionalAccess', _64 => _64.canUndo]),canRedo:_optionalChain([l, 'optionalAccess', _65 => _65.canRedo]),totalSteps:d.length,currentIndex:f}}}return r};t.updateState(e());let s=m.subscribe(()=>{t.updateState(e())});return{ui:t,destroy:()=>{s(),o.innerHTML=""}}}function xt(o,t="ws://localhost:3000"){let e=new WebSocket(t),s=new M(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 ft(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=vt(s);else if(t==="remote")console.log("[bit-form] DevTools iniciado em modo Remote."),i=xt(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= (_class5 =class{__init12() {this.cleanupFn=null}constructor(t){;_class5.prototype.__init12.call(this);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=Tt(s)}else{let s=ft();s&&typeof s.destroy=="function"&&(this.cleanupFn=s.destroy)}}destroy(){this.cleanupFn&&this.cleanupFn()}}, _class5);var pt= (_class6 =class{__init13() {this.listeners=new Set}__init14() {this.dirtyPaths=new Set}__init15() {this.configFields=new Set}constructor(t={}){;_class6.prototype.__init13.call(this);_class6.prototype.__init14.call(this);_class6.prototype.__init15.call(this);this.config=yt(t),this.depsMg=new C,this.historyMg=new D(!!this.config.enableHistory,_nullishCoalesce(this.config.historyLimit, () => (15))),this.computedMg=new I(this.config),this.validatorMg=new R(this),this.arraysMg=new w(this),this.lifecycleMg=new V(this),this.devtoolsMg=new H(this);let e=g(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.configFields.add(r),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}unregisterField(t){if(this.configFields.has(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)}registerField(t,e){this.depsMg.register(t,e,this.state.values),this.depsMg.isHidden(t)&&this.notify()}isHidden(t){return this.depsMg.isHidden(t)}isRequired(t){return this.depsMg.isRequired(t,this.state.values)}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}watch(t,e){let s=g(p(this.state.values,t));return this.subscribe(()=>{let r=p(this.state.values,t);x(r,s)||(s=g(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){let s={...this.state.errors,[t]:e};e||delete s[t],this.internalUpdateState({errors:s})}setErrors(t){this.internalUpdateState({errors:{...this.state.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)}reset(){this.lifecycleMg.reset()}registerMask(t,e){this.config.masks[t]=e}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.rebuildDirtyPaths(t,this.config.initialValues);this.internalUpdateState({values:t,isDirty:e}),this.validatorMg.validate()}}redo(){let t=this.historyMg.redo();if(t){let e=this.rebuildDirtyPaths(t,this.config.initialValues);this.internalUpdateState({values:t,isDirty:e}),this.validatorMg.validate()}}validate(t){return this.validatorMg.validate(t)}getStepStatus(t){let e=_optionalChain([this, 'access', _66 => _66.config, 'access', _67 => _67.scopes, 'optionalAccess', _68 => _68[t]])||[],s=e.some(n=>!!this.state.errors[n]),r=e.some(n=>{let l=p(this.state.values,n),a=p(this.config.initialValues,n);return!S(l,a)}),i=this.getStepErrors(t);return{hasErrors:s,isDirty:r,errors:i}}getStepErrors(t){let e=_optionalChain([this, 'access', _69 => _69.config, 'access', _70 => _70.scopes, 'optionalAccess', _71 => _71[t]])||[],s={};for(let r of e){let i=this.state.errors[r];i&&(s[r]=i)}return s}isFieldDirty(t){let e=p(this.state.values,t),s=p(this.config.initialValues,t);return!S(e,s)}isFieldValidating(t){return!!this.getState().isValidating[t]}async submit(t){return this.lifecycleMg.submit(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)}updateDirtyForPath(t,e,s){for(let n of this.dirtyPaths)n.startsWith(t+".")&&this.dirtyPaths.delete(n);let r=p(e,t),i=p(s,t);return S(r,i)?this.dirtyPaths.delete(t):this.dirtyPaths.add(t),this.dirtyPaths.size>0}clearDirtyPaths(){this.dirtyPaths.clear()}rebuildDirtyPaths(t,e){return this.dirtyPaths=O(t,e),this.dirtyPaths.size>0}cleanup(){this.listeners.clear(),this.validatorMg.cancelAll(),delete m.stores[this.storeId]}notify(){this.listeners.forEach(t=>t())}}, _class6);var St=o=>({...typeof o.getState=="function"?o.getState():o,_meta:{canUndo:o.canUndo,canRedo:o.canRedo,totalSteps:_optionalChain([o, 'access', _72 => _72.historyMg, 'optionalAccess', _73 => _73.history, 'optionalAccess', _74 => _74.length])||0,currentIndex:_nullishCoalesce(_optionalChain([o, 'access', _75 => _75.historyMg, 'optionalAccess', _76 => _76.historyIndex]), () => (-1))}}),A=null;function Tt(o){A&&(console.warn("[bit-form] Reiniciando ponte do DevTools (Fast Refresh detectado)."),A());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 l=Object.entries(m.stores);if(l.length>0){let a=l.reduce((c,[d,f])=>(c[d]=St(f),c),{});_optionalChain([t, 'optionalAccess', _77 => _77.send, 'call', _78 => _78(JSON.stringify({type:"STATE_UPDATE",payload:a}))])}e=m.subscribe((a,c)=>{if(_optionalChain([t, 'optionalAccess', _79 => _79.readyState])===WebSocket.OPEN){let d=m.stores[a];d&&t.send(JSON.stringify({type:"STATE_UPDATE",payload:{[a]:St(d)}}))}}),s=setInterval(()=>{_optionalChain([t, 'optionalAccess', _80 => _80.readyState])===WebSocket.OPEN&&t.send(JSON.stringify({type:"PING"}))},3e4)},t.onmessage=l=>{try{let{type:a,payload:c}=JSON.parse(l.data);if(a==="ACTION"){let{storeId:d,action:f}=c,h=m.stores[d];h&&typeof h[f]=="function"&&h[f]()}}catch(a){console.warn("[bit-form] Erro ao processar comando do CLI:",a)}},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(),A=null};return A=n,n}exports.a = m; exports.b = g; exports.c = S; exports.d = x; exports.e = p; exports.f = y; exports.g = kt; exports.h = gt; exports.i = Bt; exports.j = B; exports.k = mt; exports.l = u; exports.m = b; exports.n = N; exports.o = P; exports.p = _; exports.q = j; exports.r = X; exports.s = q; exports.t = W; exports.u = z; exports.v = Y; exports.w = J; exports.x = K; exports.y = G; exports.z = Z; exports.A = Q; exports.B = tt; exports.C = et; exports.D = st; exports.E = rt; exports.F = it; exports.G = Mt; exports.H = Et; exports.I = Pt; exports.J = Ct; exports.K = ot; exports.L = nt; exports.M = Dt; exports.N = at; exports.O = lt; exports.P = ct; exports.Q = dt; exports.R = wt; exports.S = ut; exports.T = Tt; exports.U = ft; exports.V = pt;
|
|
133
|
-
//# sourceMappingURL=chunk-6VDQSKUN.cjs.map
|
package/dist/chunk-KA4FAGIX.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
var F=typeof globalThis<"u"?globalThis:typeof global<"u"?global:window;F.__BIT_FORM__||(F.__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=F.__BIT_FORM__;function g(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=>g(e));let t={};for(let e in o)Object.prototype.hasOwnProperty.call(o,e)&&(t[e]=g(o[e]));return t}function S(o,t){return o===t?!0:o===null||typeof o!="object"||t===null||typeof t!="object"?!1:x(o,t)}function x(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)||!x(o[r],t[r]))return!1;return!0}function O(o,t,e="",s=new Set){if(S(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!S(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;O(o?.[i],t?.[i],n,s)}return s}var k=new Map;function p(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 l=s[n],a=s[n+1],c=/^\d+$/.test(a),d=i[l];d==null?i[l]=c?[]:{}:i[l]=Array.isArray(d)?[...d]:{...d},i=i[l]}return i[s[s.length-1]]=e,r}function kt(o,t){let e={},s=`${t}.`;for(let r in o)r!==t&&!r.startsWith(s)&&(e[r]=o[r]);return e}var $=(o,t,e)=>{let s={},r=`${t}.`;return Object.keys(o).forEach(i=>{if(!i.startsWith(r)){s[i]=o[i];return}let l=i.substring(r.length).split("."),a=parseInt(l[0],10),c=l.slice(1).join(".");if(a!==e)if(a>e){let d=a-1,f=c?`${r}${d}.${c}`:`${r}${d}`;s[f]=o[i]}else s[i]=o[i]}),s},U=(o,t,e,s)=>{let r={},i=`${t}.`;return Object.keys(o).forEach(n=>{if(!n.startsWith(i)){r[n]=o[n];return}let a=n.substring(i.length).split("."),c=parseInt(a[0],10),d=a.slice(1).join(".");if(c===e){let f=d?`${i}${s}.${d}`:`${i}${s}`;r[f]=o[n]}else if(c===s){let f=d?`${i}${e}.${d}`:`${i}${e}`;r[f]=o[n]}else r[n]=o[n]}),r},L=(o,t,e,s)=>{let r={},i=`${t}.`;return Object.keys(o).forEach(n=>{if(!n.startsWith(i)){r[n]=o[n];return}let a=n.substring(i.length).split("."),c=parseInt(a[0],10),d=a.slice(1).join("."),f=c;c===e?f=s:e<s&&c>e&&c<=s?f=c-1:e>s&&c>=s&&c<e&&(f=c+1);let h=d?`${i}${f}.${d}`:`${i}${f}`;r[h]=o[n]}),r};function gt(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 Bt(o){return gt(o)?o.errors??o:{}}var ht={"#":/\d/,A:/[a-zA-Z]/,X:/[a-zA-Z0-9]/,H:/[0-9a-fA-F]/,U:/[A-Z]/,L:/[a-z]/,"*":/./},B=(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},mt=(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},u=(o,t)=>{let e=s=>s.split("").filter(r=>ht[r]).length;return{format:s=>{let r=B(s,t?.allowChars);if(!r&&!t?.guide)return"";let n=[...Array.isArray(o)?o:[o]].sort((h,v)=>e(h)-e(v)),l=n[n.length-1];for(let h of n)if(r.length<=e(h)){l=h;break}let a="",c=0,d=t?.guide||!1,f=t?.placeholderChar||"_";for(let h=0;h<l.length;h++){let v=l[h],E=ht[v];if(c<r.length){let T=r[c];if(E)if(v==="U"&&(T=T.toUpperCase()),v==="L"&&(T=T.toLowerCase()),E.test(T))a+=T,c++;else if(d)a+=f;else break;else a+=v,T===v&&c++}else if(d)a+=E?f:v;else break}return a},parse:s=>{if(t?.customParse)return t.customParse(s);let i=u(o,t).format(s);if(t?.saveRaw){if(t?.guide){let l=(t.placeholderChar||"_").replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=new RegExp(l,"g");return i.replace(a,"")}return i}return B(i,t?.allowChars)}}},b=({prefix:o="",suffix:t="",thousand:e,decimal:s,precision:r=2,allowNegative:i=!0,saveRaw:n=!1})=>{let l=a=>{if(a==null||a==="")return"";let c="";if(typeof a=="number"?c=Math.abs(a).toFixed(r).replace(/\D/g,""):c=String(a).replace(/\D/g,""),!c&&String(a).includes("-")&&i)return"-";if(!c)return"";c=c.padStart(r+1,"0");let d=c.slice(0,-r).replace(/^0+(?=\d)/,"")||"0",f=c.slice(-r),h=d.replace(/\B(?=(\d{3})+(?!\d))/g,e);return`${(typeof a=="number"?a<0:String(a).includes("-"))&&i?"-":""}${o}${h}${s}${f}${t}`};return{format:l,parse:a=>{let c=mt(a,r),d=i?c:Math.abs(c);return n?l(d):d}}},N=o=>{let t=e=>/^3[47]/.test(e)?"#### ###### #####":/^3(?:0[0-5]|[68])/.test(e)?"#### ###### ####":"#### #### #### ####";return{format:e=>{let s=B(e,o?.allowChars),r=t(s);return u(r,o).format(e)},parse:e=>{let s=B(e,o?.allowChars),r=t(s);return u(r,o).parse(e)}}},P=o=>{let e=(o?.format||"DD/MM/YYYY")==="YYYY-MM-DD",s=u(e?"####-##-##":"##/##/####",o);return{format:r=>{let i=B(r);if(!i)return"";let n="",l="",a="";if(e?(a=i.substring(0,4),l=i.substring(4,6),n=i.substring(6,8)):(n=i.substring(0,2),l=i.substring(2,4),a=i.substring(4,8)),n.length===2){let d=parseInt(n,10);d>31&&(n="31"),d===0&&(n="01")}if(l.length===2){let d=parseInt(l,10);d>12&&(l="12"),d===0&&(l="01")}let c=e?`${a}${l}${n}`:`${n}${l}${a}`;return s.format(c)},parse:r=>s.parse(r)}};var _=b({prefix:"R$ ",thousand:".",decimal:",",precision:2}),j=b({prefix:"$",thousand:",",decimal:".",precision:2}),X=b({suffix:" \u20AC",thousand:".",decimal:",",precision:2}),q=b({prefix:"\xA3",thousand:",",decimal:".",precision:2}),W=b({prefix:"\xA5",thousand:",",decimal:".",precision:0}),z=b({suffix:"%",thousand:".",decimal:",",precision:1}),Y=b({thousand:".",decimal:",",precision:2}),J=b({thousand:".",decimal:",",precision:0}),K=u("###.###.###-##"),G=u("##.###.###/####-##"),Z=u(["(##) ####-####","(##) #####-####"]),Q=u("(##) ####-####"),tt=u("#####-###"),et=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,"")}}),st=u("##:##"),rt=u("###########"),it=u("##.###.###-X"),Mt=u("(###) ###-####"),Et=u("#####-####"),Pt=u("##/##/####"),Ct=u("###-##-####"),ot=N(),nt=u("####"),Dt=P({format:"YYYY-MM-DD",saveRaw:!0,guide:!0}),at=u("HH:HH:HH:HH:HH:HH"),lt=u("#HHHHHH"),ct=u("###.###.###.###"),dt=u("HHHH:HHHH:HHHH:HHHH:HHHH:HHHH:HHHH:HHHH"),wt=u("UU## XXXX XXXX XXXX XXXX XXXX XXXX XXXX XX",{allowChars:" "});var ut={brl:_,usd:j,eur:X,gbp:q,jpy:W,cpf:K,cnpj:G,rg:it,cep:tt,cnh:rt,phone:Z,landline:Q,date:et,time:st,ip:ct,ipv6:dt,mac:at,color:lt,cc:ot,cvv:nt,percent:z,decimal:Y,int:J};function Rt(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 yt(o={}){let t=o.initialValues||{},e=o.validation,s=o.history,{computed:r,transform:i,scopes:n}=Rt(o.fields);return{name:o.name,initialValues:g(t),resolver:e?.resolver,validationDelay:e?.delay??300,defaultRequiredMessage:e?.defaultRequiredMessage,enableHistory:s?.enabled??!1,historyLimit:s?.limit??15,computed:r,transform:i,scopes:n,masks:ut,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,e="Este campo \xE9 obrigat\xF3rio"){let s={};return this.fieldConfigs.forEach((r,i)=>{if(this.isRequired(i,t)){let n=p(t,i);this.isEmpty(n)&&(s[i]=r.validation?.requiredMessage??e)}}),s}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 l=this.isHidden(i);n!==l&&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&&x(e,t)||(this.historyIndex<this.history.length-1&&(this.history=this.history.slice(0,this.historyIndex+1)),this.history.push(g(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--,g(this.history[this.historyIndex])):null}redo(){return this.canRedo?(this.historyIndex++,g(this.history[this.historyIndex])):null}reset(t){this.history=[],this.historyIndex=-1,this.saveSnapshot(t)}};var w=class{constructor(t){this.store=t}pushItem(t,e){let s=p(this.store.getState().values,t)||[];this.store.setField(t,[...s,e]),this.store.internalSaveSnapshot()}prependItem(t,e){let s=p(this.store.getState().values,t)||[];this.store.setField(t,[e,...s]),this.store.internalSaveSnapshot()}insertItem(t,e,s){let r=[...p(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=p(s.values,t);if(!Array.isArray(r))return;this.store.unregisterPrefix&&this.store.unregisterPrefix(`${t}.${e}.`);let i=r.filter((a,c)=>c!==e),n=y(s.values,t,i),l=this.store.updateDirtyForPath(t,n,this.store.getConfig().initialValues);this.store.internalUpdateState({values:n,errors:$(s.errors,t,e),touched:$(s.touched,t,e),isDirty:l}),this.store.internalSaveSnapshot(),this.revalidate(t)}swapItems(t,e,s){let r=this.store.getState(),i=[...p(r.values,t)||[]];[i[e],i[s]]=[i[s],i[e]];let n=y(r.values,t,i),l=this.store.updateDirtyForPath(t,n,this.store.getConfig().initialValues);this.store.internalUpdateState({values:n,errors:U(r.errors,t,e,s),touched:U(r.touched,t,e,s),isDirty:l}),this.store.internalSaveSnapshot(),this.revalidate(t)}moveItem(t,e,s){let r=this.store.getState(),i=[...p(r.values,t)||[]],[n]=i.splice(e,1);i.splice(s,0,n);let l=y(r.values,t,i),a=this.store.updateDirtyForPath(t,l,this.store.getConfig().initialValues);this.store.internalUpdateState({values:l,errors:L(r.errors,t,e,s),touched:L(r.touched,t,e,s),isDirty:a}),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 I=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,l]of s){let a=l(e),c=p(e,n);x(c,a)||(e=y(e,n,a),i=!0)}if(!i)break}return e}};var R=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 l=await r(e,this.store.getState().values);if(this.asyncRequests[t]!==n)return;if(l)this.asyncErrors[t]=l,this.store.setError(t,l);else{delete this.asyncErrors[t];let a=this.store;if(a.validate)await a.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,this.store.config.defaultRequiredMessage);if(i={...i,...n},this.store.depsMg.hiddenFields.forEach(a=>{delete i[a],delete this.asyncErrors[a]}),e!==this.currentValidationId)return s.isValid;if(r){let a={...s.errors};r.forEach(d=>{i[d]?a[d]=i[d]:this.asyncErrors[d]?a[d]=this.asyncErrors[d]:delete a[d]});let c=Object.keys(a).length===0;return this.store.internalUpdateState({errors:a,isValid:c}),r.every(d=>!i[d]&&!this.asyncErrors[d])}i={...this.asyncErrors,...i};let l=Object.keys(i).length===0;return this.store.internalUpdateState({errors:i,isValid:l}),l}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 V=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(a=>{this.store.depsMg.isHidden(a)&&(delete i[a],this.store.validatorMg.clear(a))});let l=this.store.updateDirtyForPath(t,r,this.store.config.initialValues);return this.store.internalUpdateState({values:r,errors:i,isValid:Object.keys(i).length===0,isDirty:l}),this.store.config.resolver&&this.store.validatorMg.trigger([t]),this.store.validatorMg.handleAsync(t,e),{visibilitiesChanged:n.length>0}}updateAll(t){let e=g(t);this.store.config.initialValues=g(e),this.store.validatorMg.cancelAll(),this.store.depsMg.evaluateAll(e),this.store.clearDirtyPaths(),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=g(this.store.getState().values);if(this.store.depsMg.hiddenFields.forEach(i=>{r=y(r,i,void 0)}),this.store.config.transform)for(let i in this.store.config.transform){let n=this.store.config.transform[i];if(n){let l=p(r,i);r=y(r,i,n(l,this.store.getState().values))}}await t(r)}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=g(this.store.config.initialValues);this.store.depsMg.evaluateAll(t),this.store.clearDirtyPaths(),this.store.internalUpdateState({values:t,errors:{},touched:{},isValidating:{},isValid:!0,isDirty:!1,isSubmitting:!1}),this.store.historyMg.reset(t)}};function bt(){return`
|
|
2
|
-
.bit-devtools-container {
|
|
3
|
-
position: fixed;
|
|
4
|
-
bottom: 20px;
|
|
5
|
-
right: 20px;
|
|
6
|
-
z-index: 9999;
|
|
7
|
-
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
8
|
-
display: flex;
|
|
9
|
-
flex-direction: column;
|
|
10
|
-
align-items: flex-end;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.bit-devtools-trigger {
|
|
14
|
-
background: #10b981;
|
|
15
|
-
color: #fff;
|
|
16
|
-
border: none;
|
|
17
|
-
border-radius: 50%;
|
|
18
|
-
width: 48px;
|
|
19
|
-
height: 48px;
|
|
20
|
-
cursor: pointer;
|
|
21
|
-
box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
|
|
22
|
-
font-weight: bold;
|
|
23
|
-
display: flex;
|
|
24
|
-
align-items: center;
|
|
25
|
-
justify-content: center;
|
|
26
|
-
transition: transform 0.2s;
|
|
27
|
-
font-size: 16px;
|
|
28
|
-
margin-top: 16px;
|
|
29
|
-
}
|
|
30
|
-
.bit-devtools-trigger:hover { transform: scale(1.05); }
|
|
31
|
-
|
|
32
|
-
.bit-devtools-panel {
|
|
33
|
-
width: 450px;
|
|
34
|
-
max-height: 80vh;
|
|
35
|
-
background: #0f172a;
|
|
36
|
-
color: #f8fafc;
|
|
37
|
-
border-radius: 8px;
|
|
38
|
-
padding: 16px;
|
|
39
|
-
overflow-y: auto;
|
|
40
|
-
box-shadow: 0 20px 25px -5px rgba(0,0,0,0.5), 0 8px 10px -6px rgba(0,0,0,0.5);
|
|
41
|
-
border: 1px solid #334155;
|
|
42
|
-
display: flex;
|
|
43
|
-
flex-direction: column;
|
|
44
|
-
gap: 16px;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.bit-devtools-header {
|
|
48
|
-
display: flex;
|
|
49
|
-
justify-content: space-between;
|
|
50
|
-
align-items: center;
|
|
51
|
-
padding-bottom: 12px;
|
|
52
|
-
border-bottom: 1px solid #1e293b;
|
|
53
|
-
}
|
|
54
|
-
.bit-devtools-header h2 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
|
|
55
|
-
|
|
56
|
-
.bit-store-block {
|
|
57
|
-
background: #1e293b;
|
|
58
|
-
border-radius: 6px;
|
|
59
|
-
padding: 12px;
|
|
60
|
-
border: 1px solid #334155;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.bit-store-header {
|
|
64
|
-
display: flex;
|
|
65
|
-
justify-content: space-between;
|
|
66
|
-
align-items: center;
|
|
67
|
-
margin-bottom: 12px;
|
|
68
|
-
}
|
|
69
|
-
.bit-store-title { margin: 0; color: #38bdf8; font-size: 14px; font-weight: bold; }
|
|
70
|
-
|
|
71
|
-
.bit-badge-group { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
72
|
-
.bit-badge { font-size: 10px; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; font-weight: bold; }
|
|
73
|
-
.badge-success { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.2); }
|
|
74
|
-
.badge-error { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.2); }
|
|
75
|
-
.badge-warn { background: rgba(245, 158, 11, 0.2); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.2); }
|
|
76
|
-
.badge-info { background: rgba(56, 189, 248, 0.2); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.2); }
|
|
77
|
-
|
|
78
|
-
.bit-section-title { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; margin: 12px 0 4px 0; display: block; }
|
|
79
|
-
|
|
80
|
-
.bit-controls { display: flex; gap: 6px; margin-bottom: 12px; background: #0f172a; padding: 8px; border-radius: 6px; }
|
|
81
|
-
.bit-action-btn { flex: 1; background: #334155; color: #e2e8f0; border: 1px solid #475569; padding: 6px 0; border-radius: 4px; cursor: pointer; font-size: 11px; display: flex; align-items: center; justify-content: center; gap: 4px; transition: all 0.2s; }
|
|
82
|
-
.bit-action-btn:hover:not(:disabled) { background: #475569; }
|
|
83
|
-
.bit-action-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
84
|
-
.bit-btn-reset { color: #fca5a5; border-color: rgba(239,68,68,0.3); }
|
|
85
|
-
.bit-btn-reset:hover { background: rgba(239,68,68,0.1) !important; }
|
|
86
|
-
|
|
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
|
-
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 M=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=bt(),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"),l=i.getAttribute("data-store");n&&l&&(n==="undo"&&this.actions.onUndo(l),n==="redo"&&this.actions.onRedo(l),n==="reset"&&this.actions.onReset(l))}})}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
|
-
<div class="bit-devtools-panel">
|
|
91
|
-
<div class="bit-devtools-header">
|
|
92
|
-
<h2><span style="font-size: 20px;">\u{1F6E0}</span> Bit-Form DevTools</h2>
|
|
93
|
-
<span style="font-size: 11px; color: #64748b;">v1.0.0</span>
|
|
94
|
-
</div>
|
|
95
|
-
`;for(let[r,i]of t){let n=Object.keys(i.errors||{}).length>0,l=i._meta||{totalSteps:0,currentIndex:-1,canUndo:!1,canRedo:!1},a=l.currentIndex+1,c=l.totalSteps;e+=`
|
|
96
|
-
<div class="bit-store-block">
|
|
97
|
-
<div class="bit-store-header">
|
|
98
|
-
<h3 class="bit-store-title">${r}</h3>
|
|
99
|
-
<div class="bit-badge-group">
|
|
100
|
-
<span class="bit-badge ${i.isValid?"badge-success":"badge-error"}">
|
|
101
|
-
${i.isValid?"\u2713 Valid":"\u2715 Invalid"}
|
|
102
|
-
</span>
|
|
103
|
-
${i.isDirty?'<span class="bit-badge badge-warn">Dirty</span>':""}
|
|
104
|
-
${i.isSubmitting?'<span class="bit-badge badge-info">\u23F3 Submitting</span>':""}
|
|
105
|
-
</div>
|
|
106
|
-
</div>
|
|
107
|
-
|
|
108
|
-
<span class="bit-section-title">Time Travel (${a}/${c})</span>
|
|
109
|
-
|
|
110
|
-
<div class="bit-controls">
|
|
111
|
-
<button class="bit-action-btn" data-action="undo" data-store="${r}" ${l.canUndo?"":"disabled"}>
|
|
112
|
-
<span>\u21BA</span> Undo
|
|
113
|
-
</button>
|
|
114
|
-
<button class="bit-action-btn" data-action="redo" data-store="${r}" ${l.canRedo?"":"disabled"}>
|
|
115
|
-
<span>\u21BB</span> Redo
|
|
116
|
-
</button>
|
|
117
|
-
<button class="bit-action-btn bit-btn-reset" data-action="reset" data-store="${r}">
|
|
118
|
-
<span>\u{1F5D1}</span> Reset
|
|
119
|
-
</button>
|
|
120
|
-
</div>
|
|
121
|
-
`,n&&(e+=`
|
|
122
|
-
<span class="bit-section-title" style="color: #f87171;">\u26A0\uFE0F Validations Failing</span>
|
|
123
|
-
<pre class="bit-error-box">${JSON.stringify(i.errors,null,2)}</pre>
|
|
124
|
-
`),e+=`
|
|
125
|
-
<span class="bit-section-title">Values</span>
|
|
126
|
-
<pre class="bit-pre">${JSON.stringify(i.values,null,2)}</pre>
|
|
127
|
-
</div>
|
|
128
|
-
`}e+="</div>"}let s=`
|
|
129
|
-
<button class="bit-devtools-trigger" style="transform: ${this.isOpen?"scale(0.9)":"scale(1)"};" title="Abrir DevTools">
|
|
130
|
-
${this.isOpen?"\u2716":"Bit"}
|
|
131
|
-
</button>
|
|
132
|
-
`;this.rootElement.innerHTML=e+s}};function vt(o){let t=new M(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 l=n,a=l.getState(),c=l?.historyMg,d=c?.history||[],f=c?.historyIndex??-1;r[i]={...a,_meta:{canUndo:l?.canUndo,canRedo:l?.canRedo,totalSteps:d.length,currentIndex:f}}}return r};t.updateState(e());let s=m.subscribe(()=>{t.updateState(e())});return{ui:t,destroy:()=>{s(),o.innerHTML=""}}}function xt(o,t="ws://localhost:3000"){let e=new WebSocket(t),s=new M(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 ft(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=vt(s);else if(t==="remote")console.log("[bit-form] DevTools iniciado em modo Remote."),i=xt(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=Tt(s)}else{let s=ft();s&&typeof s.destroy=="function"&&(this.cleanupFn=s.destroy)}}destroy(){this.cleanupFn&&this.cleanupFn()}};var pt=class{state;listeners=new Set;config;depsMg;historyMg;validatorMg;computedMg;lifecycleMg;arraysMg;devtoolsMg;storeId;dirtyPaths=new Set;configFields=new Set;constructor(t={}){this.config=yt(t),this.depsMg=new C,this.historyMg=new D(!!this.config.enableHistory,this.config.historyLimit??15),this.computedMg=new I(this.config),this.validatorMg=new R(this),this.arraysMg=new w(this),this.lifecycleMg=new V(this),this.devtoolsMg=new H(this);let e=g(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.configFields.add(r),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}unregisterField(t){if(this.configFields.has(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)}registerField(t,e){this.depsMg.register(t,e,this.state.values),this.depsMg.isHidden(t)&&this.notify()}isHidden(t){return this.depsMg.isHidden(t)}isRequired(t){return this.depsMg.isRequired(t,this.state.values)}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}watch(t,e){let s=g(p(this.state.values,t));return this.subscribe(()=>{let r=p(this.state.values,t);x(r,s)||(s=g(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){let s={...this.state.errors,[t]:e};e||delete s[t],this.internalUpdateState({errors:s})}setErrors(t){this.internalUpdateState({errors:{...this.state.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)}reset(){this.lifecycleMg.reset()}registerMask(t,e){this.config.masks[t]=e}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.rebuildDirtyPaths(t,this.config.initialValues);this.internalUpdateState({values:t,isDirty:e}),this.validatorMg.validate()}}redo(){let t=this.historyMg.redo();if(t){let e=this.rebuildDirtyPaths(t,this.config.initialValues);this.internalUpdateState({values:t,isDirty:e}),this.validatorMg.validate()}}validate(t){return this.validatorMg.validate(t)}getStepStatus(t){let e=this.config.scopes?.[t]||[],s=e.some(n=>!!this.state.errors[n]),r=e.some(n=>{let l=p(this.state.values,n),a=p(this.config.initialValues,n);return!S(l,a)}),i=this.getStepErrors(t);return{hasErrors:s,isDirty:r,errors:i}}getStepErrors(t){let e=this.config.scopes?.[t]||[],s={};for(let r of e){let i=this.state.errors[r];i&&(s[r]=i)}return s}isFieldDirty(t){let e=p(this.state.values,t),s=p(this.config.initialValues,t);return!S(e,s)}isFieldValidating(t){return!!this.getState().isValidating[t]}async submit(t){return this.lifecycleMg.submit(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)}updateDirtyForPath(t,e,s){for(let n of this.dirtyPaths)n.startsWith(t+".")&&this.dirtyPaths.delete(n);let r=p(e,t),i=p(s,t);return S(r,i)?this.dirtyPaths.delete(t):this.dirtyPaths.add(t),this.dirtyPaths.size>0}clearDirtyPaths(){this.dirtyPaths.clear()}rebuildDirtyPaths(t,e){return this.dirtyPaths=O(t,e),this.dirtyPaths.size>0}cleanup(){this.listeners.clear(),this.validatorMg.cancelAll(),delete m.stores[this.storeId]}notify(){this.listeners.forEach(t=>t())}};var St=o=>({...typeof o.getState=="function"?o.getState():o,_meta:{canUndo:o.canUndo,canRedo:o.canRedo,totalSteps:o.historyMg?.history?.length||0,currentIndex:o.historyMg?.historyIndex??-1}}),A=null;function Tt(o){A&&(console.warn("[bit-form] Reiniciando ponte do DevTools (Fast Refresh detectado)."),A());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 l=Object.entries(m.stores);if(l.length>0){let a=l.reduce((c,[d,f])=>(c[d]=St(f),c),{});t?.send(JSON.stringify({type:"STATE_UPDATE",payload:a}))}e=m.subscribe((a,c)=>{if(t?.readyState===WebSocket.OPEN){let d=m.stores[a];d&&t.send(JSON.stringify({type:"STATE_UPDATE",payload:{[a]:St(d)}}))}}),s=setInterval(()=>{t?.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:"PING"}))},3e4)},t.onmessage=l=>{try{let{type:a,payload:c}=JSON.parse(l.data);if(a==="ACTION"){let{storeId:d,action:f}=c,h=m.stores[d];h&&typeof h[f]=="function"&&h[f]()}}catch(a){console.warn("[bit-form] Erro ao processar comando do CLI:",a)}},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(),A=null};return A=n,n}export{m as a,g as b,S as c,x as d,p as e,y as f,kt as g,gt as h,Bt as i,B as j,mt as k,u as l,b as m,N as n,P as o,_ as p,j as q,X as r,q as s,W as t,z as u,Y as v,J as w,K as x,G as y,Z as z,Q as A,tt as B,et as C,st as D,rt as E,it as F,Mt as G,Et as H,Pt as I,Ct as J,ot as K,nt as L,Dt as M,at as N,lt as O,ct as P,dt as Q,wt as R,ut as S,Tt as T,ft as U,pt as V};
|
|
133
|
-
//# sourceMappingURL=chunk-KA4FAGIX.js.map
|