@lehnihon/bit-form 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) 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 +19 -19
  4. package/dist/angular/index.d.ts +19 -19
  5. package/dist/angular/index.js +1 -1
  6. package/dist/angular/index.js.map +1 -1
  7. package/dist/{bus-70e4jnBj.d.cts → bus-B3pGaiFZ.d.cts} +14 -5
  8. package/dist/{bus-70e4jnBj.d.ts → bus-B3pGaiFZ.d.ts} +14 -5
  9. package/dist/chunk-442A4FTZ.cjs +2 -0
  10. package/dist/chunk-442A4FTZ.cjs.map +1 -0
  11. package/dist/chunk-6FJEE6O3.js +133 -0
  12. package/dist/chunk-6FJEE6O3.js.map +1 -0
  13. package/dist/chunk-FOV24ACZ.js +2 -0
  14. package/dist/chunk-FOV24ACZ.js.map +1 -0
  15. package/dist/chunk-YWXX6XRV.cjs +133 -0
  16. package/dist/chunk-YWXX6XRV.cjs.map +1 -0
  17. package/dist/devtools/bridge.cjs +1 -1
  18. package/dist/devtools/bridge.js +1 -1
  19. package/dist/devtools/index.cjs +1 -1
  20. package/dist/devtools/index.js +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +7 -6
  24. package/dist/index.d.ts +7 -6
  25. package/dist/index.js +1 -1
  26. package/dist/public-types-CtYuIAMP.d.cts +99 -0
  27. package/dist/public-types-Lq3eLstW.d.ts +99 -0
  28. package/dist/react/index.cjs +1 -1
  29. package/dist/react/index.d.cts +5 -5
  30. package/dist/react/index.d.ts +5 -5
  31. package/dist/react/index.js +1 -1
  32. package/dist/react-native/index.cjs +1 -1
  33. package/dist/react-native/index.d.cts +4 -4
  34. package/dist/react-native/index.d.ts +4 -4
  35. package/dist/react-native/index.js +1 -1
  36. package/dist/resolvers/joi.d.cts +1 -1
  37. package/dist/resolvers/joi.d.ts +1 -1
  38. package/dist/resolvers/yup.d.cts +1 -1
  39. package/dist/resolvers/yup.d.ts +1 -1
  40. package/dist/resolvers/zod.d.cts +1 -1
  41. package/dist/resolvers/zod.d.ts +1 -1
  42. package/dist/{use-bit-persist-JshPvwwy.d.cts → use-bit-persist-CWzGfovL.d.cts} +19 -23
  43. package/dist/{use-bit-persist-COdNw_fv.d.ts → use-bit-persist-hxJaKG2S.d.ts} +19 -23
  44. package/dist/vue/index.cjs +1 -1
  45. package/dist/vue/index.cjs.map +1 -1
  46. package/dist/vue/index.d.cts +36 -36
  47. package/dist/vue/index.d.ts +36 -36
  48. package/dist/vue/index.js +1 -1
  49. package/dist/vue/index.js.map +1 -1
  50. package/package.json +1 -1
  51. package/dist/chunk-25Q2XJBV.cjs +0 -133
  52. package/dist/chunk-25Q2XJBV.cjs.map +0 -1
  53. package/dist/chunk-2HAQ3QEQ.js +0 -133
  54. package/dist/chunk-2HAQ3QEQ.js.map +0 -1
  55. package/dist/chunk-HTB6QIUQ.js +0 -2
  56. package/dist/chunk-HTB6QIUQ.js.map +0 -1
  57. package/dist/chunk-W22D7QVJ.cjs +0 -2
  58. package/dist/chunk-W22D7QVJ.cjs.map +0 -1
  59. package/dist/public-types-BVZ16kgZ.d.ts +0 -74
  60. package/dist/public-types-r2aP68Gg.d.cts +0 -74
@@ -0,0 +1,99 @@
1
+ import { B as BitConfig, H as ValidatorFn, a as BitMask, m as BitFieldDefinition, J as DevToolsOptions, K as BitPersistResolvedConfig, v as BitPlugin, z as BitState, q as BitPath, n as BitFieldState, r as BitPathValue, G as DeepPartial, i as BitErrors, e as BitArrayPath, d as BitArrayItem, S as ScopeStatus } from './bus-B3pGaiFZ.js';
2
+
3
+ type BitSelector<T extends object, TSlice> = (state: Readonly<BitState<T>>) => TSlice;
4
+ type BitEqualityFn<TValue> = (previous: TValue, next: TValue) => boolean;
5
+ interface BitSelectorSubscriptionOptions<TValue> {
6
+ equalityFn?: BitEqualityFn<TValue>;
7
+ emitImmediately?: boolean;
8
+ }
9
+ interface BitValidationOptions {
10
+ scope?: string;
11
+ scopeFields?: string[];
12
+ }
13
+ interface BitHistoryMetadata {
14
+ enabled: boolean;
15
+ canUndo: boolean;
16
+ canRedo: boolean;
17
+ historyIndex: number;
18
+ historySize: number;
19
+ }
20
+ interface BitPersistMetadata {
21
+ isSaving: boolean;
22
+ isRestoring: boolean;
23
+ error: Error | null;
24
+ }
25
+ interface BitFrameworkConfig<T extends object = any> extends BitConfig<T> {
26
+ initialValues: T;
27
+ resolver?: ValidatorFn<T>;
28
+ validationDelay: number;
29
+ enableHistory: boolean;
30
+ historyLimit: number;
31
+ masks?: Record<string, BitMask>;
32
+ fields?: Record<string, BitFieldDefinition<T>>;
33
+ devTools?: boolean | DevToolsOptions;
34
+ persist: BitPersistResolvedConfig<T>;
35
+ plugins: BitPlugin<T>[];
36
+ }
37
+ interface BitStoreApi<T extends object = any> {
38
+ readonly config: Readonly<BitFrameworkConfig<T>>;
39
+ getConfig(): Readonly<BitFrameworkConfig<T>>;
40
+ getState(): Readonly<BitState<T>>;
41
+ getFieldState<P extends BitPath<T>>(path: P): Readonly<BitFieldState<T, BitPathValue<T, P>>>;
42
+ subscribe(listener: () => void): () => void;
43
+ subscribePath<P extends BitPath<T>>(path: P, listener: (value: BitPathValue<T, P>) => void, options?: BitSelectorSubscriptionOptions<BitPathValue<T, P>>): () => void;
44
+ subscribeSelector<TSlice>(selector: BitSelector<T, TSlice>, listener: (slice: TSlice) => void, options?: BitSelectorSubscriptionOptions<TSlice>): () => void;
45
+ setField<P extends BitPath<T>>(path: P, value: BitPathValue<T, P>): void;
46
+ blurField<P extends BitPath<T>>(path: P): void;
47
+ replaceValues(values: T): void;
48
+ hydrate(values: DeepPartial<T>): void;
49
+ rebase(values: T): void;
50
+ /** @deprecated Use `rebase()` instead. This method is an alias and may be removed in a future version. */
51
+ setValues(values: T): void;
52
+ setError(path: string, message: string | undefined): void;
53
+ setErrors(errors: BitErrors<T>): void;
54
+ setServerErrors(serverErrors: Record<string, string[] | string>): void;
55
+ validate(options?: BitValidationOptions): Promise<boolean>;
56
+ reset(): void;
57
+ submit(onSuccess: (values: T, dirtyValues?: Partial<T>) => void | Promise<void>): Promise<void>;
58
+ registerMask(name: string, mask: BitMask): void;
59
+ getDirtyValues(): Partial<T>;
60
+ restorePersisted(): Promise<boolean>;
61
+ forceSave(): Promise<void>;
62
+ clearPersisted(): Promise<void>;
63
+ cleanup(): void;
64
+ registerField(path: string, config: BitFieldDefinition<T>): void;
65
+ unregisterField(path: string): void;
66
+ unregisterPrefix?(prefix: string): void;
67
+ isHidden<P extends BitPath<T>>(path: P): boolean;
68
+ isRequired<P extends BitPath<T>>(path: P): boolean;
69
+ isFieldDirty(path: string): boolean;
70
+ isFieldValidating(path: string): boolean;
71
+ watch<P extends BitPath<T>>(path: P, callback: (value: BitPathValue<T, P>) => void): () => void;
72
+ pushItem<P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>): void;
73
+ prependItem<P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>): void;
74
+ insertItem<P extends BitArrayPath<T>>(path: P, index: number, value: BitArrayItem<BitPathValue<T, P>>): void;
75
+ removeItem<P extends BitArrayPath<T>>(path: P, index: number): void;
76
+ moveItem<P extends BitArrayPath<T>>(path: P, from: number, to: number): void;
77
+ swapItems<P extends BitArrayPath<T>>(path: P, indexA: number, indexB: number): void;
78
+ getHistoryMetadata(): BitHistoryMetadata;
79
+ undo(): void;
80
+ redo(): void;
81
+ getStepStatus(scopeName: string): ScopeStatus;
82
+ getStepErrors(scopeName: string): Record<string, string>;
83
+ markFieldsTouched(paths: string[]): void;
84
+ hasValidationsInProgress(scopeFields?: string[]): boolean;
85
+ beginFieldValidation(path: string): void;
86
+ endFieldValidation(path: string): void;
87
+ setFieldAsyncError(path: string, message: string): Promise<void>;
88
+ clearFieldAsyncError(path: string): Promise<void>;
89
+ resolveMask(path: string): BitMask | undefined;
90
+ getScopeFields(scopeName: string): string[];
91
+ }
92
+ /** @deprecated Use `BitStoreApi` instead. */
93
+ interface BitPublicStore<T extends object = any> extends BitStoreApi<T> {
94
+ }
95
+ /** @deprecated Use `BitStoreApi` instead. */
96
+ interface BitFrameworkStore<T extends object = any> extends BitStoreApi<T> {
97
+ }
98
+
99
+ export type { BitStoreApi as B, BitEqualityFn as a, BitFrameworkConfig as b, BitFrameworkStore as c, BitHistoryMetadata as d, BitPersistMetadata as e, BitPublicStore as f, BitSelector as g, BitSelectorSubscriptionOptions as h, BitValidationOptions as i };
@@ -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 _chunkW22D7QVJcjs = require('../chunk-W22D7QVJ.cjs');require('../chunk-25Q2XJBV.cjs');var _react = require('react');function f(e){let{fieldState:r,setValue:a,setBlur:t,store:o}=_chunkW22D7QVJcjs.d.call(void 0, e),i=_react.useMemo.call(void 0, ()=>o.resolveMask(e),[o.config.masks,o.config.fields,e]),s=_react.useMemo.call(void 0, ()=>{let n=r.value;return n==null||n===""?"":i?i.format(n):String(n)},[r.value,i]),u=_react.useCallback.call(void 0, n=>{if(!i){a(n);return}a(i.parse(String(_nullishCoalesce(n, () => ("")))))},[i,a]),{isHidden:c,isRequired:l,value:d,error:p,touched:y,isDirty:V,isValidating:b}=r,v=!!(y&&p),h=y?p:void 0,F=_react.useCallback.call(void 0, n=>{let E=_optionalChain([n, 'optionalAccess', _ => _.target])?n.target.value:n;u(E)},[u]),x=_react.useCallback.call(void 0, ()=>{t()},[t]);return{value:d,displayValue:s,setValue:u,setBlur:t,onChange:F,onBlur:x,props:{value:s,onChange:F,onBlur:x},meta:{error:h,touched:y,invalid:v,isDirty:V,isValidating:b,isHidden:c,isRequired:l,hasError:!!p}}}function C(){let e=_chunkW22D7QVJcjs.b.call(void 0, ),r=_react.useRef.call(void 0, null),a=_react.useCallback.call(void 0, ()=>{let s=e.getHistoryMetadata();if(r.current&&r.current.canUndo===s.canUndo&&r.current.canRedo===s.canRedo&&r.current.historyIndex===s.historyIndex&&r.current.historySize===s.historySize)return r.current;let u={canUndo:s.canUndo,canRedo:s.canRedo,historyIndex:s.historyIndex,historySize:s.historySize};return r.current=u,u},[e]),t=_react.useSyncExternalStore.call(void 0, e.subscribe.bind(e),a,a),o=_react.useCallback.call(void 0, ()=>{e.undo()},[e]),i=_react.useCallback.call(void 0, ()=>{e.redo()},[e]);return{...t,undo:o,redo:i}}function j(e,r,a){let t=_chunkW22D7QVJcjs.b.call(void 0, ),o=f(e),i=_react.useRef.call(void 0, null),s=_react.useCallback.call(void 0, async c=>{if(c){t.beginFieldValidation(e),await t.clearFieldAsyncError(e);try{let l=await r(c);o.setValue(l.url),i.current=l.key,await t.clearFieldAsyncError(e)}catch(l){let d=l instanceof Error?l.message:"Upload failed";await t.setFieldAsyncError(e,d)}finally{t.endFieldValidation(e)}}},[r,o,e,t]),u=_react.useCallback.call(void 0, async()=>{let c=i.current;if(c&&a)try{await a(c)}catch(l){let d=l instanceof Error?l.message:"Delete failed";await t.setFieldAsyncError(e,d);return}o.setValue(null),i.current=null,await t.clearFieldAsyncError(e)},[a,o,e,t]);return{value:o.value,setValue:o.setValue,error:_optionalChain([o, 'access', _2 => _2.meta, 'optionalAccess', _3 => _3.error]),isValidating:_optionalChain([o, 'access', _4 => _4.meta, 'optionalAccess', _5 => _5.isValidating])||!1,upload:s,remove:u}}exports.BitFormProvider = _chunkW22D7QVJcjs.a; exports.useBitArray = _chunkW22D7QVJcjs.e; exports.useBitField = f; exports.useBitForm = _chunkW22D7QVJcjs.c; exports.useBitHistory = C; exports.useBitPersist = _chunkW22D7QVJcjs.i; exports.useBitScope = _chunkW22D7QVJcjs.f; exports.useBitSteps = _chunkW22D7QVJcjs.g; exports.useBitStore = _chunkW22D7QVJcjs.b; exports.useBitUpload = j; exports.useBitWatch = _chunkW22D7QVJcjs.h;
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 _chunk442A4FTZcjs = require('../chunk-442A4FTZ.cjs');require('../chunk-YWXX6XRV.cjs');var _react = require('react');function f(e){let{fieldState:r,setValue:a,setBlur:t,store:o}=_chunk442A4FTZcjs.d.call(void 0, e),i=_react.useMemo.call(void 0, ()=>o.resolveMask(e),[o.config.masks,o.config.fields,e]),s=_react.useMemo.call(void 0, ()=>{let n=r.value;return n==null||n===""?"":i?i.format(n):String(n)},[r.value,i]),u=_react.useCallback.call(void 0, n=>{if(!i){a(n);return}a(i.parse(String(_nullishCoalesce(n, () => ("")))))},[i,a]),{isHidden:c,isRequired:l,value:d,error:p,touched:y,isDirty:V,isValidating:b}=r,v=!!(y&&p),h=y?p:void 0,F=_react.useCallback.call(void 0, n=>{let E=_optionalChain([n, 'optionalAccess', _ => _.target])?n.target.value:n;u(E)},[u]),x=_react.useCallback.call(void 0, ()=>{t()},[t]);return{value:d,displayValue:s,setValue:u,setBlur:t,onChange:F,onBlur:x,props:{value:s,onChange:F,onBlur:x},meta:{error:h,touched:y,invalid:v,isDirty:V,isValidating:b,isHidden:c,isRequired:l,hasError:!!p}}}function C(){let e=_chunk442A4FTZcjs.b.call(void 0, ),r=_react.useRef.call(void 0, null),a=_react.useCallback.call(void 0, ()=>{let s=e.getHistoryMetadata();if(r.current&&r.current.canUndo===s.canUndo&&r.current.canRedo===s.canRedo&&r.current.historyIndex===s.historyIndex&&r.current.historySize===s.historySize)return r.current;let u={canUndo:s.canUndo,canRedo:s.canRedo,historyIndex:s.historyIndex,historySize:s.historySize};return r.current=u,u},[e]),t=_react.useSyncExternalStore.call(void 0, e.subscribe.bind(e),a,a),o=_react.useCallback.call(void 0, ()=>{e.undo()},[e]),i=_react.useCallback.call(void 0, ()=>{e.redo()},[e]);return{...t,undo:o,redo:i}}function j(e,r,a){let t=_chunk442A4FTZcjs.b.call(void 0, ),o=f(e),i=_react.useRef.call(void 0, null),s=_react.useCallback.call(void 0, async c=>{if(c){t.beginFieldValidation(e),await t.clearFieldAsyncError(e);try{let l=await r(c);o.setValue(l.url),i.current=l.key,await t.clearFieldAsyncError(e)}catch(l){let d=l instanceof Error?l.message:"Upload failed";await t.setFieldAsyncError(e,d)}finally{t.endFieldValidation(e)}}},[r,o,e,t]),u=_react.useCallback.call(void 0, async()=>{let c=i.current;if(c&&a)try{await a(c)}catch(l){let d=l instanceof Error?l.message:"Delete failed";await t.setFieldAsyncError(e,d);return}o.setValue(null),i.current=null,await t.clearFieldAsyncError(e)},[a,o,e,t]);return{value:o.value,setValue:o.setValue,error:_optionalChain([o, 'access', _2 => _2.meta, 'optionalAccess', _3 => _3.error]),isValidating:_optionalChain([o, 'access', _4 => _4.meta, 'optionalAccess', _5 => _5.isValidating])||!1,upload:s,remove:u}}exports.BitFormProvider = _chunk442A4FTZcjs.a; exports.useBitArray = _chunk442A4FTZcjs.e; exports.useBitField = f; exports.useBitForm = _chunk442A4FTZcjs.c; exports.useBitHistory = C; exports.useBitPersist = _chunk442A4FTZcjs.i; exports.useBitScope = _chunk442A4FTZcjs.f; exports.useBitSteps = _chunk442A4FTZcjs.g; exports.useBitStore = _chunk442A4FTZcjs.b; exports.useBitUpload = j; exports.useBitWatch = _chunk442A4FTZcjs.h;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1,11 +1,11 @@
1
- import { U as UseBitFieldResult, a as UseBitHistoryResult, b as UseBitUploadResult } from '../use-bit-persist-JshPvwwy.cjs';
2
- export { B as BitFormProvider, c as UseBitFieldBindProps, d as UseBitFieldMeta, e as UseBitPersistResult, f as UseBitStepsResult, u as useBitArray, g as useBitForm, h as useBitPersist, i as useBitScope, j as useBitSteps, k as useBitStore, l as useBitWatch } from '../use-bit-persist-JshPvwwy.cjs';
3
- import { p as BitPath } from '../bus-70e4jnBj.cjs';
4
- export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-70e4jnBj.cjs';
1
+ import { U as UseBitFieldResult, a as UseBitHistoryResult, b as UseBitUploadResult } from '../use-bit-persist-CWzGfovL.cjs';
2
+ export { B as BitFormProvider, c as UseBitFieldBindProps, d as UseBitFieldMeta, e as UseBitPersistResult, f as UseBitStepsResult, u as useBitArray, g as useBitForm, h as useBitPersist, i as useBitScope, j as useBitSteps, k as useBitStore, l as useBitWatch } from '../use-bit-persist-CWzGfovL.cjs';
3
+ import { q as BitPath } from '../bus-B3pGaiFZ.cjs';
4
+ export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-B3pGaiFZ.cjs';
5
5
  import { a as BitUploadFn, B as BitDeleteUploadFn } from '../types-C2mpfhp1.cjs';
