@form-engine-ts/react 6.1.0 → 6.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.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _form_engine_ts_core from '@form-engine-ts/core';
2
- import { QuestionType, FormField, ChoiceOption, FormPage, FormSchema, DisplayCondition, JsonValue, SchemaIssue, FormPolicy, Question, FieldOption, TranslationReport, ValidationIssue, ValidationError, FormValues, LocaleOption, TranslationStatus, CanonicalTranslationMetadata, TranslationSlot, TranslationAdapter, AsyncTranslationAdapter, PopulateTranslationOptions, FormValue, AnswerValidationResult, FormEngineTranslator, FormEngineMessages, TranslationMissingKeyEvent, FieldType } from '@form-engine-ts/core';
2
+ import { QuestionType, FormField, ChoiceOption, FormPage, FormSchema, DisplayCondition, JsonValue, SchemaIssue, FormPolicy, TranslationAdapter, AsyncTranslationAdapter, LocaleOption, TranslationReport, TranslationSlot, PopulateTranslationOptions, TranslationProgress, Question, FieldOption, ValidationIssue, ValidationError, FormValues, TranslationStatus, CanonicalTranslationMetadata, FormValue, AnswerValidationResult, FormEngineTranslator, FormEngineMessages, TranslationMissingKeyEvent, FieldType } from '@form-engine-ts/core';
3
3
  export { FormSubmissionError, FormSubmissionSerializedError, QuestionType } from '@form-engine-ts/core';
4
4
  import * as react from 'react';
5
5
  import { ReactNode, ComponentType, KeyboardEvent, MouseEvent, CSSProperties } from 'react';
@@ -125,6 +125,135 @@ interface UseFormBuilderResult extends FormBuilderResult {
125
125
  }
126
126
  declare function useFormBuilder({ schema, onChange, policy, idFactory, factories, fieldEditorMode, activeFieldId: controlledActiveFieldId, defaultActiveFieldId, onActiveFieldChange }: FormBuilderOptions): FormBuilderResult;
127
127
 
