@lehnihon/bit-form 2.2.6 → 2.2.8

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 (177) hide show
  1. package/README.md +80 -24
  2. package/dist/angular/index.cjs +1 -1
  3. package/dist/angular/index.cjs.map +1 -1
  4. package/dist/angular/index.d.cts +20 -20
  5. package/dist/angular/index.d.ts +20 -20
  6. package/dist/angular/index.js +1 -1
  7. package/dist/angular/index.js.map +1 -1
  8. package/dist/array-controller-B5bfXV1W.d.cts +23 -0
  9. package/dist/array-controller-Cx-DMH7Y.d.ts +23 -0
  10. package/dist/bus-B2VEKrPI.d.ts +19 -0
  11. package/dist/bus-ZLQeq4Vr.d.cts +19 -0
  12. package/dist/chunk-5NA2TFPG.js +1 -0
  13. package/dist/chunk-5NA2TFPG.js.map +1 -0
  14. package/dist/chunk-63OJBMKK.js +2 -0
  15. package/dist/chunk-63OJBMKK.js.map +1 -0
  16. package/dist/chunk-BSGJ3T5S.cjs +2 -0
  17. package/dist/chunk-BSGJ3T5S.cjs.map +1 -0
  18. package/dist/chunk-CPP7ELA5.js +2 -0
  19. package/dist/chunk-CPP7ELA5.js.map +1 -0
  20. package/dist/chunk-D7JQWF6V.cjs +2 -0
  21. package/dist/chunk-D7JQWF6V.cjs.map +1 -0
  22. package/dist/chunk-E2NZR44P.js +2 -0
  23. package/dist/chunk-E2NZR44P.js.map +1 -0
  24. package/dist/chunk-EQ55DKX2.js +2 -0
  25. package/dist/chunk-EQ55DKX2.js.map +1 -0
  26. package/dist/chunk-IV32WXCF.cjs +2 -0
  27. package/dist/chunk-IV32WXCF.cjs.map +1 -0
  28. package/dist/chunk-JC4R5WCC.js +2 -0
  29. package/dist/chunk-JC4R5WCC.js.map +1 -0
  30. package/dist/chunk-K5X37E3U.js +2 -0
  31. package/dist/chunk-K5X37E3U.js.map +1 -0
  32. package/dist/chunk-M6WBNHIT.cjs +2 -0
  33. package/dist/chunk-M6WBNHIT.cjs.map +1 -0
  34. package/dist/chunk-MFSQATNZ.cjs +2 -0
  35. package/dist/chunk-MFSQATNZ.cjs.map +1 -0
  36. package/dist/chunk-MFTWAFMG.cjs +2 -0
  37. package/dist/chunk-MFTWAFMG.cjs.map +1 -0
  38. package/dist/chunk-O5UPA33R.js +2 -0
  39. package/dist/chunk-O5UPA33R.js.map +1 -0
  40. package/dist/chunk-P2YWYBWG.cjs +2 -0
  41. package/dist/chunk-P2YWYBWG.cjs.map +1 -0
  42. package/dist/chunk-QKGTVKBU.cjs +2 -0
  43. package/dist/chunk-QKGTVKBU.cjs.map +1 -0
  44. package/dist/chunk-RD73EBSN.js +2 -0
  45. package/dist/chunk-RD73EBSN.js.map +1 -0
  46. package/dist/chunk-T2JRSWQU.cjs +2 -0
  47. package/dist/chunk-T2JRSWQU.cjs.map +1 -0
  48. package/dist/chunk-UQ3DSUWC.js +2 -0
  49. package/dist/chunk-UQ3DSUWC.js.map +1 -0
  50. package/dist/chunk-VZHG372Q.cjs +2 -0
  51. package/dist/chunk-VZHG372Q.cjs.map +1 -0
  52. package/dist/chunk-W2E5UIXT.js +2 -0
  53. package/dist/chunk-W2E5UIXT.js.map +1 -0
  54. package/dist/chunk-W5CLDRRE.cjs +1 -0
  55. package/dist/chunk-W5CLDRRE.cjs.map +1 -0
  56. package/dist/cli/index.cjs +22 -22
  57. package/dist/core/bindings.cjs +2 -0
  58. package/dist/core/bindings.cjs.map +1 -0
  59. package/dist/core/bindings.d.cts +81 -0
  60. package/dist/core/bindings.d.ts +81 -0
  61. package/dist/core/bindings.js +2 -0
  62. package/dist/core/bindings.js.map +1 -0
  63. package/dist/core/status.cjs +2 -0
  64. package/dist/core/status.cjs.map +1 -0
  65. package/dist/core/status.d.cts +44 -0
  66. package/dist/core/status.d.ts +44 -0
  67. package/dist/core/status.js +2 -0
  68. package/dist/core/status.js.map +1 -0
  69. package/dist/core/store.cjs +2 -0
  70. package/dist/core/store.cjs.map +1 -0
  71. package/dist/core/store.d.cts +84 -0
  72. package/dist/core/store.d.ts +84 -0
  73. package/dist/core/store.js +2 -0
  74. package/dist/core/store.js.map +1 -0
  75. package/dist/core/utils.cjs +2 -0
  76. package/dist/core/utils.cjs.map +1 -0
  77. package/dist/core/utils.d.cts +81 -0
  78. package/dist/core/utils.d.ts +81 -0
  79. package/dist/core/utils.js +2 -0
  80. package/dist/core/utils.js.map +1 -0
  81. package/dist/core.cjs +2 -0
  82. package/dist/core.cjs.map +1 -0
  83. package/dist/core.d.cts +14 -0
  84. package/dist/core.d.ts +14 -0
  85. package/dist/core.js +2 -0
  86. package/dist/core.js.map +1 -0
  87. package/dist/devtools/bridge.cjs +1 -1
  88. package/dist/devtools/bridge.cjs.map +1 -1
  89. package/dist/devtools/bridge.d.cts +5 -1
  90. package/dist/devtools/bridge.d.ts +5 -1
  91. package/dist/devtools/bridge.js +1 -1
  92. package/dist/devtools/bridge.js.map +1 -1
  93. package/dist/devtools/index.cjs +18 -18
  94. package/dist/devtools/index.cjs.map +1 -1
  95. package/dist/devtools/index.d.cts +27 -2
  96. package/dist/devtools/index.d.ts +27 -2
  97. package/dist/devtools/index.js +18 -18
  98. package/dist/devtools/index.js.map +1 -1
  99. package/dist/devtools/protocol.cjs +2 -0
  100. package/dist/devtools/protocol.cjs.map +1 -0
  101. package/dist/devtools/protocol.d.cts +54 -0
  102. package/dist/devtools/protocol.d.ts +54 -0
  103. package/dist/devtools/protocol.js +2 -0
  104. package/dist/devtools/protocol.js.map +1 -0
  105. package/dist/field-binding-B_OX3bjp.d.cts +25 -0
  106. package/dist/field-binding-MX6jVQbT.d.ts +25 -0
  107. package/dist/index.cjs +1 -1
  108. package/dist/index.cjs.map +1 -1
  109. package/dist/index.d.cts +9 -193
  110. package/dist/index.d.ts +9 -193
  111. package/dist/index.js +1 -1
  112. package/dist/meta-types-Bzmm21TP.d.cts +18 -0
  113. package/dist/meta-types-Bzmm21TP.d.ts +18 -0
  114. package/dist/react/index.cjs +1 -1
  115. package/dist/react/index.cjs.map +1 -1
  116. package/dist/react/index.d.cts +10 -7
  117. package/dist/react/index.d.ts +10 -7
  118. package/dist/react/index.js +1 -1
  119. package/dist/react/index.js.map +1 -1
  120. package/dist/react-native/index.cjs +1 -1
  121. package/dist/react-native/index.cjs.map +1 -1
  122. package/dist/react-native/index.d.cts +8 -5
  123. package/dist/react-native/index.d.ts +8 -5
  124. package/dist/react-native/index.js +1 -1
  125. package/dist/react-native/index.js.map +1 -1
  126. package/dist/resolvers/index.cjs +1 -1
  127. package/dist/resolvers/index.cjs.map +1 -1
  128. package/dist/resolvers/index.d.cts +2 -1
  129. package/dist/resolvers/index.d.ts +2 -1
  130. package/dist/resolvers/index.js +1 -1
  131. package/dist/resolvers/joi.d.cts +2 -1
  132. package/dist/resolvers/joi.d.ts +2 -1
  133. package/dist/resolvers/yup.d.cts +2 -1
  134. package/dist/resolvers/yup.d.ts +2 -1
  135. package/dist/resolvers/zod.d.cts +2 -1
  136. package/dist/resolvers/zod.d.ts +2 -1
  137. package/dist/store-api-types-D-ZHxzRy.d.cts +161 -0
  138. package/dist/store-api-types-DPi30jQF.d.ts +161 -0
  139. package/dist/{bus-B4zZmB9C.d.ts → types-CG5nYeRk.d.ts} +140 -41
  140. package/dist/{bus-BeAeZwWu.d.cts → types-D6LhF5GC.d.cts} +140 -41
  141. package/dist/{upload-EXnJLq8k.d.cts → upload-C2mpfhp1.d.cts} +1 -1
  142. package/dist/{upload-EXnJLq8k.d.ts → upload-C2mpfhp1.d.ts} +1 -1
  143. package/dist/{use-bit-persist-Dk3fUrds.d.ts → use-bit-persist-BTwy8kvA.d.ts} +14 -14
  144. package/dist/{use-bit-persist-D_gimC9A.d.cts → use-bit-persist-C2LHNTVv.d.cts} +14 -14
  145. package/dist/utils.cjs +2 -0
  146. package/dist/utils.cjs.map +1 -0
  147. package/dist/utils.d.cts +6 -0
  148. package/dist/utils.d.ts +6 -0
  149. package/dist/utils.js +2 -0
  150. package/dist/utils.js.map +1 -0
  151. package/dist/vue/index.cjs +1 -1
  152. package/dist/vue/index.cjs.map +1 -1
  153. package/dist/vue/index.d.cts +17 -18
  154. package/dist/vue/index.d.ts +17 -18
  155. package/dist/vue/index.js +1 -1
  156. package/dist/vue/index.js.map +1 -1
  157. package/package.json +48 -17
  158. package/dist/chunk-2CVKNPWX.js +0 -2
  159. package/dist/chunk-2CVKNPWX.js.map +0 -1
  160. package/dist/chunk-3EDD3V43.cjs +0 -2
  161. package/dist/chunk-3EDD3V43.cjs.map +0 -1
  162. package/dist/chunk-PX6WKENM.js +0 -2
  163. package/dist/chunk-PX6WKENM.js.map +0 -1
  164. package/dist/chunk-QWH2NBVB.js +0 -2
  165. package/dist/chunk-QWH2NBVB.js.map +0 -1
  166. package/dist/chunk-T3FR7D5V.js +0 -2
  167. package/dist/chunk-T3FR7D5V.js.map +0 -1
  168. package/dist/chunk-VQ7MK5VB.cjs +0 -2
  169. package/dist/chunk-VQ7MK5VB.cjs.map +0 -1
  170. package/dist/chunk-Y2ONHDRE.cjs +0 -2
  171. package/dist/chunk-Y2ONHDRE.cjs.map +0 -1
  172. package/dist/chunk-YCSWULEN.cjs +0 -2
  173. package/dist/chunk-YCSWULEN.cjs.map +0 -1
  174. package/dist/field-binding-BXw0Ku2c.d.cts +0 -12
  175. package/dist/field-binding-BXw0Ku2c.d.ts +0 -12
  176. package/dist/public-types-Cd9ai20P.d.cts +0 -97
  177. package/dist/public-types-DdZxD6Op.d.ts +0 -97
