@playfast/reform-forms-react 0.0.7 → 0.0.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.
- package/package.json +2 -2
- package/src/formUi.typecheck.tsx +62 -0
- package/src/index.tsx +132 -0
- package/dist/index.d.ts +0 -48
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -45
- package/dist/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playfast/reform-forms-react",
|
|
3
3
|
"playbook": "./playbook",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "React bindings for @playfast/forms — render a typed reform form View with scoped field/array/variant helpers.",
|
|
7
7
|
"keywords": [
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"./*": "./src/*.tsx"
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
|
-
"
|
|
30
|
+
"src",
|
|
31
31
|
"README.md"
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Type-level checks enforced by `tsc --noEmit`.
|
|
2
|
+
|
|
3
|
+
import { Schema as S } from 'effect'
|
|
4
|
+
import { ui, type ViewImpl, type UiContract } from '@playfast/reform'
|
|
5
|
+
import { Form } from '@playfast/reform-forms'
|
|
6
|
+
import { FormUi, type FieldComponent } from './index'
|
|
7
|
+
|
|
8
|
+
const Payment = S.Union(
|
|
9
|
+
S.TaggedStruct('Card', { cardNumber: S.String }),
|
|
10
|
+
S.TaggedStruct('Paypal', { email: S.String }),
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
const CheckoutSchema = S.Struct({
|
|
14
|
+
email: S.String,
|
|
15
|
+
age: S.Number,
|
|
16
|
+
items: S.Array(S.Struct({ name: S.String })),
|
|
17
|
+
payment: Payment,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
class CheckoutForm extends Form.make('CheckoutTypecheckForm', { schema: CheckoutSchema }) {}
|
|
21
|
+
|
|
22
|
+
interface CheckoutContract extends UiContract {
|
|
23
|
+
readonly props: { readonly form: Form.View<typeof CheckoutForm> }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class CheckoutUi extends ui('CheckoutTypecheckUi')<CheckoutContract>() {}
|
|
27
|
+
|
|
28
|
+
const TextInput: FieldComponent<string> = () => null
|
|
29
|
+
const NumberInput: FieldComponent<number> = () => null
|
|
30
|
+
|
|
31
|
+
export const ok: ViewImpl<CheckoutContract> = FormUi.make(CheckoutUi, CheckoutForm, ({ field, array, variant }) => (
|
|
32
|
+
<>
|
|
33
|
+
{field('email').as(TextInput)}
|
|
34
|
+
{field('age').as(NumberInput)}
|
|
35
|
+
{array('items', ({ items }) => (
|
|
36
|
+
<>{items.map((item) => item.field('name').as(TextInput))}</>
|
|
37
|
+
))}
|
|
38
|
+
{variant('payment', {
|
|
39
|
+
Card: ({ field }) => field('cardNumber').as(TextInput),
|
|
40
|
+
Paypal: ({ field }) => field('email').as(TextInput),
|
|
41
|
+
})}
|
|
42
|
+
</>
|
|
43
|
+
))
|
|
44
|
+
|
|
45
|
+
export const badPath: ViewImpl<CheckoutContract> = FormUi.make(CheckoutUi, CheckoutForm, ({ field }) => (
|
|
46
|
+
// @ts-expect-error unknown field path
|
|
47
|
+
<>{field('missing').as(TextInput)}</>
|
|
48
|
+
))
|
|
49
|
+
|
|
50
|
+
export const badComponent: ViewImpl<CheckoutContract> = FormUi.make(CheckoutUi, CheckoutForm, ({ field }) => (
|
|
51
|
+
// @ts-expect-error age is a number field, not a string field
|
|
52
|
+
<>{field('age').as(TextInput)}</>
|
|
53
|
+
))
|
|
54
|
+
|
|
55
|
+
export const badVariant: ViewImpl<CheckoutContract> = FormUi.make(CheckoutUi, CheckoutForm, ({ variant }) => (
|
|
56
|
+
<>
|
|
57
|
+
{/* @ts-expect-error Paypal is required for exhaustive variant mapping */}
|
|
58
|
+
{variant('payment', {
|
|
59
|
+
Card: ({ field }) => field('cardNumber').as(TextInput),
|
|
60
|
+
})}
|
|
61
|
+
</>
|
|
62
|
+
))
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { createElement, type ComponentType, type ReactNode } from 'react'
|
|
2
|
+
import { Ui, type UiClass, type UiContract, type ViewImpl } from '@playfast/reform'
|
|
3
|
+
import type {
|
|
4
|
+
ArrayItem,
|
|
5
|
+
ArrayPath,
|
|
6
|
+
FieldBinding,
|
|
7
|
+
FieldPath,
|
|
8
|
+
PathValue,
|
|
9
|
+
Values,
|
|
10
|
+
VariantBody,
|
|
11
|
+
VariantPath,
|
|
12
|
+
VariantTag,
|
|
13
|
+
VariantValue,
|
|
14
|
+
View,
|
|
15
|
+
AnyForm,
|
|
16
|
+
} from '@playfast/reform-forms'
|
|
17
|
+
import { joinPath } from '@playfast/reform-forms'
|
|
18
|
+
|
|
19
|
+
export type FieldComponent<A, P extends object = {}> = ComponentType<{ readonly field: FieldBinding<A> } & P>
|
|
20
|
+
|
|
21
|
+
export interface FieldHandle<A> {
|
|
22
|
+
as(component: FieldComponent<A>): ReactNode
|
|
23
|
+
as<P extends object>(component: FieldComponent<A, P>, props: P): ReactNode
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ArrayItemScope<Item> extends ScopeHelpers<Item> {
|
|
27
|
+
readonly key: string
|
|
28
|
+
readonly index: number
|
|
29
|
+
readonly value: Item
|
|
30
|
+
readonly remove: () => void
|
|
31
|
+
readonly move: (to: number) => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ArrayRenderArgs<Item> {
|
|
35
|
+
readonly items: ReadonlyArray<ArrayItemScope<Item>>
|
|
36
|
+
readonly append: (value?: Item) => void
|
|
37
|
+
readonly remove: (index: number) => void
|
|
38
|
+
readonly move: (from: number, to: number) => void
|
|
39
|
+
readonly swap: (a: number, b: number) => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type VariantCases<V> = {
|
|
43
|
+
readonly [Tag in VariantTag<V>]: (scope: ScopeHelpers<VariantBody<V, Tag>>) => ReactNode
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ScopeHelpers<ScopeValues> {
|
|
47
|
+
readonly field: <P extends FieldPath<ScopeValues>>(path: P) => FieldHandle<PathValue<ScopeValues, P>>
|
|
48
|
+
readonly array: <P extends ArrayPath<ScopeValues>>(
|
|
49
|
+
path: P,
|
|
50
|
+
render: (args: ArrayRenderArgs<ArrayItem<ScopeValues, P>>) => ReactNode,
|
|
51
|
+
) => ReactNode
|
|
52
|
+
readonly variant: <P extends VariantPath<ScopeValues>>(
|
|
53
|
+
path: P,
|
|
54
|
+
cases: VariantCases<VariantValue<ScopeValues, P>>,
|
|
55
|
+
) => ReactNode
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface RootHelpers<F extends AnyForm> extends ScopeHelpers<Values<F>> {
|
|
59
|
+
readonly form: View<F>
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type ContractWithForm<F extends AnyForm> = UiContract & {
|
|
63
|
+
readonly props: { readonly form: View<F> }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const makeFieldHandle = <A,>(
|
|
67
|
+
field: FieldBinding<A>,
|
|
68
|
+
): FieldHandle<A> => ({
|
|
69
|
+
as: <P extends object>(component: FieldComponent<A, P>, props?: P): ReactNode =>
|
|
70
|
+
createElement(component, { ...(props ?? {}), field } as { readonly field: FieldBinding<A> } & P),
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const makeScope = <ScopeValues,>(
|
|
74
|
+
form: View<any>,
|
|
75
|
+
prefix: string,
|
|
76
|
+
): ScopeHelpers<ScopeValues> => {
|
|
77
|
+
const full = (path: string): string => joinPath(prefix, path)
|
|
78
|
+
return {
|
|
79
|
+
field: (path) => makeFieldHandle(form.field(full(path as string))),
|
|
80
|
+
array: (path, render) => {
|
|
81
|
+
const binding = form.array(full(path as string))
|
|
82
|
+
return render({
|
|
83
|
+
append: binding.append,
|
|
84
|
+
remove: binding.remove,
|
|
85
|
+
move: binding.move,
|
|
86
|
+
swap: binding.swap,
|
|
87
|
+
items: binding.items.map((item) => ({
|
|
88
|
+
...makeScope(form, `${binding.path}[${item.index}]`),
|
|
89
|
+
key: item.key,
|
|
90
|
+
index: item.index,
|
|
91
|
+
value: item.value as ArrayItem<ScopeValues, typeof path>,
|
|
92
|
+
remove: item.remove,
|
|
93
|
+
move: item.move,
|
|
94
|
+
})) as ReadonlyArray<ArrayItemScope<ArrayItem<ScopeValues, typeof path>>>,
|
|
95
|
+
})
|
|
96
|
+
},
|
|
97
|
+
variant: (path, cases) => {
|
|
98
|
+
const variantPath = full(path as string)
|
|
99
|
+
const value = form.variantValue(variantPath)
|
|
100
|
+
if (value === null || typeof value !== 'object' || !('_tag' in value)) return null
|
|
101
|
+
const tag = String((value as { readonly _tag: string })._tag)
|
|
102
|
+
const render = (cases as Record<string, (scope: ScopeHelpers<unknown>) => ReactNode>)[tag]
|
|
103
|
+
return render === undefined ? null : render(makeScope(form, variantPath))
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const make = <
|
|
109
|
+
F extends AnyForm,
|
|
110
|
+
C extends ContractWithForm<F>,
|
|
111
|
+
>(
|
|
112
|
+
contract: UiClass<C>,
|
|
113
|
+
_form: F,
|
|
114
|
+
render: (
|
|
115
|
+
helpers: RootHelpers<F> & { readonly props: C['props'] },
|
|
116
|
+
slots: Parameters<ViewImpl<C>>[1],
|
|
117
|
+
events: Parameters<ViewImpl<C>>[2],
|
|
118
|
+
) => ReactNode,
|
|
119
|
+
): ViewImpl<C> =>
|
|
120
|
+
Ui.make(contract, (props, slots, events) =>
|
|
121
|
+
render(
|
|
122
|
+
{
|
|
123
|
+
...makeScope<Values<F>>(props.form, ''),
|
|
124
|
+
form: props.form,
|
|
125
|
+
props,
|
|
126
|
+
},
|
|
127
|
+
slots,
|
|
128
|
+
events,
|
|
129
|
+
),
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
export const FormUi: { readonly make: typeof make } = { make }
|
package/dist/index.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { type ComponentType, type ReactNode } from 'react';
|
|
2
|
-
import { type UiClass, type UiContract, type ViewImpl } from '@playfast/reform';
|
|
3
|
-
import type { ArrayItem, ArrayPath, FieldBinding, FieldPath, PathValue, Values, VariantBody, VariantPath, VariantTag, VariantValue, View, AnyForm } from '@playfast/reform-forms';
|
|
4
|
-
export type FieldComponent<A, P extends object = {}> = ComponentType<{
|
|
5
|
-
readonly field: FieldBinding<A>;
|
|
6
|
-
} & P>;
|
|
7
|
-
export interface FieldHandle<A> {
|
|
8
|
-
as(component: FieldComponent<A>): ReactNode;
|
|
9
|
-
as<P extends object>(component: FieldComponent<A, P>, props: P): ReactNode;
|
|
10
|
-
}
|
|
11
|
-
export interface ArrayItemScope<Item> extends ScopeHelpers<Item> {
|
|
12
|
-
readonly key: string;
|
|
13
|
-
readonly index: number;
|
|
14
|
-
readonly value: Item;
|
|
15
|
-
readonly remove: () => void;
|
|
16
|
-
readonly move: (to: number) => void;
|
|
17
|
-
}
|
|
18
|
-
export interface ArrayRenderArgs<Item> {
|
|
19
|
-
readonly items: ReadonlyArray<ArrayItemScope<Item>>;
|
|
20
|
-
readonly append: (value?: Item) => void;
|
|
21
|
-
readonly remove: (index: number) => void;
|
|
22
|
-
readonly move: (from: number, to: number) => void;
|
|
23
|
-
readonly swap: (a: number, b: number) => void;
|
|
24
|
-
}
|
|
25
|
-
type VariantCases<V> = {
|
|
26
|
-
readonly [Tag in VariantTag<V>]: (scope: ScopeHelpers<VariantBody<V, Tag>>) => ReactNode;
|
|
27
|
-
};
|
|
28
|
-
export interface ScopeHelpers<ScopeValues> {
|
|
29
|
-
readonly field: <P extends FieldPath<ScopeValues>>(path: P) => FieldHandle<PathValue<ScopeValues, P>>;
|
|
30
|
-
readonly array: <P extends ArrayPath<ScopeValues>>(path: P, render: (args: ArrayRenderArgs<ArrayItem<ScopeValues, P>>) => ReactNode) => ReactNode;
|
|
31
|
-
readonly variant: <P extends VariantPath<ScopeValues>>(path: P, cases: VariantCases<VariantValue<ScopeValues, P>>) => ReactNode;
|
|
32
|
-
}
|
|
33
|
-
export interface RootHelpers<F extends AnyForm> extends ScopeHelpers<Values<F>> {
|
|
34
|
-
readonly form: View<F>;
|
|
35
|
-
}
|
|
36
|
-
type ContractWithForm<F extends AnyForm> = UiContract & {
|
|
37
|
-
readonly props: {
|
|
38
|
-
readonly form: View<F>;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
export declare const make: <F extends AnyForm, C extends ContractWithForm<F>>(contract: UiClass<C>, _form: F, render: (helpers: RootHelpers<F> & {
|
|
42
|
-
readonly props: C["props"];
|
|
43
|
-
}, slots: Parameters<ViewImpl<C>>[1], events: Parameters<ViewImpl<C>>[2]) => ReactNode) => ViewImpl<C>;
|
|
44
|
-
export declare const FormUi: {
|
|
45
|
-
readonly make: typeof make;
|
|
46
|
-
};
|
|
47
|
-
export {};
|
|
48
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AACzE,OAAO,EAAM,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACnF,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,YAAY,EACZ,SAAS,EACT,SAAS,EACT,MAAM,EACN,WAAW,EACX,WAAW,EACX,UAAU,EACV,YAAY,EACZ,IAAI,EACJ,OAAO,EACR,MAAM,wBAAwB,CAAA;AAG/B,MAAM,M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,EAE7B,UAAU,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EACR,QAAQ,CACN,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;CAAE,EACxD,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACjC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAC/B,SAAS,KACb,QAAQ,CAAC,CAAC,CAWV,CAAA;AAEH,eAAO,MAAM,MAAM,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,IAAI,CAAA;CAAa,CAAA"}
|
package/dist/index.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { createElement } from 'react';
|
|
2
|
-
import { Ui } from '@playfast/reform';
|
|
3
|
-
import { joinPath } from '@playfast/reform-forms';
|
|
4
|
-
const makeFieldHandle = (field) => ({
|
|
5
|
-
as: (component, props) => createElement(component, { ...(props ?? {}), field }),
|
|
6
|
-
});
|
|
7
|
-
const makeScope = (form, prefix) => {
|
|
8
|
-
const full = (path) => joinPath(prefix, path);
|
|
9
|
-
return {
|
|
10
|
-
field: (path) => makeFieldHandle(form.field(full(path))),
|
|
11
|
-
array: (path, render) => {
|
|
12
|
-
const binding = form.array(full(path));
|
|
13
|
-
return render({
|
|
14
|
-
append: binding.append,
|
|
15
|
-
remove: binding.remove,
|
|
16
|
-
move: binding.move,
|
|
17
|
-
swap: binding.swap,
|
|
18
|
-
items: binding.items.map((item) => ({
|
|
19
|
-
...makeScope(form, `${binding.path}[${item.index}]`),
|
|
20
|
-
key: item.key,
|
|
21
|
-
index: item.index,
|
|
22
|
-
value: item.value,
|
|
23
|
-
remove: item.remove,
|
|
24
|
-
move: item.move,
|
|
25
|
-
})),
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
variant: (path, cases) => {
|
|
29
|
-
const variantPath = full(path);
|
|
30
|
-
const value = form.variantValue(variantPath);
|
|
31
|
-
if (value === null || typeof value !== 'object' || !('_tag' in value))
|
|
32
|
-
return null;
|
|
33
|
-
const tag = String(value._tag);
|
|
34
|
-
const render = cases[tag];
|
|
35
|
-
return render === undefined ? null : render(makeScope(form, variantPath));
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
export const make = (contract, _form, render) => Ui.make(contract, (props, slots, events) => render({
|
|
40
|
-
...makeScope(props.form, ''),
|
|
41
|
-
form: props.form,
|
|
42
|
-
props,
|
|
43
|
-
}, slots, events));
|
|
44
|
-
export const FormUi = { make };
|
|
45
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAsC,MAAM,OAAO,CAAA;AACzE,OAAO,EAAE,EAAE,EAAgD,MAAM,kBAAkB,CAAA;AAenF,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAiDjD,MAAM,eAAe,GAAG,CACtB,KAAsB,EACN,EAAE,CAAC,CAAC;IACpB,EAAE,EAAE,CAAmB,SAA+B,EAAE,KAAS,EAAa,EAAE,CAC9E,aAAa,CAAC,SAAS,EAAE,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,KAAK,EAA6C,CAAC;CACnG,CAAC,CAAA;AAEF,MAAM,SAAS,GAAG,CAChB,IAAe,EACf,MAAc,EACa,EAAE;IAC7B,MAAM,IAAI,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAC7D,OAAO;QACL,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,C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