case-editor-tools 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ export declare const singleChoiceKey = "scg";
3
3
  export declare const likertScaleGroupKey = "lg";
4
4
  export declare const responsiveSingleChoiceArrayKey = "rsca";
5
5
  export declare const responsiveBipolarLikertArrayKey = "rsbla";
6
+ export declare const responsiveMatrix = "rm";
6
7
  export declare const likertScaleKey = "likert";
7
8
  export declare const multipleChoiceKey = "mcg";
8
9
  export declare const dropDownKey = "ddg";
@@ -7,6 +7,7 @@ const singleChoiceKey = 'scg';
7
7
  const likertScaleGroupKey = 'lg';
8
8
  const responsiveSingleChoiceArrayKey = 'rsca';
9
9
  const responsiveBipolarLikertArrayKey = 'rsbla';
10
+ const responsiveMatrix = 'rm';
10
11
  const likertScaleKey = 'likert';
11
12
  const multipleChoiceKey = 'mcg';
12
13
  const dropDownKey = 'ddg';
@@ -31,6 +32,7 @@ exports.multipleChoiceKey = multipleChoiceKey;
31
32
  exports.numericInputKey = numericInputKey;
32
33
  exports.responseGroupKey = responseGroupKey;
33
34
  exports.responsiveBipolarLikertArrayKey = responsiveBipolarLikertArrayKey;
35
+ exports.responsiveMatrix = responsiveMatrix;
34
36
  exports.responsiveSingleChoiceArrayKey = responsiveSingleChoiceArrayKey;
35
37
  exports.singleChoiceKey = singleChoiceKey;
36
38
  exports.sliderCategoricalKey = sliderCategoricalKey;
@@ -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,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.1.0",
4
+ "version": "1.2.0",
5
5
  "main": "index.js",
6
6
  "license": "Apache-2.0",
7
7
  "repository": "github:case-framework/case-editor-tools",
@@ -1,5 +1,5 @@
1
1
  import { Expression, ItemComponent, ItemGroupComponent } from "survey-engine/data_types";
2
- import { ResponsiveBipolarLikertArrayProps, ResponsiveSingleChoiceArrayProps } from "../types";
2
+ import { ResponsiveBipolarLikertArrayProps, ResponsiveMatrixProps, ResponsiveSingleChoiceArrayProps } from "../types";
3
3
  export interface LikertGroupRow {
4
4
  key: string;
5
5
  content: Map<string, string>;
@@ -19,6 +19,7 @@ export declare const initLikertScaleGroup: (key: string, rows: Array<LikertGroup
19
19
  }[], stackOnSmallScreen?: boolean | undefined, displayCondition?: Expression | undefined) => ItemGroupComponent;
20
20
  export declare const initResponsiveSingleChoiceArray: (rgKey: string, props: ResponsiveSingleChoiceArrayProps, displayCondition?: Expression | undefined) => ItemGroupComponent;
21
21
  export declare const initResponsiveBipolarLikertArray: (rgKey: string, props: ResponsiveBipolarLikertArrayProps, displayCondition?: Expression | undefined) => ItemGroupComponent;
22
+ export declare const initResponsiveMatrixItem: (rgKey: string, props: ResponsiveMatrixProps, displayCondition?: Expression | undefined) => ItemGroupComponent;
22
23
  export declare const initLikertScaleItem: (key: string, options: {
23
24
  key: string;
24
25
  className?: string | undefined;
@@ -311,6 +311,90 @@ const initResponsiveBipolarLikertArray = (rgKey, props, displayCondition) => {
311
311
  });
312
312
  return groupEdit.getComponent();
313
313
  };