@@ -0,0 +1,161 @@
1
+ import { G as BitState, j as BitConfig, N as ValidatorFn, o as BitFieldDefinition, M as DevToolsOptions, O as BitPersistResolvedConfig, P as BitIdFactory, A as BitPlugin, F as BitScheduler, r as BitFormGlobal, u as BitPath, p as BitFieldState, v as BitPathValue, x as BitPersistMetadata, S as ScopeStatus, L as DeepPartial, k as BitErrors, H as BitSubmitResult, c as BitArrayPath, b as BitArrayItem } from './types-CG5nYeRk.js';
2
+ import { B as BitMask } from './types-D8DgIUhJ.js';
3
+ import { a as BitHistoryMetadata, B as BitFormMeta, b as BitValidationOptions } from './meta-types-Bzmm21TP.js';
4
+
5
+ type BitSelector<T extends object, TSlice> = (state: Readonly<BitState<T>>) => TSlice;
6
+ type BitEqualityFn<TValue> = (previous: TValue, next: TValue) => boolean;
7
+ interface BitScopedSelectorSubscriptionOptions<TValue> {
8
+ mode?: "scoped";
9
+ paths: string[];
10
+ equalityFn?: BitEqualityFn<TValue>;
11
+ emitImmediately?: boolean;
12
+ }
13
+ interface BitTrackedSelectorSubscriptionOptions<TValue> {
14
+ mode: "tracked";
15
+ equalityFn?: BitEqualityFn<TValue>;
16
+ emitImmediately?: boolean;
17
+ }
18
+ type BitSelectorSubscriptionOptions<TValue> = BitScopedSelectorSubscriptionOptions<TValue> | BitTrackedSelectorSubscriptionOptions<TValue>;
19
+
20
+ interface BitValidationTriggerOptions {
21
+ forceDebounce?: boolean;
22
+ }
23
+
24
+ interface BitStoreIdentityApi<T extends object = Record<string, unknown>> {
25
+ readonly storeId: string;
26
+ readonly config: Readonly<BitFrameworkConfig<T>>;
27
+ }
28
+ interface BitFrameworkConfig<T extends object = Record<string, unknown>> extends BitConfig<T> {
29
+ initialValues: T;
30
+ resolver?: ValidatorFn<T>;
31
+ validationDelay: number;
32
+ history: {
33
+ enabled: boolean;
34
+ limit: number;
35
+ };
36
+ masks?: Record<string, BitMask>;
37
+ fields?: Record<string, BitFieldDefinition<T>>;
38
+ devTools?: boolean | DevToolsOptions;
39
+ persist: BitPersistResolvedConfig<T>;
40
+ idFactory: BitIdFactory;
41
+ plugins: BitPlugin<T>[];
42
+ scheduler?: BitScheduler;
43
+ subscriptionCacheSize?: number;
44
+ bus?: BitFormGlobal;
45
+ onUnhandledError: (error: unknown, source: "submit" | "validation" | "persist") => void;
46
+ }
47
+ interface BitFormReadApi<T extends object = Record<string, unknown>> {
48
+ getState(): Readonly<BitState<T>>;
49
+ getFieldConfig(path: string): BitFieldDefinition<T> | undefined;
50
+ getFieldState<P extends BitPath<T>>(path: P): Readonly<BitFieldState<T, BitPathValue<T, P>>>;
51
+ isHidden<P extends BitPath<T>>(path: P): boolean;
52
+ isRequired<P extends BitPath<T>>(path: P): boolean;
53
+ isFieldDirty(path: string): boolean;
54
+ isFieldValidating(path: string): boolean;
55
+ getDirtyValues(): Partial<T>;
56
+ getPersistMetadata(): BitPersistMetadata;
57
+ getHistoryMetadata(): BitHistoryMetadata;
58
+ getScopeStatus(scopeName: string): ScopeStatus;
59
+ getScopeErrors(scopeName: string): Record<string, string>;
60
+ getScopeFields(scopeName: string): string[];
61
+ }
62
+ interface BitFormObserveApi<T extends object = Record<string, unknown>> {
63
+ subscribe(listener: () => void): () => void;
64
+ subscribePersistMeta(listener: (meta: BitPersistMetadata) => void): () => void;
65
+ subscribeHistoryMeta(listener: (meta: BitHistoryMetadata) => void): () => void;
66
+ subscribeScopeStatus(scopeName: string, listener: (status: ScopeStatus) => void): () => void;
67
+ }
68
+ interface BitFormWriteApi<T extends object = Record<string, unknown>> {
69
+ setField<P extends BitPath<T>>(path: P, value: BitPathValue<T, P>): void;
70
+ blurField<P extends BitPath<T>>(path: P): void;
71
+ markFieldsTouched(paths: string[]): void;
72
+ setValues(values: T | DeepPartial<T>, options?: {
73
+ partial?: boolean;
74
+ rebase?: boolean;
75
+ }): void;
76
+ setError(path: string, message: string | undefined): void;
77
+ setErrors(errors: BitErrors<T>): void;
78
+ setServerErrors(serverErrors: Record<string, string[] | string>): void;
79
+ validate(options?: BitValidationOptions): Promise<boolean>;
80
+ triggerValidation(scopeFields?: string[], options?: BitValidationTriggerOptions): void;
81
+ reset(): void;
82
+ transaction<TResult>(callback: () => TResult): TResult;
83
+ submit(onSuccess: (values: T, dirtyValues?: Partial<T>) => void | Promise<void>): Promise<BitSubmitResult>;
84
+ }
85
+ interface BitStoreLifecycleApi {
86
+ cleanup(): void;
87
+ }
88
+ interface BitStorePersistFeatureApi {
89
+ getPersistMetadata(): BitPersistMetadata;
90
+ restorePersisted(): Promise<boolean>;
91
+ forceSave(): Promise<void>;
92
+ clearPersisted(): Promise<void>;
93
+ }
94
+ interface BitStoreRegistrationFeatureApi<T extends object = Record<string, unknown>> {
95
+ registerField(path: string, config: BitFieldDefinition<T>): void;
96
+ unregisterField(path: string): void;
97
+ unregisterPrefix(prefix: string): void;
98
+ }
99
+ interface BitStoreArrayFeatureApi<T extends object = Record<string, unknown>> {
100
+ pushItem<P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>): void;
101
+ prependItem<P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>): void;
102
+ insertItem<P extends BitArrayPath<T>>(path: P, index: number, value: BitArrayItem<BitPathValue<T, P>>): void;
103
+ removeItem<P extends BitArrayPath<T>>(path: P, index: number): void;
104
+ moveItem<P extends BitArrayPath<T>>(path: P, from: number, to: number): void;
105
+ swapItems<P extends BitArrayPath<T>>(path: P, indexA: number, indexB: number): void;
106
+ replaceItems<P extends BitArrayPath<T>>(path: P, items: BitArrayItem<BitPathValue<T, P>>[]): void;
107
+ clearItems<P extends BitArrayPath<T>>(path: P): void;
108
+ }
109
+ interface BitStoreHistoryFeatureApi {
110
+ readonly canUndo: boolean;
111
+ readonly canRedo: boolean;
112
+ undo(): void;
113
+ redo(): void;
114
+ }
115
+ interface BitStoreStateFlagsApi {
116
+ readonly isValid: boolean;
117
+ readonly isSubmitting: boolean;
118
+ readonly isDirty: boolean;
119
+ }
120
+ interface BitFormMetaBindingApi<T extends object = Record<string, unknown>> {
121
+ getState(): Readonly<BitState<T>>;
122
+ subscribeFormMeta(listener: (meta: BitFormMeta) => void): () => void;
123
+ }
124
+ interface BitStoreSelectorBindingApi<T extends object = Record<string, unknown>> {
125
+ subscribe(listener: () => void): () => void;
126
+ subscribePath<P extends BitPath<T>>(path: P, listener: (value: BitPathValue<T, P>) => void, options?: BitScopedSelectorSubscriptionOptions<BitPathValue<T, P>>): () => void;
127
+ subscribeSelector<TSlice>(selector: BitSelector<T, TSlice>, listener: (slice: TSlice) => void, options: BitSelectorSubscriptionOptions<TSlice>): () => void;
128
+ }
129
+ interface BitFieldBindingApi<T extends object = Record<string, unknown>> {
130
+ getFieldState<P extends BitPath<T>>(path: P): Readonly<BitFieldState<T, BitPathValue<T, P>>>;
131
+ subscribeFieldState<P extends BitPath<T>>(path: P, listener: (state: Readonly<BitFieldState<T, BitPathValue<T, P>>>) => void): () => void;
132
+ setField<P extends BitPath<T>>(path: P, value: BitPathValue<T, P>): void;
133
+ blurField<P extends BitPath<T>>(path: P): void;
134
+ resolveMask(path: string): BitMask | undefined;
135
+ unregisterField(path: string): void;
136
+ }
137
+ interface BitStoreFeatureApi<T extends object = Record<string, unknown>> extends BitStoreLifecycleApi, BitStorePersistFeatureApi, BitStoreRegistrationFeatureApi<T>, BitStoreArrayFeatureApi<T>, BitStoreHistoryFeatureApi {
138
+ hasValidationsInProgress(scopeFields?: string[]): boolean;
139
+ resolveMask(path: string): BitMask | undefined;
140
+ createArrayItemId(path: string, index?: number): string;
141
+ }
142
+ interface BitStoreReadSliceApi<T extends object = Record<string, unknown>> extends BitStoreIdentityApi<T>, BitStoreStateFlagsApi, BitFormReadApi<T> {
143
+ }
144
+ interface BitStoreObserveSliceApi<T extends object = Record<string, unknown>> extends BitFormObserveApi<T>, BitFormMetaBindingApi<T>, BitStoreSelectorBindingApi<T>, Pick<BitFieldBindingApi<T>, "subscribeFieldState"> {
145
+ }
146
+ interface BitStoreWriteSliceApi<T extends object = Record<string, unknown>> extends BitFormWriteApi<T> {
147
+ }
148
+ interface BitStoreNamespacesApi<T extends object = Record<string, unknown>> {
149
+ readonly read: BitStoreReadSliceApi<T>;
150
+ readonly observe: BitStoreObserveSliceApi<T>;
151
+ readonly write: BitStoreWriteSliceApi<T>;
152
+ readonly feature: BitStoreFeatureApi<T>;
153
+ }
154
+ interface BitStoreApi<T extends object = Record<string, unknown>> extends BitStoreNamespacesApi<T> {
155
+ }
156
+ interface BitStoreHooksApi<T extends object = Record<string, unknown>> extends BitStoreApi<T> {
157
+ }
158
+ interface BitFrameworkStoreApi<T extends object = Record<string, unknown>> extends BitStoreApi<T> {
159
+ }
160
+
161
+ export type { BitEqualityFn as B, BitFrameworkConfig as a, BitFrameworkStoreApi as b, BitSelector as c, BitSelectorSubscriptionOptions as d, BitStoreApi as e, BitStoreHooksApi as f, BitStoreFeatureApi as g, BitStoreObserveSliceApi as h, BitStoreReadSliceApi as i, BitStoreWriteSliceApi as j };
@@ -1,12 +1,65 @@
1
1
  import { B as BitMask, a as BitMaskName } from './types-D8DgIUhJ.js';
