@lehnihon/bit-form 1.0.1 → 1.0.6

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.
Files changed (51) hide show
  1. package/dist/angular/index.cjs +1 -1
  2. package/dist/angular/index.cjs.map +1 -1
  3. package/dist/angular/index.d.cts +1 -1
  4. package/dist/angular/index.d.ts +1 -1
  5. package/dist/angular/index.js +1 -1
  6. package/dist/{chunk-ACHDD75T.cjs → chunk-6VDQSKUN.cjs} +6 -6
  7. package/dist/chunk-6VDQSKUN.cjs.map +1 -0
  8. package/dist/chunk-KA4FAGIX.js +133 -0
  9. package/dist/chunk-KA4FAGIX.js.map +1 -0
  10. package/dist/{chunk-E6WTGKQ6.js → chunk-UFYHEI6S.js} +2 -2
  11. package/dist/{chunk-M4QDZTNK.cjs → chunk-Z6ITPS2B.cjs} +2 -2
  12. package/dist/chunk-Z6ITPS2B.cjs.map +1 -0
  13. package/dist/devtools/bridge.cjs +1 -1
  14. package/dist/devtools/bridge.cjs.map +1 -1
  15. package/dist/devtools/bridge.js +1 -1
  16. package/dist/devtools/index.cjs +1 -1
  17. package/dist/devtools/index.cjs.map +1 -1
  18. package/dist/devtools/index.js +1 -1
  19. package/dist/{index-CAsZliSy.d.cts → index-BD_l3aH5.d.cts} +2 -0
  20. package/dist/{index-_zEeufKs.d.ts → index-CPKnWBVv.d.ts} +2 -0
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +1 -1
  24. package/dist/index.d.ts +1 -1
  25. package/dist/index.js +1 -1
  26. package/dist/react/index.cjs +1 -1
  27. package/dist/react/index.cjs.map +1 -1
  28. package/dist/react/index.d.cts +2 -2
  29. package/dist/react/index.d.ts +2 -2
  30. package/dist/react/index.js +1 -1
  31. package/dist/react-native/index.cjs +1 -1
  32. package/dist/react-native/index.cjs.map +1 -1
  33. package/dist/react-native/index.d.cts +2 -2
  34. package/dist/react-native/index.d.ts +2 -2
  35. package/dist/react-native/index.js +1 -1
  36. package/dist/resolvers/joi.cjs.map +1 -1
  37. package/dist/resolvers/yup.cjs.map +1 -1
  38. package/dist/resolvers/zod.cjs.map +1 -1
  39. package/dist/{use-bit-watch-DuG0-qkf.d.cts → use-bit-watch-BSWy9rG7.d.cts} +1 -1
  40. package/dist/{use-bit-watch-paD4Vkvz.d.ts → use-bit-watch-CoCFwS-F.d.ts} +1 -1
  41. package/dist/vue/index.cjs +1 -1
  42. package/dist/vue/index.cjs.map +1 -1
  43. package/dist/vue/index.d.cts +1 -1
  44. package/dist/vue/index.d.ts +1 -1
  45. package/dist/vue/index.js +1 -1
  46. package/package.json +1 -1
  47. package/dist/chunk-ACHDD75T.cjs.map +0 -1
  48. package/dist/chunk-AM65OKT2.js +0 -133
  49. package/dist/chunk-AM65OKT2.js.map +0 -1
  50. package/dist/chunk-M4QDZTNK.cjs.map +0 -1
  51. /package/dist/{chunk-E6WTGKQ6.js.map → chunk-UFYHEI6S.js.map} +0 -0
