@roqua/quby-frontend 0.11.2 → 0.12.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.
@@ -1,6 +1,5 @@
1
1
  import { default as React } from 'react';
2
- import { IDisplayOptions, IInterpolateTextvars, Questionnaire, Response } from '../core';
3
- export declare const InterpolateCurliesContext: React.Context<IInterpolateTextvars>;
2
+ import { IDisplayOptions, Questionnaire, Response } from '../core';
4
3
  interface Props {
5
4
  questionnaire: Questionnaire;
6
5
  response: Response;
@@ -0,0 +1 @@
1
+ export declare const Footer: () => import("react/jsx-runtime").JSX.Element | null;
@@ -1,9 +1,8 @@
1
1
  import { default as React } from 'react';
2
- interface HasDescription {
3
- description?: string;
4
- }
5
2
  interface Props {
6
- question: HasDescription;
3
+ question: {
4
+ key: string;
5
+ };
7
6
  }
8
7
  export declare const QuestionDescription: React.FunctionComponent<Props>;
9
8
  export {};
@@ -0,0 +1,4 @@
1
+ export declare const TranslationCurlies: React.FunctionComponent<{
2
+ i18nKey: string;
3
+ Component: React.ElementType;
4
+ }>;
@@ -12,7 +12,7 @@ export declare class Calculations {
12
12
  };
13
13
  constructor(sexpVariables: ISexpVariables, response: Response);
14
14
  getResult(key: string): string | number | boolean | null;
15
- handleValueChanged(key: string): void;
15
+ handleValueChanged(questionKey: string): string[];
16
16
  calculate(calculation: ICalculation): string | number | null | boolean;
17
17
  calculateNumber: (calculation: INumberCalculation) => number | null;
18
18
  calculateBoolean: (calculation: IBooleanCalculation) => boolean | null;
@@ -1,7 +1,7 @@
1
1
  export * from './questionnaire_json';
2
2
  export * from './questionnaire';
3
3
  export * from './response';
4
+ export * from './questionnaire_translations_curlies';
4
5
  export * from './quby_context';
5
6
  export * from './validators';
6
7
  export * from './response_json';
7
- export * from './curlies_interpolator';
@@ -1,10 +1,11 @@
1
1
  import { default as React } from 'react';
2
- import { Response, Questionnaire, IDisplayOptions } from '.';
2
+ import { Response, Questionnaire, IDisplayOptions, QuestionnaireTranslationsCurlies } from '.';
3
3
  export type SetQuestionRef = (key: string, ref: React.RefObject<HTMLElement | null>) => void;
4
4
  export interface IQubyContext {
5
5
  questionnaire: Questionnaire;
6
6
  response: Response;
7
7
  setQuestionRef: SetQuestionRef;
8
8
  displayOptions: IDisplayOptions;
9
+ translationsCurlies: QuestionnaireTranslationsCurlies;
9
10
  }
10
11
  export declare const QubyContext: React.Context<IQubyContext>;
@@ -1,10 +1,9 @@
1
- import { IQuestionnaire, IQuestion, IPanel, ITextvar, IValidation, IQuestions, ISexpVariables, ISelectOption, IRadioOption } from './questionnaire_json';
1
+ import { IQuestionnaire, IQuestion, IPanel, ITextvar, IValidation, IQuestions, ISexpVariables, ISelectOption, IRadioOption, ICheckBoxOption } from './questionnaire_json';
2
2
  import { VisibilityRule } from './visibility_rules';
3
3
  export declare class Questionnaire {
4
4
  #private;
5
5
  key: string;
6
6
  panels: IPanel[];
7
- footer?: string;
8
7
  questions: IQuestions;
9
8
  validations: IValidation[];
10
9
  visibilityRules: VisibilityRule[];
@@ -15,9 +14,16 @@ export declare class Questionnaire {
15
14
  [key: string]: string | number;
16
15
  } | undefined;
17
16
  layoutVersion: "v1" | "v2";
17
+ defaultLanguage: string;
18
+ translations: {
19
+ [language: string]: {
20
+ [key: string]: string;
21
+ };
22
+ };
18
23
  constructor(data: IQuestionnaire);
19
24
  getField(key: string): IQuestion;
20
25
  getQuestionsInSameGroup(questionKey: string): IQuestion[];
21
- getFlatOptions(questionKey: string): (ISelectOption | IRadioOption)[];
26
+ getChildQuestionKeys(questionKey: string): string[];
27
+ getFlatOptions(questionKey: string): (ISelectOption | IRadioOption | ICheckBoxOption)[];
22
28
  getOptionNumberValue(questionKey: string, optionKey: string): number | null;
23
29
  }
@@ -78,9 +78,6 @@ export interface IMinimumCheckedRequiredValidation {
78
78
  }
79
79
  interface IBaseField {
80
80
  key: string;
81
- title?: string;
82
- description?: string;
83
- contextDescription?: string;
84
81
  presentation?: "horizontal" | "vertical";
85
82
  questionGroup?: string | null;
86
83
  as?: string | null;
@@ -130,9 +127,9 @@ export interface IFloatQuestion extends IBaseField, INumberQuestion {
130
127
  export interface ISliderQuestion extends IBaseField {
131
128
  type: "float" | "integer";
132
129
  as: "slider";
130
+ labelsI18nKey?: string;
133
131
  step: number;
134
132
  defaultPosition: number;
135
- labels: string[];
136
133
  startThumbHidden: boolean;
137
134
  valueTooltip: boolean;
138
135
  minimum: number;
@@ -150,7 +147,6 @@ export interface ISelectQuestion extends IBaseField {
150
147
  type: "select";
151
148
  as: "select";
152
149
  children: (ISelectOption | IOptgroup)[];
153
- placeholder: string;
154
150
  }
155
151
  export interface IRadioQuestion extends IBaseField {
156
152
  type: "radio";
@@ -180,35 +176,22 @@ export interface IOption {
180
176
  }
181
177
  export interface ICheckBoxOption extends IOption {
182
178
  questions: IQuestion[];
183
- label?: string;
184
- description?: string;
185
179
  }
186
180
  export interface IRadioOption extends IOption {
187
181
  value: number;
188
182
  questions: IQuestion[];
189
- label?: string;
190
- description?: string;
191
183
  }
192
184
  export interface IOptgroup {
193
185
  type: "optgroup";
194
186
  key: string;
195
- label: string;
196
187
  options: ISelectOption[];
197
188
  }
198
189
  export interface ISelectOption extends IOption {
199
190
  value: number;
200
- label?: string;
201
- description?: string;
202
191
  }
203
192
  export interface IHtmlOption {
204
193
  type: "html";
205
194
  key: string;
206
- html: string;
207
- }
208
- export interface IPlaceholderOption {
209
- type: "placeholder";
210
- key: string;
211
- description: string;
212
195
  }
213
196
  export type IQuestion = IDatePartsQuestion | IStringQuestion | ITextareaQuestion | IIntegerQuestion | IFloatQuestion | ISliderQuestion | ISplitToUnitsQuestion | IRadioQuestion | IScaleQuestion | ISelectQuestion | ICheckBoxQuestion;
214
197
  export interface IQuestions {
@@ -216,7 +199,7 @@ export interface IQuestions {
216
199
  }
217
200
  export interface IHtmlItem {
218
201
  type: 'html';
219
- html: string;
202
+ key: string;
220
203
  }
221
204
  export interface IQuestionItem {
222
205
  type: "question";
@@ -229,13 +212,12 @@ export interface IInfoItem {
229
212
  type: "info";
230
213
  subtype?: "info" | "question-bar";
231
214
  key: string;
232
- html: string;
233
215
  startOpen: boolean;
234
216
  items: Array<IHtmlItem | IQuestionItem>;
235
217
  }
236
218
  export type IPanelItem = IHtmlItem | IQuestionItem | ITableItem | IInfoItem;
237
219
  export interface IPanel {
238
- title?: string;
220
+ key: string;
239
221
  items: IPanelItem[];
240
222
  questionKeys: string[];
241
223
  }
@@ -332,10 +314,14 @@ export type ISexpVariables = {
332
314
  calculation: ICalculation;
333
315
  };
334
316
  };
317
+ export type ITranslations = {
318
+ [language: string]: {
319
+ [key: string]: string;
320
+ };
321
+ };
335
322
  export interface IQuestionnaire {
336
323
  key: string;
337
324
  title: string;
338
- footer?: string;
339
325
  language: string;
340
326
  panels: IPanel[];
341
327
  questions: IQuestions;
@@ -350,6 +336,7 @@ export interface IQuestionnaire {
350
336
  [key: string]: string;
351
337
  };
352
338
  layoutVersion?: "v1" | "v2";
339
+ translations: ITranslations;
353
340
  }
354
341
  export interface IDisplayOptions {
355
342
  displayMode: "paged" | "single_page" | "bulk";
@@ -0,0 +1,21 @@
1
+ import { Questionnaire } from './questionnaire';
2
+ import { Response } from './response';
3
+ export declare class QuestionnaireTranslationsCurlies {
4
+ response: Response;
5
+ questionnaire: Questionnaire;
6
+ keyToInterpolatedString: Map<string, string>;
7
+ keyToInterpolatedStringArray: Map<string, string[]>;
8
+ variableToKeys: Map<string, string[]>;
9
+ language: string;
10
+ translations: {
11
+ [key: string]: string;
12
+ };
13
+ callbacks: Map<string, Set<() => void>>;
14
+ subscribeMethods: Map<string, (callback: () => void) => () => void>;
15
+ constructor(response: Response, questionnaire: Questionnaire, language: string);
16
+ subscribeToKey(key: string): (cb: () => void) => () => void;
17
+ fetch(key: string): string | undefined;
18
+ fetchArray(key: string): string[];
19
+ private interpolateCurlies;
20
+ private buildVariableToKeys;
21
+ }
@@ -32,6 +32,7 @@ export interface IVisibility {
32
32
  hidden: boolean;
33
33
  }
34
34
  export interface IValidated {
35
+ key: string;
35
36
  showErrors: boolean;
36
37
  valid: boolean;
37
38
  errors: IError[];
@@ -50,7 +51,7 @@ export interface IValidationFieldState<T extends IValue> {
50
51
  value: T;
51
52
  addError: (error: IError) => void;
52
53
  }
53
- export type IChangeCallback = (response: Response, type?: "valueChanged") => void;
54
+ export type IChangeCallback = (response: Response, type: "valueChanged" | "visibilityChanged" | "textvarChanged" | "sexpVariableChanged", key?: string) => void;
54
55
  export declare class Response {
55
56
  questionnaire: Questionnaire;
56
57
  values: IValues;
@@ -59,6 +60,9 @@ export declare class Response {
59
60
  errors: Map<string, IError[]>;
60
61
  visibility: Map<string, IVisibility>;
61
62
  changeHandlers: IChangeCallback[];
63
+ questionCallbacks: Map<string, () => void>;
64
+ subscribeMethods: Map<string, (callback: () => void) => () => void>;
65
+ fieldStates: Map<string, IFieldState<IValue>>;
62
66
  flags: IFlags;
63
67
  textvars: ITextvars;
64
68
  activeQuestionKey: string | null;
@@ -68,11 +72,15 @@ export declare class Response {
68
72
  cleanValues(): IValues;
69
73
  onChange(callback: IChangeCallback): void;
70
74
  offChange(callback: IChangeCallback): void;
75
+ subscribeToQuestion(questionKey: string): (callback: () => void) => () => void;
71
76
  getFieldState<T extends IValue>(key: string): IFieldState<T>;
72
77
  getValidationFieldState<T extends IValue>(key: string): IValidationFieldState<T>;
78
+ getVisibilityFieldState(key: string): Pick<IFieldState<IValue>, "value" | "hidden" | "disabled">;
73
79
  setTextvar(key: string, value: string | null): void;
74
80
  initTextvars(fromServer: ITextvars): Map<string, string>;
75
81
  setValue<T extends IValue>(key: string, value: T | null): void;
82
+ handleCalculations(questionKey: string): void;
83
+ fieldStateChanged(key: string): void;
76
84
  setActiveQuestion(key: string | null): void;
77
85
  addError(key: string, error: IError): void;
78
86
  valueHasChanged(): boolean;
@@ -1,3 +1,4 @@
1
1
  export * from './use_might_become_valid';
2
2
  export * from './use_question_shortkeys';
3
3
  export * from './map_css_vars';
4
+ export * from './use_translation_curlies_for';
@@ -0,0 +1,2 @@
1
+ export declare const useTranslationCurliesFor: (i18nKey: string) => string | undefined;
2
+ export declare const useTranslationCurliesArrayFor: (i18nKey: string) => string[];