2
2
 
3
+ interface BitBusStorePort<T extends object = object> {
4
+ getState: () => Readonly<BitState<T>>;
5
+ getHistoryMetadata: () => {
6
+ canUndo: boolean;
7
+ canRedo: boolean;
8
+ historySize: number;
9
+ historyIndex: number;
10
+ };
11
+ undo: () => void;
12
+ redo: () => void;
13
+ reset: () => void;
14
+ }
15
+ type BitBusListener<T extends object = object> = (storeId: string, newState: BitState<T>) => void;
16
+ interface BitFormGlobal {
17
+ stores: Record<string, BitBusStorePort<object>>;
18
+ listeners: Set<BitBusListener>;
19
+ dispatch: (storeId: string, state: BitState<object>) => void;
20
+ subscribe: (fn: BitBusListener) => () => void;
21
+ }
22
+ /** Alias for {@link BitFormGlobal}. Prefer this name in user-facing APIs. */
23
+ type BitBus = BitFormGlobal;
24
+
25
+ /**
26
+ * Pluggable scheduler used for validation debounce.
27
+ * Replace the default (setTimeout-based) with a framework-aware scheduler
28
+ * to integrate with React's concurrent mode, Vue's nextTick, etc.
29
+ *
30
+ * @example
31
+ * // React concurrent mode integration:
32
+ * const scheduler: BitScheduler = {
33
+ * schedule: (fn, delay) => {
34
+ * const id = setTimeout(() => startTransition(fn), delay);
35
+ * return () => clearTimeout(id);
36
+ * },
37
+ * };
38
+ */
39
+ interface BitScheduler {
40
+ /**
41
+ * Schedule `fn` to run after `delayMs` milliseconds.
42
+ * Must return a cleanup function that cancels the scheduled call.
43
+ */
44
+ schedule(fn: () => void, delayMs: number): () => void;
45
+ }
3
46
  type DeepPartial<T> = T extends object ? {
4
47
  [P in keyof T]?: DeepPartial<T[P]>;
5
48
  } : T;
