@form-engine-ts/react 2.1.0 → 2.1.1

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;
@@ -70,7 +70,7 @@ interface FormBuilderResult {
70
70
  readonly setDisplayCondition: (fieldId: string, condition?: DisplayCondition) => BuilderActionResult;
71
71
  readonly setSourceText: (target: BuilderTextTarget, property: string, text: string) => BuilderActionResult;
72
72
  readonly setLocaleTranslation: (locale: string, target: BuilderTextTarget, property: string, text: string, options?: {
73
- readonly metadata?: Record<string, JsonValue>;
73
+ readonly metadata?: Readonly<Record<string, JsonValue>>;
74
74
  }) => BuilderActionResult;
75
75
  readonly addLocale: (locale: string) => BuilderActionResult;
76
76
  readonly setDefaultLocale: (locale: string) => BuilderActionResult;
@@ -78,20 +78,20 @@ interface FormBuilderResult {
78
78
  }
79
79
  declare function useFormBuilder({ schema, onChange, policy, idFactory, factories }: FormBuilderOptions): FormBuilderResult;
80
80
 
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;
81
+ interface BuilderActionContext {
82
+ readonly action: "addField" | "removeField" | "moveField" | "changeFieldType" | "updateField" | "addOption" | "removeOption" | "moveOption" | "updateOption" | "addPage" | "removePage" | "movePage" | "assignFieldToPage" | "setDisplayCondition" | "setSourceText" | "setLocaleTranslation";
83
+ readonly targetId?: string;
84
+ readonly params?: Record<string, unknown>;
85
+ }
86
+ interface ManualTranslationContext {
87
+ readonly locale: string;
88
+ readonly kind: "form" | "page" | "field" | "option";
89
+ readonly nodeId: string;
90
+ readonly property: "title" | "description" | "label" | "completionMessage";
91
+ readonly sourceText: string;
92
+ readonly translatedText: string;
93
+ readonly existingTranslationMetadata?: Readonly<Record<string, JsonValue>>;
92
94
  }
93
- declare function FormBuilder({ schema, onChange, locale, translator, translationAdapter, translationOptions, onTranslationReport, policy, idFactory, factories }: FormBuilderProps): react.JSX.Element;
94
-
95
95
  type SubmitResult = {
96
96
  readonly status: "invalid";
97
97
  readonly issues: readonly ValidationError[];
@@ -144,6 +144,25 @@ interface FormRendererSlots {
144
144
  }
145
145
  type BeforeSubmit = (values: Readonly<Record<string, unknown>>) => "continue" | "cancel" | Promise<"continue" | "cancel">;
146
146
 
147
+ declare function resolveInitialFieldType(defaultType?: QuestionType, allowedTypes?: readonly QuestionType[]): QuestionType | null;
148
+ interface FormBuilderProps {
149
+ readonly schema: FormSchema;
150
+ readonly onChange: (newSchema: FormSchema) => void;
151
+ readonly locale?: string;
152
+ readonly translator?: TranslationAdapter;
153
+ readonly translationAdapter?: AsyncTranslationAdapter;
154
+ readonly translationOptions?: PopulateTranslationOptions;
155
+ readonly onTranslationReport?: (report: TranslationReport) => void;
156
+ readonly policy?: FormPolicy;
157
+ readonly idFactory?: (kind: "field" | "option" | "page", existingIds: ReadonlySet<string>) => string;
158
+ readonly factories?: BuilderFactories;
159
+ readonly className?: string;
160
+ readonly defaultFieldType?: QuestionType;
161
+ readonly onActionError?: (error: BuilderActionError, context: BuilderActionContext) => void;
162
+ readonly createManualTranslationMetadata?: (context: ManualTranslationContext) => Readonly<Record<string, JsonValue>> | undefined;
163
+ }
164
+ declare function FormBuilder({ schema, onChange, locale, translator, translationAdapter, translationOptions, onTranslationReport, policy, idFactory, factories, className, defaultFieldType, onActionError, createManualTranslationMetadata }: FormBuilderProps): react.JSX.Element;
165
+
147
166
  type SubmitStatus = "idle" | "submitting" | "success" | "error";
148
167
  interface FormContextValue {
149
168
  readonly schema: FormSchema;
@@ -214,4 +233,4 @@ interface StandaloneFormRendererProps extends FormRendererPresentationProps {
214
233
  type FormRendererProps = FormRendererPresentationProps | StandaloneFormRendererProps;
215
234
  declare function FormRenderer(props: FormRendererProps): react.JSX.Element;
216
235
 
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 };
236
+ 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 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;
@@ -70,7 +70,7 @@ interface FormBuilderResult {
70
70
  readonly setDisplayCondition: (fieldId: string, condition?: DisplayCondition) => BuilderActionResult;
71
71
  readonly setSourceText: (target: BuilderTextTarget, property: string, text: string) => BuilderActionResult;
72
72
  readonly setLocaleTranslation: (locale: string, target: BuilderTextTarget, property: string, text: string, options?: {
73
- readonly metadata?: Record<string, JsonValue>;
73
+ readonly metadata?: Readonly<Record<string, JsonValue>>;
74
74
  }) => BuilderActionResult;
75
75
  readonly addLocale: (locale: string) => BuilderActionResult;
76
76
  readonly setDefaultLocale: (locale: string) => BuilderActionResult;
@@ -78,20 +78,20 @@ interface FormBuilderResult {
78
78
  }
79
79
  declare function useFormBuilder({ schema, onChange, policy, idFactory, factories }: FormBuilderOptions): FormBuilderResult;
80
80
 
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;
81
+ interface BuilderActionContext {
82
+ readonly action: "addField" | "removeField" | "moveField" | "changeFieldType" | "updateField" | "addOption" | "removeOption" | "moveOption" | "updateOption" | "addPage" | "removePage" | "movePage" | "assignFieldToPage" | "setDisplayCondition" | "setSourceText" | "setLocaleTranslation";
83
+ readonly targetId?: string;
84
+ readonly params?: Record<string, unknown>;
85
+ }
86
+ interface ManualTranslationContext {
87
+ readonly locale: string;
88
+ readonly kind: "form" | "page" | "field" | "option";
89
+ readonly nodeId: string;
90
+ readonly property: "title" | "description" | "label" | "completionMessage";
91
+ readonly sourceText: string;
92
+ readonly translatedText: string;
93
+ readonly existingTranslationMetadata?: Readonly<Record<string, JsonValue>>;
92
94
  }
93
- declare function FormBuilder({ schema, onChange, locale, translator, translationAdapter, translationOptions, onTranslationReport, policy, idFactory, factories }: FormBuilderProps): react.JSX.Element;
94
-
95
95
  type SubmitResult = {
96
96
  readonly status: "invalid";
97
97
  readonly issues: readonly ValidationError[];
@@ -144,6 +144,25 @@ interface FormRendererSlots {
144
144
  }
145
145
  type BeforeSubmit = (values: Readonly<Record<string, unknown>>) => "continue" | "cancel" | Promise<"continue" | "cancel">;
146
146
 
147
+ declare function resolveInitialFieldType(defaultType?: QuestionType, allowedTypes?: readonly QuestionType[]): QuestionType | null;
148
+ interface FormBuilderProps {
149
+ readonly schema: FormSchema;
150
+ readonly onChange: (newSchema: FormSchema) => void;
151
+ readonly locale?: string;
152
+ readonly translator?: TranslationAdapter;
153
+ readonly translationAdapter?: AsyncTranslationAdapter;
154
+ readonly translationOptions?: PopulateTranslationOptions;
155
+ readonly onTranslationReport?: (report: TranslationReport) => void;
156
+ readonly policy?: FormPolicy;
157
+ readonly idFactory?: (kind: "field" | "option" | "page", existingIds: ReadonlySet<string>) => string;
158
+ readonly factories?: BuilderFactories;
159
+ readonly className?: string;
160
+ readonly defaultFieldType?: QuestionType;
161
+ readonly onActionError?: (error: BuilderActionError, context: BuilderActionContext) => void;
162
+ readonly createManualTranslationMetadata?: (context: ManualTranslationContext) => Readonly<Record<string, JsonValue>> | undefined;
163
+ }
164
+ declare function FormBuilder({ schema, onChange, locale, translator, translationAdapter, translationOptions, onTranslationReport, policy, idFactory, factories, className, defaultFieldType, onActionError, createManualTranslationMetadata }: FormBuilderProps): react.JSX.Element;
165
+
147
166
  type SubmitStatus = "idle" | "submitting" | "success" | "error";
148
167
  interface FormContextValue {
149
168
  readonly schema: FormSchema;
@@ -214,4 +233,4 @@ interface StandaloneFormRendererProps extends FormRendererPresentationProps {
214
233
  type FormRendererProps = FormRendererPresentationProps | StandaloneFormRendererProps;
215
234
  declare function FormRenderer(props: FormRendererProps): react.JSX.Element;
216
235
 
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 };
236
+ 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 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 };