case-editor-tools 1.0.0-beta.4 → 1.0.0-beta.40

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.
Files changed (132) hide show
  1. package/{build/constants → constants}/key-definitions.d.ts +3 -0
  2. package/{build/constants → constants}/key-definitions.js +7 -1
  3. package/{build/constants → constants}/key-definitions.js.map +1 -1
  4. package/exporter/index.d.ts +2 -0
  5. package/exporter/index.js +99 -0
  6. package/exporter/index.js.map +1 -0
  7. package/{build/expression-utils → expression-utils}/expressionGen.d.ts +1 -1
  8. package/{build/expression-utils → expression-utils}/expressionGen.js +0 -0
  9. package/{build/expression-utils → expression-utils}/expressionGen.js.map +0 -0
  10. package/{build/expression-utils → expression-utils}/studyEngineExpressions.d.ts +86 -13
  11. package/{build/expression-utils → expression-utils}/studyEngineExpressions.js +189 -19
  12. package/{build/expression-utils → expression-utils}/studyEngineExpressions.js.map +1 -1
  13. package/{build/index.d.ts → index.d.ts} +0 -0
  14. package/{build/index.js → index.js} +0 -0
  15. package/{build/index.js.map → index.js.map} +0 -0
  16. package/{build/item-editor-8fd24b61.js → item-editor-59f51ecc.js} +72 -51
  17. package/item-editor-59f51ecc.js.map +1 -0
  18. package/logger/index.d.ts +1 -0
  19. package/logger/index.js +10 -0
  20. package/logger/index.js.map +1 -0
  21. package/{build/logger → logger}/logger.d.ts +0 -0
  22. package/{build/logger → logger}/logger.js +0 -0
  23. package/{build/logger → logger}/logger.js.map +0 -0
  24. package/package.json +7 -8
  25. package/surveys/index.d.ts +3 -0
  26. package/surveys/index.js +29 -0
  27. package/surveys/index.js.map +1 -0
  28. package/surveys/responseTypeGenerators/likertGroupComponents.d.ts +27 -0
  29. package/surveys/responseTypeGenerators/likertGroupComponents.js +350 -0
  30. package/surveys/responseTypeGenerators/likertGroupComponents.js.map +1 -0
  31. package/surveys/responseTypeGenerators/matrixGroupComponent.d.ts +49 -0
  32. package/surveys/responseTypeGenerators/matrixGroupComponent.js +100 -0
  33. package/surveys/responseTypeGenerators/matrixGroupComponent.js.map +1 -0
  34. package/surveys/responseTypeGenerators/optionGroupComponents.d.ts +7 -0
  35. package/surveys/responseTypeGenerators/optionGroupComponents.js +129 -0
  36. package/surveys/responseTypeGenerators/optionGroupComponents.js.map +1 -0
  37. package/{build → surveys}/survey-editor/component-editor.d.ts +1 -1
  38. package/{build → surveys}/survey-editor/component-editor.js +0 -0
  39. package/{build → surveys}/survey-editor/component-editor.js.map +0 -0
  40. package/{build → surveys}/survey-editor/data-types.d.ts +1 -1
  41. package/{build → surveys}/survey-editor/data-types.js +0 -0
  42. package/{build → surveys}/survey-editor/data-types.js.map +0 -0
  43. package/{build → surveys}/survey-editor/item-editor.d.ts +2 -1
  44. package/{build → surveys}/survey-editor/item-editor.js +3 -2
  45. package/{build → surveys}/survey-editor/item-editor.js.map +1 -1
  46. package/{build → surveys}/survey-editor/survey-editor.d.ts +6 -1
  47. package/{build → surveys}/survey-editor/survey-editor.js +15 -8
  48. package/{build → surveys}/survey-editor/survey-editor.js.map +1 -1
  49. package/{build/expression-utils/surveyEngineExpressions.d.ts → surveys/survey-engine-expressions.d.ts} +12 -2
  50. package/{build/expression-utils/surveyEngineExpressions.js → surveys/survey-engine-expressions.js} +45 -4
  51. package/{build/expression-utils/surveyEngineExpressions.js.map → surveys/survey-engine-expressions.js.map} +1 -1
  52. package/surveys/survey-items.d.ts +68 -0
  53. package/surveys/survey-items.js +384 -0
  54. package/surveys/survey-items.js.map +1 -0
  55. package/{build → surveys}/types/group.d.ts +1 -1
  56. package/{build → surveys}/types/group.js +6 -5
  57. package/{build → surveys}/types/group.js.map +1 -1
  58. package/surveys/types/index.d.ts +4 -0
  59. package/surveys/types/index.js +22 -0
  60. package/surveys/types/index.js.map +1 -0
  61. package/surveys/types/item-properties.d.ts +223 -0
  62. package/surveys/types/item-properties.js +10 -0
  63. package/surveys/types/item-properties.js.map +1 -0
  64. package/{build → surveys}/types/item.d.ts +1 -1
  65. package/{build → surveys}/types/item.js +0 -0
  66. package/{build → surveys}/types/item.js.map +0 -0
  67. package/{build/types/surveyDefinition.d.ts → surveys/types/survey-definition.d.ts} +7 -3
  68. package/{build/types/surveyDefinition.js → surveys/types/survey-definition.js} +20 -11
  69. package/surveys/types/survey-definition.js.map +1 -0
  70. package/{build → surveys}/utils/componentGenerators.d.ts +2 -13
  71. package/surveys/utils/componentGenerators.js +59 -0
  72. package/{build → surveys}/utils/componentGenerators.js.map +1 -1
  73. package/surveys/utils/optionDefGenerators.d.ts +83 -0
  74. package/surveys/utils/optionDefGenerators.js +210 -0
  75. package/surveys/utils/optionDefGenerators.js.map +1 -0
  76. package/{build → surveys}/utils/randomKeyGenerator.d.ts +0 -0
  77. package/{build → surveys}/utils/randomKeyGenerator.js +0 -0
  78. package/{build → surveys}/utils/randomKeyGenerator.js.map +0 -0
  79. package/{build → surveys}/utils/simple-generators.d.ts +4 -3
  80. package/{build → surveys}/utils/simple-generators.js +34 -5
  81. package/{build → surveys}/utils/simple-generators.js.map +1 -1
  82. package/surveys/utils/simple-question-editor.d.ts +14 -0
  83. package/{build → surveys}/utils/simple-question-editor.js +10 -7
  84. package/{build → surveys}/utils/simple-question-editor.js.map +1 -1
  85. package/{build/types → types}/duration.d.ts +0 -0
  86. package/{build/types → types}/duration.js +0 -0
  87. package/{build/types → types}/duration.js.map +0 -0
  88. package/{build/types → types}/expression.d.ts +1 -1
  89. package/{build/types → types}/expression.js +0 -0
  90. package/{build/types → types}/expression.js.map +0 -0
  91. package/{build/types → types}/study.d.ts +2 -2
  92. package/{build/types → types}/study.js +0 -0
  93. package/{build/types → types}/study.js.map +0 -0
  94. package/{build/types → types}/studyRules.d.ts +3 -2
  95. package/{build/types → types}/studyRules.js +5 -1
  96. package/types/studyRules.js.map +1 -0
  97. package/.babelrc.js +0 -7
  98. package/.editorconfig +0 -13
  99. package/LICENSE +0 -202
  100. package/build/item-editor-8fd24b61.js.map +0 -1
  101. package/build/package.json +0 -26
  102. package/build/types/studyRules.js.map +0 -1
  103. package/build/types/surveyDefinition.js.map +0 -1
  104. package/build/utils/componentGenerators.js +0 -92
  105. package/build/utils/question-type-generator.d.ts +0 -283
  106. package/build/utils/question-type-generator.js +0 -949
  107. package/build/utils/question-type-generator.js.map +0 -1
  108. package/build/utils/simple-question-editor.d.ts +0 -14
  109. package/rollup.config.js +0 -53
  110. package/src/constants/key-definitions.ts +0 -13
  111. package/src/expression-utils/expressionGen.ts +0 -28
  112. package/src/expression-utils/studyEngineExpressions.ts +0 -359
  113. package/src/expression-utils/surveyEngineExpressions.ts +0 -483
  114. package/src/index.ts +0 -1
  115. package/src/logger/logger.ts +0 -31
  116. package/src/survey-editor/component-editor.ts +0 -133
  117. package/src/survey-editor/data-types.ts +0 -18
  118. package/src/survey-editor/item-editor.ts +0 -528
  119. package/src/survey-editor/survey-editor.ts +0 -260
  120. package/src/types/duration.ts +0 -32
  121. package/src/types/expression.ts +0 -22
  122. package/src/types/group.ts +0 -73
  123. package/src/types/item.ts +0 -42
  124. package/src/types/study.ts +0 -17
  125. package/src/types/studyRules.ts +0 -39
  126. package/src/types/surveyDefinition.ts +0 -83
  127. package/src/utils/componentGenerators.ts +0 -122
  128. package/src/utils/question-type-generator.ts +0 -1516
  129. package/src/utils/randomKeyGenerator.ts +0 -11
  130. package/src/utils/simple-generators.ts +0 -106
  131. package/src/utils/simple-question-editor.ts +0 -52
  132. package/tsconfig.json +0 -100