6
49
  type BitErrors<T extends object> = Partial<Record<BitPath<T>, string | undefined>>;
7
50
  type BitTouched<T extends object> = Partial<Record<BitPath<T>, boolean | undefined>>;
8
- type BitComputedFn<T> = (values: T) => any;
9
- type BitTransformFn<T> = (value: any, allValues: T) => any;
51
+ type BitBivariantFn<TArgs extends unknown[], TResult> = {
52
+ bivarianceHack(...args: TArgs): TResult;
53
+ }["bivarianceHack"];
54
+ type BitComputedFn<T> = (values: T) => unknown;
55
+ type BitNormalizeFn<T> = BitBivariantFn<[
56
+ value: unknown,
57
+ allValues: T
58
+ ], unknown>;
59
+ type BitTransformFn<T> = BitBivariantFn<[
60
+ value: unknown,
61
+ allValues: T
62
+ ], unknown>;
10
63
  interface BitPersistMetadata {
11
64
  isSaving: boolean;
12
65
  isRestoring: boolean;
@@ -29,7 +82,7 @@ interface BitState<T extends object> {
29
82
  isSubmitting: boolean;
30
83
  isDirty: boolean;
31
84
  }
32
- interface BitFieldState<T extends object = any, TValue = unknown> {
85
+ interface BitFieldState<T extends object = Record<string, unknown>, TValue = unknown> {
33
86
  value: TValue;
34
87
  error: string | undefined;
35
88
  touched: boolean;
@@ -42,7 +95,7 @@ type ValidatorFn<T extends object> = (values: T, options?: {
42
95
  scopeFields?: string[];
43
96
  }) => Promise<BitErrors<T>> | BitErrors<T>;
44
97
  /** Conditional logic: visibility and dynamic required. */
45
- interface BitFieldConditional<T extends object = any> {
98
+ interface BitFieldConditional<T extends object = Record<string, unknown>> {
46
99
  dependsOn?: string[];
47
100
  showIf?: (values: T) => boolean;
48
101
  requiredIf?: (values: T) => boolean;
@@ -50,23 +103,42 @@ interface BitFieldConditional<T extends object = any> {
50
103
  requiredMessage?: string;
51
104
  }
52
105
  /** Field-level validation: async validation only. */
53
- interface BitFieldValidation<T extends object = any> {
54
- asyncValidate?: (value: any, values: T) => Promise<string | null | undefined>;
106
+ interface BitFieldValidation<T extends object = Record<string, unknown>> {
107
+ /**
108
+ * Breaking change: async validation now defaults to `blur` instead of eager `change`.
109
+ * `validate()`/submit still execute async validators for the targeted fields.
110
+ */
111
+ asyncValidateOn?: "change" | "blur";
112
+ asyncValidate?: BitBivariantFn<[
113
+ value: unknown,
114
+ values: T
115
+ ], Promise<string | null | undefined>>;
55
116
  asyncValidateDelay?: number;
56
117
  }
57
- /** Full field definition: conditional, validation, transform, computed, mask, scope. */
58
- interface BitFieldDefinition<T extends object = any> {
118
+ interface BitFieldDefinitionBase<T extends object = Record<string, unknown>> {
59
119
  conditional?: BitFieldConditional<T>;
60
120
  validation?: BitFieldValidation<T>;
121
+ normalize?: BitNormalizeFn<T>;
122
+ /**
123
+ * Optional explicit dependencies for normalize re-evaluation.
124
+ * Defaults to the field own path when omitted.
125
+ */
126
+ normalizeDependsOn?: string[];
61
127
  transform?: BitTransformFn<T>;
62
- computed?: BitComputedFn<T>;
63
- /** Explicit dependencies for computed optimization. Falls back to conditional.dependsOn when omitted. */
64
- computedDependsOn?: string[];
65
128
  /** Mask name (built-in or custom registry key) or BitMask instance. */
66
129
  mask?: BitMask | BitMaskName;
67
130
  /** Scope name (e.g. wizard step). */
68
131
  scope?: string;
69
132
  }
133
+ /** Full field definition: conditional, validation, transform, computed, mask, scope. */
134
+ type BitFieldDefinition<T extends object = Record<string, unknown>> = (BitFieldDefinitionBase<T> & {
135
+ computed?: undefined;
136
+ computedDependsOn?: never;
137
+ }) | (BitFieldDefinitionBase<T> & {
138
+ computed: BitComputedFn<T>;
139
+ /** Explicit dependencies are mandatory in v4 for deterministic computed scheduling. */
140
+ computedDependsOn: string[];
141
+ });
70
142
  interface DevToolsOptions {
71
143
  enabled?: boolean;
72
144
  mode?: "local" | "remote";
@@ -74,7 +146,7 @@ interface DevToolsOptions {
74
146
  }
75
147
  type BitPluginHookSource = "beforeValidate" | "afterValidate" | "beforeSubmit" | "afterSubmit" | "onFieldChange" | "setup" | "teardown" | "submit";
76
148
  type BitFieldChangeOrigin = "setField" | "rebase" | "replaceValues" | "hydrate" | "array";
77
- type BitArrayOperation = "push" | "prepend" | "insert" | "remove" | "move" | "swap";
149
+ type BitArrayOperation = "push" | "prepend" | "insert" | "remove" | "move" | "swap" | "replace" | "clear";
78
150
  interface BitFieldChangeMeta {
79
151
  origin: BitFieldChangeOrigin;
80
152
  operation?: BitArrayOperation;
@@ -82,7 +154,7 @@ interface BitFieldChangeMeta {
82
154
  from?: number;
83
155
  to?: number;
84
156
  }
85
- interface BitFieldChangeEvent<T extends object = any> {
157
+ interface BitFieldChangeEvent<T extends object = Record<string, unknown>> {
86
158
  path: string;
87
159
  previousValue: unknown;
88
160
  nextValue: unknown;
@@ -90,13 +162,13 @@ interface BitFieldChangeEvent<T extends object = any> {
90
162
  state: Readonly<BitState<T>>;
91
163
  meta: BitFieldChangeMeta;
92
164
  }
93
- interface BitBeforeValidateEvent<T extends object = any> {
165
+ interface BitBeforeValidateEvent<T extends object = Record<string, unknown>> {
94
166
  values: Readonly<T>;
95
167
  state: Readonly<BitState<T>>;
96
168
  scope?: string;
97
169
  scopeFields?: string[];
98
170
  }
99
- interface BitAfterValidateEvent<T extends object = any> {
171
+ interface BitAfterValidateEvent<T extends object = Record<string, unknown>> {
100
172
  values: Readonly<T>;
101
173
  state: Readonly<BitState<T>>;
102
174
  scope?: string;
@@ -105,12 +177,12 @@ interface BitAfterValidateEvent<T extends object = any> {
105
177
  result: boolean;
106
178
  aborted?: boolean;
107
179
  }
108
- interface BitBeforeSubmitEvent<T extends object = any> {
180
+ interface BitBeforeSubmitEvent<T extends object = Record<string, unknown>> {
109
181
  values: Readonly<T>;
110
182
  dirtyValues: Readonly<Partial<T>>;
111
183
  state: Readonly<BitState<T>>;
112
184
  }
113
- interface BitAfterSubmitEvent<T extends object = any> {
185
+ interface BitAfterSubmitEvent<T extends object = Record<string, unknown>> {
114
186
  values: Readonly<T>;
115
187
  dirtyValues: Readonly<Partial<T>>;
116
188
  state: Readonly<BitState<T>>;
@@ -118,7 +190,7 @@ interface BitAfterSubmitEvent<T extends object = any> {
118
190
  error?: unknown;
119
191
  invalid?: boolean;
120
192
  }
121
- interface BitPluginErrorEvent<T extends object = any> {
193
+ interface BitPluginErrorEvent<T extends object = Record<string, unknown>> {
122
194
  source: BitPluginHookSource;
123
195
  pluginName?: string;
124
196
  error: unknown;
@@ -126,12 +198,12 @@ interface BitPluginErrorEvent<T extends object = any> {
126
198
  values: Readonly<T>;
127
199
  state: Readonly<BitState<T>>;
128
200
  }
129
- interface BitPluginContext<T extends object = any> {
201
+ interface BitPluginContext<T extends object = Record<string, unknown>> {
130
202
  storeId: string;
131
203
  getState: () => Readonly<BitState<T>>;
132
204
  getConfig: () => Readonly<BitConfig<T>>;
133
205
  }
134
- interface BitPluginHooks<T extends object = any> {
206
+ interface BitPluginHooks<T extends object = Record<string, unknown>> {
135
207
  beforeValidate?: (event: BitBeforeValidateEvent<T>, context: BitPluginContext<T>) => BitMaybePromise<void>;
136
208
  afterValidate?: (event: BitAfterValidateEvent<T>, context: BitPluginContext<T>) => BitMaybePromise<void>;
137
209
  beforeSubmit?: (event: BitBeforeSubmitEvent<T>, context: BitPluginContext<T>) => BitMaybePromise<void>;
@@ -139,7 +211,7 @@ interface BitPluginHooks<T extends object = any> {
139
211
  onFieldChange?: (event: BitFieldChangeEvent<T>, context: BitPluginContext<T>) => BitMaybePromise<void>;
140
212
  onError?: (event: BitPluginErrorEvent<T>, context: BitPluginContext<T>) => BitMaybePromise<void>;
141
213
  }
142
- interface BitPlugin<T extends object = any> {
214
+ interface BitPlugin<T extends object = Record<string, unknown>> {
143
215
  name: string;
144
216
  setup?: (context: BitPluginContext<T>) => void | (() => void);
145
217
  hooks?: BitPluginHooks<T>;
@@ -151,7 +223,7 @@ interface BitPersistStorageAdapter {
151
223
  removeItem(key: string): BitMaybePromise<void>;
152
224
  }
153
225
  type BitPersistMode = "values" | "dirtyValues";
154
- interface BitPersistConfig<T extends object = any> {
226
+ interface BitPersistConfig<T extends object = Record<string, unknown>> {
155
227
  enabled?: boolean;
156
228
  key?: string;
157
229
  storage?: BitPersistStorageAdapter;
@@ -162,7 +234,7 @@ interface BitPersistConfig<T extends object = any> {
162
234
  deserialize?: (raw: string) => Partial<T>;
163
235
  onError?: (error: unknown) => void;
164
236
  }
165
- interface BitPersistResolvedConfig<T extends object = any> {
237
+ interface BitPersistResolvedConfig<T extends object = Record<string, unknown>> {
166
238
  enabled: boolean;
167
239
  key: string;
168
240
  storage?: BitPersistStorageAdapter;
@@ -181,13 +253,17 @@ interface BitValidationConfig<T extends object> {
181
253
  /** History config. */
182
254
  interface BitHistoryConfig {
183
255
  enabled?: boolean;
256
+ /**
257
+ * Maximum number of undo/redo steps to retain.
258
+ * @default 50
259
+ */
184
260
  limit?: number;
185
261
  }
186
262
  /**
187
263
  * BitConfig - store configuration.
188
264
  * @see CHANGELOG for migration from features to fields in 2.0.
189
265
  */
190
- interface BitConfig<T extends object = any> {
266
+ interface BitConfig<T extends object = Record<string, unknown>> {
191
267
  /** Core */
192
268
  name?: string;
193
269
  storeId?: string;
@@ -206,14 +282,50 @@ interface BitConfig<T extends object = any> {
206
282
  persist?: BitPersistConfig<T>;
207
283
  /** Plugins de lifecycle (observabilidade) */
208
284
  plugins?: BitPlugin<T>[];
285
+ /**
286
+ * Maximum number of entries for internal subscription path caches.
287
+ * Lower = less memory; higher = fewer cache evictions in large dynamic forms.
288
+ * @default 500
289
+ */
290
+ subscriptionCacheSize?: number;
291
+ /**
292
+ * Pluggable scheduler for validation debounce.
293
+ * Defaults to a `setTimeout`-based scheduler.
294
+ * Inject a framework-aware scheduler (e.g. React `startTransition`) for
295
+ * better integration with concurrent rendering.
296
+ */
297
+ scheduler?: BitScheduler;
298
+ /**
299
+ * Custom bus instance for DevTools/observability. When omitted, the
300
+ * shared browser-global bus (`bitBus`) is used — suitable for most apps.
301
+ * Pass a `createBitBus()` instance when running in SSR/Edge environments
302
+ * where a global singleton is unsafe (e.g. Next.js Edge Runtime).
303
+ */
304
+ bus?: BitFormGlobal;
305
+ /**
306
+ * Handler opcional para erros operacionais não tratados internamente.
307
+ * Se não informado, o runtime usa fallback para `console.error`.
308
+ */
309
+ onUnhandledError?: (error: unknown, source: "submit" | "validation" | "persist") => void;
209
310
  }
210
- /** Return type of BitStore.getStepStatus, used by useBitScope/injectBitScope. */
311
+ type BitSubmitResult = {
312
+ status: "submitted";
313
+ } | {
314
+ status: "invalid";
315
+ } | {
316
+ status: "failed";
317
+ error: unknown;
318
+ } | {
319
+ status: "blocked";
320
+ reason: "isSubmitting" | "validating";
321
+ };
322
+ /** Return type of BitStore.getScopeStatus, used by useBitScope/injectBitScope. */
211
323
  interface ScopeStatus {
212
324
  hasErrors: boolean;
213
325
  isDirty: boolean;
214
326
  errors: Record<string, string>;
215
327
  }
216
- /** Return type of validateStep, used by useBitScope/injectBitScope. */
328
+ /** Return type of scope validation helpers, used by useBitScope/injectBitScope. */
217
329
  interface ValidateScopeResult {
218
330
  valid: boolean;
219
331
  errors: Record<string, string>;
@@ -228,20 +340,7 @@ type BitPath<T, Prefix extends string = ""> = T extends Primitive ? never : T ex
228
340
  [K in keyof T & (string | number)]: T[K] extends Primitive ? Prefix extends "" ? `${K & (string | number)}` : `${Prefix}.${K & (string | number)}` : Prefix extends "" ? `${K & (string | number)}` | `${K & (string | number)}.${BitPath<T[K]>}` : `${Prefix}.${K & (string | number)}` | `${Prefix}.${K & (string | number)}.${BitPath<T[K]>}`;
229
341
  }[keyof T & (string | number)];
230
342
  type BitPathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends `${number}` ? T extends readonly (infer U)[] ? BitPathValue<U, Rest> : never : K extends keyof T ? BitPathValue<T[K], Rest> : never : P extends `${number}` ? T extends readonly (infer U)[] ? U : never : P extends keyof T ? T[P] : never;
231
- type BitArrayPath<T> = BitPath<T> extends infer P ? P extends string ? BitPathValue<T, P> extends readonly any[] ? P : never : never : never;
343
+ type BitArrayPath<T> = BitPath<T> extends infer P ? P extends string ? BitPathValue<T, P> extends readonly unknown[] ? P : never : never : never;
232
344
  type BitArrayItem<A> = A extends readonly (infer U)[] ? U : A extends (infer U)[] ? U : never;
233
345
 
234
- type BitBusListener<T extends object = any> = (storeId: string, newState: BitState<T>) => void;
235
- interface BitFormGlobal {
236
- stores: Record<string, unknown>;
237
- listeners: Set<BitBusListener>;
238
- dispatch: (storeId: string, state: BitState<any>) => void;
239
- subscribe: (fn: BitBusListener) => () => void;
240
- }
241
-
242
- declare global {
243
- var __BIT_FORM__: BitFormGlobal | undefined;
244
- }
245
- declare const bitBus: BitFormGlobal;
246
-
247
- export { type BitPersistMode as A, type BitConfig as B, type BitPersistStorageAdapter as C, type DevToolsOptions as D, type BitPluginContext as E, type BitPluginErrorEvent as F, type BitPluginHooks as G, type BitTouched as H, type BitValidationConfig as I, bitBus as J, type ScopeStatus as S, type ValidatorFn as V, type BitFieldDefinition as a, type BitPersistResolvedConfig as b, type BitIdFactory as c, type BitPlugin as d, type BitState as e, type BitPath as f, type BitPathValue as g, type DeepPartial as h, type BitErrors as i, type BitPersistMetadata as j, type BitArrayPath as k, type BitArrayItem as l, type BitFieldState as m, type ValidateScopeResult as n, type BitComputedFn as o, type BitTransformFn as p, type BitFieldChangeMeta as q, type BitBeforeValidateEvent as r, type BitAfterValidateEvent as s, type BitBeforeSubmitEvent as t, type BitAfterSubmitEvent as u, type BitFieldChangeEvent as v, type BitFieldConditional as w, type BitFieldValidation as x, type BitHistoryConfig as y, type BitPersistConfig as z };
346
+ export type { BitPlugin as A, BitAfterSubmitEvent as B, BitPluginContext as C, BitPluginErrorEvent as D, BitPluginHooks as E, BitScheduler as F, BitState as G, BitSubmitResult as H, BitTouched as I, BitTransformFn as J, BitValidationConfig as K, DeepPartial as L, DevToolsOptions as M, ValidatorFn as N, BitPersistResolvedConfig as O, BitIdFactory as P, ScopeStatus as S, ValidateScopeResult as V, BitAfterValidateEvent as a, BitArrayItem as b, BitArrayPath as c, BitBeforeSubmitEvent as d, BitBeforeValidateEvent as e, BitBus as f, BitBusListener as g, BitBusStorePort as h, BitComputedFn as i, BitConfig as j, BitErrors as k, BitFieldChangeEvent as l, BitFieldChangeMeta as m, BitFieldConditional as n, BitFieldDefinition as o, BitFieldState as p, BitFieldValidation as q, BitFormGlobal as r, BitHistoryConfig as s, BitNormalizeFn as t, BitPath as u, BitPathValue as v, BitPersistConfig as w, BitPersistMetadata as x, BitPersistMode as y, BitPersistStorageAdapter as z };