@lehnihon/bit-form 2.2.5 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/angular/index.cjs +1 -1
  2. package/dist/angular/index.d.cts +1 -1
  3. package/dist/angular/index.d.ts +1 -1
  4. package/dist/angular/index.js +1 -1
  5. package/dist/{chunk-2FDEJYA5.js → chunk-2CVKNPWX.js} +2 -2
  6. package/dist/{chunk-3CARTBEN.cjs → chunk-3EDD3V43.cjs} +2 -2
  7. package/dist/{chunk-3CARTBEN.cjs.map → chunk-3EDD3V43.cjs.map} +1 -1
  8. package/dist/chunk-PX6WKENM.js +2 -0
  9. package/dist/chunk-PX6WKENM.js.map +1 -0
  10. package/dist/{chunk-UMKOKAPD.js → chunk-T3FR7D5V.js} +2 -2
  11. package/dist/{chunk-JIWR4KSZ.cjs → chunk-Y2ONHDRE.cjs} +2 -2
  12. package/dist/{chunk-JIWR4KSZ.cjs.map → chunk-Y2ONHDRE.cjs.map} +1 -1
  13. package/dist/chunk-YCSWULEN.cjs +2 -0
  14. package/dist/{chunk-OZKLQRO6.cjs.map → chunk-YCSWULEN.cjs.map} +1 -1
  15. package/dist/devtools/bridge.cjs +1 -1
  16. package/dist/devtools/bridge.js +1 -1
  17. package/dist/devtools/index.cjs +2 -2
  18. package/dist/devtools/index.js +1 -1
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.d.cts +23 -2
  21. package/dist/index.d.ts +23 -2
  22. package/dist/index.js +1 -1
  23. package/dist/{public-types-BQXaxmAE.d.cts → public-types-Cd9ai20P.d.cts} +3 -0
  24. package/dist/{public-types-CVgFf_qY.d.ts → public-types-DdZxD6Op.d.ts} +3 -0
  25. package/dist/react/index.cjs +1 -1
  26. package/dist/react/index.cjs.map +1 -1
  27. package/dist/react/index.d.cts +3 -3
  28. package/dist/react/index.d.ts +3 -3
  29. package/dist/react/index.js +1 -1
  30. package/dist/react/index.js.map +1 -1
  31. package/dist/react-native/index.cjs +1 -1
  32. package/dist/react-native/index.d.cts +2 -2
  33. package/dist/react-native/index.d.ts +2 -2
  34. package/dist/react-native/index.js +1 -1
  35. package/dist/{use-bit-persist-CIVN-oIi.d.cts → use-bit-persist-D_gimC9A.d.cts} +1 -1
  36. package/dist/{use-bit-persist-iPWLbD8l.d.ts → use-bit-persist-Dk3fUrds.d.ts} +1 -1
  37. package/dist/vue/index.cjs +1 -1
  38. package/dist/vue/index.d.cts +1 -1
  39. package/dist/vue/index.d.ts +1 -1
  40. package/dist/vue/index.js +1 -1
  41. package/package.json +1 -1
  42. package/dist/chunk-64KSP4TP.js +0 -2
  43. package/dist/chunk-64KSP4TP.js.map +0 -1
  44. package/dist/chunk-OZKLQRO6.cjs +0 -2
  45. /package/dist/{chunk-2FDEJYA5.js.map → chunk-2CVKNPWX.js.map} +0 -0
  46. /package/dist/{chunk-UMKOKAPD.js.map → chunk-T3FR7D5V.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/bit-form/bit-form/dist/react/index.cjs","../../src/react/use-bit-field.ts","../../src/react/use-bit-history.ts","../../src/react/use-bit-upload.ts"],"names":["useBitField","path","fieldState","rawSetValue","setBlur","store","useBitFieldBase","resolvedMask","useMemo","displayValue","formatMaskedValue","setValue","useCallback","val","parseMaskedInput","isHidden","isRequired","value","error","touched","isDirty","isValidating","invalid","visibleError","onChange","e","isBitFieldInputEventObject","onBlur","useBitHistory","useBitStore","lastMeta","useRef","getSnapshot","nextMeta","isHistoryMetaEqual","stableMeta","subscribe","cb","meta","useSyncExternalStore","undo","redo","useBitUpload","fieldPath","uploadFn","deleteFile","field","uploadKeyRef","isUploading","setIsUploading","useState","kernelCallbacks","msg","key","upload","createUploadHandler","remove","createRemoveHandler"],"mappings":"AAAA,0uBAAiG,yDAAwD,iCAA8B,iCAA8B,yDAAwD,8BCAxO,SAerBA,CAAAA,CAGdC,CAAAA,CAAsC,CACtC,GAAM,CACJ,UAAA,CAAA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CAAA,CAEMC,CAAAA,CAAS1C,gCAAAA,iCACb2C,CAAoBZ,CAAWC,CAAAA,CAAUO,CAAe,CAAA,CACxD,CAACP,CAAAA,CAAUE,CAAAA,CAAOH,CAAAA,CAAWtC,CAAK,CACpC,CAAA,CAEMmD,CAAAA,CAAS5C,gCAAAA,iCACb6C,CAAoBd,CAAWE,CAAAA,CAAYM,CAAe,CAAA,CAC1D,CAACN,CAAAA,CAAYC,CAAAA,CAAOH,CAAAA,CAAWtC,CAAK,CACtC,CAAA,CAEA,MAAO,CACL,KAAA,CAAOyC,CAAAA,CAAM,KAAA,CACb,QAAA,CAAUA,CAAAA,CAAM,QAAA,CAChB,KAAA,iBAAOA,CAAAA,qBAAM,IAAA,6BAAM,OAAA,CACnB,YAAA,CAAc,CAAC,iBAACA,CAAAA,qBAAM,IAAA,6BAAM,cAAA,EAAgBE,CAAAA,CAC5C,MAAA,CAAAM,CAAAA,CACA,MAAA,CAAAE,CACF,CACF,CAAA,0aAAA","file":"/home/runner/work/bit-form/bit-form/dist/react/index.cjs","sourcesContent":[null,"import { useMemo, useCallback } from \"react\";\nimport { useBitFieldBase } from \"./use-bit-field-base\";\nimport { BitPath, BitPathValue } from \"../core\";\nimport {\n formatMaskedValue,\n parseMaskedInput,\n isBitFieldInputEventObject,\n} from \"../core/mask/field-binding\";\nimport type {\n BitFieldInputEvent,\n UseBitFieldMeta,\n UseBitFieldBindProps,\n UseBitFieldResult,\n} from \"./types\";\n\nexport function useBitField<\n TForm extends object = any,\n P extends BitPath<TForm> = BitPath<TForm>,\n>(path: P): UseBitFieldResult<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 () => formatMaskedValue(fieldState.value, resolvedMask ?? undefined),\n [fieldState.value, resolvedMask],\n );\n\n const setValue = useCallback(\n (val: BitPathValue<TForm, P> | string | number | null | undefined) =>\n rawSetValue(\n parseMaskedInput(val, resolvedMask ?? undefined) as BitPathValue<\n TForm,\n P\n >,\n ),\n [resolvedMask, rawSetValue],\n );\n\n const { isHidden, isRequired, value, error, touched, isDirty, isValidating } =\n fieldState;\n\n const invalid = !!(touched && error);\n const visibleError = touched ? error : undefined;\n\n const onChange = useCallback(\n (e: BitFieldInputEvent) => {\n const val = isBitFieldInputEventObject(e) ? e.target?.value : e;\n setValue(val);\n },\n [setValue],\n );\n\n const onBlur = useCallback(() => {\n setBlur();\n }, [setBlur]);\n\n return {\n // Main handlers and values (flat)\n value: value as BitPathValue<TForm, P>,\n displayValue,\n setValue,\n setBlur,\n onChange,\n onBlur,\n // Props helper\n props: {\n value: displayValue,\n onChange,\n onBlur,\n },\n // Metadata (grouped)\n meta: {\n error: visibleError,\n touched,\n invalid,\n isDirty,\n isValidating,\n isHidden,\n isRequired,\n hasError: !!error,\n },\n };\n}\n","import { useCallback, useRef, useSyncExternalStore } from \"react\";\nimport { isHistoryMetaEqual, type HistoryMeta } from \"../core/history-status\";\nimport { useBitStore } from \"./context\";\nimport type { UseBitHistoryResult } from \"./types\";\n\nexport function useBitHistory<T extends object = any>(): UseBitHistoryResult {\n const store = useBitStore<T>();\n const lastMeta = useRef<HistoryMeta | null>(null);\n\n const getSnapshot = useCallback(() => {\n const nextMeta = store.getHistoryMetadata();\n\n if (lastMeta.current && isHistoryMetaEqual(lastMeta.current, nextMeta)) {\n return lastMeta.current;\n }\n\n const stableMeta = {\n canUndo: nextMeta.canUndo,\n canRedo: nextMeta.canRedo,\n historyIndex: nextMeta.historyIndex,\n historySize: nextMeta.historySize,\n };\n\n lastMeta.current = stableMeta;\n return stableMeta;\n }, [store]);\n\n const subscribe = useCallback(\n (cb: () => void) => store.subscribe(cb),\n [store],\n );\n\n const meta = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n const undo = useCallback(() => {\n store.undo();\n }, [store]);\n\n const redo = useCallback(() => {\n store.redo();\n }, [store]);\n\n return {\n ...meta,\n undo,\n redo,\n };\n}\n","/**\n * React Hook for File Upload Integration\n *\n * Minimal upload API integrated with global field validation lifecycle.\n *\n * @example\n * ```typescript\n * const avatar = useBitUpload(\"avatar\", uploadFn);\n *\n * return (\n * <>\n * <input\n * type=\"file\"\n * onChange={(e) => avatar.upload(e.target.files?.[0])}\n * disabled={avatar.isValidating}\n * />\n * {avatar.error && <Error>{avatar.error}</Error>}\n * </>\n * );\n * ```\n */\n\nimport { useCallback, useRef, useState } from \"react\";\nimport { useBitField } from \"./use-bit-field\";\nimport { useBitStore } from \"./context\";\nimport { BitUploadFn, BitDeleteUploadFn } from \"../core\";\nimport { createUploadHandler, createRemoveHandler } from \"../core/adapters\";\nimport type { UseBitUploadResult } from \"./types\";\n\nexport function useBitUpload(\n fieldPath: string,\n uploadFn: BitUploadFn,\n deleteFile?: BitDeleteUploadFn,\n): UseBitUploadResult {\n const store = useBitStore<any>();\n const field = useBitField(fieldPath);\n const uploadKeyRef = useRef<string | null>(null);\n const [isUploading, setIsUploading] = useState(false);\n\n const kernelCallbacks = {\n setLoading: setIsUploading,\n setError: (path: string, msg: string | undefined) =>\n store.setError(path, msg),\n setValue: (val: string | null) => field.setValue(val as any),\n getUploadKey: () => uploadKeyRef.current,\n setUploadKey: (key: string | null) => {\n uploadKeyRef.current = key;\n },\n };\n\n const upload = useCallback(\n createUploadHandler(fieldPath, uploadFn, kernelCallbacks),\n [uploadFn, field, fieldPath, store],\n );\n\n const remove = useCallback(\n createRemoveHandler(fieldPath, deleteFile, kernelCallbacks),\n [deleteFile, field, fieldPath, store],\n );\n\n return {\n value: field.value,\n setValue: field.setValue,\n error: field.meta?.error,\n isValidating: !!field.meta?.isValidating || isUploading,\n upload,\n remove,\n };\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/bit-form/bit-form/dist/react/index.cjs","../../src/react/use-bit-field.ts","../../src/react/use-bit-history.ts","../../src/react/use-bit-upload.ts"],"names":["useBitField","path","fieldState","rawSetValue","setBlur","store","useBitFieldBase","masksVersion","useSyncExternalStore","cb","resolvedMask","useMemo","displayValue","formatMaskedValue","setValue","useCallback","val","parseMaskedInput","isHidden","isRequired","value","error","touched","isDirty","isValidating","invalid","visibleError","onChange","e","isBitFieldInputEventObject","onBlur","useBitHistory","useBitStore","lastMeta","useRef","getSnapshot","nextMeta","isHistoryMetaEqual","stableMeta","subscribe","meta","undo","redo","useBitUpload","fieldPath","uploadFn","deleteFile","field","uploadKeyRef","isUploading","setIsUploading","useState","kernelCallbacks","msg","key","upload","createUploadHandler","remove","createRemoveHandler"],"mappings":"AAAA,0uBAAiG,yDAAmD,iCAA8B,iCAA8B,yDAAwD,8BCA7M,SAe3CA,CAAAA,CAGdC,CAAAA,CAAsC,CACtC,GAAM,CACJ,UAAA,CAAAC,CAAAA,CACA,QAAA,CAAUC,CAAAA,CACV,OAAA,CAAAC,CAAAA,CACA,KAAA,CAAAC,CACF,CAAA,CAAIC,iCAAAA,CAAsD,CAAA,CAMpDC,CAAAA,CAAeC,yCAAAA,CAElBC,EAAOJ,CAAAA,CAAM,SAAA,CAAUI,CAAE,CAAA,CAC1B,CAAA,CAAA,EAAMJ,CAAAA,CAAM,eAAA,CAAgB,CAAA,CAC5B,CAAA,CAAA,EAAMA,CAAAA,CAAM,eAAA,CAAgB,CAC9B,CAAA,CAEMK,CAAAA,CAAeC,4BAAAA,CAAQ,CAAA,EACpBN,CAAAA,CAAM,WAAA,CAAYJ,CAAc,CAAA,CACtC,CAACM,CAAAA,CAAcF,CAAAA,CAAM,MAAA,CAAO,MAAA,CAAQJ,CAAI,CAAC,CAAA,CAEtCW,CAAAA,CAAeD,4BAAAA,CACnB,CAAA,EAAME,iCAAAA,CAAkBX,CAAW,KAAA,kBAAOQ,CAAAA,SAAgB,KAAA,GAAS,CAAA,CACnE,CAACR,CAAAA,CAAW,KAAA,CAAOQ,CAAY,CACjC,CAAA,CAEMI,CAAAA,CAAWC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AM,cAAA,EAAgBE,CAAAA,CAC5C,MAAA,CAAAM,CAAAA,CACA,MAAA,CAAAE,CACF,CACF,CAAA,0aAAA","file":"/home/runner/work/bit-form/bit-form/dist/react/index.cjs","sourcesContent":[null,"import { useMemo, useCallback, useSyncExternalStore } from \"react\";\nimport { useBitFieldBase } from \"./use-bit-field-base\";\nimport { BitPath, BitPathValue } from \"../core\";\nimport {\n formatMaskedValue,\n parseMaskedInput,\n isBitFieldInputEventObject,\n} from \"../core/mask/field-binding\";\nimport type {\n BitFieldInputEvent,\n UseBitFieldMeta,\n UseBitFieldBindProps,\n UseBitFieldResult,\n} from \"./types\";\n\nexport function useBitField<\n TForm extends object = any,\n P extends BitPath<TForm> = BitPath<TForm>,\n>(path: P): UseBitFieldResult<TForm, P> {\n const {\n fieldState,\n setValue: rawSetValue,\n setBlur,\n store,\n } = useBitFieldBase<BitPathValue<TForm, P>, TForm, P>(path);\n\n // Track mask registrations reactively. getMasksVersion() returns a counter\n // that increments on every registerMask() call. useSyncExternalStore fires\n // the snapshot on every store notification; the integer comparison is O(1)\n // so this only triggers a re-render when a mask is actually added.\n const masksVersion = useSyncExternalStore(\n // store.subscribe fires on every state change (global listener)\n (cb) => store.subscribe(cb),\n () => store.getMasksVersion(),\n () => store.getMasksVersion(),\n );\n\n const resolvedMask = useMemo(() => {\n return store.resolveMask(path as string);\n }, [masksVersion, store.config.fields, path]);\n\n const displayValue = useMemo(\n () => formatMaskedValue(fieldState.value, resolvedMask ?? undefined),\n [fieldState.value, resolvedMask],\n );\n\n const setValue = useCallback(\n (val: BitPathValue<TForm, P> | string | number | null | undefined) =>\n rawSetValue(\n parseMaskedInput(val, resolvedMask ?? undefined) as BitPathValue<\n TForm,\n P\n >,\n ),\n [resolvedMask, rawSetValue],\n );\n\n const { isHidden, isRequired, value, error, touched, isDirty, isValidating } =\n fieldState;\n\n const invalid = !!(touched && error);\n const visibleError = touched ? error : undefined;\n\n const onChange = useCallback(\n (e: BitFieldInputEvent) => {\n const val = isBitFieldInputEventObject(e) ? e.target?.value : e;\n setValue(val);\n },\n [setValue],\n );\n\n const onBlur = useCallback(() => {\n setBlur();\n }, [setBlur]);\n\n return {\n // Main handlers and values (flat)\n value: value as BitPathValue<TForm, P>,\n displayValue,\n setValue,\n setBlur,\n onChange,\n onBlur,\n // Props helper\n props: {\n value: displayValue,\n onChange,\n onBlur,\n },\n // Metadata (grouped)\n meta: {\n error: visibleError,\n touched,\n invalid,\n isDirty,\n isValidating,\n isHidden,\n isRequired,\n hasError: !!error,\n },\n };\n}\n","import { useCallback, useRef, useSyncExternalStore } from \"react\";\nimport { isHistoryMetaEqual, type HistoryMeta } from \"../core/history-status\";\nimport { useBitStore } from \"./context\";\nimport type { UseBitHistoryResult } from \"./types\";\n\nexport function useBitHistory<T extends object = any>(): UseBitHistoryResult {\n const store = useBitStore<T>();\n const lastMeta = useRef<HistoryMeta | null>(null);\n\n const getSnapshot = useCallback(() => {\n const nextMeta = store.getHistoryMetadata();\n\n if (lastMeta.current && isHistoryMetaEqual(lastMeta.current, nextMeta)) {\n return lastMeta.current;\n }\n\n const stableMeta = {\n canUndo: nextMeta.canUndo,\n canRedo: nextMeta.canRedo,\n historyIndex: nextMeta.historyIndex,\n historySize: nextMeta.historySize,\n };\n\n lastMeta.current = stableMeta;\n return stableMeta;\n }, [store]);\n\n const subscribe = useCallback(\n (cb: () => void) => store.subscribe(cb),\n [store],\n );\n\n const meta = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n const undo = useCallback(() => {\n store.undo();\n }, [store]);\n\n const redo = useCallback(() => {\n store.redo();\n }, [store]);\n\n return {\n ...meta,\n undo,\n redo,\n };\n}\n","/**\n * React Hook for File Upload Integration\n *\n * Minimal upload API integrated with global field validation lifecycle.\n *\n * @example\n * ```typescript\n * const avatar = useBitUpload(\"avatar\", uploadFn);\n *\n * return (\n * <>\n * <input\n * type=\"file\"\n * onChange={(e) => avatar.upload(e.target.files?.[0])}\n * disabled={avatar.isValidating}\n * />\n * {avatar.error && <Error>{avatar.error}</Error>}\n * </>\n * );\n * ```\n */\n\nimport { useCallback, useRef, useState } from \"react\";\nimport { useBitField } from \"./use-bit-field\";\nimport { useBitStore } from \"./context\";\nimport { BitUploadFn, BitDeleteUploadFn } from \"../core\";\nimport { createUploadHandler, createRemoveHandler } from \"../core/adapters\";\nimport type { UseBitUploadResult } from \"./types\";\n\nexport function useBitUpload(\n fieldPath: string,\n uploadFn: BitUploadFn,\n deleteFile?: BitDeleteUploadFn,\n): UseBitUploadResult {\n const store = useBitStore<any>();\n const field = useBitField(fieldPath);\n const uploadKeyRef = useRef<string | null>(null);\n const [isUploading, setIsUploading] = useState(false);\n\n const kernelCallbacks = {\n setLoading: setIsUploading,\n setError: (path: string, msg: string | undefined) =>\n store.setError(path, msg),\n setValue: (val: string | null) => field.setValue(val as any),\n getUploadKey: () => uploadKeyRef.current,\n setUploadKey: (key: string | null) => {\n uploadKeyRef.current = key;\n },\n };\n\n const upload = useCallback(\n createUploadHandler(fieldPath, uploadFn, kernelCallbacks),\n [uploadFn, field, fieldPath, store],\n );\n\n const remove = useCallback(\n createRemoveHandler(fieldPath, deleteFile, kernelCallbacks),\n [deleteFile, field, fieldPath, store],\n );\n\n return {\n value: field.value,\n setValue: field.setValue,\n error: field.meta?.error,\n isValidating: !!field.meta?.isValidating || isUploading,\n upload,\n remove,\n };\n}\n"]}
