@formancy/react 0.1.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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +48 -0
- package/dist/index.d.mts +147 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +505 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<!-- Part of formancy: https://github.com/sharkysan/formancy.ai -->
|
|
2
|
+
|
|
3
|
+
# @formancy/react
|
|
4
|
+
|
|
5
|
+
The React binding for formancy: hooks over the engine's snapshot protocol, plus
|
|
6
|
+
unstyled components you can keep or replace entirely.
|
|
7
|
+
|
|
8
|
+
Requires React 19.
|
|
9
|
+
|
|
10
|
+
## The load-bearing decision
|
|
11
|
+
|
|
12
|
+
`useField` binds through `useSyncExternalStore` against identity-stable engine
|
|
13
|
+
snapshots. The consequence is the headline: **typing in one field does not
|
|
14
|
+
re-render its siblings** — there is a test that counts renders to keep it that
|
|
15
|
+
way. The third argument serves SSR from the same snapshot the client hydrates
|
|
16
|
+
with, and because the engine's ids are deterministic, the markup matches.
|
|
17
|
+
|
|
18
|
+
The second is that markup belongs to you. Prop getters carry every id and ARIA
|
|
19
|
+
attribute, so a design system can render every element itself and still be
|
|
20
|
+
correct:
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
const field = useField('email')
|
|
24
|
+
<label {...field.labelProps}>Email</label>
|
|
25
|
+
<input {...field.controlProps} value={field.value as string} />
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Use
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { FormancyProvider, FormancyForm, ErrorSummary } from '@formancy/react'
|
|
32
|
+
|
|
33
|
+
<FormancyProvider engine={engine}>
|
|
34
|
+
<ErrorSummary />
|
|
35
|
+
<FormancyForm onSubmit={(outcome) => console.log(outcome)} />
|
|
36
|
+
</FormancyProvider>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`FormancyForm` renders pages, repeaters and a submit control from the schema.
|
|
40
|
+
Swap any field renderer through the registry — per-path beats per-type beats the
|
|
41
|
+
built-in defaults — without forking anything.
|
|
42
|
+
|
|
43
|
+
Also exported: `useRepeater`, `useWizard`, `useSubmit` (which moves focus to the
|
|
44
|
+
first problem, or defers to a mounted `ErrorSummary`).
|
|
45
|
+
|
|
46
|
+
This renderer passes the shared conformance suite; so does the Angular one.
|
|
47
|
+
|
|
48
|
+
Docs: `apps/docs` (Quickstart: React).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from "react";
|
|
2
|
+
import { ControlProps, FieldSnapshot, FormEngine, Path } from "@formancy/core";
|
|
3
|
+
import { FieldType } from "@formancy/spec";
|
|
4
|
+
//#region src/context.d.ts
|
|
5
|
+
export declare function FormancyProvider({ engine, children }: {
|
|
6
|
+
engine: FormEngine;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
9
|
+
export declare function useFormEngine(): FormEngine;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/use-field.d.ts
|
|
12
|
+
interface FieldBinding extends FieldSnapshot {
|
|
13
|
+
setValue(value: unknown): void;
|
|
14
|
+
touch(): void;
|
|
15
|
+
/** Spread onto the input/select/textarea element. */
|
|
16
|
+
controlProps: ControlProps;
|
|
17
|
+
/** Spread onto the label element. */
|
|
18
|
+
labelProps: {
|
|
19
|
+
id: string;
|
|
20
|
+
htmlFor: string;
|
|
21
|
+
};
|
|
22
|
+
/** Spread onto the error text element. */
|
|
23
|
+
errorProps: {
|
|
24
|
+
id: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One field's live state, re-rendering exactly when that field's snapshot
|
|
29
|
+
* changes and never for its siblings.
|
|
30
|
+
*
|
|
31
|
+
* useSyncExternalStore is the honest way to bind an external store in React:
|
|
32
|
+
* the engine's snapshots are identity-stable, so getSnapshot needs no
|
|
33
|
+
* memoisation and concurrent rendering gets a consistent tearing guard for
|
|
34
|
+
* free. The third argument makes SSR render from the same snapshot the client
|
|
35
|
+
* will hydrate with — ids are deterministic, so markup matches.
|
|
36
|
+
*/
|
|
37
|
+
export declare function useField(path: string | Path): FieldBinding;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/use-repeater.d.ts
|
|
40
|
+
interface RepeaterBinding {
|
|
41
|
+
rowCount: number;
|
|
42
|
+
/** Stable per-row keys, in row order. Never key a row by its index. */
|
|
43
|
+
rowIds: readonly string[];
|
|
44
|
+
addRow(): void;
|
|
45
|
+
removeRow(index: number): void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A repeater's live row list. Renders exactly when rows are added, removed or
|
|
49
|
+
* edited — the engine treats the repeater path as subscribable in its own
|
|
50
|
+
* right, so this hook needs no polling and no array identity tricks.
|
|
51
|
+
*/
|
|
52
|
+
export declare function useRepeater(path: string | Path): RepeaterBinding;
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/use-wizard.d.ts
|
|
55
|
+
interface WizardBinding {
|
|
56
|
+
page: number;
|
|
57
|
+
pageCount: number;
|
|
58
|
+
/** Resolves true iff the page advanced; a failed validation keeps the page. */
|
|
59
|
+
next(): Promise<boolean>;
|
|
60
|
+
back(): void;
|
|
61
|
+
/** Unvalidated jump — error navigation, never a way past a gate. */
|
|
62
|
+
goTo(pageIndex: number): void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The wizard's live position. Throws on an unpaged form rather than degrading
|
|
66
|
+
* to a one-page pseudo-wizard: a stepper rendered over a flat form is a bug in
|
|
67
|
+
* the caller, and a loud error at mount beats a mute component.
|
|
68
|
+
*/
|
|
69
|
+
export declare function useWizard(): WizardBinding;
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/use-submit.d.ts
|
|
72
|
+
/**
|
|
73
|
+
* Submit the form: touch everything, validate everything, and on failure move
|
|
74
|
+
* focus to the first invalid control — the WCAG-required behaviour that every
|
|
75
|
+
* consumer would otherwise have to hand-roll, and most would forget.
|
|
76
|
+
*
|
|
77
|
+
* Focus lives in the binding, not the engine, because it needs the DOM after
|
|
78
|
+
* the commit; the engine only names the field (firstInvalid) and mints the id.
|
|
79
|
+
*/
|
|
80
|
+
export declare function useSubmit(): () => {
|
|
81
|
+
ok: boolean;
|
|
82
|
+
errors: Record<string, string[]>;
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/form.d.ts
|
|
86
|
+
/**
|
|
87
|
+
* The component registry — theming mechanism number two. The schema decides
|
|
88
|
+
* WHAT a field is; the registry decides what RENDERS it, with per-path entries
|
|
89
|
+
* beating per-type entries beating the built-in defaults. A design system
|
|
90
|
+
* replaces the entire visual layer by handing in a registry, without forking
|
|
91
|
+
* anything.
|
|
92
|
+
*/
|
|
93
|
+
interface FieldComponentProps {
|
|
94
|
+
path: string;
|
|
95
|
+
label: string;
|
|
96
|
+
}
|
|
97
|
+
type FieldComponent = ComponentType<FieldComponentProps>;
|
|
98
|
+
interface Registry {
|
|
99
|
+
byType?: Partial<Record<FieldType, FieldComponent>>;
|
|
100
|
+
byPath?: Record<string, FieldComponent>;
|
|
101
|
+
}
|
|
102
|
+
interface SubmitOutcome {
|
|
103
|
+
ok: boolean;
|
|
104
|
+
errors: Record<string, string[]>;
|
|
105
|
+
/** The canonical value, present when accepted. */
|
|
106
|
+
data?: unknown;
|
|
107
|
+
}
|
|
108
|
+
interface FormancyFormProps {
|
|
109
|
+
/**
|
|
110
|
+
* Display text per wire path (row fields by their template wire,
|
|
111
|
+
* `items[].name`). A `label` on the model definition wins — that is how
|
|
112
|
+
* fixture schemas carry text until the spec's i18n section lands; a missing
|
|
113
|
+
* entry falls back to the wire path, which is at least honest.
|
|
114
|
+
*/
|
|
115
|
+
labels?: Record<string, string>;
|
|
116
|
+
registry?: Registry;
|
|
117
|
+
submitLabel?: string;
|
|
118
|
+
onSubmit?: (outcome: SubmitOutcome) => void;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Renders the whole form from the engine: one slot per field, resolved through
|
|
122
|
+
* the registry. Slots subscribe individually, so a keystroke re-renders one
|
|
123
|
+
* field and a visibility flip mounts or unmounts exactly the fields it hit.
|
|
124
|
+
* A paged schema renders a stepper, one page at a time, navigation, and the
|
|
125
|
+
* submit control on the last page — a failed submit navigates to the first
|
|
126
|
+
* page with a problem instead of leaving the user on a clean review page
|
|
127
|
+
* staring at a rejection.
|
|
128
|
+
*/
|
|
129
|
+
export declare function FormancyForm(props: FormancyFormProps): import("react").JSX.Element;
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/error-summary.d.ts
|
|
132
|
+
interface ErrorSummaryProps {
|
|
133
|
+
labels?: Record<string, string>;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The error summary a failed submit focuses.
|
|
137
|
+
*
|
|
138
|
+
* The semantics are deliberate and easy to get wrong: the container takes
|
|
139
|
+
* focus via tabindex="-1" — focusing it already makes screen readers announce
|
|
140
|
+
* it, so role="alert" would announce it TWICE. Each entry is a real in-page
|
|
141
|
+
* link to the offending control, because links are what "take me to the
|
|
142
|
+
* problem" already means to assistive tech.
|
|
143
|
+
*/
|
|
144
|
+
export declare function ErrorSummary({ labels }: ErrorSummaryProps): import("react").JSX.Element | null;
|
|
145
|
+
//#endregion
|
|
146
|
+
export type { ErrorSummaryProps, FieldBinding, FieldComponent, FieldComponentProps, FormancyFormProps, Registry, RepeaterBinding, SubmitOutcome, WizardBinding };
|
|
147
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/context.tsx","../src/use-field.ts","../src/use-repeater.ts","../src/use-wizard.ts","../src/use-submit.ts","../src/form.tsx","../src/error-summary.tsx"],"mappings":";;;;wBAYgB,mBAAmB,QAAQ;EAAc,QAAQ;EAAY,WAAW;oBAAW,IAAA;wBAInF,iBAAiB;;;UCXhB,qBAAqB;EACpC,SAAS;EACT;;EAEA,cAAc;;EAEd;IAAc;IAAY;;;EAE1B;IAAc;;;;;;;;;;;;;wBAaA,SAAS,eAAe,OAAO;;;UCrB9B;EACf;;EAEA;EACA;EACA,UAAU;;;;;;;wBAQI,YAAY,eAAe,OAAO;;;UCfjC;EACf;EACA;;EAEA,QAAQ;EACR;;EAEA,KAAK;;;;;;;wBAQS,aAAa;;;;;;;;;;;wBCNb;EAAqB;EAAa,QAAQ;;;;;;;;;;;UCKzC;EACf;EACA;;KAGU,iBAAiB,cAAc;UAE1B;EACf,SAAS,QAAQ,OAAO,WAAW;EACnC,SAAS,eAAe;;UAGT;EACf;EACA,QAAQ;;EAER;;UAGe;;;;;;;EAOf,SAAS;EACT,WAAW;EACX;EACA,YAAY,SAAS;;;;;;;;;;;wBAYP,aAAa,OAAO,oCAAiB,IAAA;;;UCtDpC;EACf,SAAS;;;;;;;;;;;wBAYK,eAAe,UAAU,oCAAiB,IAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useSyncExternalStore } from "react";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { formatPath, parsePath } from "@formancy/core";
|
|
4
|
+
//#region src/context.tsx
|
|
5
|
+
/**
|
|
6
|
+
* The engine reaches components through context, never through props drilling:
|
|
7
|
+
* a form is one engine instance, and every hook resolves against it. Kept in
|
|
8
|
+
* its own module so tree-shaking can drop the provider for consumers that only
|
|
9
|
+
* use prop getters.
|
|
10
|
+
*/
|
|
11
|
+
const FormancyContext = createContext(null);
|
|
12
|
+
function FormancyProvider({ engine, children }) {
|
|
13
|
+
return /* @__PURE__ */ jsx(FormancyContext.Provider, {
|
|
14
|
+
value: engine,
|
|
15
|
+
children
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function useFormEngine() {
|
|
19
|
+
const engine = useContext(FormancyContext);
|
|
20
|
+
if (!engine) throw new Error("formancy hooks need a <FormancyProvider engine={...}> above them in the tree");
|
|
21
|
+
return engine;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/use-field.ts
|
|
25
|
+
/**
|
|
26
|
+
* One field's live state, re-rendering exactly when that field's snapshot
|
|
27
|
+
* changes and never for its siblings.
|
|
28
|
+
*
|
|
29
|
+
* useSyncExternalStore is the honest way to bind an external store in React:
|
|
30
|
+
* the engine's snapshots are identity-stable, so getSnapshot needs no
|
|
31
|
+
* memoisation and concurrent rendering gets a consistent tearing guard for
|
|
32
|
+
* free. The third argument makes SSR render from the same snapshot the client
|
|
33
|
+
* will hydrate with — ids are deterministic, so markup matches.
|
|
34
|
+
*/
|
|
35
|
+
function useField(path) {
|
|
36
|
+
const engine = useFormEngine();
|
|
37
|
+
const wire = typeof path === "string" ? path : formatPath(path);
|
|
38
|
+
const parsed = useMemo(() => parsePath(wire), [wire]);
|
|
39
|
+
const subscribe = useCallback((onChange) => engine.subscribeField(parsed, onChange), [engine, parsed]);
|
|
40
|
+
const getSnapshot = useCallback(() => engine.getFieldSnapshot(parsed), [engine, parsed]);
|
|
41
|
+
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
42
|
+
const setValue = useCallback((value) => engine.setValue(parsed, value), [engine, parsed]);
|
|
43
|
+
const touch = useCallback(() => engine.touch(parsed), [engine, parsed]);
|
|
44
|
+
return useMemo(() => ({
|
|
45
|
+
...snapshot,
|
|
46
|
+
setValue,
|
|
47
|
+
touch,
|
|
48
|
+
controlProps: snapshot.props.control,
|
|
49
|
+
labelProps: {
|
|
50
|
+
id: snapshot.props.label.id,
|
|
51
|
+
htmlFor: snapshot.props.label.for
|
|
52
|
+
},
|
|
53
|
+
errorProps: snapshot.props.error
|
|
54
|
+
}), [
|
|
55
|
+
snapshot,
|
|
56
|
+
setValue,
|
|
57
|
+
touch
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/use-repeater.ts
|
|
62
|
+
/**
|
|
63
|
+
* A repeater's live row list. Renders exactly when rows are added, removed or
|
|
64
|
+
* edited — the engine treats the repeater path as subscribable in its own
|
|
65
|
+
* right, so this hook needs no polling and no array identity tricks.
|
|
66
|
+
*/
|
|
67
|
+
function useRepeater(path) {
|
|
68
|
+
const engine = useFormEngine();
|
|
69
|
+
const wire = typeof path === "string" ? path : formatPath(path);
|
|
70
|
+
const parsed = useMemo(() => parsePath(wire), [wire]);
|
|
71
|
+
const subscribe = useCallback((onChange) => engine.subscribeField(parsed, onChange), [engine, parsed]);
|
|
72
|
+
const getRowCount = useCallback(() => engine.rowCount(parsed), [engine, parsed]);
|
|
73
|
+
const rowCount = useSyncExternalStore(subscribe, getRowCount, getRowCount);
|
|
74
|
+
const addRow = useCallback(() => engine.addRow(parsed), [engine, parsed]);
|
|
75
|
+
const removeRow = useCallback((index) => engine.removeRow(parsed, index), [engine, parsed]);
|
|
76
|
+
const rowIds = useMemo(() => Array.from({ length: rowCount }, (_, index) => engine.rowId(parsed, index)), [
|
|
77
|
+
engine,
|
|
78
|
+
parsed,
|
|
79
|
+
rowCount
|
|
80
|
+
]);
|
|
81
|
+
return useMemo(() => ({
|
|
82
|
+
rowCount,
|
|
83
|
+
rowIds,
|
|
84
|
+
addRow,
|
|
85
|
+
removeRow
|
|
86
|
+
}), [
|
|
87
|
+
rowCount,
|
|
88
|
+
rowIds,
|
|
89
|
+
addRow,
|
|
90
|
+
removeRow
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/use-wizard.ts
|
|
95
|
+
/**
|
|
96
|
+
* The wizard's live position. Throws on an unpaged form rather than degrading
|
|
97
|
+
* to a one-page pseudo-wizard: a stepper rendered over a flat form is a bug in
|
|
98
|
+
* the caller, and a loud error at mount beats a mute component.
|
|
99
|
+
*/
|
|
100
|
+
function useWizard() {
|
|
101
|
+
const wizard = useFormEngine().wizard();
|
|
102
|
+
if (wizard === void 0) throw new Error("useWizard needs a schema with pages; this form has none");
|
|
103
|
+
const subscribe = useCallback((onChange) => wizard.subscribe(onChange), [wizard]);
|
|
104
|
+
const getPage = useCallback(() => wizard.page(), [wizard]);
|
|
105
|
+
const page = useSyncExternalStore(subscribe, getPage, getPage);
|
|
106
|
+
return useMemo(() => ({
|
|
107
|
+
page,
|
|
108
|
+
pageCount: wizard.pageCount,
|
|
109
|
+
next: () => wizard.next(),
|
|
110
|
+
back: () => wizard.back(),
|
|
111
|
+
goTo: (pageIndex) => wizard.goTo(pageIndex)
|
|
112
|
+
}), [page, wizard]);
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/use-submit.ts
|
|
116
|
+
/**
|
|
117
|
+
* Submit the form: touch everything, validate everything, and on failure move
|
|
118
|
+
* focus to the first invalid control — the WCAG-required behaviour that every
|
|
119
|
+
* consumer would otherwise have to hand-roll, and most would forget.
|
|
120
|
+
*
|
|
121
|
+
* Focus lives in the binding, not the engine, because it needs the DOM after
|
|
122
|
+
* the commit; the engine only names the field (firstInvalid) and mints the id.
|
|
123
|
+
*/
|
|
124
|
+
function useSubmit() {
|
|
125
|
+
const engine = useFormEngine();
|
|
126
|
+
return useCallback(() => {
|
|
127
|
+
const outcome = engine.submit();
|
|
128
|
+
if (!outcome.ok && typeof document !== "undefined") {
|
|
129
|
+
if (document.querySelector("[data-formancy-part=\"error-summary\"]") === null) {
|
|
130
|
+
const firstInvalid = engine.firstInvalid();
|
|
131
|
+
if (firstInvalid !== null) {
|
|
132
|
+
const ids = engine.getFieldSnapshot(parsePath(firstInvalid)).ids;
|
|
133
|
+
document.getElementById(ids.control)?.focus();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return outcome;
|
|
138
|
+
}, [engine]);
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/form.tsx
|
|
142
|
+
/**
|
|
143
|
+
* Renders the whole form from the engine: one slot per field, resolved through
|
|
144
|
+
* the registry. Slots subscribe individually, so a keystroke re-renders one
|
|
145
|
+
* field and a visibility flip mounts or unmounts exactly the fields it hit.
|
|
146
|
+
* A paged schema renders a stepper, one page at a time, navigation, and the
|
|
147
|
+
* submit control on the last page — a failed submit navigates to the first
|
|
148
|
+
* page with a problem instead of leaving the user on a clean review page
|
|
149
|
+
* staring at a rejection.
|
|
150
|
+
*/
|
|
151
|
+
function FormancyForm(props) {
|
|
152
|
+
return useFormEngine().wizard() === void 0 ? /* @__PURE__ */ jsx(FlatForm, { ...props }) : /* @__PURE__ */ jsx(PagedForm, { ...props });
|
|
153
|
+
}
|
|
154
|
+
function SubmitButton({ submitLabel, onSubmit, onFailedNavigate }) {
|
|
155
|
+
const engine = useFormEngine();
|
|
156
|
+
const submit = useSubmit();
|
|
157
|
+
return /* @__PURE__ */ jsx("button", {
|
|
158
|
+
type: "button",
|
|
159
|
+
"data-formancy-part": "submit",
|
|
160
|
+
onClick: () => {
|
|
161
|
+
const outcome = submit();
|
|
162
|
+
if (!outcome.ok && onFailedNavigate !== void 0) {
|
|
163
|
+
const firstInvalid = engine.firstInvalid();
|
|
164
|
+
if (firstInvalid !== null) onFailedNavigate(engine.pageOf(parsePath(firstInvalid)));
|
|
165
|
+
}
|
|
166
|
+
onSubmit?.(outcome.ok ? {
|
|
167
|
+
ok: true,
|
|
168
|
+
errors: outcome.errors,
|
|
169
|
+
data: engine.value()
|
|
170
|
+
} : {
|
|
171
|
+
ok: false,
|
|
172
|
+
errors: outcome.errors
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
children: submitLabel ?? "Submit"
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function FlatForm(props) {
|
|
179
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(FieldList, { ...props }), /* @__PURE__ */ jsx(SubmitButton, { ...props })] });
|
|
180
|
+
}
|
|
181
|
+
function PagedForm(props) {
|
|
182
|
+
const engine = useFormEngine();
|
|
183
|
+
const wizard = useWizard();
|
|
184
|
+
const pages = engine.pages();
|
|
185
|
+
const lastPage = wizard.pageCount - 1;
|
|
186
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
187
|
+
/* @__PURE__ */ jsx("nav", {
|
|
188
|
+
"data-formancy-part": "stepper",
|
|
189
|
+
"aria-label": "Progress",
|
|
190
|
+
children: /* @__PURE__ */ jsx("ol", { children: pages.map((page, index) => /* @__PURE__ */ jsx("li", {
|
|
191
|
+
"aria-current": index === wizard.page ? "step" : void 0,
|
|
192
|
+
children: engine.text(page.def.label) ?? page.key
|
|
193
|
+
}, page.key)) })
|
|
194
|
+
}),
|
|
195
|
+
/* @__PURE__ */ jsx(FieldList, {
|
|
196
|
+
...props,
|
|
197
|
+
page: wizard.page
|
|
198
|
+
}),
|
|
199
|
+
/* @__PURE__ */ jsxs("div", {
|
|
200
|
+
"data-formancy-part": "wizard-nav",
|
|
201
|
+
children: [wizard.page > 0 ? /* @__PURE__ */ jsx("button", {
|
|
202
|
+
type: "button",
|
|
203
|
+
onClick: () => wizard.back(),
|
|
204
|
+
children: "Back"
|
|
205
|
+
}) : null, wizard.page < lastPage ? /* @__PURE__ */ jsx("button", {
|
|
206
|
+
type: "button",
|
|
207
|
+
onClick: () => void wizard.next(),
|
|
208
|
+
children: "Next"
|
|
209
|
+
}) : /* @__PURE__ */ jsx(SubmitButton, {
|
|
210
|
+
...props,
|
|
211
|
+
onFailedNavigate: (page) => wizard.goTo(page)
|
|
212
|
+
})]
|
|
213
|
+
})
|
|
214
|
+
] });
|
|
215
|
+
}
|
|
216
|
+
function FieldList({ labels, registry, page }) {
|
|
217
|
+
const engine = useFormEngine();
|
|
218
|
+
const repeaterWires = engine.repeaterPaths();
|
|
219
|
+
const inPage = (wire) => page === void 0 || engine.pageOf(parsePath(wire)) === page;
|
|
220
|
+
const staticWires = engine.fieldPaths().filter((wire) => !repeaterWires.some((repeater) => wire.startsWith(`${repeater}[`)));
|
|
221
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [staticWires.filter(inPage).map((wire) => /* @__PURE__ */ jsx(FieldSlot, {
|
|
222
|
+
path: wire,
|
|
223
|
+
fallbackLabel: labels?.[wire],
|
|
224
|
+
registry
|
|
225
|
+
}, wire)), repeaterWires.filter(inPage).map((wire) => /* @__PURE__ */ jsx(RepeaterSection, {
|
|
226
|
+
wire,
|
|
227
|
+
labels,
|
|
228
|
+
registry
|
|
229
|
+
}, wire))] });
|
|
230
|
+
}
|
|
231
|
+
function FieldSlot({ path, fallbackLabel, registry }) {
|
|
232
|
+
const field = useField(path);
|
|
233
|
+
if (!field.visible) return null;
|
|
234
|
+
const Component = registry?.byPath?.[path] ?? registry?.byType?.[field.type] ?? DEFAULT_COMPONENTS[field.type];
|
|
235
|
+
if (Component === null) return null;
|
|
236
|
+
const label = field.label ?? fallbackLabel ?? path;
|
|
237
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
238
|
+
path,
|
|
239
|
+
label
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
function RepeaterSection({ wire, labels, registry }) {
|
|
243
|
+
const engine = useFormEngine();
|
|
244
|
+
const repeater = useRepeater(wire);
|
|
245
|
+
const def = engine.repeaters().find((candidate) => candidate.wire === wire)?.def;
|
|
246
|
+
const label = engine.text(def?.label) ?? labels?.[wire] ?? wire;
|
|
247
|
+
const addLabel = def?.addLabel ?? `Add ${label}`;
|
|
248
|
+
const removeLabel = def?.removeLabel ?? `Remove ${label}`;
|
|
249
|
+
const fallbackFor = (instanceWire) => {
|
|
250
|
+
const template = instanceWire.replace(/\[\d+\]/, "[]");
|
|
251
|
+
return labels?.[template] ?? labels?.[instanceWire];
|
|
252
|
+
};
|
|
253
|
+
return /* @__PURE__ */ jsxs("fieldset", {
|
|
254
|
+
"data-formancy-part": "repeater",
|
|
255
|
+
children: [
|
|
256
|
+
/* @__PURE__ */ jsx("legend", {
|
|
257
|
+
"data-formancy-part": "repeater-legend",
|
|
258
|
+
children: label
|
|
259
|
+
}),
|
|
260
|
+
repeater.rowIds.map((rowId, index) => /* @__PURE__ */ jsxs("div", {
|
|
261
|
+
"data-formancy-part": "row",
|
|
262
|
+
children: [engine.fieldPaths().filter((candidate) => candidate.startsWith(`${wire}[${index}]`)).map((instanceWire) => /* @__PURE__ */ jsx(FieldSlot, {
|
|
263
|
+
path: instanceWire,
|
|
264
|
+
fallbackLabel: fallbackFor(instanceWire),
|
|
265
|
+
registry
|
|
266
|
+
}, instanceWire)), /* @__PURE__ */ jsx("button", {
|
|
267
|
+
type: "button",
|
|
268
|
+
onClick: () => repeater.removeRow(index),
|
|
269
|
+
children: `${removeLabel} ${index + 1} of ${repeater.rowCount}`
|
|
270
|
+
})]
|
|
271
|
+
}, rowId)),
|
|
272
|
+
/* @__PURE__ */ jsx("button", {
|
|
273
|
+
type: "button",
|
|
274
|
+
onClick: () => repeater.addRow(),
|
|
275
|
+
children: addLabel
|
|
276
|
+
})
|
|
277
|
+
]
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/** Shared unstyled shell: real label, control, error text as the describedby
|
|
281
|
+
* target. Zero CSS; `data-formancy-part` is the styling hook. */
|
|
282
|
+
function FieldShell({ field, label, children }) {
|
|
283
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
284
|
+
"data-formancy-part": "field",
|
|
285
|
+
"data-state": field.touched && field.errors.length > 0 ? "invalid" : "valid",
|
|
286
|
+
children: [
|
|
287
|
+
/* @__PURE__ */ jsx("label", {
|
|
288
|
+
"data-formancy-part": "label",
|
|
289
|
+
...field.labelProps,
|
|
290
|
+
children: label
|
|
291
|
+
}),
|
|
292
|
+
children,
|
|
293
|
+
field.touched && field.errors.length > 0 ? /* @__PURE__ */ jsx("p", {
|
|
294
|
+
"data-formancy-part": "error",
|
|
295
|
+
...field.errorProps,
|
|
296
|
+
children: field.errors.join(", ")
|
|
297
|
+
}) : null
|
|
298
|
+
]
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function TextField({ path, label }) {
|
|
302
|
+
const field = useField(path);
|
|
303
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
304
|
+
field,
|
|
305
|
+
label,
|
|
306
|
+
children: /* @__PURE__ */ jsx("input", {
|
|
307
|
+
type: "text",
|
|
308
|
+
...field.controlProps,
|
|
309
|
+
value: typeof field.value === "string" ? field.value : "",
|
|
310
|
+
onChange: (event) => field.setValue(event.target.value),
|
|
311
|
+
onBlur: () => field.touch()
|
|
312
|
+
})
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function TextareaField({ path, label }) {
|
|
316
|
+
const field = useField(path);
|
|
317
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
318
|
+
field,
|
|
319
|
+
label,
|
|
320
|
+
children: /* @__PURE__ */ jsx("textarea", {
|
|
321
|
+
...field.controlProps,
|
|
322
|
+
value: typeof field.value === "string" ? field.value : "",
|
|
323
|
+
onChange: (event) => field.setValue(event.target.value),
|
|
324
|
+
onBlur: () => field.touch()
|
|
325
|
+
})
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
function NumberField({ path, label }) {
|
|
329
|
+
const field = useField(path);
|
|
330
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
331
|
+
field,
|
|
332
|
+
label,
|
|
333
|
+
children: /* @__PURE__ */ jsx("input", {
|
|
334
|
+
type: "number",
|
|
335
|
+
...field.controlProps,
|
|
336
|
+
value: typeof field.value === "number" ? field.value : "",
|
|
337
|
+
onChange: (event) => field.setValue(event.target.value === "" ? null : event.target.valueAsNumber),
|
|
338
|
+
onBlur: () => field.touch()
|
|
339
|
+
})
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
function CheckboxField({ path, label }) {
|
|
343
|
+
const field = useField(path);
|
|
344
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
345
|
+
field,
|
|
346
|
+
label,
|
|
347
|
+
children: /* @__PURE__ */ jsx("input", {
|
|
348
|
+
type: "checkbox",
|
|
349
|
+
...field.controlProps,
|
|
350
|
+
checked: field.value === true,
|
|
351
|
+
onChange: (event) => field.setValue(event.target.checked),
|
|
352
|
+
onBlur: () => field.touch()
|
|
353
|
+
})
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
function DateField({ path, label }) {
|
|
357
|
+
const field = useField(path);
|
|
358
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
359
|
+
field,
|
|
360
|
+
label,
|
|
361
|
+
children: /* @__PURE__ */ jsx("input", {
|
|
362
|
+
type: "date",
|
|
363
|
+
...field.controlProps,
|
|
364
|
+
value: typeof field.value === "string" ? field.value : "",
|
|
365
|
+
onChange: (event) => field.setValue(event.target.value === "" ? null : event.target.value),
|
|
366
|
+
onBlur: () => field.touch()
|
|
367
|
+
})
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Option labels resolved to strings, since a label may be a message reference.
|
|
372
|
+
* Falling back to the stored value keeps an untranslated option selectable
|
|
373
|
+
* rather than blank.
|
|
374
|
+
*/
|
|
375
|
+
function useResolvedOptions(field) {
|
|
376
|
+
const engine = useFormEngine();
|
|
377
|
+
return (field.def.options ?? []).map((option) => ({
|
|
378
|
+
value: option.value,
|
|
379
|
+
label: engine.text(option.label) ?? option.value
|
|
380
|
+
}));
|
|
381
|
+
}
|
|
382
|
+
function SelectField({ path, label }) {
|
|
383
|
+
const field = useField(path);
|
|
384
|
+
const options = useResolvedOptions(field);
|
|
385
|
+
return /* @__PURE__ */ jsx(FieldShell, {
|
|
386
|
+
field,
|
|
387
|
+
label,
|
|
388
|
+
children: /* @__PURE__ */ jsxs("select", {
|
|
389
|
+
...field.controlProps,
|
|
390
|
+
value: typeof field.value === "string" ? field.value : "",
|
|
391
|
+
onChange: (event) => field.setValue(event.target.value === "" ? null : event.target.value),
|
|
392
|
+
onBlur: () => field.touch(),
|
|
393
|
+
children: [/* @__PURE__ */ jsx("option", { value: "" }), options.map((option) => /* @__PURE__ */ jsx("option", {
|
|
394
|
+
value: option.value,
|
|
395
|
+
children: option.label
|
|
396
|
+
}, option.value))]
|
|
397
|
+
})
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
function RadioGroupField({ path, label }) {
|
|
401
|
+
const field = useField(path);
|
|
402
|
+
const options = useResolvedOptions(field);
|
|
403
|
+
const showError = field.touched && field.errors.length > 0;
|
|
404
|
+
return /* @__PURE__ */ jsxs("fieldset", {
|
|
405
|
+
"data-formancy-part": "field",
|
|
406
|
+
"data-state": showError ? "invalid" : "valid",
|
|
407
|
+
"aria-describedby": field.controlProps["aria-describedby"],
|
|
408
|
+
children: [
|
|
409
|
+
/* @__PURE__ */ jsx("legend", {
|
|
410
|
+
"data-formancy-part": "label",
|
|
411
|
+
children: label
|
|
412
|
+
}),
|
|
413
|
+
options.map((option) => {
|
|
414
|
+
const optionId = `${field.ids.control}:${option.value}`;
|
|
415
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
416
|
+
"data-formancy-part": "radio-option",
|
|
417
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
418
|
+
type: "radio",
|
|
419
|
+
id: optionId,
|
|
420
|
+
name: field.controlProps.name,
|
|
421
|
+
value: option.value,
|
|
422
|
+
checked: field.value === option.value,
|
|
423
|
+
onChange: () => field.setValue(option.value),
|
|
424
|
+
onBlur: () => field.touch()
|
|
425
|
+
}), /* @__PURE__ */ jsx("label", {
|
|
426
|
+
htmlFor: optionId,
|
|
427
|
+
children: option.label
|
|
428
|
+
})]
|
|
429
|
+
}, option.value);
|
|
430
|
+
}),
|
|
431
|
+
showError ? /* @__PURE__ */ jsx("p", {
|
|
432
|
+
"data-formancy-part": "error",
|
|
433
|
+
...field.errorProps,
|
|
434
|
+
children: field.errors.join(", ")
|
|
435
|
+
}) : null
|
|
436
|
+
]
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* The built-in unstyled components. `null` means the type renders nothing here:
|
|
441
|
+
* hidden and static are non-inputs, and the container types are laid out by
|
|
442
|
+
* their own machinery, not by a leaf slot.
|
|
443
|
+
*/
|
|
444
|
+
const DEFAULT_COMPONENTS = {
|
|
445
|
+
text: TextField,
|
|
446
|
+
textarea: TextareaField,
|
|
447
|
+
number: NumberField,
|
|
448
|
+
checkbox: CheckboxField,
|
|
449
|
+
date: DateField,
|
|
450
|
+
select: SelectField,
|
|
451
|
+
radio: RadioGroupField,
|
|
452
|
+
hidden: null,
|
|
453
|
+
static: null,
|
|
454
|
+
group: null,
|
|
455
|
+
page: null,
|
|
456
|
+
repeater: null
|
|
457
|
+
};
|
|
458
|
+
//#endregion
|
|
459
|
+
//#region src/error-summary.tsx
|
|
460
|
+
/**
|
|
461
|
+
* The error summary a failed submit focuses.
|
|
462
|
+
*
|
|
463
|
+
* The semantics are deliberate and easy to get wrong: the container takes
|
|
464
|
+
* focus via tabindex="-1" — focusing it already makes screen readers announce
|
|
465
|
+
* it, so role="alert" would announce it TWICE. Each entry is a real in-page
|
|
466
|
+
* link to the offending control, because links are what "take me to the
|
|
467
|
+
* problem" already means to assistive tech.
|
|
468
|
+
*/
|
|
469
|
+
function ErrorSummary({ labels }) {
|
|
470
|
+
const engine = useFormEngine();
|
|
471
|
+
const subscribe = useCallback((onChange) => engine.subscribe(onChange), [engine]);
|
|
472
|
+
const getErrors = useCallback(() => engine.visibleErrors(), [engine]);
|
|
473
|
+
const errors = useSyncExternalStore(subscribe, getErrors, getErrors);
|
|
474
|
+
const region = useRef(null);
|
|
475
|
+
const previousCount = useRef(0);
|
|
476
|
+
useEffect(() => {
|
|
477
|
+
if (errors.length > 0 && previousCount.current === 0) region.current?.focus();
|
|
478
|
+
previousCount.current = errors.length;
|
|
479
|
+
}, [errors]);
|
|
480
|
+
if (errors.length === 0) return null;
|
|
481
|
+
const labelFor = (path) => labels?.[path] ?? labels?.[path.replace(/\[\d+\]/, "[]")] ?? path;
|
|
482
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
483
|
+
"data-formancy-part": "error-summary",
|
|
484
|
+
tabIndex: -1,
|
|
485
|
+
ref: region,
|
|
486
|
+
children: [/* @__PURE__ */ jsx("h2", {
|
|
487
|
+
"data-formancy-part": "error-summary-heading",
|
|
488
|
+
children: errors.length === 1 ? "There is 1 problem to fix" : `There are ${errors.length} problems to fix`
|
|
489
|
+
}), /* @__PURE__ */ jsx("ul", { children: errors.map(({ path, codes }) => {
|
|
490
|
+
const controlId = engine.getFieldSnapshot(parsePath(path)).ids.control;
|
|
491
|
+
return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("a", {
|
|
492
|
+
href: `#${controlId}`,
|
|
493
|
+
onClick: (event) => {
|
|
494
|
+
event.preventDefault();
|
|
495
|
+
document.getElementById(controlId)?.focus();
|
|
496
|
+
},
|
|
497
|
+
children: `${labelFor(path)}: ${codes.join(", ")}`
|
|
498
|
+
}) }, path);
|
|
499
|
+
}) })]
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
//#endregion
|
|
503
|
+
export { ErrorSummary, FormancyForm, FormancyProvider, useField, useFormEngine, useRepeater, useSubmit, useWizard };
|
|
504
|
+
|
|
505
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/context.tsx","../src/use-field.ts","../src/use-repeater.ts","../src/use-wizard.ts","../src/use-submit.ts","../src/form.tsx","../src/error-summary.tsx"],"sourcesContent":["import { createContext, useContext } from 'react'\nimport type { ReactNode } from 'react'\nimport type { FormEngine } from '@formancy/core'\n\n/**\n * The engine reaches components through context, never through props drilling:\n * a form is one engine instance, and every hook resolves against it. Kept in\n * its own module so tree-shaking can drop the provider for consumers that only\n * use prop getters.\n */\nconst FormancyContext = createContext<FormEngine | null>(null)\n\nexport function FormancyProvider({ engine, children }: { engine: FormEngine; children?: ReactNode }) {\n return <FormancyContext.Provider value={engine}>{children}</FormancyContext.Provider>\n}\n\nexport function useFormEngine(): FormEngine {\n const engine = useContext(FormancyContext)\n if (!engine) {\n throw new Error('formancy hooks need a <FormancyProvider engine={...}> above them in the tree')\n }\n return engine\n}\n","import { useCallback, useMemo, useSyncExternalStore } from 'react'\nimport { formatPath, parsePath } from '@formancy/core'\nimport type { ControlProps, FieldSnapshot, Path } from '@formancy/core'\nimport { useFormEngine } from './context.js'\n\nexport interface FieldBinding extends FieldSnapshot {\n setValue(value: unknown): void\n touch(): void\n /** Spread onto the input/select/textarea element. */\n controlProps: ControlProps\n /** Spread onto the label element. */\n labelProps: { id: string; htmlFor: string }\n /** Spread onto the error text element. */\n errorProps: { id: string }\n}\n\n/**\n * One field's live state, re-rendering exactly when that field's snapshot\n * changes and never for its siblings.\n *\n * useSyncExternalStore is the honest way to bind an external store in React:\n * the engine's snapshots are identity-stable, so getSnapshot needs no\n * memoisation and concurrent rendering gets a consistent tearing guard for\n * free. The third argument makes SSR render from the same snapshot the client\n * will hydrate with — ids are deterministic, so markup matches.\n */\nexport function useField(path: string | Path): FieldBinding {\n const engine = useFormEngine()\n\n const wire = typeof path === 'string' ? path : formatPath(path)\n const parsed = useMemo(() => parsePath(wire), [wire])\n\n const subscribe = useCallback(\n (onChange: () => void) => engine.subscribeField(parsed, onChange),\n [engine, parsed],\n )\n const getSnapshot = useCallback(() => engine.getFieldSnapshot(parsed), [engine, parsed])\n\n const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n\n const setValue = useCallback((value: unknown) => engine.setValue(parsed, value), [engine, parsed])\n const touch = useCallback(() => engine.touch(parsed), [engine, parsed])\n\n return useMemo(\n () => ({\n ...snapshot,\n setValue,\n touch,\n controlProps: snapshot.props.control,\n labelProps: { id: snapshot.props.label.id, htmlFor: snapshot.props.label.for },\n errorProps: snapshot.props.error,\n }),\n [snapshot, setValue, touch],\n )\n}\n","import { useCallback, useMemo, useSyncExternalStore } from 'react'\nimport { formatPath, parsePath } from '@formancy/core'\nimport type { Path } from '@formancy/core'\nimport { useFormEngine } from './context.js'\n\nexport interface RepeaterBinding {\n rowCount: number\n /** Stable per-row keys, in row order. Never key a row by its index. */\n rowIds: readonly string[]\n addRow(): void\n removeRow(index: number): void\n}\n\n/**\n * A repeater's live row list. Renders exactly when rows are added, removed or\n * edited — the engine treats the repeater path as subscribable in its own\n * right, so this hook needs no polling and no array identity tricks.\n */\nexport function useRepeater(path: string | Path): RepeaterBinding {\n const engine = useFormEngine()\n\n const wire = typeof path === 'string' ? path : formatPath(path)\n const parsed = useMemo(() => parsePath(wire), [wire])\n\n const subscribe = useCallback(\n (onChange: () => void) => engine.subscribeField(parsed, onChange),\n [engine, parsed],\n )\n const getRowCount = useCallback(() => engine.rowCount(parsed), [engine, parsed])\n const rowCount = useSyncExternalStore(subscribe, getRowCount, getRowCount)\n\n const addRow = useCallback(() => engine.addRow(parsed), [engine, parsed])\n const removeRow = useCallback((index: number) => engine.removeRow(parsed, index), [engine, parsed])\n\n // Derived from rowCount rather than subscribed separately: the engine mints\n // an id when a row is created, so the count changing is exactly when the ids\n // change.\n const rowIds = useMemo(\n () => Array.from({ length: rowCount }, (_, index) => engine.rowId(parsed, index)),\n [engine, parsed, rowCount],\n )\n\n return useMemo(\n () => ({ rowCount, rowIds, addRow, removeRow }),\n [rowCount, rowIds, addRow, removeRow],\n )\n}\n","import { useCallback, useMemo, useSyncExternalStore } from 'react'\nimport { useFormEngine } from './context.js'\n\nexport interface WizardBinding {\n page: number\n pageCount: number\n /** Resolves true iff the page advanced; a failed validation keeps the page. */\n next(): Promise<boolean>\n back(): void\n /** Unvalidated jump — error navigation, never a way past a gate. */\n goTo(pageIndex: number): void\n}\n\n/**\n * The wizard's live position. Throws on an unpaged form rather than degrading\n * to a one-page pseudo-wizard: a stepper rendered over a flat form is a bug in\n * the caller, and a loud error at mount beats a mute component.\n */\nexport function useWizard(): WizardBinding {\n const engine = useFormEngine()\n const wizard = engine.wizard()\n if (wizard === undefined) {\n throw new Error('useWizard needs a schema with pages; this form has none')\n }\n\n const subscribe = useCallback((onChange: () => void) => wizard.subscribe(onChange), [wizard])\n const getPage = useCallback(() => wizard.page(), [wizard])\n const page = useSyncExternalStore(subscribe, getPage, getPage)\n\n return useMemo(\n () => ({\n page,\n pageCount: wizard.pageCount,\n next: () => wizard.next(),\n back: () => wizard.back(),\n goTo: (pageIndex: number) => wizard.goTo(pageIndex),\n }),\n [page, wizard],\n )\n}\n","import { useCallback } from 'react'\nimport { parsePath } from '@formancy/core'\nimport { useFormEngine } from './context.js'\n\n/**\n * Submit the form: touch everything, validate everything, and on failure move\n * focus to the first invalid control — the WCAG-required behaviour that every\n * consumer would otherwise have to hand-roll, and most would forget.\n *\n * Focus lives in the binding, not the engine, because it needs the DOM after\n * the commit; the engine only names the field (firstInvalid) and mints the id.\n */\nexport function useSubmit(): () => { ok: boolean; errors: Record<string, string[]> } {\n const engine = useFormEngine()\n\n return useCallback(() => {\n const outcome = engine.submit()\n if (!outcome.ok && typeof document !== 'undefined') {\n // An ErrorSummary takes precedence: it lists every problem, and focusing\n // it announces the situation once. It focuses ITSELF when errors appear,\n // so nothing to do here. Without one, fall back to the first control.\n const summary = document.querySelector('[data-formancy-part=\"error-summary\"]')\n if (summary === null) {\n const firstInvalid = engine.firstInvalid()\n if (firstInvalid !== null) {\n const ids = engine.getFieldSnapshot(parsePath(firstInvalid)).ids\n document.getElementById(ids.control)?.focus()\n }\n }\n }\n return outcome\n }, [engine])\n}\n","import type { ComponentType, ReactNode } from 'react'\nimport { parsePath } from '@formancy/core'\nimport type { FieldDef, FieldType } from '@formancy/spec'\nimport { useFormEngine } from './context.js'\nimport { useField } from './use-field.js'\nimport type { FieldBinding } from './use-field.js'\nimport { useRepeater } from './use-repeater.js'\nimport { useSubmit } from './use-submit.js'\nimport { useWizard } from './use-wizard.js'\n\n/**\n * The component registry — theming mechanism number two. The schema decides\n * WHAT a field is; the registry decides what RENDERS it, with per-path entries\n * beating per-type entries beating the built-in defaults. A design system\n * replaces the entire visual layer by handing in a registry, without forking\n * anything.\n */\nexport interface FieldComponentProps {\n path: string\n label: string\n}\n\nexport type FieldComponent = ComponentType<FieldComponentProps>\n\nexport interface Registry {\n byType?: Partial<Record<FieldType, FieldComponent>>\n byPath?: Record<string, FieldComponent>\n}\n\nexport interface SubmitOutcome {\n ok: boolean\n errors: Record<string, string[]>\n /** The canonical value, present when accepted. */\n data?: unknown\n}\n\nexport interface FormancyFormProps {\n /**\n * Display text per wire path (row fields by their template wire,\n * `items[].name`). A `label` on the model definition wins — that is how\n * fixture schemas carry text until the spec's i18n section lands; a missing\n * entry falls back to the wire path, which is at least honest.\n */\n labels?: Record<string, string>\n registry?: Registry\n submitLabel?: string\n onSubmit?: (outcome: SubmitOutcome) => void\n}\n\n/**\n * Renders the whole form from the engine: one slot per field, resolved through\n * the registry. Slots subscribe individually, so a keystroke re-renders one\n * field and a visibility flip mounts or unmounts exactly the fields it hit.\n * A paged schema renders a stepper, one page at a time, navigation, and the\n * submit control on the last page — a failed submit navigates to the first\n * page with a problem instead of leaving the user on a clean review page\n * staring at a rejection.\n */\nexport function FormancyForm(props: FormancyFormProps) {\n const engine = useFormEngine()\n return engine.wizard() === undefined ? <FlatForm {...props} /> : <PagedForm {...props} />\n}\n\nfunction SubmitButton({ submitLabel, onSubmit, onFailedNavigate }: FormancyFormProps & { onFailedNavigate?: (page: number) => void }) {\n const engine = useFormEngine()\n const submit = useSubmit()\n return (\n <button\n type=\"button\"\n data-formancy-part=\"submit\"\n onClick={() => {\n const outcome = submit()\n if (!outcome.ok && onFailedNavigate !== undefined) {\n const firstInvalid = engine.firstInvalid()\n if (firstInvalid !== null) onFailedNavigate(engine.pageOf(parsePath(firstInvalid)))\n }\n onSubmit?.(\n outcome.ok\n ? { ok: true, errors: outcome.errors, data: engine.value() }\n : { ok: false, errors: outcome.errors },\n )\n }}\n >\n {submitLabel ?? 'Submit'}\n </button>\n )\n}\n\nfunction FlatForm(props: FormancyFormProps) {\n return (\n <>\n <FieldList {...props} />\n <SubmitButton {...props} />\n </>\n )\n}\n\nfunction PagedForm(props: FormancyFormProps) {\n const engine = useFormEngine()\n const wizard = useWizard()\n const pages = engine.pages()\n const lastPage = wizard.pageCount - 1\n\n return (\n <>\n <nav data-formancy-part=\"stepper\" aria-label=\"Progress\">\n <ol>\n {pages.map((page, index) => (\n <li key={page.key} aria-current={index === wizard.page ? 'step' : undefined}>\n {engine.text(page.def.label) ?? page.key}\n </li>\n ))}\n </ol>\n </nav>\n <FieldList {...props} page={wizard.page} />\n <div data-formancy-part=\"wizard-nav\">\n {wizard.page > 0 ? (\n <button type=\"button\" onClick={() => wizard.back()}>\n Back\n </button>\n ) : null}\n {wizard.page < lastPage ? (\n <button type=\"button\" onClick={() => void wizard.next()}>\n Next\n </button>\n ) : (\n <SubmitButton {...props} onFailedNavigate={(page) => wizard.goTo(page)} />\n )}\n </div>\n </>\n )\n}\n\nfunction FieldList({ labels, registry, page }: FormancyFormProps & { page?: number }) {\n const engine = useFormEngine()\n const repeaterWires = engine.repeaterPaths()\n\n const inPage = (wire: string): boolean =>\n page === undefined || engine.pageOf(parsePath(wire)) === page\n\n // Row fields render inside their repeater's own section, never in the flat\n // list — a row needs its remove button and its position context.\n const staticWires = engine\n .fieldPaths()\n .filter((wire) => !repeaterWires.some((repeater) => wire.startsWith(`${repeater}[`)))\n\n return (\n <>\n {staticWires.filter(inPage).map((wire) => (\n <FieldSlot key={wire} path={wire} fallbackLabel={labels?.[wire]} registry={registry} />\n ))}\n {repeaterWires.filter(inPage).map((wire) => (\n <RepeaterSection key={wire} wire={wire} labels={labels} registry={registry} />\n ))}\n </>\n )\n}\n\nfunction FieldSlot({\n path,\n fallbackLabel,\n registry,\n}: {\n path: string\n fallbackLabel?: string | undefined\n registry?: Registry | undefined\n}) {\n const field = useField(path)\n\n // A hidden field leaves the DOM entirely: display:none would still ship the\n // markup, keep it in the accessibility tree's shadow, and leak its labels\n // to screen-reader \"read all\" passes.\n if (!field.visible) return null\n\n const Component =\n registry?.byPath?.[path] ?? registry?.byType?.[field.type] ?? DEFAULT_COMPONENTS[field.type]\n if (Component === null) return null\n\n const label = field.label ?? fallbackLabel ?? path\n return <Component path={path} label={label} />\n}\n\nfunction RepeaterSection({\n wire,\n labels,\n registry,\n}: {\n wire: string\n labels?: Record<string, string> | undefined\n registry?: Registry | undefined\n}) {\n const engine = useFormEngine()\n const repeater = useRepeater(wire)\n const def = engine.repeaters().find((candidate) => candidate.wire === wire)?.def\n const label = engine.text(def?.label) ?? labels?.[wire] ?? wire\n const addLabel = def?.addLabel ?? `Add ${label}`\n const removeLabel = def?.removeLabel ?? `Remove ${label}`\n\n const fallbackFor = (instanceWire: string): string | undefined => {\n const template = instanceWire.replace(/\\[\\d+\\]/, '[]')\n return labels?.[template] ?? labels?.[instanceWire]\n }\n\n return (\n <fieldset data-formancy-part=\"repeater\">\n <legend data-formancy-part=\"repeater-legend\">{label}</legend>\n {repeater.rowIds.map((rowId, index) => (\n // Keyed by identity, not position: removing a row renumbers every row\n // after it, and an index key would make React reuse the wrong DOM\n // nodes — moving focus and animating the wrong element.\n <div data-formancy-part=\"row\" key={rowId}>\n {engine\n .fieldPaths()\n .filter((candidate) => candidate.startsWith(`${wire}[${index}]`))\n .map((instanceWire) => (\n <FieldSlot\n key={instanceWire}\n path={instanceWire}\n fallbackLabel={fallbackFor(instanceWire)}\n registry={registry}\n />\n ))}\n {/* Position context in the NAME, so a screen-reader user knows which\n row this button kills without walking the tree. */}\n <button type=\"button\" onClick={() => repeater.removeRow(index)}>\n {`${removeLabel} ${index + 1} of ${repeater.rowCount}`}\n </button>\n </div>\n ))}\n <button type=\"button\" onClick={() => repeater.addRow()}>\n {addLabel}\n </button>\n </fieldset>\n )\n}\n\n/** Shared unstyled shell: real label, control, error text as the describedby\n * target. Zero CSS; `data-formancy-part` is the styling hook. */\nfunction FieldShell({\n field,\n label,\n children,\n}: {\n field: FieldBinding\n label: string\n children: ReactNode\n}) {\n return (\n <div\n data-formancy-part=\"field\"\n data-state={field.touched && field.errors.length > 0 ? 'invalid' : 'valid'}\n >\n <label data-formancy-part=\"label\" {...field.labelProps}>\n {label}\n </label>\n {children}\n {field.touched && field.errors.length > 0 ? (\n <p data-formancy-part=\"error\" {...field.errorProps}>\n {field.errors.join(', ')}\n </p>\n ) : null}\n </div>\n )\n}\n\nfunction TextField({ path, label }: FieldComponentProps) {\n const field = useField(path)\n return (\n <FieldShell field={field} label={label}>\n <input\n type=\"text\"\n {...field.controlProps}\n value={typeof field.value === 'string' ? field.value : ''}\n onChange={(event) => field.setValue(event.target.value)}\n onBlur={() => field.touch()}\n />\n </FieldShell>\n )\n}\n\nfunction TextareaField({ path, label }: FieldComponentProps) {\n const field = useField(path)\n return (\n <FieldShell field={field} label={label}>\n <textarea\n {...field.controlProps}\n value={typeof field.value === 'string' ? field.value : ''}\n onChange={(event) => field.setValue(event.target.value)}\n onBlur={() => field.touch()}\n />\n </FieldShell>\n )\n}\n\nfunction NumberField({ path, label }: FieldComponentProps) {\n const field = useField(path)\n return (\n <FieldShell field={field} label={label}>\n <input\n type=\"number\"\n {...field.controlProps}\n value={typeof field.value === 'number' ? field.value : ''}\n onChange={(event) =>\n field.setValue(event.target.value === '' ? null : event.target.valueAsNumber)\n }\n onBlur={() => field.touch()}\n />\n </FieldShell>\n )\n}\n\nfunction CheckboxField({ path, label }: FieldComponentProps) {\n const field = useField(path)\n return (\n <FieldShell field={field} label={label}>\n <input\n type=\"checkbox\"\n {...field.controlProps}\n checked={field.value === true}\n onChange={(event) => field.setValue(event.target.checked)}\n onBlur={() => field.touch()}\n />\n </FieldShell>\n )\n}\n\nfunction DateField({ path, label }: FieldComponentProps) {\n const field = useField(path)\n return (\n <FieldShell field={field} label={label}>\n <input\n type=\"date\"\n {...field.controlProps}\n value={typeof field.value === 'string' ? field.value : ''}\n onChange={(event) => field.setValue(event.target.value === '' ? null : event.target.value)}\n onBlur={() => field.touch()}\n />\n </FieldShell>\n )\n}\n\n/**\n * Option labels resolved to strings, since a label may be a message reference.\n * Falling back to the stored value keeps an untranslated option selectable\n * rather than blank.\n */\nfunction useResolvedOptions(field: { def: FieldDef }): Array<{ value: string; label: string }> {\n const engine = useFormEngine()\n return (field.def.options ?? []).map((option) => ({\n value: option.value,\n label: engine.text(option.label) ?? option.value,\n }))\n}\n\nfunction SelectField({ path, label }: FieldComponentProps) {\n const field = useField(path)\n const options = useResolvedOptions(field)\n return (\n <FieldShell field={field} label={label}>\n {/* Setting `value` on the select works only because React applies it\n AFTER the option children render; a select's value property is\n settable once its options exist. Angular binds [selected] per option\n for the same reason — the explicit form of the same contract. */}\n <select\n {...field.controlProps}\n value={typeof field.value === 'string' ? field.value : ''}\n onChange={(event) => field.setValue(event.target.value === '' ? null : event.target.value)}\n onBlur={() => field.touch()}\n >\n {/* The empty option is the unanswered state; without it the browser\n silently pre-selects the first real option, which the engine never\n heard about. */}\n <option value=\"\" />\n {options.map((option) => (\n <option key={option.value} value={option.value}>\n {option.label}\n </option>\n ))}\n </select>\n </FieldShell>\n )\n}\n\nfunction RadioGroupField({ path, label }: FieldComponentProps) {\n const field = useField(path)\n const options = useResolvedOptions(field)\n const showError = field.touched && field.errors.length > 0\n return (\n <fieldset\n data-formancy-part=\"field\"\n data-state={showError ? 'invalid' : 'valid'}\n aria-describedby={field.controlProps['aria-describedby']}\n >\n <legend data-formancy-part=\"label\">{label}</legend>\n {options.map((option) => {\n const optionId = `${field.ids.control}:${option.value}`\n return (\n <span key={option.value} data-formancy-part=\"radio-option\">\n <input\n type=\"radio\"\n id={optionId}\n name={field.controlProps.name}\n value={option.value}\n checked={field.value === option.value}\n onChange={() => field.setValue(option.value)}\n onBlur={() => field.touch()}\n />\n <label htmlFor={optionId}>{option.label}</label>\n </span>\n )\n })}\n {showError ? (\n <p data-formancy-part=\"error\" {...field.errorProps}>\n {field.errors.join(', ')}\n </p>\n ) : null}\n </fieldset>\n )\n}\n\n/**\n * The built-in unstyled components. `null` means the type renders nothing here:\n * hidden and static are non-inputs, and the container types are laid out by\n * their own machinery, not by a leaf slot.\n */\nconst DEFAULT_COMPONENTS: Record<FieldType, FieldComponent | null> = {\n text: TextField,\n textarea: TextareaField,\n number: NumberField,\n checkbox: CheckboxField,\n date: DateField,\n select: SelectField,\n radio: RadioGroupField,\n hidden: null,\n static: null,\n group: null,\n page: null,\n repeater: null,\n}\n","import { useCallback, useEffect, useRef, useSyncExternalStore } from 'react'\nimport { parsePath } from '@formancy/core'\nimport { useFormEngine } from './context.js'\n\nexport interface ErrorSummaryProps {\n labels?: Record<string, string>\n}\n\n/**\n * The error summary a failed submit focuses.\n *\n * The semantics are deliberate and easy to get wrong: the container takes\n * focus via tabindex=\"-1\" — focusing it already makes screen readers announce\n * it, so role=\"alert\" would announce it TWICE. Each entry is a real in-page\n * link to the offending control, because links are what \"take me to the\n * problem\" already means to assistive tech.\n */\nexport function ErrorSummary({ labels }: ErrorSummaryProps) {\n const engine = useFormEngine()\n const subscribe = useCallback((onChange: () => void) => engine.subscribe(onChange), [engine])\n const getErrors = useCallback(() => engine.visibleErrors(), [engine])\n const errors = useSyncExternalStore(subscribe, getErrors, getErrors)\n const region = useRef<HTMLDivElement | null>(null)\n const previousCount = useRef(0)\n\n // Focus when errors APPEAR (a submit surfaced them), not on every keystroke\n // that edits an already-broken field.\n useEffect(() => {\n if (errors.length > 0 && previousCount.current === 0) region.current?.focus()\n previousCount.current = errors.length\n }, [errors])\n\n if (errors.length === 0) return null\n\n const labelFor = (path: string): string =>\n labels?.[path] ?? labels?.[path.replace(/\\[\\d+\\]/, '[]')] ?? path\n\n return (\n <div data-formancy-part=\"error-summary\" tabIndex={-1} ref={region}>\n <h2 data-formancy-part=\"error-summary-heading\">\n {errors.length === 1 ? 'There is 1 problem to fix' : `There are ${errors.length} problems to fix`}\n </h2>\n <ul>\n {errors.map(({ path, codes }) => {\n const controlId = engine.getFieldSnapshot(parsePath(path)).ids.control\n return (\n <li key={path}>\n <a\n href={`#${controlId}`}\n onClick={(event) => {\n // The hash alone scrolls but does not focus; do both.\n event.preventDefault()\n document.getElementById(controlId)?.focus()\n }}\n >\n {`${labelFor(path)}: ${codes.join(', ')}`}\n </a>\n </li>\n )\n })}\n </ul>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAM,kBAAkB,cAAiC,IAAI;AAE7D,SAAgB,iBAAiB,EAAE,QAAQ,YAA0D;CACnG,OAAO,oBAAC,gBAAgB,UAAjB;EAA0B,OAAO;EAAS;CAAmC,CAAA;AACtF;AAEA,SAAgB,gBAA4B;CAC1C,MAAM,SAAS,WAAW,eAAe;CACzC,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,8EAA8E;CAEhG,OAAO;AACT;;;;;;;;;;;;;ACIA,SAAgB,SAAS,MAAmC;CAC1D,MAAM,SAAS,cAAc;CAE7B,MAAM,OAAO,OAAO,SAAS,WAAW,OAAO,WAAW,IAAI;CAC9D,MAAM,SAAS,cAAc,UAAU,IAAI,GAAG,CAAC,IAAI,CAAC;CAEpD,MAAM,YAAY,aACf,aAAyB,OAAO,eAAe,QAAQ,QAAQ,GAChE,CAAC,QAAQ,MAAM,CACjB;CACA,MAAM,cAAc,kBAAkB,OAAO,iBAAiB,MAAM,GAAG,CAAC,QAAQ,MAAM,CAAC;CAEvF,MAAM,WAAW,qBAAqB,WAAW,aAAa,WAAW;CAEzE,MAAM,WAAW,aAAa,UAAmB,OAAO,SAAS,QAAQ,KAAK,GAAG,CAAC,QAAQ,MAAM,CAA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ACjC,GAAG,CAAC,MAAM,CAAC;CAEX,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,MAAM,YAAY,SAChB,SAAS,SAAS,SAAS,KAAK,QAAQ,WAAW,IAAI,MAAM;CAE/D,OACE,qBAAC,OAAD;EAAK,sBAAmB;EAAgB,UAAU;EAAI,KAAK;EAA3D,UAAA,CACE,oBAAC,MAAD;GAAI,sBAAmB;GACpB,UAAA,OAAO,WAAW,IAAI,8BAA8B,aAAa,OAAO,OAAO;EAC9E,CAAA,GACJ,oBAAC,MAAD,EAAA,UACG,OAAO,KAAK,EAAE,MAAM,YAAY;GAC/B,MAAM,YAAY,OAAO,iBAAiB,UAAU,IAAI,CAAC,CAAC,CAAC,IAAI;GAC/D,OACE,oBAAC,MAAD,EAAA,UACE,oBAAC,KAAD;IACE,MAAM,IAAI;IACV,UAAU,UAAU;KAElB,MAAM,eAAe;KACrB,SAAS,eAAe,SAAS,CAAC,EAAE,MAAM;IAC5C;IAEC,UAAA,GAAG,SAAS,IAAI,EAAE,IAAI,MAAM,KAAK,IAAI;GACrC,CAAA,EACD,GAXK,IAWL;EAER,CAAC,EACC,CAAA,CACD;;AAET"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@formancy/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Idiomatic React binding for the formancy form engine.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"NOTICE"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@formancy/conformance": "0.1.0",
|
|
21
|
+
"@formancy/core": "0.1.0",
|
|
22
|
+
"@formancy/spec": "0.1.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": "^19.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
29
|
+
"@testing-library/react": "^16.3.3",
|
|
30
|
+
"@testing-library/user-event": "^14.6.7",
|
|
31
|
+
"@types/react": "^19.3.0",
|
|
32
|
+
"@types/react-dom": "^19.3.0",
|
|
33
|
+
"jsdom": "^30.1.0",
|
|
34
|
+
"publint": "^0.3.24",
|
|
35
|
+
"react": "^19.3.0",
|
|
36
|
+
"react-dom": "^19.3.0",
|
|
37
|
+
"tsdown": "^0.23.0",
|
|
38
|
+
"typescript": "~6.0.3",
|
|
39
|
+
"unrun": "^0.3.1",
|
|
40
|
+
"vitest": "^5.0.1"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/sharkysan/formancy.ai.git",
|
|
48
|
+
"directory": "packages/react"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/sharkysan/formancy.ai",
|
|
51
|
+
"bugs": "https://github.com/sharkysan/formancy.ai/issues",
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsdown",
|
|
54
|
+
"test": "vitest run",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"check:pkg": "publint && attw --pack . --profile esm-only"
|
|
57
|
+
}
|
|
58
|
+
}
|