@form-engine-ts/react 2.7.0 → 2.9.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,8 +1,23 @@
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
4
  import { SensitiveDataFinding } from '@form-engine-ts/privacy';
5
5
 
6
+ interface SubmissionAttempt {
7
+ readonly attemptId: string;
8
+ readonly formId: string;
9
+ readonly formVersion: number;
10
+ readonly createdAt: string;
11
+ }
12
+ interface SubmissionAttemptStore {
13
+ getOrCreate(formId: string, formVersion: number, idFactory?: () => string): Promise<SubmissionAttempt>;
14
+ get(formId: string, formVersion: number): Promise<SubmissionAttempt | null>;
15
+ clear(formId: string, formVersion: number): Promise<void>;
16
+ }
17
+ declare function createLocalStorageSubmissionAttemptStore(options?: {
18
+ readonly namespace?: string;
19
+ }): SubmissionAttemptStore;
20
+
6
21
  /** @deprecated Import FormPolicy from @form-engine-ts/core instead. */
7
22
  type BuilderPolicy = FormPolicy;
8
23
  type BuilderIdKind = "field" | "option" | "page";
@@ -91,14 +106,26 @@ interface SubmissionReceipt {
91
106
  readonly submissionId?: string;
92
107
  readonly submittedAt: string;
93
108
  }
109
+ interface SubmissionReceiptQuery {
110
+ readonly formId: string;
111
+ readonly formVersion: number;
112
+ }
94
113
  interface SubmissionReceiptStore {
95
114
  get(formId: string, formVersion: number): Promise<SubmissionReceipt | null>;
115
+ getBatch?(queries: readonly SubmissionReceiptQuery[]): Promise<Map<string, SubmissionReceipt>>;
96
116
  save(receipt: SubmissionReceipt): Promise<void>;
97
117
  remove(formId: string, formVersion: number): Promise<void>;
98
118
  }
119
+ interface UseSubmissionReceiptsResult {
120
+ readonly receipts: ReadonlyMap<string, SubmissionReceipt>;
121
+ readonly isLoading: boolean;
122
+ readonly error: Error | null;
123
+ }
124
+ declare function submissionReceiptQueryKey(formId: string, formVersion: number): string;
99
125
  declare function createLocalStorageSubmissionReceiptStore(options?: {
100
126
  readonly namespace?: string;
101
127
  }): SubmissionReceiptStore;
128
+ declare function useSubmissionReceipts(store: SubmissionReceiptStore, queries: readonly SubmissionReceiptQuery[]): UseSubmissionReceiptsResult;
102
129
 
