@lehnihon/bit-form 2.0.1 → 2.1.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 (66) hide show
  1. package/README.md +1 -0
  2. package/dist/angular/index.cjs +1 -1
  3. package/dist/angular/index.cjs.map +1 -1
  4. package/dist/angular/index.d.cts +74 -37
  5. package/dist/angular/index.d.ts +74 -37
  6. package/dist/angular/index.js +1 -1
  7. package/dist/angular/index.js.map +1 -1
  8. package/dist/bus-C1xKmQdw.d.cts +144 -0
  9. package/dist/bus-C1xKmQdw.d.ts +144 -0
  10. package/dist/chunk-5JV3QKOT.js +2 -0
  11. package/dist/chunk-5JV3QKOT.js.map +1 -0
  12. package/dist/{chunk-VCHMCHED.cjs → chunk-CPFHKRLU.cjs} +2 -2
  13. package/dist/chunk-CPFHKRLU.cjs.map +1 -0
  14. package/dist/{chunk-4MPIKMTH.cjs → chunk-SIM4YIOW.cjs} +7 -7
  15. package/dist/chunk-SIM4YIOW.cjs.map +1 -0
  16. package/dist/chunk-XHZAMKSZ.js +133 -0
  17. package/dist/chunk-XHZAMKSZ.js.map +1 -0
  18. package/dist/devtools/bridge.cjs +1 -1
  19. package/dist/devtools/bridge.js +1 -1
  20. package/dist/devtools/index.cjs +1 -1
  21. package/dist/devtools/index.js +1 -1
  22. package/dist/index.cjs +1 -1
  23. package/dist/index.d.cts +6 -24
  24. package/dist/index.d.ts +6 -24
  25. package/dist/index.js +1 -1
  26. package/dist/public-types-B3jU1R2E.d.cts +70 -0
  27. package/dist/public-types-By_9Weno.d.ts +70 -0
  28. package/dist/react/index.cjs +1 -1
  29. package/dist/react/index.cjs.map +1 -1
  30. package/dist/react/index.d.cts +31 -38
  31. package/dist/react/index.d.ts +31 -38
  32. package/dist/react/index.js +1 -1
  33. package/dist/react/index.js.map +1 -1
  34. package/dist/react-native/index.cjs +1 -1
  35. package/dist/react-native/index.cjs.map +1 -1
  36. package/dist/react-native/index.d.cts +15 -4
  37. package/dist/react-native/index.d.ts +15 -4
  38. package/dist/react-native/index.js +1 -1
  39. package/dist/react-native/index.js.map +1 -1
  40. package/dist/resolvers/joi.d.cts +1 -1
  41. package/dist/resolvers/joi.d.ts +1 -1
  42. package/dist/resolvers/yup.d.cts +1 -1
  43. package/dist/resolvers/yup.d.ts +1 -1
  44. package/dist/resolvers/zod.d.cts +1 -1
  45. package/dist/resolvers/zod.d.ts +1 -1
  46. package/dist/types-C2mpfhp1.d.cts +17 -0
  47. package/dist/types-C2mpfhp1.d.ts +17 -0
  48. package/dist/{use-bit-watch-CtdglHvd.d.cts → use-bit-watch-DVxSlp2A.d.ts} +92 -28
  49. package/dist/{use-bit-watch-B_ket_j5.d.ts → use-bit-watch-v4eamRCT.d.cts} +92 -28
  50. package/dist/vue/index.cjs +1 -1
  51. package/dist/vue/index.cjs.map +1 -1
  52. package/dist/vue/index.d.cts +74 -36
  53. package/dist/vue/index.d.ts +74 -36
  54. package/dist/vue/index.js +1 -1
  55. package/dist/vue/index.js.map +1 -1
  56. package/package.json +7 -2
  57. package/dist/bus-CnqfsZpc.d.cts +0 -286
  58. package/dist/bus-CnqfsZpc.d.ts +0 -286
  59. package/dist/chunk-4MPIKMTH.cjs.map +0 -1
  60. package/dist/chunk-OZOSKSJA.js +0 -2
  61. package/dist/chunk-OZOSKSJA.js.map +0 -1
  62. package/dist/chunk-VCHMCHED.cjs.map +0 -1
  63. package/dist/chunk-ZWLZ4XDF.js +0 -133
  64. package/dist/chunk-ZWLZ4XDF.js.map +0 -1
  65. package/dist/index-BAOM6INR.d.ts +0 -206
  66. package/dist/index-BdLuC0wS.d.cts +0 -206
@@ -1,5 +1,5 @@
1
1
  import { Schema } from 'yup';
2
- import { d as BitErrors } from '../bus-CnqfsZpc.js';
2
+ import { e as BitErrors } from '../bus-C1xKmQdw.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 { d as BitErrors } from '../bus-CnqfsZpc.cjs';
2
+ import { e as BitErrors } from '../bus-C1xKmQdw.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 { d as BitErrors } from '../bus-CnqfsZpc.js';
2
+ import { e as BitErrors } from '../bus-C1xKmQdw.js';
3
3
 