@@ -1,2 +1,2 @@
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 _chunkACHDD75Tcjs = require('../chunk-ACHDD75T.cjs');var _core = require('@angular/core');var h=new (0, _core.InjectionToken)("BIT_STORE");function C(t){return{provide:h,useValue:t}}function S(){let t=_core.inject.call(void 0, h,{optional:!0});if(!t)throw new Error('BitForm: N\xE3o foi poss\xEDvel encontrar a BitStore. Certifique-se de que voc\xEA adicionou "provideBitStore(store)" nos providers do seu componente.');return t}function $(){let t=S(),e=_core.inject.call(void 0, _core.DestroyRef),o=_core.signal.call(void 0, t.getState()),r=_core.signal.call(void 0, null),n=_core.signal.call(void 0, null),c=t.subscribe(()=>{o.set(t.getState())});e.onDestroy(()=>c());let g=_core.computed.call(void 0, ()=>o().isValid),s=_core.computed.call(void 0, ()=>o().isSubmitting),i=_core.computed.call(void 0, ()=>o().isDirty),d=_core.computed.call(void 0, ()=>(o(),t.canUndo)),u=_core.computed.call(void 0, ()=>(o(),t.canRedo));return{store:t,isValid:g,isSubmitting:s,isDirty:i,canUndo:d,canRedo:u,getValues:()=>o().values,getErrors:()=>o().errors,getTouched:()=>o().touched,submit:B=>f=>(_optionalChain([f, 'optionalAccess', _2 => _2.preventDefault, 'call', _3 => _3()]),_optionalChain([f, 'optionalAccess', _4 => _4.stopPropagation, 'call', _5 => _5()]),t.submit(B)),onSubmit:B=>f=>(_optionalChain([f, 'optionalAccess', _6 => _6.preventDefault, 'call', _7 => _7()]),_optionalChain([f, 'optionalAccess', _8 => _8.stopPropagation, 'call', _9 => _9()]),r.set(null),t.submit(async l=>{try{let a=await B(l);n.set(a),r.set(null)}catch(a){_chunkACHDD75Tcjs.h.call(void 0, a)?t.setServerErrors(_chunkACHDD75Tcjs.i.call(void 0, a)):r.set(a instanceof Error?a:new Error(String(a)))}})),submitError:r,lastResponse:n,reset:()=>{t.reset(),r.set(null),n.set(null)},validate:t.validate.bind(t),setValues:t.setValues.bind(t),setError:t.setError.bind(t),setErrors:t.setErrors.bind(t),setServerErrors:t.setServerErrors.bind(t),setField:t.setField.bind(t),blurField:t.blurField.bind(t),registerMask:t.registerMask.bind(t),pushItem:t.pushItem.bind(t),prependItem:t.prependItem.bind(t),removeItem:t.removeItem.bind(t),insertItem:t.insertItem.bind(t),moveItem:t.moveItem.bind(t),swapItems:t.swapItems.bind(t),undo:t.undo.bind(t),redo:t.redo.bind(t)}}function J(t,e,o){let r=_core.inject.call(void 0, h),n=_core.signal.call(void 0, r.getState()),c=r.subscribe(()=>{n.set(r.getState())});_core.inject.call(void 0, _core.DestroyRef).onDestroy(()=>{c(),r.unregisterField&&r.unregisterField(t)}),e&&r.registerField(t,e);let g=_core.computed.call(void 0, ()=>_chunkACHDD75Tcjs.e.call(void 0, n().values,t)),s=_core.computed.call(void 0, ()=>n().errors[t]),i=_core.computed.call(void 0, ()=>!!n().touched[t]),d=_core.computed.call(void 0, ()=>(n(),r.isFieldDirty(t))),u=_core.computed.call(void 0, ()=>(n(),r.isFieldValidating(t))),m=_core.computed.call(void 0, ()=>(n(),r.isHidden(t))),R=_core.computed.call(void 0, ()=>(n(),r.isRequired(t))),V=_core.computed.call(void 0, ()=>i()&&!!s()),b=_nullishCoalesce(_optionalChain([o, 'optionalAccess', _10 => _10.mask]), () => (_optionalChain([r, 'access', _11 => _11.config, 'access', _12 => _12.fields, 'optionalAccess', _13 => _13[t], 'optionalAccess', _14 => _14.mask]))),P=b?typeof b=="string"?r.config.masks[b]:b:void 0,x=_core.computed.call(void 0, ()=>{let a=g();return a==null||a===""?"":P?P.format(a):String(a)}),B=a=>{if(!P){r.setField(t,a);return}let p=String(_nullishCoalesce(a, () => ("")));r.setField(t,P.parse(p))},f=()=>r.blurField(t),l=_core.computed.call(void 0, ()=>({isDirty:d(),isValidating:u(),isHidden:m(),isRequired:R(),hasError:!!s()}));return{value:g,displayValue:x,error:s,touched:i,invalid:V,isDirty:d,isValidating:u,isHidden:m,isRequired:R,fieldMeta:l,setValue:B,setBlur:f,update:a=>B(_nullishCoalesce(_optionalChain([a, 'optionalAccess', _15 => _15.target, 'optionalAccess', _16 => _16.value]), () => (a)))}}var F=()=>Math.random().toString(36).substring(2,9);function Y(t){let e=_core.inject.call(void 0, h),o=_core.inject.call(void 0, _core.DestroyRef),r=()=>{let s=_chunkACHDD75Tcjs.e.call(void 0, e.getState().values,t);return Array.isArray(s)?s:[]},n=_core.signal.call(void 0, r()),c=_core.signal.call(void 0, n().map(F)),g=e.subscribe(()=>{let s=r(),i=_core.untracked.call(void 0, c);n.set(s),s.length!==i.length&&(s.length>i.length?c.set([...i,...Array.from({length:s.length-i.length},F)]):c.set(i.slice(0,s.length)))});return o.onDestroy(()=>{g(),e.unregisterPrefix&&e.unregisterPrefix(`${t}.`)}),{fields:_core.computed.call(void 0, ()=>n().map((s,i)=>({key:c()[i]||`temp-${i}`,value:s,index:i}))),length:_core.computed.call(void 0, ()=>n().length),append:s=>{c.update(i=>[...i,F()]),e.pushItem(t,s)},prepend:s=>{c.update(i=>[F(),...i]),e.prependItem(t,s)},remove:s=>{c.update(i=>i.filter((d,u)=>u!==s)),e.removeItem(t,s)},insert:(s,i)=>{c.update(d=>{let u=[...d];return u.splice(s,0,F()),u}),e.insertItem(t,s,i)},swap:(s,i)=>{c.update(d=>{let u=[...d];return[u[s],u[i]]=[u[i],u[s]],u}),e.swapItems(t,s,i)},move:(s,i)=>{c.update(d=>{let u=[...d],[m]=u.splice(s,1);return u.splice(i,0,m),u}),e.moveItem(t,s,i)},replace:s=>{c.set(s.map(()=>F())),e.setField(t,s)},clear:()=>{c.set([]),e.setField(t,[])}}}function et(t,e){let o=Object.keys(t),r=Object.keys(e);return o.length!==r.length?!1:o.every(n=>t[n]===e[n])}function rt(t){let e=S(),o=e.getStepStatus(t),r=_core.signal.call(void 0, o),n=e.subscribe(()=>{let u=e.getStepStatus(t),m=r();(u.hasErrors!==m.hasErrors||u.isDirty!==m.isDirty||!et(u.errors,m.errors))&&r.set(u)});try{_core.inject.call(void 0, _core.DestroyRef).onDestroy(()=>n())}catch (e2){}let c=async()=>{let u=await e.validate({scope:t}),m=e.getStepErrors(t);return{valid:u,errors:m}},g=()=>e.getStepErrors(t),s=_core.computed.call(void 0, ()=>!r().hasErrors),i=_core.computed.call(void 0, ()=>r().isDirty),d=_core.computed.call(void 0, ()=>r().errors);return{scopeName:t,status:r,errors:d,validate:c,getErrors:g,isValid:s,isDirty:i,unsubscribe:n}}function nt(t,e){let o=Object.keys(t),r=Object.keys(e);return o.length!==r.length?!1:o.every(n=>t[n]===e[n])}function it(t){let e=S(),o=_core.signal.call(void 0, 0),r=_core.computed.call(void 0, ()=>_nullishCoalesce(t[o()], () => (""))),n=()=>_nullishCoalesce(t[o()], () => ("")),c=_core.signal.call(void 0, e.getStepStatus(n())),g=()=>{let l=n(),a=e.getStepStatus(l),p=c();(a.hasErrors!==p.hasErrors||a.isDirty!==p.isDirty||!nt(a.errors,p.errors))&&c.set(a)},s=e.subscribe(g);try{_core.inject.call(void 0, _core.DestroyRef).onDestroy(()=>s())}catch (e3){}let i=async()=>{let l=n(),a=await e.validate({scope:l}),p=e.getStepErrors(l);return{valid:a,errors:p}},d=()=>e.getStepErrors(n()),u=async()=>{let l=n(),a=await e.validate({scope:l});if(a){let p=Math.min(o()+1,t.length-1);o.set(p),c.set(e.getStepStatus(_nullishCoalesce(t[p], () => (""))))}else{let p=e.getStepErrors(l),j=Object.keys(p);j.length>0&&e.markFieldsTouched(j)}return a},m=()=>{let l=Math.max(o()-1,0);o.set(l),c.set(e.getStepStatus(_nullishCoalesce(t[l], () => (""))))},R=l=>{let a=Math.max(0,Math.min(l-1,t.length-1));o.set(a),c.set(e.getStepStatus(_nullishCoalesce(t[a], () => (""))))},V=_core.computed.call(void 0, ()=>o()+1),b=_core.computed.call(void 0, ()=>o()===0),P=_core.computed.call(void 0, ()=>o()>=t.length-1),x=_core.computed.call(void 0, ()=>!c().hasErrors),B=_core.computed.call(void 0, ()=>c().isDirty),f=_core.computed.call(void 0, ()=>c().errors);return{step:V,stepIndex:o,scope:r,next:u,prev:m,goTo:R,isFirst:b,isLast:P,status:c,errors:f,isValid:x,isDirty:B,validate:i,getErrors:d}}function lt(t){let e=S(),o=_core.inject.call(void 0, _core.DestroyRef),r=_core.signal.call(void 0, _chunkACHDD75Tcjs.e.call(void 0, e.getState().values,t),{equal:_chunkACHDD75Tcjs.d}),n=e.watch(t,c=>{r.set(c)});return o.onDestroy(n),r.asReadonly()}exports.injectBitArray = Y; exports.injectBitField = J; exports.injectBitForm = $; exports.injectBitScope = rt; exports.injectBitSteps = it; exports.injectBitWatch = lt; exports.provideBitStore = C; exports.useBitStore = S;
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 _chunk6VDQSKUNcjs = require('../chunk-6VDQSKUN.cjs');var _core = require('@angular/core');var h=new (0, _core.InjectionToken)("BIT_STORE");function C(t){return{provide:h,useValue:t}}function S(){let t=_core.inject.call(void 0, h,{optional:!0});if(!t)throw new Error('BitForm: N\xE3o foi poss\xEDvel encontrar a BitStore. Certifique-se de que voc\xEA adicionou "provideBitStore(store)" nos providers do seu componente.');return t}function $(){let t=S(),e=_core.inject.call(void 0, _core.DestroyRef),o=_core.signal.call(void 0, t.getState()),r=_core.signal.call(void 0, null),n=_core.signal.call(void 0, null),c=t.subscribe(()=>{o.set(t.getState())});e.onDestroy(()=>c());let g=_core.computed.call(void 0, ()=>o().isValid),s=_core.computed.call(void 0, ()=>o().isSubmitting),i=_core.computed.call(void 0, ()=>o().isDirty),d=_core.computed.call(void 0, ()=>(o(),t.canUndo)),u=_core.computed.call(void 0, ()=>(o(),t.canRedo));return{store:t,isValid:g,isSubmitting:s,isDirty:i,canUndo:d,canRedo:u,getValues:()=>o().values,getErrors:()=>o().errors,getTouched:()=>o().touched,submit:B=>f=>(_optionalChain([f, 'optionalAccess', _2 => _2.preventDefault, 'call', _3 => _3()]),_optionalChain([f, 'optionalAccess', _4 => _4.stopPropagation, 'call', _5 => _5()]),t.submit(B)),onSubmit:B=>f=>(_optionalChain([f, 'optionalAccess', _6 => _6.preventDefault, 'call', _7 => _7()]),_optionalChain([f, 'optionalAccess', _8 => _8.stopPropagation, 'call', _9 => _9()]),r.set(null),t.submit(async l=>{try{let a=await B(l);n.set(a),r.set(null)}catch(a){_chunk6VDQSKUNcjs.h.call(void 0, a)?t.setServerErrors(_chunk6VDQSKUNcjs.i.call(void 0, a)):r.set(a instanceof Error?a:new Error(String(a)))}})),submitError:r,lastResponse:n,reset:()=>{t.reset(),r.set(null),n.set(null)},validate:t.validate.bind(t),setValues:t.setValues.bind(t),setError:t.setError.bind(t),setErrors:t.setErrors.bind(t),setServerErrors:t.setServerErrors.bind(t),setField:t.setField.bind(t),blurField:t.blurField.bind(t),registerMask:t.registerMask.bind(t),pushItem:t.pushItem.bind(t),prependItem:t.prependItem.bind(t),removeItem:t.removeItem.bind(t),insertItem:t.insertItem.bind(t),moveItem:t.moveItem.bind(t),swapItems:t.swapItems.bind(t),undo:t.undo.bind(t),redo:t.redo.bind(t)}}function J(t,e,o){let r=_core.inject.call(void 0, h),n=_core.signal.call(void 0, r.getState()),c=r.subscribe(()=>{n.set(r.getState())});_core.inject.call(void 0, _core.DestroyRef).onDestroy(()=>{c(),r.unregisterField&&r.unregisterField(t)}),e&&r.registerField(t,e);let g=_core.computed.call(void 0, ()=>_chunk6VDQSKUNcjs.e.call(void 0, n().values,t)),s=_core.computed.call(void 0, ()=>n().errors[t]),i=_core.computed.call(void 0, ()=>!!n().touched[t]),d=_core.computed.call(void 0, ()=>(n(),r.isFieldDirty(t))),u=_core.computed.call(void 0, ()=>(n(),r.isFieldValidating(t))),m=_core.computed.call(void 0, ()=>(n(),r.isHidden(t))),R=_core.computed.call(void 0, ()=>(n(),r.isRequired(t))),V=_core.computed.call(void 0, ()=>i()&&!!s()),b=_nullishCoalesce(_optionalChain([o, 'optionalAccess', _10 => _10.mask]), () => (_optionalChain([r, 'access', _11 => _11.config, 'access', _12 => _12.fields, 'optionalAccess', _13 => _13[t], 'optionalAccess', _14 => _14.mask]))),P=b?typeof b=="string"?r.config.masks[b]:b:void 0,x=_core.computed.call(void 0, ()=>{let a=g();return a==null||a===""?"":P?P.format(a):String(a)}),B=a=>{if(!P){r.setField(t,a);return}let p=String(_nullishCoalesce(a, () => ("")));r.setField(t,P.parse(p))},f=()=>r.blurField(t),l=_core.computed.call(void 0, ()=>({isDirty:d(),isValidating:u(),isHidden:m(),isRequired:R(),hasError:!!s()}));return{value:g,displayValue:x,error:s,touched:i,invalid:V,isDirty:d,isValidating:u,isHidden:m,isRequired:R,fieldMeta:l,setValue:B,setBlur:f,update:a=>B(_nullishCoalesce(_optionalChain([a, 'optionalAccess', _15 => _15.target, 'optionalAccess', _16 => _16.value]), () => (a)))}}var F=()=>Math.random().toString(36).substring(2,9);function Y(t){let e=_core.inject.call(void 0, h),o=_core.inject.call(void 0, _core.DestroyRef),r=()=>{let s=_chunk6VDQSKUNcjs.e.call(void 0, e.getState().values,t);return Array.isArray(s)?s:[]},n=_core.signal.call(void 0, r()),c=_core.signal.call(void 0, n().map(F)),g=e.subscribe(()=>{let s=r(),i=_core.untracked.call(void 0, c);n.set(s),s.length!==i.length&&(s.length>i.length?c.set([...i,...Array.from({length:s.length-i.length},F)]):c.set(i.slice(0,s.length)))});return o.onDestroy(()=>{g(),e.unregisterPrefix&&e.unregisterPrefix(`${t}.`)}),{fields:_core.computed.call(void 0, ()=>n().map((s,i)=>({key:c()[i]||`temp-${i}`,value:s,index:i}))),length:_core.computed.call(void 0, ()=>n().length),append:s=>{c.update(i=>[...i,F()]),e.pushItem(t,s)},prepend:s=>{c.update(i=>[F(),...i]),e.prependItem(t,s)},remove:s=>{c.update(i=>i.filter((d,u)=>u!==s)),e.removeItem(t,s)},insert:(s,i)=>{c.update(d=>{let u=[...d];return u.splice(s,0,F()),u}),e.insertItem(t,s,i)},swap:(s,i)=>{c.update(d=>{let u=[...d];return[u[s],u[i]]=[u[i],u[s]],u}),e.swapItems(t,s,i)},move:(s,i)=>{c.update(d=>{let u=[...d],[m]=u.splice(s,1);return u.splice(i,0,m),u}),e.moveItem(t,s,i)},replace:s=>{c.set(s.map(()=>F())),e.setField(t,s)},clear:()=>{c.set([]),e.setField(t,[])}}}function et(t,e){let o=Object.keys(t),r=Object.keys(e);return o.length!==r.length?!1:o.every(n=>t[n]===e[n])}function rt(t){let e=S(),o=e.getStepStatus(t),r=_core.signal.call(void 0, o),n=e.subscribe(()=>{let u=e.getStepStatus(t),m=r();(u.hasErrors!==m.hasErrors||u.isDirty!==m.isDirty||!et(u.errors,m.errors))&&r.set(u)});try{_core.inject.call(void 0, _core.DestroyRef).onDestroy(()=>n())}catch (e2){}let c=async()=>{let u=await e.validate({scope:t}),m=e.getStepErrors(t);return{valid:u,errors:m}},g=()=>e.getStepErrors(t),s=_core.computed.call(void 0, ()=>!r().hasErrors),i=_core.computed.call(void 0, ()=>r().isDirty),d=_core.computed.call(void 0, ()=>r().errors);return{scopeName:t,status:r,errors:d,validate:c,getErrors:g,isValid:s,isDirty:i,unsubscribe:n}}function nt(t,e){let o=Object.keys(t),r=Object.keys(e);return o.length!==r.length?!1:o.every(n=>t[n]===e[n])}function it(t){let e=S(),o=_core.signal.call(void 0, 0),r=_core.computed.call(void 0, ()=>_nullishCoalesce(t[o()], () => (""))),n=()=>_nullishCoalesce(t[o()], () => ("")),c=_core.signal.call(void 0, e.getStepStatus(n())),g=()=>{let l=n(),a=e.getStepStatus(l),p=c();(a.hasErrors!==p.hasErrors||a.isDirty!==p.isDirty||!nt(a.errors,p.errors))&&c.set(a)},s=e.subscribe(g);try{_core.inject.call(void 0, _core.DestroyRef).onDestroy(()=>s())}catch (e3){}let i=async()=>{let l=n(),a=await e.validate({scope:l}),p=e.getStepErrors(l);return{valid:a,errors:p}},d=()=>e.getStepErrors(n()),u=async()=>{let l=n(),a=await e.validate({scope:l});if(a){let p=Math.min(o()+1,t.length-1);o.set(p),c.set(e.getStepStatus(_nullishCoalesce(t[p], () => (""))))}else{let p=e.getStepErrors(l),j=Object.keys(p);j.length>0&&e.markFieldsTouched(j)}return a},m=()=>{let l=Math.max(o()-1,0);o.set(l),c.set(e.getStepStatus(_nullishCoalesce(t[l], () => (""))))},R=l=>{let a=Math.max(0,Math.min(l-1,t.length-1));o.set(a),c.set(e.getStepStatus(_nullishCoalesce(t[a], () => (""))))},V=_core.computed.call(void 0, ()=>o()+1),b=_core.computed.call(void 0, ()=>o()===0),P=_core.computed.call(void 0, ()=>o()>=t.length-1),x=_core.computed.call(void 0, ()=>!c().hasErrors),B=_core.computed.call(void 0, ()=>c().isDirty),f=_core.computed.call(void 0, ()=>c().errors);return{step:V,stepIndex:o,scope:r,next:u,prev:m,goTo:R,isFirst:b,isLast:P,status:c,errors:f,isValid:x,isDirty:B,validate:i,getErrors:d}}function lt(t){let e=S(),o=_core.inject.call(void 0, _core.DestroyRef),r=_core.signal.call(void 0, _chunk6VDQSKUNcjs.e.call(void 0, e.getState().values,t),{equal:_chunk6VDQSKUNcjs.d}),n=e.watch(t,c=>{r.set(c)});return o.onDestroy(n),r.asReadonly()}exports.injectBitArray = Y; exports.injectBitField = J; exports.injectBitForm = $; exports.injectBitScope = rt; exports.injectBitSteps = it; exports.injectBitWatch = lt; exports.provideBitStore = C; exports.useBitStore = S;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/leandrocarol/Projetos/bit-form/dist/angular/index.cjs","../../src/angular/provider.ts","../../src/angular/inject-bit-form.ts","../../src/angular/inject-bit-field.ts","../../src/angular/inject-bit-array.ts"],"names":["BIT_STORE_TOKEN","InjectionToken","provideBitStore","store","useBitStore","inject","injectBitForm","destroyRef","stateSignal","signal","submitError","lastResponse","sub","isValid","computed","isSubmitting","isDirty","canUndo","canRedo","onSuccess","event","handler","values","result","err","isValidationErrorShape","extractServerErrors","injectBitField","path","config","options","unsubscribe","value","getDeepValue","error","touched","isValidating","isHidden","isRequired","invalid","maskOption","resolvedMask","displayValue","val","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C,CAAA,CAED,OAAAhD,CAAAA,CAAW,SAAA,CAAU,CAAA,CAAA,EAAM,CACzB+C,CAAAA,CAAM,CAAA,CACFnD,CAAAA,CAAM,gBAAA,EAAkBA,CAAAA,CAAM,gBAAA,CAAiB,CAAA,EAAA","file":"/Users/leandrocarol/Projetos/bit-form/dist/angular/index.cjs","sourcesContent":[null,"import { inject, InjectionToken, Provider } from \"@angular/core\"; // IMPORTANTE: Adicione o 'inject' aqui\nimport { BitStore } from \"../core\";\n\nexport const BIT_STORE_TOKEN = new InjectionToken<BitStore<any>>(\"BIT_STORE\");\n\nexport function provideBitStore(store: BitStore<any>): Provider {\n return { provide: BIT_STORE_TOKEN, useValue: store };\n}\n\nexport function useBitStore<T extends object>() {\n const store = inject(BIT_STORE_TOKEN, { optional: true });\n\n if (!store) {\n throw new Error(\n \"BitForm: Não foi possível encontrar a BitStore. \" +\n 'Certifique-se de que você adicionou \"provideBitStore(store)\" nos providers do seu componente.',\n );\n }\n\n return store as BitStore<T>;\n}\n","import { signal, computed, inject, DestroyRef } from \"@angular/core\";\nimport { useBitStore } from \"./provider\";\nimport { isValidationErrorShape, extractServerErrors } from \"../core/utils\";\n\nexport function injectBitForm<T extends object>() {\n const store = useBitStore<T>();\n const destroyRef = inject(DestroyRef);\n const stateSignal = signal(store.getState());\n const submitError = signal<Error | null>(null);\n const lastResponse = signal<unknown>(null);\n\n const sub = store.subscribe(() => {\n stateSignal.set(store.getState());\n });\n\n destroyRef.onDestroy(() => sub());\n\n const isValid = computed(() => stateSignal().isValid);\n const isSubmitting = computed(() => stateSignal().isSubmitting);\n const isDirty = computed(() => stateSignal().isDirty);\n\n const canUndo = computed(() => {\n stateSignal();\n return store.canUndo;\n });\n\n const canRedo = computed(() => {\n stateSignal();\n return store.canRedo;\n });\n\n const getValues = () => stateSignal().values;\n const getErrors = () => stateSignal().errors;\n const getTouched = () => stateSignal().touched;\n\n const submit = (onSuccess: (values: T) => void | Promise<void>) => {\n return (event?: Event) => {\n event?.preventDefault();\n event?.stopPropagation();\n return store.submit(onSuccess);\n };\n };\n\n const onSubmit = (handler: (values: T) => Promise<unknown>) => {\n return (event?: Event) => {\n event?.preventDefault();\n event?.stopPropagation();\n submitError.set(null);\n return store.submit(async (values) => {\n try {\n const result = await handler(values);\n lastResponse.set(result);\n submitError.set(null);\n } catch (err) {\n if (isValidationErrorShape(err)) {\n store.setServerErrors(extractServerErrors(err));\n } else {\n submitError.set(\n err instanceof Error ? err : new Error(String(err)),\n );\n }\n }\n });\n };\n };\n\n const reset = () => {\n store.reset();\n submitError.set(null);\n lastResponse.set(null);\n };\n\n return {\n store,\n isValid,\n isSubmitting,\n isDirty,\n canUndo,\n canRedo,\n getValues,\n getErrors,\n getTouched,\n submit,\n onSubmit,\n submitError,\n lastResponse,\n reset,\n validate: store.validate.bind(store),\n setValues: store.setValues.bind(store),\n setError: store.setError.bind(store),\n setErrors: store.setErrors.bind(store),\n setServerErrors: store.setServerErrors.bind(store),\n setField: store.setField.bind(store),\n blurField: store.blurField.bind(store),\n registerMask: store.registerMask.bind(store),\n pushItem: store.pushItem.bind(store),\n prependItem: store.prependItem.bind(store),\n removeItem: store.removeItem.bind(store),\n insertItem: store.insertItem.bind(store),\n moveItem: store.moveItem.bind(store),\n swapItems: store.swapItems.bind(store),\n undo: store.undo.bind(store),\n redo: store.redo.bind(store),\n };\n}\n","import { inject, DestroyRef, computed, signal } from \"@angular/core\";\nimport { BIT_STORE_TOKEN } from \"./provider\";\nimport {\n BitFieldDefinition,\n BitFieldOptions,\n getDeepValue,\n BitPath,\n BitPathValue,\n} from \"../core\";\n\nexport function injectBitField<\n TValue = any,\n TForm extends object = any,\n P extends BitPath<TForm> = BitPath<TForm>,\n>(path: P, config?: BitFieldDefinition<TForm>, options?: BitFieldOptions) {\n const store = inject(BIT_STORE_TOKEN);\n\n const stateSignal = signal(store.getState());\n\n const unsubscribe = store.subscribe(() => {\n stateSignal.set(store.getState());\n });\n\n inject(DestroyRef).onDestroy(() => {\n unsubscribe();\n if (store.unregisterField) {\n store.unregisterField(path as string);\n }\n });\n\n if (config) {\n store.registerField(path as string, config as any);\n }\n\n const value = computed(\n () =>\n getDeepValue(\n stateSignal().values,\n path as string,\n ) as BitPathValue<TForm, P>,\n );\n const error = computed(\n () => (stateSignal().errors as Record<string, any>)[path],\n );\n const touched = computed(\n () => !!(stateSignal().touched as Record<string, any>)[path],\n );\n\n const isDirty = computed(() => {\n stateSignal();\n return store.isFieldDirty(path);\n });\n\n const isValidating = computed(() => {\n stateSignal();\n return store.isFieldValidating(path);\n });\n\n const isHidden = computed(() => {\n stateSignal();\n return store.isHidden(path);\n });\n\n const isRequired = computed(() => {\n stateSignal();\n return store.isRequired(path);\n });\n\n const invalid = computed(() => touched() && !!error());\n\n const maskOption =\n options?.mask ?? store.config.fields?.[path as string]?.mask;\n const resolvedMask = maskOption\n ? typeof maskOption === \"string\"\n ? store.config.masks![maskOption]\n : maskOption\n : undefined;\n\n const displayValue = computed(() => {\n const val = value();\n if (val === undefined || val === null || val === \"\") return \"\";\n\n return resolvedMask ? resolvedMask.format(val) : String(val);\n });\n\n const setValue = (val: any) => {\n if (!resolvedMask) {\n store.setField(path, val);\n return;\n }\n\n const stringVal = String(val ?? \"\");\n store.setField(path, resolvedMask.parse(stringVal) as any);\n };\n\n const setBlur = () => store.blurField(path);\n\n const fieldMeta = computed(() => ({\n isDirty: isDirty(),\n isValidating: isValidating(),\n isHidden: isHidden(),\n isRequired: isRequired(),\n hasError: !!error(),\n }));\n\n return {\n value,\n displayValue,\n error,\n touched,\n invalid,\n isDirty,\n isValidating,\n isHidden,\n isRequired,\n fieldMeta,\n setValue,\n setBlur,\n update: (e: any) => setValue(e?.target?.value ?? e),\n };\n}\n","import { DestroyRef, signal, computed, inject, untracked } from \"@angular/core\";\nimport { BIT_STORE_TOKEN } from \"./provider\";\nimport {\n getDeepValue,\n BitArrayPath,\n BitPathValue,\n BitArrayItem,\n BitPath,\n} from \"../core\";\n\nconst generateId = () => Math.random().toString(36).substring(2, 9);\n\nexport function injectBitArray<\n TForm extends object = any,\n P extends BitArrayPath<TForm> = BitArrayPath<TForm>,\n>(path: P) {\n const store = inject(BIT_STORE_TOKEN);\n const destroyRef = inject(DestroyRef);\n\n const getRaw = () => {\n const val = getDeepValue(\n store.getState().values,\n path as string,\n ) as BitPathValue<TForm, P>;\n return Array.isArray(val)\n ? (val as BitArrayItem<BitPathValue<TForm, P>>[])\n : [];\n };\n\n const valuesSig = signal<BitArrayItem<BitPathValue<TForm, P>>[]>(getRaw());\n const idsSig = signal<string[]>(valuesSig().map(generateId));\n\n const unsub = store.subscribe(() => {\n const next = getRaw();\n const ids = untracked(idsSig);\n valuesSig.set(next);\n\n if (next.length !== ids.length) {\n if (next.length > ids.length) {\n idsSig.set([\n ...ids,\n ...Array.from({ length: next.length - ids.length }, generateId),\n ]);\n } else {\n idsSig.set(ids.slice(0, next.length));\n }\n }\n });\n\n destroyRef.onDestroy(() => {\n unsub();\n if (store.unregisterPrefix) store.unregisterPrefix(`${path as string}.`);\n });\n\n return {\n fields: computed(() =>\n valuesSig().map((v, i) => ({\n key: idsSig()[i] || `temp-${i}`,\n value: v,\n index: i,\n })),\n ),\n length: computed(() => valuesSig().length),\n append: (v: BitArrayItem<BitPathValue<TForm, P>>) => {\n idsSig.update((ids) => [...ids, generateId()]);\n store.pushItem(path, v);\n },\n prepend: (v: BitArrayItem<BitPathValue<TForm, P>>) => {\n idsSig.update((ids) => [generateId(), ...ids]);\n store.prependItem(path, v);\n },\n remove: (i: number) => {\n idsSig.update((ids) => ids.filter((_, idx) => idx !== i));\n store.removeItem(path, i);\n },\n insert: (index: number, v: BitArrayItem<BitPathValue<TForm, P>>) => {\n idsSig.update((ids) => {\n const c = [...ids];\n c.splice(index, 0, generateId());\n return c;\n });\n store.insertItem(path, index, v);\n },\n swap: (a: number, b: number) => {\n idsSig.update((ids) => {\n const c = [...ids];\n [c[a], c[b]] = [c[b], c[a]];\n return c;\n });\n store.swapItems(path, a, b);\n },\n move: (f: number, t: number) => {\n idsSig.update((ids) => {\n const c = [...ids];\n const [it] = c.splice(f, 1);\n c.splice(t, 0, it);\n return c;\n });\n store.moveItem(path, f, t);\n },\n replace: (items: BitArrayItem<BitPathValue<TForm, P>>[]) => {\n idsSig.set(items.map(() => generateId()));\n store.setField(path as unknown as BitPath<TForm>, items as any);\n },\n clear: () => {\n idsSig.set([]);\n store.setField(path as unknown as BitPath<TForm>, [] as any);\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/bit-form/bit-form/dist/angular/index.cjs","../../src/angular/provider.ts","../../src/angular/inject-bit-form.ts","../../src/angular/inject-bit-field.ts","../../src/angular/inject-bit-array.ts"],"names":["BIT_STORE_TOKEN","InjectionToken","provideBitStore","store","useBitStore","inject","injectBitForm","destroyRef","stateSignal","signal","submitError","lastResponse","sub","isValid","computed","isSubmitting","isDirty","canUndo","canRedo","onSuccess","event","handler","values","result","err","isValidationErrorShape","extractServerErrors","injectBitField","path","config","options","unsubscribe","value","getDeepValue","error","touched","isValidating","isHidden","isRequired","invalid","maskOption","resolvedMask","displayValue","val","setValue","stringVal","setBlur","fieldMeta","e","generateId","injectBitArray","getRaw","valuesSig","idsSig","unsub","next","ids","untracked"],"mappings":"AAAA,0uBAA8D,qCCAb,IAGpCA,CAAAA,CAAkB,IAAIC,yBAAAA,CAA8B,WAAW,CAAA,CAErE,SAASC,CAAAA,CAAgBC,CAAAA,CAAgC,CAC9D,MAAO,CAAE,OAAA,CAASH,CAAAA,CAAiB,QAAA,CAAUG,CAAM,CACrD,CAEO,SAASC,CAAAA,CAAAA,CAAgC,CAC9C,IAAMD,CAAAA,CAAQE,0BAAAA,CAAOL,CAAiB,CAAE,QAAA,CAAU,CAAA,CAAK,CAAC,CAAA,CAExD,EAAA,CAAI,CAACG,CAAAA,CACH,MAAM,IAAI,KAAA,CACR,wJAEF,CAAA,CAGF,OAAOA,CACT,CCpBA,SAIgBG,CAAAA,CAAAA,CAAkC,CAChD,IAAMH,CAA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AAAA,CAAiB2C,CAAU,CAAA,CAAE,GAAA,CAAIH,CAAU,CAAC,CAAA,CAErDK,CAAAA,CAAQnD,CAAAA,CAAM,SAAA,CAAU,CAAA,CAAA,EAAM,CAClC,IAAMoD,CAAAA,CAAOJ,CAAAA,CAAO,CAAA,CACdK,CAAAA,CAAMC,6BAAAA,CAAgB,CAAA,CAC5BL,CAAAA,CAAU,GAAA,CAAIG,CAAI,CAAA,CAEdA,CAAAA,CAAK,MAAA,GAAWC,CAAAA,CAAI,MAAA,EAAA,CAClBD,CAAAA,CAAK,MAAA,CAASC,CAAAA,CAAI,MAAA,CACpBH,CAAAA,CAAO,GAAA,CAAI,CACT,GAAGG,CAAAA,CACH,GAAG,KAAA,CAAM,IAAA,CAAK,CAAE,MAAA,CAAQD,CAAAA,CAAK,MAAA,CAASC,CAAAA,CAAI,MAAO,CAAA,CAAGP,CAAU,CAChE,CAAC,CAAA,CAEDI,CAAAA,CAAO,GAAA,CAAIG,CAAAA,CAAI,KAAA,CAAM,CAAA,CAAGD,CAAAA,CAAK,MAAM,CAAC,CAAA,CAG1C,CAAC,CAAA,CAED,OAAAhD,CAAAA,CAAW,SAAA,CAAU,CAAA,CAAA,EAAM,CACzB+C,CAAAA,CAAM,CAAA,CACFnD,CAAAA,CAAM,gBAAA,EAAkBA,CAAAA,CAAM,gBAAA,CAAiB,CAAA,EAAA","file":"/home/runner/work/bit-form/bit-form/dist/angular/index.cjs","sourcesContent":[null,"import { inject, InjectionToken, Provider } from \"@angular/core\"; // IMPORTANTE: Adicione o 'inject' aqui\nimport { BitStore } from \"../core\";\n\nexport const BIT_STORE_TOKEN = new InjectionToken<BitStore<any>>(\"BIT_STORE\");\n\nexport function provideBitStore(store: BitStore<any>): Provider {\n return { provide: BIT_STORE_TOKEN, useValue: store };\n}\n\nexport function useBitStore<T extends object>() {\n const store = inject(BIT_STORE_TOKEN, { optional: true });\n\n if (!store) {\n throw new Error(\n \"BitForm: Não foi possível encontrar a BitStore. \" +\n 'Certifique-se de que você adicionou \"provideBitStore(store)\" nos providers do seu componente.',\n );\n }\n\n return store as BitStore<T>;\n}\n","import { signal, computed, inject, DestroyRef } from \"@angular/core\";\nimport { useBitStore } from \"./provider\";\nimport { isValidationErrorShape, extractServerErrors } from \"../core/utils\";\n\nexport function injectBitForm<T extends object>() {\n const store = useBitStore<T>();\n const destroyRef = inject(DestroyRef);\n const stateSignal = signal(store.getState());\n const submitError = signal<Error | null>(null);\n const lastResponse = signal<unknown>(null);\n\n const sub = store.subscribe(() => {\n stateSignal.set(store.getState());\n });\n\n destroyRef.onDestroy(() => sub());\n\n const isValid = computed(() => stateSignal().isValid);\n const isSubmitting = computed(() => stateSignal().isSubmitting);\n const isDirty = computed(() => stateSignal().isDirty);\n\n const canUndo = computed(() => {\n stateSignal();\n return store.canUndo;\n });\n\n const canRedo = computed(() => {\n stateSignal();\n return store.canRedo;\n });\n\n const getValues = () => stateSignal().values;\n const getErrors = () => stateSignal().errors;\n const getTouched = () => stateSignal().touched;\n\n const submit = (onSuccess: (values: T) => void | Promise<void>) => {\n return (event?: Event) => {\n event?.preventDefault();\n event?.stopPropagation();\n return store.submit(onSuccess);\n };\n };\n\n const onSubmit = (handler: (values: T) => Promise<unknown>) => {\n return (event?: Event) => {\n event?.preventDefault();\n event?.stopPropagation();\n submitError.set(null);\n return store.submit(async (values) => {\n try {\n const result = await handler(values);\n lastResponse.set(result);\n submitError.set(null);\n } catch (err) {\n if (isValidationErrorShape(err)) {\n store.setServerErrors(extractServerErrors(err));\n } else {\n submitError.set(\n err instanceof Error ? err : new Error(String(err)),\n );\n }\n }\n });\n };\n };\n\n const reset = () => {\n store.reset();\n submitError.set(null);\n lastResponse.set(null);\n };\n\n return {\n store,\n isValid,\n isSubmitting,\n isDirty,\n canUndo,\n canRedo,\n getValues,\n getErrors,\n getTouched,\n submit,\n onSubmit,\n submitError,\n lastResponse,\n reset,\n validate: store.validate.bind(store),\n setValues: store.setValues.bind(store),\n setError: store.setError.bind(store),\n setErrors: store.setErrors.bind(store),\n setServerErrors: store.setServerErrors.bind(store),\n setField: store.setField.bind(store),\n blurField: store.blurField.bind(store),\n registerMask: store.registerMask.bind(store),\n pushItem: store.pushItem.bind(store),\n prependItem: store.prependItem.bind(store),\n removeItem: store.removeItem.bind(store),\n insertItem: store.insertItem.bind(store),\n moveItem: store.moveItem.bind(store),\n swapItems: store.swapItems.bind(store),\n undo: store.undo.bind(store),\n redo: store.redo.bind(store),\n };\n}\n","import { inject, DestroyRef, computed, signal } from \"@angular/core\";\nimport { BIT_STORE_TOKEN } from \"./provider\";\nimport {\n BitFieldDefinition,\n BitFieldOptions,\n getDeepValue,\n BitPath,\n BitPathValue,\n} from \"../core\";\n\nexport function injectBitField<\n TValue = any,\n TForm extends object = any,\n P extends BitPath<TForm> = BitPath<TForm>,\n>(path: P, config?: BitFieldDefinition<TForm>, options?: BitFieldOptions) {\n const store = inject(BIT_STORE_TOKEN);\n\n const stateSignal = signal(store.getState());\n\n const unsubscribe = store.subscribe(() => {\n stateSignal.set(store.getState());\n });\n\n inject(DestroyRef).onDestroy(() => {\n unsubscribe();\n if (store.unregisterField) {\n store.unregisterField(path as string);\n }\n });\n\n if (config) {\n store.registerField(path as string, config as any);\n }\n\n const value = computed(\n () =>\n getDeepValue(\n stateSignal().values,\n path as string,\n ) as BitPathValue<TForm, P>,\n );\n const error = computed(\n () => (stateSignal().errors as Record<string, any>)[path],\n );\n const touched = computed(\n () => !!(stateSignal().touched as Record<string, any>)[path],\n );\n\n const isDirty = computed(() => {\n stateSignal();\n return store.isFieldDirty(path);\n });\n\n const isValidating = computed(() => {\n stateSignal();\n return store.isFieldValidating(path);\n });\n\n const isHidden = computed(() => {\n stateSignal();\n return store.isHidden(path);\n });\n\n const isRequired = computed(() => {\n stateSignal();\n return store.isRequired(path);\n });\n\n const invalid = computed(() => touched() && !!error());\n\n const maskOption =\n options?.mask ?? store.config.fields?.[path as string]?.mask;\n const resolvedMask = maskOption\n ? typeof maskOption === \"string\"\n ? store.config.masks![maskOption]\n : maskOption\n : undefined;\n\n const displayValue = computed(() => {\n const val = value();\n if (val === undefined || val === null || val === \"\") return \"\";\n\n return resolvedMask ? resolvedMask.format(val) : String(val);\n });\n\n const setValue = (val: any) => {\n if (!resolvedMask) {\n store.setField(path, val);\n return;\n }\n\n const stringVal = String(val ?? \"\");\n store.setField(path, resolvedMask.parse(stringVal) as any);\n };\n\n const setBlur = () => store.blurField(path);\n\n const fieldMeta = computed(() => ({\n isDirty: isDirty(),\n isValidating: isValidating(),\n isHidden: isHidden(),\n isRequired: isRequired(),\n hasError: !!error(),\n }));\n\n return {\n value,\n displayValue,\n error,\n touched,\n invalid,\n isDirty,\n isValidating,\n isHidden,\n isRequired,\n fieldMeta,\n setValue,\n setBlur,\n update: (e: any) => setValue(e?.target?.value ?? e),\n };\n}\n","import { DestroyRef, signal, computed, inject, untracked } from \"@angular/core\";\nimport { BIT_STORE_TOKEN } from \"./provider\";\nimport {\n getDeepValue,\n BitArrayPath,\n BitPathValue,\n BitArrayItem,\n BitPath,\n} from \"../core\";\n\nconst generateId = () => Math.random().toString(36).substring(2, 9);\n\nexport function injectBitArray<\n TForm extends object = any,\n P extends BitArrayPath<TForm> = BitArrayPath<TForm>,\n>(path: P) {\n const store = inject(BIT_STORE_TOKEN);\n const destroyRef = inject(DestroyRef);\n\n const getRaw = () => {\n const val = getDeepValue(\n store.getState().values,\n path as string,\n ) as BitPathValue<TForm, P>;\n return Array.isArray(val)\n ? (val as BitArrayItem<BitPathValue<TForm, P>>[])\n : [];\n };\n\n const valuesSig = signal<BitArrayItem<BitPathValue<TForm, P>>[]>(getRaw());\n const idsSig = signal<string[]>(valuesSig().map(generateId));\n\n const unsub = store.subscribe(() => {\n const next = getRaw();\n const ids = untracked(idsSig);\n valuesSig.set(next);\n\n if (next.length !== ids.length) {\n if (next.length > ids.length) {\n idsSig.set([\n ...ids,\n ...Array.from({ length: next.length - ids.length }, generateId),\n ]);\n } else {\n idsSig.set(ids.slice(0, next.length));\n }\n }\n });\n\n destroyRef.onDestroy(() => {\n unsub();\n if (store.unregisterPrefix) store.unregisterPrefix(`${path as string}.`);\n });\n\n return {\n fields: computed(() =>\n valuesSig().map((v, i) => ({\n key: idsSig()[i] || `temp-${i}`,\n value: v,\n index: i,\n })),\n ),\n length: computed(() => valuesSig().length),\n append: (v: BitArrayItem<BitPathValue<TForm, P>>) => {\n idsSig.update((ids) => [...ids, generateId()]);\n store.pushItem(path, v);\n },\n prepend: (v: BitArrayItem<BitPathValue<TForm, P>>) => {\n idsSig.update((ids) => [generateId(), ...ids]);\n store.prependItem(path, v);\n },\n remove: (i: number) => {\n idsSig.update((ids) => ids.filter((_, idx) => idx !== i));\n store.removeItem(path, i);\n },\n insert: (index: number, v: BitArrayItem<BitPathValue<TForm, P>>) => {\n idsSig.update((ids) => {\n const c = [...ids];\n c.splice(index, 0, generateId());\n return c;\n });\n store.insertItem(path, index, v);\n },\n swap: (a: number, b: number) => {\n idsSig.update((ids) => {\n const c = [...ids];\n [c[a], c[b]] = [c[b], c[a]];\n return c;\n });\n store.swapItems(path, a, b);\n },\n move: (f: number, t: number) => {\n idsSig.update((ids) => {\n const c = [...ids];\n const [it] = c.splice(f, 1);\n c.splice(t, 0, it);\n return c;\n });\n store.moveItem(path, f, t);\n },\n replace: (items: BitArrayItem<BitPathValue<TForm, P>>[]) => {\n idsSig.set(items.map(() => generateId()));\n store.setField(path as unknown as BitPath<TForm>, items as any);\n },\n clear: () => {\n idsSig.set([]);\n store.setField(path as unknown as BitPath<TForm>, [] as any);\n },\n };\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import * as _angular_core from '@angular/core';
2
2
  import { Provider, computed, signal, Signal } from '@angular/core';
3
- import { B as BitStore } from '../index-CAsZliSy.cjs';
3
+ import { B as BitStore } from '../index-BD_l3aH5.cjs';
4
4
  import { e as BitErrors, n as BitTouched, k as BitPath, l as BitPathValue, B as BitMask, b as BitArrayPath, a as BitArrayItem, g as BitFieldDefinition, h as BitFieldOptions, S as ScopeStatus, V as ValidateScopeResult } from '../bus-DAwKIiMY.cjs';
5
5
 
6
6
  declare function provideBitStore(store: BitStore<any>): Provider;
@@ -1,6 +1,6 @@
1
1
  import * as _angular_core from '@angular/core';
2
2
  import { Provider, computed, signal, Signal } from '@angular/core';
3
- import { B as BitStore } from '../index-_zEeufKs.js';
3
+ import { B as BitStore } from '../index-CPKnWBVv.js';
4
4
  import { e as BitErrors, n as BitTouched, k as BitPath, l as BitPathValue, B as BitMask, b as BitArrayPath, a as BitArrayItem, g as BitFieldDefinition, h as BitFieldOptions, S as ScopeStatus, V as ValidateScopeResult } from '../bus-DAwKIiMY.js';
5
5
 
6
6
  declare function provideBitStore(store: BitStore<any>): Provider;
@@ -1,2 +1,2 @@
1
- import{d as w,e as v,h as k,i as A}from"../chunk-AM65OKT2.js";import{inject as K,InjectionToken as W}from"@angular/core";var h=new W("BIT_STORE");function C(t){return{provide:h,useValue:t}}function S(){let t=K(h,{optional:!0});if(!t)throw new Error('BitForm: N\xE3o foi poss\xEDvel encontrar a BitStore. Certifique-se de que voc\xEA adicionou "provideBitStore(store)" nos providers do seu componente.');return t}import{signal as I,computed as E,inject as L,DestroyRef as U}from"@angular/core";function $(){let t=S(),e=L(U),o=I(t.getState()),r=I(null),n=I(null),c=t.subscribe(()=>{o.set(t.getState())});e.onDestroy(()=>c());let g=E(()=>o().isValid),s=E(()=>o().isSubmitting),i=E(()=>o().isDirty),d=E(()=>(o(),t.canUndo)),u=E(()=>(o(),t.canRedo));return{store:t,isValid:g,isSubmitting:s,isDirty:i,canUndo:d,canRedo:u,getValues:()=>o().values,getErrors:()=>o().errors,getTouched:()=>o().touched,submit:B=>f=>(f?.preventDefault(),f?.stopPropagation(),t.submit(B)),onSubmit:B=>f=>(f?.preventDefault(),f?.stopPropagation(),r.set(null),t.submit(async l=>{try{let a=await B(l);n.set(a),r.set(null)}catch(a){k(a)?t.setServerErrors(A(a)):r.set(a instanceof Error?a:new Error(String(a)))}})),submitError:r,lastResponse:n,reset:()=>{t.reset(),r.set(null),n.set(null)},validate:t.validate.bind(t),setValues:t.setValues.bind(t),setError:t.setError.bind(t),setErrors:t.setErrors.bind(t),setServerErrors:t.setServerErrors.bind(t),setField:t.setField.bind(t),blurField:t.blurField.bind(t),registerMask:t.registerMask.bind(t),pushItem:t.pushItem.bind(t),prependItem:t.prependItem.bind(t),removeItem:t.removeItem.bind(t),insertItem:t.insertItem.bind(t),moveItem:t.moveItem.bind(t),swapItems:t.swapItems.bind(t),undo:t.undo.bind(t),redo:t.redo.bind(t)}}import{inject as O,DestroyRef as z,computed as y,signal as G}from"@angular/core";function J(t,e,o){let r=O(h),n=G(r.getState()),c=r.subscribe(()=>{n.set(r.getState())});O(z).onDestroy(()=>{c(),r.unregisterField&&r.unregisterField(t)}),e&&r.registerField(t,e);let g=y(()=>v(n().values,t)),s=y(()=>n().errors[t]),i=y(()=>!!n().touched[t]),d=y(()=>(n(),r.isFieldDirty(t))),u=y(()=>(n(),r.isFieldValidating(t))),m=y(()=>(n(),r.isHidden(t))),R=y(()=>(n(),r.isRequired(t))),V=y(()=>i()&&!!s()),b=o?.mask??r.config.fields?.[t]?.mask,P=b?typeof b=="string"?r.config.masks[b]:b:void 0,x=y(()=>{let a=g();return a==null||a===""?"":P?P.format(a):String(a)}),B=a=>{if(!P){r.setField(t,a);return}let p=String(a??"");r.setField(t,P.parse(p))},f=()=>r.blurField(t),l=y(()=>({isDirty:d(),isValidating:u(),isHidden:m(),isRequired:R(),hasError:!!s()}));return{value:g,displayValue:x,error:s,touched:i,invalid:V,isDirty:d,isValidating:u,isHidden:m,isRequired:R,fieldMeta:l,setValue:B,setBlur:f,update:a=>B(a?.target?.value??a)}}import{DestroyRef as Q,signal as q,computed as M,inject as _,untracked as X}from"@angular/core";var F=()=>Math.random().toString(36).substring(2,9);function Y(t){let e=_(h),o=_(Q),r=()=>{let s=v(e.getState().values,t);return Array.isArray(s)?s:[]},n=q(r()),c=q(n().map(F)),g=e.subscribe(()=>{let s=r(),i=X(c);n.set(s),s.length!==i.length&&(s.length>i.length?c.set([...i,...Array.from({length:s.length-i.length},F)]):c.set(i.slice(0,s.length)))});return o.onDestroy(()=>{g(),e.unregisterPrefix&&e.unregisterPrefix(`${t}.`)}),{fields:M(()=>n().map((s,i)=>({key:c()[i]||`temp-${i}`,value:s,index:i}))),length:M(()=>n().length),append:s=>{c.update(i=>[...i,F()]),e.pushItem(t,s)},prepend:s=>{c.update(i=>[F(),...i]),e.prependItem(t,s)},remove:s=>{c.update(i=>i.filter((d,u)=>u!==s)),e.removeItem(t,s)},insert:(s,i)=>{c.update(d=>{let u=[...d];return u.splice(s,0,F()),u}),e.insertItem(t,s,i)},swap:(s,i)=>{c.update(d=>{let u=[...d];return[u[s],u[i]]=[u[i],u[s]],u}),e.swapItems(t,s,i)},move:(s,i)=>{c.update(d=>{let u=[...d],[m]=u.splice(s,1);return u.splice(i,0,m),u}),e.moveItem(t,s,i)},replace:s=>{c.set(s.map(()=>F())),e.setField(t,s)},clear:()=>{c.set([]),e.setField(t,[])}}}import{signal as Z,computed as D,DestroyRef as N,inject as tt}from"@angular/core";function et(t,e){let o=Object.keys(t),r=Object.keys(e);return o.length!==r.length?!1:o.every(n=>t[n]===e[n])}function rt(t){let e=S(),o=e.getStepStatus(t),r=Z(o),n=e.subscribe(()=>{let u=e.getStepStatus(t),m=r();(u.hasErrors!==m.hasErrors||u.isDirty!==m.isDirty||!et(u.errors,m.errors))&&r.set(u)});try{tt(N).onDestroy(()=>n())}catch{}let c=async()=>{let u=await e.validate({scope:t}),m=e.getStepErrors(t);return{valid:u,errors:m}},g=()=>e.getStepErrors(t),s=D(()=>!r().hasErrors),i=D(()=>r().isDirty),d=D(()=>r().errors);return{scopeName:t,status:r,errors:d,validate:c,getErrors:g,isValid:s,isDirty:i,unsubscribe:n}}import{signal as H,computed as T,DestroyRef as st,inject as ot}from"@angular/core";function nt(t,e){let o=Object.keys(t),r=Object.keys(e);return o.length!==r.length?!1:o.every(n=>t[n]===e[n])}function it(t){let e=S(),o=H(0),r=T(()=>t[o()]??""),n=()=>t[o()]??"",c=H(e.getStepStatus(n())),g=()=>{let l=n(),a=e.getStepStatus(l),p=c();(a.hasErrors!==p.hasErrors||a.isDirty!==p.isDirty||!nt(a.errors,p.errors))&&c.set(a)},s=e.subscribe(g);try{ot(st).onDestroy(()=>s())}catch{}let i=async()=>{let l=n(),a=await e.validate({scope:l}),p=e.getStepErrors(l);return{valid:a,errors:p}},d=()=>e.getStepErrors(n()),u=async()=>{let l=n(),a=await e.validate({scope:l});if(a){let p=Math.min(o()+1,t.length-1);o.set(p),c.set(e.getStepStatus(t[p]??""))}else{let p=e.getStepErrors(l),j=Object.keys(p);j.length>0&&e.markFieldsTouched(j)}return a},m=()=>{let l=Math.max(o()-1,0);o.set(l),c.set(e.getStepStatus(t[l]??""))},R=l=>{let a=Math.max(0,Math.min(l-1,t.length-1));o.set(a),c.set(e.getStepStatus(t[a]??""))},V=T(()=>o()+1),b=T(()=>o()===0),P=T(()=>o()>=t.length-1),x=T(()=>!c().hasErrors),B=T(()=>c().isDirty),f=T(()=>c().errors);return{step:V,stepIndex:o,scope:r,next:u,prev:m,goTo:R,isFirst:b,isLast:P,status:c,errors:f,isValid:x,isDirty:B,validate:i,getErrors:d}}import{DestroyRef as at,signal as ct,inject as ut}from"@angular/core";function lt(t){let e=S(),o=ut(at),r=ct(v(e.getState().values,t),{equal:w}),n=e.watch(t,c=>{r.set(c)});return o.onDestroy(n),r.asReadonly()}export{Y as injectBitArray,J as injectBitField,$ as injectBitForm,rt as injectBitScope,it as injectBitSteps,lt as injectBitWatch,C as provideBitStore,S as useBitStore};
1
+ import{d as w,e as v,h as k,i as A}from"../chunk-KA4FAGIX.js";import{inject as K,InjectionToken as W}from"@angular/core";var h=new W("BIT_STORE");function C(t){return{provide:h,useValue:t}}function S(){let t=K(h,{optional:!0});if(!t)throw new Error('BitForm: N\xE3o foi poss\xEDvel encontrar a BitStore. Certifique-se de que voc\xEA adicionou "provideBitStore(store)" nos providers do seu componente.');return t}import{signal as I,computed as E,inject as L,DestroyRef as U}from"@angular/core";function $(){let t=S(),e=L(U),o=I(t.getState()),r=I(null),n=I(null),c=t.subscribe(()=>{o.set(t.getState())});e.onDestroy(()=>c());let g=E(()=>o().isValid),s=E(()=>o().isSubmitting),i=E(()=>o().isDirty),d=E(()=>(o(),t.canUndo)),u=E(()=>(o(),t.canRedo));return{store:t,isValid:g,isSubmitting:s,isDirty:i,canUndo:d,canRedo:u,getValues:()=>o().values,getErrors:()=>o().errors,getTouched:()=>o().touched,submit:B=>f=>(f?.preventDefault(),f?.stopPropagation(),t.submit(B)),onSubmit:B=>f=>(f?.preventDefault(),f?.stopPropagation(),r.set(null),t.submit(async l=>{try{let a=await B(l);n.set(a),r.set(null)}catch(a){k(a)?t.setServerErrors(A(a)):r.set(a instanceof Error?a:new Error(String(a)))}})),submitError:r,lastResponse:n,reset:()=>{t.reset(),r.set(null),n.set(null)},validate:t.validate.bind(t),setValues:t.setValues.bind(t),setError:t.setError.bind(t),setErrors:t.setErrors.bind(t),setServerErrors:t.setServerErrors.bind(t),setField:t.setField.bind(t),blurField:t.blurField.bind(t),registerMask:t.registerMask.bind(t),pushItem:t.pushItem.bind(t),prependItem:t.prependItem.bind(t),removeItem:t.removeItem.bind(t),insertItem:t.insertItem.bind(t),moveItem:t.moveItem.bind(t),swapItems:t.swapItems.bind(t),undo:t.undo.bind(t),redo:t.redo.bind(t)}}import{inject as O,DestroyRef as z,computed as y,signal as G}from"@angular/core";function J(t,e,o){let r=O(h),n=G(r.getState()),c=r.subscribe(()=>{n.set(r.getState())});O(z).onDestroy(()=>{c(),r.unregisterField&&r.unregisterField(t)}),e&&r.registerField(t,e);let g=y(()=>v(n().values,t)),s=y(()=>n().errors[t]),i=y(()=>!!n().touched[t]),d=y(()=>(n(),r.isFieldDirty(t))),u=y(()=>(n(),r.isFieldValidating(t))),m=y(()=>(n(),r.isHidden(t))),R=y(()=>(n(),r.isRequired(t))),V=y(()=>i()&&!!s()),b=o?.mask??r.config.fields?.[t]?.mask,P=b?typeof b=="string"?r.config.masks[b]:b:void 0,x=y(()=>{let a=g();return a==null||a===""?"":P?P.format(a):String(a)}),B=a=>{if(!P){r.setField(t,a);return}let p=String(a??"");r.setField(t,P.parse(p))},f=()=>r.blurField(t),l=y(()=>({isDirty:d(),isValidating:u(),isHidden:m(),isRequired:R(),hasError:!!s()}));return{value:g,displayValue:x,error:s,touched:i,invalid:V,isDirty:d,isValidating:u,isHidden:m,isRequired:R,fieldMeta:l,setValue:B,setBlur:f,update:a=>B(a?.target?.value??a)}}import{DestroyRef as Q,signal as q,computed as M,inject as _,untracked as X}from"@angular/core";var F=()=>Math.random().toString(36).substring(2,9);function Y(t){let e=_(h),o=_(Q),r=()=>{let s=v(e.getState().values,t);return Array.isArray(s)?s:[]},n=q(r()),c=q(n().map(F)),g=e.subscribe(()=>{let s=r(),i=X(c);n.set(s),s.length!==i.length&&(s.length>i.length?c.set([...i,...Array.from({length:s.length-i.length},F)]):c.set(i.slice(0,s.length)))});return o.onDestroy(()=>{g(),e.unregisterPrefix&&e.unregisterPrefix(`${t}.`)}),{fields:M(()=>n().map((s,i)=>({key:c()[i]||`temp-${i}`,value:s,index:i}))),length:M(()=>n().length),append:s=>{c.update(i=>[...i,F()]),e.pushItem(t,s)},prepend:s=>{c.update(i=>[F(),...i]),e.prependItem(t,s)},remove:s=>{c.update(i=>i.filter((d,u)=>u!==s)),e.removeItem(t,s)},insert:(s,i)=>{c.update(d=>{let u=[...d];return u.splice(s,0,F()),u}),e.insertItem(t,s,i)},swap:(s,i)=>{c.update(d=>{let u=[...d];return[u[s],u[i]]=[u[i],u[s]],u}),e.swapItems(t,s,i)},move:(s,i)=>{c.update(d=>{let u=[...d],[m]=u.splice(s,1);return u.splice(i,0,m),u}),e.moveItem(t,s,i)},replace:s=>{c.set(s.map(()=>F())),e.setField(t,s)},clear:()=>{c.set([]),e.setField(t,[])}}}import{signal as Z,computed as D,DestroyRef as N,inject as tt}from"@angular/core";function et(t,e){let o=Object.keys(t),r=Object.keys(e);return o.length!==r.length?!1:o.every(n=>t[n]===e[n])}function rt(t){let e=S(),o=e.getStepStatus(t),r=Z(o),n=e.subscribe(()=>{let u=e.getStepStatus(t),m=r();(u.hasErrors!==m.hasErrors||u.isDirty!==m.isDirty||!et(u.errors,m.errors))&&r.set(u)});try{tt(N).onDestroy(()=>n())}catch{}let c=async()=>{let u=await e.validate({scope:t}),m=e.getStepErrors(t);return{valid:u,errors:m}},g=()=>e.getStepErrors(t),s=D(()=>!r().hasErrors),i=D(()=>r().isDirty),d=D(()=>r().errors);return{scopeName:t,status:r,errors:d,validate:c,getErrors:g,isValid:s,isDirty:i,unsubscribe:n}}import{signal as H,computed as T,DestroyRef as st,inject as ot}from"@angular/core";function nt(t,e){let o=Object.keys(t),r=Object.keys(e);return o.length!==r.length?!1:o.every(n=>t[n]===e[n])}function it(t){let e=S(),o=H(0),r=T(()=>t[o()]??""),n=()=>t[o()]??"",c=H(e.getStepStatus(n())),g=()=>{let l=n(),a=e.getStepStatus(l),p=c();(a.hasErrors!==p.hasErrors||a.isDirty!==p.isDirty||!nt(a.errors,p.errors))&&c.set(a)},s=e.subscribe(g);try{ot(st).onDestroy(()=>s())}catch{}let i=async()=>{let l=n(),a=await e.validate({scope:l}),p=e.getStepErrors(l);return{valid:a,errors:p}},d=()=>e.getStepErrors(n()),u=async()=>{let l=n(),a=await e.validate({scope:l});if(a){let p=Math.min(o()+1,t.length-1);o.set(p),c.set(e.getStepStatus(t[p]??""))}else{let p=e.getStepErrors(l),j=Object.keys(p);j.length>0&&e.markFieldsTouched(j)}return a},m=()=>{let l=Math.max(o()-1,0);o.set(l),c.set(e.getStepStatus(t[l]??""))},R=l=>{let a=Math.max(0,Math.min(l-1,t.length-1));o.set(a),c.set(e.getStepStatus(t[a]??""))},V=T(()=>o()+1),b=T(()=>o()===0),P=T(()=>o()>=t.length-1),x=T(()=>!c().hasErrors),B=T(()=>c().isDirty),f=T(()=>c().errors);return{step:V,stepIndex:o,scope:r,next:u,prev:m,goTo:R,isFirst:b,isLast:P,status:c,errors:f,isValid:x,isDirty:B,validate:i,getErrors:d}}import{DestroyRef as at,signal as ct,inject as ut}from"@angular/core";function lt(t){let e=S(),o=ut(at),r=ct(v(e.getState().values,t),{equal:w}),n=e.watch(t,c=>{r.set(c)});return o.onDestroy(n),r.asReadonly()}export{Y as injectBitArray,J as injectBitField,$ as injectBitForm,rt as injectBitScope,it as injectBitSteps,lt as injectBitWatch,C as provideBitStore,S as useBitStore};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
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(n,t){this.listeners.forEach(e=>e(n,t))},subscribe(n){return this.listeners.add(n),()=>{this.listeners.delete(n)}}});var m=F.__BIT_FORM__;function g(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=>g(e));let t={};for(let e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=g(n[e]));return t}function S(n,t){return n===t?!0:n===null||typeof n!="object"||t===null||typeof t!="object"?!1:x(n,t)}function x(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)||!x(n[r],t[r]))return!1;return!0}function O(n,t,e="",s=new Set){if(S(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!S(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;O(_optionalChain([n, 'optionalAccess', _2 => _2[i]]),_optionalChain([t, 'optionalAccess', _3 => _3[i]]),o,s)}return s}var k=new Map;function p(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 l=s[o],a=s[o+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(n,t){let e={},s=`${t}.`;for(let r in n)r!==t&&!r.startsWith(s)&&(e[r]=n[r]);return e}var $=(n,t,e)=>{let s={},r=`${t}.`;return Object.keys(n).forEach(i=>{if(!i.startsWith(r)){s[i]=n[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]=n[i]}else s[i]=n[i]}),s},U=(n,t,e,s)=>{let r={},i=`${t}.`;return Object.keys(n).forEach(o=>{if(!o.startsWith(i)){r[o]=n[o];return}let a=o.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]=n[o]}else if(c===s){let f=d?`${i}${e}.${d}`:`${i}${e}`;r[f]=n[o]}else r[o]=n[o]}),r},L=(n,t,e,s)=>{let r={},i=`${t}.`;return Object.keys(n).forEach(o=>{if(!o.startsWith(i)){r[o]=n[o];return}let a=o.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]=n[o]}),r};function gt(n){if(typeof n!="object"||n===null||Array.isArray(n))return!1;let t=_nullishCoalesce(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 Bt(n){return gt(n)?_nullishCoalesce(n.errors, () => (n)):{}}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 =(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},mt= exports.k =(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},u= exports.l =(n,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 o=[...Array.isArray(n)?n:[n]].sort((h,v)=>e(h)-e(v)),l=o[o.length-1];for(let h of o)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(n,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:n="",suffix:t="",thousand:e,decimal:s,precision:r=2,allowNegative:i=!0,saveRaw:o=!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?"-":""}${n}${h}${s}${f}${t}`};return{format:l,parse:a=>{let c=mt(a,r),d=i?c:Math.abs(c);return o?l(d):d}}},N= exports.n =n=>{let t=e=>/^3[47]/.test(e)?"#### ###### #####":/^3(?:0[0-5]|[68])/.test(e)?"#### ###### ####":"#### #### #### ####";return{format:e=>{let s=B(e,_optionalChain([n, 'optionalAccess', _12 => _12.allowChars])),r=t(s);return u(r,n).format(e)},parse:e=>{let s=B(e,_optionalChain([n, 'optionalAccess', _13 => _13.allowChars])),r=t(s);return u(r,n).parse(e)}}},P= exports.o =n=>{let e=(_optionalChain([n, 'optionalAccess', _14 => _14.format])||"DD/MM/YYYY")==="YYYY-MM-DD",s=u(e?"####-##-##":"##/##/####",n);return{format:r=>{let i=B(r);if(!i)return"";let o="",l="",a="";if(e?(a=i.substring(0,4),l=i.substring(4,6),o=i.substring(6,8)):(o=i.substring(0,2),l=i.substring(2,4),a=i.substring(4,8)),o.length===2){let d=parseInt(o,10);d>31&&(o="31"),d===0&&(o="01")}if(l.length===2){let d=parseInt(l,10);d>12&&(l="12"),d===0&&(l="01")}let c=e?`${a}${l}${o}`:`${o}${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: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,"")}}),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("###-##-####"),nt= exports.K =N(),ot= 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:nt,cvv:ot,percent:z,decimal:Y,int:J};function Rt(n){let t={},e={},s={};if(!n)return{computed:t,transform:e,scopes:s};for(let[r,i]of Object.entries(n))_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(n={}){let t=n.initialValues||{},e=n.validation,s=n.history,{computed:r,transform:i,scopes:o}=Rt(n.fields);return{name:n.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:o,masks:ut,fields:n.fields,devTools:n.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 o=p(t,i);this.isEmpty(o)&&(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 o=this.isHidden(i);this.evaluateFieldCondition(i,e);let l=this.isHidden(i);o!==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),o=y(s.values,t,i),l=this.store.updateDirtyForPath(t,o,this.store.getConfig().initialValues);this.store.internalUpdateState({values:o,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 o=y(r.values,t,i),l=this.store.updateDirtyForPath(t,o,this.store.getConfig().initialValues);this.store.internalUpdateState({values:o,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)||[]],[o]=i.splice(e,1);i.splice(s,0,o);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[o,l]of s){let a=l(e),c=p(e,o);x(c,a)||(e=y(e,o,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 o=(this.asyncRequests[t]||0)+1;this.asyncRequests[t]=o,this.store.internalUpdateState({isValidating:{...this.store.getState().isValidating,[t]:!0}});try{let l=await r(e,this.store.getState().values);if(this.asyncRequests[t]!==o)return;if(l)this.asyncErrors[t]=l,this.store.setError(t,l);else{delete this.asyncErrors[t];let a={...this.store.getState().errors};delete a[t],this.store.internalUpdateState({errors:a,isValid:Object.keys(a).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=_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}):{},o=this.store.depsMg.getRequiredErrors(s.values,this.store.config.defaultRequiredMessage);if(i={...i,...o},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 o=this.store.depsMg.updateDependencies(t,r);o.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:o.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 o=this.store.config.transform[i];if(o){let l=p(r,i);r=y(r,i,o(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(o=>{i[o]=!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`
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
2
  .bit-devtools-container {
3
3
  position: fixed;
4
4
  bottom: 20px;
@@ -86,13 +86,13 @@
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 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 o=i.getAttribute("data-action"),l=i.getAttribute("data-store");o&&l&&(o==="undo"&&this.actions.onUndo(l),o==="redo"&&this.actions.onRedo(l),o==="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=`
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
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,l=i._meta||{totalSteps:0,currentIndex:-1,canUndo:!1,canRedo:!1},a=l.currentIndex+1,c=l.totalSteps;e+=`
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
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 @@
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 @@
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}}, _class4);function vt(n){let t=new M(n,{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,o]of Object.entries(m.stores)){let l=o,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(),n.innerHTML=""}}}function xt(n,t="ws://localhost:3000"){let e=new WebSocket(t),s=new M(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 ft(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=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}constructor(t={}){;_class6.prototype.__init13.call(this);_class6.prototype.__init14.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.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){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(o=>!!this.state.errors[o]),r=e.some(o=>{let l=p(this.state.values,o),a=p(this.config.initialValues,o);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 o of this.dirtyPaths)o.startsWith(t+".")&&this.dirtyPaths.delete(o);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=n=>({...typeof n.getState=="function"?n.getState():n,_meta:{canUndo:n.canUndo,canRedo:n.canRedo,totalSteps:_optionalChain([n, 'access', _72 => _72.historyMg, 'optionalAccess', _73 => _73.history, 'optionalAccess', _74 => _74.length])||0,currentIndex:_nullishCoalesce(_optionalChain([n, 'access', _75 => _75.historyMg, 'optionalAccess', _76 => _76.historyIndex]), () => (-1))}}),A=null;function Tt(n){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(n),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 o=()=>{r=!0,e&&e(),clearInterval(s),t&&(t.readyState===WebSocket.OPEN||t.readyState===WebSocket.CONNECTING)&&t.close(),A=null};return A=o,o}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 = nt; exports.L = ot; 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-ACHDD75T.cjs.map
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
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/store/bus.ts","../src/core/utils.ts","../src/devtools/ui/styles.ts","../src/devtools/ui/index.ts","../src/devtools/init-dev-tools.ts"],"names":["rootGlobal","id","state","fn","bitBus","deepClone","obj","item","clone","key","valueEqual","a","b","deepEqual","keysA","keysB","collectDirtyPaths","initial","prefix","result","allKeys","k","p"],"mappings":"AAaA,kwBAAMA,CAAAA,CACJ,OAAO,UAAA,CAAe,GAAA,CAClB,UAAA,CACE,OAAO,MAAA,CAAW,GAAA,CAAc,MAAA,CAAS,MAAA,CAE5CA,CAAAA,CAAW,YAAA,EAAA,CACdA,CAAAA,CAAW,YAAA,CAAe,CACxB,MAAA,CAAQ,CAAC,CAAA,CACT,SAAA,CAAW,IAAI,GAAA,CAEf,QAAA,CAASC,CAAAA,CAAYC,CAAAA,CAAY,CAC/B,IAAA,CAAK,SAAA,CAAU,OAAA,CAASC,CAAAA,EAAuBA,CAAAA,CAAGF,CAAAA,CAAIC,CAAK,CAAC,CAC9D,CAAA,CAEA,SAAA,CAAUC,CAAAA,CAAoB,CAC5B,OAAA,IAAA,CAAK,SAAA,CAAU,GAAA,CAAIA,CAAE,CAAA,CACd,CAAA,CAAA,EAAM,CACX,IAAA,CAAK,SAAA,CAAU,MAAA,CAAOA,CAAE,CAC1B,CACF,CACF,CAAA,CAAA,CAGK,IAAMC,CAAAA,CAASJ,CAAAA,CAAW,YAAA,CCpC1B,SAASK,CAAAA,CAAaC,CAAAA,CAAW,CACtC,EAAA,CAAIA,CAAAA,GAAQ,IAAA,EAAQ,OAAOA,CAAAA,EAAQ,QAAA,CACjC,OAAOA,CAAAA,CAGT,EAAA,CAAIA,EAAAA,WAAe,IAAA,CACjB,OAAO,IAAI,IAAA,CAAKA,CAAAA,CAAI,OAAA,CAAQ,CAAC,CAAA,CAE/B,EAAA,CAAIA,EAAAA,WAAe,MAAA,CACjB,OAAO,IAAI,MAAA,CAAOA,CAAAA,CAAI,MAAA,CAAQA,CAAAA,CAAI,KAAK,CAAA,CAGzC,EAAA,CAAI,KAAA,CAAM,O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: any) => void;\n\ninterface BitFormGlobal {\n stores: Record<string, any>;\n listeners: Set<BitBusListener>;\n dispatch: (storeId: string, state: any) => void;\n subscribe: (fn: BitBusListener) => () => void;\n}\n\ndeclare global {\n var __BIT_FORM__: BitFormGlobal | undefined;\n}\n\nconst rootGlobal =\n typeof globalThis !== \"undefined\"\n ? globalThis\n : ((typeof global !== \"undefined\" ? global : window) as any);\n\nif (!rootGlobal.__BIT_FORM__) {\n rootGlobal.__BIT_FORM__ = {\n stores: {},\n listeners: new Set<BitBusListener>(),\n\n dispatch(id: string, state: any) {\n this.listeners.forEach((fn: BitBusListener) => fn(id, state));\n },\n\n subscribe(fn: BitBusListener) {\n this.listeners.add(fn);\n return () => {\n this.listeners.delete(fn);\n };\n },\n };\n}\n\nexport const bitBus = rootGlobal.__BIT_FORM__ as BitFormGlobal;\n","export function deepClone<T>(obj: T): T {\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as any as T;\n }\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as any as T;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => deepClone(item)) as any as T;\n }\n\n const clone: any = {};\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n clone[key] = deepClone((obj as any)[key]);\n }\n }\n return clone as T;\n}\n\n/**\n * Fast equality for single values. Uses === for primitives, deepEqual for objects/arrays.\n * Prefer over deepEqual when comparing a single field value (e.g. isFieldDirty, getStepStatus).\n */\nexport function valueEqual(a: any, b: any): boolean {\n if (a === b) return true;\n if (\n a === null ||\n typeof a !== \"object\" ||\n b === null ||\n typeof b !== \"object\"\n ) {\n return false;\n }\n return deepEqual(a, b);\n}\n\nexport function deepEqual(a: any, b: any): boolean {\n if (a === b) return true;\n if (\n a === null ||\n typeof a !== \"object\" ||\n b === null ||\n typeof b !== \"object\"\n ) {\n return false;\n }\n\n if (a instanceof Date && b instanceof Date)\n return a.getTime() === b.getTime();\n if (a instanceof RegExp && b instanceof RegExp)\n return a.toString() === b.toString();\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (\n !Object.prototype.hasOwnProperty.call(b, key) ||\n !deepEqual(a[key], b[key])\n ) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Collects all paths where obj differs from initial. Used to rebuild dirtyPaths after full state replacement.\n */\nexport function collectDirtyPaths(\n obj: any,\n initial: any,\n prefix = \"\",\n result: Set<string> = new Set(),\n): Set<string> {\n if (valueEqual(obj, initial)) return result;\n if (\n obj === null ||\n typeof obj !== \"object\" ||\n initial === null ||\n typeof initial !== \"object\"\n ) {\n if (prefix) result.add(prefix);\n return result;\n }\n if (Array.isArray(obj) || Array.isArray(initial)) {\n if (!valueEqual(obj, initial) && prefix) result.add(prefix);\n return result;\n }\n const allKeys = new Set([\n ...Object.keys(obj || {}),\n ...Object.keys(initial || {}),\n ]);\n for (const k of allKeys) {\n const p = prefix ? `${prefix}.${k}` : k;\n collectDirtyPaths((obj as any)?.[k], (initial as any)?.[k], p, result);\n }\n return result;\n}\n\nconst pathCache = new Map<string, string[]>();\n\nexport function getDeepValue(obj: any, path: string): any {\n if (!path) return obj;\n\n const keys = pathCache.get(path) || path.split(\".\");\n if (!pathCache.has(path)) pathCache.set(path, keys);\n\n let current = obj;\n for (const key of keys) {\n if (current === null || current === undefined) return undefined;\n current = current[key];\n }\n return current;\n}\n\nexport function setDeepValue(obj: any, path: string, value: any): any {\n if (!path) return value;\n\n const keys = pathCache.get(path) || path.split(\".\");\n if (!pathCache.has(path)) pathCache.set(path, keys);\n\n const result = Array.isArray(obj) ? [...obj] : { ...obj };\n let current = result;\n\n for (let i = 0; i < keys.length - 1; i++) {\n const key = keys[i];\n const nextKey = keys[i + 1];\n\n const isNextNumeric = /^\\d+$/.test(nextKey);\n const currentValue = current[key];\n\n if (currentValue === null || currentValue === undefined) {\n current[key] = isNextNumeric ? [] : {};\n } else {\n current[key] = Array.isArray(currentValue)\n ? [...currentValue]\n : { ...currentValue };\n }\n\n current = current[key];\n }\n\n current[keys[keys.length - 1]] = value;\n\n return result;\n}\n\nexport function cleanPrefixedKeys(\n obj: Record<string, any>,\n prefix: string,\n): Record<string, any> {\n const newObj: Record<string, any> = {};\n const prefixWithDot = `${prefix}.`;\n\n for (const key in obj) {\n if (key !== prefix && !key.startsWith(prefixWithDot)) {\n newObj[key] = obj[key];\n }\n }\n return newObj;\n}\n\nexport const shiftKeys = (\n obj: Record<string, any>,\n path: string,\n removedIndex: number,\n) => {\n const newObj: Record<string, any> = {};\n const prefix = `${path}.`;\n\n Object.keys(obj).forEach((key) => {\n if (!key.startsWith(prefix)) {\n newObj[key] = obj[key];\n return;\n }\n const remaining = key.substring(prefix.length);\n const parts = remaining.split(\".\");\n const currentIdx = parseInt(parts[0], 10);\n const rest = parts.slice(1).join(\".\");\n\n if (currentIdx === removedIndex) return;\n\n if (currentIdx > removedIndex) {\n const newIdx = currentIdx - 1;\n const newKey = rest ? `${prefix}${newIdx}.${rest}` : `${prefix}${newIdx}`;\n newObj[newKey] = obj[key];\n } else {\n newObj[key] = obj[key];\n }\n });\n return newObj;\n};\n\nexport const swapKeys = (\n obj: Record<string, any>,\n path: string,\n indexA: number,\n indexB: number,\n) => {\n const newObj: Record<string, any> = {};\n const prefix = `${path}.`;\n\n Object.keys(obj).forEach((key) => {\n if (!key.startsWith(prefix)) {\n newObj[key] = obj[key];\n return;\n }\n const remaining = key.substring(prefix.length);\n const parts = remaining.split(\".\");\n const currentIdx = parseInt(parts[0], 10);\n const rest = parts.slice(1).join(\".\");\n\n if (currentIdx === indexA) {\n const newKey = rest ? `${prefix}${indexB}.${rest}` : `${prefix}${indexB}`;\n newObj[newKey] = obj[key];\n } else if (currentIdx === indexB) {\n const newKey = rest ? `${prefix}${indexA}.${rest}` : `${prefix}${indexA}`;\n newObj[newKey] = obj[key];\n } else {\n newObj[key] = obj[key];\n }\n });\n return newObj;\n};\n\nexport const moveKeys = (\n obj: Record<string, any>,\n path: string,\n from: number,\n to: number,\n) => {\n const newObj: Record<string, any> = {};\n const prefix = `${path}.`;\n\n Object.keys(obj).forEach((key) => {\n if (!key.startsWith(prefix)) {\n newObj[key] = obj[key];\n return;\n }\n const remaining = key.substring(prefix.length);\n const parts = remaining.split(\".\");\n const currentIdx = parseInt(parts[0], 10);\n const rest = parts.slice(1).join(\".\");\n\n let newIdx = currentIdx;\n if (currentIdx === from) {\n newIdx = to;\n } else if (from < to && currentIdx > from && currentIdx <= to) {\n newIdx = currentIdx - 1;\n } else if (from > to && currentIdx >= to && currentIdx < from) {\n newIdx = currentIdx + 1;\n }\n\n const newKey = rest ? `${prefix}${newIdx}.${rest}` : `${prefix}${newIdx}`;\n newObj[newKey] = obj[key];\n });\n return newObj;\n};\n\n/**\n * Checks if a value looks like a server validation error response.\n * Handles shapes like { email: \"Taken\" }, { errors: { email: [\"Taken\"] } }, etc.\n */\nexport function isValidationErrorShape(\n x: unknown,\n): x is Record<string, string | string[]> {\n if (typeof x !== \"object\" || x === null || Array.isArray(x)) return false;\n\n const obj = (x as Record<string, unknown>).errors ?? x;\n if (typeof obj !== \"object\" || obj === null || Array.isArray(obj)) return false;\n\n return Object.values(obj as Record<string, unknown>).every(\n (v) =>\n typeof v === \"string\" ||\n (Array.isArray(v) && v.every((i) => typeof i === \"string\")),\n );\n}\n\n/**\n * Extracts server errors in the format expected by setServerErrors.\n */\nexport function extractServerErrors(\n x: unknown,\n): Record<string, string | string[]> {\n if (!isValidationErrorShape(x)) return {};\n\n const obj = (x as Record<string, unknown>).errors ?? x;\n return obj as Record<string, string | string[]>;\n}\n","export function getDevToolsCSS(): string {\n return `\n .bit-devtools-container {\n position: fixed;\n bottom: 20px;\n right: 20px;\n z-index: 9999;\n font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n display: flex;\n flex-direction: column;\n align-items: flex-end;\n }\n\n .bit-devtools-trigger {\n background: #10b981;\n color: #fff;\n border: none;\n border-radius: 50%;\n width: 48px;\n height: 48px;\n cursor: pointer;\n box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);\n font-weight: bold;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: transform 0.2s;\n font-size: 16px;\n margin-top: 16px;\n }\n .bit-devtools-trigger:hover { transform: scale(1.05); }\n\n .bit-devtools-panel {\n width: 450px;\n max-height: 80vh;\n background: #0f172a;\n color: #f8fafc;\n border-radius: 8px;\n padding: 16px;\n overflow-y: auto;\n box-shadow: 0 20px 25px -5px rgba(0,0,0,0.5), 0 8px 10px -6px rgba(0,0,0,0.5);\n border: 1px solid #334155;\n display: flex;\n flex-direction: column;\n gap: 16px;\n }\n\n .bit-devtools-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n padding-bottom: 12px;\n border-bottom: 1px solid #1e293b;\n }\n .bit-devtools-header h2 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }\n\n .bit-store-block {\n background: #1e293b;\n border-radius: 6px;\n padding: 12px;\n border: 1px solid #334155;\n }\n\n .bit-store-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 12px;\n }\n .bit-store-title { margin: 0; color: #38bdf8; font-size: 14px; font-weight: bold; }\n\n .bit-badge-group { display: flex; gap: 6px; flex-wrap: wrap; }\n .bit-badge { font-size: 10px; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; font-weight: bold; }\n .badge-success { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.2); }\n .badge-error { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.2); }\n .badge-warn { background: rgba(245, 158, 11, 0.2); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.2); }\n .badge-info { background: rgba(56, 189, 248, 0.2); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.2); }\n\n .bit-section-title { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; margin: 12px 0 4px 0; display: block; }\n\n .bit-controls { display: flex; gap: 6px; margin-bottom: 12px; background: #0f172a; padding: 8px; border-radius: 6px; }\n .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; }\n .bit-action-btn:hover:not(:disabled) { background: #475569; }\n .bit-action-btn:disabled { opacity: 0.5; cursor: not-allowed; }\n .bit-btn-reset { color: #fca5a5; border-color: rgba(239,68,68,0.3); }\n .bit-btn-reset:hover { background: rgba(239,68,68,0.1) !important; }\n\n pre.bit-pre { background: #020617; padding: 10px; border-radius: 4px; font-size: 11px; overflow-x: auto; border: 1px solid #1e293b; margin: 0; color: #e2e8f0; }\n 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; }\n `;\n}\n","import { getDevToolsCSS } from \"./styles\";\nimport type { DevToolsActions } from \"../types\";\n\nexport type { DevToolsActions };\n\nexport class BitFormDevToolsUI {\n private container: HTMLElement;\n private actions: DevToolsActions;\n private rootElement: HTMLDivElement;\n private currentStoresState: Record<string, any> = {};\n private isOpen: boolean = false;\n\n constructor(container: HTMLElement, actions: DevToolsActions) {\n this.container = container;\n this.actions = actions;\n\n if (!document.getElementById(\"bit-devtools-styles\")) {\n const style = document.createElement(\"style\");\n style.id = \"bit-devtools-styles\";\n style.textContent = getDevToolsCSS();\n document.head.appendChild(style);\n }\n\n this.rootElement = document.createElement(\"div\");\n this.rootElement.className = \"bit-devtools-container\";\n this.container.appendChild(this.rootElement);\n\n this.rootElement.addEventListener(\"click\", (e) => {\n const target = e.target as HTMLElement;\n\n // Evento do botão flutuante\n if (target.closest(\".bit-devtools-trigger\")) {\n this.isOpen = !this.isOpen;\n this.render();\n return;\n }\n\n // Eventos dos botões de ação\n const btn = target.closest(\".bit-action-btn\");\n if (btn && !btn.hasAttribute(\"disabled\")) {\n const action = btn.getAttribute(\"data-action\");\n const storeId = btn.getAttribute(\"data-store\");\n\n if (action && storeId) {\n if (action === \"undo\") this.actions.onUndo(storeId);\n if (action === \"redo\") this.actions.onRedo(storeId);\n if (action === \"reset\") this.actions.onReset(storeId);\n }\n }\n });\n }\n\n public updateState(storesState: Record<string, any>) {\n this.currentStoresState = storesState;\n this.render();\n }\n\n private render() {\n const storeEntries = Object.entries(this.currentStoresState);\n if (storeEntries.length === 0) {\n this.rootElement.innerHTML = \"\";\n return;\n }\n\n let panelHtml = \"\";\n\n if (this.isOpen) {\n panelHtml = `\n <div class=\"bit-devtools-panel\">\n <div class=\"bit-devtools-header\">\n <h2><span style=\"font-size: 20px;\">🛠</span> Bit-Form DevTools</h2>\n <span style=\"font-size: 11px; color: #64748b;\">v1.0.0</span>\n </div>\n `;\n\n for (const [id, state] of storeEntries) {\n const hasErrors = Object.keys(state.errors || {}).length > 0;\n\n // Lemos os metadados do histórico que o adaptador injetou\n const meta = state._meta || {\n totalSteps: 0,\n currentIndex: -1,\n canUndo: false,\n canRedo: false,\n };\n const currentStep = meta.currentIndex + 1;\n const totalSteps = meta.totalSteps;\n\n panelHtml += `\n <div class=\"bit-store-block\">\n <div class=\"bit-store-header\">\n <h3 class=\"bit-store-title\">${id}</h3>\n <div class=\"bit-badge-group\">\n <span class=\"bit-badge ${state.isValid ? \"badge-success\" : \"badge-error\"}\">\n ${state.isValid ? \"✓ Valid\" : \"✕ Invalid\"}\n </span>\n ${state.isDirty ? `<span class=\"bit-badge badge-warn\">Dirty</span>` : \"\"}\n ${state.isSubmitting ? `<span class=\"bit-badge badge-info\">⏳ Submitting</span>` : \"\"}\n </div>\n </div>\n\n <span class=\"bit-section-title\">Time Travel (${currentStep}/${totalSteps})</span>\n \n <div class=\"bit-controls\">\n <button class=\"bit-action-btn\" data-action=\"undo\" data-store=\"${id}\" ${meta.canUndo ? \"\" : \"disabled\"}>\n <span>↺</span> Undo\n </button>\n <button class=\"bit-action-btn\" data-action=\"redo\" data-store=\"${id}\" ${meta.canRedo ? \"\" : \"disabled\"}>\n <span>↻</span> Redo\n </button>\n <button class=\"bit-action-btn bit-btn-reset\" data-action=\"reset\" data-store=\"${id}\">\n <span>🗑</span> Reset\n </button>\n </div>\n `;\n\n if (hasErrors) {\n panelHtml += `\n <span class=\"bit-section-title\" style=\"color: #f87171;\">⚠️ Validations Failing</span>\n <pre class=\"bit-error-box\">${JSON.stringify(state.errors, null, 2)}</pre>\n `;\n }\n\n panelHtml += `\n <span class=\"bit-section-title\">Values</span>\n <pre class=\"bit-pre\">${JSON.stringify(state.values, null, 2)}</pre>\n </div>\n `;\n }\n\n panelHtml += `</div>`;\n }\n\n // Botão Flutuante (sempre renderizado)\n const triggerHtml = `\n <button class=\"bit-devtools-trigger\" style=\"transform: ${this.isOpen ? \"scale(0.9)\" : \"scale(1)\"};\" title=\"Abrir DevTools\">\n ${this.isOpen ? \"✖\" : \"Bit\"}\n </button>\n `;\n\n this.rootElement.innerHTML = panelHtml + triggerHtml;\n }\n}\n","import { setupLocalDevTools } from \"./adapters/local\";\nimport { setupRemoteDevTools } from \"./adapters/remote\";\nimport type { BitDevToolsOptions } from \"./types\";\n\nexport type { BitDevToolsOptions };\n\nexport function initDevTools(options: BitDevToolsOptions = {}) {\n const { mode = \"local\", url } = options;\n let containerEl: HTMLElement;\n\n let isAutoCreated = false;\n\n if (typeof options.container === \"string\") {\n const el = document.querySelector<HTMLElement>(options.container);\n if (!el)\n throw new Error(\n `[bit-form] Container '${options.container}' não encontrado na página.`,\n );\n containerEl = el;\n } else if (options.container instanceof HTMLElement) {\n containerEl = options.container;\n } else {\n containerEl = document.createElement(\"div\");\n containerEl.id = \"bit-form-devtools-root\";\n containerEl.style.position = \"fixed\";\n containerEl.style.bottom = \"20px\";\n containerEl.style.right = \"20px\";\n containerEl.style.zIndex = \"9999\";\n containerEl.style.maxHeight = \"80vh\";\n containerEl.style.overflowY = \"auto\";\n containerEl.style.boxShadow = \"0 10px 25px rgba(0,0,0,0.1)\";\n document.body.appendChild(containerEl);\n isAutoCreated = true;\n }\n\n let adapterInstance: any;\n\n if (mode === \"local\") {\n console.log(\"[bit-form] DevTools iniciado em modo Local.\");\n adapterInstance = setupLocalDevTools(containerEl);\n } else if (mode === \"remote\") {\n console.log(\"[bit-form] DevTools iniciado em modo Remote.\");\n adapterInstance = setupRemoteDevTools(containerEl, url);\n } else {\n throw new Error(`[bit-form] Modo DevTools inválido: ${mode}`);\n }\n\n return {\n ...adapterInstance,\n destroy: () => {\n if (adapterInstance && typeof adapterInstance.destroy === \"function\") {\n adapterInstance.destroy();\n }\n\n if (isAutoCreated && containerEl.parentNode) {\n containerEl.parentNode.removeChild(containerEl);\n } else {\n containerEl.innerHTML = \"\";\n }\n },\n };\n}\n"]}