@dialob/composer-material 0.0.15 → 0.0.17

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/README.md CHANGED
@@ -101,6 +101,41 @@ pnpm run preview
101
101
 
102
102
  Starts preview server for built application from `/dist` (No hot-reload!). Run `pnpm build` first to build the package
103
103
 
104
+ ## AI Translation Feature
105
+
106
+ The composer includes an AI-powered translation feature that helps automate the translation of form content across multiple languages.
107
+
108
+ ### Configuration
109
+
110
+ The AI translation feature needs `translationServiceUrl` to be set in `AppConfig` - it can come from the backend (`config.translationServiceUrl` configuration parameter) or be set manually in the app config (e.g. in `index.html`). This is the URL of the translation service API, including the path to the translation service endpoint.
111
+
112
+ ```typescript
113
+ export const appConfig: AppConfig = {
114
+ ...
115
+ translationServiceUrl: 'http://localhost:8083/api/translate',
116
+ }
117
+ ```
118
+
119
+ ### Key Features
120
+
121
+ - **Automated Translation**: Translate labels, descriptions, validation messages, and value set entries from one language to another using AI
122
+ - **Translation Tracking**: All AI-generated translations are tracked with metadata including:
123
+ - Source and target languages
124
+ - Translation timestamp
125
+ - Translation type (label, description, validation, etc.)
126
+ - **Visual Indicators**: AI-translated content is marked with a visual indicator in the translation editor
127
+ - **Manual Validation**: Users can review AI translations and remove the AI flag once validated
128
+ - **Bulk Operations**: Support for translating entire choice lists and multiple form elements at once
129
+
130
+ ### Usage
131
+
132
+ The AI translation feature is available in multiple places in the composer, either for translating single items or in bulk:
133
+ - in the translation dialog (for translating entire form content)
134
+ - in the item options dialog (for translating single items)
135
+ - in the choice editor (for translating value set entries)
136
+
137
+ The source language is always the active form language. Translations can be validated by clicking the AI indicator.
138
+
104
139
  ### Item type configuration
105
140
 
106
141
  Item type configuration defines the structure of the "Add Item" menu and available item types with their properties and behavior.
@@ -7,6 +7,7 @@ import { EditorState } from '..';
7
7
  import { FunctionComponent } from '../../node_modules/@types/react';
8
8
  import { IdField } from '../items/ItemComponents';
9
9
  import { Indicators } from '../items/ItemComponents';
10
+ import { default as ItemOptionsDialog } from '../dialogs/ItemOptionsDialog';
10
11
  import { JSX as JSX_2 } from 'react/jsx-runtime';
11
12
  import { LabelField } from '../items/ItemComponents';
12
13
  import { LanguageEditor } from '../components/translations/LanguageEditor';
@@ -18,7 +19,7 @@ import { VisibilityField } from '../items/ItemComponents';
18
19
 
19
20
  declare interface ApiResponse {
20
21
  success: boolean;
21
- result?: SaveResult | DuplicateResult | CreateTagResult | ChangeIdResult | CreateSessionResult;
22
+ result?: SaveResult | DuplicateResult | CreateTagResult | ChangeIdResult | CreateSessionResult | TranslationResponse;
22
23
  apiError?: any;
23
24
  }
24
25
 
@@ -32,6 +33,7 @@ declare interface AppConfig {
32
33
  tenantId: string;
33
34
  credentialMode: RequestCredentials;
34
35
  version: string;
36
+ translationServiceUrl?: string;
35
37
  }
36
38
 