4
4
  declare const zodResolver: <T extends object>(schema: ZodSchema<T>) => (values: T, options?: {
5
5
  scopeFields?: string[];
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Upload Integration Types
3
+ *
4
+ * Core types for backend-first upload integration.
5
+ */
6
+ /** Upload result with URL and key for reference/deletion. */
7
+ interface BitUploadResult {
8
+ url: string;
9
+ key: string;
10
+ metadata?: Record<string, any>;
11
+ }
12
+ /** Upload function contract (backend-first). All context is managed by the caller. */
13
+ type BitUploadFn = (file: File) => Promise<BitUploadResult>;
14
+ /** Optional delete function contract. */
15
+ type BitDeleteUploadFn = (key: string) => Promise<void>;
16
+
17
+ export type { BitDeleteUploadFn as B, BitUploadFn as a, BitUploadResult as b };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Upload Integration Types
3
+ *
4
+ * Core types for backend-first upload integration.
5
+ */
6
+ /** Upload result with URL and key for reference/deletion. */
7
+ interface BitUploadResult {
8
+ url: string;
9
+ key: string;
10
+ metadata?: Record<string, any>;
11
+ }
12
+ /** Upload function contract (backend-first). All context is managed by the caller. */
13
+ type BitUploadFn = (file: File) => Promise<BitUploadResult>;
14
+ /** Optional delete function contract. */
15
+ type BitDeleteUploadFn = (key: string) => Promise<void>;
16
+
17
+ export type { BitDeleteUploadFn as B, BitUploadFn as a, BitUploadResult as b };
@@ -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 BitStore } from './index-BdLuC0wS.cjs';
4
- import { d as BitErrors, o as BitTouched, b as BitPath, c as BitPathValue, h as BitArrayPath, g as BitArrayItem, S as ScopeStatus, V as ValidateScopeResult } from './bus-CnqfsZpc.cjs';
3
+ import { b as BitFrameworkStore } from './public-types-By_9Weno.js';
4
+ import { e as BitErrors, n as BitTouched, k as BitPath, l as BitPathValue, S as ScopeStatus, V as ValidateScopeResult, c as BitArrayPath, b as BitArrayItem } from './bus-C1xKmQdw.js';
5
5
 
6
6
  declare const BitFormProvider: ({ store, children, }: {
7
- store: BitStore<any>;
7
+ store: BitFrameworkStore<any>;
8
8
  children: React.ReactNode;
9
9
  }) => react_jsx_runtime.JSX.Element;
10
- declare const useBitStore: <T extends object>() => BitStore<T>;
10
+ declare const useBitStore: <T extends object>() => BitFrameworkStore<T>;
11
11
 
12
12
  declare function useBitForm<T extends object>(): {
13
13
  meta: {
@@ -30,7 +30,7 @@ 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
- setValues: (newValues: T) => void;
33
+ setValues: (values: T) => void;
34
34
  setError: (path: string, message: string | undefined) => void;
35
35
  setErrors: (errors: BitErrors<T>) => void;
36
36
  setServerErrors: (serverErrors: Record<string, string[] | string>) => void;
@@ -39,15 +39,95 @@ declare function useBitForm<T extends object>(): {
39
39
  scopeFields?: string[];
40
40
  }) => Promise<boolean>;
41
41
  mutations: {
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;
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;
48
48
  };
49
49
  };
50
50
 
51
+ /**
52
+ * Metadata describing the current state of a form field.
53
+ */
54
+ interface UseBitFieldMeta {
55
+ error: string | undefined;
56
+ touched: boolean;
57
+ invalid: boolean;
58
+ isValidating: boolean;
59
+ isDirty: boolean;
60
+ isHidden: boolean;
61
+ isRequired: boolean;
62
+ hasError: boolean;
63
+ }
64
+ /**
65
+ * Props that can be spread onto a native HTML input element.
66
+ */
67
+ interface UseBitFieldBindProps {
68
+ value: string;
69
+ onChange: (e: any) => void;
70
+ onBlur: () => void;
71
+ }
72
+ /**
73
+ * Result from useBitField hook.
74
+ * Provides field state, value, handlers, and metadata.
75
+ */
76
+ interface UseBitFieldResult<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>> {
77
+ value: BitPathValue<TForm, P>;
78
+ displayValue: string;
79
+ setValue: (val: any) => void;
80
+ setBlur: () => void;
81
+ onChange: (e: any) => void;
82
+ onBlur: () => void;
83
+ props: UseBitFieldBindProps;
84
+ meta: UseBitFieldMeta;
85
+ }
86
+ /**
87
+ * Result from useBitSteps hook.
88
+ * Provides multi-step form navigation and validation.
89
+ */
90
+ interface UseBitStepsResult {
91
+ step: number;
92
+ stepIndex: number;
93
+ scope: string;
94
+ next: () => Promise<boolean>;
95
+ prev: () => void;
96
+ goTo: (step: number) => void;
97
+ isFirst: boolean;
98
+ isLast: boolean;
99
+ status: ScopeStatus;
100
+ errors: Record<string, string>;
101
+ isValid: boolean;
102
+ isDirty: boolean;
103
+ validate: () => Promise<ValidateScopeResult>;
104
+ getErrors: () => Record<string, string>;
105
+ }
106
+ /**
107
+ * Result from useBitUpload hook.
108
+ * Provides file upload functionality with integrated validation.
109
+ */
110
+ interface UseBitUploadResult {
111
+ value: string | File | null;
112
+ setValue: (value: string | File | null) => void;
113
+ error?: string;
114
+ isValidating: boolean;
115
+ upload: (file: File | null | undefined) => Promise<void>;
116
+ remove: () => Promise<void>;
117
+ }
118
+ /**
119
+ * Result from useBitHistory hook.
120
+ * Provides form history undo/redo capabilities.
121
+ */
122
+ interface UseBitHistoryResult {
123
+ canUndo: boolean;
124
+ canRedo: boolean;
125
+ historyIndex: number;
126
+ historySize: number;
127
+ undo: () => void;
128
+ redo: () => void;
129
+ }
130
+
51
131
  declare function useBitArray<TForm extends object = any, P extends BitArrayPath<TForm> = BitArrayPath<TForm>>(path: P): {
52
132
  append: (value: BitArrayItem<BitPathValue<TForm, P>>) => void;
53
133
  prepend: (value: BitArrayItem<BitPathValue<TForm, P>>) => void;
@@ -75,24 +155,8 @@ declare function useBitScope(scopeName: string): {
75
155
  isDirty: boolean;
76
156
  };
77
157
 
78
- interface UseBitStepsResult {
79
- step: number;
80
- stepIndex: number;
81
- scope: string;
82
- next: () => Promise<boolean>;
83
- prev: () => void;
84
- goTo: (step: number) => void;
85
- isFirst: boolean;
86
- isLast: boolean;
87
- status: ScopeStatus;
88
- errors: Record<string, string>;
89
- isValid: boolean;
90
- isDirty: boolean;
91
- validate: () => Promise<ValidateScopeResult>;
92
- getErrors: () => Record<string, string>;
93
- }
94
158
  declare function useBitSteps(scopeNames: string[]): UseBitStepsResult;
95
159
 
96
160
  declare function useBitWatch<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>>(path: P): BitPathValue<TForm, P>;
97
161
 
98
- export { BitFormProvider as B, type UseBitStepsResult as U, useBitForm as a, useBitScope as b, useBitSteps as c, useBitStore as d, useBitWatch as e, useBitArray as u };
162
+ export { BitFormProvider as B, type UseBitFieldResult as U, type UseBitHistoryResult as a, type UseBitUploadResult as b, type UseBitFieldBindProps as c, type UseBitFieldMeta as d, type UseBitStepsResult as e, useBitForm as f, useBitScope as g, useBitSteps as h, useBitStore as i, useBitWatch as j, useBitArray as u };
@@ -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 BitStore } from './index-BAOM6INR.js';
4
- import { d as BitErrors, o as BitTouched, b as BitPath, c as BitPathValue, h as BitArrayPath, g as BitArrayItem, S as ScopeStatus, V as ValidateScopeResult } from './bus-CnqfsZpc.js';
3
+ import { b as BitFrameworkStore } from './public-types-B3jU1R2E.cjs';
4
+ import { e as BitErrors, n as BitTouched, k as BitPath, l as BitPathValue, S as ScopeStatus, V as ValidateScopeResult, c as BitArrayPath, b as BitArrayItem } from './bus-C1xKmQdw.cjs';
5
5
 
6
6
  declare const BitFormProvider: ({ store, children, }: {
7
- store: BitStore<any>;
7
+ store: BitFrameworkStore<any>;
8
8
  children: React.ReactNode;
9
9
  }) => react_jsx_runtime.JSX.Element;
10
- declare const useBitStore: <T extends object>() => BitStore<T>;
10
+ declare const useBitStore: <T extends object>() => BitFrameworkStore<T>;
11
11
 
12
12
  declare function useBitForm<T extends object>(): {
13
13
  meta: {
@@ -30,7 +30,7 @@ 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
- setValues: (newValues: T) => void;
33
+ setValues: (values: T) => void;
34
34
  setError: (path: string, message: string | undefined) => void;
35
35
  setErrors: (errors: BitErrors<T>) => void;
36
36
  setServerErrors: (serverErrors: Record<string, string[] | string>) => void;
@@ -39,15 +39,95 @@ declare function useBitForm<T extends object>(): {
39
39
  scopeFields?: string[];
40
40
  }) => Promise<boolean>;
41
41
  mutations: {
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;
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;
48
48
  };
49
49
  };
50
50
 
51
+ /**
52
+ * Metadata describing the current state of a form field.
53
+ */
54
+ interface UseBitFieldMeta {
55
+ error: string | undefined;
56
+ touched: boolean;
57
+ invalid: boolean;
58
+ isValidating: boolean;
59
+ isDirty: boolean;
60
+ isHidden: boolean;
61
+ isRequired: boolean;
62
+ hasError: boolean;
63
+ }
64
+ /**
65
+ * Props that can be spread onto a native HTML input element.
66
+ */
67
+ interface UseBitFieldBindProps {
68
+ value: string;
69
+ onChange: (e: any) => void;
70
+ onBlur: () => void;
71
+ }
72
+ /**
73
+ * Result from useBitField hook.
74
+ * Provides field state, value, handlers, and metadata.
75
+ */
76
+ interface UseBitFieldResult<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>> {
77
+ value: BitPathValue<TForm, P>;
78
+ displayValue: string;
79
+ setValue: (val: any) => void;
80
+ setBlur: () => void;
81
+ onChange: (e: any) => void;
82
+ onBlur: () => void;
83
+ props: UseBitFieldBindProps;
84
+ meta: UseBitFieldMeta;
85
+ }
86
+ /**
87
+ * Result from useBitSteps hook.
88
+ * Provides multi-step form navigation and validation.
89
+ */
90
+ interface UseBitStepsResult {
91
+ step: number;
92
+ stepIndex: number;
93
+ scope: string;
94
+ next: () => Promise<boolean>;
95
+ prev: () => void;
96
+ goTo: (step: number) => void;
97
+ isFirst: boolean;
98
+ isLast: boolean;
99
+ status: ScopeStatus;
100
+ errors: Record<string, string>;
101
+ isValid: boolean;
102
+ isDirty: boolean;
103
+ validate: () => Promise<ValidateScopeResult>;
104
+ getErrors: () => Record<string, string>;
105
+ }
106
+ /**
107
+ * Result from useBitUpload hook.
108
+ * Provides file upload functionality with integrated validation.
109
+ */
110
+ interface UseBitUploadResult {
111
+ value: string | File | null;
112
+ setValue: (value: string | File | null) => void;
113
+ error?: string;
114
+ isValidating: boolean;
115
+ upload: (file: File | null | undefined) => Promise<void>;
116
+ remove: () => Promise<void>;
117
+ }
118
+ /**
119
+ * Result from useBitHistory hook.
120
+ * Provides form history undo/redo capabilities.
121
+ */
122
+ interface UseBitHistoryResult {
123
+ canUndo: boolean;
124
+ canRedo: boolean;
125
+ historyIndex: number;
126
+ historySize: number;
127
+ undo: () => void;
128
+ redo: () => void;
129
+ }
130
+
51
131
  declare function useBitArray<TForm extends object = any, P extends BitArrayPath<TForm> = BitArrayPath<TForm>>(path: P): {
52
132
  append: (value: BitArrayItem<BitPathValue<TForm, P>>) => void;
53
133
  prepend: (value: BitArrayItem<BitPathValue<TForm, P>>) => void;
@@ -75,24 +155,8 @@ declare function useBitScope(scopeName: string): {
75
155
  isDirty: boolean;
76
156
  };
77
157
 
78
- interface UseBitStepsResult {
79
- step: number;
80
- stepIndex: number;
81
- scope: string;
82
- next: () => Promise<boolean>;
83
- prev: () => void;
84
- goTo: (step: number) => void;
85
- isFirst: boolean;
86
- isLast: boolean;
87
- status: ScopeStatus;
88
- errors: Record<string, string>;
89
- isValid: boolean;
90
- isDirty: boolean;
91
- validate: () => Promise<ValidateScopeResult>;
92
- getErrors: () => Record<string, string>;
93
- }
94
158
  declare function useBitSteps(scopeNames: string[]): UseBitStepsResult;
95
159
 
96
160
  declare function useBitWatch<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>>(path: P): BitPathValue<TForm, P>;
97
161
 
98
- export { BitFormProvider as B, type UseBitStepsResult as U, useBitForm as a, useBitScope as b, useBitSteps as c, useBitStore as d, useBitWatch as e, useBitArray as u };
162
+ export { BitFormProvider as B, type UseBitFieldResult as U, type UseBitHistoryResult as a, type UseBitUploadResult as b, type UseBitFieldBindProps as c, type UseBitFieldMeta as d, type UseBitStepsResult as e, useBitForm as f, useBitScope as g, useBitSteps as h, useBitStore as i, useBitWatch as j, useBitArray as u };
@@ -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 _chunk4MPIKMTHcjs = require('../chunk-4MPIKMTH.cjs');var _vue = require('vue');var j=Symbol("BIT_STORE");function z(e){_vue.provide.call(void 0, j,e)}function m(){let e=_vue.inject.call(void 0, j);if(!e)throw new Error("BitForm Vue hooks devem ser usados sob um provideBitStore");return e}function _(){let e=m(),t=_vue.shallowRef.call(void 0, e.getState()),s=_vue.ref.call(void 0, null),o=_vue.ref.call(void 0, null),n=e.subscribe(()=>{t.value={...e.getState()}});_vue.onUnmounted.call(void 0, n);let i=()=>t.value.values,l=()=>t.value.errors,f=()=>t.value.touched,y=()=>e.getDirtyValues(),r=_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:r,isDirty:c,isSubmitting:a,submitError:s,lastResponse:o},getValues:i,getErrors:l,getTouched:f,getDirtyValues:y,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()]),s.value=null,e.submit(async(I,d)=>{try{let u=await S(I,d);o.value=u,s.value=null}catch(u){_chunk4MPIKMTHcjs.h.call(void 0, u)?e.setServerErrors(_chunk4MPIKMTHcjs.i.call(void 0, u)):s.value=u instanceof Error?u:new Error(String(u))}})),reset:()=>{e.reset(),s.value=null,o.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 Y(e,t,s){let o=m();t&&o.registerField(e,t);let n=_nullishCoalesce(_optionalChain([s, 'optionalAccess', _6 => _6.mask]), () => (_optionalChain([o, 'access', _7 => _7.config, 'access', _8 => _8.fields, 'optionalAccess', _9 => _9[e], 'optionalAccess', _10 => _10.mask]))),i=n?typeof n=="string"?_optionalChain([o, 'access', _11 => _11.config, 'access', _12 => _12.masks, 'optionalAccess', _13 => _13[n]]):n:void 0,l=_vue.shallowRef.call(void 0, o.getState()),f=o.subscribe(()=>{l.value=o.getState()});_vue.onUnmounted.call(void 0, ()=>{f(),o.unregisterField&&o.unregisterField(e)});let y=_vue.computed.call(void 0, ()=>_chunk4MPIKMTHcjs.e.call(void 0, l.value.values,e)),r=_vue.computed.call(void 0, ()=>{let v=y.value;return v==null||v===""?"":i?i.format(v):String(v)}),a=_vue.computed.call(void 0, {get:()=>r.value,set:v=>{if(!i){o.setField(e,v);return}o.setField(e,i.parse(String(_nullishCoalesce(v, () => ("")))))}}),c=_vue.computed.call(void 0, ()=>l.value.errors[e]),g=_vue.computed.call(void 0, ()=>l.value.touched[e]?l.value.errors[e]:void 0),F=_vue.computed.call(void 0, ()=>!!l.value.touched[e]),E=_vue.computed.call(void 0, ()=>!!(F.value&&g.value)),S=_vue.computed.call(void 0, ()=>(l.value,o.isFieldValidating(e))),b=_vue.computed.call(void 0, ()=>(l.value,o.isFieldDirty(e))),I=_vue.computed.call(void 0, ()=>(l.value,o.isHidden(e))),d=_vue.computed.call(void 0, ()=>(l.value,o.isRequired(e))),u=_vue.computed.call(void 0, ()=>!!c.value),h=v=>{a.value=v},x=()=>o.blurField(e);return{value:y,displayValue:r,modelValue:a,setValue:h,setBlur:x,onInput:v=>{h(v)},onBlur:()=>{x()},meta:{error:g,touched:F,invalid:E,isValidating:S,isDirty:b,isHidden:I,isRequired:d,hasError:u}}}var V=()=>Math.random().toString(36).substring(2,9);function J(e){let t=m(),s=()=>{let r=_chunk4MPIKMTHcjs.e.call(void 0, t.getState().values,e);return Array.isArray(r)?r:[]},o=s(),n=_vue.ref.call(void 0, o),i=_vue.ref.call(void 0, o.map(V)),l=t.subscribe(()=>{let r=s();if(n.value=[...r],r.length!==i.value.length){let a=[...i.value];if(r.length>a.length){let c=r.length-a.length,g=Array.from({length:c},V);i.value=[...a,...g]}else i.value=a.slice(0,r.length)}});_vue.onUnmounted.call(void 0, ()=>{l(),t.unregisterPrefix&&t.unregisterPrefix(`${e}.`)});let f=_vue.computed.call(void 0, ()=>n.value.map((r,a)=>({key:i.value[a]||`temp-${a}`,value:r,index:a}))),y=_vue.computed.call(void 0, ()=>n.value.length);return{fields:f,length:y,append:r=>{i.value.push(V()),t.pushItem(e,r)},prepend:r=>{i.value.unshift(V()),t.prependItem(e,r)},insert:(r,a)=>{i.value.splice(r,0,V()),t.insertItem(e,r,a)},remove:r=>{i.value.splice(r,1),t.removeItem(e,r)},move:(r,a)=>{let c=[...i.value],[g]=c.splice(r,1);c.splice(a,0,g),i.value=c,t.moveItem(e,r,a)},swap:(r,a)=>{let c=[...i.value];[c[r],c[a]]=[c[a],c[r]],i.value=c,t.swapItems(e,r,a)},replace:r=>{i.value=r.map(V),t.setField(e,r)},clear:()=>{i.value=[],t.setField(e,[])}}}function Z(){let e=m(),t=_vue.shallowRef.call(void 0, e.getHistoryMetadata()),s=e.subscribe(()=>{t.value=e.getHistoryMetadata()});_vue.onUnmounted.call(void 0, s);let o=()=>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:o,redo:n}}function re(e,t){let s=Object.keys(e),o=Object.keys(t);return s.length!==o.length?!1:s.every(n=>e[n]===t[n])}function oe(e){let t=m(),s=_vue.ref.call(void 0, t.getStepStatus(e)),o;_vue.onMounted.call(void 0, ()=>{o=t.subscribe(()=>{let r=t.getStepStatus(e);(r.hasErrors!==s.value.hasErrors||r.isDirty!==s.value.isDirty||!re(r.errors,s.value.errors))&&(s.value=r)})}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([o, 'optionalCall', _14 => _14()])});let n=async()=>{let r=await t.validate({scope:e}),a=t.getStepErrors(e);return{valid:r,errors:a}},i=()=>t.getStepErrors(e),l=_vue.computed.call(void 0, ()=>!s.value.hasErrors),f=_vue.computed.call(void 0, ()=>s.value.isDirty),y=_vue.computed.call(void 0, ()=>s.value.errors);return{scopeName:e,status:s,errors:y,validate:n,getErrors:i,isValid:l,isDirty:f}}function ae(e,t){let s=Object.keys(e),o=Object.keys(t);return s.length!==o.length?!1:s.every(n=>e[n]===t[n])}function ue(e){let t=m(),s=_vue.ref.call(void 0, 0),o=_vue.computed.call(void 0, ()=>_nullishCoalesce(e[s.value], () => (""))),n=_vue.ref.call(void 0, t.getStepStatus(o.value)),i;_vue.watch.call(void 0, o,d=>{n.value=t.getStepStatus(d)});let l=()=>{let d=o.value,u=t.getStepStatus(d);(u.hasErrors!==n.value.hasErrors||u.isDirty!==n.value.isDirty||!ae(u.errors,n.value.errors))&&(n.value=u)};_vue.onMounted.call(void 0, ()=>{i=t.subscribe(l)}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([i, 'optionalCall', _15 => _15()])});let f=async()=>{let d=o.value,u=await t.validate({scope:d}),h=t.getStepErrors(d);return{valid:u,errors:h}},y=()=>t.getStepErrors(o.value),r=async()=>{let d=o.value,u=await t.validate({scope:d});if(u)s.value=Math.min(s.value+1,e.length-1);else{let h=t.getStepErrors(d),x=Object.keys(h);x.length>0&&t.markFieldsTouched(x)}return u},a=()=>{s.value=Math.max(s.value-1,0)},c=d=>{s.value=Math.max(0,Math.min(d-1,e.length-1))},g=_vue.computed.call(void 0, ()=>s.value+1),F=_vue.computed.call(void 0, ()=>s.value===0),E=_vue.computed.call(void 0, ()=>s.value>=e.length-1),S=_vue.computed.call(void 0, ()=>!n.value.hasErrors),b=_vue.computed.call(void 0, ()=>n.value.isDirty),I=_vue.computed.call(void 0, ()=>n.value.errors);return{step:g,stepIndex:s,scope:o,next:r,prev:a,goTo:c,isFirst:F,isLast:E,status:n,errors:I,isValid:S,isDirty:b,validate:f,getErrors:y}}function me(e){let t=m(),s=_chunk4MPIKMTHcjs.e.call(void 0, t.getState().values,e),o=_vue.ref.call(void 0, s),n=t.watch(e,i=>{_chunk4MPIKMTHcjs.d.call(void 0, o.value,i)||(o.value=i)});return _vue.onUnmounted.call(void 0, n),_vue.readonly.call(void 0, o)}exports.provideBitStore = z; exports.useBitArray = J; exports.useBitField = Y; exports.useBitForm = _; exports.useBitHistory = Z; exports.useBitScope = oe; exports.useBitSteps = ue; exports.useBitStore = m; exports.useBitWatch = me;
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 _chunkSIM4YIOWcjs = require('../chunk-SIM4YIOW.cjs');var _vue = require('vue');var M=Symbol("BIT_STORE");function z(e){_vue.provide.call(void 0, M,e)}function m(){let e=_vue.inject.call(void 0, M);if(!e)throw new Error("BitForm Vue hooks devem ser usados sob um provideBitStore");return e}function Y(){let e=m(),t=_vue.shallowRef.call(void 0, e.getState()),o=_vue.ref.call(void 0, null),s=_vue.ref.call(void 0, null),n=e.subscribe(()=>{t.value={...e.getState()}});_vue.onUnmounted.call(void 0, n);let i=()=>t.value.values,u=()=>t.value.errors,y=()=>t.value.touched,d=()=>e.getDirtyValues(),r=_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:r,isDirty:c,isSubmitting:a,submitError:o,lastResponse:s},getValues:i,getErrors:u,getTouched:y,getDirtyValues:d,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(I,p)=>{try{let l=await S(I,p);s.value=l,o.value=null}catch(l){_chunkSIM4YIOWcjs.h.call(void 0, l)?e.setServerErrors(_chunkSIM4YIOWcjs.i.call(void 0, l)):o.value=l instanceof Error?l:new Error(String(l))}})),reset:()=>{e.reset(),o.value=null,s.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 P(e,t,o){let s=m();t&&s.registerField(e,t);let n=_nullishCoalesce(_optionalChain([o, 'optionalAccess', _6 => _6.mask]), () => (_optionalChain([s, 'access', _7 => _7.config, 'access', _8 => _8.fields, 'optionalAccess', _9 => _9[e], 'optionalAccess', _10 => _10.mask]))),i=n?typeof n=="string"?_optionalChain([s, 'access', _11 => _11.config, 'access', _12 => _12.masks, 'optionalAccess', _13 => _13[n]]):n:void 0,u=_vue.shallowRef.call(void 0, s.getState()),y=s.subscribe(()=>{u.value=s.getState()});_vue.onUnmounted.call(void 0, ()=>{y(),s.unregisterField&&s.unregisterField(e)});let d=_vue.computed.call(void 0, ()=>_chunkSIM4YIOWcjs.e.call(void 0, u.value.values,e)),r=_vue.computed.call(void 0, ()=>{let v=d.value;return v==null||v===""?"":i?i.format(v):String(v)}),a=_vue.computed.call(void 0, {get:()=>r.value,set:v=>{if(!i){s.setField(e,v);return}s.setField(e,i.parse(String(_nullishCoalesce(v, () => ("")))))}}),c=_vue.computed.call(void 0, ()=>u.value.errors[e]),g=_vue.computed.call(void 0, ()=>u.value.touched[e]?u.value.errors[e]:void 0),E=_vue.computed.call(void 0, ()=>!!u.value.touched[e]),x=_vue.computed.call(void 0, ()=>!!(E.value&&g.value)),S=_vue.computed.call(void 0, ()=>(u.value,s.isFieldValidating(e))),B=_vue.computed.call(void 0, ()=>(u.value,s.isFieldDirty(e))),I=_vue.computed.call(void 0, ()=>(u.value,s.isHidden(e))),p=_vue.computed.call(void 0, ()=>(u.value,s.isRequired(e))),l=_vue.computed.call(void 0, ()=>!!c.value),b=v=>{a.value=v},T=()=>s.blurField(e);return{value:d,displayValue:r,modelValue:a,setValue:b,setBlur:T,onInput:v=>{b(v)},onBlur:()=>{T()},meta:{error:g,touched:E,invalid:x,isValidating:S,isDirty:B,isHidden:I,isRequired:p,hasError:l}}}var h=()=>Math.random().toString(36).substring(2,9);function X(e){let t=m(),o=()=>{let r=_chunkSIM4YIOWcjs.e.call(void 0, t.getState().values,e);return Array.isArray(r)?r:[]},s=o(),n=_vue.ref.call(void 0, s),i=_vue.ref.call(void 0, s.map(h)),u=t.subscribe(()=>{let r=o();if(n.value=[...r],r.length!==i.value.length){let a=[...i.value];if(r.length>a.length){let c=r.length-a.length,g=Array.from({length:c},h);i.value=[...a,...g]}else i.value=a.slice(0,r.length)}});_vue.onUnmounted.call(void 0, ()=>{u(),t.unregisterPrefix&&t.unregisterPrefix(`${e}.`)});let y=_vue.computed.call(void 0, ()=>n.value.map((r,a)=>({key:i.value[a]||`temp-${a}`,value:r,index:a}))),d=_vue.computed.call(void 0, ()=>n.value.length);return{fields:y,length:d,append:r=>{i.value.push(h()),t.pushItem(e,r)},prepend:r=>{i.value.unshift(h()),t.prependItem(e,r)},insert:(r,a)=>{i.value.splice(r,0,h()),t.insertItem(e,r,a)},remove:r=>{i.value.splice(r,1),t.removeItem(e,r)},move:(r,a)=>{let c=[...i.value],[g]=c.splice(r,1);c.splice(a,0,g),i.value=c,t.moveItem(e,r,a)},swap:(r,a)=>{let c=[...i.value];[c[r],c[a]]=[c[a],c[r]],i.value=c,t.swapItems(e,r,a)},replace:r=>{i.value=r.map(h),t.setField(e,r)},clear:()=>{i.value=[],t.setField(e,[])}}}function ee(){let e=m(),t=_vue.shallowRef.call(void 0, e.getHistoryMetadata()),o=e.subscribe(()=>{t.value=e.getHistoryMetadata()});_vue.onUnmounted.call(void 0, o);let s=()=>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:s,redo:n}}function oe(e,t){let o=Object.keys(e),s=Object.keys(t);return o.length!==s.length?!1:o.every(n=>e[n]===t[n])}function ne(e){let t=m(),o=_vue.ref.call(void 0, t.getStepStatus(e)),s;_vue.onMounted.call(void 0, ()=>{s=t.subscribe(()=>{let r=t.getStepStatus(e);(r.hasErrors!==o.value.hasErrors||r.isDirty!==o.value.isDirty||!oe(r.errors,o.value.errors))&&(o.value=r)})}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([s, 'optionalCall', _14 => _14()])});let n=async()=>{let r=await t.validate({scope:e}),a=t.getStepErrors(e);return{valid:r,errors:a}},i=()=>t.getStepErrors(e),u=_vue.computed.call(void 0, ()=>!o.value.hasErrors),y=_vue.computed.call(void 0, ()=>o.value.isDirty),d=_vue.computed.call(void 0, ()=>o.value.errors);return{scopeName:e,status:o,errors:d,validate:n,getErrors:i,isValid:u,isDirty:y}}function le(e,t){let o=Object.keys(e),s=Object.keys(t);return o.length!==s.length?!1:o.every(n=>e[n]===t[n])}function ce(e){let t=m(),o=_vue.ref.call(void 0, 0),s=_vue.computed.call(void 0, ()=>_nullishCoalesce(e[o.value], () => (""))),n=_vue.ref.call(void 0, t.getStepStatus(s.value)),i;_vue.watch.call(void 0, s,p=>{n.value=t.getStepStatus(p)});let u=()=>{let p=s.value,l=t.getStepStatus(p);(l.hasErrors!==n.value.hasErrors||l.isDirty!==n.value.isDirty||!le(l.errors,n.value.errors))&&(n.value=l)};_vue.onMounted.call(void 0, ()=>{i=t.subscribe(u)}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([i, 'optionalCall', _15 => _15()])});let y=async()=>{let p=s.value,l=await t.validate({scope:p}),b=t.getStepErrors(p);return{valid:l,errors:b}},d=()=>t.getStepErrors(s.value),r=async()=>{let p=s.value,l=_optionalChain([t, 'access', _16 => _16.getConfig, 'call', _17 => _17(), 'access', _18 => _18.scopes, 'optionalAccess', _19 => _19[p]]);if(t.hasValidationsInProgress(l))return!1;let b=await t.validate({scope:p});if(b)o.value=Math.min(o.value+1,e.length-1);else{let T=t.getStepErrors(p),R=Object.keys(T);R.length>0&&t.markFieldsTouched(R)}return b},a=()=>{o.value=Math.max(o.value-1,0)},c=p=>{o.value=Math.max(0,Math.min(p-1,e.length-1))},g=_vue.computed.call(void 0, ()=>o.value+1),E=_vue.computed.call(void 0, ()=>o.value===0),x=_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),I=_vue.computed.call(void 0, ()=>n.value.errors);return{step:g,stepIndex:o,scope:s,next:r,prev:a,goTo:c,isFirst:E,isLast:x,status:n,errors:I,isValid:S,isDirty:B,validate:y,getErrors:d}}function ve(e){let t=m(),o=_chunkSIM4YIOWcjs.e.call(void 0, t.getState().values,e),s=_vue.ref.call(void 0, o),n=t.watch(e,i=>{_chunkSIM4YIOWcjs.d.call(void 0, s.value,i)||(s.value=i)});return _vue.onUnmounted.call(void 0, n),_vue.readonly.call(void 0, s)}function fe(e,t,o){let s=m(),n=P(e),i=null,u=async d=>{if(d){s.beginFieldValidation(e),await s.clearFieldAsyncError(e);try{let r=await t(d);n.setValue(r.url),i=r.key,await s.clearFieldAsyncError(e)}catch(r){let a=r instanceof Error?r.message:"Upload failed";await s.setFieldAsyncError(e,a)}finally{s.endFieldValidation(e)}}},y=async()=>{if(i&&o)try{await o(i)}catch(d){let r=d instanceof Error?d.message:"Delete failed";await s.setFieldAsyncError(e,r);return}n.setValue(null),i=null,await s.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:u,remove:y}}exports.provideBitStore = z; exports.useBitArray = X; exports.useBitField = P; exports.useBitForm = Y; exports.useBitHistory = ee; exports.useBitScope = ne; exports.useBitSteps = ce; exports.useBitStore = m; exports.useBitUpload = fe; exports.useBitWatch = ve;
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","config","options","maskOption","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,CAA6C,MAAA,CAAO,WAAW,CAAA,CAErE,SAASC,CAAAA,CAAgBC,CAAAA,CAAsB,CACpDC,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,CCjBA,SAIgBI,CAAAA,CAAAA,CAA+B,CAC7C,IAAMJ,CAAAA,CAAQE,CAAAA,CAAe,CAAA,CACvBG,CAAAA,CAAQC,6BAAAA,CAAWN,CAAM,QAAA,CAAS,CAAC,CAAA,CACnCO,CAAAA,CAAcC,sBAAAA,IAAsB,CAAA,CACpCC,CAAAA,CAAeD,sBAAAA,IAAiB,CAAA,CAEhCE,CAAAA,CAAcV,CAAAA,CAAM,SAAA,CAAU,CAAA,CAAA,EAAM,CACxCK,CAAAA,CAAM,KAAA,CAAQ,CAAE,GAAGL,CAAAA,CAAM,QAAA,CAAS,CAAE,CACtC,CAAC,CAAA,CAEDW,8BAAAA,CAAuB,CAAA,CAEvB,IAAMC,CAAAA,CAAY,CAAA,CAAA,EAAMP,CAAAA,CAAM,KAAA,CAAM,MAAA,CAC9BQ,CAAAA,CAAY,CAAA,C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C,CAAA,KACEJ,CAAAA,CAAI,KAAA,CAAQE,CAAAA,CAAW,KAAA,CAAM,CAAA,CAAGD,CAAAA,CAAU,MAAM,CAEpD,CACF,CAAC,CAAA,CAED5C,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 { BitStore } from \"../core/store\";\n\n// Chave única para evitar colisões\nexport const BIT_STORE_KEY: InjectionKey<BitStore<any>> = Symbol(\"BIT_STORE\");\n\nexport function provideBitStore(store: BitStore<any>) {\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 BitStore<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 { BitFieldOptions, BitFieldDefinition, getDeepValue } from \"../core\";\n\nexport interface UseBitFieldVueMeta {\n error: Readonly<any>;\n touched: Readonly<any>;\n invalid: Readonly<any>;\n isValidating: Readonly<any>;\n isDirty: Readonly<any>;\n isHidden: Readonly<any>;\n isRequired: Readonly<any>;\n hasError: Readonly<any>;\n}\n\nexport interface UseBitFieldVueResult<TValue = any> {\n // Main handlers and values (flat)\n value: Readonly<any>;\n displayValue: Readonly<any>;\n modelValue: any;\n setValue: (val: any) => void;\n setBlur: () => void;\n onInput: (val: any) => void;\n onBlur: () => void;\n // Metadata (grouped)\n meta: UseBitFieldVueMeta;\n}\n\nexport function useBitField<TValue = any>(\n path: string,\n config?: BitFieldDefinition<any>,\n options?: BitFieldOptions,\n): UseBitFieldVueResult<TValue> {\n const store = useBitStore<any>();\n\n if (config) {\n store.registerField(path as string, config as any);\n }\n\n const maskOption =\n options?.mask ?? store.config.fields?.[path as string]?.mask;\n const resolvedMask = maskOption\n ? typeof maskOption === \"string\"\n ? store.config.masks?.[maskOption]\n : maskOption\n : undefined;\n\n const 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","onUnmounted","getValues","getErrors","getTouched","getDirtyValues","isValid","computed","isSubmitting","isDirty","onSuccess","e","handler","values","dirtyValues","result","err","isValidationErrorShape","extractServerErrors","useBitField","path","config","options","maskOption","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,MAAM,IAAI,KAAA,CACR,2DACF,CAAA,CACF,OAAOA,CACT,CClBA,SAIgBI,CAAAA,CA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,CAFA7B,CAAAA,CAAO,KAAA,CAAQ,CAAC,GAAGgC,CAAS,CAAA,CAExBA,CAAAA,CAAU,MAAA,GAAWD,CAAAA,CAAI,KAAA,CAAM,MAAA,CAAQ,CACzC,IAAME,CAAAA,CAAa,CAAC,GAAGF,CAAAA,CAAI,KAAK,CAAA,CAChC,EAAA,CAAIC,CAAAA,CAAU,MAAA,CAASC,CAAAA,CAAW,MAAA,CAAQ,CACxC,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,CAED5C,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 { BitFieldOptions, BitFieldDefinition, getDeepValue } from \"../core\";\nimport type { UseBitFieldVueMeta, UseBitFieldVueResult } from \"./types\";\n\nexport function useBitField<TValue = any>(\n path: string,\n config?: BitFieldDefinition<any>,\n options?: BitFieldOptions,\n): UseBitFieldVueResult<TValue> {\n const store = useBitStore<any>();\n\n if (config) {\n store.registerField(path as string, config as any);\n }\n\n const maskOption =\n options?.mask ?? store.config.fields?.[path as string]?.mask;\n const resolvedMask = maskOption\n ? typeof maskOption === \"string\"\n ? store.config.masks?.[maskOption]\n : maskOption\n : undefined;\n\n const 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"]}