@@ -1,11 +1,11 @@
1
- import { g as UseBitFieldResult, h as UseBitHistoryResult, i as UseBitUploadResult } from '../use-bit-persist-CIVN-oIi.cjs';
2
- export { B as BitFormProvider, j as UseBitFieldBindProps, k as UseBitFieldMeta, U as UseBitPersistResult, l as UseBitStepsResult, u as useBitArray, a as useBitForm, b as useBitPersist, c as useBitScope, d as useBitSteps, e as useBitStore, f as useBitWatch } from '../use-bit-persist-CIVN-oIi.cjs';
1
+ import { g as UseBitFieldResult, h as UseBitHistoryResult, i as UseBitUploadResult } from '../use-bit-persist-D_gimC9A.cjs';
2
+ export { B as BitFormProvider, j as UseBitFieldBindProps, k as UseBitFieldMeta, U as UseBitPersistResult, l as UseBitStepsResult, u as useBitArray, a as useBitForm, b as useBitPersist, c as useBitScope, d as useBitSteps, e as useBitStore, f as useBitWatch } from '../use-bit-persist-D_gimC9A.cjs';
3
3
  import { f as BitPath } from '../bus-BeAeZwWu.cjs';
4
4
  export { S as ScopeStatus, n as ValidateScopeResult } from '../bus-BeAeZwWu.cjs';
5
5
  import { B as BitUploadFn, a as BitDeleteUploadFn } from '../upload-EXnJLq8k.cjs';
6
6
  import 'react/jsx-runtime';
7
7
  import 'react';
8
- import '../public-types-BQXaxmAE.cjs';
8
+ import '../public-types-Cd9ai20P.cjs';
9
9
  import '../types-D8DgIUhJ.cjs';
10
10
  import '../field-binding-BXw0Ku2c.cjs';
11
11
 
@@ -1,11 +1,11 @@
1
- import { g as UseBitFieldResult, h as UseBitHistoryResult, i as UseBitUploadResult } from '../use-bit-persist-iPWLbD8l.js';
2
- export { B as BitFormProvider, j as UseBitFieldBindProps, k as UseBitFieldMeta, U as UseBitPersistResult, l as UseBitStepsResult, u as useBitArray, a as useBitForm, b as useBitPersist, c as useBitScope, d as useBitSteps, e as useBitStore, f as useBitWatch } from '../use-bit-persist-iPWLbD8l.js';
1
+ import { g as UseBitFieldResult, h as UseBitHistoryResult, i as UseBitUploadResult } from '../use-bit-persist-Dk3fUrds.js';
2
+ export { B as BitFormProvider, j as UseBitFieldBindProps, k as UseBitFieldMeta, U as UseBitPersistResult, l as UseBitStepsResult, u as useBitArray, a as useBitForm, b as useBitPersist, c as useBitScope, d as useBitSteps, e as useBitStore, f as useBitWatch } from '../use-bit-persist-Dk3fUrds.js';
3
3
  import { f as BitPath } from '../bus-B4zZmB9C.js';
4
4
  export { S as ScopeStatus, n as ValidateScopeResult } from '../bus-B4zZmB9C.js';
5
5
  import { B as BitUploadFn, a as BitDeleteUploadFn } from '../upload-EXnJLq8k.js';
6
6
  import 'react/jsx-runtime';
7
7
  import 'react';
8
- import '../public-types-CVgFf_qY.js';
8
+ import '../public-types-DdZxD6Op.js';
9
9
  import '../types-D8DgIUhJ.js';
10
10
  import '../field-binding-BXw0Ku2c.js';
11
11
 
@@ -1,2 +1,2 @@
1
- import{a as C,b as m,c as j,d as V,e as D,f as K,g as q,h as z,i as w}from"../chunk-UMKOKAPD.js";import{a as P,b as S,c as b}from"../chunk-QWH2NBVB.js";import"../chunk-2FDEJYA5.js";import"../chunk-64KSP4TP.js";import{a as g,b as v,c as R}from"../chunk-3NUJVIAM.js";import{useMemo as M,useCallback as y}from"react";function U(e){let{fieldState:o,setValue:a,setBlur:s,store:t}=V(e),i=M(()=>t.resolveMask(e),[t.config.masks,t.config.fields,e]),u=M(()=>v(o.value,i??void 0),[o.value,i]),r=y(p=>a(R(p,i??void 0)),[i,a]),{isHidden:l,isRequired:B,value:f,error:n,touched:d,isDirty:h,isValidating:T}=o,k=!!(d&&n),E=d?n:void 0,F=y(p=>{let I=g(p)?p.target?.value:p;r(I)},[r]),x=y(()=>{s()},[s]);return{value:f,displayValue:u,setValue:r,setBlur:s,onChange:F,onBlur:x,props:{value:u,onChange:F,onBlur:x},meta:{error:E,touched:d,invalid:k,isDirty:h,isValidating:T,isHidden:l,isRequired:B,hasError:!!n}}}import{useCallback as c,useRef as A,useSyncExternalStore as L}from"react";function O(){let e=m(),o=A(null),a=c(()=>{let r=e.getHistoryMetadata();if(o.current&&P(o.current,r))return o.current;let l={canUndo:r.canUndo,canRedo:r.canRedo,historyIndex:r.historyIndex,historySize:r.historySize};return o.current=l,l},[e]),s=c(r=>e.subscribe(r),[e]),t=L(s,a,a),i=c(()=>{e.undo()},[e]),u=c(()=>{e.redo()},[e]);return{...t,undo:i,redo:u}}import{useCallback as H,useRef as W,useState as G}from"react";function J(e,o,a){let s=m(),t=U(e),i=W(null),[u,r]=G(!1),l={setLoading:r,setError:(n,d)=>s.setError(n,d),setValue:n=>t.setValue(n),getUploadKey:()=>i.current,setUploadKey:n=>{i.current=n}},B=H(S(e,o,l),[o,t,e,s]),f=H(b(e,a,l),[a,t,e,s]);return{value:t.value,setValue:t.setValue,error:t.meta?.error,isValidating:!!t.meta?.isValidating||u,upload:B,remove:f}}export{C as BitFormProvider,D as useBitArray,U as useBitField,j as useBitForm,O as useBitHistory,w as useBitPersist,K as useBitScope,q as useBitSteps,m as useBitStore,J as useBitUpload,z as useBitWatch};
1
+ import{a as j,b as m,c as D,d as S,e as K,f as q,g as z,h as w,i as A}from"../chunk-T3FR7D5V.js";import{a as P,b,c as M}from"../chunk-QWH2NBVB.js";import"../chunk-2CVKNPWX.js";import"../chunk-PX6WKENM.js";import{a as V,b as v,c as R}from"../chunk-3NUJVIAM.js";import{useMemo as k,useCallback as U,useSyncExternalStore as L}from"react";function F(e){let{fieldState:s,setValue:n,setBlur:o,store:t}=S(e),d=L(u=>t.subscribe(u),()=>t.getMasksVersion(),()=>t.getMasksVersion()),a=k(()=>t.resolveMask(e),[d,t.config.fields,e]),r=k(()=>v(s.value,a??void 0),[s.value,a]),i=U(u=>n(R(u,a??void 0)),[a,n]),{isHidden:B,isRequired:f,value:l,error:p,touched:y,isDirty:h,isValidating:T}=s,E=!!(y&&p),I=y?p:void 0,x=U(u=>{let C=V(u)?u.target?.value:u;i(C)},[i]),g=U(()=>{o()},[o]);return{value:l,displayValue:r,setValue:i,setBlur:o,onChange:x,onBlur:g,props:{value:r,onChange:x,onBlur:g},meta:{error:I,touched:y,invalid:E,isDirty:h,isValidating:T,isHidden:B,isRequired:f,hasError:!!p}}}import{useCallback as c,useRef as O,useSyncExternalStore as W}from"react";function G(){let e=m(),s=O(null),n=c(()=>{let r=e.getHistoryMetadata();if(s.current&&P(s.current,r))return s.current;let i={canUndo:r.canUndo,canRedo:r.canRedo,historyIndex:r.historyIndex,historySize:r.historySize};return s.current=i,i},[e]),o=c(r=>e.subscribe(r),[e]),t=W(o,n,n),d=c(()=>{e.undo()},[e]),a=c(()=>{e.redo()},[e]);return{...t,undo:d,redo:a}}import{useCallback as H,useRef as J,useState as N}from"react";function Q(e,s,n){let o=m(),t=F(e),d=J(null),[a,r]=N(!1),i={setLoading:r,setError:(l,p)=>o.setError(l,p),setValue:l=>t.setValue(l),getUploadKey:()=>d.current,setUploadKey:l=>{d.current=l}},B=H(b(e,s,i),[s,t,e,o]),f=H(M(e,n,i),[n,t,e,o]);return{value:t.value,setValue:t.setValue,error:t.meta?.error,isValidating:!!t.meta?.isValidating||a,upload:B,remove:f}}export{j as BitFormProvider,K as useBitArray,F as useBitField,D as useBitForm,G as useBitHistory,A as useBitPersist,q as useBitScope,z as useBitSteps,m as useBitStore,Q as useBitUpload,w as useBitWatch};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/use-bit-field.ts","../../src/react/use-bit-history.ts","../../src/react/use-bit-upload.ts"],"sourcesContent":["import { useMemo, useCallback } from \"react\";\nimport { useBitFieldBase } from \"./use-bit-field-base\";\nimport { BitPath, BitPathValue } from \"../core\";\nimport {\n formatMaskedValue,\n parseMaskedInput,\n isBitFieldInputEventObject,\n} from \"../core/mask/field-binding\";\nimport type {\n BitFieldInputEvent,\n UseBitFieldMeta,\n UseBitFieldBindProps,\n UseBitFieldResult,\n} from \"./types\";\n\nexport function useBitField<\n TForm extends object = any,\n P extends BitPath<TForm> = BitPath<TForm>,\n>(path: P): UseBitFieldResult<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 () => formatMaskedValue(fieldState.value, resolvedMask ?? undefined),\n [fieldState.value, resolvedMask],\n );\n\n const setValue = useCallback(\n (val: BitPathValue<TForm, P> | string | number | null | undefined) =>\n rawSetValue(\n parseMaskedInput(val, resolvedMask ?? undefined) as BitPathValue<\n TForm,\n P\n >,\n ),\n [resolvedMask, rawSetValue],\n );\n\n const { isHidden, isRequired, value, error, touched, isDirty, isValidating } =\n fieldState;\n\n const invalid = !!(touched && error);\n const visibleError = touched ? error : undefined;\n\n const onChange = useCallback(\n (e: BitFieldInputEvent) => {\n const val = isBitFieldInputEventObject(e) ? e.target?.value : e;\n setValue(val);\n },\n [setValue],\n );\n\n const onBlur = useCallback(() => {\n setBlur();\n }, [setBlur]);\n\n return {\n // Main handlers and values (flat)\n value: value as BitPathValue<TForm, P>,\n displayValue,\n setValue,\n setBlur,\n onChange,\n onBlur,\n // Props helper\n props: {\n value: displayValue,\n onChange,\n onBlur,\n },\n // Metadata (grouped)\n meta: {\n error: visibleError,\n touched,\n invalid,\n isDirty,\n isValidating,\n isHidden,\n isRequired,\n hasError: !!error,\n },\n };\n}\n","import { useCallback, useRef, useSyncExternalStore } from \"react\";\nimport { isHistoryMetaEqual, type HistoryMeta } from \"../core/history-status\";\nimport { useBitStore } from \"./context\";\nimport type { UseBitHistoryResult } from \"./types\";\n\nexport function useBitHistory<T extends object = any>(): UseBitHistoryResult {\n const store = useBitStore<T>();\n const lastMeta = useRef<HistoryMeta | null>(null);\n\n const getSnapshot = useCallback(() => {\n const nextMeta = store.getHistoryMetadata();\n\n if (lastMeta.current && isHistoryMetaEqual(lastMeta.current, nextMeta)) {\n return lastMeta.current;\n }\n\n const stableMeta = {\n canUndo: nextMeta.canUndo,\n canRedo: nextMeta.canRedo,\n historyIndex: nextMeta.historyIndex,\n historySize: nextMeta.historySize,\n };\n\n lastMeta.current = stableMeta;\n return stableMeta;\n }, [store]);\n\n const subscribe = useCallback(\n (cb: () => void) => store.subscribe(cb),\n [store],\n );\n\n const meta = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n const undo = useCallback(() => {\n store.undo();\n }, [store]);\n\n const redo = useCallback(() => {\n store.redo();\n }, [store]);\n\n return {\n ...meta,\n undo,\n redo,\n };\n}\n","/**\n * React Hook for File Upload Integration\n *\n * Minimal upload API integrated with global field validation lifecycle.\n *\n * @example\n * ```typescript\n * const avatar = useBitUpload(\"avatar\", uploadFn);\n *\n * return (\n * <>\n * <input\n * type=\"file\"\n * onChange={(e) => avatar.upload(e.target.files?.[0])}\n * disabled={avatar.isValidating}\n * />\n * {avatar.error && <Error>{avatar.error}</Error>}\n * </>\n * );\n * ```\n */\n\nimport { useCallback, useRef, useState } from \"react\";\nimport { useBitField } from \"./use-bit-field\";\nimport { useBitStore } from \"./context\";\nimport { BitUploadFn, BitDeleteUploadFn } from \"../core\";\nimport { createUploadHandler, createRemoveHandler } from \"../core/adapters\";\nimport type { UseBitUploadResult } from \"./types\";\n\nexport function useBitUpload(\n fieldPath: string,\n uploadFn: BitUploadFn,\n deleteFile?: BitDeleteUploadFn,\n): UseBitUploadResult {\n const store = useBitStore<any>();\n const field = useBitField(fieldPath);\n const uploadKeyRef = useRef<string | null>(null);\n const [isUploading, setIsUploading] = useState(false);\n\n const kernelCallbacks = {\n setLoading: setIsUploading,\n setError: (path: string, msg: string | undefined) =>\n store.setError(path, msg),\n setValue: (val: string | null) => field.setValue(val as any),\n getUploadKey: () => uploadKeyRef.current,\n setUploadKey: (key: string | null) => {\n uploadKeyRef.current = key;\n },\n };\n\n const upload = useCallback(\n createUploadHandler(fieldPath, uploadFn, kernelCallbacks),\n [uploadFn, field, fieldPath, store],\n );\n\n const remove = useCallback(\n createRemoveHandler(fieldPath, deleteFile, kernelCallbacks),\n [deleteFile, field, fieldPath, store],\n );\n\n return {\n value: field.value,\n setValue: field.setValue,\n error: field.meta?.error,\n isValidating: !!field.meta?.isValidating || isUploading,\n upload,\n remove,\n };\n}\n"],"mappings":"yQAAA,OAAS,WAAAA,EAAS,eAAAC,MAAmB,QAe9B,SAASC,EAGdC,EAAsC,CACtC,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,OAAQ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lur","store","useBitFieldBase","resolvedMask","useMemo","displayValue","formatMaskedValue","setValue","useCallback","val","parseMaskedInput","isHidden","isRequired","value","error","touched","isDirty","isValidating","invalid","visibleError","onChange","e","isBitFieldInputEventObject","onBlur","useCallback","useRef","useSyncExternalStore","useBitHistory","store","useBitStore","lastMeta","useRef","getSnapshot","useCallback","nextMeta","isHistoryMetaEqual","stableMeta","subscribe","cb","meta","useSyncExternalStore","undo","redo","useCallback","useRef","useState","useBitUpload","fieldPath","uploadFn","deleteFile","store","useBitStore","field","useBitField","uploadKeyRef","useRef","isUploading","setIsUploading","useState","kernelCallbacks","path","msg","val","key","upload","useCallback","createUploadHandler","remove","createRemoveHandler"]}
1
+ {"version":3,"sources":["../../src/react/use-bit-field.ts","../../src/react/use-bit-history.ts","../../src/react/use-bit-upload.ts"],"sourcesContent":["import { useMemo, useCallback, useSyncExternalStore } from \"react\";\nimport { useBitFieldBase } from \"./use-bit-field-base\";\nimport { BitPath, BitPathValue } from \"../core\";\nimport {\n formatMaskedValue,\n parseMaskedInput,\n isBitFieldInputEventObject,\n} from \"../core/mask/field-binding\";\nimport type {\n BitFieldInputEvent,\n UseBitFieldMeta,\n UseBitFieldBindProps,\n UseBitFieldResult,\n} from \"./types\";\n\nexport function useBitField<\n TForm extends object = any,\n P extends BitPath<TForm> = BitPath<TForm>,\n>(path: P): UseBitFieldResult<TForm, P> {\n const {\n fieldState,\n setValue: rawSetValue,\n setBlur,\n store,\n } = useBitFieldBase<BitPathValue<TForm, P>, TForm, P>(path);\n\n // Track mask registrations reactively. getMasksVersion() returns a counter\n // that increments on every registerMask() call. useSyncExternalStore fires\n // the snapshot on every store notification; the integer comparison is O(1)\n // so this only triggers a re-render when a mask is actually added.\n const masksVersion = useSyncExternalStore(\n // store.subscribe fires on every state change (global listener)\n (cb) => store.subscribe(cb),\n () => store.getMasksVersion(),\n () => store.getMasksVersion(),\n );\n\n const resolvedMask = useMemo(() => {\n return store.resolveMask(path as string);\n }, [masksVersion, store.config.fields, path]);\n\n const displayValue = useMemo(\n () => formatMaskedValue(fieldState.value, resolvedMask ?? undefined),\n [fieldState.value, resolvedMask],\n );\n\n const setValue = useCallback(\n (val: BitPathValue<TForm, P> | string | number | null | undefined) =>\n rawSetValue(\n parseMaskedInput(val, resolvedMask ?? undefined) as BitPathValue<\n TForm,\n P\n >,\n ),\n [resolvedMask, rawSetValue],\n );\n\n const { isHidden, isRequired, value, error, touched, isDirty, isValidating } =\n fieldState;\n\n const invalid = !!(touched && error);\n const visibleError = touched ? error : undefined;\n\n const onChange = useCallback(\n (e: BitFieldInputEvent) => {\n const val = isBitFieldInputEventObject(e) ? e.target?.value : e;\n setValue(val);\n },\n [setValue],\n );\n\n const onBlur = useCallback(() => {\n setBlur();\n }, [setBlur]);\n\n return {\n // Main handlers and values (flat)\n value: value as BitPathValue<TForm, P>,\n displayValue,\n setValue,\n setBlur,\n onChange,\n onBlur,\n // Props helper\n props: {\n value: displayValue,\n onChange,\n onBlur,\n },\n // Metadata (grouped)\n meta: {\n error: visibleError,\n touched,\n invalid,\n isDirty,\n isValidating,\n isHidden,\n isRequired,\n hasError: !!error,\n },\n };\n}\n","import { useCallback, useRef, useSyncExternalStore } from \"react\";\nimport { isHistoryMetaEqual, type HistoryMeta } from \"../core/history-status\";\nimport { useBitStore } from \"./context\";\nimport type { UseBitHistoryResult } from \"./types\";\n\nexport function useBitHistory<T extends object = any>(): UseBitHistoryResult {\n const store = useBitStore<T>();\n const lastMeta = useRef<HistoryMeta | null>(null);\n\n const getSnapshot = useCallback(() => {\n const nextMeta = store.getHistoryMetadata();\n\n if (lastMeta.current && isHistoryMetaEqual(lastMeta.current, nextMeta)) {\n return lastMeta.current;\n }\n\n const stableMeta = {\n canUndo: nextMeta.canUndo,\n canRedo: nextMeta.canRedo,\n historyIndex: nextMeta.historyIndex,\n historySize: nextMeta.historySize,\n };\n\n lastMeta.current = stableMeta;\n return stableMeta;\n }, [store]);\n\n const subscribe = useCallback(\n (cb: () => void) => store.subscribe(cb),\n [store],\n );\n\n const meta = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\n const undo = useCallback(() => {\n store.undo();\n }, [store]);\n\n const redo = useCallback(() => {\n store.redo();\n }, [store]);\n\n return {\n ...meta,\n undo,\n redo,\n };\n}\n","/**\n * React Hook for File Upload Integration\n *\n * Minimal upload API integrated with global field validation lifecycle.\n *\n * @example\n * ```typescript\n * const avatar = useBitUpload(\"avatar\", uploadFn);\n *\n * return (\n * <>\n * <input\n * type=\"file\"\n * onChange={(e) => avatar.upload(e.target.files?.[0])}\n * disabled={avatar.isValidating}\n * />\n * {avatar.error && <Error>{avatar.error}</Error>}\n * </>\n * );\n * ```\n */\n\nimport { useCallback, useRef, useState } from \"react\";\nimport { useBitField } from \"./use-bit-field\";\nimport { useBitStore } from \"./context\";\nimport { BitUploadFn, BitDeleteUploadFn } from \"../core\";\nimport { createUploadHandler, createRemoveHandler } from \"../core/adapters\";\nimport type { UseBitUploadResult } from \"./types\";\n\nexport function useBitUpload(\n fieldPath: string,\n uploadFn: BitUploadFn,\n deleteFile?: BitDeleteUploadFn,\n): UseBitUploadResult {\n const store = useBitStore<any>();\n const field = useBitField(fieldPath);\n const uploadKeyRef = useRef<string | null>(null);\n const [isUploading, setIsUploading] = useState(false);\n\n const kernelCallbacks = {\n setLoading: setIsUploading,\n setError: (path: string, msg: string | undefined) =>\n store.setError(path, msg),\n setValue: (val: string | null) => field.setValue(val as any),\n getUploadKey: () => uploadKeyRef.current,\n setUploadKey: (key: string | null) => {\n uploadKeyRef.current = key;\n },\n };\n\n const upload = useCallback(\n createUploadHandler(fieldPath, uploadFn, kernelCallbacks),\n [uploadFn, field, fieldPath, store],\n );\n\n const remove = useCallback(\n createRemoveHandler(fieldPath, deleteFile, kernelCallbacks),\n [deleteFile, field, fieldPath, store],\n );\n\n return {\n value: field.value,\n setValue: field.setValue,\n error: field.meta?.error,\n isValidating: !!field.meta?.isValidating || isUploading,\n upload,\n remove,\n };\n}\n"],"mappings":"oQA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EAAoBnB,EAAWC,EAAUW,CAAe,EACxD,CAACX,EAAUI,EAAOL,EAAWG,CAAK,CACpC,EAEMiB,EAASF,EACbG,EAAoBrB,EAAWE,EAAYU,CAAe,EAC1D,CAACV,EAAYG,EAAOL,EAAWG,CAAK,CACtC,EAEA,MAAO,CACL,MAAOE,EAAM,MACb,SAAUA,EAAM,SAChB,MAAOA,EAAM,MAAM,MACnB,aAAc,CAAC,CAACA,EAAM,MAAM,cAAgBI,EAC5C,OAAAQ,EACA,OAAAG,CACF,CACF","names":["useMemo","useCallback","useSyncExternalStore","useBitField","path","fieldState","rawSetValue","setBlur","store","useBitFieldBase","masksVersion","useSyncExternalStore","cb","resolvedMask","useMemo","displayValue","formatMaskedValue","setValue","useCallback","val","parseMaskedInput","isHidden","isRequired","value","error","touched","isDirty","isValidating","invalid","visibleError","onChange","e","isBitFieldInputEventObject","onBlur","useCallback","useRef","useSyncExternalStore","useBitHistory","store","useBitStore","lastMeta","useRef","getSnapshot","useCallback","nextMeta","isHistoryMetaEqual","stableMeta","subscribe","cb","meta","useSyncExternalStore","undo","redo","useCallback","useRef","useState","useBitUpload","fieldPath","uploadFn","deleteFile","store","useBitStore","field","useBitField","uploadKeyRef","useRef","isUploading","setIsUploading","useState","kernelCallbacks","path","msg","val","key","upload","useCallback","createUploadHandler","remove","createRemoveHandler"]}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunk3CARTBENcjs = require('../chunk-3CARTBEN.cjs');require('../chunk-JIWR4KSZ.cjs');require('../chunk-OZKLQRO6.cjs');var _chunkPFPGASVZcjs = require('../chunk-PFPGASVZ.cjs');var _react = require('react');function E(r){let{fieldState:o,setValue:t,setBlur:s,store:i}=_chunk3CARTBENcjs.d.call(void 0, r),e=_react.useMemo.call(void 0, ()=>i.resolveMask(r),[i.config.masks,i.config.fields,r]),m=_react.useMemo.call(void 0, ()=>_chunkPFPGASVZcjs.b.call(void 0, o.value,_nullishCoalesce(e, () => (void 0))),[o.value,e]),p=_react.useCallback.call(void 0, u=>t(_chunkPFPGASVZcjs.c.call(void 0, u,_nullishCoalesce(e, () => (void 0)))),[e,t]),x=_react.useCallback.call(void 0, u=>t(_chunkPFPGASVZcjs.c.call(void 0, u,_nullishCoalesce(e, () => (void 0)))),[e,t]),{isHidden:P,isRequired:v,value:y,error:a,touched:n,isDirty:h,isValidating:V}=o,T=!!(n&&a),g=n?a:void 0,B=_react.useCallback.call(void 0, ()=>{s()},[s]);return{value:y,displayValue:m,setValue:x,setBlur:s,onChangeText:p,onBlur:B,meta:{error:g,touched:n,invalid:T,isValidating:V,isDirty:h,isHidden:P,isRequired:v,hasError:!!a},props:{value:m,onChangeText:p,onBlur:B}}}exports.BitFormProvider = _chunk3CARTBENcjs.a; exports.useBitArray = _chunk3CARTBENcjs.e; exports.useBitField = E; exports.useBitForm = _chunk3CARTBENcjs.c; exports.useBitPersist = _chunk3CARTBENcjs.i; exports.useBitScope = _chunk3CARTBENcjs.f; exports.useBitSteps = _chunk3CARTBENcjs.g; exports.useBitStore = _chunk3CARTBENcjs.b; exports.useBitWatch = _chunk3CARTBENcjs.h;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunk3EDD3V43cjs = require('../chunk-3EDD3V43.cjs');require('../chunk-Y2ONHDRE.cjs');require('../chunk-YCSWULEN.cjs');var _chunkPFPGASVZcjs = require('../chunk-PFPGASVZ.cjs');var _react = require('react');function E(r){let{fieldState:o,setValue:t,setBlur:s,store:i}=_chunk3EDD3V43cjs.d.call(void 0, r),e=_react.useMemo.call(void 0, ()=>i.resolveMask(r),[i.config.masks,i.config.fields,r]),m=_react.useMemo.call(void 0, ()=>_chunkPFPGASVZcjs.b.call(void 0, o.value,_nullishCoalesce(e, () => (void 0))),[o.value,e]),p=_react.useCallback.call(void 0, u=>t(_chunkPFPGASVZcjs.c.call(void 0, u,_nullishCoalesce(e, () => (void 0)))),[e,t]),x=_react.useCallback.call(void 0, u=>t(_chunkPFPGASVZcjs.c.call(void 0, u,_nullishCoalesce(e, () => (void 0)))),[e,t]),{isHidden:P,isRequired:v,value:y,error:a,touched:n,isDirty:h,isValidating:V}=o,T=!!(n&&a),g=n?a:void 0,B=_react.useCallback.call(void 0, ()=>{s()},[s]);return{value:y,displayValue:m,setValue:x,setBlur:s,onChangeText:p,onBlur:B,meta:{error:g,touched:n,invalid:T,isValidating:V,isDirty:h,isHidden:P,isRequired:v,hasError:!!a},props:{value:m,onChangeText:p,onBlur:B}}}exports.BitFormProvider = _chunk3EDD3V43cjs.a; exports.useBitArray = _chunk3EDD3V43cjs.e; exports.useBitField = E; exports.useBitForm = _chunk3EDD3V43cjs.c; exports.useBitPersist = _chunk3EDD3V43cjs.i; exports.useBitScope = _chunk3EDD3V43cjs.f; exports.useBitSteps = _chunk3EDD3V43cjs.g; exports.useBitStore = _chunk3EDD3V43cjs.b; exports.useBitWatch = _chunk3EDD3V43cjs.h;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1,9 +1,9 @@
1
- export { B as BitFormProvider, U as UseBitPersistResult, u as useBitArray, a as useBitForm, b as useBitPersist, c as useBitScope, d as useBitSteps, e as useBitStore, f as useBitWatch } from '../use-bit-persist-CIVN-oIi.cjs';
1
+ export { B as BitFormProvider, U as UseBitPersistResult, u as useBitArray, a as useBitForm, b as useBitPersist, c as useBitScope, d as useBitSteps, e as useBitStore, f as useBitWatch } from '../use-bit-persist-D_gimC9A.cjs';
2
2
  import { f as BitPath, g as BitPathValue } from '../bus-BeAeZwWu.cjs';