37
39
  declare interface BackendState {
@@ -47,6 +49,7 @@ declare interface BackendState {
47
49
  getTags(formName: string): Promise<ComposerTag[]>;
48
50
  changeItemId(form: ComposerState, oldId: string, newId: string): Promise<ApiResponse>;
49
51
  createPreviewSession(formId: string, language: string, context?: PreviewSessionContext): Promise<ApiResponse>;
52
+ translateEntries(request: TranslationRequest): Promise<ApiResponse>;
50
53
  }
51
54
 
52
55
  declare namespace BackendTypes {
@@ -63,6 +66,10 @@ declare namespace BackendTypes {
63
66
  TransportConfig,
64
67
  DialobComposerConfig,
65
68
  AppConfig,
69
+ TranslationEntry,
70
+ TranslationRequest,
71
+ TranslationResult,
72
+ TranslationResponse,
66
73
  BackendState
67
74
  }
68
75
  }
@@ -129,6 +136,7 @@ declare type ComposerMetadata = {
129
136
  contextValues?: {
130
137
  [name: string]: string;
131
138
  };
139
+ aiTranslations?: TranslationMetadata[];
132
140
  };
133
141
 
134
142
  declare type ComposerState = {
@@ -166,7 +174,7 @@ declare interface ConfigItemProps {
166
174
 
167
175
  export declare const ConfirmationDialog: default_2.FC;
168
176
 
169
- declare type ConfirmationDialogType = 'duplicate' | 'delete';
177
+ declare type ConfirmationDialogType = 'duplicate' | 'delete' | 'deleteVariable';
170
178
 
171
179
  declare type ContextVariable = {
172
180
  name: string;
@@ -253,6 +261,7 @@ declare interface DialobComposerConfig {
253
261
  itemTypes: ItemTypeConfig;
254
262
  backendVersion: string;
255
263
  closeHandler: () => void;
264
+ translationServiceUrl?: string;
256
265
  }
257
266
 
258
267
  declare type DialobItem = DialobItemTemplate & {
@@ -273,6 +282,7 @@ declare type DialobItemTemplate = {
273
282
  activeWhen?: string;
274
283
  canAddRowWhen?: string;
275
284
  canRemoveRowWhen?: string;
285
+ readOnlyWhen?: string;
276
286
  items?: string[];
277
287
  className?: string[];
278
288
  props?: {
@@ -300,6 +310,7 @@ declare namespace DialobTypes {
300
310
  DialobItems,
301
311
  VisibilityType,
302
312
  ComposerTag,
313
+ TranslationMetadata,
303
314
  ComposerMetadata,
304
315
  ComposerState,
305
316
  FormMetadata,
@@ -333,6 +344,8 @@ declare type ErrorSeverity = 'ERROR' | 'WARNING' | 'INFO' | 'FATAL';
333
344
 
334
345
  declare namespace ErrorUtils {
335
346
  export {
347
+ parseVariableItemId,
348
+ parseRowgroupIdFromVariableItemId,
336
349
  getErrorSeverity,
337
350
  getItemErrorColor,
338
351
  useErrorColorSx,
@@ -355,6 +368,7 @@ declare interface FlattenedItem extends TreeItem {
355
368
  depth: number;
356
369
  index: number;
357
370
  isFallbackLabel?: boolean;
371
+ isVariable?: boolean;
358
372
  }
359
373
 
360
374
  declare type FormMetadata = {
@@ -393,10 +407,7 @@ export declare const GlobalList: default_2.FC<{
393
407
  entries?: ValueSetEntry[];
394
408
  }>;
395
409
 
396
- export declare const GlobalListsDialog: default_2.FC<{
397
- open: boolean;
398
- onClose: () => void;
399
- }>;
410
+ export declare const GlobalListsDialog: default_2.FC;
400
411
 
401
412
  export declare const Group: default_2.FC<{
402
413
  item: DialobItem;
@@ -428,9 +439,9 @@ declare interface ItemConfigItem {
428
439
  props: ConfigItemProps;
429
440
  }
430
441
 
431
- export declare const itemFactory: (item: DialobItem, itemConfig: ItemConfig, setHighlightedItem?: (item: DialobItem) => void, props?: any) => JSX_2.Element | null;
442
+ export declare const itemFactory: (item: DialobItem | string, itemConfig: ItemConfig, setHighlightedItem?: (item: DialobItem) => void, props?: any) => JSX_2.Element | null;
432
443
 
433
- export declare const ItemOptionsDialog: default_2.FC;
444
+ export { ItemOptionsDialog }
434
445
 
435
446
  declare interface ItemProp {
436
447
  key: string;
@@ -487,6 +498,10 @@ export declare const PageTabs: default_2.FC<{
487
498
  items: DialobItems;
488
499
  }>;
489
500
 
501
+ declare const parseRowgroupIdFromVariableItemId: (itemId: string) => string | undefined;
502
+
503
+ declare const parseVariableItemId: (itemId: string) => string;
504
+
490
505
  export declare const PreviewDialog: default_2.FC<{
491
506
  open: boolean;
492
507
  onClose: () => void;
@@ -543,7 +558,7 @@ export declare const RuleEditor: default_3.FC<{
543
558
 
544
559
  export declare const RulesEditor: default_3.FC;
545
560
 
546
- declare type RuleType = 'visibility' | 'requirement' | 'canaddrow' | 'canremoverow';
561
+ declare type RuleType = 'visibility' | 'requirement' | 'readOnly' | 'canaddrow' | 'canremoverow';
547
562
 
548
563
  declare interface SaveResult {
549
564
  ok: boolean;
@@ -558,6 +573,7 @@ declare interface SavingState {
558
573
  composerMetadata?: ComposerMetadata;
559
574
  variables?: (ContextVariable | Variable)[];
560
575
  formMetadata?: FormMetadata;
576
+ items?: DialobItems;
561
577
  }
562
578
 
563
579
  export declare const SimpleField: default_2.FC<{
@@ -576,8 +592,36 @@ export declare const TranslationDialog: default_2.FC<{
576
592
  onClose: () => void;
577
593
  }>;
578
594
 
595
+ declare interface TranslationEntry {
596
+ id: string;
597
+ text: string;
598
+ }
599
+
579
600
  export declare const TranslationFileEditor: default_3.FC;
580
601
 
602
+ declare type TranslationMetadata = {
603
+ entryId: string;
604
+ sourceLanguage: string;
605
+ targetLanguage: string;
606
+ timestamp: string;
607
+ };
608
+
609
+ declare interface TranslationRequest {
610
+ sourceLanguage: string;
611
+ targetLanguage: string;
612
+ entries: TranslationEntry[];
613
+ }
614
+
615
+ declare interface TranslationResponse {
616
+ translations: TranslationResult[];
617
+ targetLanguage: string;
618
+ }
619
+
620
+ declare interface TranslationResult {
621
+ id: string;
622
+ translatedText: string;
623
+ }
624
+
581
625
  declare interface TransportConfig {
582
626
  csrf?: {
583
627
  headerName: string;
@@ -596,6 +640,7 @@ declare interface TreeItem {
596
640
  collapsible?: boolean;
597
641
  collapsed?: boolean;
598
642
  isFallbackLabel?: boolean;
643
+ isVariable?: boolean;
599
644
  }
600
645
 
601
646
  export declare const UploadValuesetDialog: default_2.FC<{
@@ -632,6 +677,7 @@ export declare const useComposer: () => {
632
677
  setMetadataValue: (attr: string, value: any) => void;
633
678
  setContextValue: (name: string, value: string) => void;
634
679
  createVariable: (context: boolean) => void;
680
+ createScopedExpressionVariable: (rowgroupId: string, callbacks?: ComposerCallbacks) => void;
635
681
  updateContextVariable: (variableId: string, contextType?: ContextVariableType | string, defaultValue?: any) => void;
636
682
  updateExpressionVariable: (variableId: string, expression: string) => void;
637
683
  updateVariablePublishing: (variableId: string, published: boolean) => void;
@@ -646,6 +692,8 @@ export declare const useComposer: () => {
646
692
  applyListChanges: (newState: SavingState) => void;
647
693
  applyVariableChanges: (newState: SavingState) => void;
648
694
  applyFormChanges: (newState: SavingState) => void;
695
+ applyTranslations: (translations: TranslationResult[], sourceLanguage: string, targetLanguage: string) => void;
696
+ removeAITranslation: (entryId: string, targetLanguage: string) => void;
649
697
  form: ComposerState;
650
698
  };
651
699
 
@@ -661,6 +709,7 @@ export declare const useEditor: () => {
661
709
  setHighlightedItem: (item?: DialobItem) => void;
662
710
  setActiveList: (listId?: string) => void;
663
711
  setActiveVariableTab: (tab?: VariableTabType) => void;
712
+ setActiveVariable: (variableId?: string, idEditMode?: boolean) => void;
664
713
  setConfirmationActiveItem: (item?: DialobItem) => void;
665
714
  toggleItemCollapsed: (itemId: string) => void;
666
715
  setMarkdownHelpDialogOpen: (open: boolean) => void;