103
130
  interface ComponentBaseProps {
104
131
  readonly id?: string;
@@ -261,10 +288,16 @@ type SubmitResult = {
261
288
  readonly status: "cancelled";
262
289
  } | {
263
290
  readonly status: "success";
291
+ readonly response?: SubmitResponse;
264
292
  } | {
265
293
  readonly status: "error";
266
294
  readonly error: Error;
267
295
  };
296
+ interface SubmitResponse {
297
+ readonly submissionId?: string;
298
+ readonly submittedAt?: string;
299
+ }
300
+ type FormSubmitHandler = (answers: FormValues) => SubmitResponse | void | Promise<SubmitResponse | undefined> | Promise<void>;
268
301
  type SubmissionGuardResult = {
269
302
  readonly status: "allow";
270
303
  } | {
@@ -278,6 +311,14 @@ type SubmissionGuardResult = {
278
311
  };
279
312
  type SubmissionGuard = (schema: FormSchema, values: Record<string, unknown>) => SubmissionGuardResult | Promise<SubmissionGuardResult>;
280
313
  type FormSubmitState = "idle" | "submitting" | "confirming" | "success" | "error";
314
+ interface SubmissionConfirmationSlotProps {
315
+ readonly findings: readonly SensitiveDataFinding[];
316
+ readonly message?: string;
317
+ readonly schema: FormSchema;
318
+ readonly visibleValues: Record<string, unknown>;
319
+ readonly onConfirm: () => void;
320
+ readonly onCancel: () => void;
321
+ }
281
322
  interface FormRendererSlots {
282
323
  readonly renderHeader?: (props: {
283
324
  readonly title: string;
@@ -316,11 +357,7 @@ interface FormRendererSlots {
316
357
  readonly error: Error;
317
358
  readonly onRetry?: () => void;
318
359
  }) => ReactNode;
319
- readonly renderSubmissionConfirmation?: (props: {
320
- readonly findings: readonly SensitiveDataFinding[];
321
- readonly onConfirm: () => void;
322
- readonly onCancel: () => void;
323
- }) => ReactNode;
360
+ readonly renderSubmissionConfirmation?: (props: SubmissionConfirmationSlotProps) => ReactNode;
324
361
  readonly renderAlreadySubmitted?: (props: {
325
362
  readonly receipt: SubmissionReceipt;
326
363
  readonly onReset?: () => void;
@@ -334,6 +371,8 @@ interface FormRendererSlots {
334
371
  interface SubmissionProtectionProps {
335
372
  readonly submissionGuards?: readonly SubmissionGuard[];
336
373
  readonly receiptStore?: SubmissionReceiptStore;
374
+ readonly attemptStore?: SubmissionAttemptStore;
375
+ readonly onReceiptError?: (error: Error, receipt: SubmissionReceipt) => void;
337
376
  }
338
377
  type BeforeSubmit = (values: Readonly<Record<string, unknown>>) => "continue" | "cancel" | Promise<"continue" | "cancel">;
339
378
 
@@ -381,7 +420,7 @@ interface FormContextValue {
381
420
  readonly restoreValues: (values: FormValues) => void;
382
421
  readonly validatePage: (pageIndex: number) => AnswerValidationResult;
383
422
  readonly reset: () => void;
384
- readonly submit: (beforeSubmit?: BeforeSubmit) => Promise<SubmitResult>;
423
+ readonly submit: (beforeSubmit?: BeforeSubmit, prepareSubmission?: (values: FormValues) => FormValues | Promise<FormValues>) => Promise<SubmitResult>;
385
424
  readonly translate: (key: string, params?: Readonly<Record<string, string | number>>) => string;
386
425
  }
387
426
  interface FormProviderProps {
@@ -390,7 +429,7 @@ interface FormProviderProps {
390
429
  readonly translator: TranslationAdapter;
391
430
  readonly initialValues?: FormValues;
392
431
  readonly resetOnSuccess?: boolean;
393
- readonly onSubmit: (values: FormValues) => void | Promise<void>;
432
+ readonly onSubmit: FormSubmitHandler;
394
433
  readonly children: ReactNode;
395
434
  }
396
435
  declare function FormProvider({ schema, locale, translator, initialValues, resetOnSuccess, onSubmit, children }: FormProviderProps): react.JSX.Element;
@@ -431,9 +470,9 @@ interface StandaloneFormRendererProps extends FormRendererPresentationProps {
431
470
  readonly translator?: TranslationAdapter;
432
471
  readonly initialValues?: FormValues;
433
472
  readonly resetOnSuccess?: boolean;
434
- readonly onSubmit: (answers: FormValues) => Promise<void> | void;
473
+ readonly onSubmit: FormSubmitHandler;
435
474
  }
436
475
  type FormRendererProps = FormRendererPresentationProps | StandaloneFormRendererProps;
437
476
  declare function FormRenderer(props: FormRendererProps): react.JSX.Element;
438
477
 
439
- 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 FormSubmitState, type InputComponentProps, type ManualTranslationContext, type StandaloneFormRendererProps, type SubmissionGuard, type SubmissionGuardResult, type SubmissionProtectionProps, type SubmissionReceipt, type SubmissionReceiptStore, type SubmitResult, type SubmitStatus, createLocalStorageSubmissionReceiptStore, resolveInitialFieldType, useField, useForm, useFormBuilder };
478
+ 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 SubmissionAttempt, type SubmissionAttemptStore, type SubmissionConfirmationSlotProps, type SubmissionGuard, type SubmissionGuardResult, type SubmissionProtectionProps, type SubmissionReceipt, type SubmissionReceiptQuery, type SubmissionReceiptStore, type SubmitResponse, type SubmitResult, type SubmitStatus, type UseSubmissionReceiptsResult, createLocalStorageSubmissionAttemptStore, createLocalStorageSubmissionReceiptStore, resolveInitialFieldType, submissionReceiptQueryKey, useField, useForm, useFormBuilder, useSubmissionReceipts };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,23 @@
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
4
  import { SensitiveDataFinding } from '@form-engine-ts/privacy';
5
5
 
6
+ interface SubmissionAttempt {
7
+ readonly attemptId: string;
8
+ readonly formId: string;
9
+ readonly formVersion: number;
10
+ readonly createdAt: string;
11
+ }
12
+ interface SubmissionAttemptStore {
13
+ getOrCreate(formId: string, formVersion: number, idFactory?: () => string): Promise<SubmissionAttempt>;
14
+ get(formId: string, formVersion: number): Promise<SubmissionAttempt | null>;
15
+ clear(formId: string, formVersion: number): Promise<void>;
16
+ }
17
+ declare function createLocalStorageSubmissionAttemptStore(options?: {
18
+ readonly namespace?: string;
19
+ }): SubmissionAttemptStore;
20
+
6
21
  /** @deprecated Import FormPolicy from @form-engine-ts/core instead. */
7
22
  type BuilderPolicy = FormPolicy;
8
23
  type BuilderIdKind = "field" | "option" | "page";
@@ -91,14 +106,26 @@ interface SubmissionReceipt {
91
106
  readonly submissionId?: string;
92
107
  readonly submittedAt: string;
93
108
  }
109
+ interface SubmissionReceiptQuery {
110
+ readonly formId: string;
111
+ readonly formVersion: number;
112
+ }
94
113
  interface SubmissionReceiptStore {
95
114
  get(formId: string, formVersion: number): Promise<SubmissionReceipt | null>;
115
+ getBatch?(queries: readonly SubmissionReceiptQuery[]): Promise<Map<string, SubmissionReceipt>>;
96
116
  save(receipt: SubmissionReceipt): Promise<void>;
97
117
  remove(formId: string, formVersion: number): Promise<void>;
98
118
  }
119
+ interface UseSubmissionReceiptsResult {
120
+ readonly receipts: ReadonlyMap<string, SubmissionReceipt>;
121
+ readonly isLoading: boolean;
122
+ readonly error: Error | null;
123
+ }
124
+ declare function submissionReceiptQueryKey(formId: string, formVersion: number): string;
99
125
  declare function createLocalStorageSubmissionReceiptStore(options?: {
100
126
  readonly namespace?: string;
101
127
  }): SubmissionReceiptStore;
128
+ declare function useSubmissionReceipts(store: SubmissionReceiptStore, queries: readonly SubmissionReceiptQuery[]): UseSubmissionReceiptsResult;
102
129
 
103
130
  interface ComponentBaseProps {
104
131
  readonly id?: string;
@@ -261,10 +288,16 @@ type SubmitResult = {
261
288
  readonly status: "cancelled";
262
289
  } | {
263
290
  readonly status: "success";
291
+ readonly response?: SubmitResponse;
264
292
  } | {
265
293
  readonly status: "error";
266
294
  readonly error: Error;
267
295
  };
296
+ interface SubmitResponse {
297
+ readonly submissionId?: string;
298
+ readonly submittedAt?: string;
299
+ }
300
+ type FormSubmitHandler = (answers: FormValues) => SubmitResponse | void | Promise<SubmitResponse | undefined> | Promise<void>;
268
301
  type SubmissionGuardResult = {
269
302
  readonly status: "allow";
270
303
  } | {
@@ -278,6 +311,14 @@ type SubmissionGuardResult = {
278
311
  };
279
312
  type SubmissionGuard = (schema: FormSchema, values: Record<string, unknown>) => SubmissionGuardResult | Promise<SubmissionGuardResult>;
280
313
  type FormSubmitState = "idle" | "submitting" | "confirming" | "success" | "error";
314
+ interface SubmissionConfirmationSlotProps {
315
+ readonly findings: readonly SensitiveDataFinding[];
316
+ readonly message?: string;
317
+ readonly schema: FormSchema;
318
+ readonly visibleValues: Record<string, unknown>;
319
+ readonly onConfirm: () => void;
320
+ readonly onCancel: () => void;
321
+ }
281
322
  interface FormRendererSlots {
282
323
  readonly renderHeader?: (props: {
283
324
  readonly title: string;
@@ -316,11 +357,7 @@ interface FormRendererSlots {
316
357
  readonly error: Error;
317
358
  readonly onRetry?: () => void;
318
359
  }) => ReactNode;
319
- readonly renderSubmissionConfirmation?: (props: {
320
- readonly findings: readonly SensitiveDataFinding[];
321
- readonly onConfirm: () => void;
322
- readonly onCancel: () => void;
323
- }) => ReactNode;
360
+ readonly renderSubmissionConfirmation?: (props: SubmissionConfirmationSlotProps) => ReactNode;
324
361
  readonly renderAlreadySubmitted?: (props: {
325
362
  readonly receipt: SubmissionReceipt;
326
363
  readonly onReset?: () => void;
@@ -334,6 +371,8 @@ interface FormRendererSlots {
334
371
  interface SubmissionProtectionProps {
335
372
  readonly submissionGuards?: readonly SubmissionGuard[];
336
373
  readonly receiptStore?: SubmissionReceiptStore;
374
+ readonly attemptStore?: SubmissionAttemptStore;
375
+ readonly onReceiptError?: (error: Error, receipt: SubmissionReceipt) => void;
337
376
  }
338
377
  type BeforeSubmit = (values: Readonly<Record<string, unknown>>) => "continue" | "cancel" | Promise<"continue" | "cancel">;
339
378
 
@@ -381,7 +420,7 @@ interface FormContextValue {
381
420
  readonly restoreValues: (values: FormValues) => void;
382
421
  readonly validatePage: (pageIndex: number) => AnswerValidationResult;
383
422
  readonly reset: () => void;
384
- readonly submit: (beforeSubmit?: BeforeSubmit) => Promise<SubmitResult>;
423
+ readonly submit: (beforeSubmit?: BeforeSubmit, prepareSubmission?: (values: FormValues) => FormValues | Promise<FormValues>) => Promise<SubmitResult>;
385
424
  readonly translate: (key: string, params?: Readonly<Record<string, string | number>>) => string;
386
425
  }
387
426
  interface FormProviderProps {
@@ -390,7 +429,7 @@ interface FormProviderProps {
390
429
  readonly translator: TranslationAdapter;
391
430
  readonly initialValues?: FormValues;
392
431
  readonly resetOnSuccess?: boolean;
393
- readonly onSubmit: (values: FormValues) => void | Promise<void>;
432
+ readonly onSubmit: FormSubmitHandler;
394
433
  readonly children: ReactNode;
395
434
  }
396
435
  declare function FormProvider({ schema, locale, translator, initialValues, resetOnSuccess, onSubmit, children }: FormProviderProps): react.JSX.Element;
@@ -431,9 +470,9 @@ interface StandaloneFormRendererProps extends FormRendererPresentationProps {
431
470
  readonly translator?: TranslationAdapter;
432
471
  readonly initialValues?: FormValues;
433
472
  readonly resetOnSuccess?: boolean;
434
- readonly onSubmit: (answers: FormValues) => Promise<void> | void;
473
+ readonly onSubmit: FormSubmitHandler;
435
474
  }
436
475
  type FormRendererProps = FormRendererPresentationProps | StandaloneFormRendererProps;
437
476
  declare function FormRenderer(props: FormRendererProps): react.JSX.Element;
438
477
 
439
- 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 FormSubmitState, type InputComponentProps, type ManualTranslationContext, type StandaloneFormRendererProps, type SubmissionGuard, type SubmissionGuardResult, type SubmissionProtectionProps, type SubmissionReceipt, type SubmissionReceiptStore, type SubmitResult, type SubmitStatus, createLocalStorageSubmissionReceiptStore, resolveInitialFieldType, useField, useForm, useFormBuilder };
478
+ 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 SubmissionAttempt, type SubmissionAttemptStore, type SubmissionConfirmationSlotProps, type SubmissionGuard, type SubmissionGuardResult, type SubmissionProtectionProps, type SubmissionReceipt, type SubmissionReceiptQuery, type SubmissionReceiptStore, type SubmitResponse, type SubmitResult, type SubmitStatus, type UseSubmissionReceiptsResult, createLocalStorageSubmissionAttemptStore, createLocalStorageSubmissionReceiptStore, resolveInitialFieldType, submissionReceiptQueryKey, useField, useForm, useFormBuilder, useSubmissionReceipts };