formhell 0.1.5
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 +21 -0
- package/README.md +511 -0
- package/dist/index.d.mts +127 -0
- package/dist/index.d.ts +127 -0
- package/dist/index.js +4445 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4408 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles-UY6N5SPU.css +599 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ryan Rutkin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
# formhell
|
|
2
|
+
|
|
3
|
+
React Autological Forms for React.
|
|
4
|
+
|
|
5
|
+
Incredibly robust yet remarkably simple JSON Schema based forms for React.
|
|
6
|
+
|
|
7
|
+
## Why This Library Exists
|
|
8
|
+
|
|
9
|
+
I wrote this library out of pure JSON Schema fatigue.
|
|
10
|
+
|
|
11
|
+
Specifically, I was frustrated by how the leading JSON Schema form libraries (including react-json-schema-forms) often fall short once schemas get complex, and how defaults behavior can become surprisingly unhelpful in real applications.
|
|
12
|
+
|
|
13
|
+
I wanted strong support for modern JSON Schema behavior, including deeper keyword combinations, robust `$ref` flows, and sensible defaults behavior. Many popular schema-form approaches feel great for simple demos, then quickly become awkward when you need advanced schema features, strict correctness, or predictable default handling.
|
|
14
|
+
|
|
15
|
+
formhell exists to be both:
|
|
16
|
+
|
|
17
|
+
- robust enough for complex schemas,
|
|
18
|
+
- straightforward enough to use without a three-day setup ritual.
|
|
19
|
+
|
|
20
|
+
In short: this is built to be the most robust and still easy-to-use JSON Schema form library available for React.
|
|
21
|
+
|
|
22
|
+
## Comparison Snapshot
|
|
23
|
+
|
|
24
|
+
The goal here is not drama. The goal is practical capability when schemas stop being toy examples.
|
|
25
|
+
|
|
26
|
+
| Capability | formhell | Typical basic JSON Schema form setup |
|
|
27
|
+
| --- | --- | --- |
|
|
28
|
+
| Visual schema authoring | Yes (`SchemaBuilder`) | Usually no built-in builder |
|
|
29
|
+
| Schema + form side-by-side workflow | Yes | Usually custom integration |
|
|
30
|
+
| Async missing `$ref` loading | Yes (`getSchema`) | Often limited or app-specific |
|
|
31
|
+
| Peer schema document support | Yes | Varies |
|
|
32
|
+
| Draft 2020-12 oriented workflows | Yes | Varies by implementation |
|
|
33
|
+
| Advanced keywords (`if/then/else`, `dependentSchemas`, `unevaluated*`) | Designed for this | Often partial |
|
|
34
|
+
| Widget overrides by pointer and type | Yes | Usually type-only or custom plumbing |
|
|
35
|
+
| Defaults strategy control | Yes (`all` / `required-only`) | Often limited |
|
|
36
|
+
| Validation feedback on every change | Yes | Usually yes |
|
|
37
|
+
|
|
38
|
+
If your form requirements include deep JSON Schema support and your timeline includes "this quarter," this matrix is the point.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
If you're already rolling with stuff, this should do it:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install formhell
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
If you don't already have the full set of peer dependencies, here's the full install:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install formhell react react-dom ajv json-pointer-relational @hyperjump/json-schema html-react-parser
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Import components and styles:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { SchemaForm, SchemaBuilder, SchemaBuilderHelper } from "formhell";
|
|
58
|
+
import "formhell/styles.css";
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Exported Components At A Glance
|
|
62
|
+
|
|
63
|
+
- `SchemaForm`: Render data-entry forms from JSON Schema.
|
|
64
|
+
- `SchemaBuilder`: Build or edit JSON Schema visually.
|
|
65
|
+
- `SchemaBuilderHelper`: Searchable keyword help for schema authors.
|
|
66
|
+
|
|
67
|
+
## SchemaForm
|
|
68
|
+
|
|
69
|
+
`SchemaForm` is the runtime form engine. Feed it a schema, optionally feed it data and peer schemas, and it emits updated data plus validation state on every change.
|
|
70
|
+
|
|
71
|
+
### SchemaForm features
|
|
72
|
+
|
|
73
|
+
- Supports JSON Schema types: `string`, `number`, `integer`, `boolean`, `object`, `array`, `null`.
|
|
74
|
+
- Handles nested objects/arrays recursively.
|
|
75
|
+
- Validates schema and data continuously.
|
|
76
|
+
- Resolves `$ref` references, including async peer schema fallback.
|
|
77
|
+
- Supports type-based and pointer-based widget overrides.
|
|
78
|
+
- Generates default values (`all` or `required-only`).
|
|
79
|
+
- Emits rich change metadata (`fieldPointer`, `prev`, `next`) to power audit logs, autosave, analytics, and debugging.
|
|
80
|
+
|
|
81
|
+
### SchemaForm props (with examples)
|
|
82
|
+
|
|
83
|
+
#### `schema: JSONSchema` (required)
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
const schema = {
|
|
87
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
88
|
+
title: "Profile",
|
|
89
|
+
type: "object",
|
|
90
|
+
properties: {
|
|
91
|
+
firstName: { type: "string", title: "First name" },
|
|
92
|
+
age: { type: "integer", minimum: 0 }
|
|
93
|
+
},
|
|
94
|
+
required: ["firstName"]
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
<SchemaForm schema={schema} />;
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### `data?: OutputData`
|
|
101
|
+
|
|
102
|
+
Provide controlled data. If omitted, the form builds initial data from schema/default rules.
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
<SchemaForm schema={schema} data={{ firstName: "Ada", age: 36 }} />
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### `options?: { defaults?: "all" | "required-only" }`
|
|
109
|
+
|
|
110
|
+
Choose how aggressively defaults are generated.
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
<SchemaForm
|
|
114
|
+
schema={schema}
|
|
115
|
+
options={{ defaults: "required-only" }}
|
|
116
|
+
/>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### `peerSchemas?: JSONSchema[] | Record<string, JSONSchema>`
|
|
120
|
+
|
|
121
|
+
Provide external schema documents for `$ref` resolution.
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
const addressSchema = {
|
|
125
|
+
$id: "https://example.com/schemas/address",
|
|
126
|
+
type: "object",
|
|
127
|
+
definitions: {
|
|
128
|
+
address: {
|
|
129
|
+
type: "object",
|
|
130
|
+
properties: { city: { type: "string" } },
|
|
131
|
+
required: ["city"]
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
<SchemaForm
|
|
137
|
+
schema={{
|
|
138
|
+
type: "object",
|
|
139
|
+
properties: {
|
|
140
|
+
shippingAddress: { $ref: "https://example.com/schemas/address#/definitions/address" }
|
|
141
|
+
}
|
|
142
|
+
}}
|
|
143
|
+
peerSchemas={[addressSchema]}
|
|
144
|
+
/>;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### `getSchema?: (requestedSchema: string) => Promise<JSONSchema>`
|
|
148
|
+
|
|
149
|
+
Async fallback when a referenced schema is missing.
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
<SchemaForm
|
|
153
|
+
schema={mainSchema}
|
|
154
|
+
getSchema={async (requestedSchema) => {
|
|
155
|
+
const response = await fetch(`/api/schemas?ref=${encodeURIComponent(requestedSchema)}`);
|
|
156
|
+
if (!response.ok) {
|
|
157
|
+
throw new Error("Schema fetch failed");
|
|
158
|
+
}
|
|
159
|
+
return (await response.json()) as any;
|
|
160
|
+
}}
|
|
161
|
+
/>
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
When waiting on async peer schema resolution, the component displays a loading state.
|
|
165
|
+
|
|
166
|
+
#### `widgets?: SchemaFormWidgets`
|
|
167
|
+
|
|
168
|
+
Override rendering by type and/or exact schema pointer.
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
function FancyStringField(props: any) {
|
|
172
|
+
return (
|
|
173
|
+
<label>
|
|
174
|
+
{props.label}
|
|
175
|
+
<input
|
|
176
|
+
value={props.value ?? ""}
|
|
177
|
+
onChange={(event) => props.onChange(event.target.value)}
|
|
178
|
+
/>
|
|
179
|
+
</label>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function NameOnlyField(props: any) {
|
|
184
|
+
return (
|
|
185
|
+
<label>
|
|
186
|
+
Name override:
|
|
187
|
+
<input
|
|
188
|
+
value={props.value ?? ""}
|
|
189
|
+
onChange={(event) => props.onChange(event.target.value.toUpperCase())}
|
|
190
|
+
/>
|
|
191
|
+
</label>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
<SchemaForm
|
|
196
|
+
schema={schema}
|
|
197
|
+
widgets={{
|
|
198
|
+
String: FancyStringField,
|
|
199
|
+
"/properties/firstName": NameOnlyField
|
|
200
|
+
}}
|
|
201
|
+
/>
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Widget precedence:
|
|
205
|
+
|
|
206
|
+
1. Exact pointer override
|
|
207
|
+
2. Type override
|
|
208
|
+
3. Built-in widget
|
|
209
|
+
|
|
210
|
+
#### `onChange?: (data, validationErrors, fieldPointer, prev, next) => void`
|
|
211
|
+
|
|
212
|
+
Use this to sync state, inspect changes, and surface validation messages.
|
|
213
|
+
|
|
214
|
+
```tsx
|
|
215
|
+
const [data, setData] = useState({});
|
|
216
|
+
const [errors, setErrors] = useState<Array<{ message: string; source: string }>>([]);
|
|
217
|
+
|
|
218
|
+
<SchemaForm
|
|
219
|
+
schema={schema}
|
|
220
|
+
data={data}
|
|
221
|
+
onChange={(nextData, validationErrors, fieldPointer, prev, next) => {
|
|
222
|
+
setData(nextData as any);
|
|
223
|
+
setErrors(validationErrors as any);
|
|
224
|
+
console.log("Changed", fieldPointer, "from", prev, "to", next);
|
|
225
|
+
}}
|
|
226
|
+
/>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### SchemaForm advanced schema example
|
|
230
|
+
|
|
231
|
+
If your schema enjoys advanced keywords, formhell does not panic.
|
|
232
|
+
|
|
233
|
+
```tsx
|
|
234
|
+
const advancedSchema = {
|
|
235
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
236
|
+
type: "object",
|
|
237
|
+
properties: {
|
|
238
|
+
role: { type: "string", enum: ["admin", "editor", "viewer"] },
|
|
239
|
+
tags: {
|
|
240
|
+
type: "array",
|
|
241
|
+
prefixItems: [{ type: "string" }, { type: "integer" }],
|
|
242
|
+
items: false,
|
|
243
|
+
minItems: 2
|
|
244
|
+
},
|
|
245
|
+
metadata: {
|
|
246
|
+
type: "object",
|
|
247
|
+
patternProperties: {
|
|
248
|
+
"^x-": { type: "string" }
|
|
249
|
+
},
|
|
250
|
+
unevaluatedProperties: { type: "string" }
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
dependentRequired: {
|
|
254
|
+
role: ["tags"]
|
|
255
|
+
},
|
|
256
|
+
if: { properties: { role: { const: "admin" } } },
|
|
257
|
+
then: {
|
|
258
|
+
properties: {
|
|
259
|
+
metadata: {
|
|
260
|
+
properties: {
|
|
261
|
+
"x-audit": { type: "string" }
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## SchemaBuilder
|
|
270
|
+
|
|
271
|
+
`SchemaBuilder` is the schema authoring cockpit. You can visually construct schema structures and constraints, while getting immediate validation feedback.
|
|
272
|
+
|
|
273
|
+
### SchemaBuilder features
|
|
274
|
+
|
|
275
|
+
- Build object and array structures interactively.
|
|
276
|
+
- Add/edit core metadata (`title`, `description`, `$id`, `$schema`).
|
|
277
|
+
- Manage type unions.
|
|
278
|
+
- Edit constraints (`minimum`, `maximum`, `multipleOf`, string lengths, formats, etc.).
|
|
279
|
+
- Configure object keywords (`properties`, `required`, `dependentRequired`, `dependentSchemas`, `propertyNames`, `patternProperties`, `additionalProperties`, `unevaluatedProperties`).
|
|
280
|
+
- Configure array keywords (`items`, `prefixItems`, `minItems`, `maxItems`, `unevaluatedItems`).
|
|
281
|
+
- Work with composition and logic (`allOf`, `anyOf`, `oneOf`, `not`, `if`/`then`/`else`).
|
|
282
|
+
- Use the advanced raw JSON editor for direct schema editing.
|
|
283
|
+
- Receive schema validation and JSON parse errors via callback.
|
|
284
|
+
|
|
285
|
+
### SchemaBuilder props (with examples)
|
|
286
|
+
|
|
287
|
+
#### `schema?: JSONSchema`
|
|
288
|
+
|
|
289
|
+
Seed the builder with an existing schema.
|
|
290
|
+
|
|
291
|
+
```tsx
|
|
292
|
+
<SchemaBuilder schema={advancedSchema} />
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
#### `domain?: string`
|
|
296
|
+
|
|
297
|
+
Provide a base domain used for generated schema IDs in the editor flow.
|
|
298
|
+
|
|
299
|
+
```tsx
|
|
300
|
+
<SchemaBuilder domain="https://example.com/schemas/" />
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
#### `onChange?: (schema, validationErrors) => void`
|
|
304
|
+
|
|
305
|
+
Capture live output schema and validation state.
|
|
306
|
+
|
|
307
|
+
```tsx
|
|
308
|
+
const [builtSchema, setBuiltSchema] = useState({});
|
|
309
|
+
const [builderErrors, setBuilderErrors] = useState<any[]>([]);
|
|
310
|
+
|
|
311
|
+
<SchemaBuilder
|
|
312
|
+
schema={advancedSchema}
|
|
313
|
+
domain="https://example.com/schemas/"
|
|
314
|
+
onChange={(nextSchema, validationErrors) => {
|
|
315
|
+
setBuiltSchema(nextSchema as any);
|
|
316
|
+
setBuilderErrors(validationErrors as any);
|
|
317
|
+
}}
|
|
318
|
+
/>;
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### SchemaBuilder + SchemaForm side-by-side
|
|
322
|
+
|
|
323
|
+
This is where formhell gets delightfully dramatic: author and render in one screen.
|
|
324
|
+
|
|
325
|
+
```tsx
|
|
326
|
+
function BuilderAndFormPlayground() {
|
|
327
|
+
const [schema, setSchema] = useState<any | null>(null);
|
|
328
|
+
const [data, setData] = useState<any>({});
|
|
329
|
+
|
|
330
|
+
return (
|
|
331
|
+
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 }}>
|
|
332
|
+
<SchemaBuilder
|
|
333
|
+
domain="https://example.com/schemas/"
|
|
334
|
+
onChange={(nextSchema) => setSchema(nextSchema as any)}
|
|
335
|
+
/>
|
|
336
|
+
|
|
337
|
+
{schema ? (
|
|
338
|
+
<SchemaForm
|
|
339
|
+
schema={schema}
|
|
340
|
+
data={data}
|
|
341
|
+
onChange={(nextData) => setData(nextData as any)}
|
|
342
|
+
/>
|
|
343
|
+
) : (
|
|
344
|
+
<div>Start editing in SchemaBuilder to render a form.</div>
|
|
345
|
+
)}
|
|
346
|
+
</div>
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## SchemaBuilderHelper
|
|
352
|
+
|
|
353
|
+
`SchemaBuilderHelper` is the built-in keyword reference assistant. Think of it as your schema sidekick that politely taps your shoulder when your brain says, "what does `dependentSchemas` do again?"
|
|
354
|
+
|
|
355
|
+
### SchemaBuilderHelper features
|
|
356
|
+
|
|
357
|
+
- Fast keyword search with debounce.
|
|
358
|
+
- Configurable result limit.
|
|
359
|
+
- Custom placeholder text.
|
|
360
|
+
- Optional initial query for preloaded guidance.
|
|
361
|
+
- Override built-in help content with your own docs.
|
|
362
|
+
|
|
363
|
+
### SchemaBuilderHelper props (with examples)
|
|
364
|
+
|
|
365
|
+
#### `debounceMs?: number`
|
|
366
|
+
|
|
367
|
+
```tsx
|
|
368
|
+
<SchemaBuilderHelper debounceMs={150} />
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
#### `maxResults?: number`
|
|
372
|
+
|
|
373
|
+
```tsx
|
|
374
|
+
<SchemaBuilderHelper maxResults={8} />
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
#### `placeholder?: string`
|
|
378
|
+
|
|
379
|
+
```tsx
|
|
380
|
+
<SchemaBuilderHelper placeholder="Search keyword docs..." />
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
#### `initialQuery?: string`
|
|
384
|
+
|
|
385
|
+
```tsx
|
|
386
|
+
<SchemaBuilderHelper initialQuery="condition" />
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
#### `helpContent?: Record<string, string | { longDetails: string; label?: string }>`
|
|
390
|
+
|
|
391
|
+
```tsx
|
|
392
|
+
const customHelp = {
|
|
393
|
+
if: "Apply a conditional branch.",
|
|
394
|
+
then: {
|
|
395
|
+
label: "Then",
|
|
396
|
+
longDetails: "Schema branch used when `if` matches."
|
|
397
|
+
},
|
|
398
|
+
else: {
|
|
399
|
+
label: "Else",
|
|
400
|
+
longDetails: "Schema branch used when `if` does not match."
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
<SchemaBuilderHelper helpContent={customHelp} />
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
## Complete Example: Async `$ref` Workflow
|
|
408
|
+
|
|
409
|
+
This demonstrates a practical setup with async peer schema loading.
|
|
410
|
+
|
|
411
|
+
```tsx
|
|
412
|
+
function RefAwareForm() {
|
|
413
|
+
const [data, setData] = useState<any>({});
|
|
414
|
+
|
|
415
|
+
const schema = {
|
|
416
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
417
|
+
type: "object",
|
|
418
|
+
properties: {
|
|
419
|
+
profile: {
|
|
420
|
+
$ref: "https://example.com/schemas/profile#/definitions/base"
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
return (
|
|
426
|
+
<SchemaForm
|
|
427
|
+
schema={schema}
|
|
428
|
+
data={data}
|
|
429
|
+
getSchema={async (requestedSchema) => {
|
|
430
|
+
const response = await fetch(`/schemas/by-ref?ref=${encodeURIComponent(requestedSchema)}`);
|
|
431
|
+
if (!response.ok) {
|
|
432
|
+
throw new Error(`Unable to load schema for ${requestedSchema}`);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return (await response.json()) as any;
|
|
436
|
+
}}
|
|
437
|
+
onChange={(nextData, validationErrors) => {
|
|
438
|
+
setData(nextData as any);
|
|
439
|
+
if (validationErrors.length > 0) {
|
|
440
|
+
console.warn("Validation issues", validationErrors);
|
|
441
|
+
}
|
|
442
|
+
}}
|
|
443
|
+
/>
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
## Validation Error Shapes
|
|
449
|
+
|
|
450
|
+
### SchemaForm validation error
|
|
451
|
+
|
|
452
|
+
```ts
|
|
453
|
+
type SchemaFormValidationError = {
|
|
454
|
+
message: string;
|
|
455
|
+
source: "schema" | "peerSchemas" | "ref-resolution" | "data";
|
|
456
|
+
};
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### SchemaBuilder validation error
|
|
460
|
+
|
|
461
|
+
```ts
|
|
462
|
+
type SchemaBuilderValidationError = {
|
|
463
|
+
message: string;
|
|
464
|
+
keyword?: string;
|
|
465
|
+
instancePath?: string;
|
|
466
|
+
schemaPath?: string;
|
|
467
|
+
source: "schema" | "json-parse";
|
|
468
|
+
};
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
## Scripts
|
|
472
|
+
|
|
473
|
+
- `npm run build` build library output to `dist`.
|
|
474
|
+
- `npm run typecheck` run TypeScript checks.
|
|
475
|
+
- `npm run playground:dev` run the local playground app.
|
|
476
|
+
- `npm run playground:build` build the playground app.
|
|
477
|
+
- `npm run playground:preview` preview built playground output.
|
|
478
|
+
|
|
479
|
+
## Local Playground
|
|
480
|
+
|
|
481
|
+
The repository includes a full playground under `playground` for interactive schema authoring and form rendering.
|
|
482
|
+
|
|
483
|
+
```bash
|
|
484
|
+
npm run playground:dev
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
## Discoverability Quick Guide
|
|
488
|
+
|
|
489
|
+
If you found this package while searching for any of the following, you are exactly in the right place:
|
|
490
|
+
|
|
491
|
+
- React JSON Schema form
|
|
492
|
+
- JSON Schema builder for React
|
|
493
|
+
- JSON Schema draft 2020-12 React support
|
|
494
|
+
- React form library with strong `$ref` resolution
|
|
495
|
+
- Schema-driven forms with practical defaults handling
|
|
496
|
+
|
|
497
|
+
### Relevant Links
|
|
498
|
+
|
|
499
|
+
- GitHub repository: https://github.com/RyanRutkin/formhell
|
|
500
|
+
- npm package: https://www.npmjs.com/package/formhell
|
|
501
|
+
- Live playground and docs landing page: https://ryanrutkin.github.io/formhell/
|
|
502
|
+
- React JSON Schema Form Refs guide: https://ryanrutkin.github.io/formhell/react-json-schema-form-refs
|
|
503
|
+
- Draft 2020-12 Form Builder guide: https://ryanrutkin.github.io/formhell/draft-2020-12-form-builder
|
|
504
|
+
|
|
505
|
+
### Why teams switch to formhell
|
|
506
|
+
|
|
507
|
+
- Better support for advanced JSON Schema constructs than typical basic form generators.
|
|
508
|
+
- More reliable behavior when schema complexity grows.
|
|
509
|
+
- Better defaults handling in real application flows.
|
|
510
|
+
- A visual schema builder that does not require giving up power-user control.
|
|
511
|
+
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, ComponentType } from 'react';
|
|
3
|
+
|
|
4
|
+
type JSONSchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
|
|
5
|
+
interface JSONSchema {
|
|
6
|
+
$id?: string;
|
|
7
|
+
$schema?: string;
|
|
8
|
+
$ref?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
type?: JSONSchemaType | JSONSchemaType[];
|
|
12
|
+
enum?: unknown[];
|
|
13
|
+
default?: unknown;
|
|
14
|
+
multipleOf?: number;
|
|
15
|
+
minimum?: number;
|
|
16
|
+
maximum?: number;
|
|
17
|
+
exclusiveMinimum?: number;
|
|
18
|
+
exclusiveMaximum?: number;
|
|
19
|
+
minProperties?: number;
|
|
20
|
+
maxProperties?: number;
|
|
21
|
+
deprecated?: boolean;
|
|
22
|
+
readOnly?: boolean;
|
|
23
|
+
writeOnly?: boolean;
|
|
24
|
+
examples?: unknown[];
|
|
25
|
+
properties?: Record<string, JSONSchema>;
|
|
26
|
+
patternProperties?: Record<string, JSONSchema>;
|
|
27
|
+
required?: string[];
|
|
28
|
+
dependentRequired?: Record<string, string[]>;
|
|
29
|
+
dependentSchemas?: Record<string, JSONSchema>;
|
|
30
|
+
items?: JSONSchema | boolean;
|
|
31
|
+
prefixItems?: JSONSchema[];
|
|
32
|
+
unevaluatedItems?: JSONSchema;
|
|
33
|
+
additionalProperties?: boolean | JSONSchema;
|
|
34
|
+
unevaluatedProperties?: JSONSchema;
|
|
35
|
+
propertyNames?: JSONSchema;
|
|
36
|
+
oneOf?: JSONSchema[];
|
|
37
|
+
anyOf?: JSONSchema[];
|
|
38
|
+
allOf?: JSONSchema[];
|
|
39
|
+
not?: JSONSchema;
|
|
40
|
+
if?: JSONSchema;
|
|
41
|
+
then?: JSONSchema;
|
|
42
|
+
else?: JSONSchema;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
type OutputData = unknown;
|
|
46
|
+
type PeerSchemasInput = JSONSchema[] | Record<string, JSONSchema>;
|
|
47
|
+
|
|
48
|
+
interface FieldComponentProps<TValue = unknown> {
|
|
49
|
+
label: string;
|
|
50
|
+
required: boolean;
|
|
51
|
+
pointer: string;
|
|
52
|
+
schema: JSONSchema;
|
|
53
|
+
value: TValue;
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
controls?: ReactNode;
|
|
56
|
+
onChange: (next: TValue) => void;
|
|
57
|
+
}
|
|
58
|
+
interface SchemaFormObjectProps extends FieldComponentProps<Record<string, unknown>> {
|
|
59
|
+
children: ReactNode;
|
|
60
|
+
}
|
|
61
|
+
interface SchemaFormArrayProps extends FieldComponentProps<unknown[]> {
|
|
62
|
+
itemsSchema?: JSONSchema;
|
|
63
|
+
itemSchemas?: JSONSchema[];
|
|
64
|
+
canAddItem?: boolean;
|
|
65
|
+
canRemoveItems?: boolean;
|
|
66
|
+
renderItem: (index: number, pointer: string, value: unknown) => ReactNode;
|
|
67
|
+
createDefaultItem: () => unknown;
|
|
68
|
+
}
|
|
69
|
+
type SchemaPointerWidget = ComponentType<any>;
|
|
70
|
+
interface SchemaFormWidgets {
|
|
71
|
+
[schemaPointer: string]: SchemaPointerWidget | undefined;
|
|
72
|
+
String?: ComponentType<FieldComponentProps<string>>;
|
|
73
|
+
Select?: ComponentType<FieldComponentProps<unknown>>;
|
|
74
|
+
Boolean?: ComponentType<FieldComponentProps<boolean>>;
|
|
75
|
+
Number?: ComponentType<FieldComponentProps<number | undefined>>;
|
|
76
|
+
Integer?: ComponentType<FieldComponentProps<number | undefined>>;
|
|
77
|
+
Null?: ComponentType<FieldComponentProps<null>>;
|
|
78
|
+
Object?: ComponentType<SchemaFormObjectProps>;
|
|
79
|
+
Array?: ComponentType<SchemaFormArrayProps>;
|
|
80
|
+
}
|
|
81
|
+
interface SchemaFormOptions {
|
|
82
|
+
defaults?: "all" | "required-only";
|
|
83
|
+
}
|
|
84
|
+
interface SchemaFormProps {
|
|
85
|
+
schema: JSONSchema;
|
|
86
|
+
peerSchemas?: PeerSchemasInput;
|
|
87
|
+
getSchema?: (requestedSchema: string) => Promise<JSONSchema>;
|
|
88
|
+
widgets?: SchemaFormWidgets;
|
|
89
|
+
options?: SchemaFormOptions;
|
|
90
|
+
data?: OutputData;
|
|
91
|
+
onChange?: (data: OutputData, validationErrors: SchemaFormValidationError[], fieldPointer: string, prev: any, next: any) => void;
|
|
92
|
+
}
|
|
93
|
+
interface SchemaFormValidationError {
|
|
94
|
+
message: string;
|
|
95
|
+
source: "schema" | "peerSchemas" | "ref-resolution" | "data";
|
|
96
|
+
}
|
|
97
|
+
interface SchemaBuilderProps {
|
|
98
|
+
schema?: JSONSchema;
|
|
99
|
+
domain?: string;
|
|
100
|
+
onChange?: (schema: JSONSchema, validationErrors: SchemaBuilderValidationError[]) => void;
|
|
101
|
+
}
|
|
102
|
+
interface SchemaBuilderHelperContentEntry {
|
|
103
|
+
longDetails: string;
|
|
104
|
+
label?: string;
|
|
105
|
+
}
|
|
106
|
+
type SchemaBuilderHelperContent = Record<string, string | SchemaBuilderHelperContentEntry>;
|
|
107
|
+
interface SchemaBuilderHelperProps {
|
|
108
|
+
debounceMs?: number;
|
|
109
|
+
maxResults?: number;
|
|
110
|
+
placeholder?: string;
|
|
111
|
+
initialQuery?: string;
|
|
112
|
+
helpContent?: SchemaBuilderHelperContent;
|
|
113
|
+
}
|
|
114
|
+
interface SchemaBuilderValidationError {
|
|
115
|
+
message: string;
|
|
116
|
+
keyword?: string;
|
|
117
|
+
instancePath?: string;
|
|
118
|
+
schemaPath?: string;
|
|
119
|
+
source: "schema" | "json-parse";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
declare function SchemaForm({ schema, peerSchemas, getSchema, widgets, options, data, onChange }: SchemaFormProps): react.JSX.Element;
|
|
123
|
+
|
|
124
|
+
declare function SchemaBuilderHelper({ debounceMs, maxResults, placeholder, initialQuery, helpContent }: SchemaBuilderHelperProps): react.JSX.Element;
|
|
125
|
+
declare function SchemaBuilder({ schema, domain, onChange }: SchemaBuilderProps): react.JSX.Element;
|
|
126
|
+
|
|
127
|
+
export { type FieldComponentProps, type JSONSchema, type JSONSchemaType, type OutputData, type PeerSchemasInput, SchemaBuilder, SchemaBuilderHelper, type SchemaBuilderHelperContent, type SchemaBuilderHelperContentEntry, type SchemaBuilderHelperProps, type SchemaBuilderProps, type SchemaBuilderValidationError, SchemaForm, type SchemaFormOptions, type SchemaFormProps, type SchemaFormValidationError, type SchemaFormWidgets };
|