@lehnihon/bit-form 2.2.9 → 2.2.11

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 (139) hide show
  1. package/README.md +17 -0
  2. package/dist/angular/index.cjs +1 -1
  3. package/dist/angular/index.d.cts +19 -52
  4. package/dist/angular/index.d.ts +19 -52
  5. package/dist/angular/index.js +1 -1
  6. package/dist/angular/index.js.map +1 -1
  7. package/dist/bus-BFOBGmd9.d.ts +41 -0
  8. package/dist/bus-DzTqgkZ4.d.cts +41 -0
  9. package/dist/chunk-23IYGRVG.js +2 -0
  10. package/dist/chunk-23IYGRVG.js.map +1 -0
  11. package/dist/chunk-ACEJG5FJ.cjs +2 -0
  12. package/dist/chunk-ACEJG5FJ.cjs.map +1 -0
  13. package/dist/chunk-DRLFDQ5Z.js +2 -0
  14. package/dist/chunk-DRLFDQ5Z.js.map +1 -0
  15. package/dist/{chunk-N4HCGMMM.js → chunk-HDZV334O.js} +2 -2
  16. package/dist/{chunk-GGZPA7AO.cjs → chunk-IQVY4MNY.cjs} +2 -2
  17. package/dist/{chunk-GGZPA7AO.cjs.map → chunk-IQVY4MNY.cjs.map} +1 -1
  18. package/dist/chunk-KYX4G4YS.cjs +2 -0
  19. package/dist/chunk-KYX4G4YS.cjs.map +1 -0
  20. package/dist/chunk-NYKX3QED.js +2 -0
  21. package/dist/chunk-NYKX3QED.js.map +1 -0
  22. package/dist/chunk-PA43XYOW.cjs +2 -0
  23. package/dist/{chunk-IV32WXCF.cjs.map → chunk-PA43XYOW.cjs.map} +1 -1
  24. package/dist/chunk-PG7ZH32Z.js +2 -0
  25. package/dist/chunk-PG7ZH32Z.js.map +1 -0
  26. package/dist/{chunk-2QLQPMCZ.js → chunk-RMD37PXW.js} +2 -2
  27. package/dist/{chunk-OLQVH24Z.cjs → chunk-UFJJOXVB.cjs} +2 -2
  28. package/dist/{chunk-OLQVH24Z.cjs.map → chunk-UFJJOXVB.cjs.map} +1 -1
  29. package/dist/chunk-VAP2C5QV.cjs +2 -0
  30. package/dist/{chunk-J5ALITQW.cjs.map → chunk-VAP2C5QV.cjs.map} +1 -1
  31. package/dist/chunk-W56UISAF.cjs +2 -0
  32. package/dist/chunk-W56UISAF.cjs.map +1 -0
  33. package/dist/chunk-YWBRZGEI.js +2 -0
  34. package/dist/chunk-YWBRZGEI.js.map +1 -0
  35. package/dist/cli/index.cjs +5 -5
  36. package/dist/{types-SOg9xEce.d.cts → config-types-5eR82k2V.d.cts} +40 -169
  37. package/dist/{types-CRCP4Pgq.d.ts → config-types-D9n-rQLk.d.ts} +40 -169
  38. package/dist/core/bindings.cjs +1 -1
  39. package/dist/core/bindings.d.cts +15 -11
  40. package/dist/core/bindings.d.ts +15 -11
  41. package/dist/core/bindings.js +1 -1
  42. package/dist/core/status.d.cts +3 -4
  43. package/dist/core/status.d.ts +3 -4
  44. package/dist/core/store.cjs +1 -1
  45. package/dist/core/store.d.cts +8 -6
  46. package/dist/core/store.d.ts +8 -6
  47. package/dist/core/store.js +1 -1
  48. package/dist/core/utils.cjs +1 -1
  49. package/dist/core/utils.d.cts +2 -3
  50. package/dist/core/utils.d.ts +2 -3
  51. package/dist/core/utils.js +1 -1
  52. package/dist/core.cjs +1 -1
  53. package/dist/core.d.cts +10 -9
  54. package/dist/core.d.ts +10 -9
  55. package/dist/core.js +1 -1
  56. package/dist/devtools/bridge.cjs +1 -1
  57. package/dist/devtools/bridge.d.cts +2 -3
  58. package/dist/devtools/bridge.d.ts +2 -3
  59. package/dist/devtools/bridge.js +1 -1
  60. package/dist/devtools/index.cjs +2 -2
  61. package/dist/devtools/index.d.cts +5 -3
  62. package/dist/devtools/index.d.ts +5 -3
  63. package/dist/devtools/index.js +1 -1
  64. package/dist/{field-binding-MX6jVQbT.d.ts → field-binding-Bi1g-D8X.d.ts} +1 -1
  65. package/dist/{field-binding-B_OX3bjp.d.cts → field-binding-X5TkvfUt.d.cts} +1 -1
  66. package/dist/index.cjs +1 -1
  67. package/dist/index.d.cts +7 -5
  68. package/dist/index.d.ts +7 -5
  69. package/dist/index.js +1 -1
  70. package/dist/mask.d.cts +2 -2
  71. package/dist/mask.d.ts +2 -2
  72. package/dist/meta-types-BC1VLABk.d.cts +28 -0
  73. package/dist/meta-types-BC1VLABk.d.ts +28 -0
  74. package/dist/react/index.cjs +1 -1
  75. package/dist/react/index.cjs.map +1 -1
  76. package/dist/react/index.d.cts +12 -12
  77. package/dist/react/index.d.ts +12 -12
  78. package/dist/react/index.js +1 -1
  79. package/dist/react/index.js.map +1 -1
  80. package/dist/react-native/index.cjs +1 -1
  81. package/dist/react-native/index.d.cts +10 -9
  82. package/dist/react-native/index.d.ts +10 -9
  83. package/dist/react-native/index.js +1 -1
  84. package/dist/resolvers/index.d.cts +2 -3
  85. package/dist/resolvers/index.d.ts +2 -3
  86. package/dist/resolvers/joi.d.cts +2 -3
  87. package/dist/resolvers/joi.d.ts +2 -3
  88. package/dist/resolvers/yup.d.cts +2 -3
  89. package/dist/resolvers/yup.d.ts +2 -3
  90. package/dist/resolvers/zod.d.cts +2 -3
  91. package/dist/resolvers/zod.d.ts +2 -3
  92. package/dist/runtime-types-D1SRZr-n.d.cts +43 -0
  93. package/dist/runtime-types-D1SRZr-n.d.ts +43 -0
  94. package/dist/state-types-8bUndWfg.d.cts +42 -0
  95. package/dist/state-types-8bUndWfg.d.ts +42 -0
  96. package/dist/{store-api-types-Bm3EAqR_.d.cts → store-api-types-Bozwlwyb.d.ts} +9 -5
  97. package/dist/{store-api-types-DfTFy2h4.d.ts → store-api-types-DSgYwMS3.d.cts} +9 -5
  98. package/dist/{types-D8DgIUhJ.d.cts → types-CUXh7PqD.d.cts} +1 -1
  99. package/dist/{types-D8DgIUhJ.d.ts → types-CUXh7PqD.d.ts} +1 -1
  100. package/dist/upload-C4JqIaU2.d.cts +89 -0
  101. package/dist/upload-ao6skK9K.d.ts +89 -0
  102. package/dist/{use-bit-persist-BDMZmxBh.d.ts → use-bit-persist-Bd1H2fge.d.ts} +12 -45
  103. package/dist/{use-bit-persist-CBTZIMc5.d.cts → use-bit-persist-DDxV21AN.d.cts} +12 -45
  104. package/dist/utils.cjs +1 -1
  105. package/dist/utils.js +1 -1
  106. package/dist/vue/index.cjs +1 -1
  107. package/dist/vue/index.d.cts +18 -51
  108. package/dist/vue/index.d.ts +18 -51
  109. package/dist/vue/index.js +1 -1
  110. package/dist/vue/index.js.map +1 -1
  111. package/package.json +2 -2
  112. package/dist/array-controller-C61ByyG6.d.ts +0 -23
  113. package/dist/array-controller-CtlqjA0e.d.cts +0 -23
  114. package/dist/bus-BKuMV3E7.d.ts +0 -19
  115. package/dist/bus-WOHGxuVy.d.cts +0 -19
  116. package/dist/chunk-6LNXTSZ6.cjs +0 -2
  117. package/dist/chunk-6LNXTSZ6.cjs.map +0 -1
  118. package/dist/chunk-IV32WXCF.cjs +0 -2
  119. package/dist/chunk-J5ALITQW.cjs +0 -2
  120. package/dist/chunk-J5GQLEVA.js +0 -2
  121. package/dist/chunk-J5GQLEVA.js.map +0 -1
  122. package/dist/chunk-KDHPLXZF.cjs +0 -2
  123. package/dist/chunk-KDHPLXZF.cjs.map +0 -1
  124. package/dist/chunk-O5UPA33R.js +0 -2
  125. package/dist/chunk-O5UPA33R.js.map +0 -1
  126. package/dist/chunk-QX2IVNMK.js +0 -2
  127. package/dist/chunk-QX2IVNMK.js.map +0 -1
  128. package/dist/chunk-UARLAXZX.js +0 -2
  129. package/dist/chunk-UARLAXZX.js.map +0 -1
  130. package/dist/chunk-X5UCRGYJ.cjs +0 -2
  131. package/dist/chunk-X5UCRGYJ.cjs.map +0 -1
  132. package/dist/chunk-Y3XVQGCU.js +0 -2
  133. package/dist/chunk-Y3XVQGCU.js.map +0 -1
  134. package/dist/meta-types-Bzmm21TP.d.cts +0 -18
  135. package/dist/meta-types-Bzmm21TP.d.ts +0 -18
  136. package/dist/upload-C2mpfhp1.d.cts +0 -17
  137. package/dist/upload-C2mpfhp1.d.ts +0 -17
  138. /package/dist/{chunk-N4HCGMMM.js.map → chunk-HDZV334O.js.map} +0 -0
  139. /package/dist/{chunk-2QLQPMCZ.js.map → chunk-RMD37PXW.js.map} +0 -0