3
3
  export { S as ScopeStatus, n as ValidateScopeResult } from '../bus-BeAeZwWu.cjs';
4
4
  import 'react/jsx-runtime';
5
5
  import 'react';
6
- import '../public-types-BQXaxmAE.cjs';
6
+ import '../public-types-Cd9ai20P.cjs';
7
7
  import '../types-D8DgIUhJ.cjs';
8
8
  import '../field-binding-BXw0Ku2c.cjs';
9
9
 
@@ -1,9 +1,9 @@
1
- export { B as BitFormProvider, U as UseBitPersistResult, u as useBitArray, a as useBitForm, b as useBitPersist, c as useBitScope, d as useBitSteps, e as useBitStore, f as useBitWatch } from '../use-bit-persist-iPWLbD8l.js';
1
+ export { B as BitFormProvider, U as UseBitPersistResult, u as useBitArray, a as useBitForm, b as useBitPersist, c as useBitScope, d as useBitSteps, e as useBitStore, f as useBitWatch } from '../use-bit-persist-Dk3fUrds.js';
2
2
  import { f as BitPath, g as BitPathValue } from '../bus-B4zZmB9C.js';
3
3
  export { S as ScopeStatus, n as ValidateScopeResult } from '../bus-B4zZmB9C.js';
4
4
  import 'react/jsx-runtime';
5
5
  import 'react';
6
- import '../public-types-CVgFf_qY.js';
6
+ import '../public-types-DdZxD6Op.js';
7
7
  import '../types-D8DgIUhJ.js';
8
8
  import '../field-binding-BXw0Ku2c.js';
9
9
 
@@ -1,2 +1,2 @@
1
- import{a as S,b as k,c as M,d as c,e as R,f as U,g as N,h as C,i as b}from"../chunk-UMKOKAPD.js";import"../chunk-2FDEJYA5.js";import"../chunk-64KSP4TP.js";import{b as f,c as l}from"../chunk-3NUJVIAM.js";import{useMemo as F,useCallback as d}from"react";function E(r){let{fieldState:o,setValue:t,setBlur:s,store:i}=c(r),e=F(()=>i.resolveMask(r),[i.config.masks,i.config.fields,r]),m=F(()=>f(o.value,e??void 0),[o.value,e]),p=d(u=>t(l(u,e??void 0)),[e,t]),x=d(u=>t(l(u,e??void 0)),[e,t]),{isHidden:P,isRequired:v,value:y,error:a,touched:n,isDirty:h,isValidating:V}=o,T=!!(n&&a),g=n?a:void 0,B=d(()=>{s()},[s]);return{value:y,displayValue:m,setValue:x,setBlur:s,onChangeText:p,onBlur:B,meta:{error:g,touched:n,invalid:T,isValidating:V,isDirty:h,isHidden:P,isRequired:v,hasError:!!a},props:{value:m,onChangeText:p,onBlur:B}}}export{S as BitFormProvider,R as useBitArray,E as useBitField,M as useBitForm,b as useBitPersist,U as useBitScope,N as useBitSteps,k as useBitStore,C as useBitWatch};
1
+ import{a as S,b as k,c as M,d as c,e as R,f as U,g as N,h as C,i as b}from"../chunk-T3FR7D5V.js";import"../chunk-2CVKNPWX.js";import"../chunk-PX6WKENM.js";import{b as f,c as l}from"../chunk-3NUJVIAM.js";import{useMemo as F,useCallback as d}from"react";function E(r){let{fieldState:o,setValue:t,setBlur:s,store:i}=c(r),e=F(()=>i.resolveMask(r),[i.config.masks,i.config.fields,r]),m=F(()=>f(o.value,e??void 0),[o.value,e]),p=d(u=>t(l(u,e??void 0)),[e,t]),x=d(u=>t(l(u,e??void 0)),[e,t]),{isHidden:P,isRequired:v,value:y,error:a,touched:n,isDirty:h,isValidating:V}=o,T=!!(n&&a),g=n?a:void 0,B=d(()=>{s()},[s]);return{value:y,displayValue:m,setValue:x,setBlur:s,onChangeText:p,onBlur:B,meta:{error:g,touched:n,invalid:T,isValidating:V,isDirty:h,isHidden:P,isRequired:v,hasError:!!a},props:{value:m,onChangeText:p,onBlur:B}}}export{S as BitFormProvider,R as useBitArray,E as useBitField,M as useBitForm,b as useBitPersist,U as useBitScope,N as useBitSteps,k as useBitStore,C as useBitWatch};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
- import { e as BitStoreApi, f as BitStoreHooksApi, c as BitHistoryMetadata, d as BitValidationOptions } from './public-types-BQXaxmAE.cjs';
3
+ import { e as BitStoreApi, f as BitStoreHooksApi, c as BitHistoryMetadata, d as BitValidationOptions } from './public-types-Cd9ai20P.cjs';
4
4
  import { f as BitPath, g as BitPathValue, j as BitPersistMetadata, S as ScopeStatus, n as ValidateScopeResult, i as BitErrors, H as BitTouched, h as DeepPartial, k as BitArrayPath, l as BitArrayItem } from './bus-BeAeZwWu.cjs';
5
5
  import { B as BitFieldInputEvent } from './field-binding-BXw0Ku2c.cjs';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
- import { e as BitStoreApi, f as BitStoreHooksApi, c as BitHistoryMetadata, d as BitValidationOptions } from './public-types-CVgFf_qY.js';
3
+ import { e as BitStoreApi, f as BitStoreHooksApi, c as BitHistoryMetadata, d as BitValidationOptions } from './public-types-DdZxD6Op.js';
4
4
  import { f as BitPath, g as BitPathValue, j as BitPersistMetadata, S as ScopeStatus, n as ValidateScopeResult, i as BitErrors, H as BitTouched, h as DeepPartial, k as BitArrayPath, l as BitArrayItem } from './bus-B4zZmB9C.js';
5
5
  import { B as BitFieldInputEvent } from './field-binding-BXw0Ku2c.js';
6
6
 
