@form-engine-ts/react 2.2.0 → 2.3.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.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
- import { ReactNode, ComponentType } from 'react';
3
- import { QuestionType, FormField, ChoiceOption, FormPage, FormPolicy, FormSchema, DisplayCondition, JsonValue, SchemaIssue, ValidationError, TranslationAdapter, AsyncTranslationAdapter, PopulateTranslationOptions, TranslationReport, FormValue, ValidationIssue, FormValues, AnswerValidationResult, FieldType } from '@form-engine-ts/core';
2
+ import { ReactNode, ComponentType, MouseEvent } from 'react';
3
+ import { QuestionType, FormField, ChoiceOption, FormPage, FormSchema, DisplayCondition, JsonValue, SchemaIssue, FormPolicy, FieldOption, ValidationError, TranslationAdapter, AsyncTranslationAdapter, PopulateTranslationOptions, TranslationReport, FormValue, ValidationIssue, FormValues, AnswerValidationResult, FieldType } from '@form-engine-ts/core';
4
4
 
5
5
  /** @deprecated Import FormPolicy from @form-engine-ts/core instead. */
6
6
  type BuilderPolicy = FormPolicy;
@@ -84,6 +84,142 @@ interface FormBuilderResult {
84
84
  }
85
85
  declare function useFormBuilder({ schema, onChange, policy, idFactory, factories }: FormBuilderOptions): FormBuilderResult;
86
86
 
