case-editor-tools 1.3.0 → 1.4.1

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 (37) hide show
  1. package/expression-utils/expressionGen.js +8 -1
  2. package/expression-utils/expressionGen.js.map +1 -1
  3. package/expression-utils/studyEngineExpressions.js +2 -0
  4. package/expression-utils/studyEngineExpressions.js.map +1 -1
  5. package/index-8e5154bb.js +79 -0
  6. package/index-8e5154bb.js.map +1 -0
  7. package/package.json +1 -1
  8. package/surveys/index.js +2 -1
  9. package/surveys/index.js.map +1 -1
  10. package/surveys/responseTypeGenerators/matrixGroupComponent.d.ts +4 -5
  11. package/surveys/survey-editor/item-editor.js +457 -6
  12. package/surveys/survey-editor/item-editor.js.map +1 -1
  13. package/surveys/survey-editor/survey-editor.js +7 -6
  14. package/surveys/survey-editor/survey-editor.js.map +1 -1
  15. package/surveys/survey-engine-expressions.js +2 -0
  16. package/surveys/survey-engine-expressions.js.map +1 -1
  17. package/surveys/survey-items.d.ts +3 -3
  18. package/surveys/survey-items.js +2 -1
  19. package/surveys/survey-items.js.map +1 -1
  20. package/surveys/types/group.js +2 -1
  21. package/surveys/types/group.js.map +1 -1
  22. package/surveys/types/index.js +2 -1
  23. package/surveys/types/index.js.map +1 -1
  24. package/surveys/types/survey-definition.d.ts +1 -1
  25. package/surveys/types/survey-definition.js +2 -1
  26. package/surveys/types/survey-definition.js.map +1 -1
  27. package/surveys/utils/componentGenerators.d.ts +3 -4
  28. package/surveys/utils/componentGenerators.js +4 -2
  29. package/surveys/utils/componentGenerators.js.map +1 -1
  30. package/surveys/utils/optionDefGenerators.js +2 -0
  31. package/surveys/utils/optionDefGenerators.js.map +1 -1
  32. package/surveys/utils/simple-question-editor.js +2 -1
  33. package/surveys/utils/simple-question-editor.js.map +1 -1
  34. package/types/studyRules.js +2 -0
  35. package/types/studyRules.js.map +1 -1
  36. package/item-editor-b2c1632b.js +0 -535
  37. package/item-editor-b2c1632b.js.map +0 -1
