@dynamic-field-kit/react 1.5.1 → 1.7.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/CHANGELOG.md +224 -0
- package/README.md +170 -29
- package/dist/index.d.mts +114 -7
- package/dist/index.d.ts +114 -7
- package/dist/index.js +394 -124
- package/dist/index.mjs +434 -154
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode, ComponentType } from 'react';
|
|
2
|
-
import { FieldTypeKey, Properties, FieldDescription, LayoutConfig, ValidationResult, FieldRendererProps, FieldTypeMap } from '@dynamic-field-kit/core';
|
|
3
|
-
export { FieldDescription, FieldRegistry, FieldRendererProps, FieldTypeKey, LayoutConfig, ValidationResult, resolveDisabled, resolveOptions, resolveReadOnly, validateField, validateFieldAsync, validateFields, validateFieldsAsync, validators } from '@dynamic-field-kit/core';
|
|
2
|
+
import { FieldTypeKey, Properties, OptionsStatus, FieldDescription, LayoutConfig, ValidationResult, MessageCatalog, FieldRendererProps, FieldTypeMap } from '@dynamic-field-kit/core';
|
|
3
|
+
export { FIELD_RENDERER_PROP_KEYS, FieldDescription, FieldRegistry, FieldRendererProps, FieldTypeKey, LayoutConfig, ValidationContext, ValidationResult, buildFieldRendererProps, collectFieldPaths, indexGroupPathMap, makeErrorId, makeFieldId, resolveDisabled, resolveOptions, resolveReadOnly, validateField, validateFieldAsync, validateFields, validateFieldsAsync, validators } from '@dynamic-field-kit/core';
|
|
4
4
|
|
|
5
5
|
type LayoutRenderer<C = unknown> = (props: {
|
|
6
6
|
children: React.ReactNode;
|
|
@@ -19,7 +19,10 @@ interface Props$2<T extends FieldTypeKey> {
|
|
|
19
19
|
onChange?: (value: unknown) => void;
|
|
20
20
|
onBlur?: () => void;
|
|
21
21
|
label?: string;
|
|
22
|
+
placeholder?: string;
|
|
22
23
|
options?: Properties[];
|
|
24
|
+
optionsStatus?: OptionsStatus;
|
|
25
|
+
optionsError?: unknown;
|
|
23
26
|
className?: string;
|
|
24
27
|
description?: ReactNode;
|
|
25
28
|
disabled?: boolean;
|
|
@@ -32,28 +35,80 @@ interface Props$2<T extends FieldTypeKey> {
|
|
|
32
35
|
ariaInvalid?: boolean;
|
|
33
36
|
ariaDescribedBy?: string;
|
|
34
37
|
ariaRequired?: boolean;
|
|
38
|
+
min?: number | string;
|
|
39
|
+
max?: number | string;
|
|
40
|
+
step?: number | string;
|
|
41
|
+
accept?: string;
|
|
42
|
+
multiple?: boolean;
|
|
35
43
|
/** Extra, framework-agnostic props forwarded verbatim to the renderer. */
|
|
36
44
|
extraProps?: Properties;
|
|
45
|
+
/** Renderer-driven refetch for a search-remote field. */
|
|
46
|
+
onOptionsQuery?: (query: string) => void;
|
|
37
47
|
}
|
|
38
|
-
declare const DynamicInputInner: <T extends FieldTypeKey>({ type,
|
|
48
|
+
declare const DynamicInputInner: <T extends FieldTypeKey>({ type, onChange, onBlur, extraProps, onOptionsQuery, ...rendererProps }: Props$2<T>) => React.JSX.Element;
|
|
39
49
|
declare const DynamicInput: typeof DynamicInputInner;
|
|
40
50
|
|
|
41
51
|
interface Props$1 {
|
|
42
52
|
fieldDescription: FieldDescription;
|
|
43
53
|
renderInfos: Properties;
|
|
44
54
|
rootData?: Properties;
|
|
55
|
+
/** Per-form-instance id namespace; see core's `makeFieldId`. */
|
|
56
|
+
idPrefix?: string;
|
|
45
57
|
touched?: boolean;
|
|
58
|
+
touchedMap?: Record<string, boolean>;
|
|
46
59
|
dirty?: boolean;
|
|
60
|
+
errors?: Record<string, string[]>;
|
|
47
61
|
onBlurField?: (key: string) => void;
|
|
48
62
|
onValueChangeField: (value: unknown, key: string) => void;
|
|
49
63
|
}
|
|
50
|
-
declare const FieldInput: React.MemoExoticComponent<({ fieldDescription, renderInfos, rootData, touched, dirty, onBlurField, onValueChangeField, }: Props$1) => React.JSX.Element>;
|
|
64
|
+
declare const FieldInput: React.MemoExoticComponent<({ fieldDescription, renderInfos, rootData, idPrefix, touched, touchedMap, dirty, errors, onBlurField, onValueChangeField, }: Props$1) => React.JSX.Element>;
|
|
51
65
|
|
|
66
|
+
/**
|
|
67
|
+
* The slice of `useDynamicForm`'s result `MultiFieldInput` needs to drive
|
|
68
|
+
* itself. Structural, so the hook result can be passed straight in.
|
|
69
|
+
*/
|
|
70
|
+
interface DynamicFormBinding {
|
|
71
|
+
data: Properties;
|
|
72
|
+
errors: Record<string, string[]>;
|
|
73
|
+
touched: Record<string, boolean>;
|
|
74
|
+
/** The values per-field `dirty` is measured against. See `useDynamicForm`. */
|
|
75
|
+
baselineValues?: Properties;
|
|
76
|
+
handleChange: (data: Properties) => void;
|
|
77
|
+
handleBlur: (fieldName: string) => void;
|
|
78
|
+
}
|
|
79
|
+
/** Imperative handle exposed on a `MultiFieldInput` ref. */
|
|
80
|
+
interface MultiFieldInputHandle {
|
|
81
|
+
/**
|
|
82
|
+
* Clears the internally tracked touched state. Only meaningful in
|
|
83
|
+
* uncontrolled mode - when `touched` is passed as a prop, resetting the form
|
|
84
|
+
* store (e.g. `useDynamicForm().reset()`) already clears it.
|
|
85
|
+
*/
|
|
86
|
+
resetTouched: () => void;
|
|
87
|
+
setFieldTouched: (fieldName: string, isTouched?: boolean) => void;
|
|
88
|
+
/** The touched map currently in effect, controlled or internal. */
|
|
89
|
+
getTouched: () => Record<string, boolean>;
|
|
90
|
+
}
|
|
52
91
|
interface Props {
|
|
53
92
|
fieldDescriptions: FieldDescription[];
|
|
54
93
|
properties?: Properties;
|
|
55
94
|
onChange?: (data: Properties) => void;
|
|
56
95
|
layout?: LayoutConfig;
|
|
96
|
+
/**
|
|
97
|
+
* Namespace for generated field ids: a field renders with
|
|
98
|
+
* `${idPrefix}-${name}`. Defaults to a value unique to this component
|
|
99
|
+
* instance, so two forms containing the same field name do not emit
|
|
100
|
+
* duplicate DOM ids. Pass a fixed string to pin ids (`idPrefix="dfk-field"`
|
|
101
|
+
* restores the pre-1.6 ids), or set `FieldDescription.id` per field.
|
|
102
|
+
*/
|
|
103
|
+
idPrefix?: string;
|
|
104
|
+
/**
|
|
105
|
+
* The values per-field `dirty` is measured against. Defaults to the first
|
|
106
|
+
* non-`undefined` `properties` this component sees - which is what an edit
|
|
107
|
+
* form wants when its values arrive from a fetch after mount. Supplied
|
|
108
|
+
* automatically by the `form` shorthand; pass it explicitly to re-base
|
|
109
|
+
* `dirty` without going through a form store.
|
|
110
|
+
*/
|
|
111
|
+
initialProperties?: Properties;
|
|
57
112
|
/**
|
|
58
113
|
* Top-level form data, threaded down through repeatable groups so a nested
|
|
59
114
|
* field's `appearCondition`/`computeValue` can read the root form. Omitted at
|
|
@@ -73,8 +128,26 @@ interface Props {
|
|
|
73
128
|
* map and `validateOnBlur` behaviour.
|
|
74
129
|
*/
|
|
75
130
|
onBlurField?: (fieldName: string) => void;
|
|
131
|
+
/**
|
|
132
|
+
* Controlled touched map. When provided it is the single source of truth and
|
|
133
|
+
* the internal tracker is bypassed entirely, so `useDynamicForm().touched`
|
|
134
|
+
* (updated by `setFieldTouched`, `touchAll`, `handleSubmit` and cleared by
|
|
135
|
+
* `reset`) is what renderers actually see. Omit it to keep the internal,
|
|
136
|
+
* blur-only tracker.
|
|
137
|
+
*/
|
|
138
|
+
touched?: Record<string, boolean>;
|
|
139
|
+
/** Controlled validation errors. Empty means no renderer error. */
|
|
140
|
+
errors?: Record<string, string[]>;
|
|
141
|
+
/** Fires with the next touched map whenever a field is blurred. */
|
|
142
|
+
onTouchedChange?: (touched: Record<string, boolean>) => void;
|
|
143
|
+
/**
|
|
144
|
+
* Shorthand that wires `properties`, `onChange`, `onBlurField` and `touched`
|
|
145
|
+
* from a `useDynamicForm` result in one prop. Individually passed props win
|
|
146
|
+
* over the ones derived from here.
|
|
147
|
+
*/
|
|
148
|
+
form?: DynamicFormBinding;
|
|
76
149
|
}
|
|
77
|
-
declare const MultiFieldInput:
|
|
150
|
+
declare const MultiFieldInput: React.ForwardRefExoticComponent<Props & React.RefAttributes<MultiFieldInputHandle>>;
|
|
78
151
|
|
|
79
152
|
interface DynamicFormDevToolsProps {
|
|
80
153
|
data: Properties;
|
|
@@ -91,25 +164,59 @@ interface UseDynamicFormOptions {
|
|
|
91
164
|
initialValues?: Properties;
|
|
92
165
|
validateOnBlur?: boolean;
|
|
93
166
|
validateOnChange?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Messages for the built-in validators, set once for the whole form instead
|
|
169
|
+
* of per field. A message passed directly to a validator still wins, and any
|
|
170
|
+
* key omitted here falls back to the validator's English default. See core's
|
|
171
|
+
* `MessageCatalog`.
|
|
172
|
+
*/
|
|
173
|
+
messages?: MessageCatalog;
|
|
94
174
|
}
|
|
95
175
|
interface UseDynamicFormResult {
|
|
96
176
|
data: Properties;
|
|
97
177
|
errors: Record<string, string[]>;
|
|
98
178
|
isValid: boolean;
|
|
179
|
+
isValidating: boolean;
|
|
180
|
+
isValidationComplete: boolean;
|
|
181
|
+
validationStatus: ValidationResult['status'];
|
|
99
182
|
isDirty: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* The values `dirty` is measured against: the `initialValues` option until
|
|
185
|
+
* `reset(newValues)` replaces them. Distinct from that option, which never
|
|
186
|
+
* changes - pass this to `MultiFieldInput` (or use the `form` shorthand) so
|
|
187
|
+
* per-field `dirty` survives a reset.
|
|
188
|
+
*/
|
|
189
|
+
baselineValues: Properties;
|
|
190
|
+
/**
|
|
191
|
+
* The entries of `data` that differ from `baselineValues`. Intended for
|
|
192
|
+
* PATCH-style submits that should carry only what the user actually edited.
|
|
193
|
+
*/
|
|
194
|
+
getDirtyValues: () => Properties;
|
|
100
195
|
isSubmitting: boolean;
|
|
101
196
|
isSubmitted: boolean;
|
|
102
197
|
touched: Record<string, boolean>;
|
|
103
198
|
setData: React.Dispatch<React.SetStateAction<Properties>>;
|
|
104
199
|
setFieldValue: (name: string, value: unknown) => void;
|
|
105
200
|
setFieldTouched: (name: string, isTouched?: boolean) => void;
|
|
201
|
+
/** Replaces the whole touched map. */
|
|
202
|
+
setTouched: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
|
|
203
|
+
/**
|
|
204
|
+
* Marks every field touched at once. `handleSubmit` calls this for you, so
|
|
205
|
+
* an invalid submit surfaces errors on fields the user never focused - pass
|
|
206
|
+
* `touched` into `MultiFieldInput` for it to take effect.
|
|
207
|
+
*/
|
|
208
|
+
touchAll: () => void;
|
|
209
|
+
/** Clears the touched map without touching data, errors or dirty state. */
|
|
210
|
+
resetTouched: () => void;
|
|
106
211
|
handleChange: (newData: Properties) => void;
|
|
107
212
|
handleBlur: (fieldName: string) => void;
|
|
108
213
|
reset: (newValues?: Properties) => void;
|
|
109
214
|
validate: () => boolean;
|
|
215
|
+
/** Validate all fields and await Promise-based rules. */
|
|
216
|
+
validateAsync: () => Promise<boolean>;
|
|
110
217
|
handleSubmit: (onValid: (data: Properties) => void | Promise<void>, onInvalid?: (errors: Record<string, string[]>) => void) => (e?: React.FormEvent) => Promise<void>;
|
|
111
218
|
}
|
|
112
|
-
declare function useDynamicForm({ fields, initialValues, validateOnBlur, validateOnChange, }: UseDynamicFormOptions): UseDynamicFormResult;
|
|
219
|
+
declare function useDynamicForm({ fields, initialValues, validateOnBlur, validateOnChange, messages, }: UseDynamicFormOptions): UseDynamicFormResult;
|
|
113
220
|
|
|
114
221
|
declare const defaultRenderersMap: Record<string, React.FC<FieldRendererProps>>;
|
|
115
222
|
declare function getDefaultRenderer(type: string): React.FC<FieldRendererProps> | undefined;
|
|
@@ -129,4 +236,4 @@ declare const FieldRegistryProvider: ({ registry, children, }: FieldRegistryProv
|
|
|
129
236
|
/** The registry for the nearest provider, or the global singleton. */
|
|
130
237
|
declare function useFieldRegistry(): ReactFieldRegistry;
|
|
131
238
|
|
|
132
|
-
export { DynamicFormDevTools, DynamicInput, FieldInput, FieldRegistryProvider, type FieldRegistryProviderProps, MultiFieldInput, type ReactFieldRegistry, type ReactFieldRenderer, defaultRenderersMap, fieldRegistry, getDefaultRenderer, layoutRegistry, useDynamicForm, useFieldRegistry };
|
|
239
|
+
export { type DynamicFormBinding, DynamicFormDevTools, DynamicInput, FieldInput, FieldRegistryProvider, type FieldRegistryProviderProps, MultiFieldInput, type MultiFieldInputHandle, type ReactFieldRegistry, type ReactFieldRenderer, type UseDynamicFormOptions, type UseDynamicFormResult, defaultRenderersMap, fieldRegistry, getDefaultRenderer, layoutRegistry, useDynamicForm, useFieldRegistry };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode, ComponentType } from 'react';
|
|
2
|
-
import { FieldTypeKey, Properties, FieldDescription, LayoutConfig, ValidationResult, FieldRendererProps, FieldTypeMap } from '@dynamic-field-kit/core';
|
|
3
|
-
export { FieldDescription, FieldRegistry, FieldRendererProps, FieldTypeKey, LayoutConfig, ValidationResult, resolveDisabled, resolveOptions, resolveReadOnly, validateField, validateFieldAsync, validateFields, validateFieldsAsync, validators } from '@dynamic-field-kit/core';
|
|
2
|
+
import { FieldTypeKey, Properties, OptionsStatus, FieldDescription, LayoutConfig, ValidationResult, MessageCatalog, FieldRendererProps, FieldTypeMap } from '@dynamic-field-kit/core';
|
|
3
|
+
export { FIELD_RENDERER_PROP_KEYS, FieldDescription, FieldRegistry, FieldRendererProps, FieldTypeKey, LayoutConfig, ValidationContext, ValidationResult, buildFieldRendererProps, collectFieldPaths, indexGroupPathMap, makeErrorId, makeFieldId, resolveDisabled, resolveOptions, resolveReadOnly, validateField, validateFieldAsync, validateFields, validateFieldsAsync, validators } from '@dynamic-field-kit/core';
|
|
4
4
|
|
|
5
5
|
type LayoutRenderer<C = unknown> = (props: {
|
|
6
6
|
children: React.ReactNode;
|
|
@@ -19,7 +19,10 @@ interface Props$2<T extends FieldTypeKey> {
|
|
|
19
19
|
onChange?: (value: unknown) => void;
|
|
20
20
|
onBlur?: () => void;
|
|
21
21
|
label?: string;
|
|
22
|
+
placeholder?: string;
|
|
22
23
|
options?: Properties[];
|
|
24
|
+
optionsStatus?: OptionsStatus;
|
|
25
|
+
optionsError?: unknown;
|
|
23
26
|
className?: string;
|
|
24
27
|
description?: ReactNode;
|
|
25
28
|
disabled?: boolean;
|
|
@@ -32,28 +35,80 @@ interface Props$2<T extends FieldTypeKey> {
|
|
|
32
35
|
ariaInvalid?: boolean;
|
|
33
36
|
ariaDescribedBy?: string;
|
|
34
37
|
ariaRequired?: boolean;
|
|
38
|
+
min?: number | string;
|
|
39
|
+
max?: number | string;
|
|
40
|
+
step?: number | string;
|
|
41
|
+
accept?: string;
|
|
42
|
+
multiple?: boolean;
|
|
35
43
|
/** Extra, framework-agnostic props forwarded verbatim to the renderer. */
|
|
36
44
|
extraProps?: Properties;
|
|
45
|
+
/** Renderer-driven refetch for a search-remote field. */
|
|
46
|
+
onOptionsQuery?: (query: string) => void;
|
|
37
47
|
}
|
|
38
|
-
declare const DynamicInputInner: <T extends FieldTypeKey>({ type,
|
|
48
|
+
declare const DynamicInputInner: <T extends FieldTypeKey>({ type, onChange, onBlur, extraProps, onOptionsQuery, ...rendererProps }: Props$2<T>) => React.JSX.Element;
|
|
39
49
|
declare const DynamicInput: typeof DynamicInputInner;
|
|
40
50
|
|
|
41
51
|
interface Props$1 {
|
|
42
52
|
fieldDescription: FieldDescription;
|
|
43
53
|
renderInfos: Properties;
|
|
44
54
|
rootData?: Properties;
|
|
55
|
+
/** Per-form-instance id namespace; see core's `makeFieldId`. */
|
|
56
|
+
idPrefix?: string;
|
|
45
57
|
touched?: boolean;
|
|
58
|
+
touchedMap?: Record<string, boolean>;
|
|
46
59
|
dirty?: boolean;
|
|
60
|
+
errors?: Record<string, string[]>;
|
|
47
61
|
onBlurField?: (key: string) => void;
|
|
48
62
|
onValueChangeField: (value: unknown, key: string) => void;
|
|
49
63
|
}
|
|
50
|
-
declare const FieldInput: React.MemoExoticComponent<({ fieldDescription, renderInfos, rootData, touched, dirty, onBlurField, onValueChangeField, }: Props$1) => React.JSX.Element>;
|
|
64
|
+
declare const FieldInput: React.MemoExoticComponent<({ fieldDescription, renderInfos, rootData, idPrefix, touched, touchedMap, dirty, errors, onBlurField, onValueChangeField, }: Props$1) => React.JSX.Element>;
|
|
51
65
|
|
|
66
|
+
/**
|
|
67
|
+
* The slice of `useDynamicForm`'s result `MultiFieldInput` needs to drive
|
|
68
|
+
* itself. Structural, so the hook result can be passed straight in.
|
|
69
|
+
*/
|
|
70
|
+
interface DynamicFormBinding {
|
|
71
|
+
data: Properties;
|
|
72
|
+
errors: Record<string, string[]>;
|
|
73
|
+
touched: Record<string, boolean>;
|
|
74
|
+
/** The values per-field `dirty` is measured against. See `useDynamicForm`. */
|
|
75
|
+
baselineValues?: Properties;
|
|
76
|
+
handleChange: (data: Properties) => void;
|
|
77
|
+
handleBlur: (fieldName: string) => void;
|
|
78
|
+
}
|
|
79
|
+
/** Imperative handle exposed on a `MultiFieldInput` ref. */
|
|
80
|
+
interface MultiFieldInputHandle {
|
|
81
|
+
/**
|
|
82
|
+
* Clears the internally tracked touched state. Only meaningful in
|
|
83
|
+
* uncontrolled mode - when `touched` is passed as a prop, resetting the form
|
|
84
|
+
* store (e.g. `useDynamicForm().reset()`) already clears it.
|
|
85
|
+
*/
|
|
86
|
+
resetTouched: () => void;
|
|
87
|
+
setFieldTouched: (fieldName: string, isTouched?: boolean) => void;
|
|
88
|
+
/** The touched map currently in effect, controlled or internal. */
|
|
89
|
+
getTouched: () => Record<string, boolean>;
|
|
90
|
+
}
|
|
52
91
|
interface Props {
|
|
53
92
|
fieldDescriptions: FieldDescription[];
|
|
54
93
|
properties?: Properties;
|
|
55
94
|
onChange?: (data: Properties) => void;
|
|
56
95
|
layout?: LayoutConfig;
|
|
96
|
+
/**
|
|
97
|
+
* Namespace for generated field ids: a field renders with
|
|
98
|
+
* `${idPrefix}-${name}`. Defaults to a value unique to this component
|
|
99
|
+
* instance, so two forms containing the same field name do not emit
|
|
100
|
+
* duplicate DOM ids. Pass a fixed string to pin ids (`idPrefix="dfk-field"`
|
|
101
|
+
* restores the pre-1.6 ids), or set `FieldDescription.id` per field.
|
|
102
|
+
*/
|
|
103
|
+
idPrefix?: string;
|
|
104
|
+
/**
|
|
105
|
+
* The values per-field `dirty` is measured against. Defaults to the first
|
|
106
|
+
* non-`undefined` `properties` this component sees - which is what an edit
|
|
107
|
+
* form wants when its values arrive from a fetch after mount. Supplied
|
|
108
|
+
* automatically by the `form` shorthand; pass it explicitly to re-base
|
|
109
|
+
* `dirty` without going through a form store.
|
|
110
|
+
*/
|
|
111
|
+
initialProperties?: Properties;
|
|
57
112
|
/**
|
|
58
113
|
* Top-level form data, threaded down through repeatable groups so a nested
|
|
59
114
|
* field's `appearCondition`/`computeValue` can read the root form. Omitted at
|
|
@@ -73,8 +128,26 @@ interface Props {
|
|
|
73
128
|
* map and `validateOnBlur` behaviour.
|
|
74
129
|
*/
|
|
75
130
|
onBlurField?: (fieldName: string) => void;
|
|
131
|
+
/**
|
|
132
|
+
* Controlled touched map. When provided it is the single source of truth and
|
|
133
|
+
* the internal tracker is bypassed entirely, so `useDynamicForm().touched`
|
|
134
|
+
* (updated by `setFieldTouched`, `touchAll`, `handleSubmit` and cleared by
|
|
135
|
+
* `reset`) is what renderers actually see. Omit it to keep the internal,
|
|
136
|
+
* blur-only tracker.
|
|
137
|
+
*/
|
|
138
|
+
touched?: Record<string, boolean>;
|
|
139
|
+
/** Controlled validation errors. Empty means no renderer error. */
|
|
140
|
+
errors?: Record<string, string[]>;
|
|
141
|
+
/** Fires with the next touched map whenever a field is blurred. */
|
|
142
|
+
onTouchedChange?: (touched: Record<string, boolean>) => void;
|
|
143
|
+
/**
|
|
144
|
+
* Shorthand that wires `properties`, `onChange`, `onBlurField` and `touched`
|
|
145
|
+
* from a `useDynamicForm` result in one prop. Individually passed props win
|
|
146
|
+
* over the ones derived from here.
|
|
147
|
+
*/
|
|
148
|
+
form?: DynamicFormBinding;
|
|
76
149
|
}
|
|
77
|
-
declare const MultiFieldInput:
|
|
150
|
+
declare const MultiFieldInput: React.ForwardRefExoticComponent<Props & React.RefAttributes<MultiFieldInputHandle>>;
|
|
78
151
|
|
|
79
152
|
interface DynamicFormDevToolsProps {
|
|
80
153
|
data: Properties;
|
|
@@ -91,25 +164,59 @@ interface UseDynamicFormOptions {
|
|
|
91
164
|
initialValues?: Properties;
|
|
92
165
|
validateOnBlur?: boolean;
|
|
93
166
|
validateOnChange?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Messages for the built-in validators, set once for the whole form instead
|
|
169
|
+
* of per field. A message passed directly to a validator still wins, and any
|
|
170
|
+
* key omitted here falls back to the validator's English default. See core's
|
|
171
|
+
* `MessageCatalog`.
|
|
172
|
+
*/
|
|
173
|
+
messages?: MessageCatalog;
|
|
94
174
|
}
|
|
95
175
|
interface UseDynamicFormResult {
|
|
96
176
|
data: Properties;
|
|
97
177
|
errors: Record<string, string[]>;
|
|
98
178
|
isValid: boolean;
|
|
179
|
+
isValidating: boolean;
|
|
180
|
+
isValidationComplete: boolean;
|
|
181
|
+
validationStatus: ValidationResult['status'];
|
|
99
182
|
isDirty: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* The values `dirty` is measured against: the `initialValues` option until
|
|
185
|
+
* `reset(newValues)` replaces them. Distinct from that option, which never
|
|
186
|
+
* changes - pass this to `MultiFieldInput` (or use the `form` shorthand) so
|
|
187
|
+
* per-field `dirty` survives a reset.
|
|
188
|
+
*/
|
|
189
|
+
baselineValues: Properties;
|
|
190
|
+
/**
|
|
191
|
+
* The entries of `data` that differ from `baselineValues`. Intended for
|
|
192
|
+
* PATCH-style submits that should carry only what the user actually edited.
|
|
193
|
+
*/
|
|
194
|
+
getDirtyValues: () => Properties;
|
|
100
195
|
isSubmitting: boolean;
|
|
101
196
|
isSubmitted: boolean;
|
|
102
197
|
touched: Record<string, boolean>;
|
|
103
198
|
setData: React.Dispatch<React.SetStateAction<Properties>>;
|
|
104
199
|
setFieldValue: (name: string, value: unknown) => void;
|
|
105
200
|
setFieldTouched: (name: string, isTouched?: boolean) => void;
|
|
201
|
+
/** Replaces the whole touched map. */
|
|
202
|
+
setTouched: React.Dispatch<React.SetStateAction<Record<string, boolean>>>;
|
|
203
|
+
/**
|
|
204
|
+
* Marks every field touched at once. `handleSubmit` calls this for you, so
|
|
205
|
+
* an invalid submit surfaces errors on fields the user never focused - pass
|
|
206
|
+
* `touched` into `MultiFieldInput` for it to take effect.
|
|
207
|
+
*/
|
|
208
|
+
touchAll: () => void;
|
|
209
|
+
/** Clears the touched map without touching data, errors or dirty state. */
|
|
210
|
+
resetTouched: () => void;
|
|
106
211
|
handleChange: (newData: Properties) => void;
|
|
107
212
|
handleBlur: (fieldName: string) => void;
|
|
108
213
|
reset: (newValues?: Properties) => void;
|
|
109
214
|
validate: () => boolean;
|
|
215
|
+
/** Validate all fields and await Promise-based rules. */
|
|
216
|
+
validateAsync: () => Promise<boolean>;
|
|
110
217
|
handleSubmit: (onValid: (data: Properties) => void | Promise<void>, onInvalid?: (errors: Record<string, string[]>) => void) => (e?: React.FormEvent) => Promise<void>;
|
|
111
218
|
}
|
|
112
|
-
declare function useDynamicForm({ fields, initialValues, validateOnBlur, validateOnChange, }: UseDynamicFormOptions): UseDynamicFormResult;
|
|
219
|
+
declare function useDynamicForm({ fields, initialValues, validateOnBlur, validateOnChange, messages, }: UseDynamicFormOptions): UseDynamicFormResult;
|
|
113
220
|
|
|
114
221
|
declare const defaultRenderersMap: Record<string, React.FC<FieldRendererProps>>;
|
|
115
222
|
declare function getDefaultRenderer(type: string): React.FC<FieldRendererProps> | undefined;
|
|
@@ -129,4 +236,4 @@ declare const FieldRegistryProvider: ({ registry, children, }: FieldRegistryProv
|
|
|
129
236
|
/** The registry for the nearest provider, or the global singleton. */
|
|
130
237
|
declare function useFieldRegistry(): ReactFieldRegistry;
|
|
131
238
|
|
|
132
|
-
export { DynamicFormDevTools, DynamicInput, FieldInput, FieldRegistryProvider, type FieldRegistryProviderProps, MultiFieldInput, type ReactFieldRegistry, type ReactFieldRenderer, defaultRenderersMap, fieldRegistry, getDefaultRenderer, layoutRegistry, useDynamicForm, useFieldRegistry };
|
|
239
|
+
export { type DynamicFormBinding, DynamicFormDevTools, DynamicInput, FieldInput, FieldRegistryProvider, type FieldRegistryProviderProps, MultiFieldInput, type MultiFieldInputHandle, type ReactFieldRegistry, type ReactFieldRenderer, type UseDynamicFormOptions, type UseDynamicFormResult, defaultRenderersMap, fieldRegistry, getDefaultRenderer, layoutRegistry, useDynamicForm, useFieldRegistry };
|