@dynamic-field-kit/react 1.3.0 → 1.5.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/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import React, { ReactNode, ComponentType } from 'react';
2
- import * as react_jsx_runtime from 'react/jsx-runtime';
3
- import { FieldTypeKey, Properties, FieldDescription, FieldTypeMap, FieldRendererProps } from '@dynamic-field-kit/core';
4
- export { FieldDescription, FieldRendererProps, FieldTypeKey } from '@dynamic-field-kit/core';
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';
5
4
 
6
5
  type LayoutRenderer<C = unknown> = (props: {
7
6
  children: React.ReactNode;
@@ -14,43 +13,106 @@ declare class LayoutRegistry {
14
13
  }
15
14
  declare const layoutRegistry: LayoutRegistry;
16
15
 
17
- type BaseLayout = 'column' | 'row' | {
18
- type: 'grid';
19
- columns?: number;
20
- gap?: number;
21
- };
22
- type LayoutConfig = BaseLayout | {
23
- type: 'responsive';
24
- mobile: BaseLayout;
25
- desktop: BaseLayout;
26
- };
27
-
28
16
  interface Props$2<T extends FieldTypeKey> {
29
17
  type: T;
30
18
  value?: unknown;
31
19
  onChange?: (value: unknown) => void;
20
+ onBlur?: () => void;
32
21
  label?: string;
33
22
  options?: Properties[];
34
23
  className?: string;
35
24
  description?: ReactNode;
25
+ disabled?: boolean;
26
+ readOnly?: boolean;
27
+ required?: boolean;
28
+ touched?: boolean;
29
+ dirty?: boolean;
30
+ error?: string | string[];
31
+ id?: string;
32
+ ariaInvalid?: boolean;
33
+ ariaDescribedBy?: string;
34
+ ariaRequired?: boolean;
35
+ /** Extra, framework-agnostic props forwarded verbatim to the renderer. */
36
+ extraProps?: Properties;
36
37
  }
37
- declare const DynamicInputInner: <T extends FieldTypeKey>({ type, value, onChange, label, options, className, description, }: Props$2<T>) => react_jsx_runtime.JSX.Element;
38
+ declare const DynamicInputInner: <T extends FieldTypeKey>({ type, value, onChange, onBlur, label, options, className, description, disabled, readOnly, required, touched, dirty, error, id, ariaInvalid, ariaDescribedBy, ariaRequired, extraProps, }: Props$2<T>) => React.JSX.Element;
38
39
  declare const DynamicInput: typeof DynamicInputInner;
39
40
 
40
41
  interface Props$1 {
41
42
  fieldDescription: FieldDescription;
42
43
  renderInfos: Properties;
44
+ rootData?: Properties;
45
+ touched?: boolean;
46
+ dirty?: boolean;
47
+ onBlurField?: (key: string) => void;
43
48
  onValueChangeField: (value: unknown, key: string) => void;
44
49
  }
45
- declare const FieldInput: React.MemoExoticComponent<({ fieldDescription, renderInfos, onValueChangeField, }: Props$1) => react_jsx_runtime.JSX.Element>;
50
+ declare const FieldInput: React.MemoExoticComponent<({ fieldDescription, renderInfos, rootData, touched, dirty, onBlurField, onValueChangeField, }: Props$1) => React.JSX.Element>;
46
51
 
47
52
  interface Props {
48
53
  fieldDescriptions: FieldDescription[];
49
54
  properties?: Properties;
50
55
  onChange?: (data: Properties) => void;
51
56
  layout?: LayoutConfig;
57
+ /**
58
+ * Top-level form data, threaded down through repeatable groups so a nested
59
+ * field's `appearCondition`/`computeValue` can read the root form. Omitted at
60
+ * the top level, where the form's own data is the root.
61
+ */
62
+ rootData?: Properties;
63
+ /**
64
+ * Called with the recursive validation result ({ valid, errors }) on every
65
+ * change. On the top-level component this covers the whole form (groups
66
+ * included).
67
+ */
68
+ onValidityChange?: (result: ValidationResult) => void;
69
+ /**
70
+ * Called with a field's name when it loses focus. Touched state is still
71
+ * tracked internally either way; this is the hook for driving an external
72
+ * form store - pass `useDynamicForm`'s `handleBlur` to get its `touched`
73
+ * map and `validateOnBlur` behaviour.
74
+ */
75
+ onBlurField?: (fieldName: string) => void;
76
+ }
77
+ declare const MultiFieldInput: ({ fieldDescriptions, properties, onChange, layout, rootData, onValidityChange, onBlurField, }: Props) => React.JSX.Element;
78
+
79
+ interface DynamicFormDevToolsProps {
80
+ data: Properties;
81
+ errors?: Record<string, string[]>;
82
+ touched?: Record<string, boolean>;
83
+ isDirty?: boolean;
84
+ fields?: FieldDescription[];
85
+ position?: 'bottom-right' | 'bottom-left';
86
+ }
87
+ declare const DynamicFormDevTools: React.FC<DynamicFormDevToolsProps>;
88
+
89
+ interface UseDynamicFormOptions {
90
+ fields: FieldDescription[];
91
+ initialValues?: Properties;
92
+ validateOnBlur?: boolean;
93
+ validateOnChange?: boolean;
52
94
  }
53
- declare const MultiFieldInput: ({ fieldDescriptions, properties, onChange, layout, }: Props) => react_jsx_runtime.JSX.Element;
95
+ interface UseDynamicFormResult {
96
+ data: Properties;
97
+ errors: Record<string, string[]>;
98
+ isValid: boolean;
99
+ isDirty: boolean;
100
+ isSubmitting: boolean;
101
+ isSubmitted: boolean;
102
+ touched: Record<string, boolean>;
103
+ setData: React.Dispatch<React.SetStateAction<Properties>>;
104
+ setFieldValue: (name: string, value: unknown) => void;
105
+ setFieldTouched: (name: string, isTouched?: boolean) => void;
106
+ handleChange: (newData: Properties) => void;
107
+ handleBlur: (fieldName: string) => void;
108
+ reset: (newValues?: Properties) => void;
109
+ validate: () => boolean;
110
+ handleSubmit: (onValid: (data: Properties) => void | Promise<void>, onInvalid?: (errors: Record<string, string[]>) => void) => (e?: React.FormEvent) => Promise<void>;
111
+ }
112
+ declare function useDynamicForm({ fields, initialValues, validateOnBlur, validateOnChange, }: UseDynamicFormOptions): UseDynamicFormResult;
113
+
114
+ declare const defaultRenderersMap: Record<string, React.FC<FieldRendererProps>>;
115
+ declare function getDefaultRenderer(type: string): React.FC<FieldRendererProps> | undefined;
54
116
 
55
117
  type ReactFieldRenderer<T = unknown> = ComponentType<FieldRendererProps<T>>;
56
118
  interface ReactFieldRegistry {
@@ -59,4 +121,12 @@ interface ReactFieldRegistry {
59
121
  }
60
122
  declare const fieldRegistry: ReactFieldRegistry;
61
123
 
62
- export { DynamicInput, FieldInput, type LayoutConfig, MultiFieldInput, type ReactFieldRegistry, type ReactFieldRenderer, fieldRegistry, layoutRegistry };
124
+ interface FieldRegistryProviderProps {
125
+ registry: ReactFieldRegistry;
126
+ children: React.ReactNode;
127
+ }
128
+ declare const FieldRegistryProvider: ({ registry, children, }: FieldRegistryProviderProps) => React.ReactElement;
129
+ /** The registry for the nearest provider, or the global singleton. */
130
+ declare function useFieldRegistry(): ReactFieldRegistry;
131
+
132
+ export { DynamicFormDevTools, DynamicInput, FieldInput, FieldRegistryProvider, type FieldRegistryProviderProps, MultiFieldInput, type ReactFieldRegistry, type ReactFieldRenderer, defaultRenderersMap, fieldRegistry, getDefaultRenderer, layoutRegistry, useDynamicForm, useFieldRegistry };