@form-engine-ts/react 2.1.0 → 2.2.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
2
  import { ReactNode, ComponentType } from 'react';
3
- import { QuestionType, FormField, ChoiceOption, FormPage, FormPolicy, FormSchema, DisplayCondition, JsonValue, SchemaIssue, TranslationAdapter, AsyncTranslationAdapter, PopulateTranslationOptions, TranslationReport, ValidationError, FormValue, ValidationIssue, FormValues, AnswerValidationResult, FieldType } from '@form-engine-ts/core';
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';
4
4
 
5
5
  /** @deprecated Import FormPolicy from @form-engine-ts/core instead. */
6
6
  type BuilderPolicy = FormPolicy;
@@ -37,6 +37,12 @@ type BuilderActionError = {
37
37
  } | {
38
38
  readonly type: "disallowed_field_type";
39
39
  readonly fieldType: QuestionType;
40
+ } | {
41
+ readonly type: "disallowed_locale";
42
+ readonly locale: string;
43
+ } | {
44
+ readonly type: "max_locales_exceeded";
45
+ readonly max: number;
40
46
  } | {
41
47
  readonly type: "node_not_found";
42
48
  readonly kind: BuilderTextTarget["kind"];
@@ -70,7 +76,7 @@ interface FormBuilderResult {
70
76
  readonly setDisplayCondition: (fieldId: string, condition?: DisplayCondition) => BuilderActionResult;
71
77
  readonly setSourceText: (target: BuilderTextTarget, property: string, text: string) => BuilderActionResult;
72
78
  readonly setLocaleTranslation: (locale: string, target: BuilderTextTarget, property: string, text: string, options?: {
73
- readonly metadata?: Record<string, JsonValue>;
79
+ readonly metadata?: Readonly<Record<string, JsonValue>>;
74
80
  }) => BuilderActionResult;
75
81
  readonly addLocale: (locale: string) => BuilderActionResult;
76
82
  readonly setDefaultLocale: (locale: string) => BuilderActionResult;
@@ -78,20 +84,20 @@ interface FormBuilderResult {
78
84
  }
79
85
  declare function useFormBuilder({ schema, onChange, policy, idFactory, factories }: FormBuilderOptions): FormBuilderResult;
80
86
 
81
- interface FormBuilderProps {
82
- readonly schema: FormSchema;
83
- readonly onChange: (newSchema: FormSchema) => void;
84
- readonly locale?: string;
85
- readonly translator?: TranslationAdapter;
86
- readonly translationAdapter?: AsyncTranslationAdapter;
87
- readonly translationOptions?: PopulateTranslationOptions;
88
- readonly onTranslationReport?: (report: TranslationReport) => void;
89
- readonly policy?: FormPolicy;
90
- readonly idFactory?: (kind: "field" | "option" | "page", existingIds: ReadonlySet<string>) => string;
91
- readonly factories?: BuilderFactories;
87
+ interface BuilderActionContext {
88
+ readonly action: "addField" | "removeField" | "moveField" | "changeFieldType" | "updateField" | "addOption" | "removeOption" | "moveOption" | "updateOption" | "addPage" | "removePage" | "movePage" | "updatePage" | "assignFieldToPage" | "addLocale" | "setDefaultLocale" | "setDisplayCondition" | "setSourceText" | "setLocaleTranslation";
89
+ readonly targetId?: string;
90
+ readonly params?: Record<string, unknown>;
91
+ }
92
+ interface ManualTranslationContext {
93
+ readonly locale: string;
94
+ readonly kind: "form" | "page" | "field" | "option";
95
+ readonly nodeId: string;
96
+ readonly property: "title" | "description" | "label" | "completionMessage";
97
+ readonly sourceText: string;
98
+ readonly translatedText: string;
99
+ readonly existingTranslationMetadata?: Readonly<Record<string, JsonValue>>;
92
100
  }
93
- declare function FormBuilder({ schema, onChange, locale, translator, translationAdapter, translationOptions, onTranslationReport, policy, idFactory, factories }: FormBuilderProps): react.JSX.Element;
94
-
95
101
  type SubmitResult = {
96
102
  readonly status: "invalid";
97
103
  readonly issues: readonly ValidationError[];
@@ -144,6 +150,32 @@ interface FormRendererSlots {
144
150
  }
145
151
  type BeforeSubmit = (values: Readonly<Record<string, unknown>>) => "continue" | "cancel" | Promise<"continue" | "cancel">;
146
152
 
153
+ declare function resolveInitialFieldType(defaultType?: QuestionType, allowedTypes?: readonly QuestionType[]): QuestionType | null;
154
+ interface FormBuilderFeatures {
155
+ readonly pages?: boolean;
156
+ readonly localization?: boolean;
157
+ readonly conditions?: boolean;
158
+ }
159
+ interface FormBuilderProps {
160
+ readonly schema: FormSchema;
161
+ readonly onChange: (newSchema: FormSchema) => void;
162
+ readonly locale?: string;
163
+ readonly translator?: TranslationAdapter;
164
+ readonly translationAdapter?: AsyncTranslationAdapter;
165
+ readonly translationOptions?: PopulateTranslationOptions;
166
+ readonly onTranslationReport?: (report: TranslationReport) => void;
167
+ readonly policy?: FormPolicy;
168
+ readonly idFactory?: (kind: "field" | "option" | "page", existingIds: ReadonlySet<string>) => string;
169
+ readonly factories?: BuilderFactories;
170
+ readonly className?: string;
171
+ readonly defaultFieldType?: QuestionType;
172
+ readonly onActionError?: (error: BuilderActionError, context: BuilderActionContext) => void;
173
+ readonly createManualTranslationMetadata?: (context: ManualTranslationContext) => Readonly<Record<string, JsonValue>> | undefined;
174
+ readonly readOnly?: boolean;
175
+ readonly features?: FormBuilderFeatures;
176
+ }
177
+ declare function FormBuilder({ schema, onChange, locale, translator, translationAdapter, translationOptions, onTranslationReport, policy, idFactory, factories, className, defaultFieldType, onActionError, createManualTranslationMetadata, readOnly, features }: FormBuilderProps): react.JSX.Element;
178
+
147
179
  type SubmitStatus = "idle" | "submitting" | "success" | "error";
148
180
  interface FormContextValue {
149
181
  readonly schema: FormSchema;
@@ -214,4 +246,4 @@ interface StandaloneFormRendererProps extends FormRendererPresentationProps {
214
246
  type FormRendererProps = FormRendererPresentationProps | StandaloneFormRendererProps;
215
247
  declare function FormRenderer(props: FormRendererProps): react.JSX.Element;
216
248
 
217
- export { type BeforeSubmit, type BuilderActionError, type BuilderActionResult, type BuilderFactories, type BuilderIdKind, type BuilderPolicy, type BuilderTextTarget, type FieldComponentProps, type FieldComponents, type FieldState, FormBuilder, type FormBuilderOptions, type FormBuilderProps, type FormBuilderResult, type FormContextValue, FormProvider, type FormProviderProps, FormRenderer, type FormRendererPresentationProps, type FormRendererProps, type FormRendererSlots, type StandaloneFormRendererProps, type SubmitResult, type SubmitStatus, useField, useForm, useFormBuilder };
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 };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, ComponentType } from 'react';
3
- import { QuestionType, FormField, ChoiceOption, FormPage, FormPolicy, FormSchema, DisplayCondition, JsonValue, SchemaIssue, TranslationAdapter, AsyncTranslationAdapter, PopulateTranslationOptions, TranslationReport, ValidationError, FormValue, ValidationIssue, FormValues, AnswerValidationResult, FieldType } from '@form-engine-ts/core';
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';
4
4
 
5
5
  /** @deprecated Import FormPolicy from @form-engine-ts/core instead. */
6
6
  type BuilderPolicy = FormPolicy;
@@ -37,6 +37,12 @@ type BuilderActionError = {
37
37
  } | {
38
38
  readonly type: "disallowed_field_type";
39
39
  readonly fieldType: QuestionType;
40
+ } | {
41
+ readonly type: "disallowed_locale";
42
+ readonly locale: string;
43
+ } | {
44
+ readonly type: "max_locales_exceeded";
45
+ readonly max: number;
40
46
  } | {
41
47
  readonly type: "node_not_found";
42
48
  readonly kind: BuilderTextTarget["kind"];
@@ -70,7 +76,7 @@ interface FormBuilderResult {
70
76
  readonly setDisplayCondition: (fieldId: string, condition?: DisplayCondition) => BuilderActionResult;
71
77
  readonly setSourceText: (target: BuilderTextTarget, property: string, text: string) => BuilderActionResult;
72
78
  readonly setLocaleTranslation: (locale: string, target: BuilderTextTarget, property: string, text: string, options?: {
73
- readonly metadata?: Record<string, JsonValue>;
79
+ readonly metadata?: Readonly<Record<string, JsonValue>>;
74
80
  }) => BuilderActionResult;
75
81
  readonly addLocale: (locale: string) => BuilderActionResult;
76
82
  readonly setDefaultLocale: (locale: string) => BuilderActionResult;
@@ -78,20 +84,20 @@ interface FormBuilderResult {
78
84
  }
79
85
  declare function useFormBuilder({ schema, onChange, policy, idFactory, factories }: FormBuilderOptions): FormBuilderResult;
80
86
 
81
- interface FormBuilderProps {
82
- readonly schema: FormSchema;
83
- readonly onChange: (newSchema: FormSchema) => void;
84
- readonly locale?: string;
85
- readonly translator?: TranslationAdapter;
86
- readonly translationAdapter?: AsyncTranslationAdapter;
87
- readonly translationOptions?: PopulateTranslationOptions;
88
- readonly onTranslationReport?: (report: TranslationReport) => void;
89
- readonly policy?: FormPolicy;
90
- readonly idFactory?: (kind: "field" | "option" | "page", existingIds: ReadonlySet<string>) => string;
91
- readonly factories?: BuilderFactories;
87
+ interface BuilderActionContext {
88
+ readonly action: "addField" | "removeField" | "moveField" | "changeFieldType" | "updateField" | "addOption" | "removeOption" | "moveOption" | "updateOption" | "addPage" | "removePage" | "movePage" | "updatePage" | "assignFieldToPage" | "addLocale" | "setDefaultLocale" | "setDisplayCondition" | "setSourceText" | "setLocaleTranslation";
89
+ readonly targetId?: string;
90
+ readonly params?: Record<string, unknown>;
91
+ }
92
+ interface ManualTranslationContext {
93
+ readonly locale: string;
94
+ readonly kind: "form" | "page" | "field" | "option";
95
+ readonly nodeId: string;
96
+ readonly property: "title" | "description" | "label" | "completionMessage";
97
+ readonly sourceText: string;
98
+ readonly translatedText: string;
99
+ readonly existingTranslationMetadata?: Readonly<Record<string, JsonValue>>;
92
100
  }
93
- declare function FormBuilder({ schema, onChange, locale, translator, translationAdapter, translationOptions, onTranslationReport, policy, idFactory, factories }: FormBuilderProps): react.JSX.Element;
94
-
95
101
  type SubmitResult = {
96
102
  readonly status: "invalid";
97
103
  readonly issues: readonly ValidationError[];
@@ -144,6 +150,32 @@ interface FormRendererSlots {
144
150
  }
145
151
  type BeforeSubmit = (values: Readonly<Record<string, unknown>>) => "continue" | "cancel" | Promise<"continue" | "cancel">;
146
152
 
153
+ declare function resolveInitialFieldType(defaultType?: QuestionType, allowedTypes?: readonly QuestionType[]): QuestionType | null;
154
+ interface FormBuilderFeatures {
155
+ readonly pages?: boolean;
156
+ readonly localization?: boolean;
157
+ readonly conditions?: boolean;
158
+ }
159
+ interface FormBuilderProps {
160
+ readonly schema: FormSchema;
161
+ readonly onChange: (newSchema: FormSchema) => void;
162
+ readonly locale?: string;
163
+ readonly translator?: TranslationAdapter;
164
+ readonly translationAdapter?: AsyncTranslationAdapter;
165
+ readonly translationOptions?: PopulateTranslationOptions;
166
+ readonly onTranslationReport?: (report: TranslationReport) => void;
167
+ readonly policy?: FormPolicy;
168
+ readonly idFactory?: (kind: "field" | "option" | "page", existingIds: ReadonlySet<string>) => string;
169
+ readonly factories?: BuilderFactories;
170
+ readonly className?: string;
171
+ readonly defaultFieldType?: QuestionType;
172
+ readonly onActionError?: (error: BuilderActionError, context: BuilderActionContext) => void;
173
+ readonly createManualTranslationMetadata?: (context: ManualTranslationContext) => Readonly<Record<string, JsonValue>> | undefined;
174
+ readonly readOnly?: boolean;
175
+ readonly features?: FormBuilderFeatures;
176
+ }
177
+ declare function FormBuilder({ schema, onChange, locale, translator, translationAdapter, translationOptions, onTranslationReport, policy, idFactory, factories, className, defaultFieldType, onActionError, createManualTranslationMetadata, readOnly, features }: FormBuilderProps): react.JSX.Element;
178
+
147
179
  type SubmitStatus = "idle" | "submitting" | "success" | "error";
148
180
  interface FormContextValue {
149
181
  readonly schema: FormSchema;
@@ -214,4 +246,4 @@ interface StandaloneFormRendererProps extends FormRendererPresentationProps {
214
246
  type FormRendererProps = FormRendererPresentationProps | StandaloneFormRendererProps;
215
247
  declare function FormRenderer(props: FormRendererProps): react.JSX.Element;
216
248
 
217
- export { type BeforeSubmit, type BuilderActionError, type BuilderActionResult, type BuilderFactories, type BuilderIdKind, type BuilderPolicy, type BuilderTextTarget, type FieldComponentProps, type FieldComponents, type FieldState, FormBuilder, type FormBuilderOptions, type FormBuilderProps, type FormBuilderResult, type FormContextValue, FormProvider, type FormProviderProps, FormRenderer, type FormRendererPresentationProps, type FormRendererProps, type FormRendererSlots, type StandaloneFormRendererProps, type SubmitResult, type SubmitStatus, useField, useForm, useFormBuilder };
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 };