0.2.1 #26
@@ -1,4 +1,4 @@
|
||||
import { Array, Cause, Chunk, type Duration, Effect, Equal, Exit, Fiber, flow, identity, Option, ParseResult, Pipeable, Predicate, Ref, Schema, type Scope, Stream } from "effect"
|
||||
import { Array, Cause, Chunk, type Duration, Effect, Equal, Exit, Fiber, flow, Hash, identity, Option, ParseResult, Pipeable, Predicate, Ref, Schema, type Scope, Stream } from "effect"
|
||||
import type { NoSuchElementException } from "effect/Cause"
|
||||
import type * as React from "react"
|
||||
import * as Component from "./Component.js"
|
||||
@@ -54,6 +54,21 @@ extends Pipeable.Class() implements Form<A, I, R, SA, SE, SR, SP> {
|
||||
}
|
||||
}
|
||||
|
||||
const FormFieldKeySymbol = Symbol.for("@effect-fc/Form/FormFieldKeySymbol")
|
||||
class FormFieldKey implements Equal.Equal {
|
||||
[FormFieldKeySymbol] = FormFieldKeySymbol
|
||||
constructor(readonly a: PropertyPath.PropertyPath) {}
|
||||
|
||||
[Equal.symbol](that: Equal.Equal) {
|
||||
return Predicate.hasProperty(that, FormFieldKeySymbol)
|
||||
? PropertyPath.equivalence(this.a, (that as unknown as FormFieldKey).a)
|
||||
: false
|
||||
}
|
||||
[Hash.symbol]() {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
export const isForm = (u: unknown): u is Form<unknown, unknown, unknown, unknown, unknown, unknown> => Predicate.hasProperty(u, FormTypeId)
|
||||
|
||||
export namespace make {
|
||||
@@ -204,8 +219,8 @@ export const service = <A, I = A, R = never, SA = void, SE = A, SR = never, SP =
|
||||
form => Effect.forkScoped(run(form)),
|
||||
)
|
||||
|
||||
export const field = <A, I, R, SA, SE, SR, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
||||
self: Form<A, I, R, SA, SE, SR>,
|
||||
export const field = <A, I, R, SA, SE, SR, SP, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
||||
self: Form<A, I, R, SA, SE, SR, SP>,
|
||||
path: P,
|
||||
): FormField<PropertyPath.ValueFromPath<A, P>, PropertyPath.ValueFromPath<I, P>> => new FormFieldImpl(
|
||||
Subscribable.mapEffect(self.valueRef, Option.match({
|
||||
@@ -256,6 +271,26 @@ extends Pipeable.Class() implements FormField<A, I> {
|
||||
|
||||
export const isFormField = (u: unknown): u is FormField<unknown, unknown> => Predicate.hasProperty(u, FormFieldTypeId)
|
||||
|
||||
export const makeFormField = <A, I, R, SA, SE, SR, SP, const P extends PropertyPath.Paths<NoInfer<I>>>(
|
||||
self: Form<A, I, R, SA, SE, SR, SP>,
|
||||
path: P,
|
||||
): FormField<PropertyPath.ValueFromPath<A, P>, PropertyPath.ValueFromPath<I, P>> => new FormFieldImpl(
|
||||
Subscribable.mapEffect(self.valueRef, Option.match({
|
||||
onSome: v => Option.map(PropertyPath.get(v, path), Option.some),
|
||||
onNone: () => Option.some(Option.none()),
|
||||
})),
|
||||
SubscriptionSubRef.makeFromPath(self.encodedValueRef, path),
|
||||
Subscribable.mapEffect(self.errorRef, Option.match({
|
||||
onSome: flow(
|
||||
ParseResult.ArrayFormatter.formatError,
|
||||
Effect.map(Array.filter(issue => PropertyPath.equivalence(issue.path, path))),
|
||||
),
|
||||
onNone: () => Effect.succeed([]),
|
||||
})),
|
||||
Subscribable.map(self.validationFiberRef, Option.isSome),
|
||||
Subscribable.map(self.submitResultRef, result => Result.isRunning(result) || Result.isRefreshing(result)),
|
||||
)
|
||||
|
||||
|
||||
export namespace useInput {
|
||||
export interface Options {
|
||||
|
||||
Reference in New Issue
Block a user