case-editor-tools 1.0.0-beta.3 → 1.0.0-beta.30

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 (130) hide show
  1. package/{build/constants → constants}/key-definitions.d.ts +1 -0
  2. package/{build/constants → constants}/key-definitions.js +3 -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 +37 -7
  11. package/{build/expression-utils → expression-utils}/studyEngineExpressions.js +93 -4
  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-c6933791.js} +69 -51
  17. package/item-editor-c6933791.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 +28 -0
  27. package/surveys/index.js.map +1 -0
  28. package/surveys/responseTypeGenerators/likertGroupComponents.d.ts +27 -0
  29. package/surveys/responseTypeGenerators/likertGroupComponents.js +347 -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 +99 -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 +125 -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 +1 -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} +9 -2
  50. package/{build/expression-utils/surveyEngineExpressions.js → surveys/survey-engine-expressions.js} +36 -4
  51. package/{build/expression-utils/surveyEngineExpressions.js.map → surveys/survey-engine-expressions.js.map} +1 -1
  52. package/surveys/survey-items.d.ts +66 -0
  53. package/surveys/survey-items.js +302 -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 +5 -5
  57. package/{build → surveys}/types/group.js.map +0 -0
  58. package/surveys/types/index.d.ts +4 -0
  59. package/surveys/types/index.js +20 -0
  60. package/surveys/types/index.js.map +1 -0
  61. package/surveys/types/item-properties.d.ts +189 -0
  62. package/surveys/types/item-properties.js +3 -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} +19 -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 +58 -0
  72. package/{build → surveys}/utils/componentGenerators.js.map +1 -1
  73. package/surveys/utils/optionDefGenerators.d.ts +69 -0
  74. package/surveys/utils/optionDefGenerators.js +169 -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 +2 -2
  80. package/{build → surveys}/utils/simple-generators.js +5 -5
  81. package/{build → surveys}/utils/simple-generators.js.map +0 -0
  82. package/{build → surveys}/utils/simple-question-editor.d.ts +3 -3
  83. package/{build → surveys}/utils/simple-question-editor.js +7 -6
  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 +1 -1
  95. package/{build/types → types}/studyRules.js +0 -0
  96. package/{build/types → types}/studyRules.js.map +0 -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/surveyDefinition.js.map +0 -1
  103. package/build/utils/componentGenerators.js +0 -92
  104. package/build/utils/question-type-generator.d.ts +0 -283
  105. package/build/utils/question-type-generator.js +0 -949
  106. package/build/utils/question-type-generator.js.map +0 -1
  107. package/rollup.config.js +0 -53
  108. package/src/constants/key-definitions.ts +0 -13
  109. package/src/expression-utils/expressionGen.ts +0 -28
  110. package/src/expression-utils/studyEngineExpressions.ts +0 -359
  111. package/src/expression-utils/surveyEngineExpressions.ts +0 -483
  112. package/src/index.ts +0 -1
  113. package/src/logger/logger.ts +0 -31
  114. package/src/survey-editor/component-editor.ts +0 -133
  115. package/src/survey-editor/data-types.ts +0 -18
  116. package/src/survey-editor/item-editor.ts +0 -528
  117. package/src/survey-editor/survey-editor.ts +0 -260
  118. package/src/types/duration.ts +0 -32
  119. package/src/types/expression.ts +0 -22
  120. package/src/types/group.ts +0 -73
  121. package/src/types/item.ts +0 -42
  122. package/src/types/study.ts +0 -17
  123. package/src/types/studyRules.ts +0 -39
  124. package/src/types/surveyDefinition.ts +0 -83
  125. package/src/utils/componentGenerators.ts +0 -122
  126. package/src/utils/question-type-generator.ts +0 -1516
  127. package/src/utils/randomKeyGenerator.ts +0 -11
  128. package/src/utils/simple-generators.ts +0 -106
  129. package/src/utils/simple-question-editor.ts +0 -52
  130. package/tsconfig.json +0 -100
