@fogpipe/forma-react 0.17.0 → 0.18.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/README.md +111 -26
- package/dist/FormRenderer-D_ZVK44t.d.ts +558 -0
- package/dist/chunk-5K4QITFH.js +1276 -0
- package/dist/chunk-5K4QITFH.js.map +1 -0
- package/dist/defaults/index.d.ts +56 -0
- package/dist/defaults/index.js +895 -0
- package/dist/defaults/index.js.map +1 -0
- package/dist/defaults/styles/forma-defaults.css +696 -0
- package/dist/index.d.ts +13 -549
- package/dist/index.js +34 -1273
- package/dist/index.js.map +1 -1
- package/package.json +17 -3
- package/src/FieldRenderer.tsx +12 -4
- package/src/FormRenderer.tsx +26 -9
- package/src/__tests__/FieldRenderer.test.tsx +5 -1
- package/src/__tests__/FormRenderer.test.tsx +146 -0
- package/src/__tests__/canProceed.test.ts +243 -0
- package/src/__tests__/defaults/components.test.tsx +818 -0
- package/src/__tests__/defaults/integration.test.tsx +494 -0
- package/src/__tests__/defaults/layout.test.tsx +298 -0
- package/src/__tests__/events.test.ts +15 -5
- package/src/__tests__/useForma.test.ts +108 -5
- package/src/defaults/DefaultFormRenderer.tsx +43 -0
- package/src/defaults/componentMap.ts +45 -0
- package/src/defaults/components/ArrayField.tsx +183 -0
- package/src/defaults/components/BooleanInput.tsx +32 -0
- package/src/defaults/components/ComputedDisplay.tsx +26 -0
- package/src/defaults/components/DateInput.tsx +59 -0
- package/src/defaults/components/DisplayField.tsx +15 -0
- package/src/defaults/components/FallbackField.tsx +35 -0
- package/src/defaults/components/MatrixField.tsx +98 -0
- package/src/defaults/components/MultiSelectInput.tsx +51 -0
- package/src/defaults/components/NumberInput.tsx +73 -0
- package/src/defaults/components/ObjectField.tsx +22 -0
- package/src/defaults/components/SelectInput.tsx +44 -0
- package/src/defaults/components/TextInput.tsx +48 -0
- package/src/defaults/components/TextareaInput.tsx +46 -0
- package/src/defaults/index.ts +33 -0
- package/src/defaults/layout/FieldWrapper.tsx +83 -0
- package/src/defaults/layout/FormLayout.tsx +34 -0
- package/src/defaults/layout/PageWrapper.tsx +18 -0
- package/src/defaults/layout/WizardLayout.tsx +130 -0
- package/src/defaults/styles/forma-defaults.css +696 -0
- package/src/events.ts +4 -1
- package/src/types.ts +16 -4
- package/src/useForma.ts +48 -34
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { FieldError,
|
|
1
|
+
import { FieldError, Forma, OptionsVisibilityResult, ValidationResult } from '@fogpipe/forma-core';
|
|
2
2
|
export { ComputedField, FieldDefinition, FieldError, FieldType, Forma, PageDefinition, SelectOption, ValidationResult, ValidationRule } from '@fogpipe/forma-core';
|
|
3
|
-
import
|
|
4
|
-
|
|
3
|
+
import { G as GetFieldPropsResult, a as GetSelectFieldPropsResult, b as GetArrayHelpersResult, C as ComponentMap } from './FormRenderer-D_ZVK44t.js';
|
|
4
|
+
export { v as ArrayComponentProps, A as ArrayFieldProps, j as ArrayHelpers, k as ArrayItemFieldProps, l as ArrayItemFieldPropsResult, B as BaseFieldProps, q as BooleanComponentProps, f as BooleanFieldProps, x as ComputedComponentProps, i as ComputedFieldProps, r as DateComponentProps, D as DateFieldProps, s as DateTimeComponentProps, g as DateTimeFieldProps, z as DisplayComponentProps, y as DisplayFieldProps, m as FieldComponentProps, e as FieldProps, K as FieldWrapperProps, F as FormRenderer, d as FormRendererHandle, c as FormRendererProps, p as IntegerComponentProps, I as IntegerFieldProps, J as LayoutProps, L as LegacyFieldProps, H as MatrixComponentProps, E as MatrixFieldProps, u as MultiSelectComponentProps, M as MultiSelectFieldProps, o as NumberComponentProps, N as NumberFieldProps, w as ObjectComponentProps, O as ObjectFieldProps, P as PageWrapperProps, t as SelectComponentProps, S as SelectFieldProps, h as SelectionFieldProps, n as TextComponentProps, T as TextFieldProps } from './FormRenderer-D_ZVK44t.js';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import React__default from 'react';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Event system for forma-react
|
|
@@ -82,499 +84,6 @@ type FormaEvents = Partial<{
|
|
|
82
84
|
[K in keyof FormaEventMap]: FormaEventListener<K>;
|
|
83
85
|
}>;
|
|
84
86
|
|
|
85
|
-
/**
|
|
86
|
-
* Type definitions for forma-react components
|
|
87
|
-
*/
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Base props shared by all field components
|
|
91
|
-
*/
|
|
92
|
-
interface BaseFieldProps {
|
|
93
|
-
/** Field path/name */
|
|
94
|
-
name: string;
|
|
95
|
-
/** Field definition from the Forma spec */
|
|
96
|
-
field: FieldDefinition;
|
|
97
|
-
/** Current field value */
|
|
98
|
-
value: unknown;
|
|
99
|
-
/** Whether the field has been touched */
|
|
100
|
-
touched: boolean;
|
|
101
|
-
/** Whether the field is required */
|
|
102
|
-
required: boolean;
|
|
103
|
-
/** Whether the field is disabled */
|
|
104
|
-
disabled: boolean;
|
|
105
|
-
/** Validation errors for this field */
|
|
106
|
-
errors: FieldError[];
|
|
107
|
-
/** Handler for value changes */
|
|
108
|
-
onChange: (value: unknown) => void;
|
|
109
|
-
/** Handler for blur events */
|
|
110
|
-
onBlur: () => void;
|
|
111
|
-
/** Whether field is visible (always true since FormRenderer handles visibility) */
|
|
112
|
-
visible: boolean;
|
|
113
|
-
/** Whether field is enabled (inverse of disabled) */
|
|
114
|
-
enabled: boolean;
|
|
115
|
-
/** Whether field is readonly (visible, not editable, value still submitted) */
|
|
116
|
-
readonly: boolean;
|
|
117
|
-
/** Display label from field definition */
|
|
118
|
-
label: string;
|
|
119
|
-
/** Help text or description from field definition */
|
|
120
|
-
description?: string;
|
|
121
|
-
/** Placeholder text from field definition */
|
|
122
|
-
placeholder?: string;
|
|
123
|
-
/** Prefix adorner text (e.g., "$") - only for adornable field types */
|
|
124
|
-
prefix?: string;
|
|
125
|
-
/** Suffix adorner text (e.g., "kg") - only for adornable field types */
|
|
126
|
-
suffix?: string;
|
|
127
|
-
/** Presentation variant hint (e.g., "slider", "radio", "nps") */
|
|
128
|
-
variant?: string;
|
|
129
|
-
/** Variant-specific configuration */
|
|
130
|
-
variantConfig?: Record<string, unknown>;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Props for text-based fields (text, email, password, url, textarea)
|
|
134
|
-
*/
|
|
135
|
-
interface TextFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
136
|
-
fieldType: "text" | "phone" | "email" | "password" | "url" | "textarea";
|
|
137
|
-
value: string;
|
|
138
|
-
onChange: (value: string) => void;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Props for number fields
|
|
142
|
-
*/
|
|
143
|
-
interface NumberFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
144
|
-
fieldType: "number";
|
|
145
|
-
value: number | null;
|
|
146
|
-
onChange: (value: number | null) => void;
|
|
147
|
-
min?: number;
|
|
148
|
-
max?: number;
|
|
149
|
-
step?: number;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Props for integer fields
|
|
153
|
-
*/
|
|
154
|
-
interface IntegerFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
155
|
-
fieldType: "integer";
|
|
156
|
-
value: number | null;
|
|
157
|
-
onChange: (value: number | null) => void;
|
|
158
|
-
min?: number;
|
|
159
|
-
max?: number;
|
|
160
|
-
step?: number;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Props for boolean fields
|
|
164
|
-
*/
|
|
165
|
-
interface BooleanFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
166
|
-
fieldType: "boolean";
|
|
167
|
-
value: boolean;
|
|
168
|
-
onChange: (value: boolean) => void;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Props for date fields
|
|
172
|
-
*/
|
|
173
|
-
interface DateFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
174
|
-
fieldType: "date";
|
|
175
|
-
value: string | null;
|
|
176
|
-
onChange: (value: string | null) => void;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Props for datetime fields
|
|
180
|
-
*/
|
|
181
|
-
interface DateTimeFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
182
|
-
fieldType: "datetime";
|
|
183
|
-
value: string | null;
|
|
184
|
-
onChange: (value: string | null) => void;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Props for select fields (single selection)
|
|
188
|
-
*/
|
|
189
|
-
interface SelectFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
190
|
-
fieldType: "select";
|
|
191
|
-
value: string | null;
|
|
192
|
-
onChange: (value: string | null) => void;
|
|
193
|
-
options: SelectOption[];
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Props for multi-select fields
|
|
197
|
-
*/
|
|
198
|
-
interface MultiSelectFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
199
|
-
fieldType: "multiselect";
|
|
200
|
-
value: string[];
|
|
201
|
-
onChange: (value: string[]) => void;
|
|
202
|
-
options: SelectOption[];
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Union type for all selection-based field props
|
|
206
|
-
*/
|
|
207
|
-
type SelectionFieldProps = SelectFieldProps | MultiSelectFieldProps;
|
|
208
|
-
/**
|
|
209
|
-
* Array item field props returned by getItemFieldProps
|
|
210
|
-
*/
|
|
211
|
-
interface ArrayItemFieldPropsResult {
|
|
212
|
-
/** Field path/name */
|
|
213
|
-
name: string;
|
|
214
|
-
/** Current field value */
|
|
215
|
-
value: unknown;
|
|
216
|
-
/** Field type */
|
|
217
|
-
type: string;
|
|
218
|
-
/** Display label */
|
|
219
|
-
label: string;
|
|
220
|
-
/** Help text or description */
|
|
221
|
-
description?: string;
|
|
222
|
-
/** Placeholder text */
|
|
223
|
-
placeholder?: string;
|
|
224
|
-
/** Whether field is visible */
|
|
225
|
-
visible: boolean;
|
|
226
|
-
/** Whether field is enabled */
|
|
227
|
-
enabled: boolean;
|
|
228
|
-
/** Whether field is required */
|
|
229
|
-
required: boolean;
|
|
230
|
-
/** Whether field has been touched */
|
|
231
|
-
touched: boolean;
|
|
232
|
-
/** Validation errors for this field */
|
|
233
|
-
errors: FieldError[];
|
|
234
|
-
/** Handler for value changes */
|
|
235
|
-
onChange: (value: unknown) => void;
|
|
236
|
-
/** Handler for blur events */
|
|
237
|
-
onBlur: () => void;
|
|
238
|
-
/** Item index in the array */
|
|
239
|
-
itemIndex: number;
|
|
240
|
-
/** Field name within the item */
|
|
241
|
-
fieldName: string;
|
|
242
|
-
/** Options for select fields */
|
|
243
|
-
options?: SelectOption[];
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Array manipulation helpers
|
|
247
|
-
*/
|
|
248
|
-
interface ArrayHelpers {
|
|
249
|
-
/** Current array items */
|
|
250
|
-
items: unknown[];
|
|
251
|
-
/** Add item to end of array */
|
|
252
|
-
push: (item?: unknown) => void;
|
|
253
|
-
/** Insert item at specific index */
|
|
254
|
-
insert: (index: number, item: unknown) => void;
|
|
255
|
-
/** Remove item at index */
|
|
256
|
-
remove: (index: number) => void;
|
|
257
|
-
/** Move item from one index to another */
|
|
258
|
-
move: (from: number, to: number) => void;
|
|
259
|
-
/** Swap items at two indices */
|
|
260
|
-
swap: (indexA: number, indexB: number) => void;
|
|
261
|
-
/** Get field props for an item field */
|
|
262
|
-
getItemFieldProps: (index: number, fieldName: string) => ArrayItemFieldPropsResult;
|
|
263
|
-
/** Minimum number of items allowed */
|
|
264
|
-
minItems: number;
|
|
265
|
-
/** Maximum number of items allowed */
|
|
266
|
-
maxItems: number;
|
|
267
|
-
/** Whether more items can be added */
|
|
268
|
-
canAdd: boolean;
|
|
269
|
-
/** Whether items can be removed */
|
|
270
|
-
canRemove: boolean;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Props for array fields
|
|
274
|
-
*/
|
|
275
|
-
interface ArrayFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
276
|
-
fieldType: "array";
|
|
277
|
-
value: unknown[];
|
|
278
|
-
onChange: (value: unknown[]) => void;
|
|
279
|
-
helpers: ArrayHelpers;
|
|
280
|
-
/** Item field definitions keyed by field name */
|
|
281
|
-
itemFields: Record<string, FieldDefinition>;
|
|
282
|
-
/** Explicit ordering for itemFields (jsonb does not preserve object key order) */
|
|
283
|
-
itemFieldOrder?: string[];
|
|
284
|
-
minItems?: number;
|
|
285
|
-
maxItems?: number;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Props for object fields
|
|
289
|
-
*/
|
|
290
|
-
interface ObjectFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
291
|
-
fieldType: "object";
|
|
292
|
-
value: Record<string, unknown>;
|
|
293
|
-
onChange: (value: Record<string, unknown>) => void;
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Props for computed fields (read-only)
|
|
297
|
-
*/
|
|
298
|
-
interface ComputedFieldProps extends Omit<BaseFieldProps, "onChange"> {
|
|
299
|
-
fieldType: "computed";
|
|
300
|
-
value: unknown;
|
|
301
|
-
expression: string;
|
|
302
|
-
onChange?: never;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Props for array item fields (within array context)
|
|
306
|
-
*/
|
|
307
|
-
interface ArrayItemFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
308
|
-
/** The field type */
|
|
309
|
-
fieldType: string;
|
|
310
|
-
/** Current value */
|
|
311
|
-
value: unknown;
|
|
312
|
-
/** Change handler */
|
|
313
|
-
onChange: (value: unknown) => void;
|
|
314
|
-
/** Item index in the array */
|
|
315
|
-
itemIndex: number;
|
|
316
|
-
/** Field name within the item */
|
|
317
|
-
fieldName: string;
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Props for display fields (read-only presentation content)
|
|
321
|
-
*/
|
|
322
|
-
interface DisplayFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
323
|
-
fieldType: "display";
|
|
324
|
-
/** Static content (markdown/text) */
|
|
325
|
-
content?: string;
|
|
326
|
-
/** Computed source value (resolved by useForma from display field's source property) */
|
|
327
|
-
sourceValue?: unknown;
|
|
328
|
-
/** Display format string */
|
|
329
|
-
format?: string;
|
|
330
|
-
/** No onChange - display fields are read-only */
|
|
331
|
-
onChange?: never;
|
|
332
|
-
value?: never;
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Props for matrix/grid fields
|
|
336
|
-
*/
|
|
337
|
-
interface MatrixFieldProps extends Omit<BaseFieldProps, "value" | "onChange"> {
|
|
338
|
-
fieldType: "matrix";
|
|
339
|
-
/** Current matrix value: row ID → selected column value(s) */
|
|
340
|
-
value: Record<string, string | number | string[] | number[]> | null;
|
|
341
|
-
onChange: (value: Record<string, string | number | string[] | number[]>) => void;
|
|
342
|
-
/** Row definitions with visibility state */
|
|
343
|
-
rows: Array<{
|
|
344
|
-
id: string;
|
|
345
|
-
label: string;
|
|
346
|
-
visible: boolean;
|
|
347
|
-
}>;
|
|
348
|
-
/** Column definitions (shared options for all rows) */
|
|
349
|
-
columns: MatrixColumn[];
|
|
350
|
-
/** Whether multiple selections per row are allowed */
|
|
351
|
-
multiSelect: boolean;
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Union of all field prop types
|
|
355
|
-
*/
|
|
356
|
-
type FieldProps = TextFieldProps | NumberFieldProps | IntegerFieldProps | BooleanFieldProps | DateFieldProps | DateTimeFieldProps | SelectFieldProps | MultiSelectFieldProps | ArrayFieldProps | ObjectFieldProps | ComputedFieldProps | DisplayFieldProps | MatrixFieldProps;
|
|
357
|
-
/**
|
|
358
|
-
* Map of field types to React components
|
|
359
|
-
* Components receive wrapper props with { field, spec } structure
|
|
360
|
-
*/
|
|
361
|
-
interface ComponentMap {
|
|
362
|
-
text?: React.ComponentType<TextComponentProps>;
|
|
363
|
-
phone?: React.ComponentType<TextComponentProps>;
|
|
364
|
-
email?: React.ComponentType<TextComponentProps>;
|
|
365
|
-
password?: React.ComponentType<TextComponentProps>;
|
|
366
|
-
url?: React.ComponentType<TextComponentProps>;
|
|
367
|
-
textarea?: React.ComponentType<TextComponentProps>;
|
|
368
|
-
number?: React.ComponentType<NumberComponentProps>;
|
|
369
|
-
integer?: React.ComponentType<IntegerComponentProps>;
|
|
370
|
-
boolean?: React.ComponentType<BooleanComponentProps>;
|
|
371
|
-
date?: React.ComponentType<DateComponentProps>;
|
|
372
|
-
datetime?: React.ComponentType<DateTimeComponentProps>;
|
|
373
|
-
select?: React.ComponentType<SelectComponentProps>;
|
|
374
|
-
multiselect?: React.ComponentType<MultiSelectComponentProps>;
|
|
375
|
-
array?: React.ComponentType<ArrayComponentProps>;
|
|
376
|
-
object?: React.ComponentType<ObjectComponentProps>;
|
|
377
|
-
computed?: React.ComponentType<ComputedComponentProps>;
|
|
378
|
-
display?: React.ComponentType<DisplayComponentProps>;
|
|
379
|
-
matrix?: React.ComponentType<MatrixComponentProps>;
|
|
380
|
-
fallback?: React.ComponentType<FieldComponentProps>;
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Props for custom layout components
|
|
384
|
-
*/
|
|
385
|
-
interface LayoutProps {
|
|
386
|
-
children: React.ReactNode;
|
|
387
|
-
onSubmit: () => void;
|
|
388
|
-
isSubmitting: boolean;
|
|
389
|
-
isValid: boolean;
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Props for custom field wrapper components
|
|
393
|
-
*/
|
|
394
|
-
interface FieldWrapperProps {
|
|
395
|
-
/** Field path/identifier */
|
|
396
|
-
fieldPath: string;
|
|
397
|
-
/** Field definition from the Forma spec */
|
|
398
|
-
field: FieldDefinition;
|
|
399
|
-
children: React.ReactNode;
|
|
400
|
-
errors: FieldError[];
|
|
401
|
-
touched: boolean;
|
|
402
|
-
required: boolean;
|
|
403
|
-
/**
|
|
404
|
-
* Whether to show the required indicator in the UI.
|
|
405
|
-
* False for boolean fields since false is a valid answer.
|
|
406
|
-
*/
|
|
407
|
-
showRequiredIndicator: boolean;
|
|
408
|
-
visible: boolean;
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
|
-
* Props for page wrapper components (multi-page forms)
|
|
412
|
-
*/
|
|
413
|
-
interface PageWrapperProps {
|
|
414
|
-
title: string;
|
|
415
|
-
description?: string;
|
|
416
|
-
children: React.ReactNode;
|
|
417
|
-
pageIndex: number;
|
|
418
|
-
totalPages: number;
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Wrapper type that includes spec alongside field props
|
|
422
|
-
* Components receive { field, spec } instead of just FieldProps
|
|
423
|
-
*/
|
|
424
|
-
interface TextComponentProps {
|
|
425
|
-
field: TextFieldProps;
|
|
426
|
-
spec: Forma;
|
|
427
|
-
}
|
|
428
|
-
interface NumberComponentProps {
|
|
429
|
-
field: NumberFieldProps;
|
|
430
|
-
spec: Forma;
|
|
431
|
-
}
|
|
432
|
-
interface IntegerComponentProps {
|
|
433
|
-
field: IntegerFieldProps;
|
|
434
|
-
spec: Forma;
|
|
435
|
-
}
|
|
436
|
-
interface BooleanComponentProps {
|
|
437
|
-
field: BooleanFieldProps;
|
|
438
|
-
spec: Forma;
|
|
439
|
-
}
|
|
440
|
-
interface DateComponentProps {
|
|
441
|
-
field: DateFieldProps;
|
|
442
|
-
spec: Forma;
|
|
443
|
-
}
|
|
444
|
-
interface DateTimeComponentProps {
|
|
445
|
-
field: DateTimeFieldProps;
|
|
446
|
-
spec: Forma;
|
|
447
|
-
}
|
|
448
|
-
interface SelectComponentProps {
|
|
449
|
-
field: SelectFieldProps;
|
|
450
|
-
spec: Forma;
|
|
451
|
-
}
|
|
452
|
-
interface MultiSelectComponentProps {
|
|
453
|
-
field: MultiSelectFieldProps;
|
|
454
|
-
spec: Forma;
|
|
455
|
-
}
|
|
456
|
-
interface ArrayComponentProps {
|
|
457
|
-
field: ArrayFieldProps;
|
|
458
|
-
spec: Forma;
|
|
459
|
-
}
|
|
460
|
-
interface ObjectComponentProps {
|
|
461
|
-
field: ObjectFieldProps;
|
|
462
|
-
spec: Forma;
|
|
463
|
-
}
|
|
464
|
-
interface ComputedComponentProps {
|
|
465
|
-
field: ComputedFieldProps;
|
|
466
|
-
spec: Forma;
|
|
467
|
-
}
|
|
468
|
-
interface DisplayComponentProps {
|
|
469
|
-
field: DisplayFieldProps;
|
|
470
|
-
spec: Forma;
|
|
471
|
-
}
|
|
472
|
-
interface MatrixComponentProps {
|
|
473
|
-
field: MatrixFieldProps;
|
|
474
|
-
spec: Forma;
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Generic field component props (for fallback/dynamic components)
|
|
478
|
-
*/
|
|
479
|
-
interface FieldComponentProps {
|
|
480
|
-
field: FieldProps;
|
|
481
|
-
spec: Forma;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* Field props returned by getFieldProps()
|
|
486
|
-
* Contains all field information needed for rendering
|
|
487
|
-
*/
|
|
488
|
-
interface GetFieldPropsResult {
|
|
489
|
-
/** Field path/name */
|
|
490
|
-
name: string;
|
|
491
|
-
/** Current field value */
|
|
492
|
-
value: unknown;
|
|
493
|
-
/** Field type */
|
|
494
|
-
type: string;
|
|
495
|
-
/** Display label */
|
|
496
|
-
label: string;
|
|
497
|
-
/** Help text or description */
|
|
498
|
-
description?: string;
|
|
499
|
-
/** Placeholder text */
|
|
500
|
-
placeholder?: string;
|
|
501
|
-
/** Whether field is visible */
|
|
502
|
-
visible: boolean;
|
|
503
|
-
/** Whether field is enabled (not disabled) */
|
|
504
|
-
enabled: boolean;
|
|
505
|
-
/** Whether field is readonly (visible, not editable, value still submitted) */
|
|
506
|
-
readonly: boolean;
|
|
507
|
-
/** Whether field is required (for validation) */
|
|
508
|
-
required: boolean;
|
|
509
|
-
/**
|
|
510
|
-
* Whether to show the required indicator in the UI.
|
|
511
|
-
* False for boolean fields since false is a valid answer.
|
|
512
|
-
*/
|
|
513
|
-
showRequiredIndicator: boolean;
|
|
514
|
-
/** Whether field has been touched */
|
|
515
|
-
touched: boolean;
|
|
516
|
-
/** Validation errors for this field */
|
|
517
|
-
errors: FieldError[];
|
|
518
|
-
/** Handler for value changes */
|
|
519
|
-
onChange: (value: unknown) => void;
|
|
520
|
-
/** Handler for blur events */
|
|
521
|
-
onBlur: () => void;
|
|
522
|
-
/** ARIA: Indicates the field has validation errors */
|
|
523
|
-
"aria-invalid"?: boolean;
|
|
524
|
-
/** ARIA: ID of element(s) describing validation errors */
|
|
525
|
-
"aria-describedby"?: string;
|
|
526
|
-
/** ARIA: Indicates the field is required */
|
|
527
|
-
"aria-required"?: boolean;
|
|
528
|
-
/** Options for select/multiselect fields (filtered by visibleWhen) */
|
|
529
|
-
options?: SelectOption[];
|
|
530
|
-
/** Prefix adorner text (e.g., "$") */
|
|
531
|
-
prefix?: string;
|
|
532
|
-
/** Suffix adorner text (e.g., "kg") */
|
|
533
|
-
suffix?: string;
|
|
534
|
-
/** Presentation variant hint */
|
|
535
|
-
variant?: string;
|
|
536
|
-
/** Variant-specific configuration */
|
|
537
|
-
variantConfig?: Record<string, unknown>;
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* Select field props returned by getSelectFieldProps()
|
|
541
|
-
*/
|
|
542
|
-
interface GetSelectFieldPropsResult extends GetFieldPropsResult {
|
|
543
|
-
/** Available options for selection */
|
|
544
|
-
options: SelectOption[];
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Array helpers returned by getArrayHelpers()
|
|
548
|
-
*/
|
|
549
|
-
interface GetArrayHelpersResult {
|
|
550
|
-
/** Current array items */
|
|
551
|
-
items: unknown[];
|
|
552
|
-
/** Add item to end of array */
|
|
553
|
-
push: (item: unknown) => void;
|
|
554
|
-
/** Remove item at index */
|
|
555
|
-
remove: (index: number) => void;
|
|
556
|
-
/** Move item from one index to another */
|
|
557
|
-
move: (from: number, to: number) => void;
|
|
558
|
-
/** Swap items at two indices */
|
|
559
|
-
swap: (indexA: number, indexB: number) => void;
|
|
560
|
-
/** Insert item at specific index */
|
|
561
|
-
insert: (index: number, item: unknown) => void;
|
|
562
|
-
/** Get field props for an item field */
|
|
563
|
-
getItemFieldProps: (index: number, fieldName: string) => GetFieldPropsResult;
|
|
564
|
-
/** Minimum number of items allowed */
|
|
565
|
-
minItems: number;
|
|
566
|
-
/** Maximum number of items allowed */
|
|
567
|
-
maxItems: number;
|
|
568
|
-
/** Whether more items can be added */
|
|
569
|
-
canAdd: boolean;
|
|
570
|
-
/** Whether items can be removed */
|
|
571
|
-
canRemove: boolean;
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* @deprecated Use GetFieldPropsResult instead
|
|
575
|
-
*/
|
|
576
|
-
type LegacyFieldProps = GetFieldPropsResult;
|
|
577
|
-
|
|
578
87
|
/**
|
|
579
88
|
* useForma Hook
|
|
580
89
|
*
|
|
@@ -631,6 +140,12 @@ interface WizardHelpers {
|
|
|
631
140
|
goToPage: (index: number) => void;
|
|
632
141
|
nextPage: () => void;
|
|
633
142
|
previousPage: () => void;
|
|
143
|
+
/**
|
|
144
|
+
* Safe "Next" handler for wizard navigation.
|
|
145
|
+
* Advances to the next page if one exists. Never triggers submission.
|
|
146
|
+
* Use this instead of conditionally calling nextPage/onSubmit in a single button.
|
|
147
|
+
*/
|
|
148
|
+
handleNext: () => void;
|
|
634
149
|
hasNextPage: boolean;
|
|
635
150
|
hasPreviousPage: boolean;
|
|
636
151
|
canProceed: boolean;
|
|
@@ -703,57 +218,6 @@ interface UseFormaReturn {
|
|
|
703
218
|
*/
|
|
704
219
|
declare function useForma(options: UseFormaOptions): UseFormaReturn;
|
|
705
220
|
|
|
706
|
-
/**
|
|
707
|
-
* FormRenderer Component
|
|
708
|
-
*
|
|
709
|
-
* Renders a complete form from a Forma specification.
|
|
710
|
-
* Supports single-page and multi-page (wizard) forms.
|
|
711
|
-
*/
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* Props for FormRenderer component
|
|
715
|
-
*/
|
|
716
|
-
interface FormRendererProps {
|
|
717
|
-
/** The Forma specification */
|
|
718
|
-
spec: Forma;
|
|
719
|
-
/** Initial form data */
|
|
720
|
-
initialData?: Record<string, unknown>;
|
|
721
|
-
/** Submit handler */
|
|
722
|
-
onSubmit?: (data: Record<string, unknown>) => void | Promise<void>;
|
|
723
|
-
/** Change handler */
|
|
724
|
-
onChange?: (data: Record<string, unknown>, computed?: Record<string, unknown>) => void;
|
|
725
|
-
/** Component map for rendering fields */
|
|
726
|
-
components: ComponentMap;
|
|
727
|
-
/** Custom layout component */
|
|
728
|
-
layout?: React__default.ComponentType<LayoutProps>;
|
|
729
|
-
/** Custom field wrapper component */
|
|
730
|
-
fieldWrapper?: React__default.ComponentType<FieldWrapperProps>;
|
|
731
|
-
/** Custom page wrapper component */
|
|
732
|
-
pageWrapper?: React__default.ComponentType<PageWrapperProps>;
|
|
733
|
-
/** When to validate */
|
|
734
|
-
validateOn?: "change" | "blur" | "submit";
|
|
735
|
-
/** Current page for controlled wizard */
|
|
736
|
-
page?: number;
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* Imperative handle for FormRenderer
|
|
740
|
-
*/
|
|
741
|
-
interface FormRendererHandle {
|
|
742
|
-
submitForm: () => Promise<void>;
|
|
743
|
-
resetForm: () => void;
|
|
744
|
-
validateForm: () => ValidationResult;
|
|
745
|
-
focusField: (path: string) => void;
|
|
746
|
-
focusFirstError: () => void;
|
|
747
|
-
getValues: () => Record<string, unknown>;
|
|
748
|
-
setValues: (values: Record<string, unknown>) => void;
|
|
749
|
-
isValid: boolean;
|
|
750
|
-
isDirty: boolean;
|
|
751
|
-
}
|
|
752
|
-
/**
|
|
753
|
-
* FormRenderer component
|
|
754
|
-
*/
|
|
755
|
-
declare const FormRenderer: React__default.ForwardRefExoticComponent<FormRendererProps & React__default.RefAttributes<FormRendererHandle>>;
|
|
756
|
-
|
|
757
221
|
/**
|
|
758
222
|
* Props for FieldRenderer component
|
|
759
223
|
*/
|
|
@@ -831,11 +295,11 @@ declare class FormaErrorBoundary extends React__default.Component<FormaErrorBoun
|
|
|
831
295
|
/**
|
|
832
296
|
* Context for sharing form state across components
|
|
833
297
|
*/
|
|
834
|
-
declare const FormaContext: React
|
|
298
|
+
declare const FormaContext: React.Context<UseFormaReturn | null>;
|
|
835
299
|
/**
|
|
836
300
|
* Hook to access Forma context
|
|
837
301
|
* @throws Error if used outside of FormaContext.Provider
|
|
838
302
|
*/
|
|
839
303
|
declare function useFormaContext(): UseFormaReturn;
|
|
840
304
|
|
|
841
|
-
export {
|
|
305
|
+
export { ComponentMap, FieldRenderer, type FieldRendererProps, type UseFormaReturn as FormState, FormaContext, FormaErrorBoundary, type FormaErrorBoundaryProps, type FormaEventListener, type FormaEventMap, type FormaEvents, GetArrayHelpersResult, GetFieldPropsResult, GetSelectFieldPropsResult, type PageState, type UseFormaOptions, type UseFormaReturn, type WizardHelpers, useForma, useFormaContext };
|