case-editor-tools 1.0.0-beta.14 → 1.0.0-beta.18

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.
@@ -11,3 +11,4 @@ export declare const inputKey = "ic";
11
11
  export declare const numericInputKey = "num";
12
12
  export declare const datePickerKey = "date";
13
13
  export declare const matrixKey = "mat";
14
+ export declare const clozeKey = "cloze";
@@ -14,8 +14,10 @@ const sliderCategoricalKey = "scc";
14
14
  const inputKey = "ic";
15
15
  const numericInputKey = "num";
16
16
  const datePickerKey = "date";
17
- const matrixKey = "mat";
17
+ const matrixKey = "mat";
18
+ const clozeKey = "cloze";
18
19
 
20
+ exports.clozeKey = clozeKey;
19
21
  exports.datePickerKey = datePickerKey;
20
22
  exports.dropDownKey = dropDownKey;
21
23
  exports.inputKey = inputKey;
@@ -1 +1 @@
1
- {"version":3,"file":"key-definitions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"key-definitions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "case-editor-tools",
3
3
  "description": "Javascript tools to simplify survey and study coding for CASE.",
4
- "version": "1.0.0-beta.14",
4
+ "version": "1.0.0-beta.18",
5
5
  "main": "index.js",
6
6
  "license": "Apache-2.0",
7
7
  "repository": "github:case-framework/case-editor-tools",
8
8
  "devDependencies": {
9
9
  "@rollup/plugin-commonjs": "^21.0.1",
10
10
  "@rollup/plugin-node-resolve": "^13.0.6",
11
- "rollup": "^2.59.0",
11
+ "rollup": "^2.60.2",
12
12
  "rollup-plugin-copy": "^3.4.0",
13
13
  "rollup-plugin-delete": "^2.0.0",
14
14
  "rollup-plugin-multi-input": "^1.3.1",
15
15
  "rollup-plugin-peer-deps-external": "^2.2.4",
16
- "rollup-plugin-typescript2": "^0.30.0",
16
+ "rollup-plugin-typescript2": "^0.31.1",
17
17
  "typescript": "^4.4.4"
18
18
  },
19
19
  "scripts": {
package/surveys/index.js CHANGED
@@ -14,6 +14,8 @@ require('./utils/simple-generators.js');
14
14
  require('../types/duration.js');
15
15
  require('../constants/key-definitions.js');
16
16
  require('./utils/simple-question-editor.js');
17
+ require('./responseTypeGenerators/optionGroupComponents.js');
18
+ require('./responseTypeGenerators/likertGroupComponents.js');
17
19
  require('../expression-utils/expressionGen.js');
18
20
 
19
21
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,27 @@
1
+ import { Expression, ItemComponent, ItemGroupComponent } from "survey-engine/lib/data_types";
2
+ import { ResponsiveBipolarLikertArrayProps, ResponsiveSingleChoiceArrayProps } from "../types";
3
+ export interface LikertGroupRow {
4
+ key: string;
5
+ content: Map<string, string>;
6
+ descriptions?: ItemComponent[];
7
+ hideTopBorder?: boolean;
8
+ hideLabels?: boolean;
9
+ optionDisabled?: Array<{
10
+ optionKey: string;
11
+ exp: Expression;
12
+ }>;
13
+ displayCondition?: Expression;
14
+ }
15
+ export declare const initLikertScaleGroup: (key: string, rows: Array<LikertGroupRow>, scaleOptions: {
16
+ key: string;
17
+ className?: string | undefined;
18
+ content: Map<string, string>;
19
+ }[], stackOnSmallScreen?: boolean | undefined, displayCondition?: Expression | undefined) => ItemGroupComponent;
20
+ export declare const initResponsiveSingleChoiceArray: (rgKey: string, props: ResponsiveSingleChoiceArrayProps, displayCondition?: Expression | undefined) => ItemGroupComponent;
21
+ export declare const initResponsiveBipolarLikertArray: (rgKey: string, props: ResponsiveBipolarLikertArrayProps, displayCondition?: Expression | undefined) => ItemGroupComponent;
22
+ export declare const initLikertScaleItem: (key: string, options: {
23
+ key: string;
24
+ className?: string | undefined;
25
+ content?: Map<string, string> | undefined;
26
+ disabled?: Expression | undefined;
27
+ }[], stackOnSmallScreen?: boolean | undefined, displayCondition?: Expression | undefined) => ItemGroupComponent;
@@ -0,0 +1,347 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var surveys_surveyEditor_componentEditor = require('../survey-editor/component-editor.js');
6
+ var surveys_utils_randomKeyGenerator = require('../utils/randomKeyGenerator.js');
7
+ var surveys_utils_simpleGenerators = require('../utils/simple-generators.js');
8
+
9
+ const initLikertScaleGroup = (key, rows, scaleOptions, stackOnSmallScreen, displayCondition) => {
10
+ const groupEdit = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
11
+ key: key,
12
+ isGroup: true,
13
+ role: 'likertGroup',
14
+ });
15
+ if (displayCondition) {
16
+ groupEdit.setDisplayCondition(displayCondition);
17
+ }
18
+ rows.forEach((row, index) => {
19
+ groupEdit.addItemComponent({
20
+ key: surveys_utils_randomKeyGenerator.generateRandomKey(4),
21
+ role: 'text',
22
+ style: [{
23
+ key: 'className', value: 'fw-bold' + (index !== 0 ? ' pt-1 mt-2' : '') + ((!row.hideTopBorder && index > 0) ? ' border-top border-1 border-grey-2' : '') + (row.descriptions ? ' mb-0' : ' mb-1')
24
+ }, { key: 'variant', value: 'h6' }],
25
+ content: surveys_utils_simpleGenerators.generateLocStrings(row.content),
26
+ });
27
+ if (row.descriptions) {
28
+ row.descriptions.forEach(desc => {
29
+ groupEdit.addItemComponent(desc);
30
+ });
31
+ }
32
+ const item = initLikertScaleItem(row.key, scaleOptions.map(option => {
33
+ var _a, _b;
34
+ return {
35
+ key: option.key,
36
+ className: option.className,
37
+ content: row.hideLabels ? undefined : option.content,
38
+ disabled: (_b = (_a = row.optionDisabled) === null || _a === void 0 ? void 0 : _a.find(cond => cond.optionKey === option.key)) === null || _b === void 0 ? void 0 : _b.exp,
39
+ };
40
+ }), stackOnSmallScreen, row.displayCondition);
41
+ groupEdit.addItemComponent(item);
42
+ });
43
+ return groupEdit.getComponent();
44
+ };
45
+ const initResponsiveSingleChoiceArray = (rgKey, props, displayCondition) => {
46
+ var _a, _b;
47
+ const groupEdit = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
48
+ key: rgKey,
49
+ isGroup: true,
50
+ role: 'responsiveSingleChoiceArray',
51
+ });
52
+ if (displayCondition) {
53
+ groupEdit.setDisplayCondition(displayCondition);
54
+ }
55
+ const style = [
56
+ { key: 'defaultMode', value: props.defaultMode },
57
+ ];
58
+ if (props.responsiveModes) {
59
+ if (props.responsiveModes.sm) {
60
+ style.push({ key: 'smMode', value: props.responsiveModes.sm });
61
+ }
62
+ if (props.responsiveModes.md) {
63
+ style.push({ key: 'mdMode', value: props.responsiveModes.md });
64
+ }
65
+ if (props.responsiveModes.lg) {
66
+ style.push({ key: 'lgMode', value: props.responsiveModes.lg });
67
+ }
68
+ if (props.responsiveModes.xl) {
69
+ style.push({ key: 'xlMode', value: props.responsiveModes.xl });
70
+ }
71
+ if (props.responsiveModes.xxl) {
72
+ style.push({ key: 'xxlMode', value: props.responsiveModes.xxl });
73
+ }
74
+ }
75
+ if (props.rgClassName) {
76
+ style.push({ key: 'className', value: props.rgClassName });
77
+ }
78
+ if (props.verticalModeProps) {
79
+ if (props.verticalModeProps.useReverseOptionOrder) {
80
+ style.push({ key: 'verticalModeReverseOrder', value: 'true' });
81
+ }
82
+ }
83
+ if (props.tableModeProps) {
84
+ style.push({ key: 'tableModeClassName', value: 'table-borderless mb-0 ' + props.tableModeProps.className });
85
+ if (props.tableModeProps.layout) {
86
+ style.push({ key: 'tableModeLayout', value: props.tableModeProps.layout });
87
+ }
88
+ if (props.tableModeProps.firstColWidth) {
89
+ style.push({ key: 'tableModeFirstColWidth', value: props.tableModeProps.firstColWidth });
90
+ }
91
+ }
92
+ groupEdit.setStyles(style);
93
+ const defaultBorderClass = 'border-bottom border-grey-2';
94
+ let tableModeOptionHeaderClassName = undefined;
95
+ if (!((_a = props.tableModeProps) === null || _a === void 0 ? void 0 : _a.hideRowBorder)) {
96
+ tableModeOptionHeaderClassName = defaultBorderClass;
97
+ }
98
+ if ((_b = props.tableModeProps) === null || _b === void 0 ? void 0 : _b.optionHeaderClassName) {
99
+ tableModeOptionHeaderClassName += ' ' + props.tableModeProps.optionHeaderClassName;
100
+ }
101
+ const optionStyles = [];
102
+ if (tableModeOptionHeaderClassName) {
103
+ optionStyles.push({ key: 'tableModeClassName', value: tableModeOptionHeaderClassName });
104
+ }
105
+ groupEdit.addItemComponent({
106
+ key: 'header',
107
+ role: 'options',
108
+ style: optionStyles.length > 0 ? optionStyles : undefined,
109
+ items: props.scaleOptions.map(option => {
110
+ return {
111
+ key: option.key,
112
+ role: 'option',
113
+ style: option.className ? [{ key: 'className', value: option.className }] : undefined,
114
+ content: !Array.isArray(option.content) ? surveys_utils_simpleGenerators.generateLocStrings(option.content) : undefined,
115
+ items: Array.isArray(option.content) ? option.content.map((cont, index) => {
116
+ return {
117
+ key: index.toFixed(),
118
+ role: 'text',
119
+ content: surveys_utils_simpleGenerators.generateLocStrings(cont.content),
120
+ style: cont.className ? [{ key: 'className', value: cont.className }] : undefined,
121
+ };
122
+ }) : [],
123
+ };
124
+ })
125
+ });
126
+ props.rows.forEach((row, index) => {
127
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
128
+ let tableModeRowClassName = undefined;
129
+ let horizontalModeRowClassName = undefined;
130
+ let verticalModeRowClassName = undefined;
131
+ const isLast = index === props.rows.length - 1;
132
+ if (!((_a = props.tableModeProps) === null || _a === void 0 ? void 0 : _a.hideRowBorder) && !isLast) {
133
+ tableModeRowClassName = defaultBorderClass;
134
+ }
135
+ if ((_b = row.tableModeProps) === null || _b === void 0 ? void 0 : _b.className) {
136
+ tableModeRowClassName += ' ' + ((_c = row.tableModeProps) === null || _c === void 0 ? void 0 : _c.className);
137
+ }
138
+ if (!((_d = props.horizontalModeProps) === null || _d === void 0 ? void 0 : _d.hideRowBorder) && !isLast) {
139
+ horizontalModeRowClassName = defaultBorderClass;
140
+ }
141
+ if ((_e = row.horizontalModeProps) === null || _e === void 0 ? void 0 : _e.className) {
142
+ horizontalModeRowClassName += ' ' + ((_f = row.horizontalModeProps) === null || _f === void 0 ? void 0 : _f.className);
143
+ }
144
+ if (!((_g = props.verticalModeProps) === null || _g === void 0 ? void 0 : _g.hideRowBorder) && !isLast) {
145
+ verticalModeRowClassName = defaultBorderClass;
146
+ }
147
+ if ((_h = row.verticalModeProps) === null || _h === void 0 ? void 0 : _h.className) {
148
+ verticalModeRowClassName += ' ' + ((_j = row.verticalModeProps) === null || _j === void 0 ? void 0 : _j.className);
149
+ }
150
+ const rowStyles = [];
151
+ if (tableModeRowClassName) {
152
+ rowStyles.push({ key: 'tableModeClassName', value: tableModeRowClassName });
153
+ }
154
+ if (horizontalModeRowClassName) {
155
+ rowStyles.push({ key: 'horizontalModeClassName', value: horizontalModeRowClassName });
156
+ }
157
+ if (verticalModeRowClassName) {
158
+ rowStyles.push({ key: 'verticalModeClassName', value: verticalModeRowClassName });
159
+ }
160
+ if ((_k = row.horizontalModeProps) === null || _k === void 0 ? void 0 : _k.labelPlacement) {
161
+ rowStyles.push({ key: 'horizontalModeLabelPlacement', value: row.horizontalModeProps.labelPlacement });
162
+ }
163
+ groupEdit.addItemComponent({
164
+ key: row.key,
165
+ role: 'row',
166
+ style: rowStyles.length > 0 ? rowStyles : undefined,
167
+ content: !Array.isArray(row.content) ? surveys_utils_simpleGenerators.generateLocStrings(row.content) : undefined,
168
+ items: Array.isArray(row.content) ? row.content.map((cont, index) => {
169
+ return {
170
+ key: index.toFixed(),
171
+ role: 'text',
172
+ content: surveys_utils_simpleGenerators.generateLocStrings(cont.content),
173
+ style: cont.className ? [{ key: 'className', value: cont.className }] : undefined,
174
+ };
175
+ }) : [],
176
+ });
177
+ });
178
+ return groupEdit.getComponent();
179
+ };
180
+ const initResponsiveBipolarLikertArray = (rgKey, props, displayCondition) => {
181
+ var _a;
182
+ const groupEdit = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
183
+ key: rgKey,
184
+ isGroup: true,
185
+ role: 'responsiveBipolarLikertScaleArray',
186
+ });
187
+ if (displayCondition) {
188
+ groupEdit.setDisplayCondition(displayCondition);
189
+ }
190
+ const style = [
191
+ { key: 'defaultMode', value: props.defaultMode },
192
+ ];
193
+ if (props.responsiveModes) {
194
+ if (props.responsiveModes.sm) {
195
+ style.push({ key: 'smMode', value: props.responsiveModes.sm });
196
+ }
197
+ if (props.responsiveModes.md) {
198
+ style.push({ key: 'mdMode', value: props.responsiveModes.md });
199
+ }
200
+ if (props.responsiveModes.lg) {
201
+ style.push({ key: 'lgMode', value: props.responsiveModes.lg });
202
+ }
203
+ if (props.responsiveModes.xl) {
204
+ style.push({ key: 'xlMode', value: props.responsiveModes.xl });
205
+ }
206
+ if (props.responsiveModes.xxl) {
207
+ style.push({ key: 'xxlMode', value: props.responsiveModes.xxl });
208
+ }
209
+ }
210
+ if (props.rgClassName) {
211
+ style.push({ key: 'className', value: props.rgClassName });
212
+ }
213
+ if (props.withLabelRowModeProps) {
214
+ if (props.withLabelRowModeProps.maxLabelWidth) {
215
+ style.push({ key: 'labelRowMaxLabelWidth', value: props.withLabelRowModeProps.maxLabelWidth });
216
+ }
217
+ }
218
+ style.push({ key: 'labelRowPosition', value: ((_a = props.withLabelRowModeProps) === null || _a === void 0 ? void 0 : _a.useBottomLabel) ? 'bottom' : 'top' });
219
+ if (props.tableModeProps) {
220
+ style.push({ key: 'tableModeClassName', value: 'table-borderless mb-0 ' + props.tableModeProps.className });
221
+ if (props.tableModeProps.layout) {
222
+ style.push({ key: 'tableModeLayout', value: props.tableModeProps.layout });
223
+ }
224
+ if (props.tableModeProps.labelColWidth) {
225
+ style.push({ key: 'tableModeLabelColWidth', value: props.tableModeProps.labelColWidth });
226
+ }
227
+ }
228
+ groupEdit.setStyles(style);
229
+ const defaultBorderClass = 'border-bottom border-grey-2';
230
+ groupEdit.addItemComponent({
231
+ key: 'options',
232
+ role: 'options',
233
+ items: props.scaleOptions.map(option => {
234
+ return {
235
+ key: option.key,
236
+ role: 'option',
237
+ };
238
+ })
239
+ });
240
+ props.rows.forEach((row, index) => {
241
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
242
+ let tableModeRowClassName = undefined;
243
+ let withLabelRowModeClassName = undefined;
244
+ let verticalModeRowClassName = undefined;
245
+ const isLast = index === props.rows.length - 1;
246
+ if (!((_a = props.tableModeProps) === null || _a === void 0 ? void 0 : _a.hideRowBorder) && !isLast) {
247
+ tableModeRowClassName = defaultBorderClass;
248
+ }
249
+ if ((_b = row.tableModeProps) === null || _b === void 0 ? void 0 : _b.className) {
250
+ tableModeRowClassName += ' ' + ((_c = row.tableModeProps) === null || _c === void 0 ? void 0 : _c.className);
251
+ }
252
+ if (!((_d = props.withLabelRowModeProps) === null || _d === void 0 ? void 0 : _d.hideRowBorder) && !isLast) {
253
+ withLabelRowModeClassName = defaultBorderClass;
254
+ }
255
+ if ((_e = row.withLabelRowModeProps) === null || _e === void 0 ? void 0 : _e.className) {
256
+ withLabelRowModeClassName += ' ' + ((_f = row.withLabelRowModeProps) === null || _f === void 0 ? void 0 : _f.className);
257
+ }
258
+ if (!((_g = props.verticalModeProps) === null || _g === void 0 ? void 0 : _g.hideRowBorder) && !isLast) {
259
+ verticalModeRowClassName = defaultBorderClass;
260
+ }
261
+ if ((_h = row.verticalModeProps) === null || _h === void 0 ? void 0 : _h.className) {
262
+ verticalModeRowClassName += ' ' + ((_j = row.verticalModeProps) === null || _j === void 0 ? void 0 : _j.className);
263
+ }
264
+ const rowStyles = [];
265
+ if (tableModeRowClassName) {
266
+ rowStyles.push({ key: 'tableModeClassName', value: tableModeRowClassName });
267
+ }
268
+ if (withLabelRowModeClassName) {
269
+ rowStyles.push({ key: 'withLabelRowModeClassName', value: withLabelRowModeClassName });
270
+ }
271
+ if (verticalModeRowClassName) {
272
+ rowStyles.push({ key: 'verticalModeClassName', value: verticalModeRowClassName });
273
+ }
274
+ const startLabel = {
275
+ key: 'start',
276
+ role: 'start',
277
+ content: !Array.isArray(row.startLabel) ? surveys_utils_simpleGenerators.generateLocStrings(row.startLabel) : undefined,
278
+ items: Array.isArray(row.startLabel) ? row.startLabel.map((cont, index) => {
279
+ return {
280
+ key: index.toFixed(),
281
+ role: 'text',
282
+ content: surveys_utils_simpleGenerators.generateLocStrings(cont.content),
283
+ style: cont.className ? [{ key: 'className', value: cont.className }] : undefined,
284
+ };
285
+ }) : [],
286
+ };
287
+ const endLabel = {
288
+ key: 'end',
289
+ role: 'end',
290
+ content: !Array.isArray(row.endLabel) ? surveys_utils_simpleGenerators.generateLocStrings(row.endLabel) : undefined,
291
+ items: Array.isArray(row.endLabel) ? row.endLabel.map((cont, index) => {
292
+ return {
293
+ key: index.toFixed(),
294
+ role: 'text',
295
+ content: surveys_utils_simpleGenerators.generateLocStrings(cont.content),
296
+ style: cont.className ? [{ key: 'className', value: cont.className }] : undefined,
297
+ };
298
+ }) : [],
299
+ };
300
+ groupEdit.addItemComponent({
301
+ key: row.key,
302
+ role: 'row',
303
+ style: rowStyles.length > 0 ? rowStyles : undefined,
304
+ items: [
305
+ startLabel, endLabel
306
+ ],
307
+ });
308
+ });
309
+ return groupEdit.getComponent();
310
+ };
311
+ const initLikertScaleItem = (key, options, stackOnSmallScreen, displayCondition) => {
312
+ // init group
313
+ const groupEdit = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
314
+ key: key,
315
+ isGroup: true,
316
+ role: 'likert',
317
+ });
318
+ groupEdit.setDisplayCondition(displayCondition);
319
+ if (stackOnSmallScreen) {
320
+ groupEdit.setStyles([
321
+ { key: 'responsive', value: 'stackOnSmallScreen' }
322
+ ]);
323
+ }
324
+ options.forEach((option) => {
325
+ const optionComponent = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
326
+ key: option.key,
327
+ role: 'option',
328
+ });
329
+ if (option.content) {
330
+ optionComponent.setContent(surveys_utils_simpleGenerators.generateLocStrings(option.content));
331
+ }
332
+ if (option.className) {
333
+ optionComponent.setStyles([{
334
+ key: 'className', value: option.className
335
+ }]);
336
+ }
337
+ optionComponent.setDisabled(option.disabled);
338
+ groupEdit.addItemComponent(optionComponent.getComponent());
339
+ });
340
+ return groupEdit.getComponent();
341
+ };
342
+
343
+ exports.initLikertScaleGroup = initLikertScaleGroup;
344
+ exports.initLikertScaleItem = initLikertScaleItem;
345
+ exports.initResponsiveBipolarLikertArray = initResponsiveBipolarLikertArray;
346
+ exports.initResponsiveSingleChoiceArray = initResponsiveSingleChoiceArray;
347
+ //# sourceMappingURL=likertGroupComponents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"likertGroupComponents.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,49 @@
1
+ import { ComponentProperties, Expression, ItemGroupComponent } from "survey-engine/lib/data_types";
2
+ interface HeaderRow {
3
+ role: 'headerRow';
4
+ key: string;
5
+ displayCondition?: Expression;
6
+ disabled?: Expression;
7
+ cells: Array<{
8
+ role: 'text';
9
+ key: string;
10
+ content?: Map<string, string>;
11
+ description?: Map<string, string>;
12
+ }>;
13
+ }
14
+ interface RadioRow {
15
+ role: 'radioRow';
16
+ key: string;
17
+ displayCondition?: Expression;
18
+ disabled?: Expression;
19
+ cells: Array<{
20
+ role: 'label' | 'option';
21
+ key: string;
22
+ content?: Map<string, string>;
23
+ description?: Map<string, string>;
24
+ }>;
25
+ }
26
+ export interface ResponseRowCell {
27
+ role: 'label' | 'check' | 'input' | 'numberInput' | 'dropDownGroup';
28
+ key: string;
29
+ content?: Map<string, string>;
30
+ description?: Map<string, string>;
31
+ properties?: ComponentProperties;
32
+ items?: Array<{
33
+ role: 'option';
34
+ key: string;
35
+ content?: Map<string, string>;
36
+ disabled?: Expression;
37
+ displayCondition?: Expression;
38
+ }>;
39
+ }
40
+ interface ResponseRow {
41
+ role: 'responseRow';
42
+ key: string;
43
+ displayCondition?: Expression;
44
+ disabled?: Expression;
45
+ cells: Array<ResponseRowCell>;
46
+ }
47
+ declare type MatrixRow = HeaderRow | RadioRow | ResponseRow;
48
+ export declare const initMatrixQuestion: (key: string, rows: Array<MatrixRow>, order?: Expression | undefined) => ItemGroupComponent;
49
+ export {};
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var surveys_surveyEditor_componentEditor = require('../survey-editor/component-editor.js');
6
+ var surveys_utils_simpleGenerators = require('../utils/simple-generators.js');
7
+ require('../utils/randomKeyGenerator.js');
8
+
9
+ const initMatrixQuestion = (key, rows, order) => {
10
+ // init group
11
+ const groupEdit = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
12
+ key: key,
13
+ isGroup: true,
14
+ role: 'matrix',
15
+ });
16
+ groupEdit.setOrder(order ? order : {
17
+ name: 'sequential'
18
+ });
19
+ // init rows
20
+ rows.forEach(rowDef => {
21
+ const rowEditor = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
22
+ key: rowDef.key,
23
+ role: rowDef.role,
24
+ });
25
+ if (rowDef.displayCondition) {
26
+ rowEditor.setDisplayCondition(rowDef.displayCondition);
27
+ }
28
+ if (rowDef.disabled) {
29
+ rowEditor.setDisabled(rowDef.disabled);
30
+ }
31
+ switch (rowDef.role) {
32
+ case 'headerRow':
33
+ rowDef.cells.forEach(cell => {
34
+ const cellEditor = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
35
+ key: cell.key,
36
+ role: cell.role,
37
+ });
38
+ if (cell.content) {
39
+ cellEditor.setContent(surveys_utils_simpleGenerators.generateLocStrings(cell.content));
40
+ }
41
+ if (cell.description) {
42
+ cellEditor.setDescription(surveys_utils_simpleGenerators.generateLocStrings(cell.description));
43
+ }
44
+ rowEditor.addItemComponent(cellEditor.getComponent());
45
+ });
46
+ break;
47
+ case 'radioRow':
48
+ rowDef.cells.forEach(cell => {
49
+ const cellEditor = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
50
+ key: cell.key,
51
+ role: cell.role,
52
+ });
53
+ if (cell.content) {
54
+ cellEditor.setContent(surveys_utils_simpleGenerators.generateLocStrings(cell.content));
55
+ }
56
+ if (cell.description) {
57
+ cellEditor.setDescription(surveys_utils_simpleGenerators.generateLocStrings(cell.description));
58
+ }
59
+ rowEditor.addItemComponent(cellEditor.getComponent());
60
+ });
61
+ break;
62
+ case 'responseRow':
63
+ rowDef.cells.forEach(cell => {
64
+ const cellEditor = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
65
+ key: cell.key,
66
+ role: cell.role,
67
+ });
68
+ if (cell.content) {
69
+ cellEditor.setContent(surveys_utils_simpleGenerators.generateLocStrings(cell.content));
70
+ }
71
+ if (cell.description) {
72
+ cellEditor.setDescription(surveys_utils_simpleGenerators.generateLocStrings(cell.description));
73
+ }
74
+ cellEditor.setProperties(cell.properties);
75
+ if (cell.items) {
76
+ cell.items.forEach(opt => {
77
+ const cellOptionEditor = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
78
+ key: opt.key,
79
+ role: opt.role,
80
+ });
81
+ if (opt.content) {
82
+ cellOptionEditor.setContent(surveys_utils_simpleGenerators.generateLocStrings(opt.content));
83
+ }
84
+ cellOptionEditor.setDisabled(opt.disabled);
85
+ cellOptionEditor.setDisplayCondition(opt.displayCondition);
86
+ cellEditor.addItemComponent(cellOptionEditor.getComponent());
87
+ });
88
+ }
89
+ rowEditor.addItemComponent(cellEditor.getComponent());
90
+ });
91
+ break;
92
+ }
93
+ groupEdit.addItemComponent(rowEditor.getComponent());
94
+ });
95
+ return groupEdit.getComponent();
96
+ };
97
+
98
+ exports.initMatrixQuestion = initMatrixQuestion;
99
+ //# sourceMappingURL=matrixGroupComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matrixGroupComponent.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,7 @@
1
+ import { Expression, ItemComponent, ItemGroupComponent } from "survey-engine/lib/data_types";
2
+ import { OptionDef } from "../types";
3
+ export declare const optionDefToItemComponent: (optionDef: OptionDef) => ItemComponent;
4
+ export declare const initSingleChoiceGroup: (key: string, optionItems: OptionDef[], order?: Expression | undefined) => ItemGroupComponent;
5
+ export declare const initMultipleChoiceGroup: (key: string, optionItems: OptionDef[], order?: Expression | undefined) => ItemGroupComponent;
6
+ export declare const initDropdownGroup: (key: string, optionItems: OptionDef[], order?: Expression | undefined, groupDisabled?: Expression | undefined, groupContent?: Map<string, string> | undefined, groupDescription?: Map<string, string> | undefined) => ItemGroupComponent;
7
+ export declare const initSliderCategoricalGroup: (key: string, optionItems: OptionDef[], order?: Expression | undefined, groupDisabled?: Expression | undefined) => ItemGroupComponent;