@lucas-barake/effect-form-react 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{dts/FormReact.d.ts → FormReact.d.ts} +22 -33
- package/dist/FormReact.d.ts.map +1 -0
- package/dist/FormReact.js +238 -0
- package/dist/FormReact.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -15
- package/src/FormReact.tsx +252 -470
- package/src/index.ts +2 -8
- package/dist/cjs/FormReact.js +0 -402
- package/dist/cjs/FormReact.js.map +0 -1
- package/dist/cjs/index.js +0 -42
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/internal/use-debounced.js +0 -56
- package/dist/cjs/internal/use-debounced.js.map +0 -1
- package/dist/dts/FormReact.d.ts.map +0 -1
- package/dist/dts/index.d.ts +0 -9
- package/dist/dts/index.d.ts.map +0 -1
- package/dist/dts/internal/use-debounced.d.ts +0 -2
- package/dist/dts/internal/use-debounced.d.ts.map +0 -1
- package/dist/esm/FormReact.js +0 -375
- package/dist/esm/FormReact.js.map +0 -1
- package/dist/esm/index.js +0 -9
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/internal/use-debounced.js +0 -29
- package/dist/esm/internal/use-debounced.js.map +0 -1
- package/dist/esm/package.json +0 -4
- package/src/internal/use-debounced.ts +0 -39
package/dist/esm/FormReact.js
DELETED
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { RegistryContext, useAtom, useAtomMount, useAtomSet, useAtomSubscribe, useAtomValue } from "@effect-atom/atom-react";
|
|
3
|
-
import * as Atom from "@effect-atom/atom/Atom";
|
|
4
|
-
import { Field, FormAtoms, Mode, Validation } from "@lucas-barake/effect-form";
|
|
5
|
-
import { getNestedValue } from "@lucas-barake/effect-form/Path";
|
|
6
|
-
import * as Cause from "effect/Cause";
|
|
7
|
-
import * as Layer from "effect/Layer";
|
|
8
|
-
import * as Option from "effect/Option";
|
|
9
|
-
import * as ParseResult from "effect/ParseResult";
|
|
10
|
-
import * as AST from "effect/SchemaAST";
|
|
11
|
-
import * as React from "react";
|
|
12
|
-
import { createContext, useContext } from "react";
|
|
13
|
-
import { useDebounced } from "./internal/use-debounced.js";
|
|
14
|
-
const ArrayItemContext = /*#__PURE__*/createContext(null);
|
|
15
|
-
const AutoSubmitContext = /*#__PURE__*/createContext(null);
|
|
16
|
-
const makeFieldComponent = (fieldKey, fieldDef, errorsAtom, submitCountAtom, parsedMode, getOrCreateValidationAtom, getOrCreateFieldAtoms, Component) => {
|
|
17
|
-
const FieldComponent = extraProps => {
|
|
18
|
-
const arrayCtx = useContext(ArrayItemContext);
|
|
19
|
-
const autoSubmitOnBlur = useContext(AutoSubmitContext);
|
|
20
|
-
const fieldPath = arrayCtx ? `${arrayCtx.parentPath}.${fieldKey}` : fieldKey;
|
|
21
|
-
const {
|
|
22
|
-
errorAtom,
|
|
23
|
-
isDirtyAtom,
|
|
24
|
-
touchedAtom,
|
|
25
|
-
valueAtom
|
|
26
|
-
} = React.useMemo(() => getOrCreateFieldAtoms(fieldPath), [fieldPath]);
|
|
27
|
-
const [value, setValue] = useAtom(valueAtom);
|
|
28
|
-
const [isTouched, setTouched] = useAtom(touchedAtom);
|
|
29
|
-
const storedError = useAtomValue(errorAtom);
|
|
30
|
-
const submitCount = useAtomValue(submitCountAtom);
|
|
31
|
-
const validationAtom = React.useMemo(() => getOrCreateValidationAtom(fieldPath, fieldDef.schema), [fieldPath]);
|
|
32
|
-
const validationResult = useAtomValue(validationAtom);
|
|
33
|
-
const validateImmediate = useAtomSet(validationAtom);
|
|
34
|
-
const shouldDebounceValidation = parsedMode.validation === "onChange" && parsedMode.debounce !== null && !parsedMode.autoSubmit;
|
|
35
|
-
const validate = useDebounced(validateImmediate, shouldDebounceValidation ? parsedMode.debounce : null);
|
|
36
|
-
const prevValueRef = React.useRef(value);
|
|
37
|
-
React.useEffect(() => {
|
|
38
|
-
if (prevValueRef.current === value) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
prevValueRef.current = value;
|
|
42
|
-
const shouldValidate = parsedMode.validation === "onChange" || parsedMode.validation === "onBlur" && isTouched || parsedMode.validation === "onSubmit" && submitCount > 0;
|
|
43
|
-
if (shouldValidate) {
|
|
44
|
-
validate(value);
|
|
45
|
-
}
|
|
46
|
-
}, [value, isTouched, submitCount, validate]);
|
|
47
|
-
const livePerFieldError = React.useMemo(() => {
|
|
48
|
-
if (validationResult._tag === "Failure") {
|
|
49
|
-
const parseError = Cause.failureOption(validationResult.cause);
|
|
50
|
-
if (Option.isSome(parseError) && ParseResult.isParseError(parseError.value)) {
|
|
51
|
-
return Validation.extractFirstError(parseError.value);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return Option.none();
|
|
55
|
-
}, [validationResult]);
|
|
56
|
-
const isValidating = validationResult.waiting;
|
|
57
|
-
const validationError = React.useMemo(() => {
|
|
58
|
-
if (Option.isSome(livePerFieldError)) {
|
|
59
|
-
return livePerFieldError;
|
|
60
|
-
}
|
|
61
|
-
if (Option.isSome(storedError)) {
|
|
62
|
-
// Hide field-sourced errors when validation passes or is pending (async gap).
|
|
63
|
-
// Refinement errors persist until re-submit - they can't be cleared by typing.
|
|
64
|
-
const shouldHideStoredError = storedError.value.source === "field" && (validationResult._tag === "Success" || isValidating);
|
|
65
|
-
if (shouldHideStoredError) {
|
|
66
|
-
return Option.none();
|
|
67
|
-
}
|
|
68
|
-
return Option.some(storedError.value.message);
|
|
69
|
-
}
|
|
70
|
-
return Option.none();
|
|
71
|
-
}, [livePerFieldError, storedError, validationResult, isValidating]);
|
|
72
|
-
const onChange = React.useCallback(newValue => {
|
|
73
|
-
setValue(newValue);
|
|
74
|
-
}, [setValue]);
|
|
75
|
-
const onBlur = React.useCallback(() => {
|
|
76
|
-
setTouched(true);
|
|
77
|
-
if (parsedMode.validation === "onBlur") {
|
|
78
|
-
validate(value);
|
|
79
|
-
}
|
|
80
|
-
autoSubmitOnBlur?.();
|
|
81
|
-
}, [setTouched, validate, value, autoSubmitOnBlur]);
|
|
82
|
-
const isDirty = useAtomValue(isDirtyAtom);
|
|
83
|
-
const shouldShowError = parsedMode.validation === "onChange" ? isDirty || submitCount > 0 : parsedMode.validation === "onBlur" ? isTouched || submitCount > 0 : submitCount > 0;
|
|
84
|
-
const fieldState = React.useMemo(() => ({
|
|
85
|
-
value,
|
|
86
|
-
onChange,
|
|
87
|
-
onBlur,
|
|
88
|
-
error: shouldShowError ? validationError : Option.none(),
|
|
89
|
-
isTouched,
|
|
90
|
-
isValidating,
|
|
91
|
-
isDirty
|
|
92
|
-
}), [value, onChange, onBlur, shouldShowError, validationError, isTouched, isValidating, isDirty]);
|
|
93
|
-
return _jsx(Component, {
|
|
94
|
-
field: fieldState,
|
|
95
|
-
props: extraProps
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
return React.memo(FieldComponent);
|
|
99
|
-
};
|
|
100
|
-
const makeArrayFieldComponent = (fieldKey, def, stateAtom, errorsAtom, submitCountAtom, dirtyFieldsAtom, parsedMode, getOrCreateValidationAtom, getOrCreateFieldAtoms, operations, componentMap) => {
|
|
101
|
-
const isStructSchema = AST.isTypeLiteral(def.itemSchema.ast);
|
|
102
|
-
const ArrayWrapper = ({
|
|
103
|
-
children
|
|
104
|
-
}) => {
|
|
105
|
-
const arrayCtx = useContext(ArrayItemContext);
|
|
106
|
-
const [formStateOption, setFormState] = useAtom(stateAtom);
|
|
107
|
-
const formState = Option.getOrThrow(formStateOption);
|
|
108
|
-
const fieldPath = arrayCtx ? `${arrayCtx.parentPath}.${fieldKey}` : fieldKey;
|
|
109
|
-
const items = React.useMemo(() => getNestedValue(formState.values, fieldPath) ?? [], [formState.values, fieldPath]);
|
|
110
|
-
const append = React.useCallback(value => {
|
|
111
|
-
setFormState(prev => {
|
|
112
|
-
if (Option.isNone(prev)) return prev;
|
|
113
|
-
return Option.some(operations.appendArrayItem(prev.value, fieldPath, def.itemSchema, value));
|
|
114
|
-
});
|
|
115
|
-
}, [fieldPath, setFormState]);
|
|
116
|
-
const remove = React.useCallback(index => {
|
|
117
|
-
setFormState(prev => {
|
|
118
|
-
if (Option.isNone(prev)) return prev;
|
|
119
|
-
return Option.some(operations.removeArrayItem(prev.value, fieldPath, index));
|
|
120
|
-
});
|
|
121
|
-
}, [fieldPath, setFormState]);
|
|
122
|
-
const swap = React.useCallback((indexA, indexB) => {
|
|
123
|
-
setFormState(prev => {
|
|
124
|
-
if (Option.isNone(prev)) return prev;
|
|
125
|
-
return Option.some(operations.swapArrayItems(prev.value, fieldPath, indexA, indexB));
|
|
126
|
-
});
|
|
127
|
-
}, [fieldPath, setFormState]);
|
|
128
|
-
const move = React.useCallback((from, to) => {
|
|
129
|
-
setFormState(prev => {
|
|
130
|
-
if (Option.isNone(prev)) return prev;
|
|
131
|
-
return Option.some(operations.moveArrayItem(prev.value, fieldPath, from, to));
|
|
132
|
-
});
|
|
133
|
-
}, [fieldPath, setFormState]);
|
|
134
|
-
return _jsx(_Fragment, {
|
|
135
|
-
children: children({
|
|
136
|
-
items,
|
|
137
|
-
append,
|
|
138
|
-
remove,
|
|
139
|
-
swap,
|
|
140
|
-
move
|
|
141
|
-
})
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
const ItemWrapper = ({
|
|
145
|
-
children,
|
|
146
|
-
index
|
|
147
|
-
}) => {
|
|
148
|
-
const arrayCtx = useContext(ArrayItemContext);
|
|
149
|
-
const setFormState = useAtomSet(stateAtom);
|
|
150
|
-
const parentPath = arrayCtx ? `${arrayCtx.parentPath}.${fieldKey}` : fieldKey;
|
|
151
|
-
const itemPath = `${parentPath}[${index}]`;
|
|
152
|
-
const remove = React.useCallback(() => {
|
|
153
|
-
setFormState(prev => {
|
|
154
|
-
if (Option.isNone(prev)) return prev;
|
|
155
|
-
return Option.some(operations.removeArrayItem(prev.value, parentPath, index));
|
|
156
|
-
});
|
|
157
|
-
}, [parentPath, index, setFormState]);
|
|
158
|
-
return _jsx(ArrayItemContext.Provider, {
|
|
159
|
-
value: {
|
|
160
|
-
index,
|
|
161
|
-
parentPath: itemPath
|
|
162
|
-
},
|
|
163
|
-
children: typeof children === "function" ? children({
|
|
164
|
-
remove
|
|
165
|
-
}) : children
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
|
-
const itemFieldComponents = {};
|
|
169
|
-
if (isStructSchema) {
|
|
170
|
-
const ast = def.itemSchema.ast;
|
|
171
|
-
for (const prop of ast.propertySignatures) {
|
|
172
|
-
const itemKey = prop.name;
|
|
173
|
-
const itemSchema = {
|
|
174
|
-
ast: prop.type
|
|
175
|
-
};
|
|
176
|
-
const itemDef = Field.makeField(itemKey, itemSchema);
|
|
177
|
-
const itemComponent = componentMap[itemKey];
|
|
178
|
-
itemFieldComponents[itemKey] = makeFieldComponent(itemKey, itemDef, errorsAtom, submitCountAtom, parsedMode, getOrCreateValidationAtom, getOrCreateFieldAtoms, itemComponent);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
const properties = {
|
|
182
|
-
Item: ItemWrapper,
|
|
183
|
-
...itemFieldComponents
|
|
184
|
-
};
|
|
185
|
-
return new Proxy(ArrayWrapper, {
|
|
186
|
-
get(target, prop) {
|
|
187
|
-
if (prop in properties) {
|
|
188
|
-
return properties[prop];
|
|
189
|
-
}
|
|
190
|
-
return Reflect.get(target, prop);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
const makeFieldComponents = (fields, stateAtom, errorsAtom, submitCountAtom, dirtyFieldsAtom, parsedMode, getOrCreateValidationAtom, getOrCreateFieldAtoms, operations, componentMap) => {
|
|
195
|
-
const components = {};
|
|
196
|
-
for (const [key, def] of Object.entries(fields)) {
|
|
197
|
-
if (Field.isArrayFieldDef(def)) {
|
|
198
|
-
const arrayComponentMap = componentMap[key];
|
|
199
|
-
components[key] = makeArrayFieldComponent(key, def, stateAtom, errorsAtom, submitCountAtom, dirtyFieldsAtom, parsedMode, getOrCreateValidationAtom, getOrCreateFieldAtoms, operations, arrayComponentMap);
|
|
200
|
-
} else if (Field.isFieldDef(def)) {
|
|
201
|
-
const fieldComponent = componentMap[key];
|
|
202
|
-
components[key] = makeFieldComponent(key, def, errorsAtom, submitCountAtom, parsedMode, getOrCreateValidationAtom, getOrCreateFieldAtoms, fieldComponent);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return components;
|
|
206
|
-
};
|
|
207
|
-
export const make = (self, options) => {
|
|
208
|
-
const {
|
|
209
|
-
fields: components,
|
|
210
|
-
mode,
|
|
211
|
-
onSubmit,
|
|
212
|
-
runtime: providedRuntime,
|
|
213
|
-
reactivityKeys
|
|
214
|
-
} = options;
|
|
215
|
-
const runtime = providedRuntime ?? Atom.runtime(Layer.empty);
|
|
216
|
-
const parsedMode = Mode.parse(mode);
|
|
217
|
-
const {
|
|
218
|
-
fields
|
|
219
|
-
} = self;
|
|
220
|
-
const formAtoms = FormAtoms.make({
|
|
221
|
-
formBuilder: self,
|
|
222
|
-
runtime,
|
|
223
|
-
onSubmit,
|
|
224
|
-
reactivityKeys
|
|
225
|
-
});
|
|
226
|
-
const {
|
|
227
|
-
combinedSchema,
|
|
228
|
-
dirtyFieldsAtom,
|
|
229
|
-
errorsAtom,
|
|
230
|
-
fieldRefs,
|
|
231
|
-
getFieldIsDirty,
|
|
232
|
-
getFieldValue,
|
|
233
|
-
getOrCreateFieldAtoms,
|
|
234
|
-
getOrCreateValidationAtom,
|
|
235
|
-
hasChangedSinceSubmitAtom,
|
|
236
|
-
isDirtyAtom,
|
|
237
|
-
keepAliveActiveAtom,
|
|
238
|
-
lastSubmittedValuesAtom,
|
|
239
|
-
mountAtom,
|
|
240
|
-
operations,
|
|
241
|
-
resetAtom,
|
|
242
|
-
revertToLastSubmitAtom,
|
|
243
|
-
rootErrorAtom,
|
|
244
|
-
setValue,
|
|
245
|
-
setValuesAtom,
|
|
246
|
-
stateAtom,
|
|
247
|
-
submitAtom,
|
|
248
|
-
submitCountAtom,
|
|
249
|
-
valuesAtom
|
|
250
|
-
} = formAtoms;
|
|
251
|
-
const InitializeComponent = ({
|
|
252
|
-
children,
|
|
253
|
-
defaultValues
|
|
254
|
-
}) => {
|
|
255
|
-
const registry = React.useContext(RegistryContext);
|
|
256
|
-
const state = useAtomValue(stateAtom);
|
|
257
|
-
const setFormState = useAtomSet(stateAtom);
|
|
258
|
-
const callSubmit = useAtomSet(submitAtom);
|
|
259
|
-
const isInitializedRef = React.useRef(false);
|
|
260
|
-
const [isInitialized, setIsInitialized] = React.useState(false);
|
|
261
|
-
React.useEffect(() => {
|
|
262
|
-
const isKeptAlive = registry.get(keepAliveActiveAtom);
|
|
263
|
-
const currentState = registry.get(stateAtom);
|
|
264
|
-
if (!isKeptAlive) {
|
|
265
|
-
setFormState(Option.some(operations.createInitialState(defaultValues)));
|
|
266
|
-
} else if (Option.isNone(currentState)) {
|
|
267
|
-
setFormState(Option.some(operations.createInitialState(defaultValues)));
|
|
268
|
-
}
|
|
269
|
-
isInitializedRef.current = true;
|
|
270
|
-
setIsInitialized(true);
|
|
271
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- mount-only
|
|
272
|
-
}, [registry]);
|
|
273
|
-
const debouncedAutoSubmit = useDebounced(() => {
|
|
274
|
-
const stateOption = registry.get(stateAtom);
|
|
275
|
-
if (Option.isNone(stateOption)) return;
|
|
276
|
-
callSubmit(undefined);
|
|
277
|
-
}, parsedMode.autoSubmit && parsedMode.validation === "onChange" ? parsedMode.debounce : null);
|
|
278
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
279
|
-
// Auto-Submit Coordination
|
|
280
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
281
|
-
// Two-subscription model to avoid infinite loop:
|
|
282
|
-
// - Stream 1 reacts to value changes (reference equality), triggers or queues submit
|
|
283
|
-
// - Stream 2 reacts to submit completion, flushes queued changes
|
|
284
|
-
//
|
|
285
|
-
// Single subscription to stateAtom cannot distinguish value changes from submit
|
|
286
|
-
// metadata updates (submitCount, lastSubmittedValues).
|
|
287
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
288
|
-
const lastValuesRef = React.useRef(null);
|
|
289
|
-
const pendingChangesRef = React.useRef(false);
|
|
290
|
-
const wasSubmittingRef = React.useRef(false);
|
|
291
|
-
useAtomSubscribe(stateAtom, React.useCallback(() => {
|
|
292
|
-
if (!isInitializedRef.current) return;
|
|
293
|
-
const state = registry.get(stateAtom);
|
|
294
|
-
if (Option.isNone(state)) return;
|
|
295
|
-
const currentValues = state.value.values;
|
|
296
|
-
// Reference equality filters out submit metadata changes.
|
|
297
|
-
// Works because setFieldValue creates new values object (immutable update).
|
|
298
|
-
if (currentValues === lastValuesRef.current) return;
|
|
299
|
-
lastValuesRef.current = currentValues;
|
|
300
|
-
if (!parsedMode.autoSubmit || parsedMode.validation !== "onChange") return;
|
|
301
|
-
const submitResult = registry.get(submitAtom);
|
|
302
|
-
if (submitResult.waiting) {
|
|
303
|
-
pendingChangesRef.current = true;
|
|
304
|
-
} else {
|
|
305
|
-
debouncedAutoSubmit();
|
|
306
|
-
}
|
|
307
|
-
}, [debouncedAutoSubmit, registry]), {
|
|
308
|
-
immediate: false
|
|
309
|
-
});
|
|
310
|
-
useAtomSubscribe(submitAtom, React.useCallback(result => {
|
|
311
|
-
if (!parsedMode.autoSubmit || parsedMode.validation !== "onChange") return;
|
|
312
|
-
const isSubmitting = result.waiting;
|
|
313
|
-
const wasSubmitting = wasSubmittingRef.current;
|
|
314
|
-
wasSubmittingRef.current = isSubmitting;
|
|
315
|
-
// Flush queued changes when submit completes
|
|
316
|
-
if (wasSubmitting && !isSubmitting) {
|
|
317
|
-
if (pendingChangesRef.current) {
|
|
318
|
-
pendingChangesRef.current = false;
|
|
319
|
-
debouncedAutoSubmit();
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}, [debouncedAutoSubmit]), {
|
|
323
|
-
immediate: false
|
|
324
|
-
});
|
|
325
|
-
const onBlurAutoSubmit = React.useCallback(() => {
|
|
326
|
-
if (!parsedMode.autoSubmit || parsedMode.validation !== "onBlur") return;
|
|
327
|
-
const stateOption = registry.get(stateAtom);
|
|
328
|
-
if (Option.isNone(stateOption)) return;
|
|
329
|
-
const {
|
|
330
|
-
lastSubmittedValues,
|
|
331
|
-
values
|
|
332
|
-
} = stateOption.value;
|
|
333
|
-
if (Option.isSome(lastSubmittedValues) && values === lastSubmittedValues.value.encoded) return;
|
|
334
|
-
callSubmit(undefined);
|
|
335
|
-
}, [registry, callSubmit]);
|
|
336
|
-
if (!isInitialized) return null;
|
|
337
|
-
if (Option.isNone(state)) return null;
|
|
338
|
-
return _jsx(AutoSubmitContext.Provider, {
|
|
339
|
-
value: onBlurAutoSubmit,
|
|
340
|
-
children: children
|
|
341
|
-
});
|
|
342
|
-
};
|
|
343
|
-
const fieldComponents = makeFieldComponents(fields, stateAtom, errorsAtom, submitCountAtom, dirtyFieldsAtom, parsedMode, getOrCreateValidationAtom, getOrCreateFieldAtoms, operations, components);
|
|
344
|
-
const KeepAlive = () => {
|
|
345
|
-
const setKeepAliveActive = useAtomSet(keepAliveActiveAtom);
|
|
346
|
-
React.useLayoutEffect(() => {
|
|
347
|
-
setKeepAliveActive(true);
|
|
348
|
-
return () => setKeepAliveActive(false);
|
|
349
|
-
}, [setKeepAliveActive]);
|
|
350
|
-
useAtomMount(mountAtom);
|
|
351
|
-
return null;
|
|
352
|
-
};
|
|
353
|
-
return {
|
|
354
|
-
values: valuesAtom,
|
|
355
|
-
isDirty: isDirtyAtom,
|
|
356
|
-
hasChangedSinceSubmit: hasChangedSinceSubmitAtom,
|
|
357
|
-
lastSubmittedValues: lastSubmittedValuesAtom,
|
|
358
|
-
submitCount: submitCountAtom,
|
|
359
|
-
rootError: rootErrorAtom,
|
|
360
|
-
schema: combinedSchema,
|
|
361
|
-
fields: fieldRefs,
|
|
362
|
-
Initialize: InitializeComponent,
|
|
363
|
-
submit: submitAtom,
|
|
364
|
-
reset: resetAtom,
|
|
365
|
-
revertToLastSubmit: revertToLastSubmitAtom,
|
|
366
|
-
setValues: setValuesAtom,
|
|
367
|
-
setValue,
|
|
368
|
-
getFieldValue,
|
|
369
|
-
getFieldIsDirty,
|
|
370
|
-
mount: mountAtom,
|
|
371
|
-
KeepAlive,
|
|
372
|
-
...fieldComponents
|
|
373
|
-
};
|
|
374
|
-
};
|
|
375
|
-
//# sourceMappingURL=FormReact.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormReact.js","names":["RegistryContext","useAtom","useAtomMount","useAtomSet","useAtomSubscribe","useAtomValue","Atom","Field","FormAtoms","Mode","Validation","getNestedValue","Cause","Layer","Option","ParseResult","AST","React","createContext","useContext","useDebounced","ArrayItemContext","AutoSubmitContext","makeFieldComponent","fieldKey","fieldDef","errorsAtom","submitCountAtom","parsedMode","getOrCreateValidationAtom","getOrCreateFieldAtoms","Component","FieldComponent","extraProps","arrayCtx","autoSubmitOnBlur","fieldPath","parentPath","errorAtom","isDirtyAtom","touchedAtom","valueAtom","useMemo","value","setValue","isTouched","setTouched","storedError","submitCount","validationAtom","schema","validationResult","validateImmediate","shouldDebounceValidation","validation","debounce","autoSubmit","validate","prevValueRef","useRef","useEffect","current","shouldValidate","livePerFieldError","_tag","parseError","failureOption","cause","isSome","isParseError","extractFirstError","none","isValidating","waiting","validationError","shouldHideStoredError","source","some","message","onChange","useCallback","newValue","onBlur","isDirty","shouldShowError","fieldState","error","_jsx","field","props","memo","makeArrayFieldComponent","def","stateAtom","dirtyFieldsAtom","operations","componentMap","isStructSchema","isTypeLiteral","itemSchema","ast","ArrayWrapper","children","formStateOption","setFormState","formState","getOrThrow","items","values","append","prev","isNone","appendArrayItem","remove","index","removeArrayItem","swap","indexA","indexB","swapArrayItems","move","from","to","moveArrayItem","_Fragment","ItemWrapper","itemPath","Provider","itemFieldComponents","prop","propertySignatures","itemKey","name","type","itemDef","makeField","itemComponent","properties","Item","Proxy","get","target","Reflect","makeFieldComponents","fields","components","key","Object","entries","isArrayFieldDef","arrayComponentMap","isFieldDef","fieldComponent","make","self","options","mode","onSubmit","runtime","providedRuntime","reactivityKeys","empty","parse","formAtoms","formBuilder","combinedSchema","fieldRefs","getFieldIsDirty","getFieldValue","hasChangedSinceSubmitAtom","keepAliveActiveAtom","lastSubmittedValuesAtom","mountAtom","resetAtom","revertToLastSubmitAtom","rootErrorAtom","setValuesAtom","submitAtom","valuesAtom","InitializeComponent","defaultValues","registry","state","callSubmit","isInitializedRef","isInitialized","setIsInitialized","useState","isKeptAlive","currentState","createInitialState","debouncedAutoSubmit","stateOption","undefined","lastValuesRef","pendingChangesRef","wasSubmittingRef","currentValues","submitResult","immediate","result","isSubmitting","wasSubmitting","onBlurAutoSubmit","lastSubmittedValues","encoded","fieldComponents","KeepAlive","setKeepAliveActive","useLayoutEffect","hasChangedSinceSubmit","rootError","Initialize","submit","reset","revertToLastSubmit","setValues","mount"],"sources":["../../src/FormReact.tsx"],"sourcesContent":[null],"mappings":";AAAA,SACEA,eAAe,EACfC,OAAO,EACPC,YAAY,EACZC,UAAU,EACVC,gBAAgB,EAChBC,YAAY,QACP,yBAAyB;AAChC,OAAO,KAAKC,IAAI,MAAM,wBAAwB;AAC9C,SAASC,KAAK,EAAEC,SAAS,EAAEC,IAAI,EAAEC,UAAU,QAAQ,2BAA2B;AAE9E,SAASC,cAAc,QAAQ,gCAAgC;AAC/D,OAAO,KAAKC,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,WAAW,MAAM,oBAAoB;AAEjD,OAAO,KAAKC,GAAG,MAAM,kBAAkB;AACvC,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,aAAa,EAAEC,UAAU,QAAQ,OAAO;AACjD,SAASC,YAA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AAU,EACVC,eAAe,EACfmE,eAAe,EACflE,UAAU,EACVC,yBAAyB,EACzBC,qBAAqB,EACrBiE,UAAU,EACVkD,UAAU,CACX;EAED,MAAM8D,SAAS,GAAaA,CAAA,KAAK;IAC/B,MAAMC,kBAAkB,GAAG7M,UAAU,CAACuK,mBAAmB,CAAC;IAE1DzJ,KAAK,CAACgM,eAAe,CAAC,MAAK;MACzBD,kBAAkB,CAAC,IAAI,CAAC;MACxB,OAAO,MAAMA,kBAAkB,CAAC,KAAK,CAAC;IACxC,CAAC,EAAE,CAACA,kBAAkB,CAAC,CAAC;IAExB9M,YAAY,CAAC0K,SAAS,CAAC;IACvB,OAAO,IAAI;EACb,CAAC;EAED,OAAO;IACLhE,MAAM,EAAEsE,UAAU;IAClB/F,OAAO,EAAE5C,WAAW;IACpB2K,qBAAqB,EAAEzC,yBAAyB;IAChDmC,mBAAmB,EAAEjC,uBAAuB;IAC5C3H,WAAW,EAAErB,eAAe;IAC5BwL,SAAS,EAAEpC,aAAa;IACxB7H,MAAM,EAAEmH,cAAc;IACtBrB,MAAM,EAAEsB,SAAS;IACjB8C,UAAU,EAAEjC,mBAAmB;IAC/BkC,MAAM,EAAEpC,UAAU;IAClBqC,KAAK,EAAEzC,SAAS;IAChB0C,kBAAkB,EAAEzC,sBAAsB;IAC1C0C,SAAS,EAAExC,aAAa;IACxBpI,QAAQ;IACR4H,aAAa;IACbD,eAAe;IACfkD,KAAK,EAAE7C,SAAS;IAChBmC,SAAS;IACT,GAAGD;GACJ;AACH,CAAC","ignoreList":[]}
|
package/dist/esm/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Re-export commonly used modules from the core package.
|
|
3
|
-
*/
|
|
4
|
-
export { Field, FormBuilder } from "@lucas-barake/effect-form";
|
|
5
|
-
/**
|
|
6
|
-
* React bindings for @lucas-barake/effect-form.
|
|
7
|
-
*/
|
|
8
|
-
export * as FormReact from "./FormReact.js";
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Field","FormBuilder","FormReact"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,SAASA,KAAK,EAAEC,WAAW,QAAQ,2BAA2B;AAE9D;;;AAGA,OAAO,KAAKC,SAAS,MAAM,gBAAgB","ignoreList":[]}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
export const useDebounced = (fn, delayMs) => {
|
|
3
|
-
const timeoutRef = React.useRef(null);
|
|
4
|
-
const fnRef = React.useRef(fn);
|
|
5
|
-
React.useEffect(() => {
|
|
6
|
-
fnRef.current = fn;
|
|
7
|
-
});
|
|
8
|
-
React.useEffect(() => {
|
|
9
|
-
return () => {
|
|
10
|
-
if (timeoutRef.current !== null) {
|
|
11
|
-
clearTimeout(timeoutRef.current);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
}, []);
|
|
15
|
-
return React.useMemo(() => (...args) => {
|
|
16
|
-
if (delayMs === null || delayMs === 0) {
|
|
17
|
-
fnRef.current(...args);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
if (timeoutRef.current !== null) {
|
|
21
|
-
clearTimeout(timeoutRef.current);
|
|
22
|
-
}
|
|
23
|
-
timeoutRef.current = setTimeout(() => {
|
|
24
|
-
fnRef.current(...args);
|
|
25
|
-
timeoutRef.current = null;
|
|
26
|
-
}, delayMs);
|
|
27
|
-
}, [delayMs]);
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=use-debounced.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-debounced.js","names":["React","useDebounced","fn","delayMs","timeoutRef","useRef","fnRef","useEffect","current","clearTimeout","useMemo","args","setTimeout"],"sources":["../../../src/internal/use-debounced.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,OAAO,MAAMC,YAAY,GAAGA,CAC1BC,EAAK,EACLC,OAAsB,KACjB;EACL,MAAMC,UAAU,GAAGJ,KAAK,CAACK,MAAM,CAAuC,IAAI,CAAC;EAC3E,MAAMC,KAAK,GAAGN,KAAK,CAACK,MAAM,CAACH,EAAE,CAAC;EAE9BF,KAAK,CAACO,SAAS,CAAC,MAAK;IACnBD,KAAK,CAACE,OAAO,GAAGN,EAAE;EACpB,CAAC,CAAC;EAEFF,KAAK,CAACO,SAAS,CAAC,MAAK;IACnB,OAAO,MAAK;MACV,IAAIH,UAAU,CAACI,OAAO,KAAK,IAAI,EAAE;QAC/BC,YAAY,CAACL,UAAU,CAACI,OAAO,CAAC;MAClC;IACF,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOR,KAAK,CAACU,OAAO,CAClB,MACG,CAAC,GAAGC,IAAmB,KAAI;IAC1B,IAAIR,OAAO,KAAK,IAAI,IAAIA,OAAO,KAAK,CAAC,EAAE;MACrCG,KAAK,CAACE,OAAO,CAAC,GAAGG,IAAI,CAAC;MACtB;IACF;IACA,IAAIP,UAAU,CAACI,OAAO,KAAK,IAAI,EAAE;MAC/BC,YAAY,CAACL,UAAU,CAACI,OAAO,CAAC;IAClC;IACAJ,UAAU,CAACI,OAAO,GAAGI,UAAU,CAAC,MAAK;MACnCN,KAAK,CAACE,OAAO,CAAC,GAAGG,IAAI,CAAC;MACtBP,UAAU,CAACI,OAAO,GAAG,IAAI;IAC3B,CAAC,EAAEL,OAAO,CAAC;EACb,CAAO,EACT,CAACA,OAAO,CAAC,CACV;AACH,CAAC","ignoreList":[]}
|
package/dist/esm/package.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
export const useDebounced = <T extends (...args: ReadonlyArray<any>) => void>(
|
|
4
|
-
fn: T,
|
|
5
|
-
delayMs: number | null,
|
|
6
|
-
): T => {
|
|
7
|
-
const timeoutRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
8
|
-
const fnRef = React.useRef(fn);
|
|
9
|
-
|
|
10
|
-
React.useEffect(() => {
|
|
11
|
-
fnRef.current = fn;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
React.useEffect(() => {
|
|
15
|
-
return () => {
|
|
16
|
-
if (timeoutRef.current !== null) {
|
|
17
|
-
clearTimeout(timeoutRef.current);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}, []);
|
|
21
|
-
|
|
22
|
-
return React.useMemo(
|
|
23
|
-
() =>
|
|
24
|
-
((...args: Parameters<T>) => {
|
|
25
|
-
if (delayMs === null || delayMs === 0) {
|
|
26
|
-
fnRef.current(...args);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (timeoutRef.current !== null) {
|
|
30
|
-
clearTimeout(timeoutRef.current);
|
|
31
|
-
}
|
|
32
|
-
timeoutRef.current = setTimeout(() => {
|
|
33
|
-
fnRef.current(...args);
|
|
34
|
-
timeoutRef.current = null;
|
|
35
|
-
}, delayMs);
|
|
36
|
-
}) as T,
|
|
37
|
-
[delayMs],
|
|
38
|
-
);
|
|
39
|
-
};
|