@lehnihon/bit-form 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/angular/index.cjs +1 -1
- package/dist/angular/index.cjs.map +1 -1
- package/dist/angular/index.d.cts +72 -46
- package/dist/angular/index.d.ts +72 -46
- package/dist/angular/index.js +1 -1
- package/dist/angular/index.js.map +1 -1
- package/dist/bus-vCbulIYH.d.cts +141 -0
- package/dist/bus-vCbulIYH.d.ts +141 -0
- package/dist/chunk-2QNUW6ZN.cjs +133 -0
- package/dist/chunk-2QNUW6ZN.cjs.map +1 -0
- package/dist/chunk-F6LJWWEW.js +2 -0
- package/dist/chunk-F6LJWWEW.js.map +1 -0
- package/dist/chunk-LPRLSFPT.cjs +2 -0
- package/dist/chunk-LPRLSFPT.cjs.map +1 -0
- package/dist/chunk-N6IA7HQL.js +133 -0
- package/dist/chunk-N6IA7HQL.js.map +1 -0
- package/dist/devtools/bridge.cjs +1 -1
- package/dist/devtools/bridge.js +1 -1
- package/dist/devtools/index.cjs +1 -1
- package/dist/devtools/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -24
- package/dist/index.d.ts +5 -24
- package/dist/index.js +1 -1
- package/dist/public-types-ChP5j3xc.d.ts +69 -0
- package/dist/public-types-Nv__uZTR.d.cts +69 -0
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +7 -47
- package/dist/react/index.d.ts +7 -47
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-native/index.cjs +1 -1
- package/dist/react-native/index.cjs.map +1 -1
- package/dist/react-native/index.d.cts +16 -5
- package/dist/react-native/index.d.ts +16 -5
- package/dist/react-native/index.js +1 -1
- package/dist/react-native/index.js.map +1 -1
- package/dist/resolvers/joi.d.cts +1 -1
- package/dist/resolvers/joi.d.ts +1 -1
- package/dist/resolvers/yup.d.cts +1 -1
- package/dist/resolvers/yup.d.ts +1 -1
- package/dist/resolvers/zod.d.cts +1 -1
- package/dist/resolvers/zod.d.ts +1 -1
- package/dist/{use-bit-watch-iCGj-kYp.d.ts → use-bit-watch-BRekIj2W.d.cts} +92 -28
- package/dist/{use-bit-watch-BLCTa7d4.d.cts → use-bit-watch-hA0AqCkC.d.ts} +92 -28
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.cts +66 -46
- package/dist/vue/index.d.ts +66 -46
- package/dist/vue/index.js +1 -1
- package/dist/vue/index.js.map +1 -1
- package/package.json +7 -2
- package/dist/bus-uG4EmM-Z.d.cts +0 -295
- package/dist/bus-uG4EmM-Z.d.ts +0 -295
- package/dist/chunk-ET36BANJ.js +0 -2
- package/dist/chunk-ET36BANJ.js.map +0 -1
- package/dist/chunk-NDFMZWBP.js +0 -133
- package/dist/chunk-NDFMZWBP.js.map +0 -1
- package/dist/chunk-PCVPCFPX.cjs +0 -2
- package/dist/chunk-PCVPCFPX.cjs.map +0 -1
- package/dist/chunk-VFLQH47Q.cjs +0 -133
- package/dist/chunk-VFLQH47Q.cjs.map +0 -1
- package/dist/index-1fP1eJH8.d.ts +0 -211
- package/dist/index-9vxGUNPP.d.cts +0 -211
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export { B as BitFormProvider, u as useBitArray,
|
|
2
|
-
import {
|
|
3
|
-
export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-
|
|
1
|
+
export { B as BitFormProvider, u as useBitArray, f as useBitForm, g as useBitScope, h as useBitSteps, i as useBitStore, j as useBitWatch } from '../use-bit-watch-BRekIj2W.cjs';
|
|
2
|
+
import { j as BitPath, k as BitPathValue } from '../bus-vCbulIYH.cjs';
|
|
3
|
+
export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-vCbulIYH.cjs';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
|
6
|
-
import '../
|
|
6
|
+
import '../public-types-Nv__uZTR.cjs';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Metadata describing the current state of a form field (React Native).
|
|
10
|
+
*/
|
|
8
11
|
interface UseBitFieldNativeMeta {
|
|
9
12
|
error: string | undefined;
|
|
10
13
|
touched: boolean;
|
|
@@ -15,11 +18,18 @@ interface UseBitFieldNativeMeta {
|
|
|
15
18
|
isRequired: boolean;
|
|
16
19
|
hasError: boolean;
|
|
17
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Props that can be spread onto a React Native input component.
|
|
23
|
+
*/
|
|
18
24
|
interface UseBitFieldNativeBindProps {
|
|
19
25
|
value: string;
|
|
20
26
|
onChangeText: (value: string) => void;
|
|
21
27
|
onBlur: () => void;
|
|
22
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Result from useBitField hook in React Native.
|
|
31
|
+
* Provides field state, value, handlers, and metadata for native mobile development.
|
|
32
|
+
*/
|
|
23
33
|
interface UseBitFieldNativeResult<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>> {
|
|
24
34
|
field: {
|
|
25
35
|
value: BitPathValue<TForm, P>;
|
|
@@ -32,6 +42,7 @@ interface UseBitFieldNativeResult<TForm extends object = any, P extends BitPath<
|
|
|
32
42
|
meta: UseBitFieldNativeMeta;
|
|
33
43
|
props: UseBitFieldNativeBindProps;
|
|
34
44
|
}
|
|
35
|
-
|
|
45
|
+
|
|
46
|
+
declare function useBitField<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>>(path: P): UseBitFieldNativeResult<TForm, P>;
|
|
36
47
|
|
|
37
48
|
export { type UseBitFieldNativeBindProps, type UseBitFieldNativeMeta, type UseBitFieldNativeResult, useBitField };
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export { B as BitFormProvider, u as useBitArray,
|
|
2
|
-
import {
|
|
3
|
-
export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-
|
|
1
|
+
export { B as BitFormProvider, u as useBitArray, f as useBitForm, g as useBitScope, h as useBitSteps, i as useBitStore, j as useBitWatch } from '../use-bit-watch-hA0AqCkC.js';
|
|
2
|
+
import { j as BitPath, k as BitPathValue } from '../bus-vCbulIYH.js';
|
|
3
|
+
export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-vCbulIYH.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
|
6
|
-
import '../
|
|
6
|
+
import '../public-types-ChP5j3xc.js';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Metadata describing the current state of a form field (React Native).
|
|
10
|
+
*/
|
|
8
11
|
interface UseBitFieldNativeMeta {
|
|
9
12
|
error: string | undefined;
|
|
10
13
|
touched: boolean;
|
|
@@ -15,11 +18,18 @@ interface UseBitFieldNativeMeta {
|
|
|
15
18
|
isRequired: boolean;
|
|
16
19
|
hasError: boolean;
|
|
17
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Props that can be spread onto a React Native input component.
|
|
23
|
+
*/
|
|
18
24
|
interface UseBitFieldNativeBindProps {
|
|
19
25
|
value: string;
|
|
20
26
|
onChangeText: (value: string) => void;
|
|
21
27
|
onBlur: () => void;
|
|
22
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Result from useBitField hook in React Native.
|
|
31
|
+
* Provides field state, value, handlers, and metadata for native mobile development.
|
|
32
|
+
*/
|
|
23
33
|
interface UseBitFieldNativeResult<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>> {
|
|
24
34
|
field: {
|
|
25
35
|
value: BitPathValue<TForm, P>;
|
|
@@ -32,6 +42,7 @@ interface UseBitFieldNativeResult<TForm extends object = any, P extends BitPath<
|
|
|
32
42
|
meta: UseBitFieldNativeMeta;
|
|
33
43
|
props: UseBitFieldNativeBindProps;
|
|
34
44
|
}
|
|
35
|
-
|
|
45
|
+
|
|
46
|
+
declare function useBitField<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>>(path: P): UseBitFieldNativeResult<TForm, P>;
|
|
36
47
|
|
|
37
48
|
export { type UseBitFieldNativeBindProps, type UseBitFieldNativeMeta, type UseBitFieldNativeResult, useBitField };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as S,b as T,c as V,d as B,e as N,f as U,g as M,h as R}from"../chunk-F6LJWWEW.js";import"../chunk-N6IA7HQL.js";import{useMemo as f,useCallback as u}from"react";function k(i){let{fieldState:o,setValue:r,setBlur:s,store:a}=B(i),t=f(()=>a.resolveMask(i),[a.config.masks,a.config.fields,i]),d=f(()=>{let e=o.value;return e==null||e===""?"":t?t.format(e):String(e)},[o.value,t]),m=u(e=>{if(!t){r(e);return}r(t.parse(String(e??"")))},[t,r]),c=u(e=>{if(!t){r(e);return}r(t.parse(String(e??"")))},[t,r]),{isHidden:F,isRequired:v,value:P,error:n,touched:l,isDirty:x,isValidating:y}=o,g=!!(l&&n),h=l?n:void 0,p=u(()=>{s()},[s]);return{field:{value:P,displayValue:d,setValue:c,setBlur:s,onChangeText:m,onBlur:p},meta:{error:h,touched:l,invalid:g,isValidating:y,isDirty:x,isHidden:F,isRequired:v,hasError:!!n},props:{value:d,onChangeText:m,onBlur:p}}}export{S as BitFormProvider,N as useBitArray,k as useBitField,V as useBitForm,U as useBitScope,M as useBitSteps,T as useBitStore,R as useBitWatch};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react-native/use-bit-field.ts"],"sourcesContent":["import { useMemo, useCallback } from \"react\";\nimport { useBitFieldBase } from \"../react/use-bit-field-base\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/react-native/use-bit-field.ts"],"sourcesContent":["import { useMemo, useCallback } from \"react\";\nimport { useBitFieldBase } from \"../react/use-bit-field-base\";\nimport { BitPath, BitPathValue } from \"../core\";\nimport type {\n UseBitFieldNativeMeta,\n UseBitFieldNativeBindProps,\n UseBitFieldNativeResult,\n} from \"./types\";\n\nexport function useBitField<\n TForm extends object = any,\n P extends BitPath<TForm> = BitPath<TForm>,\n>(path: P): UseBitFieldNativeResult<TForm, P> {\n const {\n fieldState,\n setValue: rawSetValue,\n setBlur,\n store,\n } = useBitFieldBase<BitPathValue<TForm, P>, TForm, P>(path);\n\n const resolvedMask = useMemo(() => {\n return store.resolveMask(path as string);\n }, [store.config.masks, store.config.fields, path]);\n\n const displayValue = useMemo(() => {\n const val = fieldState.value;\n if (val === undefined || val === null || val === \"\") return \"\";\n\n return resolvedMask ? resolvedMask.format(val) : String(val);\n }, [fieldState.value, resolvedMask]);\n\n const handleChange = useCallback(\n (text: string) => {\n if (!resolvedMask) {\n rawSetValue(text as any);\n return;\n }\n\n rawSetValue(resolvedMask.parse(String(text ?? \"\")) as any);\n },\n [resolvedMask, rawSetValue],\n );\n\n const setValue = useCallback(\n (val: any) => {\n if (!resolvedMask) {\n rawSetValue(val);\n return;\n }\n\n rawSetValue(resolvedMask.parse(String(val ?? \"\")) as any);\n },\n [resolvedMask, rawSetValue],\n );\n\n const { isHidden, isRequired, value, error, touched, isDirty, isValidating } =\n fieldState;\n const invalid = !!(touched && error);\n const visibleError = touched ? error : undefined;\n\n const onBlur = useCallback(() => {\n setBlur();\n }, [setBlur]);\n\n return {\n field: {\n value: value as BitPathValue<TForm, P>,\n displayValue,\n setValue,\n setBlur,\n onChangeText: handleChange,\n onBlur,\n },\n meta: {\n error: visibleError,\n touched,\n invalid,\n isValidating,\n isDirty,\n isHidden,\n isRequired,\n hasError: !!error,\n },\n props: {\n value: displayValue,\n onChangeText: handleChange,\n onBlur,\n },\n };\n}\n"],"mappings":"uHAAA,OAAS,WAAAA,EAAS,eAAAC,MAAmB,QAS9B,SAASC,EAGdC,EAA4C,CAC5C,GAAM,CACJ,WAAAC,EACA,SAAUC,EACV,QAAAC,EACA,MAAAC,CACF,EAAIC,EAAkDL,CAAI,EAEpDM,EAAeC,EAAQ,IACpBH,EAAM,YAAYJ,CAAc,EACtC,CAACI,EAAM,OAAO,MAAOA,EAAM,OAAO,OAAQJ,CAAI,CAAC,EAE5CQ,EAAeD,EAAQ,IAAM,CACjC,IAAME,EAAMR,EAAW,MACvB,OAAyBQ,GAAQ,MAAQA,IAAQ,GAAW,GAErDH,EAAeA,EAAa,OAAOG,CAAG,EAAI,OAAOA,CAAG,CAC7D,EAAG,CAACR,EAAW,MAAOK,CAAY,CAAC,EAE7BI,EAAeC,EAClBC,GAAiB,CAChB,GAAI,CAACN,EAAc,CACjBJ,EAAYU,CAAW,EACvB,MACF,CAEAV,EAAYI,EAAa,MAAM,OAAOM,GAAQ,EAAE,CAAC,CAAQ,CAC3D,EACA,CAACN,EAAcJ,CAAW,CAC5B,EAEMW,EAAWF,EACdF,GAAa,CACZ,GAAI,CAACH,EAAc,CACjBJ,EAAYO,CAAG,EACf,MACF,CAEAP,EAAYI,EAAa,MAAM,OAAOG,GAAO,EAAE,CAAC,CAAQ,CAC1D,EACA,CAACH,EAAcJ,CAAW,CAC5B,EAEM,CAAE,SAAAY,EAAU,WAAAC,EAAY,MAAAC,EAAO,MAAAC,EAAO,QAAAC,EAAS,QAAAC,EAAS,aAAAC,CAAa,EACzEnB,EACIoB,EAAU,CAAC,EAAEH,GAAWD,GACxBK,EAAeJ,EAAUD,EAAQ,OAEjCM,EAASZ,EAAY,IAAM,CAC/BR,EAAQ,CACV,EAAG,CAACA,CAAO,CAAC,EAEZ,MAAO,CACL,MAAO,CACL,MAAOa,EACP,aAAAR,EACA,SAAAK,EACA,QAAAV,EACA,aAAcO,EACd,OAAAa,CACF,EACA,KAAM,CACJ,MAAOD,EACP,QAAAJ,EACA,QAAAG,EACA,aAAAD,EACA,QAAAD,EACA,SAAAL,EACA,WAAAC,EACA,SAAU,CAAC,CAACE,CACd,EACA,MAAO,CACL,MAAOT,EACP,aAAcE,EACd,OAAAa,CACF,CACF,CACF","names":["useMemo","useCallback","useBitField","path","fieldState","rawSetValue","setBlur","store","useBitFieldBase","resolvedMask","useMemo","displayValue","val","handleChange","useCallback","text","setValue","isHidden","isRequired","value","error","touched","isDirty","isValidating","invalid","visibleError","onBlur"]}
|
package/dist/resolvers/joi.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ObjectSchema } from 'joi';
|
|
2
|
-
import {
|
|
2
|
+
import { e as BitErrors } from '../bus-vCbulIYH.cjs';
|
|
3
3
|
|
|
4
4
|
declare const joiResolver: <T extends object>(schema: ObjectSchema<T>) => (values: T, options?: {
|
|
5
5
|
scopeFields?: string[];
|
package/dist/resolvers/joi.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ObjectSchema } from 'joi';
|
|
2
|
-
import {
|
|
2
|
+
import { e as BitErrors } from '../bus-vCbulIYH.js';
|
|
3
3
|
|
|
4
4
|
declare const joiResolver: <T extends object>(schema: ObjectSchema<T>) => (values: T, options?: {
|
|
5
5
|
scopeFields?: string[];
|
package/dist/resolvers/yup.d.cts
CHANGED
package/dist/resolvers/yup.d.ts
CHANGED
package/dist/resolvers/zod.d.cts
CHANGED
package/dist/resolvers/zod.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { b as BitFrameworkStore } from './public-types-Nv__uZTR.cjs';
|
|
4
|
+
import { e as BitErrors, m as BitTouched, j as BitPath, k as BitPathValue, S as ScopeStatus, V as ValidateScopeResult, c as BitArrayPath, b as BitArrayItem } from './bus-vCbulIYH.cjs';
|
|
5
5
|
|
|
6
6
|
declare const BitFormProvider: ({ store, children, }: {
|
|
7
|
-
store:
|
|
7
|
+
store: BitFrameworkStore<any>;
|
|
8
8
|
children: React.ReactNode;
|
|
9
9
|
}) => react_jsx_runtime.JSX.Element;
|
|
10
|
-
declare const useBitStore: <T extends object>() =>
|
|
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: (
|
|
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:
|
|
43
|
-
removeItem:
|
|
44
|
-
prependItem:
|
|
45
|
-
insertItem:
|
|
46
|
-
moveItem:
|
|
47
|
-
swapItems:
|
|
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
|
|
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 {
|
|
4
|
-
import {
|
|
3
|
+
import { b as BitFrameworkStore } from './public-types-ChP5j3xc.js';
|
|
4
|
+
import { e as BitErrors, m as BitTouched, j as BitPath, k as BitPathValue, S as ScopeStatus, V as ValidateScopeResult, c as BitArrayPath, b as BitArrayItem } from './bus-vCbulIYH.js';
|
|
5
5
|
|
|
6
6
|
declare const BitFormProvider: ({ store, children, }: {
|
|
7
|
-
store:
|
|
7
|
+
store: BitFrameworkStore<any>;
|
|
8
8
|
children: React.ReactNode;
|
|
9
9
|
}) => react_jsx_runtime.JSX.Element;
|
|
10
|
-
declare const useBitStore: <T extends object>() =>
|
|
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: (
|
|
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:
|
|
43
|
-
removeItem:
|
|
44
|
-
prependItem:
|
|
45
|
-
insertItem:
|
|
46
|
-
moveItem:
|
|
47
|
-
swapItems:
|
|
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
|
|
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 };
|
package/dist/vue/index.cjs
CHANGED
|
@@ -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
|
|
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 _chunk2QNUW6ZNcjs = require('../chunk-2QNUW6ZN.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 L(){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,v=()=>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),u=_vue.computed.call(void 0, ()=>t.value.isDirty);return{meta:{isValid:r,isDirty:u,isSubmitting:a,submitError:s,lastResponse:o},getValues:i,getErrors:v,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()]),s.value=null,e.submit(async(F,l)=>{try{let c=await S(F,l);o.value=c,s.value=null}catch(c){_chunk2QNUW6ZNcjs.h.call(void 0, c)?e.setServerErrors(_chunk2QNUW6ZNcjs.i.call(void 0, c)):s.value=c instanceof Error?c:new Error(String(c))}})),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 R(e){let t=m(),s=t.resolveMask(e),o=_vue.shallowRef.call(void 0, t.getState()),n=t.subscribe(()=>{o.value=t.getState()});_vue.onUnmounted.call(void 0, ()=>{n(),t.unregisterField&&t.unregisterField(e)});let i=_vue.computed.call(void 0, ()=>_chunk2QNUW6ZNcjs.e.call(void 0, o.value.values,e)),v=_vue.computed.call(void 0, ()=>{let p=i.value;return p==null||p===""?"":s?s.format(p):String(p)}),y=_vue.computed.call(void 0, {get:()=>v.value,set:p=>{if(!s){t.setField(e,p);return}t.setField(e,s.parse(String(_nullishCoalesce(p, () => ("")))))}}),d=_vue.computed.call(void 0, ()=>o.value.errors[e]),r=_vue.computed.call(void 0, ()=>o.value.touched[e]?o.value.errors[e]:void 0),a=_vue.computed.call(void 0, ()=>!!o.value.touched[e]),u=_vue.computed.call(void 0, ()=>!!(a.value&&r.value)),g=_vue.computed.call(void 0, ()=>(o.value,t.isFieldValidating(e))),I=_vue.computed.call(void 0, ()=>(o.value,t.isFieldDirty(e))),x=_vue.computed.call(void 0, ()=>(o.value,t.isHidden(e))),S=_vue.computed.call(void 0, ()=>(o.value,t.isRequired(e))),B=_vue.computed.call(void 0, ()=>!!d.value),F=p=>{y.value=p},l=()=>t.blurField(e);return{value:i,displayValue:v,modelValue:y,setValue:F,setBlur:l,onInput:p=>{F(p)},onBlur:()=>{l()},meta:{error:r,touched:a,invalid:u,isValidating:g,isDirty:I,isHidden:x,isRequired:S,hasError:B}}}var h=()=>Math.random().toString(36).substring(2,9);function Q(e){let t=m(),s=()=>{let r=_chunk2QNUW6ZNcjs.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(h)),v=t.subscribe(()=>{let r=s();if(n.value=[...r],r.length!==i.value.length){let a=[...i.value];if(r.length>a.length){let u=r.length-a.length,g=Array.from({length:u},h);i.value=[...a,...g]}else i.value=a.slice(0,r.length)}});_vue.onUnmounted.call(void 0, ()=>{v(),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 u=[...i.value],[g]=u.splice(r,1);u.splice(a,0,g),i.value=u,t.moveItem(e,r,a)},swap:(r,a)=>{let u=[...i.value];[u[r],u[a]]=[u[a],u[r]],i.value=u,t.swapItems(e,r,a)},replace:r=>{i.value=r.map(h),t.setField(e,r)},clear:()=>{i.value=[],t.setField(e,[])}}}function N(){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 se(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||!se(r.errors,s.value.errors))&&(s.value=r)})}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([o, 'optionalCall', _6 => _6()])});let n=async()=>{let r=await t.validate({scope:e}),a=t.getStepErrors(e);return{valid:r,errors:a}},i=()=>t.getStepErrors(e),v=_vue.computed.call(void 0, ()=>!s.value.hasErrors),y=_vue.computed.call(void 0, ()=>s.value.isDirty),d=_vue.computed.call(void 0, ()=>s.value.errors);return{scopeName:e,status:s,errors:d,validate:n,getErrors:i,isValid:v,isDirty:y}}function ue(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 le(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,l=>{n.value=t.getStepStatus(l)});let v=()=>{let l=o.value,c=t.getStepStatus(l);(c.hasErrors!==n.value.hasErrors||c.isDirty!==n.value.isDirty||!ue(c.errors,n.value.errors))&&(n.value=c)};_vue.onMounted.call(void 0, ()=>{i=t.subscribe(v)}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([i, 'optionalCall', _7 => _7()])});let y=async()=>{let l=o.value,c=await t.validate({scope:l}),E=t.getStepErrors(l);return{valid:c,errors:E}},d=()=>t.getStepErrors(o.value),r=async()=>{let l=o.value,c=t.getScopeFields(l);if(t.hasValidationsInProgress(c))return!1;let E=await t.validate({scope:l});if(E)s.value=Math.min(s.value+1,e.length-1);else{let p=t.getStepErrors(l),P=Object.keys(p);P.length>0&&t.markFieldsTouched(P)}return E},a=()=>{s.value=Math.max(s.value-1,0)},u=l=>{s.value=Math.max(0,Math.min(l-1,e.length-1))},g=_vue.computed.call(void 0, ()=>s.value+1),I=_vue.computed.call(void 0, ()=>s.value===0),x=_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),F=_vue.computed.call(void 0, ()=>n.value.errors);return{step:g,stepIndex:s,scope:o,next:r,prev:a,goTo:u,isFirst:I,isLast:x,status:n,errors:F,isValid:S,isDirty:B,validate:y,getErrors:d}}function pe(e){let t=m(),s=_chunk2QNUW6ZNcjs.e.call(void 0, t.getState().values,e),o=_vue.ref.call(void 0, s),n=t.watch(e,i=>{_chunk2QNUW6ZNcjs.d.call(void 0, o.value,i)||(o.value=i)});return _vue.onUnmounted.call(void 0, n),_vue.readonly.call(void 0, o)}function ve(e,t,s){let o=m(),n=R(e),i=null,v=async d=>{if(d){o.beginFieldValidation(e),await o.clearFieldAsyncError(e);try{let r=await t(d);n.setValue(r.url),i=r.key,await o.clearFieldAsyncError(e)}catch(r){let a=r instanceof Error?r.message:"Upload failed";await o.setFieldAsyncError(e,a)}finally{o.endFieldValidation(e)}}},y=async()=>{if(i&&s)try{await s(i)}catch(d){let r=d instanceof Error?d.message:"Delete failed";await o.setFieldAsyncError(e,r);return}n.setValue(null),i=null,await o.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:v,remove:y}}exports.provideBitStore = z; exports.useBitArray = Q; exports.useBitField = R; exports.useBitForm = L; exports.useBitHistory = N; exports.useBitScope = oe; exports.useBitSteps = le; exports.useBitStore = m; exports.useBitUpload = ve; exports.useBitWatch = pe;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|