128
+ interface UseTranslationWorkspaceOptions {
129
+ readonly schema: FormSchema;
130
+ readonly onChange?: (schema: FormSchema) => void;
131
+ readonly sourceLocale?: string;
132
+ readonly targetLocale?: string;
133
+ readonly translationAdapter?: TranslationAdapter | AsyncTranslationAdapter;
134
+ readonly signal?: AbortSignal;
135
+ readonly readOnly?: boolean;
136
+ readonly policy?: FormPolicy;
137
+ readonly availableLocales?: readonly (string | LocaleOption)[];
138
+ readonly onLocaleAdded?: (locale: string) => void;
139
+ readonly onLocaleRemoved?: (locale: string) => void;
140
+ readonly onLocaleChange?: (targetLocale: string) => void;
141
+ readonly beforeRemoveLocale?: (locale: string, context: {
142
+ readonly slotCount: number;
143
+ }) => Promise<boolean> | boolean;
144
+ readonly confirmRemoveLocale?: (props: ConfirmRemoveLocaleSlotProps) => ReactNode;
145
+ readonly slots?: Pick<TranslationWorkspaceSlots, "confirmRemoveLocale">;
146
+ readonly onTranslationStart?: (params: {
147
+ readonly targetLocale: string;
148
+ readonly mode: "manual" | "automatic";
149
+ }) => void;
150
+ readonly onTranslationSuccess?: (payload: TranslationEventPayload) => void;
151
+ readonly onTranslationReport?: (report: TranslationReport) => void;
152
+ readonly onTranslationError?: (params: {
153
+ readonly targetLocale: string;
154
+ readonly error: TranslationWorkspaceError;
155
+ }) => void;
156
+ readonly onTranslationChange?: (event: TranslationSlotChangeEvent) => void;
157
+ readonly createTranslationMetadata?: (params: {
158
+ readonly slot: TranslationSlot;
159
+ readonly translatedText: string;
160
+ readonly mode: "manual" | "automatic";
161
+ }) => Readonly<Record<string, _form_engine_ts_core.JsonValue>>;
162
+ readonly validateLocale?: ((locale: string, currentLocales: readonly string[]) => LocaleValidationResult) | CustomLocaleValidator;
163
+ }
164
+ interface LocaleValidationContext {
165
+ readonly locale: string;
166
+ readonly defaultLocale: string;
167
+ readonly currentLocales: readonly string[];
168
+ readonly policy?: FormPolicy;
169
+ }
170
+ type CustomLocaleValidator = (locale: string, context: LocaleValidationContext) => LocaleValidationResult | boolean | string | undefined | void;
171
+ interface LocaleValidationResult {
172
+ readonly valid: boolean;
173
+ readonly error?: {
174
+ readonly type: "locale_not_allowed" | "max_locales_exceeded" | "invalid_locale_format" | "locale_already_exists" | "source_locale" | "custom_validation_failed";
175
+ readonly message: string;
176
+ };
177
+ }
178
+ interface TranslationSummary {
179
+ readonly totalSlots: number;
180
+ readonly translatedCount: number;
181
+ readonly missingCount: number;
182
+ readonly staleCount: number;
183
+ readonly manualCount: number;
184
+ readonly completionPercentage: number;
185
+ }
186
+ type TranslationWorkspaceError = {
187
+ readonly type: "locale_not_allowed";
188
+ readonly locale: string;
189
+ } | {
190
+ readonly type: "locale_already_exists";
191
+ readonly locale: string;
192
+ } | {
193
+ readonly type: "source_locale";
194
+ readonly locale: string;
195
+ } | {
196
+ readonly type: "invalid_locale_format";
197
+ readonly locale: string;
198
+ } | {
199
+ readonly type: "max_locales_exceeded";
200
+ readonly max: number;
201
+ readonly current: number;
202
+ } | {
203
+ readonly type: "read_only_mode";
204
+ } | {
205
+ readonly type: "adapter_not_configured";
206
+ } | {
207
+ readonly type: "target_locale_missing";
208
+ } | {
209
+ readonly type: "translation_failed";
210
+ readonly message: string;
211
+ readonly cause?: unknown;
212
+ } | {
213
+ readonly type: "partial_failure";
214
+ readonly succeeded: number;
215
+ readonly failed: number;
216
+ } | {
217
+ readonly type: "cancelled";
218
+ } | {
219
+ readonly type: "custom_validation_failed";
220
+ readonly message: string;
221
+ };
222
+ interface UseTranslationWorkspaceResult {
223
+ readonly sourceLocale: string;
224
+ readonly targetLocale: string;
225
+ readonly targetLocales: readonly string[];
226
+ readonly localeOptions: readonly LocaleOption[];
227
+ readonly setTargetLocale: (locale: string) => void;
228
+ readonly slots: readonly TranslationSlot[];
229
+ readonly summary: TranslationSummary;
230
+ readonly addLocale: (locale: string) => {
231
+ readonly success: boolean;
232
+ readonly error?: TranslationWorkspaceError;
233
+ };
234
+ readonly isAddLocaleAllowed: (locale: string) => boolean;
235
+ readonly removeLocale: (locale: string) => boolean | Promise<boolean>;
236
+ readonly removeLocaleConfirmation?: ReactNode;
237
+ readonly setTranslation: (slot: TranslationSlot, text: string) => void;
238
+ readonly translateAll: (options?: PopulateTranslationOptions) => Promise<{
239
+ readonly success: boolean;
240
+ readonly report?: TranslationReport;
241
+ readonly error?: TranslationWorkspaceError;
242
+ }>;
243
+ readonly translateSlot: (slot: TranslationSlot, options?: {
244
+ readonly signal?: AbortSignal;
245
+ }) => Promise<{
246
+ readonly success: boolean;
247
+ readonly error?: TranslationWorkspaceError;
248
+ }>;
249
+ readonly cancelTranslation: () => void;
250
+ readonly isTranslating: boolean;
251
+ readonly progress?: TranslationProgress;
252
+ readonly error?: TranslationWorkspaceError;
253
+ }
254
+ declare const validateLocalePipeline: (locale: string, schema: FormSchema, policy?: FormPolicy, customValidator?: ((locale: string, currentLocales: readonly string[]) => LocaleValidationResult) | CustomLocaleValidator, availableLocales?: readonly (string | LocaleOption)[], sourceLocale?: string) => LocaleValidationResult;
255
+ declare function useTranslationWorkspace({ schema, onChange, sourceLocale, targetLocale, translationAdapter, signal, readOnly, policy, availableLocales, onLocaleAdded, onLocaleRemoved, onLocaleChange, beforeRemoveLocale, confirmRemoveLocale, slots: workspaceSlots, onTranslationStart, onTranslationSuccess, onTranslationReport, onTranslationError, onTranslationChange, validateLocale, createTranslationMetadata: metadataFactory }: UseTranslationWorkspaceOptions): UseTranslationWorkspaceResult;
256
+
128
257
  interface SubmissionReceipt {
129
258
  readonly formId: string;
130
259
  readonly formVersion: number;
@@ -396,6 +525,8 @@ interface TranslationWorkspaceHeaderProps {
396
525
  readonly onTranslateAll: () => void;
397
526
  readonly isTranslating: boolean;
398
527
  readonly readOnly: boolean;
528
+ readonly progress?: TranslationProgress;
529
+ readonly onCancel?: () => void;
399
530
  }
400
531
  interface TranslationSlotRowProps {
401
532
  readonly slot: _form_engine_ts_core.TranslationSlot;
@@ -406,6 +537,7 @@ interface TranslationSlotRowProps {
406
537
  interface TranslationComparisonItem {
407
538
  readonly id: string;
408
539
  readonly path: string;
540
+ readonly nodeId?: string;
409
541
  readonly targetKind: "form" | "page" | "field" | "option";
410
542
  readonly targetProperty: "title" | "description" | "label" | "completionMessage";
411
543
  readonly nodeTitle?: string;
@@ -429,31 +561,73 @@ interface TranslationComparisonHeaderProps {
429
561
  readonly onTranslateAll: () => void;
430
562
  readonly isTranslating: boolean;
431
563
  readonly readOnly: boolean;
564
+ readonly report?: TranslationReport;
565
+ readonly progress?: TranslationProgress;
566
+ readonly onCancel?: () => void;
432
567
  }
433
568
  interface TranslationComparisonItemRowProps {
434
569
  readonly item: TranslationComparisonItem;
570
+ readonly nodeKind?: "form" | "page" | "field" | "option";
571
+ readonly questionIndex?: number;
572
+ readonly fieldType?: string;
573
+ readonly optionIndex?: number;
574
+ readonly sourceLocaleLabel?: string;
575
+ readonly targetLocaleLabel?: string;
435
576
  readonly readOnly: boolean;
436
577
  readonly onChange: (text: string) => void;
437
- readonly onTranslate: () => void;
578
+ readonly onTranslate: () => Promise<void>;
438
579
  }
439
580
  interface UseTranslationComparisonOptions {
440
581
  readonly schema: FormSchema;
441
582
  readonly sourceLocale?: string;
442
583
  readonly targetLocale: string;
443
- readonly translationAdapter?: TranslationAdapter;
584
+ readonly availableLocales?: readonly (string | LocaleOption)[];
585
+ readonly policy?: FormPolicy;
586
+ readonly translationAdapter?: TranslationAdapter | AsyncTranslationAdapter;
587
+ readonly signal?: AbortSignal;
444
588
  readonly readOnly?: boolean;
445
589
  readonly onChange?: (nextSchema: FormSchema) => void;
446
590
  readonly onTranslationChange?: (event: TranslationSlotChangeEvent) => void;
591
+ readonly onTranslationReport?: (report: TranslationReport) => void;
592
+ readonly onTranslationError?: (params: {
593
+ readonly targetLocale: string;
594
+ readonly error: TranslationWorkspaceError;
595
+ }) => void;
596
+ readonly onLocaleAdded?: (locale: string) => void;
597
+ readonly onLocaleRemoved?: (locale: string) => void;
598
+ readonly onLocaleChange?: (locale: string) => void;
599
+ readonly beforeRemoveLocale?: (locale: string, context: {
600
+ readonly slotCount: number;
601
+ }) => Promise<boolean> | boolean;
602
+ readonly confirmRemoveLocale?: (props: ConfirmRemoveLocaleSlotProps) => ReactNode;
603
+ readonly onTranslationStart?: (params: {
604
+ readonly targetLocale: string;
605
+ readonly mode: "manual" | "automatic";
606
+ }) => void;
607
+ readonly onTranslationSuccess?: (payload: TranslationEventPayload) => void;
608
+ readonly validateLocale?: UseTranslationWorkspaceOptions["validateLocale"];
609
+ readonly createTranslationMetadata?: UseTranslationWorkspaceOptions["createTranslationMetadata"];
447
610
  }
448
611
  interface UseTranslationComparisonResult {
449
612
  readonly sourceLocale: string;
450
613
  readonly targetLocale: string;
614
+ readonly targetLocales: readonly string[];
615
+ readonly localeOptions: readonly LocaleOption[];
616
+ readonly setTargetLocale: (locale: string) => void;
617
+ readonly addLocale: UseTranslationWorkspaceResult["addLocale"];
618
+ readonly isAddLocaleAllowed: UseTranslationWorkspaceResult["isAddLocaleAllowed"];
619
+ readonly removeLocale: UseTranslationWorkspaceResult["removeLocale"];
620
+ readonly removeLocaleConfirmation?: ReactNode;
451
621
  readonly items: readonly TranslationComparisonItem[];
452
622
  readonly summary: TranslationComparisonSummary;
453
623
  readonly isTranslating: boolean;
454
624
  readonly updateTranslation: (path: string, text: string) => void;
455
625
  readonly translateSingle: (path: string) => Promise<void>;
456
- readonly translateAll: () => Promise<TranslationReport>;
626
+ readonly translateAll: (options?: PopulateTranslationOptions) => Promise<TranslationReport>;
627
+ readonly cancelTranslation: () => void;
628
+ readonly progress?: TranslationProgress;
629
+ readonly error?: TranslationWorkspaceError;
630
+ readonly report?: TranslationReport;
457
631
  }
458
632
  interface LocaleSelectorProps {
459
633
  readonly targetLocale: string;
@@ -496,6 +670,7 @@ interface ConfirmRemoveLocaleSlotProps {
496
670
  interface TranslationWorkspaceSlots {
497
671
  readonly renderHeader?: (props: TranslationWorkspaceHeaderProps) => ReactNode;
498
672
  readonly renderSlotRow?: (props: TranslationSlotRowProps) => ReactNode;
673
+ readonly renderItemRow?: (props: TranslationComparisonItemRowProps) => ReactNode;
499
674
  readonly renderLocaleSelector?: (props: LocaleSelectorProps) => ReactNode;
500
675
  readonly renderStatusBadge?: (props: {
501
676
  readonly status: _form_engine_ts_core.TranslationStatus;
@@ -820,116 +995,7 @@ interface FieldState {
820
995
  }
821
996
  declare function useField(fieldId: string): FieldState;
822
997
 
823
- declare function useTranslationComparison({ schema, sourceLocale, targetLocale, translationAdapter, readOnly, onChange, onTranslationChange }: UseTranslationComparisonOptions): UseTranslationComparisonResult;
824
-
825
- interface UseTranslationWorkspaceOptions {
826
- readonly schema: FormSchema;
827
- readonly onChange?: (schema: FormSchema) => void;
828
- readonly sourceLocale?: string;
829
- readonly targetLocale?: string;
830
- readonly translationAdapter?: TranslationAdapter | AsyncTranslationAdapter;
831
- readonly readOnly?: boolean;
832
- readonly policy?: FormPolicy;
833
- readonly availableLocales?: readonly (string | LocaleOption)[];
834
- readonly onLocaleAdded?: (locale: string) => void;
835
- readonly onLocaleRemoved?: (locale: string) => void;
836
- readonly onLocaleChange?: (targetLocale: string) => void;
837
- readonly beforeRemoveLocale?: (locale: string, context: {
838
- readonly slotCount: number;
839
- }) => Promise<boolean> | boolean;
840
- readonly confirmRemoveLocale?: (props: ConfirmRemoveLocaleSlotProps) => ReactNode;
841
- readonly slots?: Pick<TranslationWorkspaceSlots, "confirmRemoveLocale">;
842
- readonly onTranslationStart?: (params: {
843
- readonly targetLocale: string;
844
- readonly mode: "manual" | "automatic";
845
- }) => void;
846
- readonly onTranslationSuccess?: (payload: TranslationEventPayload) => void;
847
- readonly onTranslationError?: (params: {
848
- readonly targetLocale: string;
849
- readonly error: TranslationWorkspaceError;
850
- }) => void;
851
- readonly onTranslationChange?: (event: TranslationSlotChangeEvent) => void;
852
- readonly validateLocale?: ((locale: string, currentLocales: readonly string[]) => LocaleValidationResult) | CustomLocaleValidator;
853
- }
854
- interface LocaleValidationContext {
855
- readonly locale: string;
856
- readonly defaultLocale: string;
857
- readonly currentLocales: readonly string[];
858
- readonly policy?: FormPolicy;
859
- }
860
- type CustomLocaleValidator = (locale: string, context: LocaleValidationContext) => LocaleValidationResult | boolean | string | undefined | void;
861
- interface LocaleValidationResult {
862
- readonly valid: boolean;
863
- readonly error?: {
864
- readonly type: "locale_not_allowed" | "max_locales_exceeded" | "invalid_locale_format" | "locale_already_exists" | "custom_validation_failed";
865
- readonly message: string;
866
- };
867
- }
868
- interface TranslationSummary {
869
- readonly totalSlots: number;
870
- readonly translatedCount: number;
871
- readonly missingCount: number;
872
- readonly staleCount: number;
873
- readonly manualCount: number;
874
- readonly completionPercentage: number;
875
- }
876
- type TranslationWorkspaceError = {
877
- readonly type: "locale_not_allowed";
878
- readonly locale: string;
879
- } | {
880
- readonly type: "locale_already_exists";
881
- readonly locale: string;
882
- } | {
883
- readonly type: "invalid_locale_format";
884
- readonly locale: string;
885
- } | {
886
- readonly type: "max_locales_exceeded";
887
- readonly max: number;
888
- readonly current: number;
889
- } | {
890
- readonly type: "read_only_mode";
891
- } | {
892
- readonly type: "adapter_not_configured";
893
- } | {
894
- readonly type: "target_locale_missing";
895
- } | {
896
- readonly type: "translation_failed";
897
- readonly message: string;
898
- readonly cause?: unknown;
899
- } | {
900
- readonly type: "custom_validation_failed";
901
- readonly message: string;
902
- };
903
- interface UseTranslationWorkspaceResult {
904
- readonly sourceLocale: string;
905
- readonly targetLocale: string;
906
- readonly targetLocales: readonly string[];
907
- readonly localeOptions: readonly LocaleOption[];
908
- readonly setTargetLocale: (locale: string) => void;
909
- readonly slots: readonly TranslationSlot[];
910
- readonly summary: TranslationSummary;
911
- readonly addLocale: (locale: string) => {
912
- readonly success: boolean;
913
- readonly error?: TranslationWorkspaceError;
914
- };
915
- readonly isAddLocaleAllowed: (locale: string) => boolean;
916
- readonly removeLocale: (locale: string) => boolean | Promise<boolean>;
917
- readonly removeLocaleConfirmation?: ReactNode;
918
- readonly setTranslation: (slot: TranslationSlot, text: string) => void;
919
- readonly translateAll: (options?: PopulateTranslationOptions) => Promise<{
920
- readonly success: boolean;
921
- readonly report?: TranslationReport;
922
- readonly error?: TranslationWorkspaceError;
923
- }>;
924
- readonly translateSlot: (slot: TranslationSlot) => Promise<{
925
- readonly success: boolean;
926
- readonly error?: TranslationWorkspaceError;
927
- }>;
928
- readonly isTranslating: boolean;
929
- readonly error?: TranslationWorkspaceError;
930
- }
931
- declare const validateLocalePipeline: (locale: string, schema: FormSchema, policy?: FormPolicy, customValidator?: ((locale: string, currentLocales: readonly string[]) => LocaleValidationResult) | CustomLocaleValidator, availableLocales?: readonly (string | LocaleOption)[]) => LocaleValidationResult;
932
- declare function useTranslationWorkspace({ schema, onChange, sourceLocale, targetLocale, translationAdapter, readOnly, policy, availableLocales, onLocaleAdded, onLocaleRemoved, onLocaleChange, beforeRemoveLocale, confirmRemoveLocale, slots: workspaceSlots, onTranslationStart, onTranslationSuccess, onTranslationError, onTranslationChange, validateLocale }: UseTranslationWorkspaceOptions): UseTranslationWorkspaceResult;
998
+ declare function useTranslationComparison({ schema, sourceLocale, targetLocale, translationAdapter, readOnly, availableLocales, policy, onChange, onTranslationChange, onTranslationReport, onTranslationError, signal, onLocaleAdded, onLocaleRemoved, onLocaleChange, beforeRemoveLocale, confirmRemoveLocale, onTranslationStart, onTranslationSuccess, validateLocale, createTranslationMetadata }: UseTranslationComparisonOptions): UseTranslationComparisonResult;
933
999
 
934
1000
  declare const BUILDER_TRANSLATION_KEYS: {
935
1001
  readonly ADD_FIELD: "builder.actions.addField";