|
|
|
@@ -233,6 +233,14 @@ export const service = <A, I = A, R = never, MA = void, ME = never, MR = never,
|
|
|
|
|
form => Effect.forkScoped(form.run),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filterIssuesByPath = (
|
|
|
|
|
issues: readonly ParseResult.ArrayFormatterIssue[],
|
|
|
|
|
path: readonly PropertyKey[],
|
|
|
|
|
): readonly ParseResult.ArrayFormatterIssue[] => Array.filter(issues, issue =>
|
|
|
|
|
issue.path.length >= path.length && Array.every(path, (p, i) => p === issue.path[i])
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
export const focusObjectField = <P extends readonly PropertyKey[], A extends object, I extends object, ER, EW, K extends keyof A & keyof I>(
|
|
|
|
|
self: Form<P, A, I, ER, EW>,
|
|
|
|
|
key: K,
|
|
|
|
@@ -242,9 +250,26 @@ export const focusObjectField = <P extends readonly PropertyKey[], A extends obj
|
|
|
|
|
|
|
|
|
|
return new FormImpl(
|
|
|
|
|
path,
|
|
|
|
|
Subscribable.map(form.value, Option.map(a => a[key])),
|
|
|
|
|
Subscribable.mapOption(form.value, a => a[key]),
|
|
|
|
|
Lens.focusObjectField(form.encodedValue, key),
|
|
|
|
|
Subscribable.map(form.issues, issues => Array.filter(issues, issue => issue.path.length >= path.length && Array.every(path, (p, i) => p === issue.path[i]))),
|
|
|
|
|
Subscribable.map(form.issues, issues => filterIssuesByPath(issues, path)),
|
|
|
|
|
form.isValidating,
|
|
|
|
|
form.canSubmit,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const focusArrayAt = <P extends readonly PropertyKey[], A extends readonly any[], I extends readonly any[], ER, EW>(
|
|
|
|
|
self: Form<P, A, I, ER, EW>,
|
|
|
|
|
index: number,
|
|
|
|
|
): Form<readonly [...P, number], A[number], I[number], ER | Cause.NoSuchElementException, EW | Cause.NoSuchElementException> => {
|
|
|
|
|
const form = self as FormImpl<P, A, I, ER, EW>
|
|
|
|
|
const path = [...form.path, index] as const
|
|
|
|
|
|
|
|
|
|
return new FormImpl(
|
|
|
|
|
path,
|
|
|
|
|
Subscribable.mapOptionEffect(form.value, Array.get(index)),
|
|
|
|
|
Lens.focusArrayAt(form.encodedValue, index),
|
|
|
|
|
Subscribable.map(form.issues, issues => filterIssuesByPath(issues, path)),
|
|
|
|
|
form.isValidating,
|
|
|
|
|
form.canSubmit,
|
|
|
|
|
)
|
|
|
|
|