@@ -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 _chunkVQ7MK5VBcjs = require('../chunk-VQ7MK5VB.cjs');var _chunkJIWR4KSZcjs = require('../chunk-JIWR4KSZ.cjs');var _chunkOZKLQRO6cjs = require('../chunk-OZKLQRO6.cjs');require('../chunk-PFPGASVZ.cjs');var _vue = require('vue');var W=Symbol("BIT_STORE");function X(t){_vue.provide.call(void 0, W,_chunkOZKLQRO6cjs.k.call(void 0, t))}function c(){let t=_vue.inject.call(void 0, W);if(!t)throw new Error("BitForm Vue hooks devem ser usados sob um provideBitStore");return t}function ee(){let t=c(),e=_vue.shallowRef.call(void 0, {isValid:t.getState().isValid,isSubmitting:t.getState().isSubmitting,isDirty:t.getState().isDirty}),i=_vue.ref.call(void 0, null),s=_vue.ref.call(void 0, null),o=t.subscribeSelector(p=>({isValid:p.isValid,isSubmitting:p.isSubmitting,isDirty:p.isDirty}),p=>{e.value=p},{paths:["isValid","isSubmitting","isDirty"]});_vue.onUnmounted.call(void 0, o);let u=_chunkJIWR4KSZcjs.b.call(void 0, t,{clearSubmissionState:()=>{i.value=null,s.value=null},setSubmissionResult:p=>{s.value=p},setSubmissionError:p=>{i.value=p}}),n=_chunkJIWR4KSZcjs.a.call(void 0, t),d=_vue.computed.call(void 0, ()=>e.value.isValid),S=_vue.computed.call(void 0, ()=>e.value.isSubmitting),f=_vue.computed.call(void 0, ()=>e.value.isDirty),r=u.onSubmit,a=u.reset;return{meta:{isValid:d,isDirty:f,isSubmitting:S,submitError:i,lastResponse:s},getValues:u.getValues,getErrors:u.getErrors,getTouched:u.getTouched,getDirtyValues:u.getDirtyValues,submit:u.submit,onSubmit:r,reset:a,...n}}function E(t){let e=c(),i=e.resolveMask(t),s=_chunkJIWR4KSZcjs.d.call(void 0, e,t,i),o=_vue.shallowRef.call(void 0, e.getFieldState(t)),u=_chunkJIWR4KSZcjs.c.call(void 0, e,t,B=>{o.value=B});_vue.onUnmounted.call(void 0, ()=>{u(),e.unregisterField&&e.unregisterField(t)});let n=_vue.computed.call(void 0, ()=>o.value.value),d=_vue.computed.call(void 0, ()=>s.displayValue(n.value)),S=_vue.computed.call(void 0, {get:()=>d.value,set:B=>{s.setValue(B)}}),f=_vue.computed.call(void 0, ()=>o.value.error),r=_vue.computed.call(void 0, ()=>o.value.touched?o.value.error:void 0),a=_vue.computed.call(void 0, ()=>o.value.touched),l=_vue.computed.call(void 0, ()=>!!(a.value&&r.value)),p=_vue.computed.call(void 0, ()=>o.value.isValidating),b=_vue.computed.call(void 0, ()=>o.value.isDirty),P=_vue.computed.call(void 0, ()=>o.value.isHidden),h=_vue.computed.call(void 0, ()=>o.value.isRequired),R=_vue.computed.call(void 0, ()=>!!f.value),m=B=>{s.setValue(B)},g=()=>s.setBlur();return{value:n,displayValue:d,modelValue:S,setValue:m,setBlur:g,onInput:B=>{m(B)},onBlur:()=>{g()},meta:{error:r,touched:a,invalid:l,isValidating:p,isDirty:b,isHidden:P,isRequired:h,hasError:R}}}function se(t){let e=c(),i=r=>e.config.idFactory({scope:"array",path:t,index:r}),o=(()=>{let r=_chunkOZKLQRO6cjs.e.call(void 0, e.getState().values,t);return Array.isArray(r)?r:[]})(),u=_vue.ref.call(void 0, o),n=_vue.ref.call(void 0, o.map((r,a)=>i(a))),d=e.subscribePath(t,r=>{let a=Array.isArray(r)?r:[];if(u.value=[...a],a.length!==n.value.length){let l=[...n.value];if(a.length>l.length){let p=a.length-l.length,b=Array.from({length:p},(P,h)=>i(l.length+h));n.value=[...l,...b]}else n.value=l.slice(0,a.length)}});_vue.onUnmounted.call(void 0, ()=>{d(),e.unregisterPrefix&&e.unregisterPrefix(`${t}.`)});let S=_vue.computed.call(void 0, ()=>u.value.map((r,a)=>({key:n.value[a]||`temp-${a}`,value:r,index:a}))),f=_vue.computed.call(void 0, ()=>u.value.length);return{fields:S,length:f,append:r=>{n.value.push(i(n.value.length)),e.pushItem(t,r)},prepend:r=>{n.value.unshift(i(0)),e.prependItem(t,r)},insert:(r,a)=>{n.value.splice(r,0,i(r)),e.insertItem(t,r,a)},remove:r=>{n.value.splice(r,1),e.removeItem(t,r)},move:(r,a)=>{let l=[...n.value],[p]=l.splice(r,1);l.splice(a,0,p),n.value=l,e.moveItem(t,r,a)},swap:(r,a)=>{let l=[...n.value];[l[r],l[a]]=[l[a],l[r]],n.value=l,e.swapItems(t,r,a)},replace:r=>{n.value=r.map((a,l)=>i(l)),e.setField(t,r)},clear:()=>{n.value=[],e.setField(t,[])}}}function ae(){let t=c(),e=_vue.shallowRef.call(void 0, t.getHistoryMetadata()),i=t.subscribe(()=>{let u=t.getHistoryMetadata();_chunkVQ7MK5VBcjs.a.call(void 0, e.value,u)||(e.value=u)});_vue.onUnmounted.call(void 0, i);let s=()=>t.undo(),o=()=>t.redo();return{canUndo:_vue.computed.call(void 0, ()=>e.value.canUndo),canRedo:_vue.computed.call(void 0, ()=>e.value.canRedo),historyIndex:_vue.computed.call(void 0, ()=>e.value.historyIndex),historySize:_vue.computed.call(void 0, ()=>e.value.historySize),undo:s,redo:o}}function me(t){let e=c(),i=e.getScopeFields(t),s=_vue.ref.call(void 0, e.getStepStatus(t)),o;_vue.onMounted.call(void 0, ()=>{o=e.subscribeSelector(r=>({errors:r.errors,isDirty:r.isDirty}),()=>{let r=e.getStepStatus(t);_chunkJIWR4KSZcjs.e.call(void 0, s.value,r)||(s.value=r)},{paths:_chunkJIWR4KSZcjs.f.call(void 0, i)})}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([o, 'optionalCall', _2 => _2()])});let u=async()=>{let r=await e.validate({scope:t}),a=e.getStepErrors(t);return{valid:r,errors:a}},n=()=>e.getStepErrors(t),d=_vue.computed.call(void 0, ()=>!s.value.hasErrors),S=_vue.computed.call(void 0, ()=>s.value.isDirty),f=_vue.computed.call(void 0, ()=>s.value.errors);return{scopeName:t,status:s,errors:f,validate:u,getErrors:n,isValid:d,isDirty:S}}function Se(t){let e=c(),i=_vue.ref.call(void 0, 0),s=_vue.computed.call(void 0, ()=>_nullishCoalesce(t[i.value], () => (""))),o=_vue.ref.call(void 0, e.getStepStatus(s.value)),u;_vue.watch.call(void 0, s,m=>{o.value=e.getStepStatus(m)});let n=()=>{let m=s.value,g=e.getStepStatus(m);_chunkJIWR4KSZcjs.e.call(void 0, o.value,g)||(o.value=g)};_vue.onMounted.call(void 0, ()=>{u=e.subscribeSelector(m=>({errors:m.errors,isDirty:m.isDirty}),n,{paths:_chunkJIWR4KSZcjs.f.call(void 0, e.getScopeFields(s.value))})}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([u, 'optionalCall', _3 => _3()])});let d=async()=>{let m=s.value,g=await e.validate({scope:m}),F=e.getStepErrors(m);return{valid:g,errors:F}},S=()=>e.getStepErrors(s.value),f=async()=>{let m=s.value,g=e.getScopeFields(m);if(e.hasValidationsInProgress(g))return!1;let F=await e.validate({scope:m});if(F)i.value=Math.min(i.value+1,t.length-1);else{let k=e.getStepErrors(m),B=Object.keys(k);B.length>0&&e.markFieldsTouched(B)}return F},r=()=>{i.value=Math.max(i.value-1,0)},a=m=>{i.value=Math.max(0,Math.min(m-1,t.length-1))},l=_vue.computed.call(void 0, ()=>i.value+1),p=_vue.computed.call(void 0, ()=>i.value===0),b=_vue.computed.call(void 0, ()=>i.value>=t.length-1),P=_vue.computed.call(void 0, ()=>!o.value.hasErrors),h=_vue.computed.call(void 0, ()=>o.value.isDirty),R=_vue.computed.call(void 0, ()=>o.value.errors);return{step:l,stepIndex:i,scope:s,next:f,prev:r,goTo:a,isFirst:p,isLast:b,status:o,errors:R,isValid:P,isDirty:h,validate:d,getErrors:S}}function ye(t){let e=c(),i=_chunkOZKLQRO6cjs.e.call(void 0, e.getState().values,t),s=_vue.ref.call(void 0, i),o=e.watch(t,u=>{_chunkOZKLQRO6cjs.d.call(void 0, s.value,u)||(s.value=u)});return _vue.onUnmounted.call(void 0, o),_vue.readonly.call(void 0, s)}function he(t,e,i){let s=c(),o=E(t),u=null,n=_vue.ref.call(void 0, !1),d={setLoading:r=>{n.value=r},setError:(r,a)=>s.setError(r,a),setValue:r=>o.setValue(r),getUploadKey:()=>u,setUploadKey:r=>{u=r}},S=_chunkVQ7MK5VBcjs.b.call(void 0, t,e,d),f=_chunkVQ7MK5VBcjs.c.call(void 0, t,i,d);return{value:o.value,setValue:o.setValue,error:_vue.computed.call(void 0, ()=>o.meta.error.value),isValidating:_vue.computed.call(void 0, ()=>!!o.meta.isValidating.value||n.value),upload:S,remove:f}}function Ve(){let t=c(),e=_vue.ref.call(void 0, t.getPersistMetadata()),i=t.subscribeSelector(n=>n.persist,n=>{e.value=n},{paths:["persist"]});return _vue.onUnmounted.call(void 0, ()=>i()),{restore:async()=>t.restorePersisted(),save:async()=>{await t.forceSave()},clear:async()=>{await t.clearPersisted()},meta:{isSaving:_vue.computed.call(void 0, ()=>e.value.isSaving),isRestoring:_vue.computed.call(void 0, ()=>e.value.isRestoring),error:_vue.computed.call(void 0, ()=>e.value.error)}}}exports.provideBitStore = X; exports.useBitArray = se; exports.useBitField = E; exports.useBitForm = ee; exports.useBitHistory = ae; exports.useBitPersist = Ve; exports.useBitScope = me; exports.useBitSteps = Se; exports.useBitStore = c; exports.useBitUpload = he; exports.useBitWatch = ye;
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 _chunkVQ7MK5VBcjs = require('../chunk-VQ7MK5VB.cjs');var _chunkY2ONHDREcjs = require('../chunk-Y2ONHDRE.cjs');var _chunkYCSWULENcjs = require('../chunk-YCSWULEN.cjs');require('../chunk-PFPGASVZ.cjs');var _vue = require('vue');var W=Symbol("BIT_STORE");function X(t){_vue.provide.call(void 0, W,_chunkYCSWULENcjs.k.call(void 0, t))}function c(){let t=_vue.inject.call(void 0, W);if(!t)throw new Error("BitForm Vue hooks devem ser usados sob um provideBitStore");return t}function ee(){let t=c(),e=_vue.shallowRef.call(void 0, {isValid:t.getState().isValid,isSubmitting:t.getState().isSubmitting,isDirty:t.getState().isDirty}),i=_vue.ref.call(void 0, null),s=_vue.ref.call(void 0, null),o=t.subscribeSelector(p=>({isValid:p.isValid,isSubmitting:p.isSubmitting,isDirty:p.isDirty}),p=>{e.value=p},{paths:["isValid","isSubmitting","isDirty"]});_vue.onUnmounted.call(void 0, o);let u=_chunkY2ONHDREcjs.b.call(void 0, t,{clearSubmissionState:()=>{i.value=null,s.value=null},setSubmissionResult:p=>{s.value=p},setSubmissionError:p=>{i.value=p}}),n=_chunkY2ONHDREcjs.a.call(void 0, t),d=_vue.computed.call(void 0, ()=>e.value.isValid),S=_vue.computed.call(void 0, ()=>e.value.isSubmitting),f=_vue.computed.call(void 0, ()=>e.value.isDirty),r=u.onSubmit,a=u.reset;return{meta:{isValid:d,isDirty:f,isSubmitting:S,submitError:i,lastResponse:s},getValues:u.getValues,getErrors:u.getErrors,getTouched:u.getTouched,getDirtyValues:u.getDirtyValues,submit:u.submit,onSubmit:r,reset:a,...n}}function E(t){let e=c(),i=e.resolveMask(t),s=_chunkY2ONHDREcjs.d.call(void 0, e,t,i),o=_vue.shallowRef.call(void 0, e.getFieldState(t)),u=_chunkY2ONHDREcjs.c.call(void 0, e,t,B=>{o.value=B});_vue.onUnmounted.call(void 0, ()=>{u(),e.unregisterField&&e.unregisterField(t)});let n=_vue.computed.call(void 0, ()=>o.value.value),d=_vue.computed.call(void 0, ()=>s.displayValue(n.value)),S=_vue.computed.call(void 0, {get:()=>d.value,set:B=>{s.setValue(B)}}),f=_vue.computed.call(void 0, ()=>o.value.error),r=_vue.computed.call(void 0, ()=>o.value.touched?o.value.error:void 0),a=_vue.computed.call(void 0, ()=>o.value.touched),l=_vue.computed.call(void 0, ()=>!!(a.value&&r.value)),p=_vue.computed.call(void 0, ()=>o.value.isValidating),b=_vue.computed.call(void 0, ()=>o.value.isDirty),P=_vue.computed.call(void 0, ()=>o.value.isHidden),h=_vue.computed.call(void 0, ()=>o.value.isRequired),R=_vue.computed.call(void 0, ()=>!!f.value),m=B=>{s.setValue(B)},g=()=>s.setBlur();return{value:n,displayValue:d,modelValue:S,setValue:m,setBlur:g,onInput:B=>{m(B)},onBlur:()=>{g()},meta:{error:r,touched:a,invalid:l,isValidating:p,isDirty:b,isHidden:P,isRequired:h,hasError:R}}}function se(t){let e=c(),i=r=>e.config.idFactory({scope:"array",path:t,index:r}),o=(()=>{let r=_chunkYCSWULENcjs.e.call(void 0, e.getState().values,t);return Array.isArray(r)?r:[]})(),u=_vue.ref.call(void 0, o),n=_vue.ref.call(void 0, o.map((r,a)=>i(a))),d=e.subscribePath(t,r=>{let a=Array.isArray(r)?r:[];if(u.value=[...a],a.length!==n.value.length){let l=[...n.value];if(a.length>l.length){let p=a.length-l.length,b=Array.from({length:p},(P,h)=>i(l.length+h));n.value=[...l,...b]}else n.value=l.slice(0,a.length)}});_vue.onUnmounted.call(void 0, ()=>{d(),e.unregisterPrefix&&e.unregisterPrefix(`${t}.`)});let S=_vue.computed.call(void 0, ()=>u.value.map((r,a)=>({key:n.value[a]||`temp-${a}`,value:r,index:a}))),f=_vue.computed.call(void 0, ()=>u.value.length);return{fields:S,length:f,append:r=>{n.value.push(i(n.value.length)),e.pushItem(t,r)},prepend:r=>{n.value.unshift(i(0)),e.prependItem(t,r)},insert:(r,a)=>{n.value.splice(r,0,i(r)),e.insertItem(t,r,a)},remove:r=>{n.value.splice(r,1),e.removeItem(t,r)},move:(r,a)=>{let l=[...n.value],[p]=l.splice(r,1);l.splice(a,0,p),n.value=l,e.moveItem(t,r,a)},swap:(r,a)=>{let l=[...n.value];[l[r],l[a]]=[l[a],l[r]],n.value=l,e.swapItems(t,r,a)},replace:r=>{n.value=r.map((a,l)=>i(l)),e.setField(t,r)},clear:()=>{n.value=[],e.setField(t,[])}}}function ae(){let t=c(),e=_vue.shallowRef.call(void 0, t.getHistoryMetadata()),i=t.subscribe(()=>{let u=t.getHistoryMetadata();_chunkVQ7MK5VBcjs.a.call(void 0, e.value,u)||(e.value=u)});_vue.onUnmounted.call(void 0, i);let s=()=>t.undo(),o=()=>t.redo();return{canUndo:_vue.computed.call(void 0, ()=>e.value.canUndo),canRedo:_vue.computed.call(void 0, ()=>e.value.canRedo),historyIndex:_vue.computed.call(void 0, ()=>e.value.historyIndex),historySize:_vue.computed.call(void 0, ()=>e.value.historySize),undo:s,redo:o}}function me(t){let e=c(),i=e.getScopeFields(t),s=_vue.ref.call(void 0, e.getStepStatus(t)),o;_vue.onMounted.call(void 0, ()=>{o=e.subscribeSelector(r=>({errors:r.errors,isDirty:r.isDirty}),()=>{let r=e.getStepStatus(t);_chunkY2ONHDREcjs.e.call(void 0, s.value,r)||(s.value=r)},{paths:_chunkY2ONHDREcjs.f.call(void 0, i)})}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([o, 'optionalCall', _2 => _2()])});let u=async()=>{let r=await e.validate({scope:t}),a=e.getStepErrors(t);return{valid:r,errors:a}},n=()=>e.getStepErrors(t),d=_vue.computed.call(void 0, ()=>!s.value.hasErrors),S=_vue.computed.call(void 0, ()=>s.value.isDirty),f=_vue.computed.call(void 0, ()=>s.value.errors);return{scopeName:t,status:s,errors:f,validate:u,getErrors:n,isValid:d,isDirty:S}}function Se(t){let e=c(),i=_vue.ref.call(void 0, 0),s=_vue.computed.call(void 0, ()=>_nullishCoalesce(t[i.value], () => (""))),o=_vue.ref.call(void 0, e.getStepStatus(s.value)),u;_vue.watch.call(void 0, s,m=>{o.value=e.getStepStatus(m)});let n=()=>{let m=s.value,g=e.getStepStatus(m);_chunkY2ONHDREcjs.e.call(void 0, o.value,g)||(o.value=g)};_vue.onMounted.call(void 0, ()=>{u=e.subscribeSelector(m=>({errors:m.errors,isDirty:m.isDirty}),n,{paths:_chunkY2ONHDREcjs.f.call(void 0, e.getScopeFields(s.value))})}),_vue.onUnmounted.call(void 0, ()=>{_optionalChain([u, 'optionalCall', _3 => _3()])});let d=async()=>{let m=s.value,g=await e.validate({scope:m}),F=e.getStepErrors(m);return{valid:g,errors:F}},S=()=>e.getStepErrors(s.value),f=async()=>{let m=s.value,g=e.getScopeFields(m);if(e.hasValidationsInProgress(g))return!1;let F=await e.validate({scope:m});if(F)i.value=Math.min(i.value+1,t.length-1);else{let k=e.getStepErrors(m),B=Object.keys(k);B.length>0&&e.markFieldsTouched(B)}return F},r=()=>{i.value=Math.max(i.value-1,0)},a=m=>{i.value=Math.max(0,Math.min(m-1,t.length-1))},l=_vue.computed.call(void 0, ()=>i.value+1),p=_vue.computed.call(void 0, ()=>i.value===0),b=_vue.computed.call(void 0, ()=>i.value>=t.length-1),P=_vue.computed.call(void 0, ()=>!o.value.hasErrors),h=_vue.computed.call(void 0, ()=>o.value.isDirty),R=_vue.computed.call(void 0, ()=>o.value.errors);return{step:l,stepIndex:i,scope:s,next:f,prev:r,goTo:a,isFirst:p,isLast:b,status:o,errors:R,isValid:P,isDirty:h,validate:d,getErrors:S}}function ye(t){let e=c(),i=_chunkYCSWULENcjs.e.call(void 0, e.getState().values,t),s=_vue.ref.call(void 0, i),o=e.watch(t,u=>{_chunkYCSWULENcjs.d.call(void 0, s.value,u)||(s.value=u)});return _vue.onUnmounted.call(void 0, o),_vue.readonly.call(void 0, s)}function he(t,e,i){let s=c(),o=E(t),u=null,n=_vue.ref.call(void 0, !1),d={setLoading:r=>{n.value=r},setError:(r,a)=>s.setError(r,a),setValue:r=>o.setValue(r),getUploadKey:()=>u,setUploadKey:r=>{u=r}},S=_chunkVQ7MK5VBcjs.b.call(void 0, t,e,d),f=_chunkVQ7MK5VBcjs.c.call(void 0, t,i,d);return{value:o.value,setValue:o.setValue,error:_vue.computed.call(void 0, ()=>o.meta.error.value),isValidating:_vue.computed.call(void 0, ()=>!!o.meta.isValidating.value||n.value),upload:S,remove:f}}function Ve(){let t=c(),e=_vue.ref.call(void 0, t.getPersistMetadata()),i=t.subscribeSelector(n=>n.persist,n=>{e.value=n},{paths:["persist"]});return _vue.onUnmounted.call(void 0, ()=>i()),{restore:async()=>t.restorePersisted(),save:async()=>{await t.forceSave()},clear:async()=>{await t.clearPersisted()},meta:{isSaving:_vue.computed.call(void 0, ()=>e.value.isSaving),isRestoring:_vue.computed.call(void 0, ()=>e.value.isRestoring),error:_vue.computed.call(void 0, ()=>e.value.error)}}}exports.provideBitStore = X; exports.useBitArray = se; exports.useBitField = E; exports.useBitForm = ee; exports.useBitHistory = ae; exports.useBitPersist = Ve; exports.useBitScope = me; exports.useBitSteps = Se; exports.useBitStore = c; exports.useBitUpload = he; exports.useBitWatch = ye;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1,4 +1,4 @@
1
- import { e as BitStoreApi, f as BitStoreHooksApi, c as BitHistoryMetadata, d as BitValidationOptions } from '../public-types-BQXaxmAE.cjs';
1
+ import { e as BitStoreApi, f as BitStoreHooksApi, c as BitHistoryMetadata, d as BitValidationOptions } from '../public-types-Cd9ai20P.cjs';
2
2
  import { j as BitPersistMetadata, S as ScopeStatus, n as ValidateScopeResult, i as BitErrors, H as BitTouched, h as DeepPartial, f as BitPath, g as BitPathValue, k as BitArrayPath, l as BitArrayItem } from '../bus-BeAeZwWu.cjs';
3
3
  import * as vue from 'vue';
4
4
  import { ComputedRef, Ref } from 'vue';
@@ -1,4 +1,4 @@
1
- import { e as BitStoreApi, f as BitStoreHooksApi, c as BitHistoryMetadata, d as BitValidationOptions } from '../public-types-CVgFf_qY.js';
1
+ import { e as BitStoreApi, f as BitStoreHooksApi, c as BitHistoryMetadata, d as BitValidationOptions } from '../public-types-DdZxD6Op.js';
2
2
  import { j as BitPersistMetadata, S as ScopeStatus, n as ValidateScopeResult, i as BitErrors, H as BitTouched, h as DeepPartial, f as BitPath, g as BitPathValue, k as BitArrayPath, l as BitArrayItem } from '../bus-B4zZmB9C.js';
3
3
  import * as vue from 'vue';
4
4
  import { ComputedRef, Ref } from 'vue';