6
6
  import 'react/jsx-runtime';
7
7
  import 'react';
8
- import '../public-types-r2aP68Gg.cjs';
8
+ import '../public-types-CtYuIAMP.cjs';
9
9
 
10
10
  declare function useBitField<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>>(path: P): UseBitFieldResult<TForm, P>;
11
11
 
@@ -1,11 +1,11 @@
1
- import { U as UseBitFieldResult, a as UseBitHistoryResult, b as UseBitUploadResult } from '../use-bit-persist-COdNw_fv.js';
2
- export { B as BitFormProvider, c as UseBitFieldBindProps, d as UseBitFieldMeta, e as UseBitPersistResult, f as UseBitStepsResult, u as useBitArray, g as useBitForm, h as useBitPersist, i as useBitScope, j as useBitSteps, k as useBitStore, l as useBitWatch } from '../use-bit-persist-COdNw_fv.js';
3
- import { p as BitPath } from '../bus-70e4jnBj.js';
4
- export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-70e4jnBj.js';
1
+ import { U as UseBitFieldResult, a as UseBitHistoryResult, b as UseBitUploadResult } from '../use-bit-persist-hxJaKG2S.js';
2
+ export { B as BitFormProvider, c as UseBitFieldBindProps, d as UseBitFieldMeta, e as UseBitPersistResult, f as UseBitStepsResult, u as useBitArray, g as useBitForm, h as useBitPersist, i as useBitScope, j as useBitSteps, k as useBitStore, l as useBitWatch } from '../use-bit-persist-hxJaKG2S.js';
3
+ import { q as BitPath } from '../bus-B3pGaiFZ.js';
4
+ export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-B3pGaiFZ.js';
5
5
  import { a as BitUploadFn, B as BitDeleteUploadFn } from '../types-C2mpfhp1.js';
6
6
  import 'react/jsx-runtime';
7
7
  import 'react';
8
- import '../public-types-BVZ16kgZ.js';
8
+ import '../public-types-Lq3eLstW.js';
9
9
 
10
10
  declare function useBitField<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>>(path: P): UseBitFieldResult<TForm, P>;
11
11
 