@@ -1,528 +0,0 @@
1
- import { SurveyItem, SurveyGroupItem, SurveyItemTypes, Expression, Validation, ItemComponent, SurveySingleItem, ItemGroupComponent, ExpressionName, ResponseComponent, isItemGroupComponent } from "survey-engine/lib/data_types";
2
- import { NewItemProps, NewComponentProps } from "./data-types";
3
- import { ComponentEditor } from "./component-editor";
4
- import { generateRandomKey } from "../utils/randomKeyGenerator";
5
-
6
-
7
- interface ItemEditorInt {
8
- getItem: () => SurveyItem;
9
- getItemJSON: (pretty?: boolean) => string;
10
-
11
- setKey: (newKey: string) => void;
12
-
13
- addToFollows: (key: string) => void;
14
- removeFromFollows: (key: string) => void;
15
- clearFollows: () => void;
16
-
17
- setCondition: (exp: Expression | undefined) => void;
18
- setPriority: (prio: number | undefined) => void;
19
-
20
- setVersion: (version: number) => void;
21
- setVersionTags: (tags: string[]) => void;
22
-
23
- // methods for survey group items:
24
- addSurveyItem: (item: SurveyItem, atPosition?: number) => void;
25
- updateSurveyItem: (item: SurveyItem) => void;
26
- removeItem: (key: string) => void;
27
- changeItemPosition: (key: string, newPosition: number) => void;
28
-
29
- setSelectionMethod: (exp: Expression | undefined) => void;
30
-
31
- // methods for survey single items:
32
- setItemType: (type: SurveyItemTypes) => void;
33
-
34
- // fixed components:
35
- setTitleComponent: (title: ItemComponent) => void;
36
- setHelpGroupComponent: (helpGroup: ItemGroupComponent) => void;
37
- // for warning, error, texts:
38
- addDisplayComponent: (comp: ItemComponent, atPosition?: number) => void;
39
- updateDisplayComponent: (at: number, comp: ItemComponent) => void;
40
- removeDisplayComponent: (at: number) => void;
41
- // response components:
42
- addNewResponseComponent: (props: NewComponentProps, parentKey?: string, atPosition?: number) => ItemComponent | undefined;
43
- addExistingResponseComponent: (newComp: ItemComponent, parentKey?: string, atPosition?: number) => ItemComponent | undefined;
44
- updateResponseComponent: (path: string, item: ItemComponent) => void;
45
- removeResponseComponent: (key: string) => void;
46
- findResponseComponent: (key: string) => ItemComponent | undefined;
47
-
48
- addValidation: (v: Validation) => void;
49
- removeValidation: (vKey: string) => void;
50
- }
51
-
52
- const initialRootComp = () => {
53
- return {
54
- role: 'root',
55
- order: { name: 'sequential' as ExpressionName },
56
- items: []
57
- }
58
- };
59
-
60
- export class ItemEditor implements ItemEditorInt {
61
- private surveyItem: SurveyItem;
62
-
63
- constructor(existingItem?: SurveyItem, newItem?: NewItemProps) {
64
- this.surveyItem = { key: '', version: 0 };
65
- if (existingItem) {
66
- this.surveyItem = { ...existingItem };
67
- // console.log(this.surveyItem);
68
- } else {
69
- const key = newItem?.itemKey ? newItem.itemKey : 'no key';
70
- if (newItem?.isGroup) {
71
- const currentItem: SurveyGroupItem = {
72
- key,
73
- version: 1,
74
- items: [],
75
- }
76
- this.surveyItem = currentItem;
77
- } else {
78
- const currentItem: SurveyItem = {
79
- key,
80
- version: 1,
81
- }
82
- if (newItem?.type) {
83
- currentItem.type = newItem.type;
84
- }
85
- this.surveyItem = currentItem;
86
- }
87
- }
88
- }
89
-
90
- getItem(): SurveyItem {
91
- return { ...this.surveyItem };
92
- }
93
-
94
- getItemJSON(pretty?: boolean): string {
95
- return JSON.stringify(this.surveyItem, undefined, pretty ? ' ' : undefined);
96
- }
97
-
98
- setKey(newKey: string) {
99
- this.surveyItem.key = newKey;
100
- }
101
-
102
- addToFollows(key: string) {
103
- if (!this.surveyItem.follows) {
104
- this.surveyItem.follows = [];
105
- }
106
- if (this.surveyItem.follows.includes(key)) {
107
- console.warn('follows array already includes key: ', key);
108
- return;
109
- }
110
- this.surveyItem.follows.push(key);
111
- }
112
-
113
- removeFromFollows(key: string) {
114
- if (!this.surveyItem.follows) {
115
- console.warn('follows array already empty');
116
- return
117
- }
118
- if (!this.surveyItem.follows.includes(key)) {
119
- console.warn('follows array does not include key: ', key);
120
- return
121
- }
122
- this.surveyItem.follows = this.surveyItem.follows.filter(k => k !== key);
123
- };
124
-
125
- clearFollows() {
126
- if (!this.surveyItem.follows) {
127
- console.warn('follows array already empty');
128
- return
129
- }
130
- this.surveyItem.follows = undefined;
131
- };
132
-
133
- setCondition(exp: Expression | undefined) {
134
- this.surveyItem.condition = exp;
135
- };
136
-
137
- setPriority(prio: number | undefined) {
138
- this.surveyItem.priority = prio;
139
- };
140
-
141
- setVersion(version: number) {
142
- this.surveyItem.version = version;
143
- };
144
-
145
- setVersionTags(tags: string[]) {
146
- this.surveyItem.versionTags = [...tags];
147
- };
148
-
149
- // methods for survey group items:
150
- addSurveyItem(item: SurveyItem, atPosition?: number) {
151
- if (atPosition !== undefined) {
152
- (this.surveyItem as SurveyGroupItem).items.splice(atPosition, 0, { ...item });
153
- } else {
154
- (this.surveyItem as SurveyGroupItem).items.push({ ...item });
155
- }
156
- };
157
-
158
- updateSurveyItem(item: SurveyItem) {
159
- const ind = (this.surveyItem as SurveyGroupItem).items.findIndex(it => item.key === it.key);
160
- if (ind < 0) {
161
- console.warn('item not found in the items array');
162
- return;
163
- }
164
- (this.surveyItem as SurveyGroupItem).items[ind] = { ...item };
165
- };
166
-
167
- removeItem(key: string) {
168
- if (!(this.surveyItem as SurveyGroupItem).items.find(it => it.key === key)) {
169
- console.warn('group items does not contain item with key: ', key);
170
- return;
171
- }
172
- (this.surveyItem as SurveyGroupItem).items = (this.surveyItem as SurveyGroupItem).items.filter(it => it.key !== key);
173
- };
174
-
175
- changeItemPosition(key: string, newPosition: number) {
176
- console.warn('unimplemented');
177
- };
178
-
179
- setSelectionMethod(exp: Expression | undefined) {
180
- (this.surveyItem as SurveyGroupItem).selectionMethod = exp;
181
- };
182
-
183
-
184
- // methods for survey single items:
185
- setItemType(type: SurveyItemTypes) {
186
- (this.surveyItem as SurveySingleItem).type = type;
187
- };
188
-
189
- setTitleComponent(title: ItemComponent) {
190
- const currentItem = (this.surveyItem as SurveySingleItem);
191
- if (!currentItem.components) {
192
- currentItem.components = { ...initialRootComp() }
193
- }
194
- title.role = 'title';
195
- const ind = currentItem.components.items.findIndex(comp => comp.role === 'title');
196
- if (ind < 0) {
197
- currentItem.components.items.push({ ...title });
198
- return;
199
- }
200
- currentItem.components.items[ind] = { ...title };
201
- }
202
-
203
- setHelpGroupComponent(helpGroup: ItemGroupComponent) {
204
- const currentItem = (this.surveyItem as SurveySingleItem);
205
- if (!currentItem.components) {
206
- currentItem.components = { ...initialRootComp() }
207
- }
208
- helpGroup.role = 'helpGroup';
209
- const ind = currentItem.components.items.findIndex(comp => comp.role === 'helpGroup');
210
- if (ind < 0) {
211
- currentItem.components.items.push({ ...helpGroup });
212
- return;
213
- }
214
- currentItem.components.items[ind] = { ...helpGroup };
215
- };
216
-
217
- // for warning, error, texts:
218
- addDisplayComponent(comp: ItemComponent, atPosition?: number) {
219
- const currentItem = (this.surveyItem as SurveySingleItem);
220
- if (!currentItem.components) {
221
- currentItem.components = { ...initialRootComp() }
222
- }
223
- if (atPosition !== undefined) {
224
- currentItem.components.items.splice(atPosition, 0, { ...comp });
225
- } else {
226
- currentItem.components.items.push({ ...comp });
227
- }
228
- };
229
-
230
- updateDisplayComponent(at: number, comp: ItemComponent) {
231
- const currentItem = (this.surveyItem as SurveySingleItem);
232
- if (!currentItem.components || !currentItem.components.items || currentItem.components.items.length <= at + 1 || at < 0) {
233
- console.warn('component not found at ', at);
234
- return;
235
- }
236
- currentItem.components.items[at] = { ...comp };
237
- };
238
-
239
- removeDisplayComponent(at: number) {
240
- const currentItem = (this.surveyItem as SurveySingleItem);
241
- if (!currentItem.components || !currentItem.components.items || currentItem.components.items.length <= at + 1 || at < 0) {
242
- console.warn('component not found at ', at);
243
- return;
244
- }
245
- currentItem.components.items.splice(at, 1);
246
- };
247
-
248
- addNewResponseComponent(props: NewComponentProps, parentKey?: string, atPosition?: number): ItemComponent | undefined {
249
- const currentItem = (this.surveyItem as SurveySingleItem);
250
- if (!currentItem.components) {
251
- currentItem.components = { ...initialRootComp() }
252
- }
253
-
254
- if (!parentKey) {
255
- props.role = 'responseGroup';
256
- if (!props.key) {
257
- props.key = 'rg';
258
- }
259
- props.isGroup = true;
260
- const newComponent = (new ComponentEditor(undefined, props)).getComponent() as ItemGroupComponent;
261
- const ind = currentItem.components.items.findIndex(comp => comp.role === 'responseGroup');
262
- if (ind < 0) {
263
- currentItem.components.items.push(newComponent);
264
- return { ...newComponent };
265
- }
266
- currentItem.components.items[ind] = newComponent;
267
- return { ...newComponent };
268
- }
269
-
270
- const ids = parentKey.split('.');
271
-
272
- let obj: ItemComponent | undefined = undefined;
273
- for (const currentKey of ids) {
274
- if (!obj) {
275
- const ind = currentItem.components.items.findIndex(c => c.key === currentKey);
276
- if (ind < 0) {
277
- console.warn('response component not found: ', currentKey);
278
- return;
279
- }
280
- obj = currentItem.components.items[ind] as ResponseComponent;
281
- continue;
282
- }
283
- if (!isItemGroupComponent(obj)) {
284
- (obj as ItemGroupComponent).items = [];
285
- // leaf found
286
- break;
287
- }
288
- const index = obj.items.findIndex(it => it.key === currentKey);
289
- if (index < 0) {
290
- console.warn('item component cannot be found: ', currentKey);
291
- return;
292
- }
293
- obj = (obj.items[index] as ItemGroupComponent);
294
- }
295
- if (!obj) {
296
- console.warn('survey item cannot be found: ', parentKey);
297
- return
298
- }
299
-
300
- if ((obj as ItemGroupComponent).items.find(it => props.key === it.key)) {
301
- console.error('item already exists with key: ', props.key);
302
- return undefined;
303
- }
304
-
305
- const newComponent = (new ComponentEditor(undefined, props)).getComponent() as ResponseComponent;
306
- if (atPosition !== undefined) {
307
- (obj as ItemGroupComponent).items.splice(atPosition, 0, newComponent);
308
- } else {
309
- (obj as ItemGroupComponent).items.push(newComponent);
310
- }
311
- return newComponent;
312
- };
313
-
314
- addExistingResponseComponent(newComp: ItemComponent, parentKey?: string, atPosition?: number): ItemComponent | undefined {
315
- const currentItem = (this.surveyItem as SurveySingleItem);
316
- if (!currentItem.components) {
317
- currentItem.components = { ...initialRootComp() }
318
- }
319
-
320
- if (newComp.key === undefined) {
321
- newComp.key = generateRandomKey(4);
322
- }
323
-
324
- if (!parentKey) {
325
- const ind = currentItem.components.items.findIndex(comp => comp.role === 'responseGroup');
326
- if (ind < 0) {
327
- currentItem.components.items.push(newComp);
328
- return { ...newComp };
329
- }
330
- currentItem.components.items[ind] = newComp;
331
- return { ...newComp };
332
- }
333
-
334
- const ids = parentKey.split('.');
335
-
336
- let obj: ItemComponent | undefined = undefined;
337
- for (const currentKey of ids) {
338
- if (!obj) {
339
- const ind = currentItem.components.items.findIndex(c => c.key === currentKey);
340
- if (ind < 0) {
341
- console.warn('response component not found: ', currentKey);
342
- return;
343
- }
344
- obj = currentItem.components.items[ind] as ResponseComponent;
345
- continue;
346
- }
347
- if (!isItemGroupComponent(obj)) {
348
- (obj as ItemGroupComponent).items = [];
349
- // leaf found
350
- break;
351
- }
352
- const index = obj.items.findIndex(it => it.key === currentKey);
353
- if (index < 0) {
354
- console.warn('item component cannot be found: ', currentKey);
355
- return;
356
- }
357
- obj = (obj.items[index] as ItemGroupComponent);
358
- }
359
- if (!obj) {
360
- console.warn('item component cannot be found: ', parentKey);
361
- return
362
- }
363
-
364
- if ((obj as ItemGroupComponent).items.find(it => newComp.key === it.key)) {
365
- console.error('item already exists with key: ', newComp.key);
366
- return undefined;
367
- }
368
-
369
- if (atPosition !== undefined) {
370
- (obj as ItemGroupComponent).items.splice(atPosition, 0, newComp);
371
- } else {
372
- (obj as ItemGroupComponent).items.push(newComp);
373
- }
374
- return newComp;
375
- };
376
-
377
- updateResponseComponent(path: string, item: ItemComponent) {
378
-
379
- const currentItem = (this.surveyItem as SurveySingleItem);
380
- if (!currentItem.components) { return; }
381
-
382
- const responseGroup = currentItem.components.items.find(comp => comp.role === 'responseGroup');
383
- if (!responseGroup) {
384
- console.warn('no responseGroup found');
385
- return;
386
- }
387
-
388
- if (responseGroup.key === path) {
389
- const ind = currentItem.components.items.findIndex(it => it.key === path)
390
- if (ind < 0) {
391
- console.warn('item component cannot be found: ', path);
392
- return;
393
- }
394
- currentItem.components.items[ind] = { ...item };
395
- return;
396
- }
397
-
398
- const ids = path.split('.');
399
- const parentIds = ids.slice(1, ids.length - 1);
400
-
401
- let obj: ItemComponent | undefined = responseGroup;
402
- for (const currentKey of parentIds) {
403
- if (!isItemGroupComponent(obj)) {
404
- // leaf found
405
- break;
406
- }
407
- const index = obj.items.findIndex(it => it.key === currentKey);
408
- if (index < 0) {
409
- console.warn('item component cannot be found: ', currentKey);
410
- return;
411
- }
412
- obj = (obj.items[index] as ItemGroupComponent);
413
- }
414
- if (!obj) {
415
- console.warn('survey item cannot be found: ', path);
416
- return
417
- }
418
-
419
- const ind = (obj as ItemGroupComponent).items.findIndex(it => it.key === ids[ids.length - 1])
420
- if (ind < 0) {
421
- console.warn('item component cannot be found: ', path);
422
- return;
423
- }
424
- (obj as ItemGroupComponent).items[ind] = { ...item };
425
- };
426
-
427
- removeResponseComponent(keyPath: string) {
428
- const currentItem = (this.surveyItem as SurveySingleItem);
429
- if (!currentItem.components) { return; }
430
-
431
- const responseGroup = currentItem.components.items.find(comp => comp.role === 'responseGroup');
432
- if (!responseGroup) {
433
- console.warn('no responseGroup found');
434
- return;
435
- }
436
-
437
- if (responseGroup.key === keyPath) {
438
- currentItem.components.items = currentItem.components.items.filter(it => it.role !== 'responseGroup');
439
- return;
440
- }
441
-
442
- const ids = keyPath.split('.');
443
- const parentIds = ids.slice(1, ids.length - 1);
444
-
445
- let obj: ItemComponent | undefined = responseGroup;
446
- for (const currentKey of parentIds) {
447
- if (!isItemGroupComponent(obj)) {
448
- // leaf found
449
- break;
450
- }
451
- const index = obj.items.findIndex(it => it.key === currentKey);
452
- if (index < 0) {
453
- console.warn('item component cannot be found: ', currentKey);
454
- return;
455
- }
456
- obj = (obj.items[index] as ItemGroupComponent);
457
- }
458
- if (!obj) {
459
- console.warn('survey item cannot be found: ', keyPath);
460
- return
461
- }
462
-
463
- (obj as ItemGroupComponent).items = (obj as ItemGroupComponent).items.filter(comp => comp.key !== ids[ids.length - 1]);
464
- };
465
-
466
- findResponseComponent(key: string): ItemComponent | undefined {
467
- const currentItem = (this.surveyItem as SurveySingleItem);
468
- if (!currentItem.components) { return; }
469
-
470
- const ids = key.split('.');
471
-
472
- let obj: ItemComponent | undefined = undefined;
473
- for (const currentKey of ids) {
474
- if (!obj) {
475
- const ind = currentItem.components.items.findIndex(c => c.key === currentKey);
476
- if (ind < 0) {
477
- console.warn('item component not found: ', currentKey);
478
- return;
479
- }
480
- obj = currentItem.components.items[ind] as ResponseComponent;
481
- continue;
482
- }
483
- if (!isItemGroupComponent(obj)) {
484
- (obj as ItemGroupComponent).items = [];
485
- // leaf found
486
- break;
487
- }
488
- const index = obj.items.findIndex(it => it.key === currentKey);
489
- if (index < 0) {
490
- console.warn('item component cannot be found: ', currentKey);
491
- return;
492
- }
493
- obj = (obj.items[index] as ItemGroupComponent);
494
- }
495
- if (!obj) {
496
- console.warn('item component cannot be found: ', key);
497
- return
498
- }
499
- return obj;
500
- };
501
-
502
- addValidation(v: Validation) {
503
- const currentItem = (this.surveyItem as SurveySingleItem);
504
- if (!currentItem.validations) {
505
- currentItem.validations = []
506
- }
507
- if (currentItem.validations.find(valid => v.key === valid.key)) {
508
- console.warn('validation key already used: ', v.key);
509
- return
510
- }
511
- currentItem.validations.push({ ...v });
512
- this.surveyItem = { ...currentItem };
513
- };
514
-
515
- removeValidation(vKey: string) {
516
- const currentItem = (this.surveyItem as SurveySingleItem);
517
- if (!currentItem.validations) {
518
- console.warn('validation key not found used: ', vKey);
519
- return
520
- }
521
- if (currentItem.validations.find(valid => vKey === valid.key)) {
522
- console.warn('validation key not found used: ', vKey);
523
- return
524
- }
525
- currentItem.validations = currentItem.validations.filter(v => v.key !== vKey);
526
- this.surveyItem = { ...currentItem };
527
- };
528
- }