@lehnihon/bit-form 2.1.2 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/angular/index.cjs +1 -1
- package/dist/angular/index.cjs.map +1 -1
- package/dist/angular/index.d.cts +29 -17
- package/dist/angular/index.d.ts +29 -17
- package/dist/angular/index.js +1 -1
- package/dist/angular/index.js.map +1 -1
- package/dist/bus-B3pGaiFZ.d.cts +255 -0
- package/dist/bus-B3pGaiFZ.d.ts +255 -0
- package/dist/chunk-442A4FTZ.cjs +2 -0
- package/dist/chunk-442A4FTZ.cjs.map +1 -0
- package/dist/chunk-6FJEE6O3.js +133 -0
- package/dist/chunk-6FJEE6O3.js.map +1 -0
- package/dist/chunk-FOV24ACZ.js +2 -0
- package/dist/chunk-FOV24ACZ.js.map +1 -0
- package/dist/chunk-YWXX6XRV.cjs +133 -0
- package/dist/chunk-YWXX6XRV.cjs.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.cjs.map +1 -1
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +1 -1
- package/dist/public-types-CtYuIAMP.d.cts +99 -0
- package/dist/public-types-Lq3eLstW.d.ts +99 -0
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +5 -5
- package/dist/react/index.d.ts +5 -5
- 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 +10 -12
- package/dist/react-native/index.d.ts +10 -12
- 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-hA0AqCkC.d.ts → use-bit-persist-CWzGfovL.d.cts} +27 -19
- package/dist/{use-bit-watch-BRekIj2W.d.cts → use-bit-persist-hxJaKG2S.d.ts} +27 -19
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.cts +45 -33
- package/dist/vue/index.d.ts +45 -33
- package/dist/vue/index.js +1 -1
- package/dist/vue/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/bus-vCbulIYH.d.cts +0 -141
- package/dist/bus-vCbulIYH.d.ts +0 -141
- package/dist/chunk-2QNUW6ZN.cjs +0 -133
- package/dist/chunk-2QNUW6ZN.cjs.map +0 -1
- package/dist/chunk-F6LJWWEW.js +0 -2
- package/dist/chunk-F6LJWWEW.js.map +0 -1
- package/dist/chunk-LPRLSFPT.cjs +0 -2
- package/dist/chunk-LPRLSFPT.cjs.map +0 -1
- package/dist/chunk-N6IA7HQL.js +0 -133
- package/dist/chunk-N6IA7HQL.js.map +0 -1
- package/dist/public-types-ChP5j3xc.d.ts +0 -69
- package/dist/public-types-Nv__uZTR.d.cts +0 -69
|
@@ -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 BitStoreApi, i as BitValidationOptions, d as BitHistoryMetadata, e as BitPersistMetadata } from './public-types-Lq3eLstW.js';
|
|
4
|
+
import { i as BitErrors, A as BitTouched, q as BitPath, r as BitPathValue, G as DeepPartial, e as BitArrayPath, d as BitArrayItem, S as ScopeStatus, V as ValidateScopeResult } from './bus-B3pGaiFZ.js';
|
|
5
5
|
|
|
6
6
|
declare const BitFormProvider: ({ store, children, }: {
|
|
7
|
-
store:
|
|
7
|
+
store: BitStoreApi<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>() => BitStoreApi<T>;
|
|
11
11
|
|
|
12
12
|
declare function useBitForm<T extends object>(): {
|
|
13
13
|
meta: {
|
|
@@ -30,21 +30,21 @@ declare function useBitForm<T extends object>(): {
|
|
|
30
30
|
reset: () => void;
|
|
31
31
|
setField: <P extends BitPath<T, "">>(path: P, value: BitPathValue<T, P>) => void;
|
|
32
32
|
blurField: <P extends BitPath<T, "">>(path: P) => void;
|
|
33
|
+
replaceValues: (values: T) => void;
|
|
34
|
+
hydrate: (values: DeepPartial<T>) => void;
|
|
35
|
+
rebase: (values: T) => void;
|
|
33
36
|
setValues: (values: T) => void;
|
|
34
37
|
setError: (path: string, message: string | undefined) => void;
|
|
35
38
|
setErrors: (errors: BitErrors<T>) => void;
|
|
36
39
|
setServerErrors: (serverErrors: Record<string, string[] | string>) => void;
|
|
37
|
-
validate: (options?:
|
|
38
|
-
scope?: string;
|
|
39
|
-
scopeFields?: string[];
|
|
40
|
-
}) => Promise<boolean>;
|
|
40
|
+
validate: (options?: BitValidationOptions) => Promise<boolean>;
|
|
41
41
|
mutations: {
|
|
42
|
-
pushItem: (path:
|
|
43
|
-
removeItem: (path:
|
|
44
|
-
prependItem: (path:
|
|
45
|
-
insertItem: (path:
|
|
46
|
-
moveItem: (path:
|
|
47
|
-
swapItems: (path:
|
|
42
|
+
pushItem: <P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>) => void;
|
|
43
|
+
removeItem: <P extends BitArrayPath<T>>(path: P, index: number) => void;
|
|
44
|
+
prependItem: <P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>) => void;
|
|
45
|
+
insertItem: <P extends BitArrayPath<T>>(path: P, index: number, value: BitArrayItem<BitPathValue<T, P>>) => void;
|
|
46
|
+
moveItem: <P extends BitArrayPath<T>>(path: P, from: number, to: number) => void;
|
|
47
|
+
swapItems: <P extends BitArrayPath<T>>(path: P, indexA: number, indexB: number) => void;
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
50
|
|
|
@@ -120,13 +120,19 @@ interface UseBitUploadResult {
|
|
|
120
120
|
* Provides form history undo/redo capabilities.
|
|
121
121
|
*/
|
|
122
122
|
interface UseBitHistoryResult {
|
|
123
|
-
canUndo:
|
|
124
|
-
canRedo:
|
|
125
|
-
historyIndex:
|
|
126
|
-
historySize:
|
|
123
|
+
canUndo: BitHistoryMetadata["canUndo"];
|
|
124
|
+
canRedo: BitHistoryMetadata["canRedo"];
|
|
125
|
+
historyIndex: BitHistoryMetadata["historyIndex"];
|
|
126
|
+
historySize: BitHistoryMetadata["historySize"];
|
|
127
127
|
undo: () => void;
|
|
128
128
|
redo: () => void;
|
|
129
129
|
}
|
|
130
|
+
interface UseBitPersistResult {
|
|
131
|
+
restore: () => Promise<boolean>;
|
|
132
|
+
save: () => Promise<void>;
|
|
133
|
+
clear: () => Promise<void>;
|
|
134
|
+
meta: BitPersistMetadata;
|
|
135
|
+
}
|
|
130
136
|
|
|
131
137
|
declare function useBitArray<TForm extends object = any, P extends BitArrayPath<TForm> = BitArrayPath<TForm>>(path: P): {
|
|
132
138
|
append: (value: BitArrayItem<BitPathValue<TForm, P>>) => void;
|
|
@@ -159,4 +165,6 @@ declare function useBitSteps(scopeNames: string[]): UseBitStepsResult;
|
|
|
159
165
|
|
|
160
166
|
declare function useBitWatch<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>>(path: P): BitPathValue<TForm, P>;
|
|
161
167
|
|
|
162
|
-
|
|
168
|
+
declare function useBitPersist(): UseBitPersistResult;
|
|
169
|
+
|
|
170
|
+
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 UseBitPersistResult as e, type UseBitStepsResult as f, useBitForm as g, useBitPersist as h, useBitScope as i, useBitSteps as j, useBitStore as k, useBitWatch as l, 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 _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;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkYWXX6XRVcjs = require('../chunk-YWXX6XRV.cjs');var _vue = require('vue');var H=Symbol("BIT_STORE");function $(e){_vue.provide.call(void 0, H,e)}function c(){let e=_vue.inject.call(void 0, H);if(!e)throw new Error("BitForm Vue hooks devem ser usados sob um provideBitStore");return e}function G(){let e=c(),t=_vue.shallowRef.call(void 0, {isValid:e.getState().isValid,isSubmitting:e.getState().isSubmitting,isDirty:e.getState().isDirty}),s=_vue.ref.call(void 0, null),r=_vue.ref.call(void 0, null),i=e.subscribeSelector(y=>({isValid:y.isValid,isSubmitting:y.isSubmitting,isDirty:y.isDirty}),y=>{t.value=y});_vue.onUnmounted.call(void 0, i);let n=()=>e.getState().values,f=()=>e.getState().errors,u=()=>e.getState().touched,v=()=>e.getDirtyValues(),o=_vue.computed.call(void 0, ()=>t.value.isValid),a=_vue.computed.call(void 0, ()=>t.value.isSubmitting),l=_vue.computed.call(void 0, ()=>t.value.isDirty);return{meta:{isValid:o,isDirty:l,isSubmitting:a,submitError:s,lastResponse:r},getValues:n,getErrors:f,getTouched:u,getDirtyValues:v,submit:y=>B=>(_optionalChain([B, 'optionalAccess', _2 => _2.preventDefault, 'optionalCall', _3 => _3()]),e.submit(y)),onSubmit:y=>B=>(_optionalChain([B, 'optionalAccess', _4 => _4.preventDefault, 'optionalCall', _5 => _5()]),s.value=null,e.submit(async(F,m)=>{try{let d=await y(F,m);r.value=d,s.value=null}catch(d){_chunkYWXX6XRVcjs.i.call(void 0, d)?e.setServerErrors(_chunkYWXX6XRVcjs.j.call(void 0, d)):s.value=d instanceof Error?d:new Error(String(d))}})),reset:()=>{e.reset(),s.value=null,r.value=null},replaceValues:e.replaceValues.bind(e),hydrate:e.hydrate.bind(e),rebase:e.rebase.bind(e),setValues:e.setValues.bind(e),setError:e.setError.bind(e),setErrors:e.setErrors.bind(e),setServerErrors:e.setServerErrors.bind(e),setField:e.setField.bind(e),blurField:e.blurField.bind(e),validate:e.validate.bind(e),mutations:{pushItem:e.pushItem.bind(e),prependItem:e.prependItem.bind(e),removeItem:e.removeItem.bind(e),insertItem:e.insertItem.bind(e),moveItem:e.moveItem.bind(e),swapItems:e.swapItems.bind(e)}}}function R(e){let t=c(),s=t.resolveMask(e),r=_vue.shallowRef.call(void 0, t.getFieldState(e)),i=t.subscribeSelector(()=>t.getFieldState(e),p=>{r.value=p});_vue.onUnmounted.call(void 0, ()=>{i(),t.unregisterField&&t.unregisterField(e)});let n=_vue.computed.call(void 0, ()=>r.value.value),f=_vue.computed.call(void 0, ()=>{let p=n.value;return p==null||p===""?"":s?s.format(p):String(p)}),u=_vue.computed.call(void 0, {get:()=>f.value,set:p=>{if(!s){t.setField(e,p);return}t.setField(e,s.parse(String(_nullishCoalesce(p, () => ("")))))}}),v=_vue.computed.call(void 0, ()=>r.value.error),o=_vue.computed.call(void 0, ()=>r.value.touched?r.value.error:void 0),a=_vue.computed.call(void 0, ()=>r.value.touched),l=_vue.computed.call(void 0, ()=>!!(a.value&&o.value)),S=_vue.computed.call(void 0, ()=>r.value.isValidating),h=_vue.computed.call(void 0, ()=>r.value.isDirty),E=_vue.computed.call(void 0, ()=>r.value.isHidden),y=_vue.computed.call(void 0, ()=>r.value.isRequired),B=_vue.computed.call(void 0, ()=>!!v.value),F=p=>{if(!s){t.setField(e,p);return}u.value=String(_nullishCoalesce(p, () => ("")))},m=()=>t.blurField(e);return{value:n,displayValue:f,modelValue:u,setValue:F,setBlur:m,onInput:p=>{F(p)},onBlur:()=>{m()},meta:{error:o,touched:a,invalid:l,isValidating:S,isDirty:h,isHidden:E,isRequired:y,hasError:B}}}var V=()=>Math.random().toString(36).substring(2,9);function Z(e){let t=c(),r=(()=>{let o=_chunkYWXX6XRVcjs.f.call(void 0, t.getState().values,e);return Array.isArray(o)?o:[]})(),i=_vue.ref.call(void 0, r),n=_vue.ref.call(void 0, r.map(V)),f=t.subscribePath(e,o=>{let a=Array.isArray(o)?o:[];if(i.value=[...a],a.length!==n.value.length){let l=[...n.value];if(a.length>l.length){let S=a.length-l.length,h=Array.from({length:S},V);n.value=[...l,...h]}else n.value=l.slice(0,a.length)}});_vue.onUnmounted.call(void 0, ()=>{f(),t.unregisterPrefix&&t.unregisterPrefix(`${e}.`)});let u=_vue.computed.call(void 0, ()=>i.value.map((o,a)=>({key:n.value[a]||`temp-${a}`,value:o,index:a}))),v=_vue.computed.call(void 0, ()=>i.value.length);return{fields:u,length:v,append:o=>{n.value.push(V()),t.pushItem(e,o)},prepend:o=>{n.value.unshift(V()),t.prependItem(e,o)},insert:(o,a)=>{n.value.splice(o,0,V()),t.insertItem(e,o,a)},remove:o=>{n.value.splice(o,1),t.removeItem(e,o)},move:(o,a)=>{let l=[...n.value],[S]=l.splice(o,1);l.splice(a,0,S),n.value=l,t.moveItem(e,o,a)},swap:(o,a)=>{let l=[...n.value];[l[o],l[a]]=[l[a],l[o]],n.value=l,t.swapItems(e,o,a)},replace:o=>{n.value=o.map(V),t.setField(e,o)},clear:()=>{n.value=[],t.setField(e,[])}}}function te(){let e=c(),t=_vue.shallowRef.call(void 0, e.getHistoryMetadata()),s=e.subscribe(()=>{t.value=e.getHistoryMetadata()});_vue.onUnmounted.call(void 0, s);let r=()=>e.undo(),i=()=>e.redo();return{canUndo:_vue.computed.call(void 0, ()=>t.value.canUndo),canRedo:_vue.computed.call(void 0, ()=>t.value.canRedo),historyIndex:_vue.computed.call(void 0, ()=>t.value.historyIndex),historySize:_vue.computed.call(void 0, ()=>t.value.historySize),undo:r,redo:i}}function ie(e,t){let s=Object.keys(e),r=Object.keys(t);return s.length!==r.length?!1:s.every(i=>e[i]===t[i])}function ne(e){let t=c(),s=_vue.ref.call(void 0, t.getStepStatus(e)),r;_vue.onMounted.call(void 0, ()=>{r=t.subscribe(()=>{let o=t.getStepStatus(e);(o.hasErrors!==s.value.hasErrors||o.isDirty!==s.value.isDirty||!ie(o.errors,s.value.errors))&&(s.value=o)})}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([r, 'optionalCall', _6 => _6()])});let i=async()=>{let o=await t.validate({scope:e}),a=t.getStepErrors(e);return{valid:o,errors:a}},n=()=>t.getStepErrors(e),f=_vue.computed.call(void 0, ()=>!s.value.hasErrors),u=_vue.computed.call(void 0, ()=>s.value.isDirty),v=_vue.computed.call(void 0, ()=>s.value.errors);return{scopeName:e,status:s,errors:v,validate:i,getErrors:n,isValid:f,isDirty:u}}function ce(e,t){let s=Object.keys(e),r=Object.keys(t);return s.length!==r.length?!1:s.every(i=>e[i]===t[i])}function me(e){let t=c(),s=_vue.ref.call(void 0, 0),r=_vue.computed.call(void 0, ()=>_nullishCoalesce(e[s.value], () => (""))),i=_vue.ref.call(void 0, t.getStepStatus(r.value)),n;_vue.watch.call(void 0, r,m=>{i.value=t.getStepStatus(m)});let f=()=>{let m=r.value,d=t.getStepStatus(m);(d.hasErrors!==i.value.hasErrors||d.isDirty!==i.value.isDirty||!ce(d.errors,i.value.errors))&&(i.value=d)};_vue.onMounted.call(void 0, ()=>{n=t.subscribe(f)}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([n, 'optionalCall', _7 => _7()])});let u=async()=>{let m=r.value,d=await t.validate({scope:m}),P=t.getStepErrors(m);return{valid:d,errors:P}},v=()=>t.getStepErrors(r.value),o=async()=>{let m=r.value,d=t.getScopeFields(m);if(t.hasValidationsInProgress(d))return!1;let P=await t.validate({scope:m});if(P)s.value=Math.min(s.value+1,e.length-1);else{let p=t.getStepErrors(m),A=Object.keys(p);A.length>0&&t.markFieldsTouched(A)}return P},a=()=>{s.value=Math.max(s.value-1,0)},l=m=>{s.value=Math.max(0,Math.min(m-1,e.length-1))},S=_vue.computed.call(void 0, ()=>s.value+1),h=_vue.computed.call(void 0, ()=>s.value===0),E=_vue.computed.call(void 0, ()=>s.value>=e.length-1),y=_vue.computed.call(void 0, ()=>!i.value.hasErrors),B=_vue.computed.call(void 0, ()=>i.value.isDirty),F=_vue.computed.call(void 0, ()=>i.value.errors);return{step:S,stepIndex:s,scope:r,next:o,prev:a,goTo:l,isFirst:h,isLast:E,status:i,errors:F,isValid:y,isDirty:B,validate:u,getErrors:v}}function fe(e){let t=c(),s=_chunkYWXX6XRVcjs.f.call(void 0, t.getState().values,e),r=_vue.ref.call(void 0, s),i=t.watch(e,n=>{_chunkYWXX6XRVcjs.e.call(void 0, r.value,n)||(r.value=n)});return _vue.onUnmounted.call(void 0, i),_vue.readonly.call(void 0, r)}function ye(e,t,s){let r=c(),i=R(e),n=null,f=async v=>{if(v){r.beginFieldValidation(e),await r.clearFieldAsyncError(e);try{let o=await t(v);i.setValue(o.url),n=o.key,await r.clearFieldAsyncError(e)}catch(o){let a=o instanceof Error?o.message:"Upload failed";await r.setFieldAsyncError(e,a)}finally{r.endFieldValidation(e)}}},u=async()=>{if(n&&s)try{await s(n)}catch(v){let o=v instanceof Error?v.message:"Delete failed";await r.setFieldAsyncError(e,o);return}i.setValue(null),n=null,await r.clearFieldAsyncError(e)};return{value:i.value,setValue:i.setValue,error:_vue.computed.call(void 0, ()=>i.meta.error.value),isValidating:_vue.computed.call(void 0, ()=>i.meta.isValidating.value||!1),upload:f,remove:u}}function ge(){let e=c(),t=_vue.ref.call(void 0, !1),s=_vue.ref.call(void 0, !1),r=_vue.ref.call(void 0, null);return{restore:async()=>{s.value=!0,r.value=null;try{return await e.restorePersisted()}catch(u){return r.value=u instanceof Error?u:new Error(String(u)),!1}finally{s.value=!1}},save:async()=>{t.value=!0,r.value=null;try{await e.forceSave()}catch(u){r.value=u instanceof Error?u:new Error(String(u))}finally{t.value=!1}},clear:async()=>{r.value=null;try{await e.clearPersisted()}catch(u){r.value=u instanceof Error?u:new Error(String(u))}},meta:{isSaving:_vue.readonly.call(void 0, t),isRestoring:_vue.readonly.call(void 0, s),error:_vue.readonly.call(void 0, r)}}}exports.provideBitStore = $; exports.useBitArray = Z; exports.useBitField = R; exports.useBitForm = G; exports.useBitHistory = te; exports.useBitPersist = ge; exports.useBitScope = ne; exports.useBitSteps = me; exports.useBitStore = c; exports.useBitUpload = ye; exports.useBitWatch = fe;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/vue/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/bit-form/bit-form/dist/vue/index.cjs","../../src/vue/context.ts","../../src/vue/use-bit-form.ts","../../src/vue/use-bit-field.ts","../../src/vue/use-bit-array.ts"],"names":["BIT_STORE_KEY","provideBitStore","store","provide","useBitStore","inject","useBitForm","state","shallowRef","submitError","ref","lastResponse","unsubscribe","onUnmounted","getValues","getErrors","getTouched","getDirtyValues","isValid","computed","isSubmitting","isDirty","onSuccess","e","handler","values","dirtyValues","result","err","isValidationErrorShape","extractServerErrors","useBitField","path","resolvedMask","rawValue","getDeepValue","displayValue","val","modelValue","rawError","error","touched","invalid","isValidating","isHidden","isRequired","hasError","setValue","setBlur","generateId","useBitArray","getSnapshot","initialValues","ids","newValues","currentIds","diff","newIds"],"mappings":"AAAA,0uBAA8D,0BCAhB,IAIjCA,CAAAA,CACX,MAAA,CAAO,WAAW,CAAA,CAEb,SAASC,CAAAA,CAAkCC,CAAAA,CAA6B,CAC7EC,0BAAAA,CAAQH,CAAeE,CAAK,CAC9B,CAEO,SAASE,CAAAA,CAAAA,CAAgC,CAC9C,IAAMF,CAAAA,CAAQG,yBAAAA,CAAoB,CAAA,CAClC,EAAA,CAAI,CAACH,CAAAA,CACH,MAAM,IAAI,KAAA,CACR,2DACF,CAAA,CACF,OAAOA,CACT,CClBA,SAIgBI,CAAA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,CACrCE,CAAAA,CAAS,KAAA,CAAM,IAAA,CAAK,CAAE,MAAA,CAAQD,CAAK,CAAA,CAAGP,CAAU,CAAA,CACtDI,CAAAA,CAAI,KAAA,CAAQ,CAAC,GAAGE,CAAAA,CAAY,GAAGE,CAAM,CACvC,CAAA,KACEJ,CAAAA,CAAI,KAAA,CAAQE,CAAAA,CAAW,KAAA,CAAM,CAAA,CAAGD,CAAAA,CAAU,MAAM,CAEpD,CACF,CAAC,CAAA,CAEDzC,8BAAAA,CAAY,CAAA,EAAM,CAChBD,CAAAA,CAAY,CAAA,CACRV,CAAAA,CAAM,gBAAA,EACRA,CAAAA,CAAM,gBAAA,CAAiB,CAAA,EAAA","file":"/home/runner/work/bit-form/bit-form/dist/vue/index.cjs","sourcesContent":[null,"import { inject, provide, InjectionKey } from \"vue\";\nimport type { BitFrameworkStore } from \"../core\";\n\n// Chave única para evitar colisões\nexport const BIT_STORE_KEY: InjectionKey<BitFrameworkStore<any>> =\n Symbol(\"BIT_STORE\");\n\nexport function provideBitStore<T extends object>(store: BitFrameworkStore<T>) {\n provide(BIT_STORE_KEY, store);\n}\n\nexport function useBitStore<T extends object>() {\n const store = inject(BIT_STORE_KEY);\n if (!store)\n throw new Error(\n \"BitForm Vue hooks devem ser usados sob um provideBitStore\",\n );\n return store as BitFrameworkStore<T>;\n}\n","import { computed, onUnmounted, shallowRef, ref } from \"vue\";\nimport { useBitStore } from \"./context\";\nimport { isValidationErrorShape, extractServerErrors } from \"../core/utils\";\n\nexport function useBitForm<T extends object>() {\n const store = useBitStore<T>();\n const state = shallowRef(store.getState());\n const submitError = ref<Error | null>(null);\n const lastResponse = ref<unknown>(null);\n\n const unsubscribe = store.subscribe(() => {\n state.value = { ...store.getState() };\n });\n\n onUnmounted(unsubscribe);\n\n const getValues = () => state.value.values;\n const getErrors = () => state.value.errors;\n const getTouched = () => state.value.touched;\n const getDirtyValues = () => store.getDirtyValues();\n\n const isValid = computed(() => state.value.isValid);\n const isSubmitting = computed(() => state.value.isSubmitting);\n const isDirty = computed(() => state.value.isDirty);\n\n const onSubmit = (\n handler: (values: T, dirtyValues?: Partial<T>) => Promise<unknown>,\n ) => {\n return (e?: Event) => {\n e?.preventDefault?.();\n submitError.value = null;\n return store.submit(async (values, dirtyValues) => {\n try {\n const result = await handler(values, dirtyValues);\n lastResponse.value = result;\n submitError.value = null;\n } catch (err) {\n if (isValidationErrorShape(err)) {\n store.setServerErrors(extractServerErrors(err));\n } else {\n submitError.value =\n err instanceof Error ? err : new Error(String(err));\n }\n }\n });\n };\n };\n\n const reset = () => {\n store.reset();\n submitError.value = null;\n lastResponse.value = null;\n };\n\n const meta = {\n isValid,\n isDirty,\n isSubmitting,\n submitError,\n lastResponse,\n };\n\n return {\n // Metadata (grouped)\n meta,\n // Getters\n getValues,\n getErrors,\n getTouched,\n getDirtyValues,\n // Main actions (frequent use - flat)\n submit: (\n onSuccess: (values: T, dirtyValues?: Partial<T>) => void | Promise<void>,\n ) => {\n return (e?: Event) => {\n e?.preventDefault?.();\n return store.submit(onSuccess);\n };\n },\n onSubmit,\n reset,\n setValues: store.setValues.bind(store),\n setError: store.setError.bind(store),\n setErrors: store.setErrors.bind(store),\n setServerErrors: store.setServerErrors.bind(store),\n setField: store.setField.bind(store),\n blurField: store.blurField.bind(store),\n validate: store.validate.bind(store),\n // Array mutations (grouped)\n mutations: {\n pushItem: store.pushItem.bind(store),\n prependItem: store.prependItem.bind(store),\n removeItem: store.removeItem.bind(store),\n insertItem: store.insertItem.bind(store),\n moveItem: store.moveItem.bind(store),\n swapItems: store.swapItems.bind(store),\n },\n };\n}\n","import { computed, onUnmounted, shallowRef } from \"vue\";\nimport { useBitStore } from \"./context\";\nimport { getDeepValue } from \"../core\";\nimport type { UseBitFieldVueMeta, UseBitFieldVueResult } from \"./types\";\n\nexport function useBitField<TValue = any>(\n path: string,\n): UseBitFieldVueResult<TValue> {\n const store = useBitStore<any>();\n\n const resolvedMask = store.resolveMask(path as string);\n\n const state = shallowRef(store.getState());\n\n const unsubscribe = store.subscribe(() => {\n state.value = store.getState();\n });\n\n onUnmounted(() => {\n unsubscribe();\n if (store.unregisterField) {\n store.unregisterField(path as string);\n }\n });\n\n const rawValue = computed(\n () => getDeepValue(state.value.values, path as string) as TValue,\n );\n\n const displayValue = computed(() => {\n const val = rawValue.value;\n if (val === undefined || val === null || val === \"\") return \"\";\n\n return resolvedMask ? resolvedMask.format(val as any) : String(val);\n });\n\n const modelValue = computed({\n get: () => displayValue.value,\n set: (val: any) => {\n if (!resolvedMask) {\n store.setField(path, val);\n return;\n }\n\n store.setField(path, resolvedMask.parse(String(val ?? \"\")));\n },\n });\n\n const rawError = computed(() => state.value.errors[path]);\n const error = computed(() =>\n state.value.touched[path] ? state.value.errors[path] : undefined,\n );\n const touched = computed(() => !!state.value.touched[path]);\n const invalid = computed(() => !!(touched.value && error.value));\n\n const isValidating = computed(() => {\n state.value;\n return store.isFieldValidating(path);\n });\n\n const isDirty = computed(() => {\n state.value;\n return store.isFieldDirty(path);\n });\n\n const isHidden = computed(() => {\n state.value;\n return store.isHidden(path);\n });\n\n const isRequired = computed(() => {\n state.value;\n return store.isRequired(path);\n });\n\n const hasError = computed(() => !!rawError.value);\n\n const setValue = (val: any) => {\n modelValue.value = val;\n };\n\n const setBlur = () => store.blurField(path);\n\n const onInput = (val: any) => {\n setValue(val);\n };\n\n const onBlur = () => {\n setBlur();\n };\n\n return {\n // Main handlers and values (flat)\n value: rawValue,\n displayValue,\n modelValue,\n setValue,\n setBlur,\n onInput,\n onBlur,\n // Metadata (grouped)\n meta: {\n error,\n touched,\n invalid,\n isValidating,\n isDirty,\n isHidden,\n isRequired,\n hasError,\n },\n };\n}\n","import { ref, computed, onUnmounted } from \"vue\";\nimport { useBitStore } from \"./context\";\nimport {\n getDeepValue,\n BitArrayPath,\n BitPathValue,\n BitArrayItem,\n BitPath,\n} from \"../core\";\n\nconst generateId = () => Math.random().toString(36).substring(2, 9);\n\nexport function useBitArray<\n TForm extends object = any,\n P extends BitArrayPath<TForm> = BitArrayPath<TForm>,\n>(path: P) {\n const store = useBitStore<TForm>();\n\n type Item = BitArrayItem<BitPathValue<TForm, P>>;\n\n const getSnapshot = (): Item[] => {\n const val = getDeepValue(\n store.getState().values,\n path as string,\n ) as BitPathValue<TForm, P> | undefined;\n return Array.isArray(val) ? (val as Item[]) : [];\n };\n\n const initialValues = getSnapshot();\n const values = ref<Item[]>(initialValues);\n const ids = ref<string[]>(initialValues.map(generateId));\n\n const unsubscribe = store.subscribe(() => {\n const newValues = getSnapshot();\n values.value = [...newValues];\n\n if (newValues.length !== ids.value.length) {\n const currentIds = [...ids.value];\n if (newValues.length > currentIds.length) {\n const diff = newValues.length - currentIds.length;\n const newIds = Array.from({ length: diff }, generateId);\n ids.value = [...currentIds, ...newIds];\n } else {\n ids.value = currentIds.slice(0, newValues.length);\n }\n }\n });\n\n onUnmounted(() => {\n unsubscribe();\n if (store.unregisterPrefix) {\n store.unregisterPrefix(`${path as string}.`);\n }\n });\n\n const fields = computed(() =>\n values.value.map((v, i) => ({\n key: ids.value[i] || `temp-${i}`,\n value: v,\n index: i,\n })),\n );\n\n const length = computed(() => values.value.length);\n\n return {\n fields,\n length,\n append: (val: Item) => {\n ids.value.push(generateId());\n store.pushItem(path, val);\n },\n prepend: (val: Item) => {\n ids.value.unshift(generateId());\n store.prependItem(path, val);\n },\n insert: (index: number, val: Item) => {\n ids.value.splice(index, 0, generateId());\n store.insertItem(path, index, val);\n },\n remove: (index: number) => {\n ids.value.splice(index, 1);\n store.removeItem(path, index);\n },\n move: (from: number, to: number) => {\n const currentIds = [...ids.value];\n const [id] = currentIds.splice(from, 1);\n currentIds.splice(to, 0, id);\n ids.value = currentIds;\n store.moveItem(path, from, to);\n },\n swap: (a: number, b: number) => {\n const currentIds = [...ids.value];\n [currentIds[a], currentIds[b]] = [currentIds[b], currentIds[a]];\n ids.value = currentIds;\n store.swapItems(path, a, b);\n },\n replace: (items: Item[]) => {\n ids.value = items.map(generateId);\n store.setField(path as unknown as BitPath<TForm>, items as any);\n },\n clear: () => {\n ids.value = [];\n store.setField(path as unknown as BitPath<TForm>, [] as any);\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/bit-form/bit-form/dist/vue/index.cjs","../../src/vue/context.ts","../../src/vue/use-bit-form.ts","../../src/vue/use-bit-field.ts","../../src/vue/use-bit-array.ts"],"names":["BIT_STORE_KEY","provideBitStore","store","provide","useBitStore","inject","useBitForm","state","shallowRef","submitError","ref","lastResponse","unsubscribe","snapshot","nextState","onUnmounted","getValues","getErrors","getTouched","getDirtyValues","isValid","computed","isSubmitting","isDirty","onSuccess","e","handler","values","dirtyValues","result","err","isValidationErrorShape","extractServerErrors","useBitField","path","resolvedMask","rawValue","displayValue","val","modelValue","rawError","error","touched","invalid","isValidating","isHidden","isRequired","hasError","setValue","setBlur","generateId","useBitArray","initialValues","getDeepValue","ids","newValues","nextValues","currentIds","diff","newIds"],"mappings":"AAAA,0uBAA8D,0BCAhB,IAIjCA,CAAAA,CACX,MAAA,CAAO,WAAW,CAAA,CAEb,SAASC,CAAAA,CAAkCC,CAAAA,CAAuB,CACvEC,0BAAAA,CAAQH,CAAeE,CAAK,CAC9B,CAEO,SAASE,CAAAA,CAAAA,CAAgC,CAC9C,IAAMF,CAAAA,CAAQG,yBAAAA,CAAoB,CAAA,CAClC,EAAA,CAAI,CAACH,CAAAA,CACH,MAAM,IAAI,KAAA,CACR,2DACF,CAAA,CACF,OAAOA,CACT,CClBA,SAIgBI,CAAAA,CAAAA,CAA+B,CAC7C,IAAMJ,CAAAA,CAAQE,CAAAA,CAAe,CAAA,CACvBG,CAAAA,CAAQC,6BAAAA,CACZ,OAAA,CAASN,CAAAA,CAAM,QAAA,CAAS,CAAA,CAAE,OAAA,CAC1B,YAAA,CAAcA,CAAAA,CAAM,QAAA,CAAS,CAAA,CAAE,YAAA,CAC/B,OAAA,CAASA,CAAAA,CAAM,QAAA,CAAS,CAAA,CAAE,OAC5B,CAAC,CA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AA,CAChC,EAAA,CAAIE,CAAAA,CAAW,MAAA,CAASC,CAAAA,CAAW,MAAA,CAAQ,CACzC,IAAMC,CAAAA,CAAOF,CAAAA,CAAW,MAAA,CAASC,CAAAA,CAAW,MAAA,CACtCE,CAAAA,CAAS,KAAA,CAAM,IAAA,CAAK,CAAE,MAAA,CAAQD,CAAK,CAAA,CAAGR,CAAU,CAAA,CACtDI,CAAAA,CAAI,KAAA,CAAQ,CAAC,GAAGG,CAAAA,CAAY,GAAGE,CAAM,CACvC,CAAA,KACEL,CAAAA,CAAI,KAAA,CAAQG,CAAAA,CAAW,KAAA,CAAM,CAAA,CAAGD,CAAAA,CAAW,MAAM,CAErD,CACF,CAAC,CAAA,CAEDzC,8BAAAA,CAAY,CAAA,EAAM,CAChBH,CAAAA,CAAY,CAAA,CACRV,CAAAA,CAAM,gBAAA,EACRA,CAAAA,CAAM,gBAAA,CAAiB,CAAA,EAAA","file":"/home/runner/work/bit-form/bit-form/dist/vue/index.cjs","sourcesContent":[null,"import { inject, provide, InjectionKey } from \"vue\";\nimport type { BitStoreApi } from \"../core\";\n\n// Chave única para evitar colisões\nexport const BIT_STORE_KEY: InjectionKey<BitStoreApi<any>> =\n Symbol(\"BIT_STORE\");\n\nexport function provideBitStore<T extends object>(store: BitStoreApi<T>) {\n provide(BIT_STORE_KEY, store);\n}\n\nexport function useBitStore<T extends object>() {\n const store = inject(BIT_STORE_KEY);\n if (!store)\n throw new Error(\n \"BitForm Vue hooks devem ser usados sob um provideBitStore\",\n );\n return store as BitStoreApi<T>;\n}\n","import { computed, onUnmounted, shallowRef, ref } from \"vue\";\nimport { useBitStore } from \"./context\";\nimport { isValidationErrorShape, extractServerErrors } from \"../core/utils\";\n\nexport function useBitForm<T extends object>() {\n const store = useBitStore<T>();\n const state = shallowRef({\n isValid: store.getState().isValid,\n isSubmitting: store.getState().isSubmitting,\n isDirty: store.getState().isDirty,\n });\n const submitError = ref<Error | null>(null);\n const lastResponse = ref<unknown>(null);\n\n const unsubscribe = store.subscribeSelector(\n (snapshot) => ({\n isValid: snapshot.isValid,\n isSubmitting: snapshot.isSubmitting,\n isDirty: snapshot.isDirty,\n }),\n (nextState) => {\n state.value = nextState;\n },\n );\n\n onUnmounted(unsubscribe);\n\n const getValues = () => store.getState().values;\n const getErrors = () => store.getState().errors;\n const getTouched = () => store.getState().touched;\n const getDirtyValues = () => store.getDirtyValues();\n\n const isValid = computed(() => state.value.isValid);\n const isSubmitting = computed(() => state.value.isSubmitting);\n const isDirty = computed(() => state.value.isDirty);\n\n const onSubmit = (\n handler: (values: T, dirtyValues?: Partial<T>) => Promise<unknown>,\n ) => {\n return (e?: Event) => {\n e?.preventDefault?.();\n submitError.value = null;\n return store.submit(async (values, dirtyValues) => {\n try {\n const result = await handler(values, dirtyValues);\n lastResponse.value = result;\n submitError.value = null;\n } catch (err) {\n if (isValidationErrorShape(err)) {\n store.setServerErrors(extractServerErrors(err));\n } else {\n submitError.value =\n err instanceof Error ? err : new Error(String(err));\n }\n }\n });\n };\n };\n\n const reset = () => {\n store.reset();\n submitError.value = null;\n lastResponse.value = null;\n };\n\n const meta = {\n isValid,\n isDirty,\n isSubmitting,\n submitError,\n lastResponse,\n };\n\n return {\n // Metadata (grouped)\n meta,\n // Getters\n getValues,\n getErrors,\n getTouched,\n getDirtyValues,\n // Main actions (frequent use - flat)\n submit: (\n onSuccess: (values: T, dirtyValues?: Partial<T>) => void | Promise<void>,\n ) => {\n return (e?: Event) => {\n e?.preventDefault?.();\n return store.submit(onSuccess);\n };\n },\n onSubmit,\n reset,\n replaceValues: store.replaceValues.bind(store),\n hydrate: store.hydrate.bind(store),\n rebase: store.rebase.bind(store),\n setValues: store.setValues.bind(store),\n setError: store.setError.bind(store),\n setErrors: store.setErrors.bind(store),\n setServerErrors: store.setServerErrors.bind(store),\n setField: store.setField.bind(store),\n blurField: store.blurField.bind(store),\n validate: store.validate.bind(store),\n // Array mutations (grouped)\n mutations: {\n pushItem: store.pushItem.bind(store),\n prependItem: store.prependItem.bind(store),\n removeItem: store.removeItem.bind(store),\n insertItem: store.insertItem.bind(store),\n moveItem: store.moveItem.bind(store),\n swapItems: store.swapItems.bind(store),\n },\n };\n}\n","import { computed, onUnmounted, shallowRef } from \"vue\";\nimport { useBitStore } from \"./context\";\nimport type { UseBitFieldVueResult } from \"./types\";\nimport type { BitPath, BitPathValue } from \"../core\";\n\nexport function useBitField<\n TForm extends object = any,\n P extends BitPath<TForm> = BitPath<TForm>,\n>(path: P): UseBitFieldVueResult<BitPathValue<TForm, P>> {\n const store = useBitStore<TForm>();\n\n const resolvedMask = store.resolveMask(path);\n\n const state = shallowRef(store.getFieldState(path));\n\n const unsubscribe = store.subscribeSelector(\n () => store.getFieldState(path),\n (nextState) => {\n state.value = nextState;\n },\n );\n\n onUnmounted(() => {\n unsubscribe();\n if (store.unregisterField) {\n store.unregisterField(path);\n }\n });\n\n const rawValue = computed(() => state.value.value as BitPathValue<TForm, P>);\n\n const displayValue = computed(() => {\n const val = rawValue.value;\n if (val === undefined || val === null || val === \"\") return \"\";\n\n return resolvedMask ? resolvedMask.format(val) : String(val);\n });\n\n const modelValue = computed({\n get: () => displayValue.value,\n set: (val: string) => {\n if (!resolvedMask) {\n store.setField(path, val as BitPathValue<TForm, P>);\n return;\n }\n\n store.setField(path, resolvedMask.parse(String(val ?? \"\")));\n },\n });\n\n const rawError = computed(() => state.value.error);\n const error = computed(() =>\n state.value.touched ? state.value.error : undefined,\n );\n const touched = computed(() => state.value.touched);\n const invalid = computed(() => !!(touched.value && error.value));\n\n const isValidating = computed(() => state.value.isValidating);\n\n const isDirty = computed(() => state.value.isDirty);\n\n const isHidden = computed(() => state.value.isHidden);\n\n const isRequired = computed(() => state.value.isRequired);\n\n const hasError = computed(() => !!rawError.value);\n\n const setValue = (\n val: BitPathValue<TForm, P> | string | number | null | undefined,\n ) => {\n if (!resolvedMask) {\n store.setField(path, val as BitPathValue<TForm, P>);\n return;\n }\n\n modelValue.value = String(val ?? \"\");\n };\n\n const setBlur = () => store.blurField(path);\n\n const onInput = (\n val: BitPathValue<TForm, P> | string | number | null | undefined,\n ) => {\n setValue(val);\n };\n\n const onBlur = () => {\n setBlur();\n };\n\n return {\n // Main handlers and values (flat)\n value: rawValue,\n displayValue,\n modelValue,\n setValue,\n setBlur,\n onInput,\n onBlur,\n // Metadata (grouped)\n meta: {\n error,\n touched,\n invalid,\n isValidating,\n isDirty,\n isHidden,\n isRequired,\n hasError,\n },\n };\n}\n","import { ref, computed, onUnmounted } from \"vue\";\nimport { useBitStore } from \"./context\";\nimport {\n getDeepValue,\n BitArrayPath,\n BitPathValue,\n BitArrayItem,\n BitPath,\n} from \"../core\";\n\nconst generateId = () => Math.random().toString(36).substring(2, 9);\n\nexport function useBitArray<\n TForm extends object = any,\n P extends BitArrayPath<TForm> = BitArrayPath<TForm>,\n>(path: P) {\n const store = useBitStore<TForm>();\n\n type Item = BitArrayItem<BitPathValue<TForm, P>>;\n\n const getSnapshot = (): Item[] => {\n const val = getDeepValue(store.getState().values, path as string) as\n | BitPathValue<TForm, P>\n | undefined;\n return Array.isArray(val) ? (val as Item[]) : [];\n };\n\n const initialValues = getSnapshot();\n const values = ref<Item[]>(initialValues);\n const ids = ref<string[]>(initialValues.map(generateId));\n\n const unsubscribe = store.subscribePath(path, (newValues) => {\n const nextValues = (Array.isArray(newValues) ? newValues : []) as Item[];\n\n values.value = [...nextValues];\n\n if (nextValues.length !== ids.value.length) {\n const currentIds = [...ids.value];\n if (nextValues.length > currentIds.length) {\n const diff = nextValues.length - currentIds.length;\n const newIds = Array.from({ length: diff }, generateId);\n ids.value = [...currentIds, ...newIds];\n } else {\n ids.value = currentIds.slice(0, nextValues.length);\n }\n }\n });\n\n onUnmounted(() => {\n unsubscribe();\n if (store.unregisterPrefix) {\n store.unregisterPrefix(`${path as string}.`);\n }\n });\n\n const fields = computed(() =>\n values.value.map((v, i) => ({\n key: ids.value[i] || `temp-${i}`,\n value: v,\n index: i,\n })),\n );\n\n const length = computed(() => values.value.length);\n\n return {\n fields,\n length,\n append: (val: Item) => {\n ids.value.push(generateId());\n store.pushItem(path, val);\n },\n prepend: (val: Item) => {\n ids.value.unshift(generateId());\n store.prependItem(path, val);\n },\n insert: (index: number, val: Item) => {\n ids.value.splice(index, 0, generateId());\n store.insertItem(path, index, val);\n },\n remove: (index: number) => {\n ids.value.splice(index, 1);\n store.removeItem(path, index);\n },\n move: (from: number, to: number) => {\n const currentIds = [...ids.value];\n const [id] = currentIds.splice(from, 1);\n currentIds.splice(to, 0, id);\n ids.value = currentIds;\n store.moveItem(path, from, to);\n },\n swap: (a: number, b: number) => {\n const currentIds = [...ids.value];\n [currentIds[a], currentIds[b]] = [currentIds[b], currentIds[a]];\n ids.value = currentIds;\n store.swapItems(path, a, b);\n },\n replace: (items: Item[]) => {\n ids.value = items.map(generateId);\n store.setField(\n path as unknown as BitPath<TForm>,\n items as unknown as BitPathValue<TForm, BitPath<TForm>>,\n );\n },\n clear: () => {\n ids.value = [];\n store.setField(\n path as unknown as BitPath<TForm>,\n [] as unknown as BitPathValue<TForm, BitPath<TForm>>,\n );\n },\n };\n}\n"]}
|
package/dist/vue/index.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { B as BitStoreApi, i as BitValidationOptions, d as BitHistoryMetadata, e as BitPersistMetadata } from '../public-types-CtYuIAMP.cjs';
|
|
2
|
+
import { i as BitErrors, A as BitTouched, G as DeepPartial, q as BitPath, r as BitPathValue, e as BitArrayPath, d as BitArrayItem, S as ScopeStatus, V as ValidateScopeResult } from '../bus-B3pGaiFZ.cjs';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
4
|
import { ComputedRef, Ref } from 'vue';
|
|
5
5
|
import * as _vue_reactivity from '@vue/reactivity';
|
|
6
6
|
import * as _vue_shared from '@vue/shared';
|
|
7
7
|
import { a as BitUploadFn, B as BitDeleteUploadFn } from '../types-C2mpfhp1.cjs';
|
|
8
8
|
|
|
9
|
-
declare function provideBitStore<T extends object>(store:
|
|
10
|
-
declare function useBitStore<T extends object>():
|
|
9
|
+
declare function provideBitStore<T extends object>(store: BitStoreApi<T>): void;
|
|
10
|
+
declare function useBitStore<T extends object>(): BitStoreApi<T>;
|
|
11
11
|
|
|
12
12
|
declare function useBitForm<T extends object>(): {
|
|
13
13
|
meta: {
|
|
@@ -24,23 +24,23 @@ declare function useBitForm<T extends object>(): {
|
|
|
24
24
|
submit: (onSuccess: (values: T, dirtyValues?: Partial<T>) => void | Promise<void>) => (e?: Event) => Promise<void>;
|
|
25
25
|
onSubmit: (handler: (values: T, dirtyValues?: Partial<T>) => Promise<unknown>) => (e?: Event) => Promise<void>;
|
|
26
26
|
reset: () => void;
|
|
27
|
+
replaceValues: (values: T) => void;
|
|
28
|
+
hydrate: (values: DeepPartial<T>) => void;
|
|
29
|
+
rebase: (values: T) => void;
|
|
27
30
|
setValues: (values: T) => void;
|
|
28
31
|
setError: (path: string, message: string | undefined) => void;
|
|
29
32
|
setErrors: (errors: BitErrors<T>) => void;
|
|
30
33
|
setServerErrors: (serverErrors: Record<string, string[] | string>) => void;
|
|
31
34
|
setField: <P extends BitPath<T, "">>(path: P, value: BitPathValue<T, P>) => void;
|
|
32
35
|
blurField: <P extends BitPath<T, "">>(path: P) => void;
|
|
33
|
-
validate: (options?:
|
|
34
|
-
scope?: string;
|
|
35
|
-
scopeFields?: string[];
|
|
36
|
-
}) => Promise<boolean>;
|
|
36
|
+
validate: (options?: BitValidationOptions) => Promise<boolean>;
|
|
37
37
|
mutations: {
|
|
38
|
-
pushItem: (path:
|
|
39
|
-
prependItem: (path:
|
|
40
|
-
removeItem: (path:
|
|
41
|
-
insertItem: (path:
|
|
42
|
-
moveItem: (path:
|
|
43
|
-
swapItems: (path:
|
|
38
|
+
pushItem: <P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>) => void;
|
|
39
|
+
prependItem: <P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>) => void;
|
|
40
|
+
removeItem: <P extends BitArrayPath<T>>(path: P, index: number) => void;
|
|
41
|
+
insertItem: <P extends BitArrayPath<T>>(path: P, index: number, value: BitArrayItem<BitPathValue<T, P>>) => void;
|
|
42
|
+
moveItem: <P extends BitArrayPath<T>>(path: P, from: number, to: number) => void;
|
|
43
|
+
swapItems: <P extends BitArrayPath<T>>(path: P, indexA: number, indexB: number) => void;
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
46
|
|
|
@@ -48,26 +48,26 @@ declare function useBitForm<T extends object>(): {
|
|
|
48
48
|
* Metadata describing the current state of a form field (Vue reactive).
|
|
49
49
|
*/
|
|
50
50
|
interface UseBitFieldVueMeta {
|
|
51
|
-
error:
|
|
52
|
-
touched:
|
|
53
|
-
invalid:
|
|
54
|
-
isValidating:
|
|
55
|
-
isDirty:
|
|
56
|
-
isHidden:
|
|
57
|
-
isRequired:
|
|
58
|
-
hasError:
|
|
51
|
+
error: ComputedRef<string | undefined>;
|
|
52
|
+
touched: ComputedRef<boolean>;
|
|
53
|
+
invalid: ComputedRef<boolean>;
|
|
54
|
+
isValidating: ComputedRef<boolean>;
|
|
55
|
+
isDirty: ComputedRef<boolean>;
|
|
56
|
+
isHidden: ComputedRef<boolean>;
|
|
57
|
+
isRequired: ComputedRef<boolean>;
|
|
58
|
+
hasError: ComputedRef<boolean>;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Result from useBitField hook in Vue.
|
|
62
62
|
* Provides field state, value, handlers, and metadata with Vue reactivity.
|
|
63
63
|
*/
|
|
64
64
|
interface UseBitFieldVueResult<TValue = any> {
|
|
65
|
-
value:
|
|
66
|
-
displayValue:
|
|
67
|
-
modelValue:
|
|
68
|
-
setValue: (val:
|
|
65
|
+
value: ComputedRef<TValue>;
|
|
66
|
+
displayValue: ComputedRef<string>;
|
|
67
|
+
modelValue: ComputedRef<string>;
|
|
68
|
+
setValue: (val: TValue | string | number | null | undefined) => void;
|
|
69
69
|
setBlur: () => void;
|
|
70
|
-
onInput: (val:
|
|
70
|
+
onInput: (val: TValue | string | number | null | undefined) => void;
|
|
71
71
|
onBlur: () => void;
|
|
72
72
|
meta: UseBitFieldVueMeta;
|
|
73
73
|
}
|
|
@@ -108,15 +108,25 @@ interface UseBitUploadResult {
|
|
|
108
108
|
* Provides form history undo/redo capabilities (Vue reactive).
|
|
109
109
|
*/
|
|
110
110
|
interface UseBitHistoryResult {
|
|
111
|
-
canUndo:
|
|
112
|
-
canRedo:
|
|
113
|
-
historyIndex:
|
|
114
|
-
historySize:
|
|
111
|
+
canUndo: ComputedRef<BitHistoryMetadata["canUndo"]>;
|
|
112
|
+
canRedo: ComputedRef<BitHistoryMetadata["canRedo"]>;
|
|
113
|
+
historyIndex: ComputedRef<BitHistoryMetadata["historyIndex"]>;
|
|
114
|
+
historySize: ComputedRef<BitHistoryMetadata["historySize"]>;
|
|
115
115
|
undo: () => void;
|
|
116
116
|
redo: () => void;
|
|
117
117
|
}
|
|
118
|
+
interface UseBitPersistResult {
|
|
119
|
+
restore: () => Promise<boolean>;
|
|
120
|
+
save: () => Promise<void>;
|
|
121
|
+
clear: () => Promise<void>;
|
|
122
|
+
meta: {
|
|
123
|
+
isSaving: Ref<BitPersistMetadata["isSaving"]>;
|
|
124
|
+
isRestoring: Ref<BitPersistMetadata["isRestoring"]>;
|
|
125
|
+
error: Ref<BitPersistMetadata["error"]>;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
118
128
|
|
|
119
|
-
declare function useBitField<
|
|
129
|
+
declare function useBitField<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>>(path: P): UseBitFieldVueResult<BitPathValue<TForm, P>>;
|
|
120
130
|
|
|
121
131
|
declare function useBitArray<TForm extends object = any, P extends BitArrayPath<TForm> = BitArrayPath<TForm>>(path: P): {
|
|
122
132
|
fields: vue.ComputedRef<{
|
|
@@ -167,4 +177,6 @@ declare function useBitWatch<TForm extends object = any, P extends BitPath<TForm
|
|
|
167
177
|
|
|
168
178
|
declare function useBitUpload(fieldPath: string, uploadFn: BitUploadFn, deleteFile?: BitDeleteUploadFn): UseBitUploadResult;
|
|
169
179
|
|
|
170
|
-
|
|
180
|
+
declare function useBitPersist<T extends object = any>(): UseBitPersistResult;
|
|
181
|
+
|
|
182
|
+
export { ScopeStatus, type UseBitFieldVueMeta, type UseBitFieldVueResult, type UseBitHistoryResult, type UseBitPersistResult, type UseBitStepsResult, type UseBitUploadResult, ValidateScopeResult, provideBitStore, useBitArray, useBitField, useBitForm, useBitHistory, useBitPersist, useBitScope, useBitSteps, useBitStore, useBitUpload, useBitWatch };
|
package/dist/vue/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { B as BitStoreApi, i as BitValidationOptions, d as BitHistoryMetadata, e as BitPersistMetadata } from '../public-types-Lq3eLstW.js';
|
|
2
|
+
import { i as BitErrors, A as BitTouched, G as DeepPartial, q as BitPath, r as BitPathValue, e as BitArrayPath, d as BitArrayItem, S as ScopeStatus, V as ValidateScopeResult } from '../bus-B3pGaiFZ.js';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
4
|
import { ComputedRef, Ref } from 'vue';
|
|
5
5
|
import * as _vue_reactivity from '@vue/reactivity';
|
|
6
6
|
import * as _vue_shared from '@vue/shared';
|
|
7
7
|
import { a as BitUploadFn, B as BitDeleteUploadFn } from '../types-C2mpfhp1.js';
|
|
8
8
|
|
|
9
|
-
declare function provideBitStore<T extends object>(store:
|
|
10
|
-
declare function useBitStore<T extends object>():
|
|
9
|
+
declare function provideBitStore<T extends object>(store: BitStoreApi<T>): void;
|
|
10
|
+
declare function useBitStore<T extends object>(): BitStoreApi<T>;
|
|
11
11
|
|
|
12
12
|
declare function useBitForm<T extends object>(): {
|
|
13
13
|
meta: {
|
|
@@ -24,23 +24,23 @@ declare function useBitForm<T extends object>(): {
|
|
|
24
24
|
submit: (onSuccess: (values: T, dirtyValues?: Partial<T>) => void | Promise<void>) => (e?: Event) => Promise<void>;
|
|
25
25
|
onSubmit: (handler: (values: T, dirtyValues?: Partial<T>) => Promise<unknown>) => (e?: Event) => Promise<void>;
|
|
26
26
|
reset: () => void;
|
|
27
|
+
replaceValues: (values: T) => void;
|
|
28
|
+
hydrate: (values: DeepPartial<T>) => void;
|
|
29
|
+
rebase: (values: T) => void;
|
|
27
30
|
setValues: (values: T) => void;
|
|
28
31
|
setError: (path: string, message: string | undefined) => void;
|
|
29
32
|
setErrors: (errors: BitErrors<T>) => void;
|
|
30
33
|
setServerErrors: (serverErrors: Record<string, string[] | string>) => void;
|
|
31
34
|
setField: <P extends BitPath<T, "">>(path: P, value: BitPathValue<T, P>) => void;
|
|
32
35
|
blurField: <P extends BitPath<T, "">>(path: P) => void;
|
|
33
|
-
validate: (options?:
|
|
34
|
-
scope?: string;
|
|
35
|
-
scopeFields?: string[];
|
|
36
|
-
}) => Promise<boolean>;
|
|
36
|
+
validate: (options?: BitValidationOptions) => Promise<boolean>;
|
|
37
37
|
mutations: {
|
|
38
|
-
pushItem: (path:
|
|
39
|
-
prependItem: (path:
|
|
40
|
-
removeItem: (path:
|
|
41
|
-
insertItem: (path:
|
|
42
|
-
moveItem: (path:
|
|
43
|
-
swapItems: (path:
|
|
38
|
+
pushItem: <P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>) => void;
|
|
39
|
+
prependItem: <P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>) => void;
|
|
40
|
+
removeItem: <P extends BitArrayPath<T>>(path: P, index: number) => void;
|
|
41
|
+
insertItem: <P extends BitArrayPath<T>>(path: P, index: number, value: BitArrayItem<BitPathValue<T, P>>) => void;
|
|
42
|
+
moveItem: <P extends BitArrayPath<T>>(path: P, from: number, to: number) => void;
|
|
43
|
+
swapItems: <P extends BitArrayPath<T>>(path: P, indexA: number, indexB: number) => void;
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
46
|
|
|
@@ -48,26 +48,26 @@ declare function useBitForm<T extends object>(): {
|
|
|
48
48
|
* Metadata describing the current state of a form field (Vue reactive).
|
|
49
49
|
*/
|
|
50
50
|
interface UseBitFieldVueMeta {
|
|
51
|
-
error:
|
|
52
|
-
touched:
|
|
53
|
-
invalid:
|
|
54
|
-
isValidating:
|
|
55
|
-
isDirty:
|
|
56
|
-
isHidden:
|
|
57
|
-
isRequired:
|
|
58
|
-
hasError:
|
|
51
|
+
error: ComputedRef<string | undefined>;
|
|
52
|
+
touched: ComputedRef<boolean>;
|
|
53
|
+
invalid: ComputedRef<boolean>;
|
|
54
|
+
isValidating: ComputedRef<boolean>;
|
|
55
|
+
isDirty: ComputedRef<boolean>;
|
|
56
|
+
isHidden: ComputedRef<boolean>;
|
|
57
|
+
isRequired: ComputedRef<boolean>;
|
|
58
|
+
hasError: ComputedRef<boolean>;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Result from useBitField hook in Vue.
|
|
62
62
|
* Provides field state, value, handlers, and metadata with Vue reactivity.
|
|
63
63
|
*/
|
|
64
64
|
interface UseBitFieldVueResult<TValue = any> {
|
|
65
|
-
value:
|
|
66
|
-
displayValue:
|
|
67
|
-
modelValue:
|
|
68
|
-
setValue: (val:
|
|
65
|
+
value: ComputedRef<TValue>;
|
|
66
|
+
displayValue: ComputedRef<string>;
|
|
67
|
+
modelValue: ComputedRef<string>;
|
|
68
|
+
setValue: (val: TValue | string | number | null | undefined) => void;
|
|
69
69
|
setBlur: () => void;
|
|
70
|
-
onInput: (val:
|
|
70
|
+
onInput: (val: TValue | string | number | null | undefined) => void;
|
|
71
71
|
onBlur: () => void;
|
|
72
72
|
meta: UseBitFieldVueMeta;
|
|
73
73
|
}
|
|
@@ -108,15 +108,25 @@ interface UseBitUploadResult {
|
|
|
108
108
|
* Provides form history undo/redo capabilities (Vue reactive).
|
|
109
109
|
*/
|
|
110
110
|
interface UseBitHistoryResult {
|
|
111
|
-
canUndo:
|
|
112
|
-
canRedo:
|
|
113
|
-
historyIndex:
|
|
114
|
-
historySize:
|
|
111
|
+
canUndo: ComputedRef<BitHistoryMetadata["canUndo"]>;
|
|
112
|
+
canRedo: ComputedRef<BitHistoryMetadata["canRedo"]>;
|
|
113
|
+
historyIndex: ComputedRef<BitHistoryMetadata["historyIndex"]>;
|
|
114
|
+
historySize: ComputedRef<BitHistoryMetadata["historySize"]>;
|
|
115
115
|
undo: () => void;
|
|
116
116
|
redo: () => void;
|
|
117
117
|
}
|
|
118
|
+
interface UseBitPersistResult {
|
|
119
|
+
restore: () => Promise<boolean>;
|
|
120
|
+
save: () => Promise<void>;
|
|
121
|
+
clear: () => Promise<void>;
|
|
122
|
+
meta: {
|
|
123
|
+
isSaving: Ref<BitPersistMetadata["isSaving"]>;
|
|
124
|
+
isRestoring: Ref<BitPersistMetadata["isRestoring"]>;
|
|
125
|
+
error: Ref<BitPersistMetadata["error"]>;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
118
128
|
|
|
119
|
-
declare function useBitField<
|
|
129
|
+
declare function useBitField<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>>(path: P): UseBitFieldVueResult<BitPathValue<TForm, P>>;
|
|
120
130
|
|
|
121
131
|
declare function useBitArray<TForm extends object = any, P extends BitArrayPath<TForm> = BitArrayPath<TForm>>(path: P): {
|
|
122
132
|
fields: vue.ComputedRef<{
|
|
@@ -167,4 +177,6 @@ declare function useBitWatch<TForm extends object = any, P extends BitPath<TForm
|
|
|
167
177
|
|
|
168
178
|
declare function useBitUpload(fieldPath: string, uploadFn: BitUploadFn, deleteFile?: BitDeleteUploadFn): UseBitUploadResult;
|
|
169
179
|
|
|
170
|
-
|
|
180
|
+
declare function useBitPersist<T extends object = any>(): UseBitPersistResult;
|
|
181
|
+
|
|
182
|
+
export { ScopeStatus, type UseBitFieldVueMeta, type UseBitFieldVueResult, type UseBitHistoryResult, type UseBitPersistResult, type UseBitStepsResult, type UseBitUploadResult, ValidateScopeResult, provideBitStore, useBitArray, useBitField, useBitForm, useBitHistory, useBitPersist, useBitScope, useBitSteps, useBitStore, useBitUpload, useBitWatch };
|
package/dist/vue/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{e as k,f as T,i as j,j as M}from"../chunk-6FJEE6O3.js";import{inject as z,provide as C}from"vue";var H=Symbol("BIT_STORE");function $(e){C(H,e)}function c(){let e=z(H);if(!e)throw new Error("BitForm Vue hooks devem ser usados sob um provideBitStore");return e}import{computed as I,onUnmounted as L,shallowRef as Y,ref as O}from"vue";function G(){let e=c(),t=Y({isValid:e.getState().isValid,isSubmitting:e.getState().isSubmitting,isDirty:e.getState().isDirty}),s=O(null),r=O(null),i=e.subscribeSelector(y=>({isValid:y.isValid,isSubmitting:y.isSubmitting,isDirty:y.isDirty}),y=>{t.value=y});L(i);let n=()=>e.getState().values,f=()=>e.getState().errors,u=()=>e.getState().touched,v=()=>e.getDirtyValues(),o=I(()=>t.value.isValid),a=I(()=>t.value.isSubmitting),l=I(()=>t.value.isDirty);return{meta:{isValid:o,isDirty:l,isSubmitting:a,submitError:s,lastResponse:r},getValues:n,getErrors:f,getTouched:u,getDirtyValues:v,submit:y=>B=>(B?.preventDefault?.(),e.submit(y)),onSubmit:y=>B=>(B?.preventDefault?.(),s.value=null,e.submit(async(F,m)=>{try{let d=await y(F,m);r.value=d,s.value=null}catch(d){j(d)?e.setServerErrors(M(d)):s.value=d instanceof Error?d:new Error(String(d))}})),reset:()=>{e.reset(),s.value=null,r.value=null},replaceValues:e.replaceValues.bind(e),hydrate:e.hydrate.bind(e),rebase:e.rebase.bind(e),setValues:e.setValues.bind(e),setError:e.setError.bind(e),setErrors:e.setErrors.bind(e),setServerErrors:e.setServerErrors.bind(e),setField:e.setField.bind(e),blurField:e.blurField.bind(e),validate:e.validate.bind(e),mutations:{pushItem:e.pushItem.bind(e),prependItem:e.prependItem.bind(e),removeItem:e.removeItem.bind(e),insertItem:e.insertItem.bind(e),moveItem:e.moveItem.bind(e),swapItems:e.swapItems.bind(e)}}}import{computed as g,onUnmounted as J,shallowRef as Q}from"vue";function R(e){let t=c(),s=t.resolveMask(e),r=Q(t.getFieldState(e)),i=t.subscribeSelector(()=>t.getFieldState(e),p=>{r.value=p});J(()=>{i(),t.unregisterField&&t.unregisterField(e)});let n=g(()=>r.value.value),f=g(()=>{let p=n.value;return p==null||p===""?"":s?s.format(p):String(p)}),u=g({get:()=>f.value,set:p=>{if(!s){t.setField(e,p);return}t.setField(e,s.parse(String(p??"")))}}),v=g(()=>r.value.error),o=g(()=>r.value.touched?r.value.error:void 0),a=g(()=>r.value.touched),l=g(()=>!!(a.value&&o.value)),S=g(()=>r.value.isValidating),h=g(()=>r.value.isDirty),E=g(()=>r.value.isHidden),y=g(()=>r.value.isRequired),B=g(()=>!!v.value),F=p=>{if(!s){t.setField(e,p);return}u.value=String(p??"")},m=()=>t.blurField(e);return{value:n,displayValue:f,modelValue:u,setValue:F,setBlur:m,onInput:p=>{F(p)},onBlur:()=>{m()},meta:{error:o,touched:a,invalid:l,isValidating:S,isDirty:h,isHidden:E,isRequired:y,hasError:B}}}import{ref as q,computed as K,onUnmounted as X}from"vue";var V=()=>Math.random().toString(36).substring(2,9);function Z(e){let t=c(),r=(()=>{let o=T(t.getState().values,e);return Array.isArray(o)?o:[]})(),i=q(r),n=q(r.map(V)),f=t.subscribePath(e,o=>{let a=Array.isArray(o)?o:[];if(i.value=[...a],a.length!==n.value.length){let l=[...n.value];if(a.length>l.length){let S=a.length-l.length,h=Array.from({length:S},V);n.value=[...l,...h]}else n.value=l.slice(0,a.length)}});X(()=>{f(),t.unregisterPrefix&&t.unregisterPrefix(`${e}.`)});let u=K(()=>i.value.map((o,a)=>({key:n.value[a]||`temp-${a}`,value:o,index:a}))),v=K(()=>i.value.length);return{fields:u,length:v,append:o=>{n.value.push(V()),t.pushItem(e,o)},prepend:o=>{n.value.unshift(V()),t.prependItem(e,o)},insert:(o,a)=>{n.value.splice(o,0,V()),t.insertItem(e,o,a)},remove:o=>{n.value.splice(o,1),t.removeItem(e,o)},move:(o,a)=>{let l=[...n.value],[S]=l.splice(o,1);l.splice(a,0,S),n.value=l,t.moveItem(e,o,a)},swap:(o,a)=>{let l=[...n.value];[l[o],l[a]]=[l[a],l[o]],n.value=l,t.swapItems(e,o,a)},replace:o=>{n.value=o.map(V),t.setField(e,o)},clear:()=>{n.value=[],t.setField(e,[])}}}import{computed as x,onUnmounted as N,shallowRef as ee}from"vue";function te(){let e=c(),t=ee(e.getHistoryMetadata()),s=e.subscribe(()=>{t.value=e.getHistoryMetadata()});N(s);let r=()=>e.undo(),i=()=>e.redo();return{canUndo:x(()=>t.value.canUndo),canRedo:x(()=>t.value.canRedo),historyIndex:x(()=>t.value.historyIndex),historySize:x(()=>t.value.historySize),undo:r,redo:i}}import{ref as re,computed as w,onMounted as se,onUnmounted as oe}from"vue";function ie(e,t){let s=Object.keys(e),r=Object.keys(t);return s.length!==r.length?!1:s.every(i=>e[i]===t[i])}function ne(e){let t=c(),s=re(t.getStepStatus(e)),r;se(()=>{r=t.subscribe(()=>{let o=t.getStepStatus(e);(o.hasErrors!==s.value.hasErrors||o.isDirty!==s.value.isDirty||!ie(o.errors,s.value.errors))&&(s.value=o)})}),oe(()=>{r?.()});let i=async()=>{let o=await t.validate({scope:e}),a=t.getStepErrors(e);return{valid:o,errors:a}},n=()=>t.getStepErrors(e),f=w(()=>!s.value.hasErrors),u=w(()=>s.value.isDirty),v=w(()=>s.value.errors);return{scopeName:e,status:s,errors:v,validate:i,getErrors:n,isValid:f,isDirty:u}}import{ref as W,computed as b,watch as ae,onMounted as ue,onUnmounted as le}from"vue";function ce(e,t){let s=Object.keys(e),r=Object.keys(t);return s.length!==r.length?!1:s.every(i=>e[i]===t[i])}function me(e){let t=c(),s=W(0),r=b(()=>e[s.value]??""),i=W(t.getStepStatus(r.value)),n;ae(r,m=>{i.value=t.getStepStatus(m)});let f=()=>{let m=r.value,d=t.getStepStatus(m);(d.hasErrors!==i.value.hasErrors||d.isDirty!==i.value.isDirty||!ce(d.errors,i.value.errors))&&(i.value=d)};ue(()=>{n=t.subscribe(f)}),le(()=>{n?.()});let u=async()=>{let m=r.value,d=await t.validate({scope:m}),P=t.getStepErrors(m);return{valid:d,errors:P}},v=()=>t.getStepErrors(r.value),o=async()=>{let m=r.value,d=t.getScopeFields(m);if(t.hasValidationsInProgress(d))return!1;let P=await t.validate({scope:m});if(P)s.value=Math.min(s.value+1,e.length-1);else{let p=t.getStepErrors(m),A=Object.keys(p);A.length>0&&t.markFieldsTouched(A)}return P},a=()=>{s.value=Math.max(s.value-1,0)},l=m=>{s.value=Math.max(0,Math.min(m-1,e.length-1))},S=b(()=>s.value+1),h=b(()=>s.value===0),E=b(()=>s.value>=e.length-1),y=b(()=>!i.value.hasErrors),B=b(()=>i.value.isDirty),F=b(()=>i.value.errors);return{step:S,stepIndex:s,scope:r,next:o,prev:a,goTo:l,isFirst:h,isLast:E,status:i,errors:F,isValid:y,isDirty:B,validate:u,getErrors:v}}import{ref as de,onUnmounted as pe,readonly as ve}from"vue";function fe(e){let t=c(),s=T(t.getState().values,e),r=de(s),i=t.watch(e,n=>{k(r.value,n)||(r.value=n)});return pe(i),ve(r)}import{computed as _}from"vue";function ye(e,t,s){let r=c(),i=R(e),n=null,f=async v=>{if(v){r.beginFieldValidation(e),await r.clearFieldAsyncError(e);try{let o=await t(v);i.setValue(o.url),n=o.key,await r.clearFieldAsyncError(e)}catch(o){let a=o instanceof Error?o.message:"Upload failed";await r.setFieldAsyncError(e,a)}finally{r.endFieldValidation(e)}}},u=async()=>{if(n&&s)try{await s(n)}catch(v){let o=v instanceof Error?v.message:"Delete failed";await r.setFieldAsyncError(e,o);return}i.setValue(null),n=null,await r.clearFieldAsyncError(e)};return{value:i.value,setValue:i.setValue,error:_(()=>i.meta.error.value),isValidating:_(()=>i.meta.isValidating.value||!1),upload:f,remove:u}}import{ref as U,readonly as D}from"vue";function ge(){let e=c(),t=U(!1),s=U(!1),r=U(null);return{restore:async()=>{s.value=!0,r.value=null;try{return await e.restorePersisted()}catch(u){return r.value=u instanceof Error?u:new Error(String(u)),!1}finally{s.value=!1}},save:async()=>{t.value=!0,r.value=null;try{await e.forceSave()}catch(u){r.value=u instanceof Error?u:new Error(String(u))}finally{t.value=!1}},clear:async()=>{r.value=null;try{await e.clearPersisted()}catch(u){r.value=u instanceof Error?u:new Error(String(u))}},meta:{isSaving:D(t),isRestoring:D(s),error:D(r)}}}export{$ as provideBitStore,Z as useBitArray,R as useBitField,G as useBitForm,te as useBitHistory,ge as useBitPersist,ne as useBitScope,me as useBitSteps,c as useBitStore,ye as useBitUpload,fe as useBitWatch};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|