package/dist/vue/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as K,b as _,c as O}from"../chunk-QWH2NBVB.js";import{a as M,b as j,c as q,d as C,e as T,f as x}from"../chunk-2FDEJYA5.js";import{d as A,e as V,k as H}from"../chunk-64KSP4TP.js";import"../chunk-3NUJVIAM.js";import{inject as J,provide as Q}from"vue";var W=Symbol("BIT_STORE");function X(t){Q(W,H(t))}function c(){let t=J(W);if(!t)throw new Error("BitForm Vue hooks devem ser usados sob um provideBitStore");return t}import{computed as I,onUnmounted as Z,shallowRef as N,ref as z}from"vue";function ee(){let t=c(),e=N({isValid:t.getState().isValid,isSubmitting:t.getState().isSubmitting,isDirty:t.getState().isDirty}),i=z(null),s=z(null),o=t.subscribeSelector(p=>({isValid:p.isValid,isSubmitting:p.isSubmitting,isDirty:p.isDirty}),p=>{e.value=p},{paths:["isValid","isSubmitting","isDirty"]});Z(o);let u=j(t,{clearSubmissionState:()=>{i.value=null,s.value=null},setSubmissionResult:p=>{s.value=p},setSubmissionError:p=>{i.value=p}}),n=M(t),d=I(()=>e.value.isValid),S=I(()=>e.value.isSubmitting),f=I(()=>e.value.isDirty),r=u.onSubmit,a=u.reset;return{meta:{isValid:d,isDirty:f,isSubmitting:S,submitError:i,lastResponse:s},getValues:u.getValues,getErrors:u.getErrors,getTouched:u.getTouched,getDirtyValues:u.getDirtyValues,submit:u.submit,onSubmit:r,reset:a,...n}}import{computed as v,onUnmounted as te,shallowRef as re}from"vue";function E(t){let e=c(),i=e.resolveMask(t),s=C(e,t,i),o=re(e.getFieldState(t)),u=q(e,t,B=>{o.value=B});te(()=>{u(),e.unregisterField&&e.unregisterField(t)});let n=v(()=>o.value.value),d=v(()=>s.displayValue(n.value)),S=v({get:()=>d.value,set:B=>{s.setValue(B)}}),f=v(()=>o.value.error),r=v(()=>o.value.touched?o.value.error:void 0),a=v(()=>o.value.touched),l=v(()=>!!(a.value&&r.value)),p=v(()=>o.value.isValidating),b=v(()=>o.value.isDirty),P=v(()=>o.value.isHidden),h=v(()=>o.value.isRequired),R=v(()=>!!f.value),m=B=>{s.setValue(B)},g=()=>s.setBlur();return{value:n,displayValue:d,modelValue:S,setValue:m,setBlur:g,onInput:B=>{m(B)},onBlur:()=>{g()},meta:{error:r,touched:a,invalid:l,isValidating:p,isDirty:b,isHidden:P,isRequired:h,hasError:R}}}import{ref as L,computed as $,onUnmounted as oe}from"vue";function se(t){let e=c(),i=r=>e.config.idFactory({scope:"array",path:t,index:r}),o=(()=>{let r=V(e.getState().values,t);return Array.isArray(r)?r:[]})(),u=L(o),n=L(o.map((r,a)=>i(a))),d=e.subscribePath(t,r=>{let a=Array.isArray(r)?r:[];if(u.value=[...a],a.length!==n.value.length){let l=[...n.value];if(a.length>l.length){let p=a.length-l.length,b=Array.from({length:p},(P,h)=>i(l.length+h));n.value=[...l,...b]}else n.value=l.slice(0,a.length)}});oe(()=>{d(),e.unregisterPrefix&&e.unregisterPrefix(`${t}.`)});let S=$(()=>u.value.map((r,a)=>({key:n.value[a]||`temp-${a}`,value:r,index:a}))),f=$(()=>u.value.length);return{fields:S,length:f,append:r=>{n.value.push(i(n.value.length)),e.pushItem(t,r)},prepend:r=>{n.value.unshift(i(0)),e.prependItem(t,r)},insert:(r,a)=>{n.value.splice(r,0,i(r)),e.insertItem(t,r,a)},remove:r=>{n.value.splice(r,1),e.removeItem(t,r)},move:(r,a)=>{let l=[...n.value],[p]=l.splice(r,1);l.splice(a,0,p),n.value=l,e.moveItem(t,r,a)},swap:(r,a)=>{let l=[...n.value];[l[r],l[a]]=[l[a],l[r]],n.value=l,e.swapItems(t,r,a)},replace:r=>{n.value=r.map((a,l)=>i(l)),e.setField(t,r)},clear:()=>{n.value=[],e.setField(t,[])}}}import{computed as U,onUnmounted as ie,shallowRef as ne}from"vue";function ae(){let t=c(),e=ne(t.getHistoryMetadata()),i=t.subscribe(()=>{let u=t.getHistoryMetadata();K(e.value,u)||(e.value=u)});ie(i);let s=()=>t.undo(),o=()=>t.redo();return{canUndo:U(()=>e.value.canUndo),canRedo:U(()=>e.value.canRedo),historyIndex:U(()=>e.value.historyIndex),historySize:U(()=>e.value.historySize),undo:s,redo:o}}import{ref as ue,computed as D,onMounted as le,onUnmounted as ce}from"vue";function me(t){let e=c(),i=e.getScopeFields(t),s=ue(e.getStepStatus(t)),o;le(()=>{o=e.subscribeSelector(r=>({errors:r.errors,isDirty:r.isDirty}),()=>{let r=e.getStepStatus(t);T(s.value,r)||(s.value=r)},{paths:x(i)})}),ce(()=>{o?.()});let u=async()=>{let r=await e.validate({scope:t}),a=e.getStepErrors(t);return{valid:r,errors:a}},n=()=>e.getStepErrors(t),d=D(()=>!s.value.hasErrors),S=D(()=>s.value.isDirty),f=D(()=>s.value.errors);return{scopeName:t,status:s,errors:f,validate:u,getErrors:n,isValid:d,isDirty:S}}import{ref as Y,computed as y,watch as pe,onMounted as de,onUnmounted as ve}from"vue";function Se(t){let e=c(),i=Y(0),s=y(()=>t[i.value]??""),o=Y(e.getStepStatus(s.value)),u;pe(s,m=>{o.value=e.getStepStatus(m)});let n=()=>{let m=s.value,g=e.getStepStatus(m);T(o.value,g)||(o.value=g)};de(()=>{u=e.subscribeSelector(m=>({errors:m.errors,isDirty:m.isDirty}),n,{paths:x(e.getScopeFields(s.value))})}),ve(()=>{u?.()});let d=async()=>{let m=s.value,g=await e.validate({scope:m}),F=e.getStepErrors(m);return{valid:g,errors:F}},S=()=>e.getStepErrors(s.value),f=async()=>{let m=s.value,g=e.getScopeFields(m);if(e.hasValidationsInProgress(g))return!1;let F=await e.validate({scope:m});if(F)i.value=Math.min(i.value+1,t.length-1);else{let k=e.getStepErrors(m),B=Object.keys(k);B.length>0&&e.markFieldsTouched(B)}return F},r=()=>{i.value=Math.max(i.value-1,0)},a=m=>{i.value=Math.max(0,Math.min(m-1,t.length-1))},l=y(()=>i.value+1),p=y(()=>i.value===0),b=y(()=>i.value>=t.length-1),P=y(()=>!o.value.hasErrors),h=y(()=>o.value.isDirty),R=y(()=>o.value.errors);return{step:l,stepIndex:i,scope:s,next:f,prev:r,goTo:a,isFirst:p,isLast:b,status:o,errors:R,isValid:P,isDirty:h,validate:d,getErrors:S}}import{ref as fe,onUnmounted as Be,readonly as ge}from"vue";function ye(t){let e=c(),i=V(e.getState().values,t),s=fe(i),o=e.watch(t,u=>{A(s.value,u)||(s.value=u)});return Be(o),ge(s)}import{computed as G,ref as be}from"vue";function he(t,e,i){let s=c(),o=E(t),u=null,n=be(!1),d={setLoading:r=>{n.value=r},setError:(r,a)=>s.setError(r,a),setValue:r=>o.setValue(r),getUploadKey:()=>u,setUploadKey:r=>{u=r}},S=_(t,e,d),f=O(t,i,d);return{value:o.value,setValue:o.setValue,error:G(()=>o.meta.error.value),isValidating:G(()=>!!o.meta.isValidating.value||n.value),upload:S,remove:f}}import{computed as w,onUnmounted as Fe,ref as Pe}from"vue";function Ve(){let t=c(),e=Pe(t.getPersistMetadata()),i=t.subscribeSelector(n=>n.persist,n=>{e.value=n},{paths:["persist"]});return Fe(()=>i()),{restore:async()=>t.restorePersisted(),save:async()=>{await t.forceSave()},clear:async()=>{await t.clearPersisted()},meta:{isSaving:w(()=>e.value.isSaving),isRestoring:w(()=>e.value.isRestoring),error:w(()=>e.value.error)}}}export{X as provideBitStore,se as useBitArray,E as useBitField,ee as useBitForm,ae as useBitHistory,Ve as useBitPersist,me as useBitScope,Se as useBitSteps,c as useBitStore,he as useBitUpload,ye as useBitWatch};
1
+ import{a as K,b as _,c as O}from"../chunk-QWH2NBVB.js";import{a as M,b as j,c as q,d as C,e as T,f as x}from"../chunk-2CVKNPWX.js";import{d as A,e as V,k as H}from"../chunk-PX6WKENM.js";import"../chunk-3NUJVIAM.js";import{inject as J,provide as Q}from"vue";var W=Symbol("BIT_STORE");function X(t){Q(W,H(t))}function c(){let t=J(W);if(!t)throw new Error("BitForm Vue hooks devem ser usados sob um provideBitStore");return t}import{computed as I,onUnmounted as Z,shallowRef as N,ref as z}from"vue";function ee(){let t=c(),e=N({isValid:t.getState().isValid,isSubmitting:t.getState().isSubmitting,isDirty:t.getState().isDirty}),i=z(null),s=z(null),o=t.subscribeSelector(p=>({isValid:p.isValid,isSubmitting:p.isSubmitting,isDirty:p.isDirty}),p=>{e.value=p},{paths:["isValid","isSubmitting","isDirty"]});Z(o);let u=j(t,{clearSubmissionState:()=>{i.value=null,s.value=null},setSubmissionResult:p=>{s.value=p},setSubmissionError:p=>{i.value=p}}),n=M(t),d=I(()=>e.value.isValid),S=I(()=>e.value.isSubmitting),f=I(()=>e.value.isDirty),r=u.onSubmit,a=u.reset;return{meta:{isValid:d,isDirty:f,isSubmitting:S,submitError:i,lastResponse:s},getValues:u.getValues,getErrors:u.getErrors,getTouched:u.getTouched,getDirtyValues:u.getDirtyValues,submit:u.submit,onSubmit:r,reset:a,...n}}import{computed as v,onUnmounted as te,shallowRef as re}from"vue";function E(t){let e=c(),i=e.resolveMask(t),s=C(e,t,i),o=re(e.getFieldState(t)),u=q(e,t,B=>{o.value=B});te(()=>{u(),e.unregisterField&&e.unregisterField(t)});let n=v(()=>o.value.value),d=v(()=>s.displayValue(n.value)),S=v({get:()=>d.value,set:B=>{s.setValue(B)}}),f=v(()=>o.value.error),r=v(()=>o.value.touched?o.value.error:void 0),a=v(()=>o.value.touched),l=v(()=>!!(a.value&&r.value)),p=v(()=>o.value.isValidating),b=v(()=>o.value.isDirty),P=v(()=>o.value.isHidden),h=v(()=>o.value.isRequired),R=v(()=>!!f.value),m=B=>{s.setValue(B)},g=()=>s.setBlur();return{value:n,displayValue:d,modelValue:S,setValue:m,setBlur:g,onInput:B=>{m(B)},onBlur:()=>{g()},meta:{error:r,touched:a,invalid:l,isValidating:p,isDirty:b,isHidden:P,isRequired:h,hasError:R}}}import{ref as L,computed as $,onUnmounted as oe}from"vue";function se(t){let e=c(),i=r=>e.config.idFactory({scope:"array",path:t,index:r}),o=(()=>{let r=V(e.getState().values,t);return Array.isArray(r)?r:[]})(),u=L(o),n=L(o.map((r,a)=>i(a))),d=e.subscribePath(t,r=>{let a=Array.isArray(r)?r:[];if(u.value=[...a],a.length!==n.value.length){let l=[...n.value];if(a.length>l.length){let p=a.length-l.length,b=Array.from({length:p},(P,h)=>i(l.length+h));n.value=[...l,...b]}else n.value=l.slice(0,a.length)}});oe(()=>{d(),e.unregisterPrefix&&e.unregisterPrefix(`${t}.`)});let S=$(()=>u.value.map((r,a)=>({key:n.value[a]||`temp-${a}`,value:r,index:a}))),f=$(()=>u.value.length);return{fields:S,length:f,append:r=>{n.value.push(i(n.value.length)),e.pushItem(t,r)},prepend:r=>{n.value.unshift(i(0)),e.prependItem(t,r)},insert:(r,a)=>{n.value.splice(r,0,i(r)),e.insertItem(t,r,a)},remove:r=>{n.value.splice(r,1),e.removeItem(t,r)},move:(r,a)=>{let l=[...n.value],[p]=l.splice(r,1);l.splice(a,0,p),n.value=l,e.moveItem(t,r,a)},swap:(r,a)=>{let l=[...n.value];[l[r],l[a]]=[l[a],l[r]],n.value=l,e.swapItems(t,r,a)},replace:r=>{n.value=r.map((a,l)=>i(l)),e.setField(t,r)},clear:()=>{n.value=[],e.setField(t,[])}}}import{computed as U,onUnmounted as ie,shallowRef as ne}from"vue";function ae(){let t=c(),e=ne(t.getHistoryMetadata()),i=t.subscribe(()=>{let u=t.getHistoryMetadata();K(e.value,u)||(e.value=u)});ie(i);let s=()=>t.undo(),o=()=>t.redo();return{canUndo:U(()=>e.value.canUndo),canRedo:U(()=>e.value.canRedo),historyIndex:U(()=>e.value.historyIndex),historySize:U(()=>e.value.historySize),undo:s,redo:o}}import{ref as ue,computed as D,onMounted as le,onUnmounted as ce}from"vue";function me(t){let e=c(),i=e.getScopeFields(t),s=ue(e.getStepStatus(t)),o;le(()=>{o=e.subscribeSelector(r=>({errors:r.errors,isDirty:r.isDirty}),()=>{let r=e.getStepStatus(t);T(s.value,r)||(s.value=r)},{paths:x(i)})}),ce(()=>{o?.()});let u=async()=>{let r=await e.validate({scope:t}),a=e.getStepErrors(t);return{valid:r,errors:a}},n=()=>e.getStepErrors(t),d=D(()=>!s.value.hasErrors),S=D(()=>s.value.isDirty),f=D(()=>s.value.errors);return{scopeName:t,status:s,errors:f,validate:u,getErrors:n,isValid:d,isDirty:S}}import{ref as Y,computed as y,watch as pe,onMounted as de,onUnmounted as ve}from"vue";function Se(t){let e=c(),i=Y(0),s=y(()=>t[i.value]??""),o=Y(e.getStepStatus(s.value)),u;pe(s,m=>{o.value=e.getStepStatus(m)});let n=()=>{let m=s.value,g=e.getStepStatus(m);T(o.value,g)||(o.value=g)};de(()=>{u=e.subscribeSelector(m=>({errors:m.errors,isDirty:m.isDirty}),n,{paths:x(e.getScopeFields(s.value))})}),ve(()=>{u?.()});let d=async()=>{let m=s.value,g=await e.validate({scope:m}),F=e.getStepErrors(m);return{valid:g,errors:F}},S=()=>e.getStepErrors(s.value),f=async()=>{let m=s.value,g=e.getScopeFields(m);if(e.hasValidationsInProgress(g))return!1;let F=await e.validate({scope:m});if(F)i.value=Math.min(i.value+1,t.length-1);else{let k=e.getStepErrors(m),B=Object.keys(k);B.length>0&&e.markFieldsTouched(B)}return F},r=()=>{i.value=Math.max(i.value-1,0)},a=m=>{i.value=Math.max(0,Math.min(m-1,t.length-1))},l=y(()=>i.value+1),p=y(()=>i.value===0),b=y(()=>i.value>=t.length-1),P=y(()=>!o.value.hasErrors),h=y(()=>o.value.isDirty),R=y(()=>o.value.errors);return{step:l,stepIndex:i,scope:s,next:f,prev:r,goTo:a,isFirst:p,isLast:b,status:o,errors:R,isValid:P,isDirty:h,validate:d,getErrors:S}}import{ref as fe,onUnmounted as Be,readonly as ge}from"vue";function ye(t){let e=c(),i=V(e.getState().values,t),s=fe(i),o=e.watch(t,u=>{A(s.value,u)||(s.value=u)});return Be(o),ge(s)}import{computed as G,ref as be}from"vue";function he(t,e,i){let s=c(),o=E(t),u=null,n=be(!1),d={setLoading:r=>{n.value=r},setError:(r,a)=>s.setError(r,a),setValue:r=>o.setValue(r),getUploadKey:()=>u,setUploadKey:r=>{u=r}},S=_(t,e,d),f=O(t,i,d);return{value:o.value,setValue:o.setValue,error:G(()=>o.meta.error.value),isValidating:G(()=>!!o.meta.isValidating.value||n.value),upload:S,remove:f}}import{computed as w,onUnmounted as Fe,ref as Pe}from"vue";function Ve(){let t=c(),e=Pe(t.getPersistMetadata()),i=t.subscribeSelector(n=>n.persist,n=>{e.value=n},{paths:["persist"]});return Fe(()=>i()),{restore:async()=>t.restorePersisted(),save:async()=>{await t.forceSave()},clear:async()=>{await t.clearPersisted()},meta:{isSaving:w(()=>e.value.isSaving),isRestoring:w(()=>e.value.isRestoring),error:w(()=>e.value.error)}}}export{X as provideBitStore,se as useBitArray,E as useBitField,ee as useBitForm,ae as useBitHistory,Ve as useBitPersist,me as useBitScope,Se as useBitSteps,c as useBitStore,he as useBitUpload,ye as useBitWatch};
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lehnihon/bit-form",
3
- "version": "2.2.5",
3
+ "version": "2.2.6",
4
4
  "description": "Gerenciamento de estado de formulários agnóstico e performático",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,2 +0,0 @@
