@form-engine-ts/react 2.6.0 → 2.8.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,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, ComponentType, MouseEvent } from 'react';
3
- import { QuestionType, FormField, ChoiceOption, FormPage, FormSchema, DisplayCondition, JsonValue, SchemaIssue, FormPolicy, FieldOption, TranslationReport, ValidationError, TranslationAdapter, AsyncTranslationAdapter, PopulateTranslationOptions, FormValue, ValidationIssue, FormValues, AnswerValidationResult, FieldType } from '@form-engine-ts/core';
3
+ import { QuestionType, FormField, ChoiceOption, FormPage, FormSchema, DisplayCondition, JsonValue, SchemaIssue, FormPolicy, FieldOption, TranslationReport, ValidationError, FormValues, TranslationAdapter, AsyncTranslationAdapter, PopulateTranslationOptions, FormValue, ValidationIssue, AnswerValidationResult, FieldType } from '@form-engine-ts/core';
4
+ import { SensitiveDataFinding } from '@form-engine-ts/privacy';
4
5
 
5
6
  /** @deprecated Import FormPolicy from @form-engine-ts/core instead. */
6
7
  type BuilderPolicy = FormPolicy;
@@ -84,6 +85,33 @@ interface FormBuilderResult {
84
85
  }
85
86
  declare function useFormBuilder({ schema, onChange, policy, idFactory, factories }: FormBuilderOptions): FormBuilderResult;
86
87
 