@@ -1,2 +1,2 @@
1
- import{a as M,b as m,c as T,d as R,e as w,f as P,g as k,h as H,i as A}from"../chunk-HTB6QIUQ.js";import"../chunk-2HAQ3QEQ.js";import{useMemo as S,useCallback as B}from"react";function f(e){let{fieldState:r,setValue:a,setBlur:t,store:o}=R(e),i=S(()=>o.resolveMask(e),[o.config.masks,o.config.fields,e]),s=S(()=>{let n=r.value;return n==null||n===""?"":i?i.format(n):String(n)},[r.value,i]),u=B(n=>{if(!i){a(n);return}a(i.parse(String(n??"")))},[i,a]),{isHidden:c,isRequired:l,value:d,error:p,touched:y,isDirty:V,isValidating:b}=r,v=!!(y&&p),h=y?p:void 0,F=B(n=>{let E=n?.target?n.target.value:n;u(E)},[u]),x=B(()=>{t()},[t]);return{value:d,displayValue:s,setValue:u,setBlur:t,onChange:F,onBlur:x,props:{value:s,onChange:F,onBlur:x},meta:{error:h,touched:y,invalid:v,isDirty:V,isValidating:b,isHidden:c,isRequired:l,hasError:!!p}}}import{useCallback as U,useRef as z,useSyncExternalStore as I}from"react";function C(){let e=m(),r=z(null),a=U(()=>{let s=e.getHistoryMetadata();if(r.current&&r.current.canUndo===s.canUndo&&r.current.canRedo===s.canRedo&&r.current.historyIndex===s.historyIndex&&r.current.historySize===s.historySize)return r.current;let u={canUndo:s.canUndo,canRedo:s.canRedo,historyIndex:s.historyIndex,historySize:s.historySize};return r.current=u,u},[e]),t=I(e.subscribe.bind(e),a,a),o=U(()=>{e.undo()},[e]),i=U(()=>{e.redo()},[e]);return{...t,undo:o,redo:i}}import{useCallback as g,useRef as D}from"react";function j(e,r,a){let t=m(),o=f(e),i=D(null),s=g(async c=>{if(c){t.beginFieldValidation(e),await t.clearFieldAsyncError(e);try{let l=await r(c);o.setValue(l.url),i.current=l.key,await t.clearFieldAsyncError(e)}catch(l){let d=l instanceof Error?l.message:"Upload failed";await t.setFieldAsyncError(e,d)}finally{t.endFieldValidation(e)}}},[r,o,e,t]),u=g(async()=>{let c=i.current;if(c&&a)try{await a(c)}catch(l){let d=l instanceof Error?l.message:"Delete failed";await t.setFieldAsyncError(e,d);return}o.setValue(null),i.current=null,await t.clearFieldAsyncError(e)},[a,o,e,t]);return{value:o.value,setValue:o.setValue,error:o.meta?.error,isValidating:o.meta?.isValidating||!1,upload:s,remove:u}}export{M as BitFormProvider,w as useBitArray,f as useBitField,T as useBitForm,C as useBitHistory,A as useBitPersist,P as useBitScope,k as useBitSteps,m as useBitStore,j as useBitUpload,H as useBitWatch};
1
+ import{a as M,b as m,c as T,d as R,e as w,f as P,g as k,h as H,i as A}from"../chunk-FOV24ACZ.js";import"../chunk-6FJEE6O3.js";import{useMemo as S,useCallback as B}from"react";function f(e){let{fieldState:r,setValue:a,setBlur:t,store:o}=R(e),i=S(()=>o.resolveMask(e),[o.config.masks,o.config.fields,e]),s=S(()=>{let n=r.value;return n==null||n===""?"":i?i.format(n):String(n)},[r.value,i]),u=B(n=>{if(!i){a(n);return}a(i.parse(String(n??"")))},[i,a]),{isHidden:c,isRequired:l,value:d,error:p,touched:y,isDirty:V,isValidating:b}=r,v=!!(y&&p),h=y?p:void 0,F=B(n=>{let E=n?.target?n.target.value:n;u(E)},[u]),x=B(()=>{t()},[t]);return{value:d,displayValue:s,setValue:u,setBlur:t,onChange:F,onBlur:x,props:{value:s,onChange:F,onBlur:x},meta:{error:h,touched:y,invalid:v,isDirty:V,isValidating:b,isHidden:c,isRequired:l,hasError:!!p}}}import{useCallback as U,useRef as z,useSyncExternalStore as I}from"react";function C(){let e=m(),r=z(null),a=U(()=>{let s=e.getHistoryMetadata();if(r.current&&r.current.canUndo===s.canUndo&&r.current.canRedo===s.canRedo&&r.current.historyIndex===s.historyIndex&&r.current.historySize===s.historySize)return r.current;let u={canUndo:s.canUndo,canRedo:s.canRedo,historyIndex:s.historyIndex,historySize:s.historySize};return r.current=u,u},[e]),t=I(e.subscribe.bind(e),a,a),o=U(()=>{e.undo()},[e]),i=U(()=>{e.redo()},[e]);return{...t,undo:o,redo:i}}import{useCallback as g,useRef as D}from"react";function j(e,r,a){let t=m(),o=f(e),i=D(null),s=g(async c=>{if(c){t.beginFieldValidation(e),await t.clearFieldAsyncError(e);try{let l=await r(c);o.setValue(l.url),i.current=l.key,await t.clearFieldAsyncError(e)}catch(l){let d=l instanceof Error?l.message:"Upload failed";await t.setFieldAsyncError(e,d)}finally{t.endFieldValidation(e)}}},[r,o,e,t]),u=g(async()=>{let c=i.current;if(c&&a)try{await a(c)}catch(l){let d=l instanceof Error?l.message:"Delete failed";await t.setFieldAsyncError(e,d);return}o.setValue(null),i.current=null,await t.clearFieldAsyncError(e)},[a,o,e,t]);return{value:o.value,setValue:o.setValue,error:o.meta?.error,isValidating:o.meta?.isValidating||!1,upload:s,remove:u}}export{M as BitFormProvider,w as useBitArray,f as useBitField,T as useBitForm,C as useBitHistory,A as useBitPersist,P as useBitScope,k as useBitSteps,m as useBitStore,j as useBitUpload,H as useBitWatch};
2
2
  //# sourceMappingURL=index.js.map
@@ -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(); } }var _chunkW22D7QVJcjs = require('../chunk-W22D7QVJ.cjs');require('../chunk-25Q2XJBV.cjs');var _react = require('react');function M(o){let{fieldState:i,setValue:r,setBlur:s,store:a}=_chunkW22D7QVJcjs.d.call(void 0, o),t=_react.useMemo.call(void 0, ()=>a.resolveMask(o),[a.config.masks,a.config.fields,o]),m=_react.useMemo.call(void 0, ()=>{let e=i.value;return e==null||e===""?"":t?t.format(e):String(e)},[i.value,t]),p=_react.useCallback.call(void 0, e=>{if(!t){r(e);return}r(t.parse(String(_nullishCoalesce(e, () => ("")))))},[t,r]),c=_react.useCallback.call(void 0, e=>{if(!t){r(e);return}r(t.parse(String(_nullishCoalesce(e, () => ("")))))},[t,r]),{isHidden:F,isRequired:P,value:v,error:n,touched:u,isDirty:x,isValidating:y}=i,g=!!(u&&n),h=u?n:void 0,d=_react.useCallback.call(void 0, ()=>{s()},[s]);return{value:v,displayValue:m,setValue:c,setBlur:s,onChangeText:p,onBlur:d,meta:{error:h,touched:u,invalid:g,isValidating:y,isDirty:x,isHidden:F,isRequired:P,hasError:!!n},props:{value:m,onChangeText:p,onBlur:d}}}exports.BitFormProvider = _chunkW22D7QVJcjs.a; exports.useBitArray = _chunkW22D7QVJcjs.e; exports.useBitField = M; exports.useBitForm = _chunkW22D7QVJcjs.c; exports.useBitPersist = _chunkW22D7QVJcjs.i; exports.useBitScope = _chunkW22D7QVJcjs.f; exports.useBitSteps = _chunkW22D7QVJcjs.g; exports.useBitStore = _chunkW22D7QVJcjs.b; exports.useBitWatch = _chunkW22D7QVJcjs.h;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunk442A4FTZcjs = require('../chunk-442A4FTZ.cjs');require('../chunk-YWXX6XRV.cjs');var _react = require('react');function M(o){let{fieldState:i,setValue:r,setBlur:s,store:a}=_chunk442A4FTZcjs.d.call(void 0, o),t=_react.useMemo.call(void 0, ()=>a.resolveMask(o),[a.config.masks,a.config.fields,o]),m=_react.useMemo.call(void 0, ()=>{let e=i.value;return e==null||e===""?"":t?t.format(e):String(e)},[i.value,t]),p=_react.useCallback.call(void 0, e=>{if(!t){r(e);return}r(t.parse(String(_nullishCoalesce(e, () => ("")))))},[t,r]),c=_react.useCallback.call(void 0, e=>{if(!t){r(e);return}r(t.parse(String(_nullishCoalesce(e, () => ("")))))},[t,r]),{isHidden:F,isRequired:P,value:v,error:n,touched:u,isDirty:x,isValidating:y}=i,g=!!(u&&n),h=u?n:void 0,d=_react.useCallback.call(void 0, ()=>{s()},[s]);return{value:v,displayValue:m,setValue:c,setBlur:s,onChangeText:p,onBlur:d,meta:{error:h,touched:u,invalid:g,isValidating:y,isDirty:x,isHidden:F,isRequired:P,hasError:!!n},props:{value:m,onChangeText:p,onBlur:d}}}exports.BitFormProvider = _chunk442A4FTZcjs.a; exports.useBitArray = _chunk442A4FTZcjs.e; exports.useBitField = M; exports.useBitForm = _chunk442A4FTZcjs.c; exports.useBitPersist = _chunk442A4FTZcjs.i; exports.useBitScope = _chunk442A4FTZcjs.f; exports.useBitSteps = _chunk442A4FTZcjs.g; exports.useBitStore = _chunk442A4FTZcjs.b; exports.useBitWatch = _chunk442A4FTZcjs.h;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1,9 +1,9 @@
1
- export { B as BitFormProvider, e as UseBitPersistResult, u as useBitArray, g as useBitForm, h as useBitPersist, i as useBitScope, j as useBitSteps, k as useBitStore, l as useBitWatch } from '../use-bit-persist-JshPvwwy.cjs';
2
- import { p as BitPath, q as BitPathValue } from '../bus-70e4jnBj.cjs';
3
- export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-70e4jnBj.cjs';
1
+ export { B as BitFormProvider, e as UseBitPersistResult, u as useBitArray, g as useBitForm, h as useBitPersist, i as useBitScope, j as useBitSteps, k as useBitStore, l as useBitWatch } from '../use-bit-persist-CWzGfovL.cjs';
2
+ import { q as BitPath, r as BitPathValue } from '../bus-B3pGaiFZ.cjs';
3
+ export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-B3pGaiFZ.cjs';
4
4
  import 'react/jsx-runtime';
5
5
  import 'react';
6
- import '../public-types-r2aP68Gg.cjs';
6
+ import '../public-types-CtYuIAMP.cjs';
7
7
 