@@ -2,11 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var index = require('../index-8e5154bb.js');
6
+ var logger_logger = require('../logger/logger.js');
7
+
5
8
  const generateExpression = (name, returnType, ...args) => {
6
9
  return {
7
10
  name: name,
8
11
  returnType: returnType,
9
- data: args.filter(a => a !== undefined).map(arg => {
12
+ data: args.filter(a => a !== undefined).map((arg, index$1) => {
10
13
  if (typeof (arg) === 'string') {
11
14
  return {
12
15
  dtype: 'str',
@@ -19,6 +22,10 @@ const generateExpression = (name, returnType, ...args) => {
19
22
  num: arg
20
23
  };
21
24
  }
25
+ if (!index.isExpression(arg)) {
26
+ logger_logger.Logger.criticalError(`Wrong argument type in: ${name} at pos ${index$1}`);
27
+ process.exit(1);
28
+ }
22
29
  return {
23
30
  dtype: 'exp',
24
31
  exp: arg
@@ -1 +1 @@
1
- {"version":3,"file":"expressionGen.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"expressionGen.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -5,6 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var constants_keyDefinitions = require('../constants/key-definitions.js');
6
6
  var types_duration = require('../types/duration.js');
7
7
  var expressionUtils_expressionGen = require('./expressionGen.js');
8
+ require('../index-8e5154bb.js');
9
+ require('../logger/logger.js');
8
10
 
9
11
  const or = (...args) => expressionUtils_expressionGen.generateExpression('or', undefined, ...args);
10
12
  const and = (...args) => expressionUtils_expressionGen.generateExpression('and', undefined, ...args);
@@ -1 +1 @@
1
- {"version":3,"file":"studyEngineExpressions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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+ var data_types = {};
4
+
5
+ var expression = {};
6
+
7
+ Object.defineProperty(expression, '__esModule', { value: true });
8
+
9
+ const isExpression$1 = (value) => {
10
+ return typeof (value) === 'object' && value.name !== undefined && value.name.length > 0;
11
+ };
12
+ const expressionArgParser = (arg) => {
13
+ switch (arg.dtype) {
14
+ case 'num':
15
+ return arg.num;
16
+ case 'str':
17
+ return arg.str;
18
+ case 'exp':
19
+ return arg.exp;
20
+ default:
21
+ return arg.str;
22
+ }
23
+ };
24
+
25
+ expression.expressionArgParser = expressionArgParser;
26
+ expression.isExpression = isExpression$1;
27
+
28
+ var surveyItem = {};
29
+
30
+ Object.defineProperty(surveyItem, '__esModule', { value: true });
31
+
32
+ const isSurveyGroupItem$1 = (item) => {
33
+ const items = item.items;
34
+ return items !== undefined && items.length > 0;
35
+ };
36
+
37
+ surveyItem.isSurveyGroupItem = isSurveyGroupItem$1;
38
+
39
+ var surveyItemComponent = {};
40
+
41
+ Object.defineProperty(surveyItemComponent, '__esModule', { value: true });
42
+
43
+ const isItemGroupComponent$1 = (item) => {
44
+ const items = item.items;
45
+ return items !== undefined && items.length > 0;
46
+ };
47
+
48
+ surveyItemComponent.isItemGroupComponent = isItemGroupComponent$1;
49
+
50
+ var response = {};
51
+
52
+ Object.defineProperty(response, '__esModule', { value: true });
53
+
54
+ const isSurveyGroupItemResponse = (item) => {
55
+ const items = item.items;
56
+ return items !== undefined && items.length > 0;
57
+ };
58
+
59
+ response.isSurveyGroupItemResponse = isSurveyGroupItemResponse;
60
+
61
+ Object.defineProperty(data_types, '__esModule', { value: true });
62
+
63
+ var data_types_expression = expression;
64
+ var data_types_surveyItem = surveyItem;
65
+ var data_types_surveyItemComponent = surveyItemComponent;
66
+ var data_types_response = response;
67
+
68
+
69
+
70
+ data_types.expressionArgParser = data_types_expression.expressionArgParser;
71
+ var isExpression = data_types.isExpression = data_types_expression.isExpression;
72
+ var isSurveyGroupItem = data_types.isSurveyGroupItem = data_types_surveyItem.isSurveyGroupItem;
73
+ var isItemGroupComponent = data_types.isItemGroupComponent = data_types_surveyItemComponent.isItemGroupComponent;
74
+ data_types.isSurveyGroupItemResponse = data_types_response.isSurveyGroupItemResponse;
75
+
76
+ exports.isExpression = isExpression;
77
+ exports.isItemGroupComponent = isItemGroupComponent;
78
+ exports.isSurveyGroupItem = isSurveyGroupItem;
79
+ //# sourceMappingURL=index-8e5154bb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-8e5154bb.js","sources":["../node_modules/survey-engine/data_types/expression.js","../node_modules/survey-engine/data_types/survey-item.js","../node_modules/survey-engine/data_types/survey-item-component.js","../node_modules/survey-engine/data_types/response.js","../node_modules/survey-engine/data_types/index.js"],"sourcesContent":["'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nconst isExpression = (value) => {\r\n return typeof (value) === 'object' && value.name !== undefined && value.name.length > 0;\r\n};\r\nconst expressionArgParser = (arg) => {\r\n switch (arg.dtype) {\r\n case 'num':\r\n return arg.num;\r\n case 'str':\r\n return arg.str;\r\n case 'exp':\r\n return arg.exp;\r\n default:\r\n return arg.str;\r\n }\r\n};\n\nexports.expressionArgParser = expressionArgParser;\nexports.isExpression = isExpression;\n//# sourceMappingURL=expression.js.map\n","'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nconst isSurveyGroupItem = (item) => {\r\n const items = item.items;\r\n return items !== undefined && items.length > 0;\r\n};\n\nexports.isSurveyGroupItem = isSurveyGroupItem;\n//# sourceMappingURL=survey-item.js.map\n","'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nconst isItemGroupComponent = (item) => {\r\n const items = item.items;\r\n return items !== undefined && items.length > 0;\r\n};\n\nexports.isItemGroupComponent = isItemGroupComponent;\n//# sourceMappingURL=survey-item-component.js.map\n","'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nconst isSurveyGroupItemResponse = (item) => {\r\n const items = item.items;\r\n return items !== undefined && items.length > 0;\r\n};\n\nexports.isSurveyGroupItemResponse = isSurveyGroupItemResponse;\n//# sourceMappingURL=response.js.map\n","'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nvar data_types_expression = require('./expression.js');\nvar data_types_surveyItem = require('./survey-item.js');\nvar data_types_surveyItemComponent = require('./survey-item-component.js');\nvar data_types_response = require('./response.js');\n\n\n\nexports.expressionArgParser = data_types_expression.expressionArgParser;\nexports.isExpression = data_types_expression.isExpression;\nexports.isSurveyGroupItem = data_types_surveyItem.isSurveyGroupItem;\nexports.isItemGroupComponent = data_types_surveyItemComponent.isItemGroupComponent;\nexports.isSurveyGroupItemResponse = data_types_response.isSurveyGroupItemResponse;\n//# sourceMappingURL=index.js.map\n"],"names":["isExpression","isSurveyGroupItem","isItemGroupComponent","require$$0","require$$1","require$$2","require$$3"],"mappings":";;;;;;AAEA,MAAM,CAAC,cAAc,CAAC,UAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D;AACA,MAAMA,cAAY,GAAG,CAAC,KAAK,KAAK;AAChC,IAAI,OAAO,QAAQ,KAAK,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5F,CAAC,CAAC;AACF,MAAM,mBAAmB,GAAG,CAAC,GAAG,KAAK;AACrC,IAAI,QAAQ,GAAG,CAAC,KAAK;AACrB,QAAQ,KAAK,KAAK;AAClB,YAAY,OAAO,GAAG,CAAC,GAAG,CAAC;AAC3B,QAAQ,KAAK,KAAK;AAClB,YAAY,OAAO,GAAG,CAAC,GAAG,CAAC;AAC3B,QAAQ,KAAK,KAAK;AAClB,YAAY,OAAO,GAAG,CAAC,GAAG,CAAC;AAC3B,QAAQ;AACR,YAAY,OAAO,GAAG,CAAC,GAAG,CAAC;AAC3B,KAAK;AACL,CAAC,CAAC;AACF;AAC2B,UAAA,CAAA,mBAAA,GAAG,oBAAoB;AAC9B,UA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CAAC;AACxD,IAAI,8BAA8B,GAAGC,mBAAqC,CAAC;AAC3E,IAAI,mBAAmB,GAAGC,QAAwB,CAAC;AACnD;AACA;AACA;AACA,UAAA,CAAA,mBAA2B,GAAG,qBAAqB,CAAC,oBAAoB;AACxE,IAAA,YAAA,GAAA,UAAA,CAAA,YAAoB,GAAG,qBAAqB,CAAC,aAAa;AAC1D,IAAA,iBAAA,GAAA,UAAA,CAAA,iBAAyB,GAAG,qBAAqB,CAAC,kBAAkB;AACpE,IAAA,oBAAA,GAAA,UAAA,CAAA,oBAA4B,GAAG,8BAA8B,CAAC,qBAAqB;AACnF,UAAA,CAAA,yBAAiC,GAAG,mBAAmB,CAAC;;;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "case-editor-tools",
3
3
  "description": "Javascript tools to simplify survey and study coding for CASE.",
4
- "version": "1.3.0",
4
+ "version": "1.4.1",
5
5
  "main": "index.js",
6
6
  "license": "Apache-2.0",
7
7
  "repository": "github:case-framework/case-editor-tools",
package/surveys/index.js CHANGED
@@ -6,7 +6,8 @@ var surveys_surveyItems = require('./survey-items.js');
6
6
  var surveys_utils_optionDefGenerators = require('./utils/optionDefGenerators.js');
7
7
  var surveys_surveyEngineExpressions = require('./survey-engine-expressions.js');
8
8
  require('./survey-editor/component-editor.js');
9
- require('../item-editor-b2c1632b.js');
9
+ require('./survey-editor/item-editor.js');
10
+ require('../index-8e5154bb.js');
10
11
  require('./utils/randomKeyGenerator.js');
11
12
  require('../logger/logger.js');
12
13
  require('./utils/componentGenerators.js');
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { ComponentProperties, Expression, ItemGroupComponent } from "survey-engine/data_types";
2
- interface HeaderRow {
2
+ export interface HeaderRow {
3
3
  role: 'headerRow';
4
4
  key: string;
5
5
  displayCondition?: Expression;
@@ -11,7 +11,7 @@ interface HeaderRow {
11
11
  description?: Map<string, string>;
12
12
  }>;
13
13
  }
14
- interface RadioRow {
14
+ export interface RadioRow {
15
15
  role: 'radioRow';
16
16
  key: string;
17
17
  displayCondition?: Expression;
@@ -37,13 +37,12 @@ export interface ResponseRowCell {
37
37
  displayCondition?: Expression;
38
38
  }>;
39
39
  }
40
- interface ResponseRow {
40
+ export interface ResponseRow {
41
41
  role: 'responseRow';
42
42
  key: string;
43
43
  displayCondition?: Expression;
44
44
  disabled?: Expression;
45
45
  cells: Array<ResponseRowCell>;
46
46
  }
47
- declare type MatrixRow = HeaderRow | RadioRow | ResponseRow;
47
+ export declare type MatrixRow = HeaderRow | RadioRow | ResponseRow;
48
48
  export declare const initMatrixQuestion: (key: string, rows: Array<MatrixRow>, order?: Expression) => ItemGroupComponent;
49
- export {};
@@ -2,12 +2,463 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var surveys_surveyEditor_itemEditor = require('../../item-editor-b2c1632b.js');
6
- require('./component-editor.js');
7
- require('../utils/randomKeyGenerator.js');
8
- require('../../logger/logger.js');
5
+ var index = require('../../index-8e5154bb.js');
6
+ var surveys_surveyEditor_componentEditor = require('./component-editor.js');
7
+ var surveys_utils_randomKeyGenerator = require('../utils/randomKeyGenerator.js');
8
+ var logger_logger = require('../../logger/logger.js');
9
9
 
10
+ const initialRootComp = () => {
11
+ return {
12
+ role: 'root',
13
+ order: { name: 'sequential' },
14
+ items: []
15
+ };
16
+ };
17
+ class ItemEditor {
18
+ constructor(existingItem, newItem) {
19
+ this.surveyItem = { key: '' };
20
+ if (existingItem) {
21
+ this.surveyItem = Object.assign({}, existingItem);
22
+ // console.log(this.surveyItem);
23
+ }
24
+ else {
25
+ const key = (newItem === null || newItem === void 0 ? void 0 : newItem.itemKey) ? newItem.itemKey : 'no key';
26
+ if (newItem === null || newItem === void 0 ? void 0 : newItem.isGroup) {
27
+ const currentItem = {
28
+ key,
29
+ items: [],
30
+ };
31
+ this.surveyItem = currentItem;
32
+ }
33
+ else {
34
+ const currentItem = {
35
+ key,
36
+ };
37
+ if (newItem === null || newItem === void 0 ? void 0 : newItem.type) {
38
+ currentItem.type = newItem.type;
39
+ }
40
+ this.surveyItem = currentItem;
41
+ }
42
+ }
43
+ }
44
+ getItem() {
45
+ return Object.assign({}, this.surveyItem);
46
+ }
47
+ getItemJSON(pretty) {
48
+ return JSON.stringify(this.surveyItem, undefined, pretty ? ' ' : undefined);
49
+ }
50
+ setKey(newKey) {
51
+ this.surveyItem.key = newKey;
52
+ }
53
+ setConfidentialMode(confidentialMode) {
54
+ this.surveyItem.confidentialMode = confidentialMode;
55
+ }
56
+ addToFollows(key) {
57
+ if (!this.surveyItem.follows) {
58
+ this.surveyItem.follows = [];
59
+ }
60
+ if (this.surveyItem.follows.includes(key)) {
61
+ console.warn('follows array already includes key: ', key);
62
+ return;
63
+ }
64
+ this.surveyItem.follows.push(key);
65
+ }
66
+ removeFromFollows(key) {
67
+ if (!this.surveyItem.follows) {
68
+ console.warn('follows array already empty');
69
+ return;
70
+ }
71
+ if (!this.surveyItem.follows.includes(key)) {
72
+ console.warn('follows array does not include key: ', key);
73
+ return;
74
+ }
75
+ this.surveyItem.follows = this.surveyItem.follows.filter(k => k !== key);
76
+ }
77
+ ;
78
+ clearFollows() {
79
+ if (!this.surveyItem.follows) {
80
+ console.warn('follows array already empty');
81
+ return;
82
+ }
83
+ this.surveyItem.follows = undefined;
84
+ }
85
+ ;
86
+ setCondition(exp) {
87
+ this.surveyItem.condition = exp;
88
+ }
89
+ ;
90
+ setPriority(prio) {
91
+ this.surveyItem.priority = prio;
92
+ }
93
+ ;
94
+ setMetadata(data) {
95
+ this.surveyItem.metadata = data;
96
+ }
97
+ // methods for survey group items:
98
+ addSurveyItem(item, atPosition) {
99
+ if (atPosition !== undefined) {
100
+ this.surveyItem.items.splice(atPosition, 0, Object.assign({}, item));
101
+ }
102
+ else {
103
+ this.surveyItem.items.push(Object.assign({}, item));
104
+ }
105
+ }
106
+ ;
107
+ updateSurveyItem(item) {
108
+ const ind = this.surveyItem.items.findIndex(it => item.key === it.key);
109
+ if (ind < 0) {
110
+ console.warn('item not found in the items array');
111
+ return;
112
+ }
113
+ this.surveyItem.items[ind] = Object.assign({}, item);
114
+ }
115
+ ;
116
+ removeItem(key) {
117
+ if (!this.surveyItem.items.find(it => it.key === key)) {
118
+ console.warn('group items does not contain item with key: ', key);
119
+ return;
120
+ }
121
+ this.surveyItem.items = this.surveyItem.items.filter(it => it.key !== key);
122
+ }
123
+ ;
124
+ changeItemPosition(key, newPosition) {
125
+ console.warn('unimplemented');
126
+ }
127
+ ;
128
+ setSelectionMethod(exp) {
129
+ this.surveyItem.selectionMethod = exp;
130
+ }
131
+ ;
132
+ // methods for survey single items:
133
+ setItemType(type) {
134
+ this.surveyItem.type = type;
135
+ }
136
+ ;
137
+ setTitleComponent(title) {
138
+ const currentItem = this.surveyItem;
139
+ if (!currentItem.components) {
140
+ currentItem.components = Object.assign({}, initialRootComp());
141
+ }
142
+ title.role = 'title';
143
+ const ind = currentItem.components.items.findIndex(comp => comp.role === 'title');
144
+ if (ind < 0) {
145
+ currentItem.components.items.push(Object.assign({}, title));
146
+ return;
147
+ }
148
+ currentItem.components.items[ind] = Object.assign({}, title);
149
+ }
150
+ setHelpGroupComponent(helpGroup) {
151
+ const currentItem = this.surveyItem;
152
+ if (!currentItem.components) {
153
+ currentItem.components = Object.assign({}, initialRootComp());
154
+ }
155
+ helpGroup.role = 'helpGroup';
156
+ const ind = currentItem.components.items.findIndex(comp => comp.role === 'helpGroup');
157
+ if (ind < 0) {
158
+ currentItem.components.items.push(Object.assign({}, helpGroup));
159
+ return;
160
+ }
161
+ currentItem.components.items[ind] = Object.assign({}, helpGroup);
162
+ }
163
+ ;
164
+ // for warning, error, texts:
165
+ addDisplayComponent(comp, atPosition) {
166
+ const currentItem = this.surveyItem;
167
+ if (!currentItem.components) {
168
+ currentItem.components = Object.assign({}, initialRootComp());
169
+ }
170
+ if (atPosition !== undefined) {
171
+ currentItem.components.items.splice(atPosition, 0, Object.assign({}, comp));
172
+ }
173
+ else {
174
+ currentItem.components.items.push(Object.assign({}, comp));
175
+ }
176
+ }
177
+ ;
178
+ updateDisplayComponent(at, comp) {
179
+ const currentItem = this.surveyItem;
180
+ if (!currentItem.components || !currentItem.components.items || currentItem.components.items.length <= at + 1 || at < 0) {
181
+ console.warn('component not found at ', at);
182
+ return;
183
+ }
184
+ currentItem.components.items[at] = Object.assign({}, comp);
185
+ }
186
+ ;
187
+ removeDisplayComponent(at) {
188
+ const currentItem = this.surveyItem;
189
+ if (!currentItem.components || !currentItem.components.items || currentItem.components.items.length <= at + 1 || at < 0) {
190
+ console.warn('component not found at ', at);
191
+ return;
192
+ }
193
+ currentItem.components.items.splice(at, 1);
194
+ }
195
+ ;
196
+ addNewResponseComponent(props, parentKey, atPosition) {
197
+ const currentItem = this.surveyItem;
198
+ if (!currentItem.components) {
199
+ currentItem.components = Object.assign({}, initialRootComp());
200
+ }
201
+ if (!parentKey) {
202
+ props.role = 'responseGroup';
203
+ if (!props.key) {
204
+ props.key = 'rg';
205
+ }
206
+ props.isGroup = true;
207
+ const newComponent = (new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, props)).getComponent();
208
+ const ind = currentItem.components.items.findIndex(comp => comp.role === 'responseGroup');
209
+ if (ind < 0) {
210
+ currentItem.components.items.push(newComponent);
211
+ return Object.assign({}, newComponent);
212
+ }
213
+ currentItem.components.items[ind] = newComponent;
214
+ return Object.assign({}, newComponent);
215
+ }
216
+ const ids = parentKey.split('.');
217
+ let obj = undefined;
218
+ for (const currentKey of ids) {
219
+ if (!obj) {
220
+ const ind = currentItem.components.items.findIndex(c => c.key === currentKey);
221
+ if (ind < 0) {
222
+ console.warn('response component not found: ', currentKey);
223
+ return;
224
+ }
225
+ obj = currentItem.components.items[ind];
226
+ continue;
227
+ }
228
+ if (!index.isItemGroupComponent(obj)) {
229
+ obj.items = [];
230
+ // leaf found
231
+ break;
232
+ }
233
+ const index$1 = obj.items.findIndex(it => it.key === currentKey);
234
+ if (index$1 < 0) {
235
+ console.warn('item component cannot be found: ', currentKey);
236
+ return;
237
+ }
238
+ obj = obj.items[index$1];
239
+ }
240
+ if (!obj) {
241
+ console.warn('survey item cannot be found: ', parentKey);
242
+ return;
243
+ }
244
+ if (obj.items.find(it => props.key === it.key)) {
245
+ logger_logger.Logger.criticalError('Duplicate key: ' + props.key);
246
+ return undefined;
247
+ }
248
+ const newComponent = (new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, props)).getComponent();
249
+ if (atPosition !== undefined) {
250
+ obj.items.splice(atPosition, 0, newComponent);
251
+ }
252
+ else {
253
+ obj.items.push(newComponent);
254
+ }
255
+ return newComponent;
256
+ }
257
+ ;
258
+ addExistingResponseComponent(newComp, parentKey, atPosition) {
259
+ const currentItem = this.surveyItem;
260
+ if (!currentItem.components) {
261
+ currentItem.components = Object.assign({}, initialRootComp());
262
+ }
263
+ if (newComp.key === undefined) {
264
+ newComp.key = surveys_utils_randomKeyGenerator.generateRandomKey(4);
265
+ }
266
+ if (!parentKey) {
267
+ const ind = currentItem.components.items.findIndex(comp => comp.role === 'responseGroup');
268
+ if (ind < 0) {
269
+ currentItem.components.items.push(newComp);
270
+ return Object.assign({}, newComp);
271
+ }
272
+ currentItem.components.items[ind] = newComp;
273
+ return Object.assign({}, newComp);
274
+ }
275
+ const ids = parentKey.split('.');
276
+ let obj = undefined;
277
+ for (const currentKey of ids) {
278
+ if (!obj) {
279
+ const ind = currentItem.components.items.findIndex(c => c.key === currentKey);
280
+ if (ind < 0) {
281
+ console.warn('response component not found: ', currentKey);
282
+ return;
283
+ }
284
+ obj = currentItem.components.items[ind];
285
+ continue;
286
+ }
287
+ if (!index.isItemGroupComponent(obj)) {
288
+ obj.items = [];
289
+ // leaf found
290
+ break;
291
+ }
292
+ const index$1 = obj.items.findIndex(it => it.key === currentKey);
293
+ if (index$1 < 0) {
294
+ console.warn('item component cannot be found: ', currentKey);
295
+ return;
296
+ }
297
+ obj = obj.items[index$1];
298
+ }
299
+ if (!obj) {
300
+ console.warn('item component cannot be found: ', parentKey);
301
+ return;
302
+ }
303
+ if (obj.items.find(it => newComp.key === it.key)) {
304
+ logger_logger.Logger.criticalError('Duplicate key: ' + newComp.key);
305
+ return undefined;
306
+ }
307
+ if (atPosition !== undefined) {
308
+ obj.items.splice(atPosition, 0, newComp);
309
+ }
310
+ else {
311
+ obj.items.push(newComp);
312
+ }
313
+ return newComp;
314
+ }
315
+ ;
316
+ updateResponseComponent(path, item) {
317
+ const currentItem = this.surveyItem;
318
+ if (!currentItem.components) {
319
+ return;
320
+ }
321
+ const responseGroup = currentItem.components.items.find(comp => comp.role === 'responseGroup');
322
+ if (!responseGroup) {
323
+ console.warn('no responseGroup found');
324
+ return;
325
+ }
326
+ if (responseGroup.key === path) {
327
+ const ind = currentItem.components.items.findIndex(it => it.key === path);
328
+ if (ind < 0) {
329
+ console.warn('item component cannot be found: ', path);
330
+ return;
331
+ }
332
+ currentItem.components.items[ind] = Object.assign({}, item);
333
+ return;
334
+ }
335
+ const ids = path.split('.');
336
+ const parentIds = ids.slice(1, ids.length - 1);
337
+ let obj = responseGroup;
338
+ for (const currentKey of parentIds) {
339
+ if (!index.isItemGroupComponent(obj)) {
340
+ // leaf found
341
+ break;
342
+ }
343
+ const index$1 = obj.items.findIndex(it => it.key === currentKey);
344
+ if (index$1 < 0) {
345
+ console.warn('item component cannot be found: ', currentKey);
346
+ return;
347
+ }
348
+ obj = obj.items[index$1];
349
+ }
350
+ if (!obj) {
351
+ console.warn('survey item cannot be found: ', path);
352
+ return;
353
+ }
354
+ const ind = obj.items.findIndex(it => it.key === ids[ids.length - 1]);
355
+ if (ind < 0) {
356
+ console.warn('item component cannot be found: ', path);
357
+ return;
358
+ }
359
+ obj.items[ind] = Object.assign({}, item);
360
+ }
361
+ ;
362
+ removeResponseComponent(keyPath) {
363
+ const currentItem = this.surveyItem;
364
+ if (!currentItem.components) {
365
+ return;
366
+ }
367
+ const responseGroup = currentItem.components.items.find(comp => comp.role === 'responseGroup');
368
+ if (!responseGroup) {
369
+ console.warn('no responseGroup found');
370
+ return;
371
+ }
372
+ if (responseGroup.key === keyPath) {
373
+ currentItem.components.items = currentItem.components.items.filter(it => it.role !== 'responseGroup');
374
+ return;
375
+ }
376
+ const ids = keyPath.split('.');
377
+ const parentIds = ids.slice(1, ids.length - 1);
378
+ let obj = responseGroup;
379
+ for (const currentKey of parentIds) {
380
+ if (!index.isItemGroupComponent(obj)) {
381
+ // leaf found
382
+ break;
383
+ }
384
+ const index$1 = obj.items.findIndex(it => it.key === currentKey);
385
+ if (index$1 < 0) {
386
+ console.warn('item component cannot be found: ', currentKey);
387
+ return;
388
+ }
389
+ obj = obj.items[index$1];
390
+ }
391
+ if (!obj) {
392
+ console.warn('survey item cannot be found: ', keyPath);
393
+ return;
394
+ }
395
+ obj.items = obj.items.filter(comp => comp.key !== ids[ids.length - 1]);
396
+ }
397
+ ;
398
+ findResponseComponent(key) {
399
+ const currentItem = this.surveyItem;
400
+ if (!currentItem.components) {
401
+ return;
402
+ }
403
+ const ids = key.split('.');
404
+ let obj = undefined;
405
+ for (const currentKey of ids) {
406
+ if (!obj) {
407
+ const ind = currentItem.components.items.findIndex(c => c.key === currentKey);
408
+ if (ind < 0) {
409
+ console.warn('item component not found: ', currentKey);
410
+ return;
411
+ }
412
+ obj = currentItem.components.items[ind];
413
+ continue;
414
+ }
415
+ if (!index.isItemGroupComponent(obj)) {
416
+ obj.items = [];
417
+ // leaf found
418
+ break;
419
+ }
420
+ const index$1 = obj.items.findIndex(it => it.key === currentKey);
421
+ if (index$1 < 0) {
422
+ console.warn('item component cannot be found: ', currentKey);
423
+ return;
424
+ }
425
+ obj = obj.items[index$1];
426
+ }
427
+ if (!obj) {
428
+ console.warn('item component cannot be found: ', key);
429
+ return;
430
+ }
431
+ return obj;
432
+ }
433
+ ;
434
+ addValidation(v) {
435
+ const currentItem = this.surveyItem;
436
+ if (!currentItem.validations) {
437
+ currentItem.validations = [];
438
+ }
439
+ if (currentItem.validations.find(valid => v.key === valid.key)) {
440
+ console.warn('validation key already used: ', v.key);
441
+ return;
442
+ }
443
+ currentItem.validations.push(Object.assign({}, v));
444
+ this.surveyItem = Object.assign({}, currentItem);
445
+ }
446
+ ;
447
+ removeValidation(vKey) {
448
+ const currentItem = this.surveyItem;
449
+ if (!currentItem.validations) {
450
+ console.warn('validation key not found used: ', vKey);
451
+ return;
452
+ }
453
+ if (currentItem.validations.find(valid => vKey === valid.key)) {
454
+ console.warn('validation key not found used: ', vKey);
455
+ return;
456
+ }
457
+ currentItem.validations = currentItem.validations.filter(v => v.key !== vKey);
458
+ this.surveyItem = Object.assign({}, currentItem);
459
+ }
460
+ ;
461
+ }
10
462
 
11
-
12
- exports.ItemEditor = surveys_surveyEditor_itemEditor.ItemEditor;
463
+ exports.ItemEditor = ItemEditor;
13
464
  //# sourceMappingURL=item-editor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"item-editor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
1
+ {"version":3,"file":"item-editor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}