88
+ interface SubmissionReceipt {
89
+ readonly formId: string;
90
+ readonly formVersion: number;
91
+ readonly submissionId?: string;
92
+ readonly submittedAt: string;
93
+ }
94
+ interface SubmissionReceiptQuery {
95
+ readonly formId: string;
96
+ readonly formVersion: number;
97
+ }
98
+ interface SubmissionReceiptStore {
99
+ get(formId: string, formVersion: number): Promise<SubmissionReceipt | null>;
100
+ getBatch(queries: readonly SubmissionReceiptQuery[]): Promise<Map<string, SubmissionReceipt>>;
101
+ save(receipt: SubmissionReceipt): Promise<void>;
102
+ remove(formId: string, formVersion: number): Promise<void>;
103
+ }
104
+ interface UseSubmissionReceiptsResult {
105
+ readonly receipts: ReadonlyMap<string, SubmissionReceipt>;
106
+ readonly isLoading: boolean;
107
+ readonly error: Error | null;
108
+ }
109
+ declare function submissionReceiptQueryKey(formId: string, formVersion: number): string;
110
+ declare function createLocalStorageSubmissionReceiptStore(options?: {
111
+ readonly namespace?: string;
112
+ }): SubmissionReceiptStore;
113
+ declare function useSubmissionReceipts(store: SubmissionReceiptStore, queries: readonly SubmissionReceiptQuery[]): UseSubmissionReceiptsResult;
114
+
87
115
  interface ComponentBaseProps {
88
116
  readonly id?: string;
89
117
  readonly className?: string;
@@ -245,10 +273,37 @@ type SubmitResult = {
245
273
  readonly status: "cancelled";
246
274
  } | {
247
275
  readonly status: "success";
276
+ readonly response?: SubmitResponse;
248
277
  } | {
249
278
  readonly status: "error";
250
279
  readonly error: Error;
251
280
  };
281
+ interface SubmitResponse {
282
+ readonly submissionId?: string;
283
+ readonly submittedAt?: string;
284
+ }
285
+ type FormSubmitHandler = (answers: FormValues) => SubmitResponse | void | Promise<SubmitResponse | undefined> | Promise<void>;
286
+ type SubmissionGuardResult = {
287
+ readonly status: "allow";
288
+ } | {
289
+ readonly status: "confirm";
290
+ readonly findings: readonly SensitiveDataFinding[];
291
+ readonly message?: string;
292
+ } | {
293
+ readonly status: "block";
294
+ readonly findings: readonly SensitiveDataFinding[];
295
+ readonly message?: string;
296
+ };
297
+ type SubmissionGuard = (schema: FormSchema, values: Record<string, unknown>) => SubmissionGuardResult | Promise<SubmissionGuardResult>;
298
+ type FormSubmitState = "idle" | "submitting" | "confirming" | "success" | "error";
299
+ interface SubmissionConfirmationSlotProps {
300
+ readonly findings: readonly SensitiveDataFinding[];
301
+ readonly message?: string;
302
+ readonly schema: FormSchema;
303
+ readonly visibleValues: Record<string, unknown>;
304
+ readonly onConfirm: () => void;
305
+ readonly onCancel: () => void;
306
+ }
252
307
  interface FormRendererSlots {
253
308
  readonly renderHeader?: (props: {
254
309
  readonly title: string;
@@ -287,6 +342,20 @@ interface FormRendererSlots {
287
342
  readonly error: Error;
288
343
  readonly onRetry?: () => void;
289
344
  }) => ReactNode;
345
+ readonly renderSubmissionConfirmation?: (props: SubmissionConfirmationSlotProps) => ReactNode;
346
+ readonly renderAlreadySubmitted?: (props: {
347
+ readonly receipt: SubmissionReceipt;
348
+ readonly onReset?: () => void;
349
+ }) => ReactNode;
350
+ readonly renderCharacterCount?: (props: {
351
+ readonly fieldId: string;
352
+ readonly current: number;
353
+ readonly max: number;
354
+ }) => ReactNode;
355
+ }
356
+ interface SubmissionProtectionProps {
357
+ readonly submissionGuards?: readonly SubmissionGuard[];
358
+ readonly receiptStore?: SubmissionReceiptStore;
290
359
  }
291
360
  type BeforeSubmit = (values: Readonly<Record<string, unknown>>) => "continue" | "cancel" | Promise<"continue" | "cancel">;
292
361
 
@@ -343,7 +412,7 @@ interface FormProviderProps {
343
412
  readonly translator: TranslationAdapter;
344
413
  readonly initialValues?: FormValues;
345
414
  readonly resetOnSuccess?: boolean;
346
- readonly onSubmit: (values: FormValues) => void | Promise<void>;
415
+ readonly onSubmit: FormSubmitHandler;
347
416
  readonly children: ReactNode;
348
417
  }
349
418
  declare function FormProvider({ schema, locale, translator, initialValues, resetOnSuccess, onSubmit, children }: FormProviderProps): react.JSX.Element;
@@ -365,9 +434,10 @@ interface FieldComponentProps {
365
434
  readonly inputId: string;
366
435
  readonly errorId: string;
367
436
  readonly helpId: string;
437
+ readonly renderCharacterCount?: FormRendererSlots["renderCharacterCount"];
368
438
  }
369
439
  type FieldComponents = Partial<Record<FieldType, ComponentType<FieldComponentProps>>>;
370
- interface FormRendererPresentationProps {
440
+ interface FormRendererPresentationProps extends SubmissionProtectionProps {
371
441
  readonly components?: FieldComponents;
372
442
  readonly className?: string;
373
443
  readonly successMessageKey?: string;
@@ -383,9 +453,9 @@ interface StandaloneFormRendererProps extends FormRendererPresentationProps {
383
453
  readonly translator?: TranslationAdapter;
384
454
  readonly initialValues?: FormValues;
385
455
  readonly resetOnSuccess?: boolean;
386
- readonly onSubmit: (answers: FormValues) => Promise<void> | void;
456
+ readonly onSubmit: FormSubmitHandler;
387
457
  }
388
458
  type FormRendererProps = FormRendererPresentationProps | StandaloneFormRendererProps;
389
459
  declare function FormRenderer(props: FormRendererProps): react.JSX.Element;
390
460
 
391
- 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 InputComponentProps, type ManualTranslationContext, type StandaloneFormRendererProps, type SubmitResult, type SubmitStatus, resolveInitialFieldType, useField, useForm, useFormBuilder };
461
+ 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 FormSubmitHandler, type FormSubmitState, type InputComponentProps, type ManualTranslationContext, type StandaloneFormRendererProps, type SubmissionConfirmationSlotProps, type SubmissionGuard, type SubmissionGuardResult, type SubmissionProtectionProps, type SubmissionReceipt, type SubmissionReceiptQuery, type SubmissionReceiptStore, type SubmitResponse, type SubmitResult, type SubmitStatus, type UseSubmissionReceiptsResult, createLocalStorageSubmissionReceiptStore, resolveInitialFieldType, submissionReceiptQueryKey, useField, useForm, useFormBuilder, useSubmissionReceipts };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, ComponentType, MouseEvent } from 'react';
3
- import { QuestionType, FormField, ChoiceOption, FormPage, FormSchema, DisplayCondition, JsonValue, SchemaIssue, FormPolicy, FieldOption, TranslationReport, ValidationError, TranslationAdapter, AsyncTranslationAdapter, PopulateTranslationOptions, FormValue, ValidationIssue, FormValues, AnswerValidationResult, FieldType } from '@form-engine-ts/core';
3
+ import { QuestionType, FormField, ChoiceOption, FormPage, FormSchema, DisplayCondition, JsonValue, SchemaIssue, FormPolicy, FieldOption, TranslationReport, ValidationError, FormValues, TranslationAdapter, AsyncTranslationAdapter, PopulateTranslationOptions, FormValue, ValidationIssue, AnswerValidationResult, FieldType } from '@form-engine-ts/core';
4
+ import { SensitiveDataFinding } from '@form-engine-ts/privacy';
4
5
 
5
6
  /** @deprecated Import FormPolicy from @form-engine-ts/core instead. */
6
7
  type BuilderPolicy = FormPolicy;
@@ -84,6 +85,33 @@ interface FormBuilderResult {
84
85
  }
85
86
  declare function useFormBuilder({ schema, onChange, policy, idFactory, factories }: FormBuilderOptions): FormBuilderResult;
86
87
 
88
+ interface SubmissionReceipt {
89
+ readonly formId: string;
90
+ readonly formVersion: number;
91
+ readonly submissionId?: string;
92
+ readonly submittedAt: string;
93
+ }
94
+ interface SubmissionReceiptQuery {
95
+ readonly formId: string;
96
+ readonly formVersion: number;
97
+ }
98
+ interface SubmissionReceiptStore {
99
+ get(formId: string, formVersion: number): Promise<SubmissionReceipt | null>;
100
+ getBatch(queries: readonly SubmissionReceiptQuery[]): Promise<Map<string, SubmissionReceipt>>;
101
+ save(receipt: SubmissionReceipt): Promise<void>;
102
+ remove(formId: string, formVersion: number): Promise<void>;
103
+ }
104
+ interface UseSubmissionReceiptsResult {
105
+ readonly receipts: ReadonlyMap<string, SubmissionReceipt>;
106
+ readonly isLoading: boolean;
107
+ readonly error: Error | null;
108
+ }
109
+ declare function submissionReceiptQueryKey(formId: string, formVersion: number): string;
110
+ declare function createLocalStorageSubmissionReceiptStore(options?: {
111
+ readonly namespace?: string;
112
+ }): SubmissionReceiptStore;
113
+ declare function useSubmissionReceipts(store: SubmissionReceiptStore, queries: readonly SubmissionReceiptQuery[]): UseSubmissionReceiptsResult;
114
+
87
115
  interface ComponentBaseProps {
88
116
  readonly id?: string;
89
117
  readonly className?: string;
@@ -245,10 +273,37 @@ type SubmitResult = {
245
273
  readonly status: "cancelled";
246
274
  } | {
247
275
  readonly status: "success";
276
+ readonly response?: SubmitResponse;
248
277
  } | {
249
278
  readonly status: "error";
250
279
  readonly error: Error;
251
280
  };
281
+ interface SubmitResponse {
282
+ readonly submissionId?: string;
283
+ readonly submittedAt?: string;
284
+ }
285
+ type FormSubmitHandler = (answers: FormValues) => SubmitResponse | void | Promise<SubmitResponse | undefined> | Promise<void>;
286
+ type SubmissionGuardResult = {
287
+ readonly status: "allow";
288
+ } | {
289
+ readonly status: "confirm";
290
+ readonly findings: readonly SensitiveDataFinding[];
291
+ readonly message?: string;
292
+ } | {
293
+ readonly status: "block";
294
+ readonly findings: readonly SensitiveDataFinding[];
295
+ readonly message?: string;
296
+ };
297
+ type SubmissionGuard = (schema: FormSchema, values: Record<string, unknown>) => SubmissionGuardResult | Promise<SubmissionGuardResult>;
298
+ type FormSubmitState = "idle" | "submitting" | "confirming" | "success" | "error";
299
+ interface SubmissionConfirmationSlotProps {
300
+ readonly findings: readonly SensitiveDataFinding[];
301
+ readonly message?: string;
302
+ readonly schema: FormSchema;
303
+ readonly visibleValues: Record<string, unknown>;
304
+ readonly onConfirm: () => void;
305
+ readonly onCancel: () => void;
306
+ }
252
307
  interface FormRendererSlots {
253
308
  readonly renderHeader?: (props: {
254
309
  readonly title: string;
@@ -287,6 +342,20 @@ interface FormRendererSlots {
287
342
  readonly error: Error;
288
343
  readonly onRetry?: () => void;
289
344
  }) => ReactNode;
345
+ readonly renderSubmissionConfirmation?: (props: SubmissionConfirmationSlotProps) => ReactNode;
346
+ readonly renderAlreadySubmitted?: (props: {
347
+ readonly receipt: SubmissionReceipt;
348
+ readonly onReset?: () => void;
349
+ }) => ReactNode;
350
+ readonly renderCharacterCount?: (props: {
351
+ readonly fieldId: string;
352
+ readonly current: number;
353
+ readonly max: number;
354
+ }) => ReactNode;
355
+ }
356
+ interface SubmissionProtectionProps {
357
+ readonly submissionGuards?: readonly SubmissionGuard[];
358
+ readonly receiptStore?: SubmissionReceiptStore;
290
359
  }
291
360
  type BeforeSubmit = (values: Readonly<Record<string, unknown>>) => "continue" | "cancel" | Promise<"continue" | "cancel">;
292
361
 
@@ -343,7 +412,7 @@ interface FormProviderProps {
343
412
  readonly translator: TranslationAdapter;
344
413
  readonly initialValues?: FormValues;
345
414
  readonly resetOnSuccess?: boolean;
346
- readonly onSubmit: (values: FormValues) => void | Promise<void>;
415
+ readonly onSubmit: FormSubmitHandler;
347
416
  readonly children: ReactNode;
348
417
  }
349
418
  declare function FormProvider({ schema, locale, translator, initialValues, resetOnSuccess, onSubmit, children }: FormProviderProps): react.JSX.Element;
@@ -365,9 +434,10 @@ interface FieldComponentProps {
365
434
  readonly inputId: string;
366
435
  readonly errorId: string;
367
436
  readonly helpId: string;
437
+ readonly renderCharacterCount?: FormRendererSlots["renderCharacterCount"];
368
438
  }
369
439
  type FieldComponents = Partial<Record<FieldType, ComponentType<FieldComponentProps>>>;
370
- interface FormRendererPresentationProps {
440
+ interface FormRendererPresentationProps extends SubmissionProtectionProps {
371
441
  readonly components?: FieldComponents;
372
442
  readonly className?: string;
373
443
  readonly successMessageKey?: string;
@@ -383,9 +453,9 @@ interface StandaloneFormRendererProps extends FormRendererPresentationProps {
383
453
  readonly translator?: TranslationAdapter;
384
454
  readonly initialValues?: FormValues;
385
455
  readonly resetOnSuccess?: boolean;
386
- readonly onSubmit: (answers: FormValues) => Promise<void> | void;
456
+ readonly onSubmit: FormSubmitHandler;
387
457
  }
388
458
  type FormRendererProps = FormRendererPresentationProps | StandaloneFormRendererProps;
389
459
  declare function FormRenderer(props: FormRendererProps): react.JSX.Element;
390
460
 
391
- 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 InputComponentProps, type ManualTranslationContext, type StandaloneFormRendererProps, type SubmitResult, type SubmitStatus, resolveInitialFieldType, useField, useForm, useFormBuilder };
461
+ 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 FormSubmitHandler, type FormSubmitState, type InputComponentProps, type ManualTranslationContext, type StandaloneFormRendererProps, type SubmissionConfirmationSlotProps, type SubmissionGuard, type SubmissionGuardResult, type SubmissionProtectionProps, type SubmissionReceipt, type SubmissionReceiptQuery, type SubmissionReceiptStore, type SubmitResponse, type SubmitResult, type SubmitStatus, type UseSubmissionReceiptsResult, createLocalStorageSubmissionReceiptStore, resolveInitialFieldType, submissionReceiptQueryKey, useField, useForm, useFormBuilder, useSubmissionReceipts };