@@ -1,260 +0,0 @@
1
- import { Survey, LocalizedString, SurveyItem, isSurveyGroupItem, SurveyGroupItem, SurveyContextDef, Expression } from "survey-engine/lib/data_types";
2
- import { NewItemProps } from "./data-types";
3
- import { ItemEditor } from "./item-editor";
4
-
5
- interface SurveyEditorInt {
6
- setSurveyName: (name: Array<LocalizedString>) => void;
7
- setSurveyDescription: (description: Array<LocalizedString>) => void;
8
- setSurveyDuration: (duration: Array<LocalizedString>) => void;
9
- setSurveyContextRules: (contextRules: SurveyContextDef) => void;
10
- setPrefillRules: (rules: Expression[]) => void;
11
-
12
-
13
- changeItemKey: (oldKey: string, newKey: string) => void;
14
- addNewSurveyItem: (itemProps: NewItemProps, parentKey?: string, atPosition?: number) => SurveyItem | undefined;
15
- updateSurveyItem: (item: SurveyItem) => void;
16
- removeItem: (key: string) => void;
17
- findSurveyItem: (itemKey: string) => SurveyItem | undefined;
18
- moveSurveyItem: (item: SurveyItem, destination: string) => void;
19
-
20
-
21
- getSurvey: () => Survey;
22
- getSurveyJSON: (pretty?: boolean) => string;
23
- }
24
-
25
- export class SurveyEditor implements SurveyEditorInt {
26
- private survey: Survey;
27
- private surveyKey: string;
28
-
29
- constructor(survey?: Survey) {
30
- if (survey) {
31
- this.survey = { ...survey };
32
- this.surveyKey = this.survey.current.surveyDefinition.key;
33
- } else {
34
- this.surveyKey = 'survey';
35
- this.survey = {
36
- props: {},
37
- current: {
38
- versionId: '',
39
- surveyDefinition: {
40
- key: this.surveyKey,
41
- version: 1,
42
- items: []
43
- }
44
- }
45
- }
46
- }
47
- }
48
-
49
- setSurveyName(name: Array<LocalizedString>) {
50
- if (!this.survey.props) {
51
- this.survey.props = {};
52
- }
53
- this.survey.props.name = name;
54
- };
55
-
56
- setSurveyDescription(description: Array<LocalizedString>) {
57
- if (!this.survey.props) {
58
- this.survey.props = {};
59
- }
60
- this.survey.props.description = description;
61
- };
62
-
63
- setSurveyDuration(duration: Array<LocalizedString>) {
64
- if (!this.survey.props) {
65
- this.survey.props = {};
66
- }
67
- this.survey.props.typicalDuration = duration;
68
- };
69
-
70
- setMaxItemPerPage(itemLimits: { small: number; large: number }) {
71
- this.survey.maxItemsPerPage = itemLimits;
72
- }
73
-
74
- setSurveyContextRules(contextRules: SurveyContextDef) {
75
- this.survey.contextRules = { ...contextRules };
76
- };
77
-
78
- setPrefillRules(rules: Expression[]) {
79
- this.survey.prefillRules = [...rules];
80
- };
81
-
82
- addNewSurveyItem(newItem: NewItemProps, parentKey?: string, atPosition?: number): SurveyItem | undefined {
83
- if (!parentKey) {
84
- newItem.itemKey = this.surveyKey + '.' + newItem.itemKey;
85
-
86
- if (this.survey.current.surveyDefinition.items.find(it => newItem.itemKey === it.key)) {
87
- console.error('item already exists with key: ', newItem.itemKey);
88
- return undefined;
89
- }
90
- const item = (new ItemEditor(undefined, newItem)).getItem();
91
-
92
- if (atPosition !== undefined) {
93
- this.survey.current.surveyDefinition.items.splice(atPosition, 0, item);
94
- } else {
95
- this.survey.current.surveyDefinition.items.push(item);
96
- }
97
- return item;
98
- }
99
- const obj = this.findSurveyItem(parentKey);
100
- if (!obj) {
101
- console.warn('parent survey item cannot be found: ', parentKey);
102
- return
103
- }
104
-
105
- newItem.itemKey = parentKey + '.' + newItem.itemKey;
106
- if ((obj as SurveyGroupItem).items.find(it => newItem.itemKey === it.key)) {
107
- console.error('item already exists with key: ', newItem.itemKey);
108
- return undefined;
109
- }
110
- const item = (new ItemEditor(undefined, newItem)).getItem();
111
- if (atPosition !== undefined) {
112
- (obj as SurveyGroupItem).items.splice(atPosition, 0, item);
113
- } else {
114
- (obj as SurveyGroupItem).items.push(item);
115
- }
116
- return item;
117
- }
118
-
119
- addExistingSurveyItem(surveyItem: SurveyItem, parentKey: string, atPosition?: number): SurveyItem | undefined {
120
- const parent = this.findSurveyItem(parentKey);
121
- if (!parent) {
122
- console.warn('parent survey item cannot be found: ', parentKey);
123
- return
124
- }
125
- if ((parent as SurveyGroupItem).items.find(it => surveyItem.key === it.key)) {
126
- console.error('item already exists with key: ', surveyItem.key);
127
- return undefined;
128
- }
129
- if (atPosition !== undefined) {
130
- (parent as SurveyGroupItem).items.splice(atPosition, 0, surveyItem);
131
- } else {
132
- (parent as SurveyGroupItem).items.push(surveyItem);
133
- }
134
- return surveyItem;
135
- }
136
-
137
- changeItemKey(oldKey: string, newKey: string, ignoreReferences?: boolean) {
138
- if (oldKey === this.surveyKey) {
139
- this.surveyKey = newKey;
140
- this.survey.current.surveyDefinition = this.changeItemKeyForSubtree(this.survey.current.surveyDefinition, newKey) as SurveyGroupItem;
141
- return;
142
- }
143
-
144
- let obj = this.findSurveyItem(oldKey);
145
- if (!obj) {
146
- console.warn('survey item cannot be found: ', oldKey);
147
- return
148
- }
149
- obj = Object.assign(obj, this.changeItemKeyForSubtree(obj, newKey));
150
-
151
- if (!ignoreReferences) {
152
- // replace key in every expression of the survey
153
- // replace key in every follows
154
- console.warn('unimplemented UPDATING KEY REFERENCES');
155
- }
156
- };
157
-
158
- updateSurveyItem(item: SurveyItem) {
159
- if (item.key === this.surveyKey) {
160
- this.survey.current.surveyDefinition = {
161
- ...this.survey.current.surveyDefinition,
162
- ...item
163
- }
164
- return;
165
- }
166
- const ids = item.key.split('.');
167
- const parentIds = ids.slice(0, ids.length - 1);
168
- const parentKey = parentIds.join('.');
169
-
170
- const obj = this.findSurveyItem(parentKey);
171
- if (!obj) {
172
- console.warn('parent survey item cannot be found: ', parentKey);
173
- return
174
- }
175
-
176
- const index = (obj as SurveyGroupItem).items.findIndex(it => it.key === item.key);
177
- if (index < 0) {
178
- console.warn('survey item cannot be found: ', item.key);
179
- return;
180
- }
181
- (obj as SurveyGroupItem).items[index] = {
182
- ...(obj as SurveyGroupItem).items[index],
183
- ...item
184
- };
185
- return;
186
- };
187
-
188
- removeItem(key: string) {
189
- // <- error if item is not found
190
- console.warn('removeItem unimplemented');
191
- return;
192
- };
193
-
194
- moveSurveyItem(item: SurveyItem, destination: string) {
195
- console.warn('moveSurveyItem unimplemented');
196
- // error if destination not exists
197
- // change item key
198
- // change key for all children recursivly
199
- };
200
-
201
- findSurveyItem(itemKey: string): SurveyItem | undefined {
202
- const ids = itemKey.split('.');
203
- const paths = this.getKeyListForPath(ids);
204
-
205
- let obj: SurveyItem | undefined = undefined;
206
- for (const currentKey of paths) {
207
- if (!obj) {
208
- obj = this.survey.current.surveyDefinition;
209
- continue;
210
- }
211
- if (!isSurveyGroupItem(obj)) {
212
- console.warn('survey item is not a group: ', obj.key);
213
- return;
214
- }
215
- const index = obj.items.findIndex(it => it.key === currentKey);
216
- if (index < 0) {
217
- console.warn('survey item cannot be found: ', currentKey);
218
- return;
219
- }
220
- obj = (obj.items[index] as SurveyGroupItem);
221
- }
222
- return obj;
223
- };
224
-
225
- getSurvey(): Survey {
226
- return { ...this.survey };
227
- };
228
-
229
- getSurveyJSON(pretty?: boolean): string {
230
- return JSON.stringify(this.survey, undefined, pretty ? ' ' : undefined);
231
- };
232
-
233
- // Private methods:
234
- private getKeyListForPath(ids: string[]): string[] {
235
- const paths: string[] = [];
236
- let compID = '';
237
- for (let i = 0; i < ids.length; i++) {
238
- const id = ids[i];
239
- if (compID.length < 1) {
240
- compID = id;
241
- } else {
242
- compID += '.' + id;
243
- }
244
- paths.push(compID);
245
- }
246
- return paths;
247
- }
248
-
249
- private changeItemKeyForSubtree(currentItem: SurveyItem, newKey: string): SurveyItem {
250
- currentItem = { ...currentItem };
251
- if (isSurveyGroupItem(currentItem)) {
252
- currentItem.items = currentItem.items.map(item => {
253
- const newSubkey = newKey + '.' + item.key.slice(item.key.lastIndexOf('.') + 1);
254
- return this.changeItemKeyForSubtree(item, newSubkey);
255
- });
256
- }
257
- currentItem.key = newKey;
258
- return currentItem;
259
- }
260
- }
@@ -1,32 +0,0 @@
1
- export interface Duration {
2
- years?: number;
3
- months?: number;
4
- days?: number;
5
- hours?: number;
6
- minutes?: number;
7
- seconds?: number;
8
- };
9
-
10
- export const durationObjectToSeconds = (duration: Duration): number => {
11
- let value = 0;
12
-
13
- if (duration.years !== undefined) {
14
- value += duration.years * 31536000;
15
- }
16
- if (duration.months !== undefined) {
17
- value += duration.months * 2592000;
18
- }
19
- if (duration.days !== undefined) {
20
- value += duration.days * 86400;
21
- }
22
- if (duration.hours !== undefined) {
23
- value += duration.hours * 3600;
24
- }
25
- if (duration.minutes !== undefined) {
26
- value += duration.minutes * 60;
27
- }
28
- if (duration.seconds !== undefined) {
29
- value += duration.seconds;
30
- }
31
- return value;
32
- }
@@ -1,22 +0,0 @@
1
- import { Expression, ExpressionArg } from "survey-engine/lib/data_types";
2
-
3
-
4
- export const isExpression = (value: Expression | any): value is Expression => {
5
- return typeof (value) === 'object' && (value as Expression).name !== undefined && (value as Expression).name.length > 0;
6
- }
7
-
8
- export type ExpressionArgDType = 'exp' | 'num' | 'str';
9
-
10
-
11
- export const expressionArgParser = (arg: ExpressionArg): any => {
12
- switch (arg.dtype) {
13
- case 'num':
14
- return arg.num;
15
- case 'str':
16
- return arg.str;
17
- case 'exp':
18
- return arg.exp;
19
- default:
20
- return arg.str;
21
- }
22
- }
@@ -1,73 +0,0 @@
1
- import { Expression, SurveyGroupItem, SurveyItem } from "survey-engine/lib/data_types";
2
- import { Logger } from "../logger/logger";
3
- import { ItemEditor } from "../survey-editor/item-editor";
4
- import { generatePageBreak } from "../utils/simple-generators";
5
-
6
- export abstract class Group {
7
- groupEditor: ItemEditor;
8
- key: string;
9
- private parentKey: string;
10
-
11
- constructor(parentKey: string, groupKey: string, selectionMethod?: Expression) {
12
- this.parentKey = parentKey;
13
- this.key = [this.parentKey, groupKey].join('.');
14
- this.groupEditor = new ItemEditor(undefined, {
15
- itemKey: this.key,
16
- isGroup: true
17
- });
18
- if (!selectionMethod) {
19
- this.groupEditor.setSelectionMethod({ name: 'sequential' });
20
- } else {
21
- this.groupEditor.setSelectionMethod(selectionMethod);
22
- }
23
- }
24
-
25
- abstract buildGroup(): void;
26
-
27
- /**
28
- * Check if this group is currently part of a path, by checking if the key attribute exists in the path of the group.
29
- * @param partialKey Is this key segment included somewhere in the parent key of this item.
30
- * @returns
31
- */
32
- isPartOf(partialKey: string): boolean {
33
- return this.parentKey.includes(partialKey)
34
- }
35
-
36
- /**
37
- * Use this method to retrieve the generated survey item
38
- * @returns
39
- */
40
- get() {
41
- this.buildGroup();
42
- this.checkDuplicateChildKeys();
43
- return this.groupEditor.getItem();
44
- }
45
-
46
- addPageBreak() {
47
- this.groupEditor.addSurveyItem(generatePageBreak(this.key));
48
- }
49
-
50
- addItem(item: SurveyItem, pageBreakAfter?: boolean) {
51
- this.groupEditor.addSurveyItem(item);
52
- if (pageBreakAfter) {
53
- this.addPageBreak();
54
- }
55
- }
56
-
57
- private checkDuplicateChildKeys() {
58
- const group = this.groupEditor.getItem() as SurveyGroupItem;
59
- const keys = group.items.map(item => item.key);
60
- const hasDuplicates = keys.some((key, index) => {
61
- const isDuplicateKey = keys.indexOf(key) !== index;
62
- if (isDuplicateKey) {
63
- Logger.error('Duplicate key:');
64
- Logger.criticalError(`${key} is used twice (at index ${keys.indexOf(key)} and at index ${index})`);
65
- }
66
- return isDuplicateKey;
67
- });
68
- if (hasDuplicates) {
69
- Logger.error('\nSurvey contains duplicate keys.\nPlease check the lines above for more infos.\nProcess stopped prematurely.')
70
- process.exit(1)
71
- }
72
- }
73
- }
package/src/types/item.ts DELETED
@@ -1,42 +0,0 @@
1
- import { Expression, SurveySingleItem } from "survey-engine/lib/data_types";
2
-
3
-
4
- export abstract class Item {
5
- key: string;
6
- item: SurveySingleItem;
7
- protected itemKey: string;
8
- protected parentKey: string;
9
-
10
- protected condition?: Expression;
11
- protected isRequired?: boolean;
12
-
13
- constructor(parentKey: string, itemKey: string) {
14
- this.parentKey = parentKey;
15
- this.itemKey = itemKey;
16
- this.key = [this.parentKey, itemKey].join('.');
17
- this.item = {
18
- version: 0,
19
- key: "not defined"
20
- }
21
- }
22
-
23
- abstract buildItem(): SurveySingleItem;
24
-
25
- /**
26
- * Check if this item is currently part of a path, by checking if the key attribute exists in the path of the group.
27
- * @param partialKey Is this key segment included somewhere in the parent key of this item.
28
- * @returns
29
- */
30
- isPartOf(partialKey: string): boolean {
31
- return this.parentKey.includes(partialKey)
32
- }
33
-
34
- /**
35
- * Use this method to retrieve the generated survey item
36
- * @returns
37
- */
38
- get() {
39
- this.item = this.buildItem();
40
- return this.item;
41
- }
42
- }
@@ -1,17 +0,0 @@
1
- import { Expression } from "survey-engine/lib/data_types";
2
- import { StudyRules } from "./studyRules";
3
- import { SurveyDefinition } from "./surveyDefinition";
4
-
5
- export interface Study {
6
- studyKey: string;
7
- outputFolderName?: string;
8
- surveys: SurveyDefinition[];
9
-
10
- // normal study rules
11
- studyRules?: StudyRules;
12
-
13
- customStudyRules?: Array<{
14
- name: string;
15
- rules: Expression[];
16
- }>;
17
- }
@@ -1,39 +0,0 @@
1
- import { Expression } from 'survey-engine/lib/data_types';
2
- import { StudyEngine } from '../expression-utils/studyEngineExpressions';
3
-
4
-
5
- export class StudyRules {
6
- private enterRules?: Expression[];
7
- private submitRules?: Expression[];
8
- private timerRules?: Expression[];
9
-
10
- constructor(
11
- enterRules?: Expression[],
12
- submitRules?: Expression[],
13
- timerRules?: Expression[],
14
- ) {
15
- this.enterRules = enterRules;
16
- this.submitRules = submitRules;
17
- this.timerRules = timerRules;
18
- }
19
-
20
- get() {
21
- const rules = [];
22
- if (this.enterRules) {
23
- rules.push(
24
- StudyEngine.ifThen(StudyEngine.checkEventType('ENTER'), ...this.enterRules)
25
- );
26
- }
27
- if (this.submitRules) {
28
- rules.push(
29
- StudyEngine.ifThen(StudyEngine.checkEventType('SUBMIT'), ...this.submitRules)
30
- );
31
- }
32
- if (this.timerRules) {
33
- rules.push(
34
- StudyEngine.ifThen(StudyEngine.checkEventType('TIMER'), ...this.timerRules)
35
- );
36
- }
37
- return rules;
38
- }
39
- }
@@ -1,83 +0,0 @@
1
- import { SurveyGroupItem, SurveyItem } from "survey-engine/lib/data_types";
2
- import { Logger } from "../logger/logger";
3
- import { ItemEditor } from "../survey-editor/item-editor";
4
- import { SurveyEditor } from "../survey-editor/survey-editor";
5
- import { generateLocStrings } from "../utils/simple-generators";
6
-
7
- export interface SurveyProps {
8
- surveyKey: string;
9
- name: Map<string, string>;
10
- description: Map<string, string>;
11
- durationText: Map<string, string>;
12
- // max item per page
13
- // set prefill rules
14
- // set context rules
15
- }
16
-
17
-
18
- export abstract class SurveyDefinition {
19
- key: string;
20
- editor: SurveyEditor;
21
-
22
- constructor(props: SurveyProps) {
23
- this.editor = new SurveyEditor();
24
- this.editor.changeItemKey('survey', props.surveyKey);
25
- this.key = props.surveyKey;
26
-
27
- // define name and description of the survey
28
- this.editor.setSurveyName(generateLocStrings(
29
- props.name
30
- ));
31
-
32
- this.editor.setSurveyDescription(generateLocStrings(
33
- props.description
34
- ));
35
-
36
- this.editor.setSurveyDuration(generateLocStrings(
37
- props.durationText
38
- ));
39
-
40
- const rootItemEditor = new ItemEditor(this.editor.findSurveyItem(props.surveyKey) as SurveyGroupItem);
41
- rootItemEditor.setSelectionMethod({ name: 'sequential' });
42
- this.editor.updateSurveyItem(rootItemEditor.getItem());
43
- }
44
-
45
- abstract buildSurvey(): void;
46
-
47
- getSurvey() {
48
- this.buildSurvey();
49
- this.checkDuplicateChildKeys();
50
- return this.editor.getSurvey();
51
- }
52
-
53
- getSurveyJSON(pretty?: boolean) {
54
- this.buildSurvey();
55
- this.checkDuplicateChildKeys();
56
- return this.editor.getSurveyJSON(pretty);
57
- }
58
-
59
- addItem(item: SurveyItem) {
60
- this.editor.addExistingSurveyItem(item, this.key);
61
- }
62
-
63
- addSurveyItemToPath(item: SurveyItem, parentKey: string) {
64
- this.editor.addExistingSurveyItem(item, parentKey);
65
- }
66
-
67
- private checkDuplicateChildKeys() {
68
- const group = this.editor.getSurvey().current.surveyDefinition;
69
- const keys = group.items.map(item => item.key);
70
- const hasDuplicates = keys.some((key, index) => {
71
- const isDuplicateKey = keys.indexOf(key) !== index;
72
- if (isDuplicateKey) {
73
- Logger.error('Duplicate key:');
74
- Logger.criticalError(`${key} is used twice (at index ${keys.indexOf(key)} and at index ${index})`);
75
- }
76
- return isDuplicateKey;
77
- });
78
- if (hasDuplicates) {
79
- Logger.error('\nSurvey item contains duplicate keys.\nPlease check the lines above for more infos.\nProcess stopped prematurely.')
80
- process.exit(1)
81
- }
82
- }
83
- }
@@ -1,122 +0,0 @@
1
- import { Expression, ItemComponent } from "survey-engine/lib/data_types"
2
- import { OptionDef, StyledTextComponentProp } from "./question-type-generator"
3
- import { generateRandomKey } from "./randomKeyGenerator"
4
- import { generateLocStrings } from "./simple-generators"
5
-
6
- interface CommonProps {
7
- key?: string,
8
- content?: Map<string, string> | StyledTextComponentProp[];
9
- displayCondition?: Expression;
10
- }
11
-
12
- interface OptionProps extends CommonProps {
13
- key: string;
14
- disabled?: Expression;
15
- className?: string;
16
- }
17
-
18
- interface OptionTextProps extends CommonProps {
19
- key: string;
20
- className?: string;
21
- }
22
-
23
- const option = (props: OptionProps): OptionDef => {
24
- const styles = [];
25
- if (props.className !== undefined) {
26
- styles.push({
27
- key: 'className', value: props.className
28
- })
29
- }
30
-
31
- return {
32
- key: props.key,
33
- role: 'option',
34
- content: !Array.isArray(props.content) ? props.content : undefined,
35
- items: Array.isArray(props.content) ? props.content : undefined,
36
- displayCondition: props.displayCondition,
37
- disabled: props.disabled,
38
- style: styles,
39
- }
40
- }
41
-
42
- const multipleChoiceOptionSubtitle = (props: OptionTextProps): OptionDef => {
43
- const styles = [];
44
- if (props.className !== undefined) {
45
- styles.push({
46
- key: 'className', value: props.className
47
- })
48
- }
49
- return {
50
- key: props.key,
51
- role: 'text',
52
- content: !Array.isArray(props.content) ? props.content : undefined,
53
- displayCondition: props.displayCondition,
54
- style: styles,
55
- }
56
- }
57
-
58
- interface TextProps extends CommonProps {
59
- content: Map<string, string>;
60
- variant?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'li';
61
- className?: string;
62
- }
63
-
64
- const text = (props: TextProps): ItemComponent => {
65
- const styles = [];
66
- if (props.className !== undefined) {
67
- styles.push({
68
- key: 'className', value: props.className
69
- })
70
- }
71
- if (props.variant !== undefined) {
72
- styles.push({
73
- key: 'variant', value: props.variant
74
- })
75
- }
76
- return {
77
- key: generateRandomKey(3),
78
- role: 'text',
79
- style: styles.length > 0 ? styles : undefined,
80
- content: generateLocStrings(props.content),
81
- displayCondition: props.displayCondition,
82
- }
83
- }
84
-
85
- interface MarkdownProps extends CommonProps {
86
- content: Map<string, string>;
87
- className?: string;
88
- }
89
-
90
- const markdown = (props: MarkdownProps): ItemComponent => {
91
- const styles = [];
92
- if (props.className !== undefined) {
93
- styles.push({
94
- key: 'className', value: props.className
95
- })
96
- }
97
- return {
98
- key: generateRandomKey(3),
99
- role: 'markdown',
100
- style: styles.length > 0 ? styles : undefined,
101
- content: generateLocStrings(props.content),
102
- displayCondition: props.displayCondition,
103
- }
104
- }
105
-
106
- const footnote = (props: {
107
- content: Map<string, string>;
108
- }): ItemComponent => {
109
- return {
110
- role: 'footnote', content: generateLocStrings(props.content), style: [
111
- { key: 'className', value: 'fs-small fst-italic text-center' }
112
- ]
113
- }
114
- }
115
-
116
- export const ComponentGenerators = {
117
- option,
118
- multipleChoiceOptionSubtitle,
119
- footnote,
120
- text,
121
- markdown,
122
- }