314
+ function hasDuplicates(array) {
315
+ return (new Set(array)).size !== array.length;
316
+ }
317
+ const initResponsiveMatrixItem = (rgKey, props, displayCondition) => {
318
+ const groupEdit = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
319
+ key: rgKey,
320
+ isGroup: true,
321
+ role: 'responsiveBipolarLikertScaleArray',
322
+ });
323
+ if (hasDuplicates(props.rows.map(item => item.key))) {
324
+ throw Error(`has duplicate row keys in ${rgKey}`);
325
+ }
326
+ if (hasDuplicates(props.columns.map(item => item.key))) {
327
+ throw Error(`has duplicate column keys in ${rgKey}`);
328
+ }
329
+ if (displayCondition) {
330
+ groupEdit.setDisplayCondition(displayCondition);
331
+ }
332
+ const style = [
333
+ { key: 'responseType', value: props.responseType },
334
+ ];
335
+ if (props.breakpoint) {
336
+ style.push({ key: 'breakpoint', value: props.breakpoint });
337
+ }
338
+ groupEdit.setStyles(style);
339
+ // ADD COLUMNS
340
+ groupEdit.addItemComponent({
341
+ key: 'cols',
342
+ role: 'columns',
343
+ items: props.columns.map(option => {
344
+ return {
345
+ key: option.key,
346
+ role: 'category',
347
+ content: !Array.isArray(option.label) ? surveys_utils_simpleGenerators.generateLocStrings(option.label) : undefined,
348
+ items: Array.isArray(option.label) ? option.label.map((cont, index) => {
349
+ return {
350
+ key: index.toFixed(),
351
+ role: 'text',
352
+ content: surveys_utils_simpleGenerators.generateLocStrings(cont.content),
353
+ style: cont.className ? [{ key: 'className', value: cont.className }] : undefined,
354
+ };
355
+ }) : [],
356
+ };
357
+ })
358
+ });
359
+ // ADD DROPDOWN OPTIONS (if applicable)
360
+ if (props.responseType == 'dropdown' && props.dropdownConfig !== undefined) {
361
+ groupEdit.addItemComponent({
362
+ key: 'do',
363
+ role: 'dropdownOptions',
364
+ content: surveys_utils_simpleGenerators.generateLocStrings(props.dropdownConfig.unselectedLabeL),
365
+ items: props.dropdownConfig.options.map(option => {
366
+ return {
367
+ key: option.key,
368
+ role: 'option',
369
+ content: surveys_utils_simpleGenerators.generateLocStrings(option.label),
370
+ };
371
+ })
372
+ });
373
+ }
374
+ // ADD ROWS
375
+ props.rows.forEach((row, index) => {
376
+ const rowStyles = [];
377
+ if (row.className !== undefined) {
378
+ rowStyles.push({ key: 'className', value: row.className });
379
+ }
380
+ groupEdit.addItemComponent({
381
+ key: row.key,
382
+ role: 'row',
383
+ displayCondition: row.displayCondition,
384
+ style: rowStyles.length > 0 ? rowStyles : undefined,
385
+ content: !Array.isArray(row.label) ? surveys_utils_simpleGenerators.generateLocStrings(row.label) : undefined,
386
+ items: Array.isArray(row.label) ? row.label.map((cont, index) => {
387
+ return {
388
+ key: index.toFixed(),
389
+ role: 'text',
390
+ content: surveys_utils_simpleGenerators.generateLocStrings(cont.content),
391
+ style: cont.className ? [{ key: 'className', value: cont.className }] : undefined,
392
+ };
393
+ }) : [],
394
+ });
395
+ });
396
+ return groupEdit.getComponent();
397
+ };
314
398
  const initLikertScaleItem = (key, options, stackOnSmallScreen, displayCondition) => {
315
399
  // init group
316
400
  const groupEdit = new surveys_surveyEditor_componentEditor.ComponentEditor(undefined, {
@@ -346,5 +430,6 @@ const initLikertScaleItem = (key, options, stackOnSmallScreen, displayCondition)
346
430
  exports.initLikertScaleGroup = initLikertScaleGroup;
347
431
  exports.initLikertScaleItem = initLikertScaleItem;
348
432
  exports.initResponsiveBipolarLikertArray = initResponsiveBipolarLikertArray;
433
+ exports.initResponsiveMatrixItem = initResponsiveMatrixItem;
349
434
  exports.initResponsiveSingleChoiceArray = initResponsiveSingleChoiceArray;
350
435
  //# sourceMappingURL=likertGroupComponents.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"likertGroupComponents.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"likertGroupComponents.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { ItemGroupComponent, Expression, ItemComponent, SurveyItem, ExpressionArg, ResponseComponent } from "survey-engine/data_types";
2
- import { ClozeQuestionProps, ConsentQuestionProps, DateInputQuestionProps, GenericQuestionProps, MultiLineTextInput, NumericInputQuestionProps, OptionDef, ResponsiveBipolarLikertArrayQuestionProps, ResponsiveSingleChoiceArrayQuestionProps, TextInputQuestionProps, TimeInputQuestionProps } from "./types/item-properties";
2
+ import { ClozeQuestionProps, ConsentQuestionProps, DateInputQuestionProps, GenericQuestionProps, MultiLineTextInput, NumericInputQuestionProps, OptionDef, ResponsiveBipolarLikertArrayQuestionProps, ResponsiveMatrixQuestionProps, ResponsiveSingleChoiceArrayQuestionProps, TextInputQuestionProps, TimeInputQuestionProps } from "./types/item-properties";
3
3
  import { LikertGroupRow } from "./responseTypeGenerators/likertGroupComponents";
4
4
  interface OptionQuestionProps extends GenericQuestionProps {
5
5
  responseOptions: Array<OptionDef>;
@@ -53,6 +53,7 @@ export declare const SurveyItems: {
53
53
  singleChoice: (props: OptionQuestionProps) => SurveyItem;
54
54
  responsiveSingleChoiceArray: (props: ResponsiveSingleChoiceArrayQuestionProps) => SurveyItem;
55
55
  responsiveBipolarLikertArray: (props: ResponsiveBipolarLikertArrayQuestionProps) => SurveyItem;
56
+ responsiveMatrix: (props: ResponsiveMatrixQuestionProps) => SurveyItem;
56
57
  multipleChoice: (props: OptionQuestionProps) => SurveyItem;
57
58
  dateInput: (props: DateInputQuestionProps) => SurveyItem;
58
59
  timeInput: (props: TimeInputQuestionProps) => SurveyItem;
@@ -141,6 +141,32 @@ const generateResponsiveBipolarLikertArray = (props) => {
141
141
  }
142
142
  return commonQuestionGenerator(props, rg_inner);
143
143
  };
144
+ const generateResponsiveMatrix = (props) => {
145
+ var _a;
146
+ const rg_inner = surveys_responseTypeGenerators_likertGroupComponents.initResponsiveMatrixItem(constants_keyDefinitions.responsiveMatrix, Object.assign({}, props));
147
+ // Add extra validation
148
+ if (props.isRequired) {
149
+ if (!props.customValidations) {
150
+ props.customValidations = [];
151
+ }
152
+ (_a = props.customValidations) === null || _a === void 0 ? void 0 : _a.push({
153
+ key: 'r',
154
+ type: 'hard',
155
+ rule: surveys_utils_simpleGenerators.expWithArgs('and', ...props.rows.map(row => {
156
+ return [
157
+ ...props.columns.map(col => {
158
+ const hasRespExp = surveys_surveyEngineExpressions.SurveyEngine.hasResponse([props.parentKey, props.itemKey].join('.'), [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.responsiveMatrix, `${row.key}-${col.key}`].join('.'));
159
+ if (row.displayCondition === undefined) {
160
+ return hasRespExp;
161
+ }
162
+ return surveys_surveyEngineExpressions.SurveyEngine.logic.or(surveys_surveyEngineExpressions.SurveyEngine.logic.not(row.displayCondition), hasRespExp);
163
+ })
164
+ ];
165
+ }))
166
+ });
167
+ }
168
+ return commonQuestionGenerator(props, rg_inner);
169
+ };
144
170
  const generateNumericSliderQuestion = (props) => {
145
171
  const rg_inner = {
146
172
  key: 'slider', role: 'sliderNumeric',
@@ -212,6 +238,9 @@ const generateTextInputQuestion = (props) => {
212
238
  if (props.inputMaxWidth !== undefined) {
213
239
  style.push({ key: 'inputMaxWidth', value: props.inputMaxWidth });
214
240
  }
241
+ if (props.transformLetterCaseTo) {
242
+ style.push({ key: 'transformCase', value: props.transformLetterCaseTo });
243
+ }
215
244
  const rg_inner = {
216
245
  key: constants_keyDefinitions.inputKey, role: 'input',
217
246
  content: props.inputLabel ? surveys_utils_simpleGenerators.generateLocStrings(props.inputLabel) : undefined,
@@ -361,6 +390,7 @@ const SurveyItems = {
361
390
  singleChoice: generateSingleChoiceQuestion,
362
391
  responsiveSingleChoiceArray: generateResponsiveSingleChoiceArrayQuestion,
363
392
  responsiveBipolarLikertArray: generateResponsiveBipolarLikertArray,
393
+ responsiveMatrix: generateResponsiveMatrix,
364
394
  multipleChoice: generateMultipleChoiceQuestion,
365
395
  dateInput: generateDatePickerInput,
366
396
  timeInput: generateTimeInput,
@@ -1 +1 @@
1
- {"version":3,"file":"survey-items.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"survey-items.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -222,3 +222,30 @@ export interface ResponsiveBipolarLikertArrayProps {
222
222
  };
223
223
  }
224
224
  export declare type ResponsiveBipolarLikertArrayQuestionProps = GenericQuestionProps & ResponsiveBipolarLikertArrayProps;
225
+ /**
226
+ * Responsive Matrix
227
+ */
228
+ export declare type ResponsiveMatrixResponseType = 'dropdown' | 'input' | 'numberInput';
229
+ export interface ResponsiveMatrixProps {
230
+ responseType: ResponsiveMatrixResponseType;
231
+ breakpoint?: 'sm' | 'md' | 'lg' | 'xl';
232
+ columns: Array<{
233
+ key: string;
234
+ label: Map<string, string> | StyledTextComponentProp[];
235
+ }>;
236
+ rows: Array<{
237
+ key: string;
238
+ role: 'row' | 'category';
239
+ label: Map<string, string> | StyledTextComponentProp[];
240
+ displayCondition?: Expression;
241
+ className?: string;
242
+ }>;
243
+ dropdownConfig?: {
244
+ unselectedLabeL: Map<string, string>;
245
+ options: Array<{
246
+ key: string;
247
+ label: Map<string, string>;
248
+ }>;
249
+ };
250
+ }
251
+ export declare type ResponsiveMatrixQuestionProps = GenericQuestionProps & ResponsiveMatrixProps;