8
8
  /**
9
9
  * Metadata describing the current state of a form field (React Native).
@@ -1,9 +1,9 @@
1
- export { B as BitFormProvider, e as UseBitPersistResult, u as useBitArray, g as useBitForm, h as useBitPersist, i as useBitScope, j as useBitSteps, k as useBitStore, l as useBitWatch } from '../use-bit-persist-COdNw_fv.js';
2
- import { p as BitPath, q as BitPathValue } from '../bus-70e4jnBj.js';
3
- export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-70e4jnBj.js';
1
+ export { B as BitFormProvider, e as UseBitPersistResult, u as useBitArray, g as useBitForm, h as useBitPersist, i as useBitScope, j as useBitSteps, k as useBitStore, l as useBitWatch } from '../use-bit-persist-hxJaKG2S.js';
2
+ import { q as BitPath, r as BitPathValue } from '../bus-B3pGaiFZ.js';
3
+ export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-B3pGaiFZ.js';
4
4
  import 'react/jsx-runtime';
5
5
  import 'react';
6
- import '../public-types-BVZ16kgZ.js';
6
+ import '../public-types-Lq3eLstW.js';
7
7
 
8
8
  /**
9
9
  * Metadata describing the current state of a form field (React Native).
@@ -1,2 +1,2 @@
1
- import{a as S,b as T,c as V,d as B,e as R,f as U,g as N,h as k,i as C}from"../chunk-HTB6QIUQ.js";import"../chunk-2HAQ3QEQ.js";import{useMemo as f,useCallback as l}from"react";function M(o){let{fieldState:i,setValue:r,setBlur:s,store:a}=B(o),t=f(()=>a.resolveMask(o),[a.config.masks,a.config.fields,o]),m=f(()=>{let e=i.value;return e==null||e===""?"":t?t.format(e):String(e)},[i.value,t]),p=l(e=>{if(!t){r(e);return}r(t.parse(String(e??"")))},[t,r]),c=l(e=>{if(!t){r(e);return}r(t.parse(String(e??"")))},[t,r]),{isHidden:F,isRequired:P,value:v,error:n,touched:u,isDirty:x,isValidating:y}=i,g=!!(u&&n),h=u?n:void 0,d=l(()=>{s()},[s]);return{value:v,displayValue:m,setValue:c,setBlur:s,onChangeText:p,onBlur:d,meta:{error:h,touched:u,invalid:g,isValidating:y,isDirty:x,isHidden:F,isRequired:P,hasError:!!n},props:{value:m,onChangeText:p,onBlur:d}}}export{S as BitFormProvider,R as useBitArray,M as useBitField,V as useBitForm,C as useBitPersist,U as useBitScope,N as useBitSteps,T as useBitStore,k as useBitWatch};
1
+ import{a as S,b as T,c as V,d as B,e as R,f as U,g as N,h as k,i as C}from"../chunk-FOV24ACZ.js";import"../chunk-6FJEE6O3.js";import{useMemo as f,useCallback as l}from"react";function M(o){let{fieldState:i,setValue:r,setBlur:s,store:a}=B(o),t=f(()=>a.resolveMask(o),[a.config.masks,a.config.fields,o]),m=f(()=>{let e=i.value;return e==null||e===""?"":t?t.format(e):String(e)},[i.value,t]),p=l(e=>{if(!t){r(e);return}r(t.parse(String(e??"")))},[t,r]),c=l(e=>{if(!t){r(e);return}r(t.parse(String(e??"")))},[t,r]),{isHidden:F,isRequired:P,value:v,error:n,touched:u,isDirty:x,isValidating:y}=i,g=!!(u&&n),h=u?n:void 0,d=l(()=>{s()},[s]);return{value:v,displayValue:m,setValue:c,setBlur:s,onChangeText:p,onBlur:d,meta:{error:h,touched:u,invalid:g,isValidating:y,isDirty:x,isHidden:F,isRequired:P,hasError:!!n},props:{value:m,onChangeText:p,onBlur:d}}}export{S as BitFormProvider,R as useBitArray,M as useBitField,V as useBitForm,C as useBitPersist,U as useBitScope,N as useBitSteps,T as useBitStore,k as useBitWatch};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import { ObjectSchema } from 'joi';
2
- import { i as BitErrors } from '../bus-70e4jnBj.cjs';
2
+ import { i as BitErrors } from '../bus-B3pGaiFZ.cjs';
3
3
 
4
4
  declare const joiResolver: <T extends object>(schema: ObjectSchema<T>) => (values: T, options?: {
5
5
  scopeFields?: string[];
@@ -1,5 +1,5 @@
1
1
  import { ObjectSchema } from 'joi';
2
- import { i as BitErrors } from '../bus-70e4jnBj.js';
2
+ import { i as BitErrors } from '../bus-B3pGaiFZ.js';
3
3
 
4
4
  declare const joiResolver: <T extends object>(schema: ObjectSchema<T>) => (values: T, options?: {
5
5
  scopeFields?: string[];
@@ -1,5 +1,5 @@
1
1
  import { Schema } from 'yup';
2
- import { i as BitErrors } from '../bus-70e4jnBj.cjs';
2
+ import { i as BitErrors } from '../bus-B3pGaiFZ.cjs';
3
3
 
4
4
  declare const yupResolver: <T extends object>(schema: Schema<any>) => (values: T, options?: {
5
5
  scopeFields?: string[];
@@ -1,5 +1,5 @@
1
1
  import { Schema } from 'yup';
2
- import { i as BitErrors } from '../bus-70e4jnBj.js';
2
+ import { i as BitErrors } from '../bus-B3pGaiFZ.js';
3
3
 
4
4
  declare const yupResolver: <T extends object>(schema: Schema<any>) => (values: T, options?: {
5
5
  scopeFields?: string[];
@@ -1,5 +1,5 @@
1
1
  import { ZodSchema } from 'zod';
2
- import { i as BitErrors } from '../bus-70e4jnBj.cjs';
2
+ import { i as BitErrors } from '../bus-B3pGaiFZ.cjs';
3
3
 
4
4
  declare const zodResolver: <T extends object>(schema: ZodSchema<T>) => (values: T, options?: {
5
5
  scopeFields?: string[];
@@ -1,5 +1,5 @@
1
1
  import { ZodSchema } from 'zod';
2
- import { i as BitErrors } from '../bus-70e4jnBj.js';
2
+ import { i as BitErrors } from '../bus-B3pGaiFZ.js';
3
3
 
4
4
  declare const zodResolver: <T extends object>(schema: ZodSchema<T>) => (values: T, options?: {
5
5
  scopeFields?: string[];
@@ -1,13 +1,13 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
- import { b as BitFrameworkStore } from './public-types-r2aP68Gg.cjs';
4
- import { i as BitErrors, z as BitTouched, p as BitPath, q as BitPathValue, S as ScopeStatus, V as ValidateScopeResult, e as BitArrayPath, d as BitArrayItem } from './bus-70e4jnBj.cjs';
3
+ import { B as BitStoreApi, i as BitValidationOptions, d as BitHistoryMetadata, e as BitPersistMetadata } from './public-types-CtYuIAMP.cjs';
4
+ import { i as BitErrors, A as BitTouched, q as BitPath, r as BitPathValue, G as DeepPartial, e as BitArrayPath, d as BitArrayItem, S as ScopeStatus, V as ValidateScopeResult } from './bus-B3pGaiFZ.cjs';
5
5
 
6
6
  declare const BitFormProvider: ({ store, children, }: {
7
- store: BitFrameworkStore<any>;
7
+ store: BitStoreApi<any>;
8
8
  children: React.ReactNode;
9
9
  }) => react_jsx_runtime.JSX.Element;
10
- declare const useBitStore: <T extends object>() => BitFrameworkStore<T>;
10
+ declare const useBitStore: <T extends object>() => BitStoreApi<T>;
11
11
 
12
12
  declare function useBitForm<T extends object>(): {
13
13
  meta: {
@@ -30,21 +30,21 @@ declare function useBitForm<T extends object>(): {
30
30
  reset: () => void;
31
31
  setField: <P extends BitPath<T, "">>(path: P, value: BitPathValue<T, P>) => void;
32
32
  blurField: <P extends BitPath<T, "">>(path: P) => void;
33
+ replaceValues: (values: T) => void;
34
+ hydrate: (values: DeepPartial<T>) => void;
35
+ rebase: (values: T) => void;
33
36
  setValues: (values: T) => void;
34
37
  setError: (path: string, message: string | undefined) => void;
35
38
  setErrors: (errors: BitErrors<T>) => void;
36
39
  setServerErrors: (serverErrors: Record<string, string[] | string>) => void;
37
- validate: (options?: {
38
- scope?: string;
39
- scopeFields?: string[];
40
- }) => Promise<boolean>;
40
+ validate: (options?: BitValidationOptions) => Promise<boolean>;
41
41
  mutations: {
42
- pushItem: (path: any, value: any) => void;
43
- removeItem: (path: any, index: number) => void;
44
- prependItem: (path: any, value: any) => void;
45
- insertItem: (path: any, index: number, value: any) => void;
46
- moveItem: (path: any, from: number, to: number) => void;
47
- swapItems: (path: any, indexA: number, indexB: number) => void;
42
+ pushItem: <P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>) => void;
43
+ removeItem: <P extends BitArrayPath<T>>(path: P, index: number) => void;
44
+ prependItem: <P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>) => void;
45
+ insertItem: <P extends BitArrayPath<T>>(path: P, index: number, value: BitArrayItem<BitPathValue<T, P>>) => void;
46
+ moveItem: <P extends BitArrayPath<T>>(path: P, from: number, to: number) => void;
47
+ swapItems: <P extends BitArrayPath<T>>(path: P, indexA: number, indexB: number) => void;
48
48
  };
49
49
  };
50
50
 
@@ -120,10 +120,10 @@ interface UseBitUploadResult {
120
120
  * Provides form history undo/redo capabilities.
121
121
  */
122
122
  interface UseBitHistoryResult {
123
- canUndo: boolean;
124
- canRedo: boolean;
125
- historyIndex: number;
126
- historySize: number;
123
+ canUndo: BitHistoryMetadata["canUndo"];
124
+ canRedo: BitHistoryMetadata["canRedo"];
125
+ historyIndex: BitHistoryMetadata["historyIndex"];
126
+ historySize: BitHistoryMetadata["historySize"];
127
127
  undo: () => void;
128
128
  redo: () => void;
129
129
  }
@@ -131,11 +131,7 @@ interface UseBitPersistResult {
131
131
  restore: () => Promise<boolean>;
132
132
  save: () => Promise<void>;
133
133
  clear: () => Promise<void>;
134
- meta: {
135
- isSaving: boolean;
136
- isRestoring: boolean;
137
- error: Error | null;
138
- };
134
+ meta: BitPersistMetadata;
139
135
  }
140
136
 