87
+ interface ComponentBaseProps {
88
+ readonly id?: string;
89
+ readonly className?: string;
90
+ readonly disabled?: boolean;
91
+ readonly readOnly?: boolean;
92
+ readonly "aria-label"?: string;
93
+ }
94
+ interface BuilderButtonProps extends ComponentBaseProps {
95
+ readonly onClick?: () => void;
96
+ readonly variant?: "primary" | "secondary" | "danger";
97
+ readonly children: ReactNode;
98
+ readonly title?: string;
99
+ readonly action?: string;
100
+ readonly targetId?: string;
101
+ }
102
+ interface BuilderIconButtonProps extends ComponentBaseProps {
103
+ readonly onClick?: () => void;
104
+ readonly icon: string;
105
+ readonly title: string;
106
+ }
107
+ interface BuilderTextInputProps extends ComponentBaseProps {
108
+ readonly value: string;
109
+ readonly onChange: (value: string) => void;
110
+ readonly placeholder?: string;
111
+ readonly maxLength?: number;
112
+ readonly inputMode?: "text" | "numeric";
113
+ readonly type?: "text" | "number";
114
+ readonly min?: number;
115
+ readonly max?: number;
116
+ readonly step?: number;
117
+ }
118
+ interface BuilderTextAreaProps extends ComponentBaseProps {
119
+ readonly value: string;
120
+ readonly onChange: (value: string) => void;
121
+ readonly rows?: number;
122
+ readonly placeholder?: string;
123
+ readonly maxLength?: number;
124
+ }
125
+ interface BuilderSelectOption {
126
+ readonly label: string;
127
+ readonly value: string;
128
+ readonly disabled?: boolean;
129
+ }
130
+ interface BuilderSelectProps extends ComponentBaseProps {
131
+ readonly value: string;
132
+ readonly onChange: (value: string) => void;
133
+ readonly options: readonly BuilderSelectOption[];
134
+ }
135
+ interface BuilderCheckboxProps extends ComponentBaseProps {
136
+ readonly checked: boolean;
137
+ readonly onChange: (checked: boolean) => void;
138
+ readonly label: string;
139
+ }
140
+ interface BuilderSectionProps {
141
+ readonly id?: string;
142
+ readonly className?: string;
143
+ readonly title?: string;
144
+ readonly description?: string;
145
+ readonly headingId?: string;
146
+ readonly "aria-label"?: string;
147
+ readonly onClickCapture?: (event: MouseEvent<HTMLElement>) => void;
148
+ readonly children: ReactNode;
149
+ }
150
+ interface BuilderFieldsetProps {
151
+ readonly className?: string;
152
+ readonly legend?: string;
153
+ readonly disabled?: boolean;
154
+ readonly children: ReactNode;
155
+ }
156
+ interface FormBuilderComponents {
157
+ readonly Button?: ComponentType<BuilderButtonProps>;
158
+ readonly IconButton?: ComponentType<BuilderIconButtonProps>;
159
+ readonly TextInput?: ComponentType<BuilderTextInputProps>;
160
+ readonly TextArea?: ComponentType<BuilderTextAreaProps>;
161
+ readonly Select?: ComponentType<BuilderSelectProps>;
162
+ readonly Checkbox?: ComponentType<BuilderCheckboxProps>;
163
+ readonly Section?: ComponentType<BuilderSectionProps>;
164
+ readonly Fieldset?: ComponentType<BuilderFieldsetProps>;
165
+ readonly ErrorMessage?: ComponentType<{
166
+ readonly message: string;
167
+ }>;
168
+ }
169
+ type FormBuilderActions = Omit<FormBuilderResult, "schema" | "validationIssues">;
170
+ interface BuilderSlotBaseProps {
171
+ readonly schema: FormSchema;
172
+ readonly readOnly: boolean;
173
+ readonly actions: FormBuilderActions;
174
+ readonly components: Required<FormBuilderComponents>;
175
+ }
176
+ interface BuilderToolbarSlotProps extends BuilderSlotBaseProps {
177
+ readonly kind: "page" | "field" | "option";
178
+ readonly targetId: string;
179
+ readonly index: number;
180
+ readonly total: number;
181
+ readonly title: string;
182
+ readonly onMoveUp: () => void;
183
+ readonly onMoveDown: () => void;
184
+ readonly onRemove: () => void;
185
+ }
186
+ interface BuilderFieldEditorSlotProps extends BuilderSlotBaseProps {
187
+ readonly field: FormField;
188
+ readonly index: number;
189
+ readonly currentLocale: string;
190
+ readonly policy?: FormPolicy;
191
+ }
192
+ interface BuilderOptionEditorSlotProps extends BuilderSlotBaseProps {
193
+ readonly field: FormField & {
194
+ readonly options: readonly FieldOption[];
195
+ };
196
+ readonly option: FieldOption;
197
+ readonly index: number;
198
+ readonly currentLocale: string;
199
+ }
200
+ interface BuilderPagesSlotProps extends BuilderSlotBaseProps {
201
+ readonly currentLocale: string;
202
+ }
203
+ interface BuilderLocalizationSlotProps extends BuilderSlotBaseProps {
204
+ readonly currentLocale: string;
205
+ readonly onCurrentLocaleChange: (locale: string) => void;
206
+ readonly onAutoTranslate: () => void;
207
+ readonly isTranslating: boolean;
208
+ readonly translationError?: string;
209
+ }
210
+ interface BuilderTranslationActionsSlotProps extends BuilderSlotBaseProps {
211
+ readonly currentLocale: string;
212
+ readonly onAutoTranslate: () => void;
213
+ readonly isTranslating: boolean;
214
+ }
215
+ interface FormBuilderSlots {
216
+ readonly toolbar?: ComponentType<BuilderToolbarSlotProps>;
217
+ readonly fieldEditor?: ComponentType<BuilderFieldEditorSlotProps>;
218
+ readonly optionEditor?: ComponentType<BuilderOptionEditorSlotProps>;
219
+ readonly pages?: ComponentType<BuilderPagesSlotProps>;
220
+ readonly localization?: ComponentType<BuilderLocalizationSlotProps>;
221
+ readonly translationActions?: ComponentType<BuilderTranslationActionsSlotProps>;
222
+ }
87
223
  interface BuilderActionContext {
88
224
  readonly action: "addField" | "removeField" | "moveField" | "changeFieldType" | "updateField" | "addOption" | "removeOption" | "moveOption" | "updateOption" | "addPage" | "removePage" | "movePage" | "updatePage" | "assignFieldToPage" | "addLocale" | "setDefaultLocale" | "setDisplayCondition" | "setSourceText" | "setLocaleTranslation";
89
225
  readonly targetId?: string;
@@ -173,8 +309,10 @@ interface FormBuilderProps {
173
309
  readonly createManualTranslationMetadata?: (context: ManualTranslationContext) => Readonly<Record<string, JsonValue>> | undefined;
174
310
  readonly readOnly?: boolean;
175
311
  readonly features?: FormBuilderFeatures;
312
+ readonly components?: FormBuilderComponents;
313
+ readonly slots?: FormBuilderSlots;
176
314
  }
177
- declare function FormBuilder({ schema, onChange, locale, translator, translationAdapter, translationOptions, onTranslationReport, policy, idFactory, factories, className, defaultFieldType, onActionError, createManualTranslationMetadata, readOnly, features }: FormBuilderProps): react.JSX.Element;
315
+ declare function FormBuilder({ schema, onChange, locale, translator, translationAdapter, translationOptions, onTranslationReport, policy, idFactory, factories, className, defaultFieldType, onActionError, createManualTranslationMetadata, readOnly, features, components: componentOverrides, slots }: FormBuilderProps): react.JSX.Element;
178
316
 
179
317
  type SubmitStatus = "idle" | "submitting" | "success" | "error";
180
318
  interface FormContextValue {
@@ -246,4 +384,4 @@ interface StandaloneFormRendererProps extends FormRendererPresentationProps {
246
384
  type FormRendererProps = FormRendererPresentationProps | StandaloneFormRendererProps;
247
385
  declare function FormRenderer(props: FormRendererProps): react.JSX.Element;
248
386
 
249
- export { type BeforeSubmit, type BuilderActionContext, type BuilderActionError, type BuilderActionResult, type BuilderFactories, type BuilderIdKind, type BuilderPolicy, type BuilderTextTarget, type FieldComponentProps, type FieldComponents, type FieldState, FormBuilder, type FormBuilderFeatures, type FormBuilderOptions, type FormBuilderProps, type FormBuilderResult, type FormContextValue, FormProvider, type FormProviderProps, FormRenderer, type FormRendererPresentationProps, type FormRendererProps, type FormRendererSlots, type ManualTranslationContext, type StandaloneFormRendererProps, type SubmitResult, type SubmitStatus, resolveInitialFieldType, useField, useForm, useFormBuilder };
387
+ export { type BeforeSubmit, type BuilderActionContext, type BuilderActionError, type BuilderActionResult, type BuilderButtonProps, type BuilderCheckboxProps, type BuilderFactories, type BuilderFieldEditorSlotProps, type BuilderFieldsetProps, type BuilderIconButtonProps, type BuilderIdKind, type BuilderLocalizationSlotProps, type BuilderOptionEditorSlotProps, type BuilderPagesSlotProps, type BuilderPolicy, type BuilderSectionProps, type BuilderSelectOption, type BuilderSelectProps, type BuilderTextAreaProps, type BuilderTextInputProps, type BuilderTextTarget, type BuilderToolbarSlotProps, type BuilderTranslationActionsSlotProps, type ComponentBaseProps, type FieldComponentProps, type FieldComponents, type FieldState, FormBuilder, type FormBuilderActions, type FormBuilderComponents, type FormBuilderFeatures, type FormBuilderOptions, type FormBuilderProps, type FormBuilderResult, type FormBuilderSlots, type FormContextValue, FormProvider, type FormProviderProps, FormRenderer, type FormRendererPresentationProps, type FormRendererProps, type FormRendererSlots, type ManualTranslationContext, type StandaloneFormRendererProps, type SubmitResult, type SubmitStatus, resolveInitialFieldType, useField, useForm, useFormBuilder };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
- import { ReactNode, ComponentType } from 'react';
3
- import { QuestionType, FormField, ChoiceOption, FormPage, FormPolicy, FormSchema, DisplayCondition, JsonValue, SchemaIssue, ValidationError, TranslationAdapter, AsyncTranslationAdapter, PopulateTranslationOptions, TranslationReport, FormValue, ValidationIssue, FormValues, AnswerValidationResult, FieldType } from '@form-engine-ts/core';
2
+ import { ReactNode, ComponentType, MouseEvent } from 'react';
3
+ import { QuestionType, FormField, ChoiceOption, FormPage, FormSchema, DisplayCondition, JsonValue, SchemaIssue, FormPolicy, FieldOption, ValidationError, TranslationAdapter, AsyncTranslationAdapter, PopulateTranslationOptions, TranslationReport, FormValue, ValidationIssue, FormValues, AnswerValidationResult, FieldType } from '@form-engine-ts/core';
4
4
 
5
5
  /** @deprecated Import FormPolicy from @form-engine-ts/core instead. */
6
6
  type BuilderPolicy = FormPolicy;
@@ -84,6 +84,142 @@ interface FormBuilderResult {
84
84
  }
85
85
  declare function useFormBuilder({ schema, onChange, policy, idFactory, factories }: FormBuilderOptions): FormBuilderResult;
86
86
 
87
+ interface ComponentBaseProps {
88
+ readonly id?: string;
89
+ readonly className?: string;
90
+ readonly disabled?: boolean;
91
+ readonly readOnly?: boolean;
92
+ readonly "aria-label"?: string;
93
+ }
94
+ interface BuilderButtonProps extends ComponentBaseProps {
95
+ readonly onClick?: () => void;
96
+ readonly variant?: "primary" | "secondary" | "danger";
97
+ readonly children: ReactNode;
98
+ readonly title?: string;
99
+ readonly action?: string;
100
+ readonly targetId?: string;
101
+ }
102
+ interface BuilderIconButtonProps extends ComponentBaseProps {
103
+ readonly onClick?: () => void;
104
+ readonly icon: string;
105
+ readonly title: string;
106
+ }
107
+ interface BuilderTextInputProps extends ComponentBaseProps {
108
+ readonly value: string;
109
+ readonly onChange: (value: string) => void;
110
+ readonly placeholder?: string;
111
+ readonly maxLength?: number;
112
+ readonly inputMode?: "text" | "numeric";
113
+ readonly type?: "text" | "number";
114
+ readonly min?: number;
115
+ readonly max?: number;
116
+ readonly step?: number;
117
+ }
118
+ interface BuilderTextAreaProps extends ComponentBaseProps {
119
+ readonly value: string;
120
+ readonly onChange: (value: string) => void;
121
+ readonly rows?: number;
122
+ readonly placeholder?: string;
123
+ readonly maxLength?: number;
124
+ }
125
+ interface BuilderSelectOption {
126
+ readonly label: string;
127
+ readonly value: string;
128
+ readonly disabled?: boolean;
129
+ }
130
+ interface BuilderSelectProps extends ComponentBaseProps {
131
+ readonly value: string;
132
+ readonly onChange: (value: string) => void;
133
+ readonly options: readonly BuilderSelectOption[];
134
+ }
135
+ interface BuilderCheckboxProps extends ComponentBaseProps {
136
+ readonly checked: boolean;
137
+ readonly onChange: (checked: boolean) => void;
138
+ readonly label: string;
139
+ }
140
+ interface BuilderSectionProps {
141
+ readonly id?: string;
142
+ readonly className?: string;
143
+ readonly title?: string;
144
+ readonly description?: string;
145
+ readonly headingId?: string;
146
+ readonly "aria-label"?: string;
147
+ readonly onClickCapture?: (event: MouseEvent<HTMLElement>) => void;
148
+ readonly children: ReactNode;
149
+ }
150
+ interface BuilderFieldsetProps {
151
+ readonly className?: string;
152
+ readonly legend?: string;
153
+ readonly disabled?: boolean;
154
+ readonly children: ReactNode;
155
+ }
156
+ interface FormBuilderComponents {
157
+ readonly Button?: ComponentType<BuilderButtonProps>;
158
+ readonly IconButton?: ComponentType<BuilderIconButtonProps>;
159
+ readonly TextInput?: ComponentType<BuilderTextInputProps>;
160
+ readonly TextArea?: ComponentType<BuilderTextAreaProps>;
161
+ readonly Select?: ComponentType<BuilderSelectProps>;
162
+ readonly Checkbox?: ComponentType<BuilderCheckboxProps>;
163
+ readonly Section?: ComponentType<BuilderSectionProps>;
164
+ readonly Fieldset?: ComponentType<BuilderFieldsetProps>;
165
+ readonly ErrorMessage?: ComponentType<{
166
+ readonly message: string;
167
+ }>;
168
+ }
169
+ type FormBuilderActions = Omit<FormBuilderResult, "schema" | "validationIssues">;
170
+ interface BuilderSlotBaseProps {
171
+ readonly schema: FormSchema;
172
+ readonly readOnly: boolean;
173
+ readonly actions: FormBuilderActions;
174
+ readonly components: Required<FormBuilderComponents>;
175
+ }
176
+ interface BuilderToolbarSlotProps extends BuilderSlotBaseProps {
177
+ readonly kind: "page" | "field" | "option";
178
+ readonly targetId: string;
179
+ readonly index: number;
180
+ readonly total: number;
181
+ readonly title: string;
182
+ readonly onMoveUp: () => void;
183
+ readonly onMoveDown: () => void;
184
+ readonly onRemove: () => void;
185
+ }
186
+ interface BuilderFieldEditorSlotProps extends BuilderSlotBaseProps {
187
+ readonly field: FormField;
188
+ readonly index: number;
189
+ readonly currentLocale: string;
190
+ readonly policy?: FormPolicy;
191
+ }
192
+ interface BuilderOptionEditorSlotProps extends BuilderSlotBaseProps {
193
+ readonly field: FormField & {
194
+ readonly options: readonly FieldOption[];
195
+ };
196
+ readonly option: FieldOption;
197
+ readonly index: number;
198
+ readonly currentLocale: string;
199
+ }
200
+ interface BuilderPagesSlotProps extends BuilderSlotBaseProps {
201
+ readonly currentLocale: string;
202
+ }
203
+ interface BuilderLocalizationSlotProps extends BuilderSlotBaseProps {
204
+ readonly currentLocale: string;
205
+ readonly onCurrentLocaleChange: (locale: string) => void;
206
+ readonly onAutoTranslate: () => void;
207
+ readonly isTranslating: boolean;
208
+ readonly translationError?: string;
209
+ }
210
+ interface BuilderTranslationActionsSlotProps extends BuilderSlotBaseProps {
211
+ readonly currentLocale: string;
212
+ readonly onAutoTranslate: () => void;
213
+ readonly isTranslating: boolean;
214
+ }
215
+ interface FormBuilderSlots {
216
+ readonly toolbar?: ComponentType<BuilderToolbarSlotProps>;
217
+ readonly fieldEditor?: ComponentType<BuilderFieldEditorSlotProps>;
218
+ readonly optionEditor?: ComponentType<BuilderOptionEditorSlotProps>;
219
+ readonly pages?: ComponentType<BuilderPagesSlotProps>;
220
+ readonly localization?: ComponentType<BuilderLocalizationSlotProps>;
221
+ readonly translationActions?: ComponentType<BuilderTranslationActionsSlotProps>;
222
+ }
87
223
  interface BuilderActionContext {
88
224
  readonly action: "addField" | "removeField" | "moveField" | "changeFieldType" | "updateField" | "addOption" | "removeOption" | "moveOption" | "updateOption" | "addPage" | "removePage" | "movePage" | "updatePage" | "assignFieldToPage" | "addLocale" | "setDefaultLocale" | "setDisplayCondition" | "setSourceText" | "setLocaleTranslation";
89
225
  readonly targetId?: string;
@@ -173,8 +309,10 @@ interface FormBuilderProps {
173
309
  readonly createManualTranslationMetadata?: (context: ManualTranslationContext) => Readonly<Record<string, JsonValue>> | undefined;
174
310
  readonly readOnly?: boolean;
175
311
  readonly features?: FormBuilderFeatures;
312
+ readonly components?: FormBuilderComponents;
313
+ readonly slots?: FormBuilderSlots;
176
314
  }
177
- declare function FormBuilder({ schema, onChange, locale, translator, translationAdapter, translationOptions, onTranslationReport, policy, idFactory, factories, className, defaultFieldType, onActionError, createManualTranslationMetadata, readOnly, features }: FormBuilderProps): react.JSX.Element;
315
+ declare function FormBuilder({ schema, onChange, locale, translator, translationAdapter, translationOptions, onTranslationReport, policy, idFactory, factories, className, defaultFieldType, onActionError, createManualTranslationMetadata, readOnly, features, components: componentOverrides, slots }: FormBuilderProps): react.JSX.Element;
178
316
 
179
317
  type SubmitStatus = "idle" | "submitting" | "success" | "error";
180
318
  interface FormContextValue {
@@ -246,4 +384,4 @@ interface StandaloneFormRendererProps extends FormRendererPresentationProps {
246
384
  type FormRendererProps = FormRendererPresentationProps | StandaloneFormRendererProps;
247
385
  declare function FormRenderer(props: FormRendererProps): react.JSX.Element;
248
386
 
249
- export { type BeforeSubmit, type BuilderActionContext, type BuilderActionError, type BuilderActionResult, type BuilderFactories, type BuilderIdKind, type BuilderPolicy, type BuilderTextTarget, type FieldComponentProps, type FieldComponents, type FieldState, FormBuilder, type FormBuilderFeatures, type FormBuilderOptions, type FormBuilderProps, type FormBuilderResult, type FormContextValue, FormProvider, type FormProviderProps, FormRenderer, type FormRendererPresentationProps, type FormRendererProps, type FormRendererSlots, type ManualTranslationContext, type StandaloneFormRendererProps, type SubmitResult, type SubmitStatus, resolveInitialFieldType, useField, useForm, useFormBuilder };
387
+ export { type BeforeSubmit, type BuilderActionContext, type BuilderActionError, type BuilderActionResult, type BuilderButtonProps, type BuilderCheckboxProps, type BuilderFactories, type BuilderFieldEditorSlotProps, type BuilderFieldsetProps, type BuilderIconButtonProps, type BuilderIdKind, type BuilderLocalizationSlotProps, type BuilderOptionEditorSlotProps, type BuilderPagesSlotProps, type BuilderPolicy, type BuilderSectionProps, type BuilderSelectOption, type BuilderSelectProps, type BuilderTextAreaProps, type BuilderTextInputProps, type BuilderTextTarget, type BuilderToolbarSlotProps, type BuilderTranslationActionsSlotProps, type ComponentBaseProps, type FieldComponentProps, type FieldComponents, type FieldState, FormBuilder, type FormBuilderActions, type FormBuilderComponents, type FormBuilderFeatures, type FormBuilderOptions, type FormBuilderProps, type FormBuilderResult, type FormBuilderSlots, type FormContextValue, FormProvider, type FormProviderProps, FormRenderer, type FormRendererPresentationProps, type FormRendererProps, type FormRendererSlots, type ManualTranslationContext, type StandaloneFormRendererProps, type SubmitResult, type SubmitStatus, resolveInitialFieldType, useField, useForm, useFormBuilder };