1
- function h(s){if(s===null||typeof s!="object")return s;if(typeof structuredClone=="function")return structuredClone(s);if(s instanceof Date)return new Date(s.getTime());if(s instanceof RegExp)return new RegExp(s.source,s.flags);if(Array.isArray(s))return s.map(t=>h(t));let e={};for(let t in s)Object.prototype.hasOwnProperty.call(s,t)&&(e[t]=h(s[t]));return e}function P(s,e){if(e===void 0)return h(s);if(e===null||typeof e!="object"||e instanceof Date||e instanceof RegExp||Array.isArray(e))return h(e);let t=s&&typeof s=="object"&&!Array.isArray(s)?h(s):{};for(let i of Object.keys(e)){let r=e[i],n=t[i];if(r!==null&&typeof r=="object"&&!Array.isArray(r)&&!(r instanceof Date)&&!(r instanceof RegExp)){t[i]=P(n,r);continue}t[i]=h(r)}return t}function S(s,e){return s===e?!0:s===null||typeof s!="object"||e===null||typeof e!="object"?!1:m(s,e)}function m(s,e){if(s===e)return!0;if(s===null||typeof s!="object"||e===null||typeof e!="object")return!1;if(s instanceof Date&&e instanceof Date)return s.getTime()===e.getTime();if(s instanceof RegExp&&e instanceof RegExp)return s.toString()===e.toString();let t=Object.keys(s),i=Object.keys(e);if(t.length!==i.length)return!1;for(let r of t)if(!Object.prototype.hasOwnProperty.call(e,r)||!m(s[r],e[r]))return!1;return!0}function N(s,e,t="",i=new Set){if(S(s,e))return i;if(s===null||typeof s!="object"||e===null||typeof e!="object")return t&&i.add(t),i;if(Array.isArray(s)||Array.isArray(e))return!S(s,e)&&t&&i.add(t),i;let r=new Set;for(let n of Object.keys(s||{}))r.add(n);for(let n of Object.keys(e||{}))r.add(n);for(let n of r){let o=t?`${t}.${n}`:n;N(s?.[n],e?.[n],o,i)}return i}var ie=1e3,B=new Map;function _(s){let e=B.get(s);if(e)return e;let t=s.split(".");return B.size>=ie&&B.clear(),B.set(s,t),t}function p(s,e){if(!e)return s;let t=_(e),i=s;for(let r of t){if(i==null)return;i=i[r]}return i}function y(s,e,t){if(!e)return t;let i=_(e),r=Array.isArray(s)?[...s]:{...s},n=r;for(let o=0;o<i.length-1;o++){let a=i[o],l=i[o+1],d=Number(l),c=Number.isInteger(d)&&String(d)===l,u=n[a];u==null?n[a]=c?[]:{}:n[a]=Array.isArray(u)?[...u]:{...u},n=n[a]}return n[i[i.length-1]]=t,r}function W(s,e){if(e.length===0)return s;let t=Array.isArray(s)?[...s]:{...s},i=new WeakSet;t&&typeof t=="object"&&i.add(t);for(let[r,n]of e){let o=_(r),a=t;for(let l=0;l<o.length-1;l++){let d=o[l],c=o[l+1],u=Number(c),g=Number.isInteger(u)&&String(u)===c,f=a[d];f==null?(a[d]=g?[]:{},i.add(a[d])):typeof f=="object"?i.has(f)||(a[d]=Array.isArray(f)?[...f]:{...f},i.add(a[d])):(a[d]=g?[]:{},i.add(a[d])),a=a[d]}a[o[o.length-1]]=n}return t}function re(s,e){let t={},i=`${e}.`;for(let r in s)r!==e&&!r.startsWith(i)&&(t[r]=s[r]);return t}function E(s,e,t){let i={},r={},n={},o=new Set;Object.keys(s.errors).forEach(l=>o.add(l)),Object.keys(s.touched).forEach(l=>o.add(l)),Object.keys(s.isValidating).forEach(l=>o.add(l));let a=`${e}.`;for(let l of o){let d=se(l,a,t);d&&(Object.prototype.hasOwnProperty.call(s.errors,l)&&(i[d]=s.errors[l]),Object.prototype.hasOwnProperty.call(s.touched,l)&&(r[d]=s.touched[l]),Object.prototype.hasOwnProperty.call(s.isValidating,l)&&(n[d]=s.isValidating[l]))}return{errors:i,touched:r,isValidating:n}}function se(s,e,t){if(!s.startsWith(e))return s;let r=s.substring(e.length).split("."),n=parseInt(r[0],10),o=t(n);if(o===null)return null;let a=r.slice(1).join(".");return a?`${e}${o}.${a}`:`${e}${o}`}function G(s){if(typeof s!="object"||s===null||Array.isArray(s))return!1;let e=s.errors??s;return typeof e!="object"||e===null||Array.isArray(e)?!1:Object.values(e).every(t=>typeof t=="string"||Array.isArray(t)&&t.every(i=>typeof i=="string"))}function ne(s){return G(s)?s.errors??s:{}}var $=typeof globalThis<"u"?globalThis:typeof global<"u"?global:window;$.__BIT_FORM__||($.__BIT_FORM__={stores:{},listeners:new Set,dispatch(s,e){this.listeners.forEach(t=>t(s,e))},subscribe(s){return this.listeners.add(s),()=>{this.listeners.delete(s)}}});var T=$.__BIT_FORM__;function ae(){return`bit-form-${Math.random().toString(36).slice(2,9)}`}function J(s={}){let e=s.initialValues??{},t=s.validation,i=s.history,r=s.name?`bit-form:${s.name}:draft`:"bit-form:draft",n={enabled:s.persist?.enabled??!1,key:s.persist?.key??r,storage:s.persist?.storage,autoSave:s.persist?.autoSave??!0,debounceMs:s.persist?.debounceMs??300,mode:s.persist?.mode??"values",serialize:s.persist?.serialize??JSON.stringify,deserialize:s.persist?.deserialize??(o=>JSON.parse(o)),onError:s.persist?.onError};return{name:s.name,initialValues:h(e),resolver:t?.resolver,validationDelay:t?.delay??300,enableHistory:i?.enabled??!1,historyLimit:i?.limit??15,masks:s.masks,fields:s.fields,devTools:s.devTools,persist:n,idFactory:s.idFactory??ae,plugins:s.plugins??[]}}var V=class{fieldConfigs=new Map;dependencies=new Map;hiddenFields=new Set;conditionalVisibilityPaths=new Set;requiredPathsByDependency=new Map;requiredConditionalPaths=new Set;requiredEvaluationCache=new WeakMap;requiredEvaluationCacheDirty=!1;getFieldConfig(e){return this.fieldConfigs.get(e)}forEachFieldConfig(e){this.fieldConfigs.forEach((t,i)=>e(t,i))}hasFieldConfig(e){return this.fieldConfigs.has(e)}getHiddenFields(){return this.hiddenFields}register(e,t,i){this.fieldConfigs.set(e,t),t.conditional?.showIf&&this.conditionalVisibilityPaths.add(e);let r=t.conditional?.dependsOn;r&&r.forEach(o=>{this.dependencies.has(o)||this.dependencies.set(o,new Set),this.dependencies.get(o).add(e)});let n=t.conditional?.dependsOn;n&&t.conditional?.requiredIf&&(this.requiredConditionalPaths.add(e),n.forEach(o=>{this.requiredPathsByDependency.has(o)||this.requiredPathsByDependency.set(o,new Set),this.requiredPathsByDependency.get(o).add(e)})),this.requiredEvaluationCacheDirty=!0,this.evaluateFieldCondition(e,i)}isHidden(e){return this.hiddenFields.has(e)}isRequired(e,t){let i=this.fieldConfigs.get(e);if(!i||this.isHidden(e)||!i.conditional?.requiredIf)return!1;this.requiredEvaluationCacheDirty&&(this.requiredEvaluationCache=new WeakMap,this.requiredEvaluationCacheDirty=!1);let r=this.requiredEvaluationCache.get(t);if(r||(r=new Map,this.requiredEvaluationCache.set(t,r)),r.has(e))return r.get(e);let n=!!i.conditional.requiredIf(t);return r.set(e,n),n}getRequiredErrors(e){let t={};return this.requiredConditionalPaths.forEach(i=>{let r=this.fieldConfigs.get(i);if(r&&this.isRequired(i,e)){let n=p(e,i);this.isEmpty(n)&&(t[i]=r.conditional?.requiredMessage??"required field")}}),t}evaluateAll(e){this.conditionalVisibilityPaths.forEach(t=>{this.evaluateFieldCondition(t,e)})}updateDependencies(e,t){let i=[],r=[e],n=new Set;for(;r.length>0;){let o=r.shift();if(n.has(o))continue;n.add(o);let a=this.dependencies.get(o);a&&a.forEach(l=>{let d=this.isHidden(l);this.evaluateFieldCondition(l,t);let c=this.isHidden(l);d!==c&&i.push(l),r.push(l)})}return i}unregister(e){let t=this.fieldConfigs.get(e);this.fieldConfigs.delete(e),this.hiddenFields.delete(e),this.conditionalVisibilityPaths.delete(e),this.dependencies.delete(e),this.requiredEvaluationCacheDirty=!0,this.requiredConditionalPaths.delete(e),t?.conditional?.dependsOn?.forEach(i=>{let r=this.requiredPathsByDependency.get(i);r&&(r.delete(e),r.size===0&&this.requiredPathsByDependency.delete(i))}),this.dependencies.forEach(i=>{i.delete(e)})}unregisterPrefix(e){let t=[];return this.fieldConfigs.forEach((i,r)=>{r.startsWith(e)&&t.push([r,i])}),t.forEach(([i])=>this.unregister(i)),t}evaluateFieldCondition(e,t){let r=this.fieldConfigs.get(e)?.conditional?.showIf;r&&(r(t)?this.hiddenFields.delete(e):this.hiddenFields.add(e))}isEmpty(e){return e==null||typeof e=="string"&&e.trim()===""||Array.isArray(e)&&e.length===0}};var C=class s{constructor(e){this.getComputedEntries=e}static MIN_PASSES=4;computedDependencyCache=new Map;reverseDepsCache=null;childDepsIndex=null;invalidateReverseDeps(){this.reverseDepsCache=null,this.childDepsIndex=null}getReverseDependencies(e){if(this.reverseDepsCache)return this.reverseDepsCache;let t=new Map;for(let r of e){let n=this.getDependenciesForEntry(r);for(let o of n){let a=t.get(o);a||(a=new Set,t.set(o,a)),a.add(r.path)}}let i=new Map;for(let r of t.keys()){let n=r.split(".");for(let o=1;o<n.length;o++){let a=n.slice(0,o).join("."),l=i.get(a);l||(l=new Set,i.set(a,l)),l.add(r)}}return this.reverseDepsCache=t,this.childDepsIndex=i,t}apply(e,t){let i=this.normalizeEntries(this.getComputedEntries());if(i.length===0)return e;let r=this.resolveEntriesToRun(i,t),n=r.entries;if(n.length===0)return e;let o=e,a=r.requiresStabilizationPasses?Math.max(s.MIN_PASSES,n.length*2):1;for(let l=0;l<a;l++){let d=!1;for(let c of n){let{newValue:u,trackedDependencies:g}=this.computeWithTracking(c,o,r.shouldTrackDependencies),f=p(o,c.path);if(m(f,u)||(o=y(o,c.path,u),d=!0),g){let L=this.computedDependencyCache.get(c.path);this.computedDependencyCache.set(c.path,g),(!L||L.size!==g.size||Array.from(L).some(te=>!g.has(te)))&&this.invalidateReverseDeps()}}if(!d)break;if(r.requiresStabilizationPasses&&l===a-1)throw new Error("BitStore: computed fields did not stabilize. Check for cyclic computed definitions.")}return o}resolveEntriesToRun(e,t){if(!t||t.length===0||t.includes("*"))return{entries:this.orderEntries(e),shouldTrackDependencies:!0,requiresStabilizationPasses:!0};let i=this.getReverseDependencies(e),r=!1;for(let l of e)this.getDependenciesForEntry(l).length===0&&(r=!0);let n=new Set,o=[...t];for(;o.length>0;){let l=o.shift(),d=this.getDependentsForPath(i,l);if(d)for(let c of d)n.has(c)||(n.add(c),o.push(c))}if(n.size===0)return{entries:[],shouldTrackDependencies:r,requiresStabilizationPasses:!1};let a=e.filter(l=>n.has(l.path));return{entries:this.orderEntries(a),shouldTrackDependencies:r,requiresStabilizationPasses:r}}normalizeEntries(e){return e.length===0||!Array.isArray(e[0])?e:e.map(t=>Array.isArray(t)?{path:t[0],compute:t[1]}:t)}getDependenciesForEntry(e){return e.dependsOn??Array.from(this.computedDependencyCache.get(e.path)??[])}orderEntries(e){if(e.length<=1)return e;let t=new Map(e.map(a=>[a.path,a])),i=new Map,r=new Map;e.forEach(a=>i.set(a.path,0)),e.forEach(a=>{this.getDependenciesForEntry(a).forEach(d=>{if(!t.has(d))return;let c=r.get(d)??new Set;c.has(a.path)||(c.add(a.path),r.set(d,c),i.set(a.path,(i.get(a.path)??0)+1))})});let n=e.filter(a=>(i.get(a.path)??0)===0).map(a=>a.path),o=[];for(;n.length>0;){let a=n.shift();o.push(a);let l=r.get(a);l&&l.forEach(d=>{let c=(i.get(d)??0)-1;i.set(d,c),c===0&&n.push(d)})}if(o.length!==e.length)throw new Error("BitStore: cyclic computed dependencies detected. Check computedDependsOn definitions.");return o.map(a=>t.get(a))}getDependentsForPath(e,t){let i=new Set,r=a=>{let l=e.get(a);l&&l.forEach(d=>i.add(d))};r(t);let n=t.split(".");for(;n.length>1;)n.pop(),r(n.join("."));let o=this.childDepsIndex?.get(t);if(o)for(let a of o)r(a);return i}computeWithTracking(e,t,i){let r=this.getDependenciesForEntry(e);if(!i||r.length>0)return{newValue:e.compute(t),trackedDependencies:null};let n=new Set,o=this.createTrackedValues(t,n);return{newValue:e.compute(o),trackedDependencies:n}}createTrackedValues(e,t){let i=(r,n)=>!r||typeof r!="object"?r:new Proxy(r,{get:(o,a)=>{if(typeof a!="string")return Reflect.get(o,a);let l=n?`${n}.${a}`:a;t.add(l);let d=Reflect.get(o,a);return i(d,l)}});return i(e,"")}};var F=class{dirtyPaths=new Set;dirtyPathIndex=new Set;dirtyPrefixRefCount=new Map;updateForPath(e,t,i){this.removeDirtyChildren(e);let r=p(t,e),n=p(i,e);return S(r,n)?this.removeDirtyPath(e):this.addDirtyPath(e),this.dirtyPaths.size>0}rebuild(e,t){return this.dirtyPaths=N(e,t),this.dirtyPrefixRefCount.clear(),this.rebuildIndex(),this.dirtyPaths.size>0}clear(){this.dirtyPaths.clear(),this.dirtyPathIndex.clear(),this.dirtyPrefixRefCount.clear()}get isDirty(){return this.dirtyPaths.size>0}getDirtyPaths(){return this.dirtyPaths}isPathDirty(e){if(this.dirtyPathIndex.has(e))return!0;let t=e.split(".");for(;t.length>1;)if(t.pop(),this.dirtyPaths.has(t.join(".")))return!0;return!1}buildDirtyValues(e){if(this.dirtyPaths.size===0)return{};let t={},i=new Set;for(let r of this.dirtyPaths){let n=r.match(/^(.+)\.\d+/);if(n){let o=n[1];if(i.has(o))continue;i.add(o);let a=p(e,o);t=y(t,o,a)}else{let o=p(e,r);t=y(t,r,o)}}return t}rebuildIndex(){let e=new Set,t=new Map;for(let i of this.dirtyPaths)this.forEachPathPrefix(i,r=>{e.add(r),t.set(r,(t.get(r)??0)+1)});this.dirtyPathIndex=e,this.dirtyPrefixRefCount=t}removeDirtyChildren(e){let t=[];for(let i of this.dirtyPaths)i.startsWith(`${e}.`)&&t.push(i);t.forEach(i=>this.removeDirtyPath(i))}addDirtyPath(e){this.dirtyPaths.has(e)||(this.dirtyPaths.add(e),this.forEachPathPrefix(e,t=>{this.dirtyPathIndex.add(t),this.dirtyPrefixRefCount.set(t,(this.dirtyPrefixRefCount.get(t)??0)+1)}))}removeDirtyPath(e){this.dirtyPaths.has(e)&&(this.dirtyPaths.delete(e),this.forEachPathPrefix(e,t=>{let i=(this.dirtyPrefixRefCount.get(t)??0)-1;if(i<=0){this.dirtyPrefixRefCount.delete(t),this.dirtyPathIndex.delete(t);return}this.dirtyPrefixRefCount.set(t,i)}))}forEachPathPrefix(e,t){let i=e.split("."),r="";for(let n of i)r=r?`${r}.${n}`:n,t(r)}};var x=class{constructor(e){this.getState=e}listeners=new Set;selectorListeners=new Set;pathScopedSubscriptions=new Map;pathSelectorIndex=new Map;expandedPathCache=new Map;notifyScopedSubscribers=new Set;subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}subscribeSelector(e,t,i,r){let n=e(this.getState()),o={notify:d=>{let c=e(d);r(n,c)||(n=c,t(c))}},a=i?.autoTrackPaths?this.collectTrackedSelectorPaths(e):[],l=this.normalizeSubscriptionPaths([...i?.paths??[],...a]);return l.length>0?(this.pathScopedSubscriptions.set(o,l),l.forEach(d=>{this.expandPathForIndexing(d).forEach(c=>{let u=this.pathSelectorIndex.get(c)??new Set;u.add(o),this.pathSelectorIndex.set(c,u)})})):this.selectorListeners.add(o),i?.emitImmediately&&t(n),()=>{this.selectorListeners.delete(o);let d=this.pathScopedSubscriptions.get(o);d&&(d.forEach(c=>{this.expandPathForIndexing(c).forEach(u=>{let g=this.pathSelectorIndex.get(u);g&&(g.delete(o),g.size===0&&this.pathSelectorIndex.delete(u))})}),this.pathScopedSubscriptions.delete(o))}}notify(e,t){if(this.listeners.forEach(r=>r()),this.selectorListeners.forEach(r=>{r.notify(e)}),this.pathScopedSubscriptions.size===0)return;if(!t||t.length===0||t.includes("*")){this.pathScopedSubscriptions.forEach((r,n)=>{n.notify(e)});return}this.collectSubscribersForChangedPaths(t).forEach(r=>{r.notify(e)})}destroy(){this.listeners.clear(),this.selectorListeners.clear(),this.pathScopedSubscriptions.clear(),this.pathSelectorIndex.clear(),this.expandedPathCache.clear(),this.notifyScopedSubscribers.clear()}normalizeSubscriptionPaths(e){if(!e||e.length===0)return[];let t=new Set,i=[];for(let r of e){let n=r.trim();n.length===0||t.has(n)||(t.add(n),i.push(n))}return i}collectTrackedSelectorPaths(e){let t=new Set,i=(n,o)=>!n||typeof n!="object"?n:new Proxy(n,{get:(a,l)=>{if(typeof l!="string")return Reflect.get(a,l);let d=o?`${o}.${l}`:l;t.add(d);let c=Reflect.get(a,l);return i(c,d)}}),r=new Proxy(this.getState(),{get:(n,o)=>{if(typeof o!="string")return Reflect.get(n,o);let a=Reflect.get(n,o);return o==="values"?i(a,""):a}});try{return e(r),Array.from(t)}catch{return[]}}collectSubscribersForChangedPaths(e){let t=this.notifyScopedSubscribers;t.clear();let i=n=>{let o=this.pathSelectorIndex.get(n);o&&o.forEach(a=>t.add(a))};return this.normalizeSubscriptionPaths(e).forEach(n=>{i(n);let o=n.split(".");for(;o.length>1;)o.pop(),i(o.join("."))}),t}expandPathForIndexing(e){let t=this.expandedPathCache.get(e);if(t)return t;let i=e.split("."),r=[];for(let n=1;n<=i.length;n++)r.push(i.slice(0,n).join("."));return this.expandedPathCache.set(e,r),r}};function oe(s){let e=!1;for(let i of Object.values(s))if(i===void 0){e=!0;break}if(!e)return s;let t={};return Object.entries(s).forEach(([i,r])=>{r!==void 0&&(t[i]=r)}),t}function le(s){for(let e in s)return!0;return!1}function K(s){let{currentState:e,partialState:t,changedPaths:i,applyComputedValues:r}=s,n={...e,...t},o=!!t.values;t.values&&(n.values=r(t.values)),t.errors&&(n.errors=oe(t.errors),n.isValid=!le(n.errors));let a=i&&i.length>0?i:void 0,l=de(t,!a),d=ce(a,l);return{nextState:n,changedPaths:d,valuesChanged:o}}function de(s,e){if(e&&s.values)return["*"];let t=new Set,i=[s.errors,s.touched,s.isValidating];for(let r of i)if(r)for(let n in r)t.add(n);return s.persist&&t.add("persist"),"isValid"in s&&t.add("isValid"),"isDirty"in s&&t.add("isDirty"),"isSubmitting"in s&&t.add("isSubmitting"),t.size>0?Array.from(t):void 0}function ce(s,e){if(!s?.length)return e;if(!e?.length)return s;let t=new Set;for(let i of s)t.add(i);for(let i of e)t.add(i);return Array.from(t)}function ue(s){return typeof s=="boolean"?{enabled:s,mode:"local"}:{enabled:!!s,mode:s?.mode??"local",url:s?.url}}function X(s){let e=ue(s);return e.enabled?{name:"bit-devtools",setup:()=>{let t=null,i=!1;return(async()=>{try{if(e.mode==="remote"){let{setupRemoteBridge:r}=await import("./devtools/bridge.js");t=r(e.url||"ws://localhost:3000")}else{let{initDevTools:r}=await import("./devtools/index.js"),n=r();t=n&&typeof n.destroy=="function"?n.destroy:null}i&&t&&(t(),t=null)}catch{}})(),()=>{i=!0,t&&(t(),t=null)}}}:null}function he(){if(typeof globalThis>"u")return;let s=globalThis.localStorage;if(s)return{getItem:e=>s.getItem(e),setItem:(e,t)=>s.setItem(e,t),removeItem:e=>s.removeItem(e)}}var w=class{constructor(e,t,i,r){this.config=e;this.getValues=t;this.getDirtyValues=i;this.applyRestoredValues=r}timer;getStorage(){return this.config.storage||he()}canPersist(){return!!(this.config.enabled&&this.config.key&&this.getStorage())}handleError(e){this.config.onError?.(e)}async saveNow(){if(!this.canPersist())return;let e=this.getStorage();if(e)try{let t=this.config.mode==="dirtyValues"?this.getDirtyValues():this.getValues(),i=this.config.serialize(t);await e.setItem(this.config.key,i)}catch(t){this.handleError(t)}}queueSave(){!this.canPersist()||!this.config.autoSave||(this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.saveNow()},this.config.debounceMs))}async restore(){if(!this.canPersist())return!1;let e=this.getStorage();if(!e)return!1;try{let t=await e.getItem(this.config.key);if(!t)return!1;let i=this.config.deserialize(t);return!i||typeof i!="object"?!1:(this.applyRestoredValues(i),!0)}catch(t){return this.handleError(t),!1}}async clear(){if(!this.canPersist())return;let e=this.getStorage();if(e)try{await e.removeItem(this.config.key)}catch(t){this.handleError(t)}}destroy(){this.timer&&(clearTimeout(this.timer),this.timer=void 0)}};var D=class{constructor(e,t){this.plugins=e;this.contextFactory=t}teardownFns=[];notifyingError=!1;setupAll(){this.plugins.forEach(e=>{if(e.setup)try{let t=e.setup(this.contextFactory());typeof t=="function"&&this.teardownFns.push(t)}catch(t){this.reportError("setup",t,void 0,e.name)}})}async beforeValidate(e){await this.emitHook("beforeValidate",e)}async afterValidate(e){await this.emitHook("afterValidate",e)}async beforeSubmit(e){await this.emitHook("beforeSubmit",e)}async afterSubmit(e){await this.emitHook("afterSubmit",e)}onFieldChange(e){this.plugins.forEach(t=>{let i=t.hooks?.onFieldChange;if(i)try{let r=i(e,this.contextFactory());Promise.resolve(r).catch(n=>{this.reportError("onFieldChange",n,e,t.name)})}catch(r){this.reportError("onFieldChange",r,e,t.name)}})}async reportError(e,t,i,r){if(this.notifyingError)return;this.notifyingError=!0;let n=this.contextFactory(),o={source:e,pluginName:r,error:t,event:i,values:n.getState().values,state:n.getState()};for(let a of this.plugins){let l=a.hooks?.onError;if(l)try{await l(o,n)}catch{}}this.notifyingError=!1}destroy(){for(let e=this.teardownFns.length-1;e>=0;e-=1){let t=this.teardownFns[e];try{t()}catch(i){this.reportError("teardown",i)}}this.teardownFns=[]}async emitHook(e,t){let i=this.contextFactory();for(let r of this.plugins){let n=r.hooks?.[e];if(n)try{await n(t,i)}catch(o){await this.reportError(e,o,t,r.name)}}}};var k=class{constructor(e,t,i,r){this.storeId=e;this.storeInstance=t;this.persistManager=i;this.pluginManager=r}initialize(){this.pluginManager.setupAll(),T.stores[this.storeId]=this.storeInstance}onStateUpdated(e,t){t&&this.persistManager.queueSave(),T.dispatch(this.storeId,e)}restorePersisted(){return this.persistManager.restore()}savePersistedNow(){return this.persistManager.saveNow()}clearPersisted(){return this.persistManager.clear()}beforeValidate(e){return this.pluginManager.beforeValidate(e)}afterValidate(e){return this.pluginManager.afterValidate(e)}beforeSubmit(e){return this.pluginManager.beforeSubmit(e)}afterSubmit(e){return this.pluginManager.afterSubmit(e)}onFieldChange(e){this.pluginManager.onFieldChange(e)}reportOperationalError(e){return this.pluginManager.reportError(e.source,e.error,e.payload)}destroy(){this.persistManager.destroy(),this.pluginManager.destroy(),delete T.stores[this.storeId]}};var v=class{constructor(e){this.steps=e}async run(e){for(let t of this.steps){if(e.halted)break;await t.run(e)}}},M=class{constructor(e){this.steps=e}run(e){for(let t of this.steps){if(e.halted)break;t.run(e)}}};function A(s){for(let e in s)return!0;return!1}var R=class{constructor(e){this.store=e;this.validationPipeline=new v([{name:"validate:resolve-target-fields",run:t=>this.resolveTargetFields(t)},{name:"validate:before-hooks",run:async t=>this.runBeforeValidateHooks(t)},{name:"validate:resolver",run:async t=>this.runResolver(t)},{name:"validate:required-and-hidden",run:t=>this.applyRequiredAndHiddenRules(t)},{name:"validate:abort-check",run:async t=>this.abortIfOutdated(t)},{name:"validate:commit-scoped",run:async t=>this.commitScopedValidation(t)},{name:"validate:commit-global",run:async t=>this.commitGlobalValidation(t)}])}validationTimeout;currentValidationId=0;asyncEpoch=0;validatingCount=0;pendingScopeFields=null;asyncTimers=new Map;asyncRequests=new Map;asyncErrors=new Map;validationPipeline;updateFieldValidating(e,t){let i=this.store.getState();if(!!i.isValidating[e]===t)return;let n={...i.isValidating};t?(n[e]=!0,this.validatingCount+=1):(delete n[e],this.validatingCount=Math.max(0,this.validatingCount-1)),this.store.internalUpdateState({isValidating:n})}cancelFieldAsync(e){let t=this.asyncTimers.get(e);t&&(clearTimeout(t),this.asyncTimers.delete(e)),this.asyncRequests.set(e,(this.asyncRequests.get(e)||0)+1)}cleanupField(e){this.cancelFieldAsync(e),this.asyncTimers.delete(e),this.asyncRequests.delete(e),this.asyncErrors.delete(e),this.updateFieldValidating(e,!1)}cleanupPrefix(e){for(let t of this.asyncTimers.keys())(t===e||t.startsWith(`${e}.`))&&this.cleanupField(t)}beginExternalValidation(e){this.cancelFieldAsync(e),this.updateFieldValidating(e,!0)}endExternalValidation(e){this.updateFieldValidating(e,!1)}async setExternalError(e,t){if(t){this.asyncErrors.set(e,t),this.store.setError(e,t);return}if(this.asyncErrors.delete(e),this.store.validate){await this.store.validate({scopeFields:[e]});return}let i={...this.store.getState().errors};delete i[e],this.store.internalUpdateState({errors:i,isValid:!A(i)})}handleAsync(e,t){let i=this.store.getFieldConfig(e),r=i?.validation?.asyncValidate;if(!r){this.updateFieldValidating(e,!1);return}let n=this.asyncTimers.get(e);n&&clearTimeout(n);let o=i.validation?.asyncValidateDelay??500;this.updateFieldValidating(e,!0),this.asyncTimers.set(e,setTimeout(async()=>{this.asyncTimers.delete(e);let a=this.asyncEpoch,l=(this.asyncRequests.get(e)||0)+1;this.asyncRequests.set(e,l);try{let d=await r(t,this.store.getState().values);if(this.asyncRequests.get(e)!==l||a!==this.asyncEpoch)return;if(d)this.asyncErrors.set(e,d),this.store.setError(e,d);else if(this.asyncErrors.delete(e),this.store.validate)await this.store.validate({scopeFields:[e]});else{let c={...this.store.getState().errors};delete c[e],this.store.internalUpdateState({errors:c,isValid:!A(c)})}}finally{this.asyncRequests.get(e)===l&&a===this.asyncEpoch&&this.updateFieldValidating(e,!1)}},o))}hasValidationsInProgress(e){let t=this.store.getState();return e&&e.length>0?e.some(i=>!!t.isValidating[i]):this.validatingCount>0}trigger(e,t){this.validationTimeout&&clearTimeout(this.validationTimeout);let i=this.store.config.validationDelay??300,r=t?.forceDebounce?Math.max(1,i):i;if(r>0){if(e&&e.length>0)if(!this.pendingScopeFields)this.pendingScopeFields=new Set(e);else for(let o of e)this.pendingScopeFields.add(o);else this.pendingScopeFields=null;let n=this.pendingScopeFields?Array.from(this.pendingScopeFields):void 0;this.validationTimeout=setTimeout(()=>{this.pendingScopeFields=null,this.validate({scopeFields:n})},r)}else this.pendingScopeFields=null,this.validate({scopeFields:e})}async validate(e){let t={options:e,validationId:++this.currentValidationId,currentState:this.store.getState(),targetFields:e?.scopeFields,allErrors:{},isValid:!0,result:!0,aborted:!1};return await this.validationPipeline.run(t),t.result}clear(e){let t=this.asyncTimers.get(e);t&&clearTimeout(t),this.asyncTimers.delete(e),this.updateFieldValidating(e,!1),this.asyncErrors.delete(e)}cancelAll(){this.asyncEpoch+=1,this.validatingCount=0,this.pendingScopeFields=null,this.validationTimeout&&clearTimeout(this.validationTimeout),this.asyncTimers.forEach(e=>clearTimeout(e)),this.asyncTimers.clear(),this.asyncRequests.clear(),this.asyncErrors.clear(),this.store.internalUpdateState({isValidating:{}})}resolveTargetFields(e){if(e.options?.scope){let t=this.store.getScopeFields(e.options.scope);t.length>0&&(e.targetFields=t)}}async runBeforeValidateHooks(e){await this.store.emitBeforeValidate({values:e.currentState.values,state:e.currentState,scope:e.options?.scope,scopeFields:e.targetFields})}async runResolver(e){e.allErrors=this.store.config.resolver?await this.store.config.resolver(e.currentState.values,{scopeFields:e.targetFields}):{}}applyRequiredAndHiddenRules(e){let t=this.store.getRequiredErrors(e.currentState.values);e.allErrors={...e.allErrors,...t},this.store.getHiddenFields().forEach(i=>{delete e.allErrors[i],this.asyncErrors.delete(i)})}async abortIfOutdated(e){e.validationId!==this.currentValidationId&&(e.aborted=!0,e.result=e.currentState.isValid,await this.store.emitAfterValidate({values:this.store.getState().values,state:this.store.getState(),scope:e.options?.scope,scopeFields:e.targetFields,errors:this.store.getState().errors,result:e.currentState.isValid,aborted:!0}),e.halted=!0)}async commitScopedValidation(e){if(!e.targetFields)return;let t={...e.currentState.errors};e.targetFields.forEach(i=>{e.allErrors[i]?t[i]=e.allErrors[i]:this.asyncErrors.has(i)?t[i]=this.asyncErrors.get(i):delete t[i]}),e.isValid=!A(t),e.result=e.targetFields.every(i=>!e.allErrors[i]&&!this.asyncErrors.has(i)),this.store.internalUpdateState({errors:t,isValid:e.isValid}),await this.store.emitAfterValidate({values:this.store.getState().values,state:this.store.getState(),scope:e.options?.scope,scopeFields:e.targetFields,errors:t,result:e.result}),e.halted=!0}async commitGlobalValidation(e){e.allErrors={...Object.fromEntries(this.asyncErrors.entries()),...e.allErrors},e.isValid=!A(e.allErrors),e.result=e.isValid,this.store.internalUpdateState({errors:e.allErrors,isValid:e.isValid}),await this.store.emitAfterValidate({values:this.store.getState().values,state:this.store.getState(),scope:e.options?.scope,scopeFields:e.targetFields,errors:e.allErrors,result:e.isValid})}};var I=class{constructor(e){this.store=e;this.fieldUpdatePipeline=new M([{name:"field:clear-current-error",run:t=>this.clearCurrentError(t)},{name:"field:update-dependencies",run:t=>this.updateDependencies(t)},{name:"field:update-dirty",run:t=>this.updateDirtyState(t)},{name:"field:commit-state",run:t=>this.commitFieldState(t)},{name:"field:emit-change",run:t=>this.emitFieldChange(t)},{name:"field:trigger-validate",run:t=>this.triggerResolverValidation(t)},{name:"field:trigger-async-validate",run:t=>this.triggerAsyncValidation(t)}]),this.submitPipeline=new v([{name:"submit:start",run:async t=>this.startSubmit(t)},{name:"submit:invalid",run:async t=>this.handleInvalidSubmit(t)},{name:"submit:prepare",run:t=>this.prepareSubmitValues(t)},{name:"submit:before-hooks",run:async t=>this.runBeforeSubmitHooks(t)},{name:"submit:user-handler",run:async t=>this.runSubmitHandler(t)},{name:"submit:after-hooks",run:async t=>this.runAfterSubmitHooks(t)}])}fieldUpdatePipeline;submitPipeline;updateField(e,t,i={origin:"setField"}){let r=this.store.getState(),n={path:e,value:t,meta:i,previousValue:p(r.values,e),nextValues:y(r.values,e,t),nextErrors:r.errors,hasMutatedErrors:!1,toggledFields:[],isDirty:!1};this.fieldUpdatePipeline.run(n)}replaceValues(e,t="replaceValues"){let i=this.store.getState().values,r=h(e);this.store.cancelAllValidations(),this.store.evaluateAllDependencies(r);let n=this.store.rebuildDirtyState(r,this.store.config.initialValues);this.store.internalUpdateState({values:r,errors:{},isValidating:{},isValid:!0,isDirty:n,isSubmitting:!1},["*"]),this.store.internalSaveSnapshot(),this.store.validateNow(),this.store.emitFieldChange({path:"*",previousValue:i,nextValue:r,values:this.store.getState().values,state:this.store.getState(),meta:{origin:t}})}hydrateValues(e){let t=P(this.store.getState().values,e);this.replaceValues(t,"hydrate")}rebaseValues(e){let t=this.store.getState().values,i=h(e);this.store.config.initialValues=h(i),this.store.cancelAllValidations(),this.store.evaluateAllDependencies(i),this.store.clearDirtyState(),this.store.internalUpdateState({values:i,errors:{},touched:{},isValidating:{},isValid:!0,isDirty:!1,isSubmitting:!1},["*"]),this.store.internalSaveSnapshot(),this.store.validateNow(),this.store.emitFieldChange({path:"*",previousValue:t,nextValue:i,values:this.store.getState().values,state:this.store.getState(),meta:{origin:"rebase"}})}async submit(e){if(this.store.getState().isSubmitting||this.store.hasValidationsInProgress())return;this.store.cancelAllValidations();let i={onSuccess:e,isValid:!1,valuesToSubmit:h(this.store.getState().values),dirtyValues:{}};try{await this.submitPipeline.run(i)}catch(r){i.error=r,await this.store.emitOperationalError({source:"submit",error:r}),await this.store.emitAfterSubmit({values:this.store.getState().values,dirtyValues:this.store.buildDirtyValues(this.store.getState().values),state:this.store.getState(),success:!1,error:r}),console.error(r)}finally{this.store.internalUpdateState({isSubmitting:!1})}}reset(){this.store.cancelAllValidations();let e=h(this.store.config.initialValues);this.store.evaluateAllDependencies(e),this.store.clearDirtyState(),this.store.internalUpdateState({values:e,errors:{},touched:{},isValidating:{},isValid:!0,isDirty:!1,isSubmitting:!1},["*"]),this.store.resetHistory(e)}clearCurrentError(e){let t=Object.prototype.hasOwnProperty.call(e.nextErrors,e.path);t&&!e.hasMutatedErrors&&(e.nextErrors={...e.nextErrors},e.hasMutatedErrors=!0),t&&delete e.nextErrors[e.path],this.store.clearFieldValidation(e.path)}updateDependencies(e){e.toggledFields=this.store.updateDependencies(e.path,e.nextValues),e.toggledFields.forEach(t=>{if(this.store.isFieldHidden(t)){let i=Object.prototype.hasOwnProperty.call(e.nextErrors,t);i&&!e.hasMutatedErrors&&(e.nextErrors={...e.nextErrors},e.hasMutatedErrors=!0),i&&delete e.nextErrors[t],this.store.clearFieldValidation(t)}})}updateDirtyState(e){e.isDirty=this.store.updateDirtyForPath(e.path,e.nextValues,this.store.config.initialValues)}commitFieldState(e){this.store.internalUpdateState({values:e.nextValues,errors:e.nextErrors,isDirty:e.isDirty},[e.path,...e.toggledFields])}emitFieldChange(e){this.store.emitFieldChange({path:e.path,previousValue:e.previousValue,nextValue:e.value,values:this.store.getState().values,state:this.store.getState(),meta:e.meta})}triggerResolverValidation(e){this.store.config.resolver&&this.store.triggerValidation([e.path])}triggerAsyncValidation(e){this.store.handleFieldAsyncValidation(e.path,e.value)}async startSubmit(e){this.store.internalUpdateState({isSubmitting:!0}),e.isValid=await this.store.validateNow()}async handleInvalidSubmit(e){if(e.isValid)return;let t=this.store.getState().errors,i={...this.store.getState().touched};Object.keys(t).forEach(r=>{i[r]=!0}),this.store.batchStateUpdates(()=>{this.store.internalUpdateState({touched:i})}),e.dirtyValues=this.store.buildDirtyValues(this.store.getState().values),e.invalid=!0,await this.store.emitAfterSubmit({values:this.store.getState().values,dirtyValues:e.dirtyValues,state:this.store.getState(),success:!1,invalid:!0}),e.halted=!0}prepareSubmitValues(e){let t=[];this.store.getHiddenFields().forEach(i=>{t.push([i,void 0])});for(let[i,r]of this.store.getTransformEntries()){let n=p(e.valuesToSubmit,i);t.push([i,r(n,this.store.getState().values)])}t.length>0&&(e.valuesToSubmit=W(e.valuesToSubmit,t)),e.dirtyValues=this.store.buildDirtyValues(e.valuesToSubmit)}async runBeforeSubmitHooks(e){await this.store.emitBeforeSubmit({values:e.valuesToSubmit,dirtyValues:e.dirtyValues,state:this.store.getState()})}async runSubmitHandler(e){await e.onSuccess(e.valuesToSubmit,e.dirtyValues)}async runAfterSubmitHooks(e){await this.store.emitAfterSubmit({values:e.valuesToSubmit,dirtyValues:e.dirtyValues,state:this.store.getState(),success:!0})}};var q=class{constructor(e,t=15){this.enableHistory=e;this.maxHistory=t}history=[];historyIndex=-1;historySize=0;historyHead=0;saveSnapshot(e){if(!this.enableHistory)return;let t=this.getSnapshotAt(this.historyIndex);if(t&&m(t,e))return;let i=h(e),r=this.getCapacity();this.historyIndex<this.historySize-1&&(this.historySize=this.historyIndex+1);let n=this.historyIndex+1;n<r?(this.history[this.toPhysicalIndex(n)]=i,this.historySize=Math.max(this.historySize,n+1),this.historyIndex=n):(this.historyHead=(this.historyHead+1)%r,this.history[this.toPhysicalIndex(r-1)]=i,this.historySize=r,this.historyIndex=r-1)}get canUndo(){return this.enableHistory?this.historyIndex>0:!1}get canRedo(){return this.enableHistory?this.historyIndex<this.historySize-1:!1}undo(){return this.canUndo?(this.historyIndex--,h(this.getSnapshotAt(this.historyIndex))):null}redo(){return this.canRedo?(this.historyIndex++,h(this.getSnapshotAt(this.historyIndex))):null}reset(e){this.history=[],this.historyIndex=-1,this.historySize=0,this.historyHead=0,this.saveSnapshot(e)}getMetadata(){return{enabled:this.enableHistory,canUndo:this.canUndo,canRedo:this.canRedo,historyIndex:this.historyIndex,historySize:this.historySize}}getCapacity(){return Math.max(1,this.maxHistory)}toPhysicalIndex(e){return(this.historyHead+e)%this.getCapacity()}getSnapshotAt(e){if(!(e<0||e>=this.historySize))return this.history[this.toPhysicalIndex(e)]}};var O=class{constructor(e){this.store=e}pushItem(e,t){let i=p(this.store.getState().values,e)||[];this.store.setFieldWithMeta(e,[...i,t],{origin:"array",operation:"push"}),this.store.internalSaveSnapshot()}prependItem(e,t){let i=p(this.store.getState().values,e)||[];this.store.setFieldWithMeta(e,[t,...i],{origin:"array",operation:"prepend"}),this.store.internalSaveSnapshot()}insertItem(e,t,i){let r=[...p(this.store.getState().values,e)||[]];r.splice(t,0,i),this.store.setFieldWithMeta(e,r,{origin:"array",operation:"insert",index:t}),this.store.internalSaveSnapshot()}removeItem(e,t){let i=this.store.getState(),r=p(i.values,e);if(!Array.isArray(r))return;let n=[...r];this.store.unregisterPrefix&&this.store.unregisterPrefix(`${e}.${t}.`);let o=r.filter((c,u)=>u!==t),a=y(i.values,e,o),l=this.store.updateDirtyForPath(e,a,this.store.getConfig().initialValues),d=E(i,e,c=>c===t?null:c>t?c-1:c);this.store.internalUpdateState({values:a,errors:d.errors,touched:d.touched,isValidating:d.isValidating,isDirty:l}),this.store.emitFieldChange({path:e,previousValue:n,nextValue:o,values:this.store.getState().values,state:this.store.getState(),meta:{origin:"array",operation:"remove",index:t}}),this.store.internalSaveSnapshot(),this.revalidate(e)}swapItems(e,t,i){let r=this.store.getState(),n=[...p(r.values,e)||[]],o=[...n];[n[t],n[i]]=[n[i],n[t]];let a=y(r.values,e,n),l=this.store.updateDirtyForPath(e,a,this.store.getConfig().initialValues),d=E(r,e,c=>c===t?i:c===i?t:c);this.store.internalUpdateState({values:a,errors:d.errors,touched:d.touched,isValidating:d.isValidating,isDirty:l}),this.store.emitFieldChange({path:e,previousValue:o,nextValue:n,values:this.store.getState().values,state:this.store.getState(),meta:{origin:"array",operation:"swap",from:t,to:i}}),this.store.internalSaveSnapshot(),this.revalidate(e)}moveItem(e,t,i){let r=this.store.getState(),n=[...p(r.values,e)||[]],o=[...n],[a]=n.splice(t,1);n.splice(i,0,a);let l=y(r.values,e,n),d=this.store.updateDirtyForPath(e,l,this.store.getConfig().initialValues),c=E(r,e,u=>u===t?i:t<i&&u>t&&u<=i?u-1:t>i&&u>=i&&u<t?u+1:u);this.store.internalUpdateState({values:l,errors:c.errors,touched:c.touched,isValidating:c.isValidating,isDirty:d}),this.store.emitFieldChange({path:e,previousValue:o,nextValue:n,values:this.store.getState().values,state:this.store.getState(),meta:{origin:"array",operation:"move",from:t,to:i}}),this.store.internalSaveSnapshot(),this.revalidate(e)}revalidate(e){this.store.triggerValidation([e])}};var H=class{constructor(e,t,i,r){this.getState=e;this.getInitialValues=t;this.getScopeFields=i;this.isPathDirty=r}getStepStatus(e){let t=this.getScopeFields(e),i=this.getState(),r=t.some(a=>!!i.errors[a]),n=t.some(a=>this.isPathDirty(a)),o=this.getStepErrors(e);return{hasErrors:r,isDirty:n,errors:o}}getStepErrors(e){let t=this.getScopeFields(e),i=this.getState(),r={};for(let n of t){let o=i.errors[n];o&&(r[n]=o)}return r}};var U=class{constructor(e,t,i,r){this.dependencyManager=e;this.getState=t;this.getConfig=i;this.isPathDirty=r}requiredValuesRef=null;isHidden(e){return this.dependencyManager.isHidden(e)}isRequired(e){let t=this.getState().values;return this.requiredValuesRef!==t&&(this.requiredValuesRef=t),this.dependencyManager.isRequired(e,t)}isFieldDirty(e){return this.isPathDirty(e)}isFieldValidating(e){return!!this.getState().isValidating[e]}};var j=class{constructor(e,t){this.getState=e;this.internalUpdateState=t}setError(e,t){let i={...this.getState().errors,[e]:t};t||delete i[e],this.internalUpdateState({errors:i})}setErrors(e){this.internalUpdateState({errors:{...this.getState().errors,...e}})}setServerErrors(e){let t={};for(let[i,r]of Object.entries(e))t[i]=Array.isArray(r)?r[0]:r;this.setErrors(t)}};var z=class{capabilities=new Map;register(e,t){this.capabilities.set(e,t)}get(e){let t=this.capabilities.get(e);if(!t)throw new Error(`Capability "${String(e)}" is not registered`);return t}has(e){return this.capabilities.has(e)}clear(){this.capabilities.clear()}};function Y(s){let{store:e,dependencyManager:t,dirtyManager:i}=s,r=new z,n={getState:()=>e.getState(),internalUpdateState:a=>e.internalUpdateState(a),setError:(a,l)=>e.setError(a,l),validate:a=>e.validate(a),getFieldConfig:a=>e.getFieldConfig(a),getScopeFields:a=>e.getScopeFields(a),config:e.config,getRequiredErrors:a=>e.getRequiredErrors(a),getHiddenFields:()=>e.getHiddenFields(),emitBeforeValidate:a=>e.emitBeforeValidate(a),emitAfterValidate:a=>e.emitAfterValidate(a)},o={getState:()=>e.getState(),internalUpdateState:(a,l)=>e.internalUpdateState(a,l),internalSaveSnapshot:()=>e.internalSaveSnapshot(),batchStateUpdates:a=>e.batchStateUpdates(a),config:e.config,getTransformEntries:()=>e.getTransformEntries(),updateDependencies:(a,l)=>e.updateDependencies(a,l),isFieldHidden:a=>e.isFieldHidden(a),evaluateAllDependencies:a=>e.evaluateAllDependencies(a),getHiddenFields:()=>e.getHiddenFields(),clearFieldValidation:a=>e.clearFieldValidation(a),triggerValidation:(a,l)=>e.triggerValidation(a,l),handleFieldAsyncValidation:(a,l)=>e.handleFieldAsyncValidation(a,l),cancelAllValidations:()=>e.cancelAllValidations(),validateNow:a=>e.validateNow(a),hasValidationsInProgress:a=>e.hasValidationsInProgress(a),updateDirtyForPath:(a,l,d)=>e.updateDirtyForPath(a,l,d),rebuildDirtyState:(a,l)=>e.rebuildDirtyState(a,l),clearDirtyState:()=>e.clearDirtyState(),buildDirtyValues:a=>e.buildDirtyValues(a),resetHistory:a=>e.resetHistory(a),emitFieldChange:a=>e.emitFieldChange(a),emitBeforeSubmit:a=>e.emitBeforeSubmit(a),emitAfterSubmit:a=>e.emitAfterSubmit(a),emitOperationalError:a=>e.emitOperationalError(a)};return r.register("validation",new R(n)),r.register("lifecycle",new I(o)),r.register("history",new q(!!e.config.enableHistory,e.config.historyLimit??15)),r.register("arrays",new O(e)),r.register("scope",new H(()=>e.getState(),()=>e.config.initialValues,a=>e.getScopeFields(a),a=>i.isPathDirty(a))),r.register("query",new U(t,()=>e.getState(),()=>e.config,a=>i.isPathDirty(a))),r.register("error",new j(()=>e.getState(),a=>e.internalUpdateState(a))),r}function Q(s){let{storeId:e,storeInstance:t,config:i,getState:r,getConfig:n,getValues:o,getDirtyValues:a,applyPersistedValues:l}=s,d=new w(i.persist,o,a,l),c=[...i.plugins],u=X(i.devTools);u&&c.push(u);let g=new D(c,()=>({storeId:e,getState:()=>r(),getConfig:()=>n()})),f=new k(e,t,d,g);return f.initialize(),f}function Z(s){let{config:e,dependencyManager:t,computedManager:i}=s,r=h(e.initialValues);return e.fields&&Object.entries(e.fields).forEach(([o,a])=>{t.register(o,a,r)}),{values:i.apply(r),errors:{},touched:{},isValidating:{},persist:{isSaving:!1,isRestoring:!1,error:null},isValid:!0,isSubmitting:!1,isDirty:!1}}var b=class{state;subscriptions;effects;capabilities;config;storeId;dependencyManager;computedManager;dirtyManager;scopeFieldsIndex=null;computedEntriesCache=null;transformEntriesCache=null;batchDepth=0;batchedState=null;batchedChangedPaths=null;batchedValuesChanged=!1;invalidateFieldIndexes(){this.scopeFieldsIndex=null,this.computedEntriesCache=null,this.transformEntriesCache=null,this.computedManager.invalidateReverseDeps()}registerCachedFieldIndexes(e,t){if(this.scopeFieldsIndex&&t.scope){let i=this.scopeFieldsIndex.get(t.scope)??[];i.includes(e)||(i.push(e),this.scopeFieldsIndex.set(t.scope,i))}this.computedEntriesCache&&t.computed&&this.computedEntriesCache.push({path:e,compute:t.computed,dependsOn:t.computedDependsOn??t.conditional?.dependsOn}),this.transformEntriesCache&&t.transform&&this.transformEntriesCache.push([e,t.transform])}unregisterCachedFieldIndexes(e,t){if(!t){this.invalidateFieldIndexes();return}if(this.scopeFieldsIndex&&t.scope){let i=this.scopeFieldsIndex.get(t.scope);if(i){let r=i.filter(n=>n!==e);r.length>0?this.scopeFieldsIndex.set(t.scope,r):this.scopeFieldsIndex.delete(t.scope)}}this.computedEntriesCache&&t.computed&&(this.computedEntriesCache=this.computedEntriesCache.filter(i=>i.path!==e)),this.transformEntriesCache&&t.transform&&(this.transformEntriesCache=this.transformEntriesCache.filter(([i])=>i!==e))}getCapability(e){return this.capabilities.get(e)}get validation(){return this.getCapability("validation")}get lifecycle(){return this.getCapability("lifecycle")}get history(){return this.getCapability("history")}get arrays(){return this.getCapability("arrays")}get scope(){return this.getCapability("scope")}get query(){return this.getCapability("query")}get error(){return this.getCapability("error")}constructor(e={}){this.config=J(e),this.dependencyManager=new V,this.computedManager=new C(()=>this.getComputedEntries()),this.dirtyManager=new F,this.capabilities=Y({store:this,dependencyManager:this.dependencyManager,dirtyManager:this.dirtyManager}),this.state=Z({config:this.config,dependencyManager:this.dependencyManager,computedManager:this.computedManager}),this.subscriptions=new x(()=>this.state),this.internalSaveSnapshot(),this.storeId=e.storeId||this.config.name||this.config.idFactory({scope:"store",storeName:this.config.name}),this.effects=Q({storeId:this.storeId,storeInstance:this,config:this.config,getState:()=>this.getState(),getConfig:()=>this.getConfig(),getValues:()=>this.state.values,getDirtyValues:()=>this.getDirtyValues(),applyPersistedValues:t=>this.applyPersistedValues(t)})}getConfig(){return this.config}getFieldConfig(e){return this.dependencyManager.getFieldConfig(e)||this.config.fields?.[e]}getScopeFields(e){if(!this.scopeFieldsIndex){let t=new Map;this.dependencyManager.forEachFieldConfig((i,r)=>{if(!i.scope)return;let n=t.get(i.scope)??[];n.push(r),t.set(i.scope,n)}),this.scopeFieldsIndex=t}return this.scopeFieldsIndex.get(e)??[]}getComputedEntries(){if(!this.computedEntriesCache){let e=[];this.dependencyManager.forEachFieldConfig((t,i)=>{t.computed&&e.push({path:i,compute:t.computed,dependsOn:t.computedDependsOn??t.conditional?.dependsOn})}),this.computedEntriesCache=e}return this.computedEntriesCache}getTransformEntries(){if(!this.transformEntriesCache){let e=[];this.dependencyManager.forEachFieldConfig((t,i)=>{t.transform&&e.push([i,t.transform])}),this.transformEntriesCache=e}return this.transformEntriesCache}resolveMask(e){let t=this.getFieldConfig(e)?.mask;if(t)return typeof t=="string"?this.config.masks?.[t]:t}getState(){return this.batchedState??this.state}getFieldState(e){return{value:p(this.state.values,e),error:this.state.errors[e],touched:!!this.state.touched[e],isHidden:this.isHidden(e),isRequired:this.isRequired(e),isDirty:this.isFieldDirty(e),isValidating:this.isFieldValidating(e)}}get isValid(){return this.state.isValid}get isSubmitting(){return this.state.isSubmitting}get isDirty(){return this.state.isDirty}registerField(e,t){this.dependencyManager.register(e,t,this.state.values),this.registerCachedFieldIndexes(e,t),this.dependencyManager.isHidden(e)&&this.subscriptions.notify(this.state,["*"])}unregisterField(e){if(this.config.fields?.[e])return;let t=this.getFieldConfig(e);this.validation.cleanupField(e),this.dependencyManager.unregister(e),this.unregisterCachedFieldIndexes(e,t);let i={...this.state.errors},r={...this.state.touched},n=!1;i[e]&&(delete i[e],n=!0),r[e]&&(delete r[e],n=!0),n&&this.internalUpdateState({errors:i,touched:r})}unregisterPrefix(e){this.validation.cleanupPrefix(e),this.dependencyManager.unregisterPrefix(e).forEach(([i,r])=>{this.unregisterCachedFieldIndexes(i,r)})}isHidden(e){return this.query.isHidden(e)}isRequired(e){return this.query.isRequired(e)}isFieldDirty(e){return this.query.isFieldDirty(e)}isFieldValidating(e){return this.query.isFieldValidating(e)}subscribe(e){return this.subscriptions.subscribe(e)}subscribeSelector(e,t,i){let r=i?.equalityFn??S;return this.subscriptions.subscribeSelector(e,t,i,r)}subscribePath(e,t,i){let r=[...i?.paths??[],e];return this.subscribeSelector(n=>p(n.values,e),t,{...i,paths:r})}watch(e,t){return this.subscribePath(e,t,{equalityFn:m})}setField(e,t){this.setFieldWithMeta(e,t,{origin:"setField"})}setFieldWithMeta(e,t,i={origin:"setField"}){this.lifecycle.updateField(e,t,i)}blurField(e){this.internalSaveSnapshot(),this.state.touched[e]||this.batchStateUpdates(()=>{this.internalUpdateState({touched:{...this.state.touched,[e]:!0}})}),this.validation.trigger([e])}markFieldsTouched(e){if(e.length===0)return;let t={...this.state.touched};e.forEach(i=>{t[i]=!0}),this.internalUpdateState({touched:t})}replaceValues(e){this.lifecycle.replaceValues(e)}hydrate(e){this.lifecycle.hydrateValues(e)}rebase(e){this.lifecycle.rebaseValues(e)}setError(e,t){this.error.setError(e,t)}setErrors(e){this.error.setErrors(e)}setServerErrors(e){this.error.setServerErrors(e)}reset(){this.lifecycle.reset()}transaction(e){return this.batchStateUpdates(e)}async submit(e){return this.lifecycle.submit(e)}registerMask(e,t){this.config.masks={...this.config.masks||{},[e]:t}}getDirtyValues(){return this.dirtyManager.buildDirtyValues(this.state.values)}getPersistMetadata(){return this.state.persist}async restorePersisted(){this.internalUpdateState({persist:{...this.state.persist,isRestoring:!0,error:null}});try{return await this.effects.restorePersisted()}catch(e){return this.internalUpdateState({persist:{...this.state.persist,isRestoring:!1,error:e instanceof Error?e:new Error(String(e))}}),!1}finally{this.internalUpdateState({persist:{...this.state.persist,isRestoring:!1}})}}async forceSave(){this.internalUpdateState({persist:{...this.state.persist,isSaving:!0,error:null}});try{await this.effects.savePersistedNow()}catch(e){this.internalUpdateState({persist:{...this.state.persist,isSaving:!1,error:e instanceof Error?e:new Error(String(e))}});return}this.internalUpdateState({persist:{...this.state.persist,isSaving:!1}})}async clearPersisted(){this.internalUpdateState({persist:{...this.state.persist,error:null}});try{await this.effects.clearPersisted()}catch(e){this.internalUpdateState({persist:{...this.state.persist,error:e instanceof Error?e:new Error(String(e))}})}}pushItem(e,t){this.arrays.pushItem(e,t)}prependItem(e,t){this.arrays.prependItem(e,t)}insertItem(e,t,i){this.arrays.insertItem(e,t,i)}removeItem(e,t){this.arrays.removeItem(e,t)}swapItems(e,t,i){this.arrays.swapItems(e,t,i)}moveItem(e,t,i){this.arrays.moveItem(e,t,i)}get canUndo(){return this.history.canUndo}get canRedo(){return this.history.canRedo}undo(){let e=this.history.undo();if(e){let t=this.dirtyManager.rebuild(e,this.config.initialValues);this.internalUpdateState({values:e,isDirty:t}),this.validation.trigger(void 0,{forceDebounce:!0})}}redo(){let e=this.history.redo();if(e){let t=this.dirtyManager.rebuild(e,this.config.initialValues);this.internalUpdateState({values:e,isDirty:t}),this.validation.trigger(void 0,{forceDebounce:!0})}}getHistoryMetadata(){return this.history.getMetadata()}validate(e){return this.validation.validate(e)}emitBeforeValidate(e){return this.effects.beforeValidate(e)}emitAfterValidate(e){return this.effects.afterValidate(e)}emitBeforeSubmit(e){return this.effects.beforeSubmit(e)}emitAfterSubmit(e){return this.effects.afterSubmit(e)}emitFieldChange(e){this.effects.onFieldChange(e)}emitOperationalError(e){return this.effects.reportOperationalError(e)}hasValidationsInProgress(e){return this.validation.hasValidationsInProgress(e)}triggerValidation(e,t){this.validation.trigger(e,t)}getStepStatus(e){return this.scope.getStepStatus(e)}getStepErrors(e){return this.scope.getStepErrors(e)}updateDependencies(e,t){return this.dependencyManager.updateDependencies(e,t)}isFieldHidden(e){return this.dependencyManager.isHidden(e)}evaluateAllDependencies(e){this.dependencyManager.evaluateAll(e)}getHiddenFields(){return this.dependencyManager.getHiddenFields()}getRequiredErrors(e){return this.dependencyManager.getRequiredErrors(e)}clearFieldValidation(e){this.validation.clear(e)}handleFieldAsyncValidation(e,t){this.validation.handleAsync(e,t)}cancelAllValidations(){this.validation.cancelAll()}validateNow(e){return this.validation.validate(e)}updateDirtyForPath(e,t,i){return this.dirtyManager.updateForPath(e,t,i)}rebuildDirtyState(e,t){return this.dirtyManager.rebuild(e,t)}clearDirtyState(){this.dirtyManager.clear()}buildDirtyValues(e){return this.dirtyManager.buildDirtyValues(e)}batchStateUpdates(e){this.batchDepth+=1;try{return e()}finally{this.batchDepth-=1,this.batchDepth===0&&this.flushBatchedStateUpdates()}}resetHistory(e){this.history.reset(e)}internalUpdateState(e,t){if(this.batchDepth>0){let r=K({currentState:this.batchedState??this.state,partialState:e,changedPaths:t,applyComputedValues:n=>n});if(this.batchedState=r.nextState,this.batchedValuesChanged||=r.valuesChanged,r.changedPaths&&r.changedPaths.length>0){let n=this.batchedChangedPaths??new Set;r.changedPaths.forEach(o=>n.add(o)),this.batchedChangedPaths=n}return}let i=K({currentState:this.state,partialState:e,changedPaths:t,applyComputedValues:r=>this.computedManager.apply(r,t)});this.state=i.nextState,this.subscriptions.notify(this.state,i.changedPaths),this.effects.onStateUpdated(this.state,i.valuesChanged)}internalSaveSnapshot(){this.history.saveSnapshot(this.state.values)}applyPersistedValues(e){let t=h({...this.config.initialValues,...e});this.validation.cancelAll(),this.dependencyManager.evaluateAll(t);let i=this.dirtyManager.rebuild(t,this.config.initialValues);this.internalUpdateState({values:t,errors:{},touched:{},isValidating:{},persist:{...this.state.persist,error:null},isValid:!0,isDirty:i,isSubmitting:!1}),this.internalSaveSnapshot(),this.validation.validate()}cleanup(){this.subscriptions.destroy(),this.validation.cancelAll(),this.capabilities.clear(),this.effects.destroy()}flushBatchedStateUpdates(){if(!this.batchedState)return;let e=this.batchedState,t=this.batchedChangedPaths?Array.from(this.batchedChangedPaths):void 0,i=this.batchedValuesChanged;i&&(e={...e,values:this.computedManager.apply(e.values,t)}),this.batchedState=null,this.batchedChangedPaths=null,this.batchedValuesChanged=!1,this.state=e,this.subscriptions.notify(this.state,t),this.effects.onStateUpdated(this.state,i)}};var ee=new Set(["config","getConfig","getState","subscribe","setField","blurField","replaceValues","hydrate","rebase","setError","setErrors","setServerErrors","validate","reset","transaction","submit","registerMask","getDirtyValues","getPersistMetadata","restorePersisted","forceSave","clearPersisted","cleanup","registerField","unregisterField","isHidden","isRequired","isFieldDirty","isFieldValidating","watch","pushItem","prependItem","insertItem","removeItem","moveItem","swapItems","getHistoryMetadata","undo","redo","getStepStatus","getStepErrors","getFieldState","subscribePath","subscribeSelector","unregisterPrefix","markFieldsTouched","hasValidationsInProgress","resolveMask","getScopeFields"]);function pe(s){return new Proxy(s,{get(e,t){if(typeof t=="string"&&!ee.has(t))return;let i=Reflect.get(e,t,e);return typeof i=="function"?i.bind(e):i},has(e,t){return typeof t=="string"&&ee.has(t)},set(){return!1}})}function ge(s){return typeof s.getFieldState=="function"&&typeof s.subscribePath=="function"&&typeof s.subscribeSelector=="function"&&typeof s.markFieldsTouched=="function"&&typeof s.hasValidationsInProgress=="function"&&typeof s.resolveMask=="function"&&typeof s.getScopeFields=="function"}function fe(s){if(s instanceof b||ge(s))return s;throw new Error("BitForm: o store informado n\xE3o exp\xF5e a API necess\xE1ria para hooks/framework bindings.")}function ye(s={}){return pe(new b(s))}export{h as a,P as b,S as c,m as d,p as e,y as f,re as g,G as h,ne as i,T as j,fe as k,ye as l};
2
- //# sourceMappingURL=chunk-64KSP4TP.js.map