141
137
  declare function useBitArray<TForm extends object = any, P extends BitArrayPath<TForm> = BitArrayPath<TForm>>(path: P): {
@@ -1,13 +1,13 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
- import { b as BitFrameworkStore } from './public-types-BVZ16kgZ.js';
4
- import { i as BitErrors, z as BitTouched, p as BitPath, q as BitPathValue, S as ScopeStatus, V as ValidateScopeResult, e as BitArrayPath, d as BitArrayItem } from './bus-70e4jnBj.js';
3
+ import { B as BitStoreApi, i as BitValidationOptions, d as BitHistoryMetadata, e as BitPersistMetadata } from './public-types-Lq3eLstW.js';
4
+ import { i as BitErrors, A as BitTouched, q as BitPath, r as BitPathValue, G as DeepPartial, e as BitArrayPath, d as BitArrayItem, S as ScopeStatus, V as ValidateScopeResult } from './bus-B3pGaiFZ.js';
5
5
 
6
6
  declare const BitFormProvider: ({ store, children, }: {
7
- store: BitFrameworkStore<any>;
7
+ store: BitStoreApi<any>;
8
8
  children: React.ReactNode;
9
9
  }) => react_jsx_runtime.JSX.Element;
10
- declare const useBitStore: <T extends object>() => BitFrameworkStore<T>;
10
+ declare const useBitStore: <T extends object>() => BitStoreApi<T>;
11
11
 
12
12
  declare function useBitForm<T extends object>(): {
13
13
  meta: {
@@ -30,21 +30,21 @@ declare function useBitForm<T extends object>(): {
30
30
  reset: () => void;
31
31
  setField: <P extends BitPath<T, "">>(path: P, value: BitPathValue<T, P>) => void;
32
32
  blurField: <P extends BitPath<T, "">>(path: P) => void;
33
+ replaceValues: (values: T) => void;
34
+ hydrate: (values: DeepPartial<T>) => void;
35
+ rebase: (values: T) => void;
33
36
  setValues: (values: T) => void;
34
37
  setError: (path: string, message: string | undefined) => void;
35
38
  setErrors: (errors: BitErrors<T>) => void;
36
39
  setServerErrors: (serverErrors: Record<string, string[] | string>) => void;
37
- validate: (options?: {
38
- scope?: string;
39
- scopeFields?: string[];
40
- }) => Promise<boolean>;
40
+ validate: (options?: BitValidationOptions) => Promise<boolean>;
41
41
  mutations: {
42
- pushItem: (path: any, value: any) => void;
43
- removeItem: (path: any, index: number) => void;
44
- prependItem: (path: any, value: any) => void;
45
- insertItem: (path: any, index: number, value: any) => void;
46
- moveItem: (path: any, from: number, to: number) => void;
47
- swapItems: (path: any, indexA: number, indexB: number) => void;
42
+ pushItem: <P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>) => void;
43
+ removeItem: <P extends BitArrayPath<T>>(path: P, index: number) => void;
44
+ prependItem: <P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>) => void;
45
+ insertItem: <P extends BitArrayPath<T>>(path: P, index: number, value: BitArrayItem<BitPathValue<T, P>>) => void;
46
+ moveItem: <P extends BitArrayPath<T>>(path: P, from: number, to: number) => void;
47
+ swapItems: <P extends BitArrayPath<T>>(path: P, indexA: number, indexB: number) => void;
48
48
  };
49
49
  };
50
50
 
@@ -120,10 +120,10 @@ interface UseBitUploadResult {
120
120
  * Provides form history undo/redo capabilities.
121
121
  */
122
122
  interface UseBitHistoryResult {
123
- canUndo: boolean;
124
- canRedo: boolean;
125
- historyIndex: number;
126
- historySize: number;
123
+ canUndo: BitHistoryMetadata["canUndo"];
124
+ canRedo: BitHistoryMetadata["canRedo"];
125
+ historyIndex: BitHistoryMetadata["historyIndex"];
126
+ historySize: BitHistoryMetadata["historySize"];
127
127
  undo: () => void;
128
128
  redo: () => void;
129
129
  }
@@ -131,11 +131,7 @@ interface UseBitPersistResult {
131
131
  restore: () => Promise<boolean>;
132
132
  save: () => Promise<void>;
133
133
  clear: () => Promise<void>;
134
- meta: {
135
- isSaving: boolean;
136
- isRestoring: boolean;
137
- error: Error | null;
138
- };
134
+ meta: BitPersistMetadata;
139
135
  }
140
136
 
141
137
  declare function useBitArray<TForm extends object = any, P extends BitArrayPath<TForm> = BitArrayPath<TForm>>(path: P): {
@@ -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 _chunk25Q2XJBVcjs = require('../chunk-25Q2XJBV.cjs');var _vue = require('vue');var H=Symbol("BIT_STORE");function $(e){_vue.provide.call(void 0, H,e)}function l(){let e=_vue.inject.call(void 0, H);if(!e)throw new Error("BitForm Vue hooks devem ser usados sob um provideBitStore");return e}function G(){let e=l(),t=_vue.shallowRef.call(void 0, e.getState()),o=_vue.ref.call(void 0, null),r=_vue.ref.call(void 0, null),n=e.subscribe(()=>{t.value={...e.getState()}});_vue.onUnmounted.call(void 0, n);let i=()=>t.value.values,f=()=>t.value.errors,u=()=>t.value.touched,v=()=>e.getDirtyValues(),s=_vue.computed.call(void 0, ()=>t.value.isValid),a=_vue.computed.call(void 0, ()=>t.value.isSubmitting),c=_vue.computed.call(void 0, ()=>t.value.isDirty);return{meta:{isValid:s,isDirty:c,isSubmitting:a,submitError:o,lastResponse:r},getValues:i,getErrors:f,getTouched:u,getDirtyValues:v,submit:S=>B=>(_optionalChain([B, 'optionalAccess', _2 => _2.preventDefault, 'optionalCall', _3 => _3()]),e.submit(S)),onSubmit:S=>B=>(_optionalChain([B, 'optionalAccess', _4 => _4.preventDefault, 'optionalCall', _5 => _5()]),o.value=null,e.submit(async(F,m)=>{try{let d=await S(F,m);r.value=d,o.value=null}catch(d){_chunk25Q2XJBVcjs.h.call(void 0, d)?e.setServerErrors(_chunk25Q2XJBVcjs.i.call(void 0, d)):o.value=d instanceof Error?d:new Error(String(d))}})),reset:()=>{e.reset(),o.value=null,r.value=null},setValues:e.setValues.bind(e),setError:e.setError.bind(e),setErrors:e.setErrors.bind(e),setServerErrors:e.setServerErrors.bind(e),setField:e.setField.bind(e),blurField:e.blurField.bind(e),validate:e.validate.bind(e),mutations:{pushItem:e.pushItem.bind(e),prependItem:e.prependItem.bind(e),removeItem:e.removeItem.bind(e),insertItem:e.insertItem.bind(e),moveItem:e.moveItem.bind(e),swapItems:e.swapItems.bind(e)}}}function T(e){let t=l(),o=t.resolveMask(e),r=_vue.shallowRef.call(void 0, t.getState()),n=t.subscribe(()=>{r.value=t.getState()});_vue.onUnmounted.call(void 0, ()=>{n(),t.unregisterField&&t.unregisterField(e)});let i=_vue.computed.call(void 0, ()=>_chunk25Q2XJBVcjs.e.call(void 0, r.value.values,e)),f=_vue.computed.call(void 0, ()=>{let p=i.value;return p==null||p===""?"":o?o.format(p):String(p)}),u=_vue.computed.call(void 0, {get:()=>f.value,set:p=>{if(!o){t.setField(e,p);return}t.setField(e,o.parse(String(_nullishCoalesce(p, () => ("")))))}}),v=_vue.computed.call(void 0, ()=>r.value.errors[e]),s=_vue.computed.call(void 0, ()=>r.value.touched[e]?r.value.errors[e]:void 0),a=_vue.computed.call(void 0, ()=>!!r.value.touched[e]),c=_vue.computed.call(void 0, ()=>!!(a.value&&s.value)),g=_vue.computed.call(void 0, ()=>(r.value,t.isFieldValidating(e))),I=_vue.computed.call(void 0, ()=>(r.value,t.isFieldDirty(e))),w=_vue.computed.call(void 0, ()=>(r.value,t.isHidden(e))),S=_vue.computed.call(void 0, ()=>(r.value,t.isRequired(e))),B=_vue.computed.call(void 0, ()=>!!v.value),F=p=>{u.value=p},m=()=>t.blurField(e);return{value:i,displayValue:f,modelValue:u,setValue:F,setBlur:m,onInput:p=>{F(p)},onBlur:()=>{m()},meta:{error:s,touched:a,invalid:c,isValidating:g,isDirty:I,isHidden:w,isRequired:S,hasError:B}}}var E=()=>Math.random().toString(36).substring(2,9);function Z(e){let t=l(),o=()=>{let s=_chunk25Q2XJBVcjs.e.call(void 0, t.getState().values,e);return Array.isArray(s)?s:[]},r=o(),n=_vue.ref.call(void 0, r),i=_vue.ref.call(void 0, r.map(E)),f=t.subscribe(()=>{let s=o();if(n.value=[...s],s.length!==i.value.length){let a=[...i.value];if(s.length>a.length){let c=s.length-a.length,g=Array.from({length:c},E);i.value=[...a,...g]}else i.value=a.slice(0,s.length)}});_vue.onUnmounted.call(void 0, ()=>{f(),t.unregisterPrefix&&t.unregisterPrefix(`${e}.`)});let u=_vue.computed.call(void 0, ()=>n.value.map((s,a)=>({key:i.value[a]||`temp-${a}`,value:s,index:a}))),v=_vue.computed.call(void 0, ()=>n.value.length);return{fields:u,length:v,append:s=>{i.value.push(E()),t.pushItem(e,s)},prepend:s=>{i.value.unshift(E()),t.prependItem(e,s)},insert:(s,a)=>{i.value.splice(s,0,E()),t.insertItem(e,s,a)},remove:s=>{i.value.splice(s,1),t.removeItem(e,s)},move:(s,a)=>{let c=[...i.value],[g]=c.splice(s,1);c.splice(a,0,g),i.value=c,t.moveItem(e,s,a)},swap:(s,a)=>{let c=[...i.value];[c[s],c[a]]=[c[a],c[s]],i.value=c,t.swapItems(e,s,a)},replace:s=>{i.value=s.map(E),t.setField(e,s)},clear:()=>{i.value=[],t.setField(e,[])}}}function te(){let e=l(),t=_vue.shallowRef.call(void 0, e.getHistoryMetadata()),o=e.subscribe(()=>{t.value=e.getHistoryMetadata()});_vue.onUnmounted.call(void 0, o);let r=()=>e.undo(),n=()=>e.redo();return{canUndo:_vue.computed.call(void 0, ()=>t.value.canUndo),canRedo:_vue.computed.call(void 0, ()=>t.value.canRedo),historyIndex:_vue.computed.call(void 0, ()=>t.value.historyIndex),historySize:_vue.computed.call(void 0, ()=>t.value.historySize),undo:r,redo:n}}function ne(e,t){let o=Object.keys(e),r=Object.keys(t);return o.length!==r.length?!1:o.every(n=>e[n]===t[n])}function ie(e){let t=l(),o=_vue.ref.call(void 0, t.getStepStatus(e)),r;_vue.onMounted.call(void 0, ()=>{r=t.subscribe(()=>{let s=t.getStepStatus(e);(s.hasErrors!==o.value.hasErrors||s.isDirty!==o.value.isDirty||!ne(s.errors,o.value.errors))&&(o.value=s)})}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([r, 'optionalCall', _6 => _6()])});let n=async()=>{let s=await t.validate({scope:e}),a=t.getStepErrors(e);return{valid:s,errors:a}},i=()=>t.getStepErrors(e),f=_vue.computed.call(void 0, ()=>!o.value.hasErrors),u=_vue.computed.call(void 0, ()=>o.value.isDirty),v=_vue.computed.call(void 0, ()=>o.value.errors);return{scopeName:e,status:o,errors:v,validate:n,getErrors:i,isValid:f,isDirty:u}}function ce(e,t){let o=Object.keys(e),r=Object.keys(t);return o.length!==r.length?!1:o.every(n=>e[n]===t[n])}function me(e){let t=l(),o=_vue.ref.call(void 0, 0),r=_vue.computed.call(void 0, ()=>_nullishCoalesce(e[o.value], () => (""))),n=_vue.ref.call(void 0, t.getStepStatus(r.value)),i;_vue.watch.call(void 0, r,m=>{n.value=t.getStepStatus(m)});let f=()=>{let m=r.value,d=t.getStepStatus(m);(d.hasErrors!==n.value.hasErrors||d.isDirty!==n.value.isDirty||!ce(d.errors,n.value.errors))&&(n.value=d)};_vue.onMounted.call(void 0, ()=>{i=t.subscribe(f)}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([i, 'optionalCall', _7 => _7()])});let u=async()=>{let m=r.value,d=await t.validate({scope:m}),h=t.getStepErrors(m);return{valid:d,errors:h}},v=()=>t.getStepErrors(r.value),s=async()=>{let m=r.value,d=t.getScopeFields(m);if(t.hasValidationsInProgress(d))return!1;let h=await t.validate({scope:m});if(h)o.value=Math.min(o.value+1,e.length-1);else{let p=t.getStepErrors(m),k=Object.keys(p);k.length>0&&t.markFieldsTouched(k)}return h},a=()=>{o.value=Math.max(o.value-1,0)},c=m=>{o.value=Math.max(0,Math.min(m-1,e.length-1))},g=_vue.computed.call(void 0, ()=>o.value+1),I=_vue.computed.call(void 0, ()=>o.value===0),w=_vue.computed.call(void 0, ()=>o.value>=e.length-1),S=_vue.computed.call(void 0, ()=>!n.value.hasErrors),B=_vue.computed.call(void 0, ()=>n.value.isDirty),F=_vue.computed.call(void 0, ()=>n.value.errors);return{step:g,stepIndex:o,scope:r,next:s,prev:a,goTo:c,isFirst:I,isLast:w,status:n,errors:F,isValid:S,isDirty:B,validate:u,getErrors:v}}function fe(e){let t=l(),o=_chunk25Q2XJBVcjs.e.call(void 0, t.getState().values,e),r=_vue.ref.call(void 0, o),n=t.watch(e,i=>{_chunk25Q2XJBVcjs.d.call(void 0, r.value,i)||(r.value=i)});return _vue.onUnmounted.call(void 0, n),_vue.readonly.call(void 0, r)}function ye(e,t,o){let r=l(),n=T(e),i=null,f=async v=>{if(v){r.beginFieldValidation(e),await r.clearFieldAsyncError(e);try{let s=await t(v);n.setValue(s.url),i=s.key,await r.clearFieldAsyncError(e)}catch(s){let a=s instanceof Error?s.message:"Upload failed";await r.setFieldAsyncError(e,a)}finally{r.endFieldValidation(e)}}},u=async()=>{if(i&&o)try{await o(i)}catch(v){let s=v instanceof Error?v.message:"Delete failed";await r.setFieldAsyncError(e,s);return}n.setValue(null),i=null,await r.clearFieldAsyncError(e)};return{value:n.value,setValue:n.setValue,error:_vue.computed.call(void 0, ()=>n.meta.error.value),isValidating:_vue.computed.call(void 0, ()=>n.meta.isValidating.value||!1),upload:f,remove:u}}function ge(){let e=l(),t=_vue.ref.call(void 0, !1),o=_vue.ref.call(void 0, !1),r=_vue.ref.call(void 0, null);return{restore:async()=>{o.value=!0,r.value=null;try{return await e.restorePersisted()}catch(u){return r.value=u instanceof Error?u:new Error(String(u)),!1}finally{o.value=!1}},save:async()=>{t.value=!0,r.value=null;try{await e.forceSave()}catch(u){r.value=u instanceof Error?u:new Error(String(u))}finally{t.value=!1}},clear:async()=>{r.value=null;try{await e.clearPersisted()}catch(u){r.value=u instanceof Error?u:new Error(String(u))}},meta:{isSaving:_vue.readonly.call(void 0, t),isRestoring:_vue.readonly.call(void 0, o),error:_vue.readonly.call(void 0, r)}}}exports.provideBitStore = $; exports.useBitArray = Z; exports.useBitField = T; exports.useBitForm = G; exports.useBitHistory = te; exports.useBitPersist = ge; exports.useBitScope = ie; exports.useBitSteps = me; exports.useBitStore = l; exports.useBitUpload = ye; exports.useBitWatch = fe;
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 _chunkYWXX6XRVcjs = require('../chunk-YWXX6XRV.cjs');var _vue = require('vue');var H=Symbol("BIT_STORE");function $(e){_vue.provide.call(void 0, H,e)}function c(){let e=_vue.inject.call(void 0, H);if(!e)throw new Error("BitForm Vue hooks devem ser usados sob um provideBitStore");return e}function G(){let e=c(),t=_vue.shallowRef.call(void 0, {isValid:e.getState().isValid,isSubmitting:e.getState().isSubmitting,isDirty:e.getState().isDirty}),s=_vue.ref.call(void 0, null),r=_vue.ref.call(void 0, null),i=e.subscribeSelector(y=>({isValid:y.isValid,isSubmitting:y.isSubmitting,isDirty:y.isDirty}),y=>{t.value=y});_vue.onUnmounted.call(void 0, i);let n=()=>e.getState().values,f=()=>e.getState().errors,u=()=>e.getState().touched,v=()=>e.getDirtyValues(),o=_vue.computed.call(void 0, ()=>t.value.isValid),a=_vue.computed.call(void 0, ()=>t.value.isSubmitting),l=_vue.computed.call(void 0, ()=>t.value.isDirty);return{meta:{isValid:o,isDirty:l,isSubmitting:a,submitError:s,lastResponse:r},getValues:n,getErrors:f,getTouched:u,getDirtyValues:v,submit:y=>B=>(_optionalChain([B, 'optionalAccess', _2 => _2.preventDefault, 'optionalCall', _3 => _3()]),e.submit(y)),onSubmit:y=>B=>(_optionalChain([B, 'optionalAccess', _4 => _4.preventDefault, 'optionalCall', _5 => _5()]),s.value=null,e.submit(async(F,m)=>{try{let d=await y(F,m);r.value=d,s.value=null}catch(d){_chunkYWXX6XRVcjs.i.call(void 0, d)?e.setServerErrors(_chunkYWXX6XRVcjs.j.call(void 0, d)):s.value=d instanceof Error?d:new Error(String(d))}})),reset:()=>{e.reset(),s.value=null,r.value=null},replaceValues:e.replaceValues.bind(e),hydrate:e.hydrate.bind(e),rebase:e.rebase.bind(e),setValues:e.setValues.bind(e),setError:e.setError.bind(e),setErrors:e.setErrors.bind(e),setServerErrors:e.setServerErrors.bind(e),setField:e.setField.bind(e),blurField:e.blurField.bind(e),validate:e.validate.bind(e),mutations:{pushItem:e.pushItem.bind(e),prependItem:e.prependItem.bind(e),removeItem:e.removeItem.bind(e),insertItem:e.insertItem.bind(e),moveItem:e.moveItem.bind(e),swapItems:e.swapItems.bind(e)}}}function R(e){let t=c(),s=t.resolveMask(e),r=_vue.shallowRef.call(void 0, t.getFieldState(e)),i=t.subscribeSelector(()=>t.getFieldState(e),p=>{r.value=p});_vue.onUnmounted.call(void 0, ()=>{i(),t.unregisterField&&t.unregisterField(e)});let n=_vue.computed.call(void 0, ()=>r.value.value),f=_vue.computed.call(void 0, ()=>{let p=n.value;return p==null||p===""?"":s?s.format(p):String(p)}),u=_vue.computed.call(void 0, {get:()=>f.value,set:p=>{if(!s){t.setField(e,p);return}t.setField(e,s.parse(String(_nullishCoalesce(p, () => ("")))))}}),v=_vue.computed.call(void 0, ()=>r.value.error),o=_vue.computed.call(void 0, ()=>r.value.touched?r.value.error:void 0),a=_vue.computed.call(void 0, ()=>r.value.touched),l=_vue.computed.call(void 0, ()=>!!(a.value&&o.value)),S=_vue.computed.call(void 0, ()=>r.value.isValidating),h=_vue.computed.call(void 0, ()=>r.value.isDirty),E=_vue.computed.call(void 0, ()=>r.value.isHidden),y=_vue.computed.call(void 0, ()=>r.value.isRequired),B=_vue.computed.call(void 0, ()=>!!v.value),F=p=>{if(!s){t.setField(e,p);return}u.value=String(_nullishCoalesce(p, () => ("")))},m=()=>t.blurField(e);return{value:n,displayValue:f,modelValue:u,setValue:F,setBlur:m,onInput:p=>{F(p)},onBlur:()=>{m()},meta:{error:o,touched:a,invalid:l,isValidating:S,isDirty:h,isHidden:E,isRequired:y,hasError:B}}}var V=()=>Math.random().toString(36).substring(2,9);function Z(e){let t=c(),r=(()=>{let o=_chunkYWXX6XRVcjs.f.call(void 0, t.getState().values,e);return Array.isArray(o)?o:[]})(),i=_vue.ref.call(void 0, r),n=_vue.ref.call(void 0, r.map(V)),f=t.subscribePath(e,o=>{let a=Array.isArray(o)?o:[];if(i.value=[...a],a.length!==n.value.length){let l=[...n.value];if(a.length>l.length){let S=a.length-l.length,h=Array.from({length:S},V);n.value=[...l,...h]}else n.value=l.slice(0,a.length)}});_vue.onUnmounted.call(void 0, ()=>{f(),t.unregisterPrefix&&t.unregisterPrefix(`${e}.`)});let u=_vue.computed.call(void 0, ()=>i.value.map((o,a)=>({key:n.value[a]||`temp-${a}`,value:o,index:a}))),v=_vue.computed.call(void 0, ()=>i.value.length);return{fields:u,length:v,append:o=>{n.value.push(V()),t.pushItem(e,o)},prepend:o=>{n.value.unshift(V()),t.prependItem(e,o)},insert:(o,a)=>{n.value.splice(o,0,V()),t.insertItem(e,o,a)},remove:o=>{n.value.splice(o,1),t.removeItem(e,o)},move:(o,a)=>{let l=[...n.value],[S]=l.splice(o,1);l.splice(a,0,S),n.value=l,t.moveItem(e,o,a)},swap:(o,a)=>{let l=[...n.value];[l[o],l[a]]=[l[a],l[o]],n.value=l,t.swapItems(e,o,a)},replace:o=>{n.value=o.map(V),t.setField(e,o)},clear:()=>{n.value=[],t.setField(e,[])}}}function te(){let e=c(),t=_vue.shallowRef.call(void 0, e.getHistoryMetadata()),s=e.subscribe(()=>{t.value=e.getHistoryMetadata()});_vue.onUnmounted.call(void 0, s);let r=()=>e.undo(),i=()=>e.redo();return{canUndo:_vue.computed.call(void 0, ()=>t.value.canUndo),canRedo:_vue.computed.call(void 0, ()=>t.value.canRedo),historyIndex:_vue.computed.call(void 0, ()=>t.value.historyIndex),historySize:_vue.computed.call(void 0, ()=>t.value.historySize),undo:r,redo:i}}function ie(e,t){let s=Object.keys(e),r=Object.keys(t);return s.length!==r.length?!1:s.every(i=>e[i]===t[i])}function ne(e){let t=c(),s=_vue.ref.call(void 0, t.getStepStatus(e)),r;_vue.onMounted.call(void 0, ()=>{r=t.subscribe(()=>{let o=t.getStepStatus(e);(o.hasErrors!==s.value.hasErrors||o.isDirty!==s.value.isDirty||!ie(o.errors,s.value.errors))&&(s.value=o)})}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([r, 'optionalCall', _6 => _6()])});let i=async()=>{let o=await t.validate({scope:e}),a=t.getStepErrors(e);return{valid:o,errors:a}},n=()=>t.getStepErrors(e),f=_vue.computed.call(void 0, ()=>!s.value.hasErrors),u=_vue.computed.call(void 0, ()=>s.value.isDirty),v=_vue.computed.call(void 0, ()=>s.value.errors);return{scopeName:e,status:s,errors:v,validate:i,getErrors:n,isValid:f,isDirty:u}}function ce(e,t){let s=Object.keys(e),r=Object.keys(t);return s.length!==r.length?!1:s.every(i=>e[i]===t[i])}function me(e){let t=c(),s=_vue.ref.call(void 0, 0),r=_vue.computed.call(void 0, ()=>_nullishCoalesce(e[s.value], () => (""))),i=_vue.ref.call(void 0, t.getStepStatus(r.value)),n;_vue.watch.call(void 0, r,m=>{i.value=t.getStepStatus(m)});let f=()=>{let m=r.value,d=t.getStepStatus(m);(d.hasErrors!==i.value.hasErrors||d.isDirty!==i.value.isDirty||!ce(d.errors,i.value.errors))&&(i.value=d)};_vue.onMounted.call(void 0, ()=>{n=t.subscribe(f)}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([n, 'optionalCall', _7 => _7()])});let u=async()=>{let m=r.value,d=await t.validate({scope:m}),P=t.getStepErrors(m);return{valid:d,errors:P}},v=()=>t.getStepErrors(r.value),o=async()=>{let m=r.value,d=t.getScopeFields(m);if(t.hasValidationsInProgress(d))return!1;let P=await t.validate({scope:m});if(P)s.value=Math.min(s.value+1,e.length-1);else{let p=t.getStepErrors(m),A=Object.keys(p);A.length>0&&t.markFieldsTouched(A)}return P},a=()=>{s.value=Math.max(s.value-1,0)},l=m=>{s.value=Math.max(0,Math.min(m-1,e.length-1))},S=_vue.computed.call(void 0, ()=>s.value+1),h=_vue.computed.call(void 0, ()=>s.value===0),E=_vue.computed.call(void 0, ()=>s.value>=e.length-1),y=_vue.computed.call(void 0, ()=>!i.value.hasErrors),B=_vue.computed.call(void 0, ()=>i.value.isDirty),F=_vue.computed.call(void 0, ()=>i.value.errors);return{step:S,stepIndex:s,scope:r,next:o,prev:a,goTo:l,isFirst:h,isLast:E,status:i,errors:F,isValid:y,isDirty:B,validate:u,getErrors:v}}function fe(e){let t=c(),s=_chunkYWXX6XRVcjs.f.call(void 0, t.getState().values,e),r=_vue.ref.call(void 0, s),i=t.watch(e,n=>{_chunkYWXX6XRVcjs.e.call(void 0, r.value,n)||(r.value=n)});return _vue.onUnmounted.call(void 0, i),_vue.readonly.call(void 0, r)}function ye(e,t,s){let r=c(),i=R(e),n=null,f=async v=>{if(v){r.beginFieldValidation(e),await r.clearFieldAsyncError(e);try{let o=await t(v);i.setValue(o.url),n=o.key,await r.clearFieldAsyncError(e)}catch(o){let a=o instanceof Error?o.message:"Upload failed";await r.setFieldAsyncError(e,a)}finally{r.endFieldValidation(e)}}},u=async()=>{if(n&&s)try{await s(n)}catch(v){let o=v instanceof Error?v.message:"Delete failed";await r.setFieldAsyncError(e,o);return}i.setValue(null),n=null,await r.clearFieldAsyncError(e)};return{value:i.value,setValue:i.setValue,error:_vue.computed.call(void 0, ()=>i.meta.error.value),isValidating:_vue.computed.call(void 0, ()=>i.meta.isValidating.value||!1),upload:f,remove:u}}function ge(){let e=c(),t=_vue.ref.call(void 0, !1),s=_vue.ref.call(void 0, !1),r=_vue.ref.call(void 0, null);return{restore:async()=>{s.value=!0,r.value=null;try{return await e.restorePersisted()}catch(u){return r.value=u instanceof Error?u:new Error(String(u)),!1}finally{s.value=!1}},save:async()=>{t.value=!0,r.value=null;try{await e.forceSave()}catch(u){r.value=u instanceof Error?u:new Error(String(u))}finally{t.value=!1}},clear:async()=>{r.value=null;try{await e.clearPersisted()}catch(u){r.value=u instanceof Error?u:new Error(String(u))}},meta:{isSaving:_vue.readonly.call(void 0, t),isRestoring:_vue.readonly.call(void 0, s),error:_vue.readonly.call(void 0, r)}}}exports.provideBitStore = $; exports.useBitArray = Z; exports.useBitField = R; exports.useBitForm = G; exports.useBitHistory = te; exports.useBitPersist = ge; exports.useBitScope = ne; exports.useBitSteps = me; exports.useBitStore = c; exports.useBitUpload = ye; exports.useBitWatch = fe;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/bit-form/bit-form/dist/vue/index.cjs","../../src/vue/context.ts","../../src/vue/use-bit-form.ts","../../src/vue/use-bit-field.ts","../../src/vue/use-bit-array.ts"],"names":["BIT_STORE_KEY","provideBitStore","store","provide","useBitStore","inject","useBitForm","state","shallowRef","submitError","ref","lastResponse","unsubscribe","onUnmounted","getValues","getErrors","getTouched","getDirtyValues","isValid","computed","isSubmitting","isDirty","onSuccess","e","handler","values","dirtyValues","result","err","isValidationErrorShape","extractServerErrors","useBitField","path","resolvedMask","rawValue","getDeepValue","displayValue","val","modelValue","rawError","error","touched","invalid","isValidating","isHidden","isRequired","hasError","setValue","setBlur","generateId","useBitArray","getSnapshot","initialValues","ids","newValues","currentIds","diff","newIds"],"mappings":"AAAA,0uBAA8D,0BCAhB,IAIjCA,CAAAA,CACX,MAAA,CAAO,WAAW,CAAA,CAEb,SAASC,CAAAA,CAAkCC,CAAAA,CAA6B,CAC7EC,0BAAAA,CAAQH,CAAeE,CAAK,CAC9B,CAEO,SAASE,CAAAA,CAAAA,CAAgC,CAC9C,IAAMF,CAAAA,CAAQG,yBAAAA,CAAoB,CAAA,CAClC,EAAA,CAAI,CAACH,CAAAA,CACH,MAA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C,IAAMC,CAAAA,CAAOF,CAAAA,CAAU,MAAA,CAASC,CAAAA,CAAW,MAAA,CACrCE,CAAAA,CAAS,KAAA,CAAM,IAAA,CAAK,CAAE,MAAA,CAAQD,CAAK,CAAA,CAAGP,CAAU,CAAA,CACtDI,CAAAA,CAAI,KAAA,CAAQ,CAAC,GAAGE,CAAAA,CAAY,GAAGE,CAAM,CACvC,CAAA,KACEJ,CAAAA,CAAI,KAAA,CAAQE,CAAAA,CAAW,KAAA,CAAM,CAAA,CAAGD,CAAAA,CAAU,MAAM,CAEpD,CACF,CAAC,CAAA,CAEDzC,8BAAAA,CAAY,CAAA,EAAM,CAChBD,CAAAA,CAAY,CAAA,CACRV,CAAAA,CAAM,gBAAA,EACRA,CAAAA,CAAM,gBAAA,CAAiB,CAAA,EAAA","file":"/home/runner/work/bit-form/bit-form/dist/vue/index.cjs","sourcesContent":[null,"import { inject, provide, InjectionKey } from \"vue\";\nimport type { BitFrameworkStore } from \"../core\";\n\n// Chave única para evitar colisões\nexport const BIT_STORE_KEY: InjectionKey<BitFrameworkStore<any>> =\n Symbol(\"BIT_STORE\");\n\nexport function provideBitStore<T extends object>(store: BitFrameworkStore<T>) {\n provide(BIT_STORE_KEY, store);\n}\n\nexport function useBitStore<T extends object>() {\n const store = inject(BIT_STORE_KEY);\n if (!store)\n throw new Error(\n \"BitForm Vue hooks devem ser usados sob um provideBitStore\",\n );\n return store as BitFrameworkStore<T>;\n}\n","import { computed, onUnmounted, shallowRef, ref } from \"vue\";\nimport { useBitStore } from \"./context\";\nimport { isValidationErrorShape, extractServerErrors } from \"../core/utils\";\n\nexport function useBitForm<T extends object>() {\n const store = useBitStore<T>();\n const state = shallowRef(store.getState());\n const submitError = ref<Error | null>(null);\n const lastResponse = ref<unknown>(null);\n\n const unsubscribe = store.subscribe(() => {\n state.value = { ...store.getState() };\n });\n\n onUnmounted(unsubscribe);\n\n const getValues = () => state.value.values;\n const getErrors = () => state.value.errors;\n const getTouched = () => state.value.touched;\n const getDirtyValues = () => store.getDirtyValues();\n\n const isValid = computed(() => state.value.isValid);\n const isSubmitting = computed(() => state.value.isSubmitting);\n const isDirty = computed(() => state.value.isDirty);\n\n const onSubmit = (\n handler: (values: T, dirtyValues?: Partial<T>) => Promise<unknown>,\n ) => {\n return (e?: Event) => {\n e?.preventDefault?.();\n submitError.value = null;\n return store.submit(async (values, dirtyValues) => {\n try {\n const result = await handler(values, dirtyValues);\n lastResponse.value = result;\n submitError.value = null;\n } catch (err) {\n if (isValidationErrorShape(err)) {\n store.setServerErrors(extractServerErrors(err));\n } else {\n submitError.value =\n err instanceof Error ? err : new Error(String(err));\n }\n }\n });\n };\n };\n\n const reset = () => {\n store.reset();\n submitError.value = null;\n lastResponse.value = null;\n };\n\n const meta = {\n isValid,\n isDirty,\n isSubmitting,\n submitError,\n lastResponse,\n };\n\n return {\n // Metadata (grouped)\n meta,\n // Getters\n getValues,\n getErrors,\n getTouched,\n getDirtyValues,\n // Main actions (frequent use - flat)\n submit: (\n onSuccess: (values: T, dirtyValues?: Partial<T>) => void | Promise<void>,\n ) => {\n return (e?: Event) => {\n e?.preventDefault?.();\n return store.submit(onSuccess);\n };\n },\n onSubmit,\n reset,\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 validate: store.validate.bind(store),\n // Array mutations (grouped)\n mutations: {\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 },\n };\n}\n","import { computed, onUnmounted, shallowRef } from \"vue\";\nimport { useBitStore } from \"./context\";\nimport { getDeepValue } from \"../core\";\nimport type { UseBitFieldVueMeta, UseBitFieldVueResult } from \"./types\";\n\nexport function useBitField<TValue = any>(\n path: string,\n): UseBitFieldVueResult<TValue> {\n const store = useBitStore<any>();\n\n const resolvedMask = store.resolveMask(path as string);\n\n const state = shallowRef(store.getState());\n\n const unsubscribe = store.subscribe(() => {\n state.value = store.getState();\n });\n\n onUnmounted(() => {\n unsubscribe();\n if (store.unregisterField) {\n store.unregisterField(path as string);\n }\n });\n\n const rawValue = computed(\n () => getDeepValue(state.value.values, path as string) as TValue,\n );\n\n const displayValue = computed(() => {\n const val = rawValue.value;\n if (val === undefined || val === null || val === \"\") return \"\";\n\n return resolvedMask ? resolvedMask.format(val as any) : String(val);\n });\n\n const modelValue = computed({\n get: () => displayValue.value,\n set: (val: any) => {\n if (!resolvedMask) {\n store.setField(path, val);\n return;\n }\n\n store.setField(path, resolvedMask.parse(String(val ?? \"\")));\n },\n });\n\n const rawError = computed(() => state.value.errors[path]);\n const error = computed(() =>\n state.value.touched[path] ? state.value.errors[path] : undefined,\n );\n const touched = computed(() => !!state.value.touched[path]);\n const invalid = computed(() => !!(touched.value && error.value));\n\n const isValidating = computed(() => {\n state.value;\n return store.isFieldValidating(path);\n });\n\n const isDirty = computed(() => {\n state.value;\n return store.isFieldDirty(path);\n });\n\n const isHidden = computed(() => {\n state.value;\n return store.isHidden(path);\n });\n\n const isRequired = computed(() => {\n state.value;\n return store.isRequired(path);\n });\n\n const hasError = computed(() => !!rawError.value);\n\n const setValue = (val: any) => {\n modelValue.value = val;\n };\n\n const setBlur = () => store.blurField(path);\n\n const onInput = (val: any) => {\n setValue(val);\n };\n\n const onBlur = () => {\n setBlur();\n };\n\n return {\n // Main handlers and values (flat)\n value: rawValue,\n displayValue,\n modelValue,\n setValue,\n setBlur,\n onInput,\n onBlur,\n // Metadata (grouped)\n meta: {\n error,\n touched,\n invalid,\n isValidating,\n isDirty,\n isHidden,\n isRequired,\n hasError,\n },\n };\n}\n","import { ref, computed, onUnmounted } from \"vue\";\nimport { useBitStore } from \"./context\";\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 useBitArray<\n TForm extends object = any,\n P extends BitArrayPath<TForm> = BitArrayPath<TForm>,\n>(path: P) {\n const store = useBitStore<TForm>();\n\n type Item = BitArrayItem<BitPathValue<TForm, P>>;\n\n const getSnapshot = (): Item[] => {\n const val = getDeepValue(\n store.getState().values,\n path as string,\n ) as BitPathValue<TForm, P> | undefined;\n return Array.isArray(val) ? (val as Item[]) : [];\n };\n\n const initialValues = getSnapshot();\n const values = ref<Item[]>(initialValues);\n const ids = ref<string[]>(initialValues.map(generateId));\n\n const unsubscribe = store.subscribe(() => {\n const newValues = getSnapshot();\n values.value = [...newValues];\n\n if (newValues.length !== ids.value.length) {\n const currentIds = [...ids.value];\n if (newValues.length > currentIds.length) {\n const diff = newValues.length - currentIds.length;\n const newIds = Array.from({ length: diff }, generateId);\n ids.value = [...currentIds, ...newIds];\n } else {\n ids.value = currentIds.slice(0, newValues.length);\n }\n }\n });\n\n onUnmounted(() => {\n unsubscribe();\n if (store.unregisterPrefix) {\n store.unregisterPrefix(`${path as string}.`);\n }\n });\n\n const fields = computed(() =>\n values.value.map((v, i) => ({\n key: ids.value[i] || `temp-${i}`,\n value: v,\n index: i,\n })),\n );\n\n const length = computed(() => values.value.length);\n\n return {\n fields,\n length,\n append: (val: Item) => {\n ids.value.push(generateId());\n store.pushItem(path, val);\n },\n prepend: (val: Item) => {\n ids.value.unshift(generateId());\n store.prependItem(path, val);\n },\n insert: (index: number, val: Item) => {\n ids.value.splice(index, 0, generateId());\n store.insertItem(path, index, val);\n },\n remove: (index: number) => {\n ids.value.splice(index, 1);\n store.removeItem(path, index);\n },\n move: (from: number, to: number) => {\n const currentIds = [...ids.value];\n const [id] = currentIds.splice(from, 1);\n currentIds.splice(to, 0, id);\n ids.value = currentIds;\n store.moveItem(path, from, to);\n },\n swap: (a: number, b: number) => {\n const currentIds = [...ids.value];\n [currentIds[a], currentIds[b]] = [currentIds[b], currentIds[a]];\n ids.value = currentIds;\n store.swapItems(path, a, b);\n },\n replace: (items: Item[]) => {\n ids.value = items.map(generateId);\n store.setField(path as unknown as BitPath<TForm>, items as any);\n },\n clear: () => {\n ids.value = [];\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/vue/index.cjs","../../src/vue/context.ts","../../src/vue/use-bit-form.ts","../../src/vue/use-bit-field.ts","../../src/vue/use-bit-array.ts"],"names":["BIT_STORE_KEY","provideBitStore","store","provide","useBitStore","inject","useBitForm","state","shallowRef","submitError","ref","lastResponse","unsubscribe","snapshot","nextState","onUnmounted","getValues","getErrors","getTouched","getDirtyValues","isValid","computed","isSubmitting","isDirty","onSuccess","e","handler","values","dirtyValues","result","err","isValidationErrorShape","extractServerErrors","useBitField","path","resolvedMask","rawValue","displayValue","val","modelValue","rawError","error","touched","invalid","isValidating","isHidden","isRequired","hasError","setValue","setBlur","generateId","useBitArray","initialValues","getDeepValue","ids","newValues","nextValues","currentIds","diff","newIds"],"mappings":"AAAA,0uBAA8D,0BCAhB,IAIjCA,CAAAA,CACX,MAAA,CAAO,WAAW,CAAA,CAEb,SAASC,CAAAA,CAAkCC,CAAAA,CAAuB,CACvEC,0BAAAA,CAAQH,CAAeE,CAAK,CAC9B,CAEO,SAASE,CAAAA,CAAAA,CAAgC,CAC9C,IAAMF,CAAAA,CAAQG,yBAAAA,CAAoB,CAAA,CAClC,EAAA,CAAI,CAACH,CAAAA,CACH,MAAM,IAAI,KAAA,CACR,2DACF,CAAA,CACF,OAAOA,CACT,CClBA,SAIgBI,CAAAA,CAAAA,CAA+B,CAC7C,IAAMJ,CAAAA,CAAQE,CAAAA,CAAe,CAAA,CACvBG,CAAAA,CAAQC,6BAAAA,CACZ,OAAA,CAASN,CAAAA,CAAM,QAAA,CAAS,CAAA,CAAE,OAAA,CAC1B,YAAA,CAAcA,CAAAA,CAAM,QAAA,CAAS,CAAA,CAAE,YAAA,CAC/B,OAAA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C1C,IAAMG,CAAAA,CAAa,CAAC,GAAGH,CAAAA,CAAI,KAAK,CAAA,CAChC,EAAA,CAAIE,CAAAA,CAAW,MAAA,CAASC,CAAAA,CAAW,MAAA,CAAQ,CACzC,IAAMC,CAAAA,CAAOF,CAAAA,CAAW,MAAA,CAASC,CAAAA,CAAW,MAAA,CACtCE,CAAAA,CAAS,KAAA,CAAM,IAAA,CAAK,CAAE,MAAA,CAAQD,CAAK,CAAA,CAAGR,CAAU,CAAA,CACtDI,CAAAA,CAAI,KAAA,CAAQ,CAAC,GAAGG,CAAAA,CAAY,GAAGE,CAAM,CACvC,CAAA,KACEL,CAAAA,CAAI,KAAA,CAAQG,CAAAA,CAAW,KAAA,CAAM,CAAA,CAAGD,CAAAA,CAAW,MAAM,CAErD,CACF,CAAC,CAAA,CAEDzC,8BAAAA,CAAY,CAAA,EAAM,CAChBH,CAAAA,CAAY,CAAA,CACRV,CAAAA,CAAM,gBAAA,EACRA,CAAAA,CAAM,gBAAA,CAAiB,CAAA,EAAA","file":"/home/runner/work/bit-form/bit-form/dist/vue/index.cjs","sourcesContent":[null,"import { inject, provide, InjectionKey } from \"vue\";\nimport type { BitStoreApi } from \"../core\";\n\n// Chave única para evitar colisões\nexport const BIT_STORE_KEY: InjectionKey<BitStoreApi<any>> =\n Symbol(\"BIT_STORE\");\n\nexport function provideBitStore<T extends object>(store: BitStoreApi<T>) {\n provide(BIT_STORE_KEY, store);\n}\n\nexport function useBitStore<T extends object>() {\n const store = inject(BIT_STORE_KEY);\n if (!store)\n throw new Error(\n \"BitForm Vue hooks devem ser usados sob um provideBitStore\",\n );\n return store as BitStoreApi<T>;\n}\n","import { computed, onUnmounted, shallowRef, ref } from \"vue\";\nimport { useBitStore } from \"./context\";\nimport { isValidationErrorShape, extractServerErrors } from \"../core/utils\";\n\nexport function useBitForm<T extends object>() {\n const store = useBitStore<T>();\n const state = shallowRef({\n isValid: store.getState().isValid,\n isSubmitting: store.getState().isSubmitting,\n isDirty: store.getState().isDirty,\n });\n const submitError = ref<Error | null>(null);\n const lastResponse = ref<unknown>(null);\n\n const unsubscribe = store.subscribeSelector(\n (snapshot) => ({\n isValid: snapshot.isValid,\n isSubmitting: snapshot.isSubmitting,\n isDirty: snapshot.isDirty,\n }),\n (nextState) => {\n state.value = nextState;\n },\n );\n\n onUnmounted(unsubscribe);\n\n const getValues = () => store.getState().values;\n const getErrors = () => store.getState().errors;\n const getTouched = () => store.getState().touched;\n const getDirtyValues = () => store.getDirtyValues();\n\n const isValid = computed(() => state.value.isValid);\n const isSubmitting = computed(() => state.value.isSubmitting);\n const isDirty = computed(() => state.value.isDirty);\n\n const onSubmit = (\n handler: (values: T, dirtyValues?: Partial<T>) => Promise<unknown>,\n ) => {\n return (e?: Event) => {\n e?.preventDefault?.();\n submitError.value = null;\n return store.submit(async (values, dirtyValues) => {\n try {\n const result = await handler(values, dirtyValues);\n lastResponse.value = result;\n submitError.value = null;\n } catch (err) {\n if (isValidationErrorShape(err)) {\n store.setServerErrors(extractServerErrors(err));\n } else {\n submitError.value =\n err instanceof Error ? err : new Error(String(err));\n }\n }\n });\n };\n };\n\n const reset = () => {\n store.reset();\n submitError.value = null;\n lastResponse.value = null;\n };\n\n const meta = {\n isValid,\n isDirty,\n isSubmitting,\n submitError,\n lastResponse,\n };\n\n return {\n // Metadata (grouped)\n meta,\n // Getters\n getValues,\n getErrors,\n getTouched,\n getDirtyValues,\n // Main actions (frequent use - flat)\n submit: (\n onSuccess: (values: T, dirtyValues?: Partial<T>) => void | Promise<void>,\n ) => {\n return (e?: Event) => {\n e?.preventDefault?.();\n return store.submit(onSuccess);\n };\n },\n onSubmit,\n reset,\n replaceValues: store.replaceValues.bind(store),\n hydrate: store.hydrate.bind(store),\n rebase: store.rebase.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 validate: store.validate.bind(store),\n // Array mutations (grouped)\n mutations: {\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 },\n };\n}\n","import { computed, onUnmounted, shallowRef } from \"vue\";\nimport { useBitStore } from \"./context\";\nimport type { UseBitFieldVueResult } from \"./types\";\nimport type { BitPath, BitPathValue } from \"../core\";\n\nexport function useBitField<\n TForm extends object = any,\n P extends BitPath<TForm> = BitPath<TForm>,\n>(path: P): UseBitFieldVueResult<BitPathValue<TForm, P>> {\n const store = useBitStore<TForm>();\n\n const resolvedMask = store.resolveMask(path);\n\n const state = shallowRef(store.getFieldState(path));\n\n const unsubscribe = store.subscribeSelector(\n () => store.getFieldState(path),\n (nextState) => {\n state.value = nextState;\n },\n );\n\n onUnmounted(() => {\n unsubscribe();\n if (store.unregisterField) {\n store.unregisterField(path);\n }\n });\n\n const rawValue = computed(() => state.value.value as BitPathValue<TForm, P>);\n\n const displayValue = computed(() => {\n const val = rawValue.value;\n if (val === undefined || val === null || val === \"\") return \"\";\n\n return resolvedMask ? resolvedMask.format(val) : String(val);\n });\n\n const modelValue = computed({\n get: () => displayValue.value,\n set: (val: string) => {\n if (!resolvedMask) {\n store.setField(path, val as BitPathValue<TForm, P>);\n return;\n }\n\n store.setField(path, resolvedMask.parse(String(val ?? \"\")));\n },\n });\n\n const rawError = computed(() => state.value.error);\n const error = computed(() =>\n state.value.touched ? state.value.error : undefined,\n );\n const touched = computed(() => state.value.touched);\n const invalid = computed(() => !!(touched.value && error.value));\n\n const isValidating = computed(() => state.value.isValidating);\n\n const isDirty = computed(() => state.value.isDirty);\n\n const isHidden = computed(() => state.value.isHidden);\n\n const isRequired = computed(() => state.value.isRequired);\n\n const hasError = computed(() => !!rawError.value);\n\n const setValue = (\n val: BitPathValue<TForm, P> | string | number | null | undefined,\n ) => {\n if (!resolvedMask) {\n store.setField(path, val as BitPathValue<TForm, P>);\n return;\n }\n\n modelValue.value = String(val ?? \"\");\n };\n\n const setBlur = () => store.blurField(path);\n\n const onInput = (\n val: BitPathValue<TForm, P> | string | number | null | undefined,\n ) => {\n setValue(val);\n };\n\n const onBlur = () => {\n setBlur();\n };\n\n return {\n // Main handlers and values (flat)\n value: rawValue,\n displayValue,\n modelValue,\n setValue,\n setBlur,\n onInput,\n onBlur,\n // Metadata (grouped)\n meta: {\n error,\n touched,\n invalid,\n isValidating,\n isDirty,\n isHidden,\n isRequired,\n hasError,\n },\n };\n}\n","import { ref, computed, onUnmounted } from \"vue\";\nimport { useBitStore } from \"./context\";\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 useBitArray<\n TForm extends object = any,\n P extends BitArrayPath<TForm> = BitArrayPath<TForm>,\n>(path: P) {\n const store = useBitStore<TForm>();\n\n type Item = BitArrayItem<BitPathValue<TForm, P>>;\n\n const getSnapshot = (): Item[] => {\n const val = getDeepValue(store.getState().values, path as string) as\n | BitPathValue<TForm, P>\n | undefined;\n return Array.isArray(val) ? (val as Item[]) : [];\n };\n\n const initialValues = getSnapshot();\n const values = ref<Item[]>(initialValues);\n const ids = ref<string[]>(initialValues.map(generateId));\n\n const unsubscribe = store.subscribePath(path, (newValues) => {\n const nextValues = (Array.isArray(newValues) ? newValues : []) as Item[];\n\n values.value = [...nextValues];\n\n if (nextValues.length !== ids.value.length) {\n const currentIds = [...ids.value];\n if (nextValues.length > currentIds.length) {\n const diff = nextValues.length - currentIds.length;\n const newIds = Array.from({ length: diff }, generateId);\n ids.value = [...currentIds, ...newIds];\n } else {\n ids.value = currentIds.slice(0, nextValues.length);\n }\n }\n });\n\n onUnmounted(() => {\n unsubscribe();\n if (store.unregisterPrefix) {\n store.unregisterPrefix(`${path as string}.`);\n }\n });\n\n const fields = computed(() =>\n values.value.map((v, i) => ({\n key: ids.value[i] || `temp-${i}`,\n value: v,\n index: i,\n })),\n );\n\n const length = computed(() => values.value.length);\n\n return {\n fields,\n length,\n append: (val: Item) => {\n ids.value.push(generateId());\n store.pushItem(path, val);\n },\n prepend: (val: Item) => {\n ids.value.unshift(generateId());\n store.prependItem(path, val);\n },\n insert: (index: number, val: Item) => {\n ids.value.splice(index, 0, generateId());\n store.insertItem(path, index, val);\n },\n remove: (index: number) => {\n ids.value.splice(index, 1);\n store.removeItem(path, index);\n },\n move: (from: number, to: number) => {\n const currentIds = [...ids.value];\n const [id] = currentIds.splice(from, 1);\n currentIds.splice(to, 0, id);\n ids.value = currentIds;\n store.moveItem(path, from, to);\n },\n swap: (a: number, b: number) => {\n const currentIds = [...ids.value];\n [currentIds[a], currentIds[b]] = [currentIds[b], currentIds[a]];\n ids.value = currentIds;\n store.swapItems(path, a, b);\n },\n replace: (items: Item[]) => {\n ids.value = items.map(generateId);\n store.setField(\n path as unknown as BitPath<TForm>,\n items as unknown as BitPathValue<TForm, BitPath<TForm>>,\n );\n },\n clear: () => {\n ids.value = [];\n store.setField(\n path as unknown as BitPath<TForm>,\n [] as unknown as BitPathValue<TForm, BitPath<TForm>>,\n );\n },\n };\n}\n"]}