@@ -1,2 +0,0 @@
1
- import{b as St,c as At,d as C,e as Mt,h as k}from"./chunk-UIKO6GGW.js";import{c as Rt}from"./chunk-2QLQPMCZ.js";import{a as y,b as Ct,c as F,d as M,e as Vt,f as m,g as R,h as T,i as wt,k as Dt}from"./chunk-QX2IVNMK.js";function kt(r){let{path:t,getFieldConfig:e,masks:i}=r,s=e(t)?.mask;if(s)return typeof s=="string"?i?.[s]:s}function It(r){let{state:t,path:e,value:i,isHidden:s,isRequired:a,isDirty:n,isValidating:o}=r,d=e;return{value:i,error:t.errors[d],touched:!!t.touched[d],isHidden:s,isRequired:a,isDirty:n,isValidating:o}}var D=Symbol.for("bit-form.framework-store-api");var A=Symbol.for("bit-form.hooks-api");var I=class{constructor(t){this.baselineValues=y(t)}baselineValues;baselineSnapshot;getValues(){return this.baselineSnapshot||(this.baselineSnapshot=Object.freeze(y(this.baselineValues))),this.baselineSnapshot}setValues(t){this.baselineValues=y(t),this.baselineSnapshot=void 0}};var O=class{constructor(t){this.getComputedEntries=t}equalityCache=new Map;reverseDepsCache=null;childDepsIndex=null;validatedEntriesSignature=null;validatedEntriesRef=null;orderedAllEntriesCache=null;orderedIndexByPathCache=null;isCacheableScalar(t){return t===null||typeof t!="object"&&typeof t!="function"}invalidateReverseDeps(){this.reverseDepsCache=null,this.childDepsIndex=null,this.orderedAllEntriesCache=null,this.validatedEntriesSignature=null,this.validatedEntriesRef=null,this.orderedIndexByPathCache=null,this.equalityCache.clear()}apply(t,e){let i=this.getComputedEntries();if(i.length===0)return t;this.ensureEntriesAreValid(i);let s=this.resolveEntriesToRun(i,e);if(s.length===0)return t;let a=t;for(let n of s){let o=n.compute(a),d=m(a,n.path),p=this.equalityCache.get(n.path),l,c=this.isCacheableScalar(d)&&this.isCacheableScalar(o);c&&p&&p.current===d&&p.next===o?l=p.equal:(l=M(d,o),c?this.equalityCache.set(n.path,{current:d,next:o,equal:l}):this.equalityCache.delete(n.path)),l||(a=R(a,n.path,o))}return a}getReverseDependencies(t){if(this.reverseDepsCache)return this.reverseDepsCache;let e=new Map;for(let s of t)for(let a of s.dependsOn){let n=e.get(a);n||(n=new Set,e.set(a,n)),n.add(s.path)}let i=new Map;for(let s of e.keys()){let a=s.split(".");for(let n=1;n<a.length;n++){let o=a.slice(0,n).join("."),d=i.get(o);d||(d=new Set,i.set(o,d)),d.add(s)}}return this.reverseDepsCache=e,this.childDepsIndex=i,e}resolveEntriesToRun(t,e){if(!e||e.length===0||e.includes("*"))return this.getOrderedAllEntries(t);let i=this.getReverseDependencies(t),s=new Set,a=[...e],n=0;for(;n<a.length;){let l=a[n++],c=this.getDependentsForPath(i,l);if(c)for(let u of c)s.has(u)||(s.add(u),a.push(u))}if(s.size===0)return[];let o=this.getOrderedAllEntries(t),d=this.getOrderedIndexByPath(t,o),p=[];return s.forEach(l=>{let c=d.get(l);if(c===void 0)return;let u=o[c];u&&p.push({index:c,entry:u})}),p.sort((l,c)=>l.index-c.index),p.map(l=>l.entry)}orderEntries(t){if(t.length<=1)return t;let e=new Map(t.map(o=>[o.path,o])),i=new Map,s=new Map;t.forEach(o=>i.set(o.path,0)),t.forEach(o=>{o.dependsOn.forEach(d=>{if(!e.has(d))return;let p=s.get(d)??new Set;p.has(o.path)||(p.add(o.path),s.set(d,p),i.set(o.path,(i.get(o.path)??0)+1))})});let a=t.filter(o=>(i.get(o.path)??0)===0).map(o=>o.path),n=[];for(;a.length>0;){let o=a.shift();n.push(o);let d=s.get(o);d&&d.forEach(p=>{let l=(i.get(p)??0)-1;i.set(p,l),l===0&&a.push(p)})}if(n.length!==t.length)throw new Error("BitStore: cyclic computed dependencies detected. Check computedDependsOn definitions.");return n.map(o=>e.get(o))}getOrderedAllEntries(t){let e=this.createEntriesSignature(t);if(this.orderedAllEntriesCache&&this.orderedAllEntriesCache.signature===e)return this.orderedAllEntriesCache.ordered;let i=this.orderEntries(t);return this.orderedAllEntriesCache={signature:e,ordered:i},i}getOrderedIndexByPath(t,e){let i=this.createEntriesSignature(t);if(this.orderedIndexByPathCache&&this.orderedIndexByPathCache.signature===i)return this.orderedIndexByPathCache.indexByPath;let s=new Map;return e.forEach((a,n)=>{s.set(a.path,n)}),this.orderedIndexByPathCache={signature:i,indexByPath:s},s}ensureEntriesAreValid(t){if(this.validatedEntriesRef===t)return;let e=this.createEntriesSignature(t);if(this.validatedEntriesSignature===e){this.validatedEntriesRef=t;return}t.forEach(i=>this.assertDependencies(i)),this.invalidateReverseDeps(),this.validatedEntriesSignature=e,this.validatedEntriesRef=t}createEntriesSignature(t){return t.map(e=>`${e.path}:${e.dependsOn.join(",")}`).join("|")}getDependentsForPath(t,e){let i=new Set,s=o=>{let d=t.get(o);d&&d.forEach(p=>i.add(p))};s(e);let a=e.split(".");for(;a.length>1;)a.pop(),s(a.join("."));let n=this.childDepsIndex?.get(e);if(n)for(let o of n)s(o);return i}assertDependencies(t){if(t.dependsOn.length===0)throw new Error(`BitStore: computed field \`${t.path}\` requires explicit computedDependsOn in v4.`);if(t.dependsOn.includes(t.path))throw new Error(`BitStore: computed field \`${t.path}\` cannot depend on itself.`)}};var j=class{dirtyPaths=new Set;dirtyPathIndex=new Set;dirtyPrefixRefCount=new Map;childrenByPrefix=new Map;updateForPath(t,e,i){this.removeDirtyChildren(t);let s=m(e,t),a=m(i,t);return F(s,a)?this.removeDirtyPath(t):this.addDirtyPath(t),this.dirtyPaths.size>0}rebuild(t,e){return this.dirtyPaths=Vt(t,e),this.dirtyPrefixRefCount.clear(),this.rebuildIndex(),this.dirtyPaths.size>0}clear(){this.dirtyPaths.clear(),this.dirtyPathIndex.clear(),this.dirtyPrefixRefCount.clear(),this.childrenByPrefix.clear()}get isDirty(){return this.dirtyPaths.size>0}getDirtyPaths(){return this.dirtyPaths}isPathDirty(t){if(this.dirtyPathIndex.has(t))return!0;let e=t.lastIndexOf(".");for(;e>-1;){let i=t.slice(0,e);if((this.dirtyPrefixRefCount.get(i)??0)>0)return!0;e=t.lastIndexOf(".",e-1)}return!1}buildDirtyValues(t){if(this.dirtyPaths.size===0)return{};let e=[],i=[...this.dirtyPaths].sort(),s=new Set,a=new Set,n=o=>{let d=o.lastIndexOf(".");for(;d>-1;){if(a.has(o.slice(0,d)))return!0;d=o.lastIndexOf(".",d-1)}return!1};for(let o of i){if(n(o))continue;let d=o.match(/^(.+)\.\d+/);if(d){let p=d[1];if(s.has(p))continue;s.add(p);let l=m(t,p);e.push([p,l]),a.add(p)}else{let p=m(t,o);e.push([o,p]),a.add(o)}}return e.length===0?{}:T({},e)}rebuildIndex(){let t=new Set,e=new Map,i=new Map;for(let s of this.dirtyPaths)this.forEachPathPrefix(s,a=>{t.add(a),e.set(a,(e.get(a)??0)+1)}),this.forEachAncestorPrefix(s,a=>{let n=i.get(a);n?n.add(s):i.set(a,new Set([s]))});this.dirtyPathIndex=t,this.dirtyPrefixRefCount=e,this.childrenByPrefix=i}removeDirtyChildren(t){let e=this.childrenByPrefix.get(t);if(!(!e||e.size===0))for(let i of[...e])this.removeDirtyPath(i)}addDirtyPath(t){this.dirtyPaths.has(t)||(this.dirtyPaths.add(t),this.forEachPathPrefix(t,e=>{this.dirtyPathIndex.add(e),this.dirtyPrefixRefCount.set(e,(this.dirtyPrefixRefCount.get(e)??0)+1)}),this.forEachAncestorPrefix(t,e=>{let i=this.childrenByPrefix.get(e);i?i.add(t):this.childrenByPrefix.set(e,new Set([t]))}))}removeDirtyPath(t){this.dirtyPaths.has(t)&&(this.dirtyPaths.delete(t),this.forEachPathPrefix(t,e=>{let i=(this.dirtyPrefixRefCount.get(e)??0)-1;if(i<=0){this.dirtyPrefixRefCount.delete(e),this.dirtyPathIndex.delete(e);return}this.dirtyPrefixRefCount.set(e,i)}),this.forEachAncestorPrefix(t,e=>{this.childrenByPrefix.get(e)?.delete(t)}))}forEachPathPrefix(t,e){let i=t.split("."),s="";for(let a of i)s=s?`${s}.${a}`:a,e(s)}forEachAncestorPrefix(t,e){let i=t.split("."),s="";for(let a=0;a<i.length-1;a++)s=s?`${s}.${i[a]}`:i[a],e(s)}};var H=class{masks=new Map;registerMask(t,e){this.masks.set(t,e)}unregisterMask(t){this.masks.has(t)&&this.masks.delete(t)}resolveMask(t){return this.masks.get(t)}getAllMasks(){return Object.fromEntries(this.masks.entries())}clear(){this.masks.clear()}};var z=class{fieldConfigs=new Map;scopeFieldsIndex=null;computedEntriesCache=null;normalizerEntriesCache=null;transformEntriesCache=null;get(t){return this.fieldConfigs.get(t)}set(t,e){this.fieldConfigs.set(t,e),this.registerCachedIndexes(t,e)}delete(t){let e=this.fieldConfigs.get(t);return this.fieldConfigs.delete(t),this.unregisterCachedIndexes(t,e),e}has(t){return this.fieldConfigs.has(t)}forEach(t){this.fieldConfigs.forEach((e,i)=>t(e,i))}entries(){return Array.from(this.fieldConfigs.entries())}getScopeFields(t){if(!this.scopeFieldsIndex){let e=new Map;this.forEach((i,s)=>{if(!i.scope)return;let a=e.get(i.scope)??new Set;a.add(s),e.set(i.scope,a)}),this.scopeFieldsIndex=e}return Array.from(this.scopeFieldsIndex.get(t)??[])}getComputedEntries(){if(!this.computedEntriesCache){let t=[];this.forEach((e,i)=>{e.computed&&t.push({path:i,compute:e.computed,dependsOn:e.computedDependsOn})}),this.computedEntriesCache=t}return this.computedEntriesCache}getTransformEntries(){if(!this.transformEntriesCache){let t=[];this.forEach((e,i)=>{e.transform&&t.push([i,e.transform])}),this.transformEntriesCache=t}return this.transformEntriesCache}getNormalizerEntries(){if(!this.normalizerEntriesCache){let t=[];this.forEach((e,i)=>{e.normalize&&t.push({path:i,normalize:e.normalize,dependsOn:e.normalizeDependsOn?.length?e.normalizeDependsOn:[i]})}),this.normalizerEntriesCache=t}return this.normalizerEntriesCache}invalidateIndexes(){this.scopeFieldsIndex=null,this.computedEntriesCache=null,this.normalizerEntriesCache=null,this.transformEntriesCache=null}registerCachedIndexes(t,e){if(this.scopeFieldsIndex&&e.scope){let i=this.scopeFieldsIndex.get(e.scope)??new Set;i.add(t),this.scopeFieldsIndex.set(e.scope,i)}this.computedEntriesCache&&e.computed&&this.computedEntriesCache.push({path:t,compute:e.computed,dependsOn:e.computedDependsOn}),this.normalizerEntriesCache&&e.normalize&&this.normalizerEntriesCache.push({path:t,normalize:e.normalize,dependsOn:e.normalizeDependsOn?.length?e.normalizeDependsOn:[t]}),this.transformEntriesCache&&e.transform&&this.transformEntriesCache.push([t,e.transform])}unregisterCachedIndexes(t,e){if(!e){this.invalidateIndexes();return}if(this.scopeFieldsIndex&&e.scope){let i=this.scopeFieldsIndex.get(e.scope);i&&(i.delete(t),i.size>0?this.scopeFieldsIndex.set(e.scope,i):this.scopeFieldsIndex.delete(e.scope))}this.computedEntriesCache&&e.computed&&(this.computedEntriesCache=this.computedEntriesCache.filter(i=>i.path!==t)),this.normalizerEntriesCache&&e.normalize&&(this.normalizerEntriesCache=this.normalizerEntriesCache.filter(i=>i.path!==t)),this.transformEntriesCache&&e.transform&&(this.transformEntriesCache=this.transformEntriesCache.filter(([i])=>i!==t))}};var q=class{constructor(t){this.getFieldConfig=t}dependencies=new Map;hiddenFields=new Set;conditionalVisibilityPaths=new Set;requiredPathsByDependency=new Map;requiredConditionalPaths=new Set;requiredEvaluationVersion=0;requiredEvaluationCache=new Map;getHiddenFields(){return this.hiddenFields}onRegister(t,e,i){e.conditional?.showIf&&this.conditionalVisibilityPaths.add(t);let s=e.conditional?.dependsOn;s&&s.forEach(a=>{this.dependencies.has(a)||this.dependencies.set(a,new Set),this.dependencies.get(a).add(t)}),s&&e.conditional?.requiredIf&&(this.requiredConditionalPaths.add(t),s.forEach(a=>{this.requiredPathsByDependency.has(a)||this.requiredPathsByDependency.set(a,new Set),this.requiredPathsByDependency.get(a).add(t)})),this.requiredEvaluationVersion+=1,this.requiredEvaluationCache.clear(),this.evaluateFieldCondition(t,i)}onUnregister(t,e){this.hiddenFields.delete(t),this.conditionalVisibilityPaths.delete(t),this.dependencies.delete(t),this.requiredEvaluationVersion+=1,this.requiredEvaluationCache.clear(),this.requiredConditionalPaths.delete(t),e?.conditional?.dependsOn?.forEach(i=>{let s=this.requiredPathsByDependency.get(i);s&&(s.delete(t),s.size===0&&this.requiredPathsByDependency.delete(i))}),this.dependencies.forEach(i=>{i.delete(t)})}isHidden(t){return this.hiddenFields.has(t)}hasDependents(t){return(this.dependencies.get(t)?.size??0)>0}isRequired(t,e){let i=this.getFieldConfig(t);if(!i||this.isHidden(t)||!i.conditional?.requiredIf)return!1;let s=this.requiredEvaluationCache.get(t);if(s&&s.version===this.requiredEvaluationVersion&&s.valuesRef===e)return s.result;let a=!!i.conditional.requiredIf(e);return this.requiredEvaluationCache.set(t,{version:this.requiredEvaluationVersion,valuesRef:e,result:a}),a}getRequiredErrors(t){let e={};return this.requiredConditionalPaths.forEach(i=>{let s=this.getFieldConfig(i);if(s&&this.isRequired(i,t)){let a=m(t,i);this.isEmpty(a)&&(e[i]=s.conditional?.requiredMessage??"required field")}}),e}evaluateAll(t){this.conditionalVisibilityPaths.forEach(e=>{this.evaluateFieldCondition(e,t)})}updateDependencies(t,e,i){let s=new Set,a=new Set,n=new Set,o=[t],d=new Set;for(;o.length>0;){let p=o.shift();if(d.has(p))continue;d.add(p);let l=this.dependencies.get(p);l&&l.forEach(c=>{s.add(c);let u=this.isHidden(c),h=this.isRequired(c,e);this.evaluateFieldCondition(c,i);let S=this.isHidden(c),B=this.isRequired(c,i);u!==S&&a.add(c),h!==B&&n.add(c),o.push(c)})}return{affectedFields:Array.from(s),visibilityChanged:Array.from(a),requiredChanged:Array.from(n)}}evaluateFieldCondition(t,e){let s=this.getFieldConfig(t)?.conditional?.showIf;s&&(s(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}};function Ge(r){return r.replace(/\.+$/g,"")}function E(r){return Ge(r.trim())}function v(r,t){let e=E(t);return e.length===0?!1:r===e||r.startsWith(`${e}.`)}function bt(r,t){return E(t===void 0?r:`${r}.${t}`)}var U=class{catalog=new z;conditions=new q(t=>this.catalog.get(t));getFieldConfig(t){return this.catalog.get(t)}forEachFieldConfig(t){this.catalog.forEach((e,i)=>t(e,i))}hasFieldConfig(t){return this.catalog.has(t)}getHiddenFields(){return this.conditions.getHiddenFields()}register(t,e,i){this.catalog.set(t,e),this.conditions.onRegister(t,e,i)}unregister(t){let e=this.catalog.delete(t);this.conditions.onUnregister(t,e)}unregisterPrefix(t){let e=[],i=E(t);return i.length===0||(this.catalog.forEach((s,a)=>{v(a,i)&&e.push([a,s])}),e.forEach(([s,a])=>{this.catalog.delete(s),this.conditions.onUnregister(s,a)})),e}isHidden(t){return this.conditions.isHidden(t)}hasDependents(t){return this.conditions.hasDependents(t)}isRequired(t,e){return this.conditions.isRequired(t,e)}getRequiredErrors(t){return this.conditions.getRequiredErrors(t)}evaluateAll(t){this.conditions.evaluateAll(t)}updateDependencies(t,e,i){return this.conditions.updateDependencies(t,e,i)}getScopeFields(t){return this.catalog.getScopeFields(t)}getComputedEntries(){return this.catalog.getComputedEntries()}getTransformEntries(){return this.catalog.getTransformEntries()}getNormalizerEntries(){return this.catalog.getNormalizerEntries()}invalidateIndexes(){this.catalog.invalidateIndexes()}};function Ye(){return`bit-form-${Math.random().toString(36).slice(2,9)}`}function Xe(r){typeof console<"u"&&typeof console.error=="function"&&console.error(r)}function Ot(r={}){let t=r.initialValues??{},e=r.validation,i=r.history,s=r.name?`bit-form:${r.name}:draft`:"bit-form:draft",a=r.onUnhandledError??Xe,n=r.persist?.onError,o={enabled:r.persist?.enabled??!1,key:r.persist?.key??s,storage:r.persist?.storage,autoSave:r.persist?.autoSave??!0,debounceMs:r.persist?.debounceMs??300,mode:r.persist?.mode??"values",serialize:r.persist?.serialize??JSON.stringify,deserialize:r.persist?.deserialize??(d=>JSON.parse(d)),onError:d=>{if(n){n(d);return}a(d,"persist")}};return{name:r.name,initialValues:y(t),resolver:e?.resolver,validationDelay:e?.delay??300,history:{enabled:i?.enabled??!1,limit:i?.limit??50},masks:r.masks,fields:r.fields,devTools:r.devTools,persist:o,idFactory:r.idFactory??Ye,plugins:r.plugins??[],scheduler:r.scheduler,subscriptionCacheSize:r.subscriptionCacheSize,trackedSubscriptions:r.trackedSubscriptions??!1,bus:r.bus,onUnhandledError:a}}function _(r,t){if((!r||r.length===0)&&(!t||t.length===0))return;let e=new Set(r??[]);return t?.forEach(i=>e.add(i)),Array.from(e)}function jt(r){let{values:t,entries:e,deriveValue:i}=r,s=[];for(let a of e){let n=m(t,a.path),o=i(a,n);F(n,o)||s.push([a.path,o])}return s}function Ze(r){let t=r?.includes("*")??!1,e=new Set(r??[]),i=new Set;for(let s of e){i.add(s);let a=s.lastIndexOf(".");for(;a>-1;)i.add(s.slice(0,a)),a=s.lastIndexOf(".",a-1)}return s=>{if(!r||r.length===0||t||e.has(s)||i.has(s))return!0;let a=s.lastIndexOf(".");for(;a>-1;){if(e.has(s.slice(0,a)))return!0;a=s.lastIndexOf(".",a-1)}return!1}}function Qe(r,t){if(!t||t.length===0||t.includes("*"))return r;let e=Ze(t);return r.filter(i=>i.dependsOn.some(s=>e(s)))}function N(r){let{values:t,changedPaths:e,normalizerEntries:i,applyComputed:s}=r,a=Qe(i,e);if(a.length===0)return s(t,e);let n=jt({values:t,entries:a,deriveValue:(p,l)=>p.normalize(l,t)}),o=n.length>0?T(t,n):t,d=_(e,n.map(([p])=>p));return s(o,d)}function Ht(r){let{values:t,sourceValues:e,transformEntries:i}=r;if(i.length===0)return t;let s=jt({values:t,entries:i.map(([a,n])=>({path:a,transform:n})),deriveValue:(a,n)=>a.transform(n,e)});return s.length===0?t:T(t,s)}var L=class{constructor(t,e,i=!0,s){this.storeId=t;this.bus=e;this.enableBusDispatch=i;this.storeBusPort=s}storeBusPort;attachStorePort(t){this.storeBusPort=t,this.enableBusDispatch&&(this.bus.stores[this.storeId]=t)}initialize(){!this.enableBusDispatch||!this.storeBusPort||(this.bus.stores[this.storeId]=this.storeBusPort)}onStateUpdated(t){this.enableBusDispatch&&this.bus.dispatch(this.storeId,t)}destroy(){this.enableBusDispatch&&delete this.bus.stores[this.storeId]}};var W=class{constructor(t){this.persistManager=t}onStateUpdated(t,e){e&&this.persistManager.queueSave()}restorePersisted(){return this.persistManager.restore()}savePersistedNow(){return this.persistManager.saveNow()}clearPersisted(){return this.persistManager.clear()}destroy(){this.persistManager.destroy()}};var K=class{constructor(t){this.pluginManager=t}initialize(){this.pluginManager.setupAll()}beforeValidate(t){return this.pluginManager.beforeValidate(t)}afterValidate(t){return this.pluginManager.afterValidate(t)}beforeSubmit(t){return this.pluginManager.beforeSubmit(t)}afterSubmit(t){return this.pluginManager.afterSubmit(t)}onFieldChange(t){this.pluginManager.onFieldChange(t)}reportOperationalError(t){return this.pluginManager.reportError(t.source,t.error,t.payload)}destroy(){this.pluginManager.destroy()}};var $=class{persistEffects;pluginEffects;busEffects;constructor(t,e,i,s,a=!0,n){this.persistEffects=new W(i),this.pluginEffects=new K(s),this.busEffects=new L(t,e,a,n)}attachStorePort(t){this.busEffects.attachStorePort(t)}initialize(){this.pluginEffects.initialize(),this.busEffects.initialize()}onStateUpdated(t,e){this.persistEffects.onStateUpdated(t,e),this.busEffects.onStateUpdated(t)}restorePersisted(){return this.persistEffects.restorePersisted()}savePersistedNow(){return this.persistEffects.savePersistedNow()}clearPersisted(){return this.persistEffects.clearPersisted()}beforeValidate(t){return this.pluginEffects.beforeValidate(t)}afterValidate(t){return this.pluginEffects.afterValidate(t)}beforeSubmit(t){return this.pluginEffects.beforeSubmit(t)}afterSubmit(t){return this.pluginEffects.afterSubmit(t)}onFieldChange(t){this.pluginEffects.onFieldChange(t)}reportOperationalError(t){return this.pluginEffects.reportOperationalError(t)}destroy(){this.persistEffects.destroy(),this.pluginEffects.destroy(),this.busEffects.destroy()}};function ti(){if(typeof globalThis>"u")return;let r=globalThis.localStorage;if(r)return{getItem:t=>r.getItem(t),setItem:(t,e)=>r.setItem(t,e),removeItem:t=>r.removeItem(t)}}var J=class{constructor(t,e,i,s){this.config=t;this.getValues=e;this.getDirtyValues=i;this.applyRestoredValues=s}timer;getStorage(){return this.config.storage||ti()}canPersist(){return!!(this.config.enabled&&this.config.key&&this.getStorage())}handleError(t){this.config.onError?.(t)}async saveNow(){if(!this.canPersist())return;let t=this.getStorage();if(t)try{let e=this.config.mode==="dirtyValues"?this.getDirtyValues():this.getValues(),i=this.config.serialize(e);await t.setItem(this.config.key,i)}catch(e){this.handleError(e)}}queueSave(){!this.canPersist()||!this.config.autoSave||(this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.saveNow()},this.config.debounceMs))}async restore(){if(!this.canPersist())return!1;let t=this.getStorage();if(!t)return!1;try{let e=await t.getItem(this.config.key);if(!e)return!1;let i=this.config.deserialize(e);return!i||typeof i!="object"?!1:(this.applyRestoredValues(i),!0)}catch(e){return this.handleError(e),!1}}async clear(){if(!this.canPersist())return;let t=this.getStorage();if(t)try{await t.removeItem(this.config.key)}catch(e){this.handleError(e)}}destroy(){this.timer&&(clearTimeout(this.timer),this.timer=void 0)}};var G=class{constructor(t,e){this.plugins=t;this.contextFactory=e}teardownFns=[];notifyingError=!1;cachedContext=null;setupAll(){let t=this.getContext();this.plugins.forEach(e=>{if(e.setup)try{let i=e.setup(t);typeof i=="function"&&this.teardownFns.push(i)}catch(i){this.reportError("setup",i,void 0,e.name)}})}async beforeValidate(t){await this.emitHook("beforeValidate",t)}async afterValidate(t){await this.emitHook("afterValidate",t)}async beforeSubmit(t){await this.emitHook("beforeSubmit",t)}async afterSubmit(t){await this.emitHook("afterSubmit",t)}onFieldChange(t){let e=this.getContext();this.plugins.forEach(i=>{let s=i.hooks?.onFieldChange;if(s)try{let a=s(t,e);Promise.resolve(a).catch(n=>{this.reportError("onFieldChange",n,t,i.name)})}catch(a){this.reportError("onFieldChange",a,t,i.name)}})}async reportError(t,e,i,s){if(this.notifyingError)return;this.notifyingError=!0;let a=this.getContext(),n={source:t,pluginName:s,error:e,event:i,values:a.getState().values,state:a.getState()};for(let o of this.plugins){let d=o.hooks?.onError;if(d)try{await d(n,a)}catch{}}this.notifyingError=!1}destroy(){for(let t=this.teardownFns.length-1;t>=0;t-=1){let e=this.teardownFns[t];try{e()}catch(i){this.reportError("teardown",i)}}this.teardownFns=[],this.cachedContext=null}async emitHook(t,e){let i=this.getContext();for(let s of this.plugins){let a=s.hooks?.[t];if(a)try{await a(e,i)}catch(n){await this.reportError(t,n,e,s.name)}}}getContext(){return this.cachedContext||(this.cachedContext=this.contextFactory()),this.cachedContext}};var Bt=typeof globalThis<"u"?globalThis:typeof global<"u"?global:window;Bt.__BIT_FORM__||(Bt.__BIT_FORM__={stores:{},listeners:new Set,dispatch(r,t){this.listeners.forEach(e=>e(r,t))},subscribe(r){return this.listeners.add(r),()=>{this.listeners.delete(r)}}});var Tt=Bt.__BIT_FORM__,ei={stores:{},listeners:new Set,dispatch:()=>{},subscribe:()=>()=>{}};function vt(){return ei}function ii(){let r=new Set;return{stores:{},listeners:r,dispatch(t,e){r.forEach(i=>i(t,e))},subscribe(t){return r.add(t),()=>r.delete(t)}}}function ri(r){return r.bus?!0:typeof r.devTools=="boolean"?r.devTools:r.devTools&&typeof r.devTools=="object"?r.devTools.enabled!==!1:!1}function zt(r){let{storeId:t,storeBusPort:e,config:i,getState:s,getConfig:a,getValues:n,getDirtyValues:o,applyPersistedValues:d}=r,p=new J(i.persist,n,o,d),l=new G([...i.plugins],()=>({storeId:t,getState:()=>s(),getConfig:()=>a()})),c=ri(i),u=typeof process<"u"&&typeof process.env<"u"&&process.env.VITEST==="true",h=c?i.bus??(u?vt():Tt):vt(),S=new $(t,h,p,l,c,e);return S.initialize(),S}function g(r,t,e){return{kind:"state.patch",partialState:r,changedPaths:t,skipComputed:e?.skipComputed}}function Pt(r){return{kind:"field.touchMany",paths:r}}function P(r){return{kind:"form.persistMeta",patch:r}}function V(r,t){return{kind:"validation.commit",errors:r,isValid:t}}async function qt(r){let{dispatch:t,effects:e}=r;t(P({isRestoring:!0,error:null}));try{return await e.restorePersisted()}catch(i){return t(P({isRestoring:!1,error:i instanceof Error?i:new Error(String(i))})),!1}finally{t(P({isRestoring:!1}))}}async function Ut(r){let{dispatch:t,effects:e}=r;t(P({isSaving:!0,error:null}));try{await e.savePersistedNow()}catch(i){t(P({isSaving:!1,error:i instanceof Error?i:new Error(String(i))}));return}t(P({isSaving:!1}))}async function _t(r){let{dispatch:t,effects:e}=r;t(P({error:null}));try{await e.clearPersisted()}catch(i){t(P({error:i instanceof Error?i:new Error(String(i))}))}}function Nt(r){let{values:t,state:e,initialValues:i,validation:s,fieldRegistry:a,dirtyManager:n,dispatch:o,saveHistorySnapshot:d}=r,p=y(Ct(i,t));s.cancelAll(),a.evaluateAll(p);let l=n.rebuild(p,i);o(g({values:p,errors:{},touched:{},isValidating:{},persist:{...e.persist,error:null},isValid:!0,isDirty:l,isSubmitting:!1})),d(),s.validate()}function Lt(r){let{state:t,path:e}=r,i={...t.errors},s={...t.touched},a=!1;return i[e]&&(delete i[e],a=!0),s[e]&&(delete s[e],a=!0),a?{errors:i,touched:s}:null}function Wt(r){let{path:t,config:e,state:i,fieldRegistry:s,subscriptions:a,stateReader:n,invalidateFieldIndexes:o}=r;s.register(t,e,i.values),o(),a.invalidatePathExpansionCache(t),n.invalidatePath(t),e.scope&&a.notify(i,[C(e.scope)]),s.isHidden(t)&&a.notify(i,[t])}function Kt(r){let{path:t,state:e,hasStaticConfig:i,fieldRegistry:s,subscriptions:a,validationCleanupField:n,invalidateFieldIndexes:o,dispatch:d}=r;if(i)return;let p=s.getFieldConfig(t);n(t),s.unregister(t),o(),a.invalidatePathExpansionCache(t),p?.scope&&a.notify(e,[C(p.scope)]);let l=Lt({state:e,path:t});l&&d(g({errors:l.errors,touched:l.touched}))}function Y(r){let{prefix:t,state:e,fieldRegistry:i,subscriptions:s,validationCleanupPrefix:a,invalidateFieldIndexes:n}=r;a(t);let o=i.unregisterPrefix(t);n(),s.invalidatePathExpansionCache(t),new Set(o.map(([,p])=>p.scope).filter(p=>!!p)).forEach(p=>{s.notify(e,[C(p)])})}var X=class{constructor(t,e=500){this.getState=t;this.MAX_PATH_EXPANSION_CACHE_SIZE=e}listeners=new Set;pathScopedSubscriptions=new Map;pathSelectorIndex=new Map;pathExpansionCache=new Map;subscriptionSeenVersion=new Map;notifyVersion=0;MAX_PATH_EXPANSION_CACHE_SIZE;subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}subscribeSelector(t,e,i,s){let a=t(this.getState()),n={notify:d=>{let p=t(d);s(a,p)||(a=p,e(p))}},o=this.normalizeSubscriptionPaths(i.paths);return this.pathScopedSubscriptions.set(n,o),o.forEach(d=>{this.forEachIndexPath(d,p=>{let l=this.pathSelectorIndex.get(p)??new Set;l.add(n),this.pathSelectorIndex.set(p,l)})}),i.emitImmediately&&e(a),()=>{this.subscriptionSeenVersion.delete(n);let d=this.pathScopedSubscriptions.get(n);d&&(d.forEach(p=>{this.forEachIndexPath(p,l=>{let c=this.pathSelectorIndex.get(l);c&&(c.delete(n),c.size===0&&this.pathSelectorIndex.delete(l))})}),this.pathScopedSubscriptions.delete(n))}}notify(t,e){if(this.listeners.forEach(a=>a()),this.pathScopedSubscriptions.size===0)return;let i=this.normalizeChangedPathIterable(e);if(i.length===0||i.includes("*")){this.pathScopedSubscriptions.forEach((a,n)=>{n.notify(t)});return}if(i.length===1&&this.isSimplePath(i[0])){this.collectSubscribersForSingleChangedPath(i[0]).forEach(n=>{n.notify(t)});return}this.collectSubscribersForChangedPaths(i).forEach(a=>{a.notify(t)})}destroy(){this.listeners.clear(),this.pathScopedSubscriptions.clear(),this.pathSelectorIndex.clear(),this.pathExpansionCache.clear(),this.subscriptionSeenVersion.clear()}invalidatePathExpansionCache(t){if(!t){this.pathExpansionCache.clear();return}let e=E(t);if(e.length===0){this.pathExpansionCache.clear();return}for(let i of this.pathExpansionCache.keys())(v(i,e)||v(e,i))&&this.pathExpansionCache.delete(i)}normalizeSubscriptionPaths(t){if(!t||t.length===0)return[];let e=new Set,i=[];for(let s of t){let a=s.trim();a.length===0||e.has(a)||(e.add(a),i.push(a))}return i}normalizeChangedPathIterable(t){if(!t)return[];let e=new Set,i=[];for(let s of t){let a=s.trim();a.length===0||e.has(a)||(e.add(a),i.push(a))}return i}collectSubscribersForChangedPaths(t){let e=[],i=++this.notifyVersion,s=a=>{let n=this.pathSelectorIndex.get(a);n&&n.forEach(o=>{(this.subscriptionSeenVersion.get(o)??0)>=i||(this.subscriptionSeenVersion.set(o,i),e.push(o))})};return t.forEach(a=>{this.forEachLookupPath(a,s)}),e}collectSubscribersForSingleChangedPath(t){let e=[],i=++this.notifyVersion,s=a=>{let n=this.pathSelectorIndex.get(a);n&&n.forEach(o=>{(this.subscriptionSeenVersion.get(o)??0)>=i||(this.subscriptionSeenVersion.set(o,i),e.push(o))})};return this.forEachLookupPath(t,s),e}expandChangedPathForLookup(t){return this.expandPathGeneric(t)}expandPathForIndexing(t){return this.expandPathGeneric(t)}forEachIndexPath(t,e){if(!this.isSimplePath(t)){this.expandPathForIndexing(t).forEach(e);return}let i=t.split("."),s="";for(let a=0;a<i.length;a+=1)s=s?`${s}.${i[a]}`:i[a],e(s)}forEachLookupPath(t,e){if(!this.isSimplePath(t)){this.expandChangedPathForLookup(t).forEach(e);return}e(t);let i=t.lastIndexOf(".");for(;i>-1;)e(t.slice(0,i)),i=t.lastIndexOf(".",i-1)}isSimplePath(t){return!t.includes("*")&&!t.includes("[")&&!t.includes("]")}expandPathGeneric(t){let e=this.pathExpansionCache.get(t);if(e)return e;let i=t.split("."),s=[];for(let a=1;a<=i.length;a++)s.push(i.slice(0,a).join("."));return this.setBoundedCacheEntry(this.pathExpansionCache,t,s,this.MAX_PATH_EXPANSION_CACHE_SIZE),s}setBoundedCacheEntry(t,e,i,s){if(t.size>=s){let a=t.keys().next().value;a!==void 0&&t.delete(a)}t.set(e,i)}};var w=class{constructor(t){this.steps=t}async run(t){for(let e of this.steps){if(t.halted)break;await e.run(t)}}},Z=class{constructor(t){this.steps=t}run(t){for(let e of this.steps){if(t.halted)break;let i=e.run(t);i!=null&&typeof i.then=="function"&&typeof process<"u"&&process.env?.NODE_ENV!=="production"&&console.warn(`BitSyncPipelineRunner: step "${e.name}" returned a Promise and will not be awaited.`)}}};function x(r){for(let t in r)return!0;return!1}function $t(r){let{targetFields:t,currentErrors:e,allErrors:i,asyncErrors:s}=r;if(t&&t.length>0){let n=e,o=!1,d=()=>(o||(n={...e},o=!0),n);t.forEach(l=>{let c=l,u=e[c];if(i[l])u!==i[l]&&(d()[c]=i[l]);else if(s.has(l)){let h=s.get(l);u!==h&&(d()[c]=h)}else u!==void 0&&delete d()[c]});let p=t.every(l=>!i[l]&&!s.has(l));return{committedErrors:o?n:e,result:p,mode:"scoped"}}let a={};return s.forEach((n,o)=>{a[o]=n}),Object.entries(i).forEach(([n,o])=>{a[n]=o}),{committedErrors:a,result:void 0,mode:"global"}}function Jt(r){let{targetFields:t,hiddenFields:e,getFieldConfig:i,forEachFieldConfig:s}=r,a=[];if(t&&t.length>0){for(let n of t){if(e.has(n))continue;i(n)?.validation?.asyncValidate&&a.push(n)}return a}return s&&s((n,o)=>{!n.validation?.asyncValidate||e.has(o)||a.push(o)}),a}async function Gt(r){let{path:t,values:e,validationId:i,currentValidationId:s,getFieldConfig:a,cancelFieldAsync:n,createAbortController:o,setAbortController:d,clearAbortController:p,setFieldValidating:l,setAsyncError:c,clearAsyncError:u}=r,h=a(t)?.validation?.asyncValidate;if(!h){u(t);return}n(t);let S=o();d(t,S),l(t,!0);try{let B=await h(m(e,t),e);if(S.signal.aborted||i!==s)return;B?c(t,B):u(t)}finally{!S.signal.aborted&&i===s&&l(t,!1),p(t)}}var Q=class{constructor(t){this.port=t}cancelSchedulerTimeout;abortControllers=new Map;pendingJobs=new Map;handle(t,e,i,s){if(!i){this.cancel(t),this.port.setFieldValidating(t,!1);return}this.cancel(t),this.port.setFieldValidating(t,!0);let a=new AbortController;this.abortControllers.set(t,a),this.pendingJobs.set(t,{value:e,dueAt:Date.now()+s,validate:i,controller:a}),this.schedulePendingJobs()}cancel(t){this.pendingJobs.has(t)&&(this.pendingJobs.delete(t),this.schedulePendingJobs());let e=this.abortControllers.get(t);e&&(e.abort(),this.abortControllers.delete(t))}cleanupPrefix(t){for(let e of this.pendingJobs.keys())v(e,t)&&(this.cancel(e),this.port.clearAsyncError(e),this.port.setFieldValidating(e,!1))}cancelAll(){this.cancelSchedulerTimeout&&(this.cancelSchedulerTimeout(),this.cancelSchedulerTimeout=void 0),this.pendingJobs.clear(),this.abortControllers.forEach(t=>t.abort()),this.abortControllers.clear()}schedulePendingJobs(){this.cancelSchedulerTimeout&&(this.cancelSchedulerTimeout(),this.cancelSchedulerTimeout=void 0);let t=Number.POSITIVE_INFINITY;for(let e of this.pendingJobs.values())e.dueAt<t&&(t=e.dueAt);Number.isFinite(t)&&(this.cancelSchedulerTimeout=this.port.schedule(()=>{this.cancelSchedulerTimeout=void 0,this.flushPendingJobs()},Math.max(0,t-Date.now())))}async flushPendingJobs(){this.cancelSchedulerTimeout=void 0;let t=Date.now(),e=[];for(let[i,s]of this.pendingJobs.entries())s.dueAt<=t&&e.push([i,s]);if(e.length===0){this.schedulePendingJobs();return}e.forEach(([i])=>{this.pendingJobs.delete(i)}),await Promise.all(e.map(([i,s])=>this.runJob(i,s))),this.schedulePendingJobs()}async runJob(t,e){if(!e.controller.signal.aborted)try{let i=await e.validate(e.value,this.port.getValues());if(e.controller.signal.aborted)return;i?this.port.setAsyncError(t,i):(this.port.clearAsyncError(t),await this.port.onValidationPassed(t))}finally{e.controller.signal.aborted||this.port.setFieldValidating(t,!1),this.abortControllers.delete(t)}}};var tt=class{constructor(t){this.port=t}cancelTimeout;pendingScopeFields=null;trigger(t,e){this.cancelTimeout&&(this.cancelTimeout(),this.cancelTimeout=void 0);let i=this.port.validationDelay??300,s=e?.forceDebounce?Math.max(1,i):i;if(s>0){if(t&&t.length>0)if(!this.pendingScopeFields)this.pendingScopeFields=new Set(t);else for(let n of t)this.pendingScopeFields.add(n);else this.pendingScopeFields=null;let a=this.pendingScopeFields?Array.from(this.pendingScopeFields):void 0;this.cancelTimeout=this.port.schedule(()=>{this.pendingScopeFields=null,this.cancelTimeout=void 0,this.port.validate({scopeFields:a})},s)}else this.pendingScopeFields=null,this.port.validate({scopeFields:t})}cancelPending(){this.cancelTimeout&&(this.cancelTimeout(),this.cancelTimeout=void 0),this.pendingScopeFields=null}};function Yt(r){let{ctx:t,deps:e}=r;if(t.options?.scope){let i=e.store.getScopeFields(t.options.scope);i.length>0&&(t.targetFields=i)}}async function Xt(r){let{ctx:t,deps:e}=r;await e.store.emitBeforeValidate({values:t.currentState.values,state:t.currentState,scope:t.options?.scope,scopeFields:t.targetFields})}async function Zt(r){let{ctx:t,deps:e}=r,i=e.store.config.resolver?await e.store.config.resolver(t.currentState.values,{scopeFields:t.targetFields}):{},s=e.store.getRequiredErrors(t.currentState.values);t.allErrors={...i,...s},e.store.getHiddenFields().forEach(a=>{delete t.allErrors[a],e.asyncErrors.delete(a)})}async function Qt(r){let{ctx:t,deps:e}=r,i=Jt({targetFields:t.targetFields,hiddenFields:e.store.getHiddenFields(),getFieldConfig:s=>e.store.getFieldConfig(s),forEachFieldConfig:e.store.forEachFieldConfig});i.length!==0&&await Promise.all(i.map(s=>e.runImmediateAsyncValidation(s,t.currentState.values,t.validationId)))}function te(r){let{ctx:t,deps:e}=r,i=$t({targetFields:t.targetFields,currentErrors:t.currentState.errors,allErrors:t.allErrors,asyncErrors:e.asyncErrors});t.committedErrors=i.committedErrors,t.isValid=!x(i.committedErrors),t.result=i.mode==="scoped"?i.result:t.isValid}async function xt(r){let{ctx:t,deps:e}=r;t.validationId!==e.getCurrentValidationId()&&(t.aborted=!0,t.result=t.currentState.isValid,t.halted=!0)}async function ee(r){let{ctx:t,deps:e}=r;e.store.dispatch(V(t.committedErrors,t.isValid)),await e.store.emitAfterValidate({values:e.store.getState().values,state:e.store.getState(),scope:t.options?.scope,scopeFields:t.targetFields,errors:t.committedErrors,result:t.result}),t.halted=!0}async function ie(r){let{scopeFields:t,store:e,asyncErrors:i}=r,s=e.getState(),a=e.config.resolver?await e.config.resolver(s.values,{scopeFields:t}):{},n=e.getRequiredErrors(s.values),o={...a,...n};e.getHiddenFields().forEach(p=>{delete o[p],i.delete(p)});let d={...s.errors};t.forEach(p=>{o[p]?d[p]=o[p]:i.has(p)?d[p]=i.get(p):delete d[p]}),e.dispatch(V(d,!x(d)))}var et=class{currentValidationId=0;immediateAbortControllers=new Map;beginValidation(){return this.currentValidationId+=1,this.currentValidationId}getCurrentValidationId(){return this.currentValidationId}isValidationCurrent(t){return t===this.currentValidationId}setImmediateController(t,e){this.immediateAbortControllers.set(t,e)}clearImmediateController(t){this.immediateAbortControllers.delete(t)}cancelImmediate(t){let e=this.immediateAbortControllers.get(t);e&&(e.abort(),this.immediateAbortControllers.delete(t))}cancelImmediatePrefix(t,e){for(let i of this.immediateAbortControllers.keys())v(i,t)&&(this.cancelImmediate(i),e(i))}cancelAllImmediate(){this.immediateAbortControllers.forEach(t=>{t.abort()}),this.immediateAbortControllers.clear()}};var it=class{constructor(t){this.store=t;this.schedule=t.config.scheduler?.schedule??((i,s)=>{let a=setTimeout(i,s);return()=>clearTimeout(a)}),this.debouncer=new tt({schedule:(i,s)=>this.schedule(i,s),validate:i=>this.validate(i),validationDelay:t.config.validationDelay??300}),this.asyncScheduler=new Q({schedule:(i,s)=>this.schedule(i,s),getValues:()=>this.store.getState().values,setFieldValidating:(i,s)=>this.updateFieldValidating(i,s),setAsyncError:(i,s)=>{this.asyncErrors.set(i,s),this.store.setError(i,s)},clearAsyncError:i=>{this.asyncErrors.delete(i)},onValidationPassed:async i=>{await ie({scopeFields:[i],store:this.store,asyncErrors:this.asyncErrors})}});let e={store:this.store,asyncErrors:this.asyncErrors,getCurrentValidationId:()=>this.coordinator.getCurrentValidationId(),runImmediateAsyncValidation:(i,s,a)=>this.runImmediateAsyncValidation(i,s,a)};this.validationPipeline=new w([{name:"validate:resolve-target-fields",run:i=>Yt({ctx:i,deps:e})},{name:"validate:before-hooks",run:async i=>Xt({ctx:i,deps:e})},{name:"validate:sync-track",run:async i=>Zt({ctx:i,deps:e})},{name:"validate:abort-check-pre-async",run:async i=>xt({ctx:i,deps:e})},{name:"validate:async-track",run:async i=>Qt({ctx:i,deps:e})},{name:"validate:abort-check",run:async i=>xt({ctx:i,deps:e})},{name:"validate:async-track-merge",run:i=>te({ctx:i,deps:e})},{name:"validate:commit",run:async i=>ee({ctx:i,deps:e})}])}validatingCount=0;asyncErrors=new Map;coordinator=new et;validationPipeline;schedule;asyncScheduler;debouncer;updateFieldValidating(t,e){let i=this.store.getState();if(!!i.isValidating[t]===e)return;let a={...i.isValidating};e?(a[t]=!0,this.validatingCount+=1):(delete a[t],this.validatingCount=Math.max(0,this.validatingCount-1)),this.store.dispatch(g({isValidating:a}))}cancelFieldAsync(t){this.asyncScheduler.cancel(t),this.coordinator.cancelImmediate(t)}cleanupField(t){this.cancelFieldAsync(t),this.asyncErrors.delete(t),this.updateFieldValidating(t,!1)}cleanupPrefix(t){this.asyncScheduler.cleanupPrefix(t),this.coordinator.cancelImmediatePrefix(t,e=>{this.asyncErrors.delete(e),this.updateFieldValidating(e,!1)})}beginExternalValidation(t){this.cancelFieldAsync(t),this.updateFieldValidating(t,!0)}endExternalValidation(t){this.updateFieldValidating(t,!1)}async setExternalError(t,e){if(e){this.asyncErrors.set(t,e),this.store.setError(t,e);return}if(this.asyncErrors.delete(t),this.store.validate){await this.store.validate({scopeFields:[t]});return}let i={...this.store.getState().errors};delete i[t],this.store.dispatch(V(i,!x(i)))}handleAsync(t,e){let i=this.store.getFieldConfig(t),s=i?.validation?.asyncValidate,a=i?.validation?.asyncValidateOn??"blur";if(!s||a!=="change"){this.cancelFieldAsync(t),this.updateFieldValidating(t,!1);return}let n=i.validation?.asyncValidateDelay??500;this.asyncScheduler.handle(t,e,s,n)}hasValidationsInProgress(t){let e=this.store.getState();return t&&t.length>0?t.some(i=>!!e.isValidating[i]):this.validatingCount>0}trigger(t,e){this.debouncer.trigger(t,e)}async validate(t){try{t?.scopeFields?.length&&t.scopeFields.forEach(i=>this.cancelFieldAsync(i));let e={options:t,validationId:this.coordinator.beginValidation(),currentState:this.store.getState(),targetFields:t?.scopeFields,allErrors:{},committedErrors:{},isValid:!0,result:!0,aborted:!1};return await this.validationPipeline.run(e),e.aborted&&await this.store.emitAfterValidate({values:this.store.getState().values,state:this.store.getState(),scope:e.options?.scope,scopeFields:e.targetFields,errors:this.store.getState().errors,result:e.currentState.isValid,aborted:!0}),e.result}catch(e){return this.store.config.onUnhandledError(e,"validation"),!1}}clear(t){this.cancelFieldAsync(t),this.updateFieldValidating(t,!1),this.asyncErrors.delete(t)}cancelAll(){this.validatingCount=0,this.debouncer.cancelPending(),this.asyncScheduler.cancelAll(),this.asyncErrors.clear(),this.coordinator.cancelAllImmediate(),this.store.dispatch(g({isValidating:{}}))}async runImmediateAsyncValidation(t,e,i){await Gt({path:t,values:e,validationId:i,currentValidationId:this.coordinator.getCurrentValidationId(),getFieldConfig:s=>this.store.getFieldConfig(s),cancelFieldAsync:s=>this.cancelFieldAsync(s),createAbortController:()=>new AbortController,setAbortController:(s,a)=>{this.coordinator.setImmediateController(s,a)},clearAbortController:s=>{this.coordinator.clearImmediateController(s)},setFieldValidating:(s,a)=>this.updateFieldValidating(s,a),setAsyncError:(s,a)=>{this.asyncErrors.set(s,a)},clearAsyncError:s=>{this.asyncErrors.delete(s)}})}};function Et(r,t,e){if(!Object.prototype.hasOwnProperty.call(r,t))return[r,e];let s=r,a=e;return a||(s={...r},a=!0),delete s[t],[s,a]}var rt=class{constructor(t){this.store=t;this.fieldUpdatePipeline=new Z([{name:"field:clear-current-error",run:e=>this.clearCurrentError(e)},{name:"field:update-dependencies",run:e=>this.updateDependencies(e)},{name:"field:update-dirty",run:e=>this.updateDirtyState(e)},{name:"field:commit-state",run:e=>this.commitFieldState(e)},{name:"field:emit-change",run:e=>this.emitFieldChange(e)},{name:"field:trigger-validate",run:e=>this.triggerResolverValidation(e)},{name:"field:trigger-async-validate",run:e=>this.triggerAsyncValidation(e)}])}fieldUpdatePipeline;updateField(t,e,i={origin:"setField"}){let s=this.store.getState(),a=m(s.values,t),n={path:t,value:e,meta:i,previousValue:a,nextValues:R(s.values,t,e),nextErrors:s.errors,hasMutatedErrors:!1,dependencyDiff:{affectedFields:[],visibilityChanged:[],requiredChanged:[]},isDirty:!1};this.fieldUpdatePipeline.run(n)}clearCurrentError(t){[t.nextErrors,t.hasMutatedErrors]=Et(t.nextErrors,t.path,t.hasMutatedErrors),this.store.clearFieldValidation(t.path)}updateDependencies(t){if(typeof this.store.hasDependentFields=="function"&&!this.store.hasDependentFields(t.path)){t.dependencyDiff.affectedFields.length=0,t.dependencyDiff.visibilityChanged.length=0,t.dependencyDiff.requiredChanged.length=0;return}t.dependencyDiff=this.store.updateDependencies(t.path,this.store.getState().values,t.nextValues),new Set([...t.dependencyDiff.visibilityChanged,...t.dependencyDiff.requiredChanged]).forEach(i=>{[t.nextErrors,t.hasMutatedErrors]=Et(t.nextErrors,i,t.hasMutatedErrors),this.store.clearFieldValidation(i)})}updateDirtyState(t){t.isDirty=this.store.updateDirtyForPath(t.path,t.nextValues,this.store.getBaselineValues())}commitFieldState(t){let e=Array.from(new Set([t.path,...t.dependencyDiff.visibilityChanged,...t.dependencyDiff.requiredChanged]));this.store.dispatch(g({values:t.nextValues,errors:t.nextErrors,isDirty:t.isDirty},e))}emitFieldChange(t){this.store.emitFieldChange({path:t.path,previousValue:t.previousValue,nextValue:t.value,values:this.store.getState().values,state:this.store.getState(),meta:t.meta})}triggerResolverValidation(t){let e=Array.from(new Set([t.path,...t.dependencyDiff.visibilityChanged,...t.dependencyDiff.requiredChanged]));(this.store.config.resolver||t.dependencyDiff.visibilityChanged.length>0||t.dependencyDiff.requiredChanged.length>0)&&this.store.triggerValidation(e)}triggerAsyncValidation(t){(typeof this.store.getFieldConfig=="function"?this.store.getFieldConfig(t.path)?.validation?.asyncValidateOn:void 0)==="change"&&this.store.handleFieldAsyncValidation(t.path,t.value)}};var st=class{constructor(t){this.store=t}collectChangedUpdates(t,e="",i=[]){return Object.entries(t).forEach(([s,a])=>{let n=e?`${e}.${s}`:s;if(a&&typeof a=="object"&&!Array.isArray(a)&&Object.keys(a).length>0){this.collectChangedUpdates(a,n,i);return}i.push([n,a])}),i}setValues(t,e){if(e?.rebase){this.rebaseValues(t);return}if(e?.partial){this.hydrateValues(t);return}this.replaceValuesInternal(t,"replaceValues")}hydrateValues(t){let e=this.collectChangedUpdates(t),i=e.map(([a])=>a),s=e.length>0?T(this.store.getState().values,e):this.store.getState().values;this.replaceValuesInternal(s,"hydrate",i.length>0?i:["*"])}rebaseValues(t){let e=this.store.getState().values,i=y(t);this.store.setBaselineValues(t),this.store.cancelAllValidations(),this.store.evaluateAllDependencies(i),this.store.clearDirtyState(),this.store.dispatch(g({values:i,errors:{},touched:{},isValidating:{},isValid:!0,isDirty:!1,isSubmitting:!1},["*"])),this.store.resetHistory(i),this.store.validateNow(),this.store.emitFieldChange({path:"*",previousValue:e,nextValue:i,values:this.store.getState().values,state:this.store.getState(),meta:{origin:"rebase"}})}applyHistoryState(t){let e=this.store.rebuildDirtyState(t,this.store.getBaselineValues());this.store.dispatch(g({values:t,isDirty:e},["*"])),this.store.triggerValidation(void 0,{forceDebounce:!0})}reset(){this.store.cancelAllValidations();let t=y(this.store.getBaselineValues());this.store.evaluateAllDependencies(t),this.store.clearDirtyState(),this.store.dispatch(g({values:t,errors:{},touched:{},isValidating:{},isValid:!0,isDirty:!1,isSubmitting:!1},["*"])),this.store.resetHistory(t)}replaceValuesInternal(t,e="replaceValues",i=["*"]){let s=this.store.getState().values,a=y(t);this.store.cancelAllValidations(),this.store.evaluateAllDependencies(a);let n=this.store.rebuildDirtyState(a,this.store.getBaselineValues());this.store.dispatch(g({values:a,errors:{},isValidating:{},isValid:!0,isDirty:n,isSubmitting:!1},i)),this.store.internalSaveSnapshot(),this.store.validateNow(),this.store.emitFieldChange({path:"*",previousValue:s,nextValue:a,values:this.store.getState().values,state:this.store.getState(),meta:{origin:e}})}};var at=class{constructor(t){this.store=t;this.submitPipeline=new w([{name:"submit:start",run:async e=>this.startSubmit(e)},{name:"submit:invalid",run:async e=>this.handleInvalidSubmit(e)},{name:"submit:prepare",run:e=>this.prepareSubmitValues(e)},{name:"submit:before-hooks",run:async e=>this.runBeforeSubmitHooks(e)},{name:"submit:user-handler",run:async e=>this.runSubmitHandler(e)},{name:"submit:after-hooks",run:async e=>this.runAfterSubmitHooks(e)}])}submitPipeline;async submit(t){if(this.store.getState().isSubmitting)return{status:"blocked",reason:"isSubmitting"};if(this.store.hasValidationsInProgress())return{status:"blocked",reason:"validating"};this.store.cancelAllValidations();let i={onSuccess:t,isValid:!1,valuesToSubmit:y(this.store.getState().values),dirtyValues:{}};try{return await this.submitPipeline.run(i),i.invalid?{status:"invalid"}:{status:"submitted"}}catch(s){return i.error=s,await this.store.emitOperationalError({source:"submit",error:s}),await this.store.emitAfterSubmit({values:this.store.getState().values,dirtyValues:this.store.buildDirtyValues(this.store.getState().values),state:this.store.getState(),success:!1,error:s}),this.store.config.onUnhandledError(s,"submit"),{status:"failed",error:s}}finally{this.store.dispatch(g({isSubmitting:!1}))}}async startSubmit(t){this.store.dispatch(g({isSubmitting:!0})),t.isValid=await this.store.validateNow()}async handleInvalidSubmit(t){if(t.isValid)return;let e=this.store.getState().errors,i={...this.store.getState().touched};Object.keys(e).forEach(s=>{i[s]=!0}),this.store.batchStateUpdates(()=>{this.store.dispatch(g({touched:i}))}),t.dirtyValues=this.store.buildDirtyValues(this.store.getState().values),t.invalid=!0,await this.store.emitAfterSubmit({values:this.store.getState().values,dirtyValues:t.dirtyValues,state:this.store.getState(),success:!1,invalid:!0}),t.halted=!0}prepareSubmitValues(t){let e=[];this.store.getHiddenFields().forEach(i=>{e.push([i,void 0])}),t.valuesToSubmit=Ht({values:t.valuesToSubmit,sourceValues:this.store.getState().values,transformEntries:this.store.getTransformEntries()}),e.length>0&&(t.valuesToSubmit=T(t.valuesToSubmit,e)),t.dirtyValues=this.store.buildDirtyValues(t.valuesToSubmit)}async runBeforeSubmitHooks(t){await this.store.emitBeforeSubmit({values:t.valuesToSubmit,dirtyValues:t.dirtyValues,state:this.store.getState()})}async runSubmitHandler(t){await t.onSuccess(t.valuesToSubmit,t.dirtyValues)}async runAfterSubmitHooks(t){await this.store.emitAfterSubmit({values:t.valuesToSubmit,dirtyValues:t.dirtyValues,state:this.store.getState(),success:!0})}};var nt=class{constructor(t){this.ports=t;this.fieldUpdate=new rt(t.fieldUpdate),this.values=new st(t.values),this.submitFlow=new at(t.submit)}fieldUpdate;values;submitFlow;updateField(t,e,i={origin:"setField"}){this.fieldUpdate.updateField(t,e,i)}setValues(t,e){this.values.setValues(t,e)}hydrateValues(t){this.values.hydrateValues(t)}rebaseValues(t){this.values.rebaseValues(t)}applyHistoryState(t){this.values.applyHistoryState(t)}async submit(t){return this.submitFlow.submit(t)}reset(){this.values.reset()}};function re(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)&&!(r instanceof Date)&&!(r instanceof RegExp)}function se(r,t){let e=[],i=(s,a,n,o,d)=>{if(!(o&&d&&M(s,a))){if(re(s)&&re(a)&&o&&d){let p=new Set([...Object.keys(s),...Object.keys(a)]);for(let l of p){let c=n?`${n}.${l}`:l,u=Object.prototype.hasOwnProperty.call(s,l),h=Object.prototype.hasOwnProperty.call(a,l);i(s[l],a[l],c,u,h)}return}e.push({path:n,previousValue:y(s),nextValue:y(a),hadPreviousValue:o,hasNextValue:d})}};return i(r,t,"",!0,!0),{operations:e}}function ot(r,t,e){let i=r,s=[],a=[];for(let n of t.operations){let o=e==="undo"?n.hadPreviousValue:n.hasNextValue,d=e==="undo"?n.previousValue:n.nextValue;if(!n.path){i=o?d:{},s.length=0,a.length=0;continue}if(o){s.push([n.path,d]);continue}a.push(n.path)}return s.length>0&&(i=T(i,s)),a.length>0&&(i=wt(i,a)),i}var lt=class{constructor(t,e){this.enableHistory=t;this.maxHistory=e}baseSnapshot=null;currentSnapshot=null;patches=[];historyIndex=-1;historySize=0;saveSnapshot(t){if(!this.enableHistory)return;if(!this.currentSnapshot||this.baseSnapshot===null){this.reset(t);return}this.historyIndex<this.historySize-1&&(this.patches.splice(this.historyIndex),this.historySize=this.historyIndex+1);let e=se(this.currentSnapshot,t);if(e.operations.length!==0)for(this.patches.push(e),this.currentSnapshot=t,this.historyIndex+=1,this.historySize=this.historyIndex+1;this.historySize>this.getCapacity();)this.compactOldestSnapshot()}get canUndo(){return this.enableHistory?this.historyIndex>0:!1}get canRedo(){return this.enableHistory?this.historyIndex<this.historySize-1:!1}undo(){if(!this.canUndo||!this.currentSnapshot)return null;let t=this.patches[this.historyIndex-1],e=ot(this.currentSnapshot,t,"undo");return this.currentSnapshot=e,this.historyIndex-=1,e}redo(){if(!this.canRedo||!this.currentSnapshot)return null;let t=this.patches[this.historyIndex],e=ot(this.currentSnapshot,t,"redo");return this.currentSnapshot=e,this.historyIndex+=1,e}reset(t){if(!this.enableHistory){this.baseSnapshot=null,this.currentSnapshot=null,this.patches=[],this.historyIndex=-1,this.historySize=0;return}this.baseSnapshot=y(t),this.currentSnapshot=this.baseSnapshot,this.patches=[],this.historyIndex=0,this.historySize=1}getMetadata(){return{enabled:this.enableHistory,canUndo:this.canUndo,canRedo:this.canRedo,historyIndex:this.historyIndex,historySize:this.historySize}}compactOldestSnapshot(){let t=this.patches.shift();!t||this.baseSnapshot===null||(this.baseSnapshot=ot(this.baseSnapshot,t,"redo"),this.historySize=Math.max(1,this.historySize-1),this.historyIndex=Math.max(0,this.historyIndex-1))}getCapacity(){return Math.max(1,this.maxHistory)}};var dt=class{constructor(t){this.store=t}pushItem(t,e){this.mutateArrayWithSetField(t,i=>[...i,e],{origin:"array",operation:"push"})}prependItem(t,e){this.mutateArrayWithSetField(t,i=>[e,...i],{origin:"array",operation:"prepend"})}insertItem(t,e,i){this.mutateArrayWithSetField(t,s=>{let a=[...s];return a.splice(e,0,i),a},{origin:"array",operation:"insert",index:e})}removeItem(t,e){let i=this.store.getState(),s=m(i.values,t);if(!Array.isArray(s))return;let a=[...s];this.store.unregisterPrefix&&this.store.unregisterPrefix(bt(t,e));let n=s.filter((o,d)=>d!==e);this.commitArrayMutationWithFieldPipeline({path:t,nextArray:n,meta:{origin:"array",operation:"remove",index:e},reindex:o=>o===e?null:o>e?o-1:o})}swapItems(t,e,i){let s=this.store.getState(),a=[...m(s.values,t)||[]];[a[e],a[i]]=[a[i],a[e]],this.commitArrayMutationWithFieldPipeline({path:t,nextArray:a,meta:{origin:"array",operation:"swap",from:e,to:i},reindex:n=>n===e?i:n===i?e:n})}moveItem(t,e,i){let s=this.store.getState(),a=[...m(s.values,t)||[]],[n]=a.splice(e,1);a.splice(i,0,n),this.commitArrayMutationWithFieldPipeline({path:t,nextArray:a,meta:{origin:"array",operation:"move",from:e,to:i},reindex:o=>o===e?i:e<i&&o>e&&o<=i?o-1:e>i&&o>=i&&o<e?o+1:o})}replaceItems(t,e){this.commitArrayMutationWithFieldPipeline({path:t,nextArray:e,meta:{origin:"array",operation:"replace"},reindex:i=>i<e.length?i:null})}clearItems(t){this.store.unregisterPrefix&&this.store.unregisterPrefix(bt(t)),this.commitArrayMutationWithFieldPipeline({path:t,nextArray:[],meta:{origin:"array",operation:"clear"},reindex:()=>null})}mutateArrayWithSetField(t,e,i){let s=m(this.store.getState().values,t)||[];this.store.setFieldWithMeta(t,e(s),i),this.store.internalSaveSnapshot()}commitArrayMutationWithFieldPipeline(t){let{path:e,nextArray:i,meta:s,reindex:a}=t,n=this.store.getState();this.store.setFieldWithMeta(e,i,s);let o=Dt(n,e,a);this.store.dispatch(g({errors:o.errors,touched:o.touched,isValidating:o.isValidating},[e])),this.store.internalSaveSnapshot()}};var ct=class{constructor(t,e,i,s){this.getState=t;this.getInitialValues=e;this.getScopeFields=i;this.isPathDirty=s}getScopeStatus(t){let e=this.getScopeFields(t),i=this.getState(),s=e.some(o=>!!i.errors[o]),a=e.some(o=>this.isPathDirty(o)),n=this.getScopeErrors(t);return{hasErrors:s,isDirty:a,errors:n}}getScopeErrors(t){let e=this.getScopeFields(t),i=this.getState(),s={};for(let a of e){let n=i.errors[a];n&&(s[a]=n)}return s}};var pt=class{constructor(t,e,i){this.fieldMetadataProvider=t;this.getState=e;this.isPathDirty=i}requiredValuesRef=null;isHidden(t){return this.fieldMetadataProvider.isHidden(t)}isRequired(t){let e=this.getState().values;return this.requiredValuesRef!==e&&(this.requiredValuesRef=e),this.fieldMetadataProvider.isRequired(t,e)}isFieldDirty(t){return this.isPathDirty(t)}isFieldValidating(t){return!!this.getState().isValidating[t]}isTouched(t){return!!this.getState().touched[t]}};var ut=class{constructor(t,e){this.getState=t;this.dispatch=e}setError(t,e){let i={...this.getState().errors,[t]:e};e||delete i[t],this.dispatch(g({errors:i}))}setErrors(t){this.dispatch(g({errors:{...this.getState().errors,...t}}))}setServerErrors(t){let e={};for(let[i,s]of Object.entries(t))e[i]=Array.isArray(s)?s[0]:s;this.setErrors(e)}};function ae(r){let t=[],e=new Map;for(let n of r)if(e.has(n.path)||e.set(n.path,new Set),n.dependsOn)for(let o of n.dependsOn)r.find(p=>p.path===o)&&e.get(n.path).add(o);let i=new Set,s=new Set,a=(n,o)=>{i.add(n),s.add(n),o.push(n);let d=e.get(n)||new Set;for(let p of d)if(i.has(p)){if(s.has(p)){let l=o.indexOf(p),c=[...o.slice(l),p];return{cycle:c,paths:Array.from(e.keys()).filter(u=>c.includes(u)),message:`Circular dependency detected: ${c.join(" \u2192 ")}. Check your computed field definitions.`}}}else{let l=a(p,[...o]);if(l)return l}return s.delete(n),null};for(let n of e.keys())if(!i.has(n)){let o=a(n,[]);o&&!t.some(d=>d.message===o.message)&&t.push(o)}return t}var Ft=class{entries=new Map;register(t,e){this.entries.set(t,e)}resolve(t){let e=this.entries.get(t);if(!e)throw new Error(`BitStore capability "${String(t)}" n\xE3o foi registrada.`);return e}toCapabilities(){return{validation:this.resolve("validation"),lifecycle:this.resolve("lifecycle"),history:this.resolve("history"),arrays:this.resolve("arrays"),scope:this.resolve("scope"),query:this.resolve("query"),error:this.resolve("error")}}};function ne(){return new Ft}function si(r){let{registry:t,ports:e,fieldRegistry:i}=r;t.register("validation",new it(e.validationPort)),t.register("lifecycle",new nt(e.lifecyclePorts)),t.register("history",new lt(!!e.config.history.enabled,e.config.history.limit??50)),t.register("arrays",new dt(e.arrayPort)),t.register("scope",new ct(()=>e.getState(),()=>e.getBaselineValues(),s=>e.getScopeFields(s),s=>e.isPathDirty(s))),t.register("query",new pt(i,()=>e.getState(),s=>e.isPathDirty(s))),t.register("error",new ut(()=>e.getState(),s=>e.dispatch(s)))}function oe(r){let{ports:t,fieldRegistry:e}=r,i=ne();return si({registry:i,ports:t,fieldRegistry:e}),{registry:i,capabilities:i.toCapabilities()}}function le(r){let{config:t,fieldRegistry:e,computedManager:i}=r,s=y(t.initialValues);t.fields&&Object.entries(t.fields).forEach(([o,d])=>{e.register(o,d,s)});let a=ae(e.getComputedEntries());if(a.length>0)throw new Error(a[0].message);return{values:N({values:s,normalizerEntries:e.getNormalizerEntries(),applyComputed:(o,d)=>i.apply(o,d)}),errors:{},touched:{},isValidating:{},persist:{isSaving:!1,isRestoring:!1,error:null},isValid:!0,isSubmitting:!1,isDirty:!1}}function de(r){return{getState:r.getState,dispatch:r.dispatch,setError:r.setError,validate:r.validate,getFieldConfig:r.getFieldConfig,forEachFieldConfig:t=>r.fieldRegistry.forEachFieldConfig((e,i)=>t(e,i)),getScopeFields:r.getScopeFields,config:r.config,getRequiredErrors:t=>r.fieldRegistry.getRequiredErrors(t),getHiddenFields:()=>r.fieldRegistry.getHiddenFields(),emitBeforeValidate:t=>r.getEffects().beforeValidate(t),emitAfterValidate:t=>r.getEffects().afterValidate(t)}}function ce(r){let t={getState:r.getState,dispatch:r.dispatch,config:r.config,getFieldConfig:s=>r.fieldRegistry.getFieldConfig(s),updateDependencies:(s,a,n)=>r.fieldRegistry.updateDependencies(s,a,n),hasDependentFields:s=>r.fieldRegistry.hasDependents(s),isFieldHidden:s=>r.fieldRegistry.isHidden(s),clearFieldValidation:s=>r.getValidation().clear(s),triggerValidation:(s,a)=>r.getValidation().trigger(s,a),handleFieldAsyncValidation:(s,a)=>r.getValidation().handleAsync(s,a),updateDirtyForPath:(s,a,n)=>r.dirtyManager.updateForPath(s,a,n),getBaselineValues:r.getBaselineValues,emitFieldChange:s=>r.getEffects().onFieldChange(s)},e={getState:r.getState,dispatch:r.dispatch,internalSaveSnapshot:r.saveHistorySnapshot,evaluateAllDependencies:s=>r.fieldRegistry.evaluateAll(s),cancelAllValidations:()=>r.getValidation().cancelAll(),validateNow:s=>r.getValidation().validate(s),rebuildDirtyState:(s,a)=>r.dirtyManager.rebuild(s,a),clearDirtyState:r.dirtyManager.clear.bind(r.dirtyManager),getBaselineValues:r.getBaselineValues,setBaselineValues:r.setBaselineValues,resetHistory:s=>r.getHistory().reset(s),emitFieldChange:s=>r.getEffects().onFieldChange(s),triggerValidation:(s,a)=>r.getValidation().trigger(s,a)},i={getState:r.getState,dispatch:r.dispatch,batchStateUpdates:r.runStateBatch,config:r.config,getTransformEntries:r.getTransformEntries,getHiddenFields:()=>r.fieldRegistry.getHiddenFields(),cancelAllValidations:()=>r.getValidation().cancelAll(),validateNow:s=>r.getValidation().validate(s),hasValidationsInProgress:s=>r.getValidation().hasValidationsInProgress(s),buildDirtyValues:s=>r.dirtyManager.buildDirtyValues(s),emitBeforeSubmit:s=>r.getEffects().beforeSubmit(s),emitAfterSubmit:s=>r.getEffects().afterSubmit(s),emitOperationalError:s=>r.getEffects().reportOperationalError(s)};return{fieldUpdate:t,values:e,submit:i}}function pe(r){return{getState:r.getState,setFieldWithMeta:r.setFieldWithMeta,dispatch:r.dispatch,internalSaveSnapshot:r.saveHistorySnapshot,unregisterPrefix:r.unregisterPrefix}}function ue(r){let{config:t,fieldRegistry:e,dirtyManager:i,baselineManager:s,runtimeContext:a}=r,{stateAccess:n,fieldAccess:o,featureAccess:d,actions:p}=a,l=de({config:t,fieldRegistry:e,getState:n.getState,dispatch:n.dispatch,setError:p.setError,validate:p.validate,getFieldConfig:o.getFieldConfig,getScopeFields:o.getScopeFields,getEffects:d.getEffects}),c=ce({config:t,fieldRegistry:e,dirtyManager:i,getState:n.getState,dispatch:n.dispatch,saveHistorySnapshot:n.saveHistorySnapshot,runStateBatch:n.runStateBatch,getTransformEntries:o.getTransformEntries,getBaselineValues:()=>s.getValues(),setBaselineValues:h=>s.setValues(h),getValidation:d.getValidation,getHistory:d.getHistory,getEffects:d.getEffects}),u=pe({getState:n.getState,dispatch:n.dispatch,setFieldWithMeta:(h,S,B)=>p.setFieldWithMeta(h,S,B),unregisterPrefix:p.unregisterPrefix,saveHistorySnapshot:n.saveHistorySnapshot});return oe({ports:{validationPort:l,lifecyclePorts:c,arrayPort:u,config:t,getScopeFields:o.getScopeFields,getState:n.getState,dispatch:n.dispatch,getBaselineValues:()=>s.getValues(),isPathDirty:h=>i.isPathDirty(h)},fieldRegistry:e})}function he(r){let{config:t,fieldRegistry:e,dirtyManager:i,computedManager:s,rawConfig:a,baselineManager:n,runtimeContext:o}=r,{stateAccess:d,fieldAccess:p,featureAccess:l,actions:c}=o,u=ue({config:t,fieldRegistry:e,dirtyManager:i,baselineManager:n,runtimeContext:{stateAccess:d,fieldAccess:p,featureAccess:l,actions:c}}),h=le({config:t,fieldRegistry:e,computedManager:s}),S=new X(d.getState,t.subscriptionCacheSize),B=a.storeId||t.name||t.idFactory({scope:"store",storeName:t.name});return{state:h,subscriptions:S,capabilityRegistry:u.registry,storeId:B}}function ge(){return{depth:0,pendingState:null,changedPathSet:null,changedPathList:null,valuesChanged:!1,pendingHistorySnapshot:!1}}function fe(r){r.depth+=1}function me(r){return r.depth-=1,r.depth===0}function ht(r,t){return t.pendingState??r}function ye(r,t){if(r.pendingState=t.nextState,r.valuesChanged||=t.valuesChanged,t.valuesChanged&&(r.pendingHistorySnapshot=!0),t.changedPaths&&t.changedPaths.length>0){let e=r.changedPathSet??new Set,i=r.changedPathList??[];t.changedPaths.forEach(s=>{if(e.has("*")||e.has(s))return;if(s==="*"){e.clear(),i.length=0,e.add("*"),i.push("*");return}if(!i.some(n=>n!=="*"&&s.startsWith(`${n}.`))){for(let n=i.length-1;n>=0;n-=1){let o=i[n];o==="*"||!o.startsWith(`${s}.`)||(e.delete(o),i.splice(n,1))}e.add(s),i.push(s)}}),r.changedPathSet=e,r.changedPathList=i}}function Se(r){let{currentState:t,batchState:e,applyValueDerivations:i}=r;if(!e.pendingState)return e.pendingHistorySnapshot=!1,null;let s=e.pendingState,a=e.changedPathList??void 0,n=e.valuesChanged;return n&&(s={...s,values:i(s.values,a)}),e.pendingState=null,e.changedPathSet=null,e.changedPathList=null,e.valuesChanged=!1,{nextState:s??t,changedPaths:a,valuesChanged:n}}function ai(r){let t=!1;for(let i of Object.values(r))if(i===void 0){t=!0;break}if(!t)return r;let e={};return Object.entries(r).forEach(([i,s])=>{let a=s;a!==void 0&&(e[i]=a)}),e}function be(r){let{currentState:t,partialState:e,changedPaths:i,applyValueDerivations:s,applyComputedValues:a}=r,n=s??(u=>a?a(u):u),o={...t,...e},d=!!e.values;e.values&&(o.values=n(e.values,i)),e.errors&&(o.errors=ai(e.errors),o.isValid=!x(o.errors));let p=i&&i.length>0?i:void 0,l=ni(e),c=_(p,l);return{nextState:o,changedPaths:c,valuesChanged:d}}function ni(r){let t=new Set,e=[r.errors,r.touched,r.isValidating];for(let i of e)if(i)for(let s in i)t.add(s);return r.persist&&t.add("persist"),"isValid"in r&&t.add("isValid"),"isDirty"in r&&t.add("isDirty"),"isSubmitting"in r&&t.add("isSubmitting"),t.size>0?Array.from(t):void 0}function oi(r){throw new Error(`BitStore: unsupported operation kind: ${String(r.kind)}`)}function li(r,t){switch(t.kind){case"state.patch":return t;case"field.touchMany":{if(t.paths.length===0)return null;let e={...r.touched};for(let i of t.paths)e[i]=!0;return g({touched:e},t.paths)}case"form.persistMeta":return g({persist:{...r.persist,...t.patch}});case"history.apply":return g({values:t.values,isDirty:t.isDirty},["*"]);case"validation.commit":return g({errors:t.errors,isValid:t.isValid});default:return oi(t)}}function di(r){let{currentState:t,operation:e,applyValueDerivations:i}=r,s=Object.prototype.hasOwnProperty.call(e.partialState,"values"),a=e.changedPaths??(s?["*"]:void 0);return be({currentState:t,partialState:e.partialState,changedPaths:a,applyValueDerivations:i})}function Be(r){let{currentState:t,operation:e,applyValueDerivations:i}=r,s=li(t,e);return s?di({currentState:t,operation:s,applyValueDerivations:(a,n)=>s.skipComputed?a:i(a,n)}):null}function Te(r){let{state:t,batchState:e,operation:i,applyValueDerivations:s,onStateCommitted:a}=r,n=ht(t,e);if(e.depth>0){let d=Be({currentState:n,operation:i,applyValueDerivations:p=>p});return d&&ye(e,d),t}let o=Be({currentState:t,operation:i,applyValueDerivations:s});return o?(a({nextState:o.nextState,changedPaths:o.changedPaths,valuesChanged:o.valuesChanged}),o.nextState):t}function ve(r){let{state:t,batchState:e,applyValueDerivations:i,onStateCommitted:s}=r,a=Se({currentState:t,batchState:e,applyValueDerivations:i});return a?(s({nextState:a.nextState,changedPaths:a.changedPaths,valuesChanged:a.valuesChanged}),a.nextState):t}function Pe(r){let{batchState:t,callback:e,flushBatchedStateUpdates:i}=r;fe(t);try{return e()}finally{me(t)&&i()}}function xe(r){let{payload:t,setState:e,notifySubscriptions:i,notifyEffects:s}=r;e(t.nextState),i(t.nextState,t.changedPaths),s(t.nextState,t.valuesChanged)}function Ee(r){let{state:t,batchState:e,operation:i,applyValueDerivations:s,onStateCommitted:a}=r;return Te({state:t,batchState:e,operation:i,applyValueDerivations:s,onStateCommitted:a})}function Fe(r){let{batchState:t,values:e,saveHistory:i}=r;if(t.depth>0){t.pendingHistorySnapshot=!0;return}i(e)}function Ce(r){let{state:t,batchState:e,applyValueDerivations:i,onStateCommitted:s,saveHistory:a}=r,n=ve({state:t,batchState:e,applyValueDerivations:i,onStateCommitted:s});return e.pendingHistorySnapshot&&(e.pendingHistorySnapshot=!1,a(n.values)),n}var gt=class{constructor(t){this.args=t;this.state=t.state,this.subscriptions=t.subscriptions,this.effects=t.effects,this.capabilityRegistry=t.capabilityRegistry,this.capabilities=t.capabilityRegistry.toCapabilities()}state;batchState=ge();subscriptions;effects;capabilityRegistry;capabilities;getCapability(t){return this.capabilityRegistry.resolve(t)}getState(){return ht(this.state,this.batchState)}runBatch(t){return Pe({batchState:this.batchState,callback:t,flushBatchedStateUpdates:()=>this.flushBatchedStateUpdates()})}dispatch(t){this.state=Ee({state:this.state,batchState:this.batchState,operation:t,applyValueDerivations:(e,i)=>this.applyValueDerivations(e,i),onStateCommitted:e=>this.onStateCommitted(e)})}saveHistorySnapshot(){let t=this.capabilities.history.getMetadata();Fe({batchState:this.batchState,values:this.state.values,saveHistory:i=>this.capabilities.history.saveSnapshot(i)});let e=this.capabilities.history.getMetadata();this.notifyIfHistoryChanged(t,e)}cleanup(){this.subscriptions.destroy(),this.capabilities.validation.cancelAll(),this.effects.destroy()}onStateCommitted(t){xe({payload:t,setState:e=>{this.state=e},notifySubscriptions:(e,i)=>this.subscriptions.notify(e,i),notifyEffects:(e,i)=>this.effects.onStateUpdated(e,i)})}flushBatchedStateUpdates(){let t=this.capabilities.history.getMetadata();this.state=Ce({state:this.state,batchState:this.batchState,applyValueDerivations:(i,s)=>this.applyValueDerivations(i,s),onStateCommitted:i=>this.onStateCommitted(i),saveHistory:i=>this.capabilities.history.saveSnapshot(i)});let e=this.capabilities.history.getMetadata();this.notifyIfHistoryChanged(t,e)}applyValueDerivations(t,e){return this.args.applyValueDerivations?this.args.applyValueDerivations(t,e):t}notifyIfHistoryChanged(t,e){t.canUndo===e.canUndo&&t.canRedo===e.canRedo&&t.historyIndex===e.historyIndex&&t.historySize===e.historySize||this.subscriptions.notify(this.getState(),[k()])}};function Ve(r){let{rawConfig:t,overrides:e}=r,i=Ot(t),s=e?.baselineManager??new I(i.initialValues),a=e?.fieldRegistry??new U,n=e?.computedManager??new O(()=>a.getComputedEntries()),o=e?.dirtyManager??new j,d=e?.maskManager??new H;i.masks&&Object.entries(i.masks).forEach(([f,b])=>{d.registerMask(f,b)});let p=()=>{a.invalidateIndexes(),n.invalidateReverseDeps()},l,c=()=>{if(!l)throw new Error("BitStore runtime kernel is not initialized yet.");return l},u=he({rawConfig:t,config:i,fieldRegistry:a,computedManager:n,dirtyManager:o,baselineManager:s,runtimeContext:{stateAccess:{getState:()=>c().getState(),dispatch:f=>c().dispatch(f),saveHistorySnapshot:()=>c().saveHistorySnapshot(),runStateBatch:f=>c().runBatch(f)},fieldAccess:{getFieldConfig:f=>a.getFieldConfig(f),getScopeFields:f=>a.getScopeFields(f),getNormalizerEntries:()=>a.getNormalizerEntries(),getTransformEntries:()=>a.getTransformEntries()},featureAccess:{getEffects:()=>c().effects,getHistory:()=>c().getCapability("history"),getValidation:()=>c().getCapability("validation")},actions:{setError:(f,b)=>{c().getCapability("error").setError(f,b)},validate:f=>c().getCapability("validation").validate(f),setFieldWithMeta:(f,b,yt={origin:"setField"})=>{c().runBatch(()=>{c().getCapability("lifecycle").updateField(f,b,yt)})},unregisterPrefix:f=>{Y({prefix:f,state:c().getState(),fieldRegistry:a,subscriptions:c().subscriptions,validationCleanupPrefix:b=>c().getCapability("validation").cleanupPrefix(b),invalidateFieldIndexes:p})},triggerValidation:(f,b)=>{c().getCapability("validation").trigger(f,b)}}}}),h=()=>{let f=c().getState();return o.buildDirtyValues(f.values)},S=f=>{Nt({values:f,state:c().getState(),initialValues:s.getValues(),validation:c().getCapability("validation"),fieldRegistry:a,dirtyManager:o,dispatch:b=>c().dispatch(b),saveHistorySnapshot:()=>c().saveHistorySnapshot()})},B=zt({storeId:u.storeId,config:i,getState:()=>c().getState(),getConfig:()=>i,getValues:()=>c().getState().values,getDirtyValues:h,applyPersistedValues:S});return l=new gt({state:u.state,subscriptions:u.subscriptions,effects:B,capabilityRegistry:u.capabilityRegistry,applyValueDerivations:(f,b)=>N({values:f,changedPaths:b,normalizerEntries:a.getNormalizerEntries(),applyComputed:(yt,Je)=>n.apply(yt,Je)})}),l.saveHistorySnapshot(),{config:i,storeId:u.storeId,runtime:l,fieldRegistry:a,computedManager:n,dirtyManager:o,maskManager:d,baselineManager:s}}function we(r){let{dispatch:t,effects:e}=r;return qt({dispatch:t,effects:e})}function De(r){let{dispatch:t,effects:e}=r;return Ut({dispatch:t,effects:e})}function Ae(r){let{dispatch:t,effects:e}=r;return _t({dispatch:t,effects:e})}function Me(r){let{history:t,applyHistoryState:e}=r,i=t.undo();i&&e(i)}function Re(r){let{history:t,applyHistoryState:e}=r,i=t.redo();i&&e(i)}function ke(r){return r.history.getMetadata()}function Ie(r,t){let e=new Set,i=(n,o)=>n===null||typeof n!="object"?n:new Proxy(n,{get:(d,p,l)=>{if(typeof p=="symbol")return Reflect.get(d,p,l);let c=String(p),u=o?`${o}.${c}`:c;e.add(u);let h=Reflect.get(d,p,l);return i(h,u)}}),s=i(r,"");t(s);let a=new Set;return e.forEach(n=>{let o=ci(n);o&&a.add(o)}),Array.from(a)}function ci(r){if(r)return r==="values"?"*":r.startsWith("values.")?r.slice(7):r==="errors"||r==="touched"||r==="isValidating"?"*":r.startsWith("errors.")?r.slice(7):r.startsWith("touched.")?r.slice(8):r.startsWith("isValidating.")?r.slice(13):r==="persist"||r.startsWith("persist.")?"persist":r}function pi(r,t){if(r.length!==t.length)return!1;let e=new Set(t);for(let i of r)if(!e.has(i))return!1;return!0}function ui(r,t){return r.length===0?{emitImmediately:t?.emitImmediately,equalityFn:t?.equalityFn,mode:"scoped",paths:["*"]}:{emitImmediately:t?.emitImmediately,equalityFn:t?.equalityFn,mode:"scoped",paths:r}}function Oe(r){let{getState:t,subscribeSelector:e,selector:i,listener:s,options:a}=r,n=null,o=Ie(t(),i),d=!1,p=!1,l=c=>{n=e(i,u=>{s(u);let h=Ie(t(),i);pi(o,h)||(o=h,!(p||d)&&(p=!0,queueMicrotask(()=>{p=!1,!d&&(n?.(),l(o))})))},ui(c,a))};return l(o),()=>{d=!0,n?.(),n=null}}function je(r){let{getState:t,subscriptions:e,selector:i,listener:s,options:a,trackedSubscriptionsEnabled:n}=r,o=a?.equalityFn??F;if(a?.mode==="tracked"){if(!n)throw new Error('BitForm: subscribeSelector com mode="tracked" est\xE1 desabilitado por padr\xE3o. Ative config.trackedSubscriptions=true para habilitar o modo avan\xE7ado.');return Oe({getState:t,subscribeSelector:(d,p,l)=>e.subscribeSelector(d,p,l,o),selector:i,listener:s,options:a})}return e.subscribeSelector(i,s,a,o)}function He(r){let{path:t,listener:e,options:i,subscribeSelector:s}=r,a=[...i?.paths??[],t];return s(n=>m(n.values,t),e,{...i,paths:a})}function ze(r){let{path:t,listener:e,getFieldState:i,subscribeSelector:s}=r;return s(()=>i(t),e,{paths:[t],equalityFn:Rt})}function qe(r){let{listener:t,subscribeSelector:e}=r;return e(i=>({isValid:i.isValid,isDirty:i.isDirty,isSubmitting:i.isSubmitting}),t,{paths:["isValid","isDirty","isSubmitting"],equalityFn:(i,s)=>i.isValid===s.isValid&&i.isDirty===s.isDirty&&i.isSubmitting===s.isSubmitting})}function Ue(r){let{listener:t,subscribeSelector:e}=r;return e(i=>i.persist,t,{paths:["persist"],equalityFn:(i,s)=>i.isSaving===s.isSaving&&i.isRestoring===s.isRestoring&&i.error===s.error})}function _e(r){let{readHistoryMeta:t,subscribeSelector:e,listener:i}=r;return e(()=>t(),i,{paths:[k()],equalityFn:(s,a)=>Mt(s,a)})}function Ne(r){let{scopeName:t,getScopeFields:e,readScopeStatus:i,subscribeSelector:s,listener:a}=r,n=C(t),o=i(t),d=()=>{},p=()=>{d();let c=At(e(t));d=s(()=>i(t),u=>{St(o,u)||(o=u,a(u))},{paths:[...c,n]})};p();let l=s(()=>e(t).length,()=>{p();let c=i(t);St(o,c)||(o=c,a(c))},{paths:[n]});return()=>{d(),l()}}function Le(r){let{runtime:t,config:e,fieldRegistry:i,dirtyManager:s,stateReader:a}=r,n={getState:()=>a.getState(),getFieldState:l=>a.getFieldState(l),getIsValid:()=>a.getFlag("isValid"),getIsSubmitting:()=>a.getFlag("isSubmitting"),getIsDirty:()=>a.getFlag("isDirty"),isHidden:l=>t.capabilities.query.isHidden(l),isRequired:l=>t.capabilities.query.isRequired(l),isFieldDirty:l=>t.capabilities.query.isFieldDirty(l),isFieldValidating:l=>t.capabilities.query.isFieldValidating(l),getDirtyValues:()=>s.buildDirtyValues(a.getState().values),getPersistMetadata:()=>a.getPersistMetadata(),getHistoryMetadata:()=>ke({history:t.capabilities.history}),getScopeStatus:l=>t.capabilities.scope.getScopeStatus(l),getScopeErrors:l=>t.capabilities.scope.getScopeErrors(l),getCanUndo:()=>t.capabilities.history.canUndo,getCanRedo:()=>t.capabilities.history.canRedo,getScopeFields:l=>i.getScopeFields(l)},o={subscribe:l=>t.subscriptions.subscribe(l),subscribePersistMeta:l=>Ue({listener:l,subscribeSelector:(c,u,h)=>o.subscribeSelector(c,u,h)}),subscribeHistoryMeta:l=>_e({readHistoryMeta:()=>n.getHistoryMetadata(),subscribeSelector:(c,u,h)=>o.subscribeSelector(c,u,h),listener:l}),subscribeScopeStatus:(l,c)=>Ne({scopeName:l,getScopeFields:u=>n.getScopeFields(u),readScopeStatus:u=>n.getScopeStatus(u),subscribeSelector:(u,h,S)=>o.subscribeSelector(u,h,S),listener:c}),subscribeSelector:(l,c,u)=>je({getState:()=>n.getState(),subscriptions:t.subscriptions,selector:l,listener:c,options:u,trackedSubscriptionsEnabled:!!e.trackedSubscriptions}),subscribePath:(l,c,u)=>He({path:l,listener:c,options:u,subscribeSelector:(h,S,B)=>o.subscribeSelector(h,S,B)}),subscribeFieldState:(l,c)=>ze({path:l,listener:c,getFieldState:u=>n.getFieldState(u),subscribeSelector:(u,h,S)=>o.subscribeSelector(u,h,S)}),subscribeFormMeta:l=>qe({listener:l,subscribeSelector:(c,u,h)=>o.subscribeSelector(c,u,h)})};return{read:n,observe:o,write:{registerField:(l,c)=>{Wt({path:l,config:c,state:t.getState(),fieldRegistry:i,subscriptions:t.subscriptions,stateReader:a,invalidateFieldIndexes:()=>{i.invalidateIndexes()}})},unregisterField:l=>{Kt({path:l,state:t.getState(),hasStaticConfig:!!e.fields?.[l],fieldRegistry:i,subscriptions:t.subscriptions,validationCleanupField:c=>t.capabilities.validation.cleanupField(c),invalidateFieldIndexes:()=>{i.invalidateIndexes()},dispatch:c=>t.dispatch(c)})},unregisterPrefix:l=>{Y({prefix:l,state:t.getState(),fieldRegistry:i,subscriptions:t.subscriptions,validationCleanupPrefix:c=>t.capabilities.validation.cleanupPrefix(c),invalidateFieldIndexes:()=>{i.invalidateIndexes()}})},setField:(l,c)=>{t.runBatch(()=>{t.capabilities.lifecycle.updateField(l,c,{origin:"setField"})})},blurField:l=>{t.capabilities.query.isTouched(l)||t.runBatch(()=>{t.dispatch(Pt([l]))}),t.capabilities.validation.trigger([l])},markFieldsTouched:l=>{l.length!==0&&t.dispatch(Pt(l))},setValues:(l,c)=>{t.capabilities.lifecycle.setValues(l,c)},setError:(l,c)=>{t.capabilities.error.setError(l,c)},setErrors:l=>{t.capabilities.error.setErrors(l)},setServerErrors:l=>{t.capabilities.error.setServerErrors(l)},reset:()=>{t.runBatch(()=>{t.capabilities.lifecycle.reset()})},transaction:l=>t.runBatch(l),submit:l=>t.capabilities.lifecycle.submit(l),pushItem:(l,c)=>t.capabilities.arrays.pushItem(l,c),prependItem:(l,c)=>t.capabilities.arrays.prependItem(l,c),insertItem:(l,c,u)=>t.capabilities.arrays.insertItem(l,c,u),removeItem:(l,c)=>t.capabilities.arrays.removeItem(l,c),swapItems:(l,c,u)=>t.capabilities.arrays.swapItems(l,c,u),moveItem:(l,c,u)=>t.capabilities.arrays.moveItem(l,c,u),replaceItems:(l,c)=>t.capabilities.arrays.replaceItems(l,c),clearItems:l=>t.capabilities.arrays.clearItems(l)},feature:{undo:()=>{Me({history:t.capabilities.history,applyHistoryState:l=>t.capabilities.lifecycle.applyHistoryState(l)})},redo:()=>{Re({history:t.capabilities.history,applyHistoryState:l=>t.capabilities.lifecycle.applyHistoryState(l)})},validate:l=>t.capabilities.validation.validate(l),hasValidationsInProgress:l=>t.capabilities.validation.hasValidationsInProgress(l),triggerValidation:(l,c)=>t.capabilities.validation.trigger(l,c),restorePersisted:()=>we({dispatch:l=>t.dispatch(l),effects:t.effects}),forceSave:()=>De({dispatch:l=>t.dispatch(l),effects:t.effects}),clearPersisted:()=>Ae({dispatch:l=>t.dispatch(l),effects:t.effects}),cleanup:()=>t.cleanup()}}}function We(r){let t=()=>r.read.getState();return{read:{get storeId(){return r.identity.storeId},get config(){return r.identity.config},get isValid(){return r.read.getIsValid()},get isSubmitting(){return r.read.getIsSubmitting()},get isDirty(){return r.read.getIsDirty()},getState:t,getFieldConfig:n=>r.getFieldConfig(n),getFieldState:n=>r.read.getFieldState(n),isHidden:n=>r.read.isHidden(n),isRequired:n=>r.read.isRequired(n),isFieldDirty:n=>r.read.isFieldDirty(n),isFieldValidating:n=>r.read.isFieldValidating(n),getDirtyValues:()=>r.read.getDirtyValues(),getPersistMetadata:()=>r.read.getPersistMetadata(),getHistoryMetadata:()=>r.read.getHistoryMetadata(),getScopeStatus:n=>r.read.getScopeStatus(n),getScopeErrors:n=>r.read.getScopeErrors(n),getScopeFields:n=>r.read.getScopeFields(n)},observe:{getState:t,subscribe:n=>r.observe.subscribe(n),subscribePersistMeta:n=>r.observe.subscribePersistMeta(n),subscribeHistoryMeta:n=>r.observe.subscribeHistoryMeta(n),subscribeScopeStatus:(n,o)=>r.observe.subscribeScopeStatus(n,o),subscribeFormMeta:n=>r.observe.subscribeFormMeta(n),subscribeSelector:(n,o,d)=>r.observe.subscribeSelector(n,o,d),subscribePath:(n,o,d)=>r.observe.subscribePath(n,o,d),subscribeFieldState:(n,o)=>r.observe.subscribeFieldState(n,o)},write:{setField:(n,o)=>r.write.setField(n,o),blurField:n=>r.write.blurField(n),markFieldsTouched:n=>r.write.markFieldsTouched(n),setValues:(n,o)=>r.write.setValues(n,o),setError:(n,o)=>r.write.setError(n,o),setErrors:n=>r.write.setErrors(n),setServerErrors:n=>r.write.setServerErrors(n),reset:()=>r.write.reset(),transaction:n=>r.write.transaction(n),submit:n=>r.write.submit(n)},feature:{cleanup:()=>r.feature.cleanup(),validate:n=>r.feature.validate(n),triggerValidation:(n,o)=>r.feature.triggerValidation(n,o),restorePersisted:()=>r.feature.restorePersisted(),forceSave:()=>r.feature.forceSave(),clearPersisted:()=>r.feature.clearPersisted(),registerField:(n,o)=>r.write.registerField(n,o),unregisterField:n=>r.write.unregisterField(n),unregisterPrefix:n=>r.write.unregisterPrefix(n),pushItem:(n,o)=>r.write.pushItem(n,o),prependItem:(n,o)=>r.write.prependItem(n,o),insertItem:(n,o,d)=>r.write.insertItem(n,o,d),removeItem:(n,o)=>r.write.removeItem(n,o),moveItem:(n,o,d)=>r.write.moveItem(n,o,d),swapItems:(n,o,d)=>r.write.swapItems(n,o,d),replaceItems:(n,o)=>r.write.replaceItems(n,o),clearItems:n=>r.write.clearItems(n),get canUndo(){return r.read.getCanUndo()},get canRedo(){return r.read.getCanRedo()},hasValidationsInProgress:n=>r.feature.hasValidationsInProgress(n),resolveMask:n=>r.resolveMask(n),createArrayItemId:(n,o)=>r.createArrayItemId(n,o),undo:()=>r.feature.undo(),redo:()=>r.feature.redo()}}}var ft=class{constructor(t){this.deps=t}fieldStateCache=new Map;getState(){return this.deps.getState()}getFlag(t){return this.deps.getState()[t]}getPersistMetadata(){return this.deps.getState().persist}getFieldState(t){let e=t,i=this.deps.getState(),s=this.fieldStateCache.get(e),a=m(i.values,e),n=i.errors[e],o=!!i.touched[e],d=this.deps.isHidden(e),p=this.deps.isRequired(e),l=this.deps.isFieldDirty(e),c=this.deps.isFieldValidating(e);if(s){let h=s.snapshot;if(h.value===a&&h.error===n&&h.touched===o&&h.isHidden===d&&h.isRequired===p&&h.isDirty===l&&h.isValidating===c)return h}let u=It({state:i,path:t,value:a,isHidden:d,isRequired:p,isDirty:l,isValidating:c});return this.fieldStateCache.set(e,{state:i,snapshot:u}),u}invalidatePath(t){this.fieldStateCache.delete(t)}};var mt=class{[A]=!0;[D]=!0;storeId;_config;read;observe;write;feature;constructor(t={}){let e=Ve({rawConfig:t});this._config=e.config,this.storeId=e.storeId;let i=new ft({getState:()=>e.runtime.getState(),isHidden:n=>e.runtime.capabilities.query.isHidden(n),isRequired:n=>e.runtime.capabilities.query.isRequired(n),isFieldDirty:n=>e.runtime.capabilities.query.isFieldDirty(n),isFieldValidating:n=>e.runtime.capabilities.query.isFieldValidating(n)}),s=Le({runtime:e.runtime,config:this._config,fieldRegistry:e.fieldRegistry,dirtyManager:e.dirtyManager,stateReader:i}),a=We({identity:{storeId:this.storeId,config:this._config},read:s.read,observe:s.observe,write:s.write,feature:s.feature,getFieldConfig:n=>e.fieldRegistry.getFieldConfig(n),resolveMask:n=>kt({path:n,getFieldConfig:o=>e.fieldRegistry.getFieldConfig(o),masks:e.maskManager.getAllMasks()}),createArrayItemId:(n,o)=>this._config.idFactory({scope:"array",path:n,index:o})});this.read=a.read,this.observe=a.observe,this.write=a.write,this.feature=a.feature,e.runtime.effects.attachStorePort({getState:()=>this.read.getState(),getHistoryMetadata:()=>this.read.getHistoryMetadata(),undo:()=>this.feature.undo(),redo:()=>this.feature.redo(),reset:()=>this.write.reset()})}};function Ke(r={}){return new mt(r)}function $e(r){if(!r||typeof r!="object")return!1;let t=r;return t[A]===!0&&!!t.read&&!!t.observe&&!!t.write&&!!t.feature}function hi(r){if($e(r))return r;throw new Error("BitForm: o store informado n\xE3o exp\xF5e a API necess\xE1ria para hooks/framework bindings.")}function gi(r){return!r||typeof r!="object"?!1:r[D]===!0}function fi(r){if(!$e(r))throw new Error("BitForm: o store informado n\xE3o possui branding de hooks (BIT_HOOKS_API_SYMBOL).");if(!gi(r))throw new Error("BitForm: o store informado n\xE3o possui branding de framework (BIT_FRAMEWORK_STORE_SYMBOL).");return r}function mi(r){return Object.defineProperty(r,A,{value:!0,enumerable:!1,configurable:!1,writable:!1}),Object.defineProperty(r,D,{value:!0,enumerable:!1,configurable:!1,writable:!1}),r}function yi(r={}){let t=Ke(r),e={read:t.read,observe:t.observe,write:t.write,feature:t.feature};return mi(e)}function Si(r){return r.read}function bi(r){return r.observe}function Bi(r){return r.write}function Ti(r){return r.feature}function vi(r,t){let e={};for(let i of t)e[i]=r[i];return e}export{Tt as a,ii as b,hi as c,fi as d,yi as e,Si as f,bi as g,Bi as h,Ti as i,vi as j};
2
- //# sourceMappingURL=chunk-UARLAXZX.js.map