@lehnihon/bit-form 2.2.6 → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -24
- package/dist/angular/index.cjs +1 -1
- package/dist/angular/index.cjs.map +1 -1
- package/dist/angular/index.d.cts +18 -20
- package/dist/angular/index.d.ts +18 -20
- package/dist/angular/index.js +1 -1
- package/dist/angular/index.js.map +1 -1
- package/dist/array-controller-C1A5VKYd.d.cts +23 -0
- package/dist/array-controller-DtkmcnUr.d.ts +23 -0
- package/dist/{bus-B4zZmB9C.d.ts → bus-DgilLszS.d.ts} +83 -15
- package/dist/{bus-BeAeZwWu.d.cts → bus-rcUiufS7.d.cts} +83 -15
- package/dist/chunk-DIEE6LUO.js +2 -0
- package/dist/chunk-DIEE6LUO.js.map +1 -0
- package/dist/chunk-FUUQB4DV.cjs +2 -0
- package/dist/chunk-FUUQB4DV.cjs.map +1 -0
- package/dist/chunk-IV32WXCF.cjs +2 -0
- package/dist/chunk-IV32WXCF.cjs.map +1 -0
- package/dist/chunk-K5X37E3U.js +2 -0
- package/dist/chunk-K5X37E3U.js.map +1 -0
- package/dist/chunk-KWLLYQOL.cjs +2 -0
- package/dist/chunk-KWLLYQOL.cjs.map +1 -0
- package/dist/chunk-LIYZPSWM.js +2 -0
- package/dist/chunk-LIYZPSWM.js.map +1 -0
- package/dist/chunk-O5UPA33R.js +2 -0
- package/dist/chunk-O5UPA33R.js.map +1 -0
- package/dist/chunk-QAL6J5GQ.cjs +2 -0
- package/dist/chunk-QAL6J5GQ.cjs.map +1 -0
- package/dist/chunk-QKGTVKBU.cjs +2 -0
- package/dist/chunk-QKGTVKBU.cjs.map +1 -0
- package/dist/chunk-SA47B5OP.js +2 -0
- package/dist/chunk-SA47B5OP.js.map +1 -0
- package/dist/cli/index.cjs +22 -22
- package/dist/core.cjs +2 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +122 -0
- package/dist/core.d.ts +122 -0
- package/dist/core.js +2 -0
- package/dist/core.js.map +1 -0
- package/dist/devtools/bridge.cjs +1 -1
- package/dist/devtools/bridge.cjs.map +1 -1
- package/dist/devtools/bridge.d.cts +4 -1
- package/dist/devtools/bridge.d.ts +4 -1
- package/dist/devtools/bridge.js +1 -1
- package/dist/devtools/bridge.js.map +1 -1
- package/dist/devtools/index.cjs +18 -18
- package/dist/devtools/index.cjs.map +1 -1
- package/dist/devtools/index.d.cts +26 -2
- package/dist/devtools/index.d.ts +26 -2
- package/dist/devtools/index.js +18 -18
- package/dist/devtools/index.js.map +1 -1
- package/dist/devtools/protocol.cjs +2 -0
- package/dist/devtools/protocol.cjs.map +1 -0
- package/dist/devtools/protocol.d.cts +54 -0
- package/dist/devtools/protocol.d.ts +54 -0
- package/dist/devtools/protocol.js +2 -0
- package/dist/devtools/protocol.js.map +1 -0
- package/dist/field-binding-Bi1g-D8X.d.ts +25 -0
- package/dist/field-binding-X5TkvfUt.d.cts +25 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -171
- package/dist/index.d.ts +64 -171
- package/dist/index.js +1 -1
- package/dist/mask.d.cts +2 -2
- package/dist/mask.d.ts +2 -2
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +8 -7
- package/dist/react/index.d.ts +8 -7
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-native/index.cjs +1 -1
- package/dist/react-native/index.cjs.map +1 -1
- package/dist/react-native/index.d.cts +7 -6
- package/dist/react-native/index.d.ts +7 -6
- package/dist/react-native/index.js +1 -1
- package/dist/react-native/index.js.map +1 -1
- package/dist/resolvers/index.cjs +1 -1
- package/dist/resolvers/index.cjs.map +1 -1
- package/dist/resolvers/index.d.cts +2 -2
- package/dist/resolvers/index.d.ts +2 -2
- package/dist/resolvers/index.js +1 -1
- package/dist/resolvers/joi.d.cts +2 -2
- package/dist/resolvers/joi.d.ts +2 -2
- package/dist/resolvers/yup.d.cts +2 -2
- package/dist/resolvers/yup.d.ts +2 -2
- package/dist/resolvers/zod.d.cts +2 -2
- package/dist/resolvers/zod.d.ts +2 -2
- package/dist/store-api-types-9ipdute1.d.ts +187 -0
- package/dist/store-api-types-B6_bPoVI.d.cts +187 -0
- package/dist/{types-D8DgIUhJ.d.cts → types-CUXh7PqD.d.cts} +1 -1
- package/dist/{types-D8DgIUhJ.d.ts → types-CUXh7PqD.d.ts} +1 -1
- package/dist/{use-bit-persist-Dk3fUrds.d.ts → use-bit-persist-Bc06fmqZ.d.ts} +12 -14
- package/dist/{use-bit-persist-D_gimC9A.d.cts → use-bit-persist-CIKFwtdM.d.cts} +12 -14
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.cts +15 -18
- package/dist/vue/index.d.ts +15 -18
- package/dist/vue/index.js +1 -1
- package/dist/vue/index.js.map +1 -1
- package/package.json +20 -11
- package/dist/chunk-2CVKNPWX.js +0 -2
- package/dist/chunk-2CVKNPWX.js.map +0 -1
- package/dist/chunk-3EDD3V43.cjs +0 -2
- package/dist/chunk-3EDD3V43.cjs.map +0 -1
- package/dist/chunk-PX6WKENM.js +0 -2
- package/dist/chunk-PX6WKENM.js.map +0 -1
- package/dist/chunk-QWH2NBVB.js +0 -2
- package/dist/chunk-QWH2NBVB.js.map +0 -1
- package/dist/chunk-T3FR7D5V.js +0 -2
- package/dist/chunk-T3FR7D5V.js.map +0 -1
- package/dist/chunk-VQ7MK5VB.cjs +0 -2
- package/dist/chunk-VQ7MK5VB.cjs.map +0 -1
- package/dist/chunk-Y2ONHDRE.cjs +0 -2
- package/dist/chunk-Y2ONHDRE.cjs.map +0 -1
- package/dist/chunk-YCSWULEN.cjs +0 -2
- package/dist/chunk-YCSWULEN.cjs.map +0 -1
- package/dist/field-binding-BXw0Ku2c.d.cts +0 -12
- package/dist/field-binding-BXw0Ku2c.d.ts +0 -12
- package/dist/public-types-Cd9ai20P.d.cts +0 -97
- package/dist/public-types-DdZxD6Op.d.ts +0 -97
package/dist/index.d.cts
CHANGED
|
@@ -1,175 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { g as BitEqualityFn } from './public-types-Cd9ai20P.cjs';
|
|
1
|
+
import { j as BitConfig } from './bus-rcUiufS7.cjs';
|
|
2
|
+
export { s as BitAfterSubmitEvent, t as BitAfterValidateEvent, a as BitArrayItem, B as BitArrayPath, u as BitBeforeSubmitEvent, v as BitBeforeValidateEvent, d as BitBus, w as BitBusListener, x as BitComputedFn, c as BitErrors, y as BitFieldChangeEvent, z as BitFieldChangeMeta, A as BitFieldConditional, h as BitFieldDefinition, g as BitFieldState, C as BitFieldValidation, q as BitFormGlobal, E as BitHistoryConfig, e as BitPath, b as BitPathValue, F as BitPersistConfig, i as BitPersistMetadata, G as BitPersistMode, H as BitPersistStorageAdapter, o as BitPlugin, I as BitPluginContext, J as BitPluginErrorEvent, K as BitPluginHooks, p as BitScheduler, f as BitState, r as BitTouched, L as BitTransformFn, M as BitValidationConfig, D as DeepPartial, l as DevToolsOptions, S as ScopeStatus, V as ValidateScopeResult, k as ValidatorFn, N as bitBus, O as createBitBus } from './bus-rcUiufS7.cjs';
|
|
3
|
+
import { a as BitStoreHooksApi } from './store-api-types-B6_bPoVI.cjs';
|
|
4
|
+
export { B as BitArrayBindingApi, h as BitEqualityFn, g as BitFieldBindingApi, b as BitFormBindingApi, f as BitFormMeta, e as BitFormMetaBindingApi, i as BitFrameworkConfig, c as BitHistoryMetadata, j as BitSelector, k as BitSelectorSubscriptionOptions, l as BitStoreApi, m as BitStoreArrayFeatureApi, n as BitStoreFeatureApi, o as BitStoreHistoryFeatureApi, p as BitStoreObserveApi, q as BitStorePersistFeatureApi, r as BitStoreQueryApi, s as BitStoreRegistrationFeatureApi, t as BitStoreWriteApi, d as BitValidationOptions } from './store-api-types-B6_bPoVI.cjs';
|
|
6
5
|
export { a as BitDeleteUploadFn, B as BitUploadFn, b as BitUploadResult } from './upload-EXnJLq8k.cjs';
|
|
6
|
+
import './types-CUXh7PqD.cjs';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
compute: BitComputedFn<T>;
|
|
11
|
-
dependsOn?: readonly string[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface BitValidationTriggerOptions {
|
|
15
|
-
forceDebounce?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* BitStore
|
|
20
|
-
*
|
|
21
|
-
* The core orchestrator of form state management.
|
|
22
|
-
*
|
|
23
|
-
* This store coordinates multiple managers to provide comprehensive form handling:
|
|
24
|
-
* - Core managers handle essential state and validation
|
|
25
|
-
* - Feature managers provide optional enhancements (history, arrays, scopes)
|
|
26
|
-
* - Query/mutation managers organize domain-specific operations
|
|
27
|
-
*/
|
|
28
|
-
declare class BitStore<T extends object = any> {
|
|
29
|
-
private state;
|
|
30
|
-
private readonly subscriptions;
|
|
31
|
-
private readonly effects;
|
|
32
|
-
private readonly capabilities;
|
|
33
|
-
/** Baseline for dirty tracking. Decoupled from config so that rebaseValues
|
|
34
|
-
* can update it without mutating the user-provided config object. */
|
|
35
|
-
private _initialValues;
|
|
36
|
-
/** Incremented on every registerMask() call so React hooks can track mask
|
|
37
|
-
* configuration changes via useSyncExternalStore without putting masks in
|
|
38
|
-
* BitState and triggering a full re-render of all fields. */
|
|
39
|
-
private _masksVersion;
|
|
40
|
-
config: BitFrameworkConfig<T>;
|
|
41
|
-
readonly storeId: string;
|
|
42
|
-
private readonly dependencyManager;
|
|
43
|
-
private readonly computedManager;
|
|
44
|
-
private readonly dirtyManager;
|
|
45
|
-
private scopeFieldsIndex;
|
|
46
|
-
private computedEntriesCache;
|
|
47
|
-
private transformEntriesCache;
|
|
48
|
-
private batchDepth;
|
|
49
|
-
private batchedState;
|
|
50
|
-
private batchedChangedPaths;
|
|
51
|
-
private batchedValuesChanged;
|
|
52
|
-
private invalidateFieldIndexes;
|
|
53
|
-
private registerCachedFieldIndexes;
|
|
54
|
-
private unregisterCachedFieldIndexes;
|
|
55
|
-
private getCapability;
|
|
56
|
-
private get validation();
|
|
57
|
-
private get lifecycle();
|
|
58
|
-
private get history();
|
|
59
|
-
private get arrays();
|
|
60
|
-
private get scope();
|
|
61
|
-
private get query();
|
|
62
|
-
private get error();
|
|
63
|
-
constructor(config?: BitConfig<T>);
|
|
64
|
-
getConfig(): BitFrameworkConfig<T>;
|
|
65
|
-
getFieldConfig(path: string): BitFieldDefinition<T> | undefined;
|
|
66
|
-
getScopeFields(scopeName: string): string[];
|
|
67
|
-
getComputedEntries(): BitComputedEntry<T>[];
|
|
68
|
-
getTransformEntries(): [string, BitTransformFn<T>][];
|
|
69
|
-
resolveMask(path: string): BitMask | undefined;
|
|
70
|
-
getState(): BitState<T>;
|
|
71
|
-
getFieldState<P extends BitPath<T>>(path: P): BitFieldState<T, BitPathValue<T, P>>;
|
|
72
|
-
get isValid(): boolean;
|
|
73
|
-
get isSubmitting(): boolean;
|
|
74
|
-
get isDirty(): boolean;
|
|
75
|
-
registerField(path: string, config: BitFieldDefinition<T>): void;
|
|
76
|
-
unregisterField(path: string): void;
|
|
77
|
-
unregisterPrefix(prefix: string): void;
|
|
78
|
-
isHidden<P extends BitPath<T>>(path: P): boolean;
|
|
79
|
-
isRequired<P extends BitPath<T>>(path: P): boolean;
|
|
80
|
-
isFieldDirty(path: string): boolean;
|
|
81
|
-
isFieldValidating(path: string): boolean;
|
|
82
|
-
subscribe(listener: () => void): () => void;
|
|
83
|
-
subscribeSelector<TSlice>(selector: BitSelector<T, TSlice>, listener: (slice: TSlice) => void, options?: BitSelectorSubscriptionOptions<TSlice>): () => void;
|
|
84
|
-
subscribePath<P extends BitPath<T>>(path: P, listener: (value: BitPathValue<T, P>) => void, options?: BitSelectorSubscriptionOptions<BitPathValue<T, P>>): () => void;
|
|
85
|
-
watch<P extends BitPath<T>>(path: P, callback: (value: BitPathValue<T, P>) => void): () => void;
|
|
86
|
-
setField<P extends BitPath<T>>(path: P, value: BitPathValue<T, P>): void;
|
|
87
|
-
setFieldWithMeta(path: string, value: any, meta?: BitFieldChangeMeta): void;
|
|
88
|
-
blurField<P extends BitPath<T>>(path: P): void;
|
|
89
|
-
markFieldsTouched(paths: string[]): void;
|
|
90
|
-
replaceValues(newValues: T): void;
|
|
91
|
-
hydrate(values: DeepPartial<T>): void;
|
|
92
|
-
rebase(newValues: T): void;
|
|
93
|
-
setError(path: string, message: string | undefined): void;
|
|
94
|
-
setErrors(errors: BitErrors<T>): void;
|
|
95
|
-
setServerErrors(serverErrors: Record<string, string[] | string>): void;
|
|
96
|
-
reset(): void;
|
|
97
|
-
transaction<TResult>(callback: () => TResult): TResult;
|
|
98
|
-
submit(onSuccess: (values: T, dirtyValues?: Partial<T>) => void | Promise<void>): Promise<void>;
|
|
99
|
-
registerMask(name: BitMaskName, mask: BitMask): void;
|
|
100
|
-
getDirtyValues(): Partial<T>;
|
|
101
|
-
getPersistMetadata(): BitPersistMetadata;
|
|
102
|
-
restorePersisted(): Promise<boolean>;
|
|
103
|
-
forceSave(): Promise<void>;
|
|
104
|
-
clearPersisted(): Promise<void>;
|
|
105
|
-
pushItem<P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>): void;
|
|
106
|
-
prependItem<P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>): void;
|
|
107
|
-
insertItem<P extends BitArrayPath<T>>(path: P, index: number, value: BitArrayItem<BitPathValue<T, P>>): void;
|
|
108
|
-
removeItem<P extends BitArrayPath<T>>(path: P, index: number): void;
|
|
109
|
-
swapItems<P extends BitArrayPath<T>>(path: P, indexA: number, indexB: number): void;
|
|
110
|
-
moveItem<P extends BitArrayPath<T>>(path: P, from: number, to: number): void;
|
|
111
|
-
get canUndo(): boolean;
|
|
112
|
-
get canRedo(): boolean;
|
|
113
|
-
undo(): void;
|
|
114
|
-
redo(): void;
|
|
115
|
-
getHistoryMetadata(): BitHistoryMetadata;
|
|
116
|
-
validate(options?: BitValidationOptions): Promise<boolean>;
|
|
117
|
-
emitBeforeValidate(event: BitBeforeValidateEvent<T>): Promise<void>;
|
|
118
|
-
emitAfterValidate(event: BitAfterValidateEvent<T>): Promise<void>;
|
|
119
|
-
emitBeforeSubmit(event: BitBeforeSubmitEvent<T>): Promise<void>;
|
|
120
|
-
emitAfterSubmit(event: BitAfterSubmitEvent<T>): Promise<void>;
|
|
121
|
-
emitFieldChange(event: BitFieldChangeEvent<T>): void;
|
|
122
|
-
emitOperationalError(event: {
|
|
123
|
-
source: "submit";
|
|
124
|
-
error: unknown;
|
|
125
|
-
payload?: unknown;
|
|
126
|
-
}): Promise<void>;
|
|
127
|
-
hasValidationsInProgress(scopeFields?: string[]): boolean;
|
|
128
|
-
triggerValidation(scopeFields?: string[], options?: BitValidationTriggerOptions): void;
|
|
129
|
-
getStepStatus(scopeName: string): {
|
|
130
|
-
hasErrors: boolean;
|
|
131
|
-
isDirty: boolean;
|
|
132
|
-
errors: Record<string, string>;
|
|
133
|
-
};
|
|
134
|
-
getStepErrors(scopeName: string): Record<string, string>;
|
|
135
|
-
updateDependencies(changedPath: string, newValues: T): string[];
|
|
136
|
-
isFieldHidden(path: string): boolean;
|
|
137
|
-
evaluateAllDependencies(values: T): void;
|
|
138
|
-
getHiddenFields(): ReadonlySet<string>;
|
|
139
|
-
getRequiredErrors(values: T): BitErrors<T>;
|
|
140
|
-
clearFieldValidation(path: string): void;
|
|
141
|
-
handleFieldAsyncValidation(path: string, value: any): void;
|
|
142
|
-
cancelAllValidations(): void;
|
|
143
|
-
validateNow(options?: BitValidationOptions): Promise<boolean>;
|
|
144
|
-
updateDirtyForPath(path: string, nextValues: T, baselineValues: T): boolean;
|
|
145
|
-
rebuildDirtyState(nextValues: T, baselineValues: T): boolean;
|
|
146
|
-
clearDirtyState(): void;
|
|
147
|
-
buildDirtyValues(values: T): Partial<T>;
|
|
148
|
-
batchStateUpdates<TResult>(callback: () => TResult): TResult;
|
|
149
|
-
resetHistory(initialValues: T): void;
|
|
150
|
-
/** Current baseline used for dirty-state comparisons. */
|
|
151
|
-
get initialValues(): T;
|
|
152
|
-
/** Returns the current baseline (usable as a port method). */
|
|
153
|
-
getInitialValues(): T;
|
|
154
|
-
/**
|
|
155
|
-
* Updates the baseline used for dirty comparisons.
|
|
156
|
-
* Called by rebaseValues so that config is never mutated directly by managers.
|
|
157
|
-
* Also syncs config.initialValues so getConfig() reflects the new baseline.
|
|
158
|
-
*/
|
|
159
|
-
setInitialValues(values: T): void;
|
|
160
|
-
/** Returns a monotonically increasing counter that increments every time a
|
|
161
|
-
* mask is registered via registerMask(). Used by React components to track
|
|
162
|
-
* mask configuration changes reactively without storing masks in BitState. */
|
|
163
|
-
getMasksVersion(): number;
|
|
164
|
-
internalUpdateState(partialState: Partial<BitState<T>>, changedPaths?: string[]): void;
|
|
165
|
-
internalSaveSnapshot(): void;
|
|
166
|
-
private applyPersistedValues;
|
|
167
|
-
cleanup(): void;
|
|
168
|
-
private flushBatchedStateUpdates;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
declare function resolveBitStoreForHooks<T extends object>(store: BitStoreApi<T> | BitStore<T>): BitStoreHooksApi<T>;
|
|
172
|
-
declare function createBitStore<T extends object = any>(config?: BitConfig<T>): BitStoreApi<T>;
|
|
8
|
+
declare function resolveBitStoreForHooks<T extends object>(store: unknown): BitStoreHooksApi<T>;
|
|
9
|
+
declare function createBitStore<T extends object = any>(config?: BitConfig<T>): BitStoreHooksApi<T>;
|
|
173
10
|
|
|
174
11
|
declare function deepClone<T>(obj: T): T;
|
|
175
12
|
declare function deepMerge<T>(target: T, source: any): T;
|
|
@@ -192,4 +29,60 @@ declare function isValidationErrorShape(x: unknown): x is Record<string, string
|
|
|
192
29
|
*/
|
|
193
30
|
declare function extractServerErrors(x: unknown): Record<string, string | string[]>;
|
|
194
31
|
|
|
195
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Field State Snapshot Utilities
|
|
34
|
+
*
|
|
35
|
+
* Shared utilities for creating and managing field state snapshots across frameworks
|
|
36
|
+
* (React, Vue, Angular). Reduces code duplication while maintaining type safety.
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Represents a stable snapshot of field state that can be compared for equality.
|
|
40
|
+
*/
|
|
41
|
+
interface BitFieldSnapshot<TValue = any> {
|
|
42
|
+
value: TValue;
|
|
43
|
+
error: string | undefined;
|
|
44
|
+
touched: boolean;
|
|
45
|
+
isHidden: boolean;
|
|
46
|
+
isRequired: boolean;
|
|
47
|
+
isDirty: boolean;
|
|
48
|
+
isValidating: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates or reuses a field state snapshot with shallow equality checking.
|
|
52
|
+
*
|
|
53
|
+
* This function prevents unnecessary re-renders in frameworks like React by
|
|
54
|
+
* returning the same object reference when field state hasn't changed.
|
|
55
|
+
*
|
|
56
|
+
* @param nextState - The new field state from the store
|
|
57
|
+
* @param lastSnapshot - The previous snapshot (can be null on first call)
|
|
58
|
+
* @returns A stable snapshot object that can be used for equality comparison
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const snapshot = createFieldStateSnapshot(store.getFieldState("email"), lastSnapshot);
|
|
63
|
+
* if (snapshot !== lastSnapshot) {
|
|
64
|
+
* // Field state changed, update component
|
|
65
|
+
* render(snapshot);
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function createFieldStateSnapshot<TValue = any>(nextState: {
|
|
70
|
+
value: TValue;
|
|
71
|
+
error: string | undefined;
|
|
72
|
+
touched: boolean;
|
|
73
|
+
isHidden: boolean;
|
|
74
|
+
isRequired: boolean;
|
|
75
|
+
isDirty: boolean;
|
|
76
|
+
isValidating: boolean;
|
|
77
|
+
}, lastSnapshot: BitFieldSnapshot<TValue> | null): BitFieldSnapshot<TValue>;
|
|
78
|
+
/**
|
|
79
|
+
* Deep comparison utility for field state snapshots.
|
|
80
|
+
* Useful for scenarios where shallow comparison isn't sufficient (e.g., object/array values).
|
|
81
|
+
*
|
|
82
|
+
* @param snapshotA - First snapshot
|
|
83
|
+
* @param snapshotB - Second snapshot
|
|
84
|
+
* @returns true if snapshots are deeply equal
|
|
85
|
+
*/
|
|
86
|
+
declare function areFieldSnapshotsEqual(snapshotA: BitFieldSnapshot | null | undefined, snapshotB: BitFieldSnapshot | null | undefined): boolean;
|
|
87
|
+
|
|
88
|
+
export { BitConfig, type BitFieldSnapshot, BitStoreHooksApi, areFieldSnapshotsEqual, cleanPrefixedKeys, createBitStore, createFieldStateSnapshot, deepClone, deepEqual, deepMerge, extractServerErrors, getDeepValue, isValidationErrorShape, resolveBitStoreForHooks, setDeepValue, valueEqual };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,175 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { g as BitEqualityFn } from './public-types-DdZxD6Op.js';
|
|
1
|
+
import { j as BitConfig } from './bus-DgilLszS.js';
|
|
2
|
+
export { s as BitAfterSubmitEvent, t as BitAfterValidateEvent, a as BitArrayItem, B as BitArrayPath, u as BitBeforeSubmitEvent, v as BitBeforeValidateEvent, d as BitBus, w as BitBusListener, x as BitComputedFn, c as BitErrors, y as BitFieldChangeEvent, z as BitFieldChangeMeta, A as BitFieldConditional, h as BitFieldDefinition, g as BitFieldState, C as BitFieldValidation, q as BitFormGlobal, E as BitHistoryConfig, e as BitPath, b as BitPathValue, F as BitPersistConfig, i as BitPersistMetadata, G as BitPersistMode, H as BitPersistStorageAdapter, o as BitPlugin, I as BitPluginContext, J as BitPluginErrorEvent, K as BitPluginHooks, p as BitScheduler, f as BitState, r as BitTouched, L as BitTransformFn, M as BitValidationConfig, D as DeepPartial, l as DevToolsOptions, S as ScopeStatus, V as ValidateScopeResult, k as ValidatorFn, N as bitBus, O as createBitBus } from './bus-DgilLszS.js';
|
|
3
|
+
import { a as BitStoreHooksApi } from './store-api-types-9ipdute1.js';
|
|
4
|
+
export { B as BitArrayBindingApi, h as BitEqualityFn, g as BitFieldBindingApi, b as BitFormBindingApi, f as BitFormMeta, e as BitFormMetaBindingApi, i as BitFrameworkConfig, c as BitHistoryMetadata, j as BitSelector, k as BitSelectorSubscriptionOptions, l as BitStoreApi, m as BitStoreArrayFeatureApi, n as BitStoreFeatureApi, o as BitStoreHistoryFeatureApi, p as BitStoreObserveApi, q as BitStorePersistFeatureApi, r as BitStoreQueryApi, s as BitStoreRegistrationFeatureApi, t as BitStoreWriteApi, d as BitValidationOptions } from './store-api-types-9ipdute1.js';
|
|
6
5
|
export { a as BitDeleteUploadFn, B as BitUploadFn, b as BitUploadResult } from './upload-EXnJLq8k.js';
|
|
6
|
+
import './types-CUXh7PqD.js';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
compute: BitComputedFn<T>;
|
|
11
|
-
dependsOn?: readonly string[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface BitValidationTriggerOptions {
|
|
15
|
-
forceDebounce?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* BitStore
|
|
20
|
-
*
|
|
21
|
-
* The core orchestrator of form state management.
|
|
22
|
-
*
|
|
23
|
-
* This store coordinates multiple managers to provide comprehensive form handling:
|
|
24
|
-
* - Core managers handle essential state and validation
|
|
25
|
-
* - Feature managers provide optional enhancements (history, arrays, scopes)
|
|
26
|
-
* - Query/mutation managers organize domain-specific operations
|
|
27
|
-
*/
|
|
28
|
-
declare class BitStore<T extends object = any> {
|
|
29
|
-
private state;
|
|
30
|
-
private readonly subscriptions;
|
|
31
|
-
private readonly effects;
|
|
32
|
-
private readonly capabilities;
|
|
33
|
-
/** Baseline for dirty tracking. Decoupled from config so that rebaseValues
|
|
34
|
-
* can update it without mutating the user-provided config object. */
|
|
35
|
-
private _initialValues;
|
|
36
|
-
/** Incremented on every registerMask() call so React hooks can track mask
|
|
37
|
-
* configuration changes via useSyncExternalStore without putting masks in
|
|
38
|
-
* BitState and triggering a full re-render of all fields. */
|
|
39
|
-
private _masksVersion;
|
|
40
|
-
config: BitFrameworkConfig<T>;
|
|
41
|
-
readonly storeId: string;
|
|
42
|
-
private readonly dependencyManager;
|
|
43
|
-
private readonly computedManager;
|
|
44
|
-
private readonly dirtyManager;
|
|
45
|
-
private scopeFieldsIndex;
|
|
46
|
-
private computedEntriesCache;
|
|
47
|
-
private transformEntriesCache;
|
|
48
|
-
private batchDepth;
|
|
49
|
-
private batchedState;
|
|
50
|
-
private batchedChangedPaths;
|
|
51
|
-
private batchedValuesChanged;
|
|
52
|
-
private invalidateFieldIndexes;
|
|
53
|
-
private registerCachedFieldIndexes;
|
|
54
|
-
private unregisterCachedFieldIndexes;
|
|
55
|
-
private getCapability;
|
|
56
|
-
private get validation();
|
|
57
|
-
private get lifecycle();
|
|
58
|
-
private get history();
|
|
59
|
-
private get arrays();
|
|
60
|
-
private get scope();
|
|
61
|
-
private get query();
|
|
62
|
-
private get error();
|
|
63
|
-
constructor(config?: BitConfig<T>);
|
|
64
|
-
getConfig(): BitFrameworkConfig<T>;
|
|
65
|
-
getFieldConfig(path: string): BitFieldDefinition<T> | undefined;
|
|
66
|
-
getScopeFields(scopeName: string): string[];
|
|
67
|
-
getComputedEntries(): BitComputedEntry<T>[];
|
|
68
|
-
getTransformEntries(): [string, BitTransformFn<T>][];
|
|
69
|
-
resolveMask(path: string): BitMask | undefined;
|
|
70
|
-
getState(): BitState<T>;
|
|
71
|
-
getFieldState<P extends BitPath<T>>(path: P): BitFieldState<T, BitPathValue<T, P>>;
|
|
72
|
-
get isValid(): boolean;
|
|
73
|
-
get isSubmitting(): boolean;
|
|
74
|
-
get isDirty(): boolean;
|
|
75
|
-
registerField(path: string, config: BitFieldDefinition<T>): void;
|
|
76
|
-
unregisterField(path: string): void;
|
|
77
|
-
unregisterPrefix(prefix: string): void;
|
|
78
|
-
isHidden<P extends BitPath<T>>(path: P): boolean;
|
|
79
|
-
isRequired<P extends BitPath<T>>(path: P): boolean;
|
|
80
|
-
isFieldDirty(path: string): boolean;
|
|
81
|
-
isFieldValidating(path: string): boolean;
|
|
82
|
-
subscribe(listener: () => void): () => void;
|
|
83
|
-
subscribeSelector<TSlice>(selector: BitSelector<T, TSlice>, listener: (slice: TSlice) => void, options?: BitSelectorSubscriptionOptions<TSlice>): () => void;
|
|
84
|
-
subscribePath<P extends BitPath<T>>(path: P, listener: (value: BitPathValue<T, P>) => void, options?: BitSelectorSubscriptionOptions<BitPathValue<T, P>>): () => void;
|
|
85
|
-
watch<P extends BitPath<T>>(path: P, callback: (value: BitPathValue<T, P>) => void): () => void;
|
|
86
|
-
setField<P extends BitPath<T>>(path: P, value: BitPathValue<T, P>): void;
|
|
87
|
-
setFieldWithMeta(path: string, value: any, meta?: BitFieldChangeMeta): void;
|
|
88
|
-
blurField<P extends BitPath<T>>(path: P): void;
|
|
89
|
-
markFieldsTouched(paths: string[]): void;
|
|
90
|
-
replaceValues(newValues: T): void;
|
|
91
|
-
hydrate(values: DeepPartial<T>): void;
|
|
92
|
-
rebase(newValues: T): void;
|
|
93
|
-
setError(path: string, message: string | undefined): void;
|
|
94
|
-
setErrors(errors: BitErrors<T>): void;
|
|
95
|
-
setServerErrors(serverErrors: Record<string, string[] | string>): void;
|
|
96
|
-
reset(): void;
|
|
97
|
-
transaction<TResult>(callback: () => TResult): TResult;
|
|
98
|
-
submit(onSuccess: (values: T, dirtyValues?: Partial<T>) => void | Promise<void>): Promise<void>;
|
|
99
|
-
registerMask(name: BitMaskName, mask: BitMask): void;
|
|
100
|
-
getDirtyValues(): Partial<T>;
|
|
101
|
-
getPersistMetadata(): BitPersistMetadata;
|
|
102
|
-
restorePersisted(): Promise<boolean>;
|
|
103
|
-
forceSave(): Promise<void>;
|
|
104
|
-
clearPersisted(): Promise<void>;
|
|
105
|
-
pushItem<P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>): void;
|
|
106
|
-
prependItem<P extends BitArrayPath<T>>(path: P, value: BitArrayItem<BitPathValue<T, P>>): void;
|
|
107
|
-
insertItem<P extends BitArrayPath<T>>(path: P, index: number, value: BitArrayItem<BitPathValue<T, P>>): void;
|
|
108
|
-
removeItem<P extends BitArrayPath<T>>(path: P, index: number): void;
|
|
109
|
-
swapItems<P extends BitArrayPath<T>>(path: P, indexA: number, indexB: number): void;
|
|
110
|
-
moveItem<P extends BitArrayPath<T>>(path: P, from: number, to: number): void;
|
|
111
|
-
get canUndo(): boolean;
|
|
112
|
-
get canRedo(): boolean;
|
|
113
|
-
undo(): void;
|
|
114
|
-
redo(): void;
|
|
115
|
-
getHistoryMetadata(): BitHistoryMetadata;
|
|
116
|
-
validate(options?: BitValidationOptions): Promise<boolean>;
|
|
117
|
-
emitBeforeValidate(event: BitBeforeValidateEvent<T>): Promise<void>;
|
|
118
|
-
emitAfterValidate(event: BitAfterValidateEvent<T>): Promise<void>;
|
|
119
|
-
emitBeforeSubmit(event: BitBeforeSubmitEvent<T>): Promise<void>;
|
|
120
|
-
emitAfterSubmit(event: BitAfterSubmitEvent<T>): Promise<void>;
|
|
121
|
-
emitFieldChange(event: BitFieldChangeEvent<T>): void;
|
|
122
|
-
emitOperationalError(event: {
|
|
123
|
-
source: "submit";
|
|
124
|
-
error: unknown;
|
|
125
|
-
payload?: unknown;
|
|
126
|
-
}): Promise<void>;
|
|
127
|
-
hasValidationsInProgress(scopeFields?: string[]): boolean;
|
|
128
|
-
triggerValidation(scopeFields?: string[], options?: BitValidationTriggerOptions): void;
|
|
129
|
-
getStepStatus(scopeName: string): {
|
|
130
|
-
hasErrors: boolean;
|
|
131
|
-
isDirty: boolean;
|
|
132
|
-
errors: Record<string, string>;
|
|
133
|
-
};
|
|
134
|
-
getStepErrors(scopeName: string): Record<string, string>;
|
|
135
|
-
updateDependencies(changedPath: string, newValues: T): string[];
|
|
136
|
-
isFieldHidden(path: string): boolean;
|
|
137
|
-
evaluateAllDependencies(values: T): void;
|
|
138
|
-
getHiddenFields(): ReadonlySet<string>;
|
|
139
|
-
getRequiredErrors(values: T): BitErrors<T>;
|
|
140
|
-
clearFieldValidation(path: string): void;
|
|
141
|
-
handleFieldAsyncValidation(path: string, value: any): void;
|
|
142
|
-
cancelAllValidations(): void;
|
|
143
|
-
validateNow(options?: BitValidationOptions): Promise<boolean>;
|
|
144
|
-
updateDirtyForPath(path: string, nextValues: T, baselineValues: T): boolean;
|
|
145
|
-
rebuildDirtyState(nextValues: T, baselineValues: T): boolean;
|
|
146
|
-
clearDirtyState(): void;
|
|
147
|
-
buildDirtyValues(values: T): Partial<T>;
|
|
148
|
-
batchStateUpdates<TResult>(callback: () => TResult): TResult;
|
|
149
|
-
resetHistory(initialValues: T): void;
|
|
150
|
-
/** Current baseline used for dirty-state comparisons. */
|
|
151
|
-
get initialValues(): T;
|
|
152
|
-
/** Returns the current baseline (usable as a port method). */
|
|
153
|
-
getInitialValues(): T;
|
|
154
|
-
/**
|
|
155
|
-
* Updates the baseline used for dirty comparisons.
|
|
156
|
-
* Called by rebaseValues so that config is never mutated directly by managers.
|
|
157
|
-
* Also syncs config.initialValues so getConfig() reflects the new baseline.
|
|
158
|
-
*/
|
|
159
|
-
setInitialValues(values: T): void;
|
|
160
|
-
/** Returns a monotonically increasing counter that increments every time a
|
|
161
|
-
* mask is registered via registerMask(). Used by React components to track
|
|
162
|
-
* mask configuration changes reactively without storing masks in BitState. */
|
|
163
|
-
getMasksVersion(): number;
|
|
164
|
-
internalUpdateState(partialState: Partial<BitState<T>>, changedPaths?: string[]): void;
|
|
165
|
-
internalSaveSnapshot(): void;
|
|
166
|
-
private applyPersistedValues;
|
|
167
|
-
cleanup(): void;
|
|
168
|
-
private flushBatchedStateUpdates;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
declare function resolveBitStoreForHooks<T extends object>(store: BitStoreApi<T> | BitStore<T>): BitStoreHooksApi<T>;
|
|
172
|
-
declare function createBitStore<T extends object = any>(config?: BitConfig<T>): BitStoreApi<T>;
|
|
8
|
+
declare function resolveBitStoreForHooks<T extends object>(store: unknown): BitStoreHooksApi<T>;
|
|
9
|
+
declare function createBitStore<T extends object = any>(config?: BitConfig<T>): BitStoreHooksApi<T>;
|
|
173
10
|
|
|
174
11
|
declare function deepClone<T>(obj: T): T;
|
|
175
12
|
declare function deepMerge<T>(target: T, source: any): T;
|
|
@@ -192,4 +29,60 @@ declare function isValidationErrorShape(x: unknown): x is Record<string, string
|
|
|
192
29
|
*/
|
|
193
30
|
declare function extractServerErrors(x: unknown): Record<string, string | string[]>;
|
|
194
31
|
|
|
195
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Field State Snapshot Utilities
|
|
34
|
+
*
|
|
35
|
+
* Shared utilities for creating and managing field state snapshots across frameworks
|
|
36
|
+
* (React, Vue, Angular). Reduces code duplication while maintaining type safety.
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Represents a stable snapshot of field state that can be compared for equality.
|
|
40
|
+
*/
|
|
41
|
+
interface BitFieldSnapshot<TValue = any> {
|
|
42
|
+
value: TValue;
|
|
43
|
+
error: string | undefined;
|
|
44
|
+
touched: boolean;
|
|
45
|
+
isHidden: boolean;
|
|
46
|
+
isRequired: boolean;
|
|
47
|
+
isDirty: boolean;
|
|
48
|
+
isValidating: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates or reuses a field state snapshot with shallow equality checking.
|
|
52
|
+
*
|
|
53
|
+
* This function prevents unnecessary re-renders in frameworks like React by
|
|
54
|
+
* returning the same object reference when field state hasn't changed.
|
|
55
|
+
*
|
|
56
|
+
* @param nextState - The new field state from the store
|
|
57
|
+
* @param lastSnapshot - The previous snapshot (can be null on first call)
|
|
58
|
+
* @returns A stable snapshot object that can be used for equality comparison
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const snapshot = createFieldStateSnapshot(store.getFieldState("email"), lastSnapshot);
|
|
63
|
+
* if (snapshot !== lastSnapshot) {
|
|
64
|
+
* // Field state changed, update component
|
|
65
|
+
* render(snapshot);
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function createFieldStateSnapshot<TValue = any>(nextState: {
|
|
70
|
+
value: TValue;
|
|
71
|
+
error: string | undefined;
|
|
72
|
+
touched: boolean;
|
|
73
|
+
isHidden: boolean;
|
|
74
|
+
isRequired: boolean;
|
|
75
|
+
isDirty: boolean;
|
|
76
|
+
isValidating: boolean;
|
|
77
|
+
}, lastSnapshot: BitFieldSnapshot<TValue> | null): BitFieldSnapshot<TValue>;
|
|
78
|
+
/**
|
|
79
|
+
* Deep comparison utility for field state snapshots.
|
|
80
|
+
* Useful for scenarios where shallow comparison isn't sufficient (e.g., object/array values).
|
|
81
|
+
*
|
|
82
|
+
* @param snapshotA - First snapshot
|
|
83
|
+
* @param snapshotB - Second snapshot
|
|
84
|
+
* @returns true if snapshots are deeply equal
|
|
85
|
+
*/
|
|
86
|
+
declare function areFieldSnapshotsEqual(snapshotA: BitFieldSnapshot | null | undefined, snapshotB: BitFieldSnapshot | null | undefined): boolean;
|
|
87
|
+
|
|
88
|
+
export { BitConfig, type BitFieldSnapshot, BitStoreHooksApi, areFieldSnapshotsEqual, cleanPrefixedKeys, createBitStore, createFieldStateSnapshot, deepClone, deepEqual, deepMerge, extractServerErrors, getDeepValue, isValidationErrorShape, resolveBitStoreForHooks, setDeepValue, valueEqual };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as t,b as i,c as e,d as r,e as o,f as a,g as B,h as n,i as l,j as s,k as p,s as d,t as u,u as S,v as F}from"./chunk-SA47B5OP.js";import"./chunk-3NUJVIAM.js";export{F as areFieldSnapshotsEqual,s as bitBus,B as cleanPrefixedKeys,p as createBitBus,u as createBitStore,S as createFieldStateSnapshot,t as deepClone,r as deepEqual,i as deepMerge,l as extractServerErrors,o as getDeepValue,n as isValidationErrorShape,d as resolveBitStoreForHooks,a as setDeepValue,e as valueEqual};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/mask.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PatternMaskOptions, B as BitMask, C as CurrencyMaskConfig, D as DateMaskConfig,
|
|
2
|
-
export {
|
|
1
|
+
import { P as PatternMaskOptions, B as BitMask, C as CurrencyMaskConfig, D as DateMaskConfig, a as BitBuiltInMaskName } from './types-CUXh7PqD.cjs';
|
|
2
|
+
export { b as BitMaskName } from './types-CUXh7PqD.cjs';
|
|
3
3
|
|
|
4
4
|
declare const unmask: (value: string | number | null | undefined, allowChars?: string) => string;
|
|
5
5
|
declare const unmaskCurrency: (value: any, precision?: number) => number;
|
package/dist/mask.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PatternMaskOptions, B as BitMask, C as CurrencyMaskConfig, D as DateMaskConfig,
|
|
2
|
-
export {
|
|
1
|
+
import { P as PatternMaskOptions, B as BitMask, C as CurrencyMaskConfig, D as DateMaskConfig, a as BitBuiltInMaskName } from './types-CUXh7PqD.js';
|
|
2
|
+
export { b as BitMaskName } from './types-CUXh7PqD.js';
|
|
3
3
|
|
|
4
4
|
declare const unmask: (value: string | number | null | undefined, allowChars?: string) => string;
|
|
5
5
|
declare const unmaskCurrency: (value: any, precision?: number) => number;
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 _chunkKWLLYQOLcjs = require('../chunk-KWLLYQOL.cjs');var _chunkIV32WXCFcjs = require('../chunk-IV32WXCF.cjs');var _chunkFUUQB4DVcjs = require('../chunk-FUUQB4DV.cjs');var _chunkPFPGASVZcjs = require('../chunk-PFPGASVZ.cjs');var _react = require('react');function f(e){let{fieldState:t,setBlur:n,store:a}=_chunkKWLLYQOLcjs.d.call(void 0, e),{fieldController:r}=_react.useMemo.call(void 0, ()=>_chunkFUUQB4DVcjs.E.call(void 0, a,e),[a,e]),l=_react.useMemo.call(void 0, ()=>r.displayValue(t.value),[t.value,r]),u=_react.useCallback.call(void 0, i=>{r.setValue(i)},[r]),{value:o}=t,s=_chunkFUUQB4DVcjs.I.call(void 0, t),p=_react.useCallback.call(void 0, i=>{let B=_chunkPFPGASVZcjs.a.call(void 0, i)?_optionalChain([i, 'access', _ => _.target, 'optionalAccess', _2 => _2.value]):i;u(B)},[u]),c=_react.useCallback.call(void 0, ()=>{n()},[n]);return{value:o,displayValue:l,setValue:u,setBlur:n,onChange:p,onBlur:c,props:{value:l,onChange:p,onBlur:c},meta:{error:s.error,touched:s.touched,invalid:s.invalid,isDirty:s.isDirty,isValidating:s.isValidating,isHidden:s.isHidden,isRequired:s.isRequired,hasError:s.hasError}}}function D(){let e=_chunkKWLLYQOLcjs.b.call(void 0, ),t=_react.useRef.call(void 0, null),n=_react.useCallback.call(void 0, ()=>{let o=_chunkFUUQB4DVcjs.m.call(void 0, e);return t.current&&t.current.canUndo===o.canUndo&&t.current.canRedo===o.canRedo&&t.current.historyIndex===o.historyIndex&&t.current.historySize===o.historySize?t.current:(t.current=o,o)},[e]),a=_react.useCallback.call(void 0, o=>e.subscribeHistoryMeta(()=>o()),[e]),r=_react.useSyncExternalStore.call(void 0, a,n,n),l=_react.useCallback.call(void 0, ()=>{e.undo()},[e]),u=_react.useCallback.call(void 0, ()=>{e.redo()},[e]);return{...r,undo:l,redo:u}}function q(e,t,n){let a=_chunkKWLLYQOLcjs.b.call(void 0, ),r=f(e),l=_react.useRef.call(void 0, null),[u,o]=_react.useState.call(void 0, !1),s={setLoading:o,setError:(i,B)=>a.setError(i,B),setValue:i=>r.setValue(i),getUploadKey:()=>l.current,setUploadKey:i=>{l.current=i}},p=_react.useCallback.call(void 0, _chunkIV32WXCFcjs.a.call(void 0, e,t,s),[t,r,e,a]),c=_react.useCallback.call(void 0, _chunkIV32WXCFcjs.b.call(void 0, e,n,s),[n,r,e,a]);return{value:r.value,setValue:r.setValue,error:_optionalChain([r, 'access', _3 => _3.meta, 'optionalAccess', _4 => _4.error]),isValidating:!!_optionalChain([r, 'access', _5 => _5.meta, 'optionalAccess', _6 => _6.isValidating])||u,upload:p,remove:c}}exports.BitFormProvider = _chunkKWLLYQOLcjs.a; exports.useBitArray = _chunkKWLLYQOLcjs.e; exports.useBitField = f; exports.useBitForm = _chunkKWLLYQOLcjs.c; exports.useBitHistory = D; exports.useBitPersist = _chunkKWLLYQOLcjs.i; exports.useBitScope = _chunkKWLLYQOLcjs.f; exports.useBitSteps = _chunkKWLLYQOLcjs.g; exports.useBitStore = _chunkKWLLYQOLcjs.b; exports.useBitUpload = q; exports.useBitWatch = _chunkKWLLYQOLcjs.h;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -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","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,gCAAAA,CACdC,EACCb,CAAAA,CACEc,iCAAAA,CAAiBD,kBAAKN,CAAAA,SAAgB,KAAA,GAAS,CAIjD,CAAA,CACF,CAACA,CAAAA,CAAcP,CAAW,CAC5B,CAAA,CAEM,CAAE,QAAA,CAAAe,CAAAA,CAAU,UAAA,CAAAC,CAAAA,CAAY,KA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AA,CAC7BI,CAAAA,CAAed,2BAAAA,IAA0B,CAAA,CACzC,CAACe,CAAAA,CAAaC,CAAc,CAAA,CAAIC,6BAAAA,CAAS,CAAK,CAAA,CAE9CC,CAAAA,CAAkB,CACtB,UAAA,CAAYF,CAAAA,CACZ,QAAA,CAAU,CAACjD,CAAAA,CAAcoD,CAAAA,CAAAA,EACvBhD,CAAAA,CAAM,QAAA,CAASJ,CAAAA,CAAMoD,CAAG,CAAA,CAC1B,QAAA,CAAWrC,CAAAA,EAAuB+B,CAAAA,CAAM,QAAA,CAAS/B,CAAU,CAAA,CAC3D,YAAA,CAAc,CAAA,CAAA,EAAMgC,CAAAA,CAAa,OAAA,CACjC,YAAA,CAAeM,CAAAA,EAAuB,CACpCN,CAAAA,CAAa,OAAA,CAAUM,CACzB,CACF,CAAA,CAEMC,CAAAA,CAASxC,gCAAAA,iCACbyC,CAAoBZ,CAAWC,CAAAA,CAAUO,CAAe,CAAA,CACxD,CAACP,CAAAA,CAAUE,CAAAA,CAAOH,CAAAA,CAAWvC,CAAK,CACpC,CAAA,CAEMoD,CAAAA,CAAS1C,gCAAAA,iCACb2C,CAAoBd,CAAWE,CAAAA,CAAYM,CAAe,CAAA,CAC1D,CAACN,CAAAA,CAAYC,CAAAA,CAAOH,CAAAA,CAAWvC,CAAK,CACtC,CAAA,CAEA,MAAO,CACL,KAAA,CAAO0C,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, 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
|
+
{"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","setBlur","store","useBitFieldBase","fieldController","useMemo","createFrameworkMaskedFieldBinding","displayValue","setValue","useCallback","val","value","metaState","deriveFieldMeta","onChange","e","isBitFieldInputEventObject","onBlur","useBitHistory","useBitStore","lastMeta","useRef","getSnapshot","nextMeta","readHistoryMetaSnapshot","subscribe","cb","meta","useSyncExternalStore","undo","redo","useBitUpload","fieldPath","uploadFn","deleteFile","field","uploadKeyRef","isUploading","setIsUploading","useState","kernelCallbacks","msg","key","upload","createUploadHandler","remove","createRemoveHandler"],"mappings":"AAAA,soBAAiG,yDAAiD,yDAAwD,yDAA0C,8BCA/M,SAgBrBA,CAAAA,CAGdC,CAAAA,CAAsC,CACtC,GAAM,CAAE,UAAA,CAAAC,CAAAA,C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AYC,CAAAA,CAAOH,CAAAA,CAAW9B,CAAK,CACtC,CAAA,CAEA,MAAO,CACL,KAAA,CAAOiC,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 {\n BitPath,\n BitPathValue,\n createFrameworkMaskedFieldBinding,\n deriveFieldMeta,\n isBitFieldInputEventObject,\n} from \"../core\";\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 { fieldState, setBlur, store } = useBitFieldBase<\n BitPathValue<TForm, P>,\n TForm,\n P\n >(path);\n\n const { fieldController } = useMemo(() => {\n return createFrameworkMaskedFieldBinding(store, path);\n }, [store, path]);\n\n const displayValue = useMemo(\n () => fieldController.displayValue(fieldState.value),\n [fieldState.value, fieldController],\n );\n\n const setValue = useCallback(\n (val: BitPathValue<TForm, P> | string | number | null | undefined) => {\n fieldController.setValue(val);\n },\n [fieldController],\n );\n\n const { value } = fieldState;\n const metaState = deriveFieldMeta(fieldState);\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: metaState.error,\n touched: metaState.touched,\n invalid: metaState.invalid,\n isDirty: metaState.isDirty,\n isValidating: metaState.isValidating,\n isHidden: metaState.isHidden,\n isRequired: metaState.isRequired,\n hasError: metaState.hasError,\n },\n };\n}\n","import { useCallback, useRef, useSyncExternalStore } from \"react\";\nimport { readHistoryMetaSnapshot, type HistoryMeta } from \"../core\";\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 = readHistoryMetaSnapshot(store);\n\n if (\n lastMeta.current &&\n lastMeta.current.canUndo === nextMeta.canUndo &&\n lastMeta.current.canRedo === nextMeta.canRedo &&\n lastMeta.current.historyIndex === nextMeta.historyIndex &&\n lastMeta.current.historySize === nextMeta.historySize\n ) {\n return lastMeta.current;\n }\n\n lastMeta.current = nextMeta;\n return nextMeta;\n }, [store]);\n\n const subscribe = useCallback(\n (cb: () => void) => store.subscribeHistoryMeta(() => 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"]}
|
package/dist/react/index.d.cts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { g as UseBitFieldResult, h as UseBitHistoryResult, i as UseBitUploadResult } from '../use-bit-persist-
|
|
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-
|
|
3
|
-
import {
|
|
4
|
-
export { S as ScopeStatus,
|
|
1
|
+
import { g as UseBitFieldResult, h as UseBitHistoryResult, i as UseBitUploadResult } from '../use-bit-persist-CIKFwtdM.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-CIKFwtdM.cjs';
|
|
3
|
+
import { e as BitPath } from '../bus-rcUiufS7.cjs';
|
|
4
|
+
export { S as ScopeStatus, V as ValidateScopeResult } from '../bus-rcUiufS7.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 '../
|
|
9
|
-
import '../types-
|
|
10
|
-
import '../
|
|
8
|
+
import '../store-api-types-B6_bPoVI.cjs';
|
|
9
|
+
import '../types-CUXh7PqD.cjs';
|
|
10
|
+
import '../array-controller-C1A5VKYd.cjs';
|
|
11
|
+
import '../field-binding-X5TkvfUt.cjs';
|
|
11
12
|
|
|
12
13
|
declare function useBitField<TForm extends object = any, P extends BitPath<TForm> = BitPath<TForm>>(path: P): UseBitFieldResult<TForm, P>;
|
|
13
14
|
|