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,483 +0,0 @@
1
- import { Expression } from "survey-engine/lib/data_types"
2
- import { datePickerKey, inputKey, multipleChoiceKey, responseGroupKey, singleChoiceKey } from "../constants/key-definitions"
3
- import { Duration, durationObjectToSeconds } from "../types/duration"
4
- import { generateExpression } from "./expressionGen"
5
-
6
- /**
7
- * Logical OR expression
8
- * @returns expression that return true if any of the arguments evaluates to true
9
- */
10
- const or = (...args: Expression[]): Expression => generateExpression('or', undefined, ...args)
11
-
12
- /**
13
- * Logical AND expression
14
- * @returns expression that return true if all of the arguments evaluates to true
15
- */
16
- const and = (...args: Expression[]): Expression => generateExpression('and', undefined, ...args)
17
-
18
- /**
19
- * Logical NOT expression
20
- * @returns expression that negates the argument - true if arg is false, false if arg is true
21
- */
22
- const not = (arg: Expression): Expression => generateExpression('not', undefined, arg)
23
-
24
- /**
25
- * [===] Equality check
26
- * @returns expression that return true of both arguments are equal
27
- */
28
- const eq = (val1: Expression | string | number, val2: Expression | string | number) => generateExpression('eq', undefined, val1, val2);
29
-
30
- /**
31
- * [<] val1 is less than val2?
32
- * @param val1
33
- * @param val2
34
- * @returns
35
- */
36
- const lt = (val1: Expression | string | number, val2: Expression | string | number) => generateExpression('lt', undefined, val1, val2);
37
-
38
- /**
39
- * [<=] val1 is less than or equal to val2?
40
- * @param val1
41
- * @param val2
42
- * @returns
43
- */
44
- const lte = (val1: Expression | string | number, val2: Expression | string | number) => generateExpression('lte', undefined, val1, val2);
45
-
46
- /**
47
- * [>] val1 is greater than val2?
48
- * @param val1
49
- * @param val2
50
- * @returns
51
- */
52
- const gt = (val1: Expression | string | number, val2: Expression | string | number) => generateExpression('gt', undefined, val1, val2);
53
-
54
- /**
55
- * [>=] val1 is greater than or equal to val2?
56
- * @param val1
57
- * @param val2
58
- * @returns
59
- */
60
- const gte = (val1: Expression | string | number, val2: Expression | string | number) => generateExpression('gte', undefined, val1, val2);
61
-
62
- /**
63
- * Generate a timestamp value (POSIX timestamp). T = T_ref + delta. If 'reference' is not defined, the current time will be used as a reference.
64
- * @param delta offset for the timestamp generation
65
- * @param reference optional - a hard coded number, or an expression that should retrieve a timestamp (e.g., surveys assigned from, or response to a date question)
66
- * @returns
67
- */
68
- const timestampWithOffset = (delta: Duration, reference?: number | Expression): Expression => generateExpression(
69
- 'timestampWithOffset',
70
- undefined,
71
- durationObjectToSeconds(delta),
72
- reference ? reference : undefined
73
- )
74
-
75
- /**
76
- * Extract value from a response if exits parsed as a number
77
- * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
78
- * @param responseKey full key of the response slot inside the item (e.g. rg.num)
79
- * @returns expression that returns the value or undefined
80
- */
81
- const getResponseValueAsNum = (itemKey: string, responseKey: string): Expression => {
82
- return generateExpression('getResponseValueAsNum', 'float', itemKey, responseKey);
83
- }
84
-
85
- /**
86
- * Extract value from a response if exits as string
87
- * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
88
- * @param responseKey full key of the response slot inside the item (e.g. rg.input)
89
- * @returns expression that returns the value or undefined
90
- */
91
- const getResponseValueAsStr = (itemKey: string, responseKey: string): Expression => {
92
- return generateExpression('getResponseValueAsStr', 'string', itemKey, responseKey);
93
- }
94
-
95
- /**
96
- * Count the number of existing response items inside the slot
97
- * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
98
- * @param responseKey full key of the response slot inside the item (e.g. rg.mcg)
99
- * @returns expression that returns the number of items of the response slot
100
- */
101
- const countResponseItems = (itemKey: string, responseKey: string): Expression => {
102
- return generateExpression('countResponseItems', undefined, itemKey, responseKey);
103
- }
104
-
105
- /**
106
- * Evaluates an expression and checks if the return value is defined
107
- * @param arg Expression with a potentially undefined return value
108
- * @returns
109
- */
110
- const isDefined = (arg: Expression): Expression => {
111
- return generateExpression('isDefined', undefined, arg);
112
- }
113
-
114
- /**
115
- * Reference to the context variable storing e.g. participant infos
116
- * @returns
117
- */
118
- const getContext = (): Expression => {
119
- return generateExpression('getContext', undefined);
120
- }
121
-
122
- /**
123
- * Reference to the current response array
124
- * @returns
125
- */
126
- const getResponses = (): Expression => {
127
- return generateExpression('getResponses', undefined);
128
- }
129
-
130
- /**
131
- * Reference to the list of currently active survey questions
132
- * @returns
133
- */
134
- const getRenderedItems = (): Expression => {
135
- return generateExpression('getRenderedItems', undefined);
136
- }
137
-
138
- /**
139
- * Extract value of an attribute of the referenced object
140
- * @param objectRef expression that references an object
141
- * @param attributeName name of the attribute to be extracted
142
- * @returns
143
- */
144
- const getAttribute = (objectRef: Expression, attributeName: string): Expression => {
145
- return generateExpression('getAttribute', undefined, objectRef, attributeName);
146
- }
147
-
148
- /**
149
- * Extract value at index
150
- * @param arrayRef expression that references an array
151
- * @param index position in the array
152
- * @returns
153
- */
154
- const getArrayItemAtIndex = (arrayRef: Expression, index: number): Expression => {
155
- return generateExpression('getArrayItemAtIndex', undefined, arrayRef, index);
156
- }
157
-
158
- /**
159
- * Extract value with a specific key
160
- * @param arrayRef expression that references an array
161
- * @param itemKey key of the target item
162
- * @returns
163
- */
164
- const getArrayItemByKey = (arrayRef: Expression, itemKey: string): Expression => {
165
- return generateExpression('getArrayItemByKey', undefined, arrayRef, itemKey);
166
- }
167
-
168
- /**
169
- * Extract value with a specific key from the hierarchical tree
170
- * @param objectRef expression that references the root object
171
- * @param itemKey key of the target item
172
- * @returns
173
- */
174
- const getObjByHierarchicalKey = (objectRef: Expression, itemKey: string): Expression => {
175
- return generateExpression('getObjByHierarchicalKey', undefined, objectRef, itemKey);
176
- }
177
-
178
- /**
179
- * Extract value with a specific key from the tree
180
- * @param objectRef expression that references the root object
181
- * @param itemKey key of the target item
182
- * @returns
183
- */
184
- const getNestedObjectByKey = (objectRef: Expression, itemKey: string): Expression => {
185
- return generateExpression('getNestedObjectByKey', undefined, objectRef, itemKey);
186
- }
187
-
188
-
189
- /**
190
- * Retrieve items by the same key from the previous responses arrays
191
- * @param itemKey key of the target item
192
- * @returns
193
- */
194
- const findPreviousSurveyResponsesByKey = (itemKey: string): Expression => {
195
- return generateExpression('findPreviousSurveyResponsesByKey', undefined, itemKey);
196
- }
197
-
198
- /**
199
- * Retrieve all previous responses for a specific survey key
200
- * @param surveyKey key of the target survey
201
- * @returns
202
- */
203
- const getPreviousResponses = (surveyKey: string): Expression => {
204
- return generateExpression('getPreviousResponses', undefined, surveyKey);
205
- }
206
-
207
- /**
208
- * Retrieve last item for a specific key from the previous responses arrays
209
- * @param itemKey key of the target item
210
- * @returns
211
- */
212
- const getLastFromSurveyResponses = (itemKey: string): Expression => {
213
- return generateExpression('getLastFromSurveyResponses', undefined, itemKey);
214
- }
215
-
216
-
217
- const filterResponsesByIncludesKeys = (responsesRef: Expression, itemKey: string, searchKeys: string): Expression => {
218
- return generateExpression('filterResponsesByIncludesKeys', undefined, responsesRef, itemKey, ...searchKeys);
219
- }
220
-
221
- const filterResponsesByValue = (responsesRef: Expression, itemKey: string, expectedValue: string): Expression => {
222
- return generateExpression('filterResponsesByValue', undefined, responsesRef, itemKey, expectedValue);
223
- }
224
-
225
- /**
226
- * Given a list of previous responses (list of single responses), retrieve the latest one.
227
- * @param responsesRef expression that references a list of response items
228
- * @returns
229
- */
230
- const getLastFromSurveyItemResponses = (responsesRef: Expression): Expression => {
231
- return generateExpression('getLastFromSurveyItemResponses', undefined, responsesRef);
232
- }
233
-
234
- /**
235
- * Calculate time difference between "now" and the reference time in seconds
236
- * @param referenceTime expression that should return a time (in POSIX timestamp form)
237
- * @returns expression returns undefined if rerefence time is evaluated to undefined
238
- */
239
- const getSecondsSince = (referenceTime: Expression): Expression => {
240
- return generateExpression('getSecondsSince', undefined, referenceTime);
241
- }
242
-
243
- /**
244
- * Get response object for a specific item and slot
245
- * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
246
- * @param responseKey full key of the response slot inside the item (e.g. rg.num)
247
- * @returns
248
- */
249
- const getResponseItem = (itemKey: string, responseKey: string): Expression => {
250
- return generateExpression('getResponseItem', undefined, itemKey, responseKey);
251
- }
252
-
253
- /**
254
- * Check if an item has a specific response object (by key)
255
- * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
256
- * @param responseKey full key of the response slot inside the item (e.g. rg.num)
257
- * @returns
258
- */
259
- const hasResponse = (itemKey: string, responseKey: string): Expression => {
260
- return generateExpression('hasResponse', undefined, itemKey, responseKey);
261
- }
262
-
263
- /**
264
- * Evaluate if regex expression is fulfilled on the responses value attribute
265
- * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
266
- * @param responseKey full key of the response slot inside the item (e.g. rg.input)
267
- * @param regexPattern regex pattern to check value against
268
- * @returns
269
- */
270
- const checkResponseValueWithRegex = (itemKey: string, responseKey: string, regexPattern: string): Expression => {
271
- return generateExpression('checkResponseValueWithRegex', undefined, itemKey, responseKey, regexPattern);
272
- }
273
-
274
- /**
275
- * Check if any of the following options is selected
276
- * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
277
- * @param responseKey full key of the response slot inside the item (e.g. rg.scg)
278
- * @param optionKeys keys of the option that should be selected
279
- * @returns
280
- */
281
- const responseHasKeysAny = (itemKey: string, responseKey: string, ...optionKeys: string[]): Expression => {
282
- return generateExpression('responseHasKeysAny', undefined, itemKey, responseKey, ...optionKeys);
283
- }
284
-
285
- /**
286
- * Check if all of the following options are selected
287
- * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
288
- * @param responseKey full key of the response slot inside the item (e.g. rg.scg)
289
- * @param optionKeys keys of the option that should be selected
290
- * @returns
291
- */
292
- const responseHasKeysAll = (itemKey: string, responseKey: string, ...optionKeys: string[]): Expression => {
293
- return generateExpression('responseHasKeysAll', undefined, itemKey, responseKey, ...optionKeys);
294
- }
295
-
296
- /**
297
- * Check if only other options were selected
298
- * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
299
- * @param responseKey full key of the response slot inside the item (e.g. rg.scg)
300
- * @param optionKeys keys of the option that shouldn't be selected
301
- * @returns
302
- */
303
- const responseHasOnlyKeysOtherThan = (itemKey: string, responseKey: string, ...optionKeys: string[]): Expression => {
304
- return generateExpression('responseHasOnlyKeysOtherThan', undefined, itemKey, responseKey, ...optionKeys);
305
- }
306
-
307
- /**
308
- * To use evaluated validations rules, we can reference them with this method.
309
- * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
310
- * @param validationKey key of the validation rule
311
- * @returns
312
- */
313
- const getSurveyItemValidation = (itemKey: string, validationKey: string): Expression => {
314
- return generateExpression('getSurveyItemValidation', undefined, itemKey, validationKey);
315
- }
316
-
317
- /**
318
- * Calculate difference of a selected date input and current timestamp with selected unit
319
- * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
320
- * @param responseKey full key of the response slot inside the item (e.g. rg.input)
321
- * @param unit in which unit should the difference be returned
322
- * @param ignoreSign if set to true, sign (+/-) is ignored and the absolute value of the difference is returned
323
- * @returns
324
- */
325
- const dateResponseDiffFromNow = (itemKey: string, responseKey: string, unit: 'years' | 'months' | 'days' | 'hours' | 'minutes' | 'seconds', ignoreSign?: boolean): Expression => {
326
- return generateExpression('dateResponseDiffFromNow', undefined, itemKey, responseKey, unit, ignoreSign ? 1 : undefined);
327
- }
328
-
329
- /**
330
- * Check participant flags object if contains the specified key value pair
331
- * @param key retrieve participant flag's value for this key
332
- * @param value string value to be checked for a match
333
- * @returns
334
- */
335
- const hasParticipantFlag = (key: string, value: string): Expression => {
336
- return eq(
337
- getAttribute(
338
- getAttribute(
339
- getContext(),
340
- 'participantFlags'
341
- ),
342
- key,
343
- ),
344
- value,
345
- );
346
- }
347
-
348
- /**
349
- * Counts the number of selected options in a multiple choice question
350
- * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
351
- * @returns
352
- */
353
- const multipleChoiceSelectionCount = (itemKey: string): Expression => {
354
- return countResponseItems(itemKey, [responseGroupKey, multipleChoiceKey].join('.'));
355
- }
356
-
357
- const getDatePickerResponseValue = (itemKey: string): Expression => {
358
- return getResponseValueAsNum(itemKey, [responseGroupKey, datePickerKey].join('.'))
359
- }
360
-
361
- const singleChoiceOptionsSelected = (itemKey: string, ...optionKeys: string[]) =>
362
- responseHasKeysAll(itemKey, [responseGroupKey, singleChoiceKey].join('.'), ...optionKeys)
363
-
364
- const multipleChoiceOptionsSelected = (itemKey: string, ...optionKeys: string[]) =>
365
- responseHasKeysAny(itemKey, [responseGroupKey, multipleChoiceKey].join('.'), ...optionKeys)
366
-
367
- const multipleChoiceAllOfTheseSelected = (itemKey: string, ...optionKeys: string[]) =>
368
- responseHasKeysAll(itemKey, [responseGroupKey, multipleChoiceKey].join('.'), ...optionKeys)
369
-
370
- const multipleChoiceOnlyOtherKeysSelected = (itemKey: string, ...optionKeys: string[]) =>
371
- responseHasOnlyKeysOtherThan(itemKey, [responseGroupKey, multipleChoiceKey].join('.'), ...optionKeys)
372
-
373
- const singleChoiceOnlyOtherOptionSelected = (itemKey: string, ...optionKeys: string[]) =>
374
- responseHasOnlyKeysOtherThan(itemKey, [responseGroupKey, singleChoiceKey].join('.'), ...optionKeys)
375
-
376
- const singleChoiceGetNumOptionValue = (itemKey: string, optionKey: string): Expression => {
377
- return getResponseValueAsNum(itemKey, [responseGroupKey, singleChoiceKey, optionKey].join('.'))
378
- }
379
-
380
- const multipleChoiceGetNumOptionValue = (itemKey: string, optionKey: string): Expression => {
381
- return getResponseValueAsNum(itemKey, [responseGroupKey, multipleChoiceKey, optionKey].join('.'))
382
- }
383
-
384
- const singleChoiceTextInputRegexCheck = (itemKey: string, optionKey: string, pattern: string): Expression => {
385
- return checkResponseValueWithRegex(itemKey, [responseGroupKey, singleChoiceKey, optionKey].join('.'), pattern)
386
- }
387
-
388
- const mulitpleChoiceTextInputRegexCheck = (itemKey: string, optionKey: string, pattern: string): Expression => {
389
- return checkResponseValueWithRegex(itemKey, [responseGroupKey, multipleChoiceKey, optionKey].join('.'), pattern)
390
- }
391
-
392
- const textInputRegexCheck = (itemKey: string, pattern: string): Expression => {
393
- return checkResponseValueWithRegex(itemKey, [responseGroupKey, inputKey].join('.'), pattern)
394
- }
395
-
396
- const multilineTextInputRegexCheck = (itemKey: string, pattern: string): Expression => {
397
- return checkResponseValueWithRegex(itemKey, [responseGroupKey, inputKey].join('.'), pattern)
398
- }
399
-
400
- export const NativeSurveyEngineExpressions = {
401
- getters: {
402
- // root data reference:
403
- getContext,
404
- getResponses,
405
- getRenderedItems,
406
-
407
- // object access:
408
- getAttribute,
409
- getArrayItemAtIndex,
410
- getArrayItemByKey,
411
- getObjByHierarchicalKey,
412
- getNestedObjectByKey,
413
- },
414
- // query methods for previous names:
415
- previousResponses: {
416
- getItemsByKey: findPreviousSurveyResponsesByKey,
417
- getLastItemByKey: getLastFromSurveyResponses,
418
- getAllResponsesForSurveyKey: getPreviousResponses,
419
- filterResponsesByIncludesKeys,
420
- filterResponsesByValue,
421
- getLastFromSurveyItemResponses,
422
- },
423
-
424
- // client side shortcut methods:
425
- isDefined,
426
- hasResponse,
427
- getResponseItem,
428
- getResponseValueAsNum,
429
- getResponseValueAsStr,
430
- checkResponseValueWithRegex,
431
- responseHasKeysAny,
432
- responseHasKeysAll,
433
- responseHasOnlyKeysOtherThan,
434
- getSurveyItemValidation,
435
- dateResponseDiffFromNow,
436
- countResponseItems,
437
- compare: {
438
- eq,
439
- lt,
440
- lte,
441
- gt,
442
- gte,
443
- },
444
- logic: {
445
- or,
446
- and,
447
- not,
448
- },
449
-
450
- // Other
451
- getSecondsSince,
452
- timestampWithOffset,
453
- }
454
-
455
- export const SurveyEngine = {
456
- ...NativeSurveyEngineExpressions,
457
- singleChoice: {
458
- any: singleChoiceOptionsSelected,
459
- none: singleChoiceOnlyOtherOptionSelected,
460
- getDateValue: singleChoiceGetNumOptionValue,
461
- getNumValue: singleChoiceGetNumOptionValue,
462
- regexCheck: singleChoiceTextInputRegexCheck,
463
- },
464
- multipleChoice: {
465
- any: multipleChoiceOptionsSelected,
466
- none: multipleChoiceOnlyOtherKeysSelected,
467
- all: multipleChoiceAllOfTheseSelected,
468
- selectionCount: multipleChoiceSelectionCount,
469
- getDateValue: multipleChoiceGetNumOptionValue,
470
- getNumValue: multipleChoiceGetNumOptionValue,
471
- regexCheck: mulitpleChoiceTextInputRegexCheck,
472
- },
473
- textInput: {
474
- regexCheck: textInputRegexCheck,
475
- },
476
- multilineTextInput: {
477
- regexCheck: multilineTextInputRegexCheck,
478
- },
479
- datePicker: {
480
- get: getDatePickerResponseValue,
481
- },
482
- hasParticipantFlag,
483
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
-
@@ -1,31 +0,0 @@
1
- export class Logger {
2
- static pretty = true;
3
-
4
- static warn = (msg: any) => {
5
-
6
- console.error(`\x1b[33m${Logger.prepocessMsg(msg)}\x1b[0m`);
7
- }
8
-
9
- static error = (msg: any) => {
10
- console.error(`\x1b[31m${Logger.prepocessMsg(msg)}\x1b[0m`);
11
- }
12
-
13
- static criticalError = (msg: any) => {
14
- console.error(`\x1b[41m${Logger.prepocessMsg(msg)}\x1b[0m`);
15
- }
16
-
17
- static success = (msg: any) => {
18
- console.log(`\x1b[32m${Logger.prepocessMsg(msg)}\x1b[0m`);
19
- }
20
-
21
- static log = (msg: any) => {
22
- console.log(`${Logger.prepocessMsg(msg)}`);
23
- }
24
-
25
- private static prepocessMsg(msg: any) {
26
- if (typeof (msg) === 'object') {
27
- return JSON.stringify(msg, undefined, Logger.pretty ? 2 : undefined)
28
- }
29
- return msg;
30
- }
31
- }
@@ -1,133 +0,0 @@
1
- import { ItemComponent, ItemGroupComponent, Expression, LocalizedObject, ComponentProperties, ResponseComponent } from "survey-engine/lib/data_types";
2
- import { NewComponentProps } from "./data-types";
3
-
4
-
5
- interface ComponentEditorInt {
6
- getComponent: () => ItemComponent;
7
- getComponentJSON: (pretty?: boolean) => string;
8
-
9
- setKey: (key: string | undefined) => void;
10
- setRole: (role: string) => void;
11
- setDisplayCondition: (expression: Expression | undefined) => void;
12
- setDisabled: (expression: Expression | undefined) => void;
13
-
14
- setContent: (translations: LocalizedObject[] | undefined) => void;
15
- setDescription: (translations: LocalizedObject[] | undefined) => void;
16
- setStyles: (styles: Array<{ key: string, value: string }> | undefined) => void;
17
-
18
- // response components:
19
- setDType: (dtype: 'string' | 'number' | 'date') => void;
20
- setProperties: (props: ComponentProperties | undefined) => void;
21
-
22
- // item group component:
23
- setOrder: (orderExp: Expression | undefined) => void;
24
- addItemComponent: (item: ItemComponent, atPosition?: number) => void;
25
- updateItemComponent: (selector: string | number, updatedItem: ItemComponent) => void;
26
- removeItem: (index: number) => void;
27
- }
28
-
29
- export class ComponentEditor implements ComponentEditorInt {
30
- component: ItemComponent;
31
-
32
- constructor(existingComponent?: ItemComponent, newComponent?: NewComponentProps) {
33
- if (existingComponent) {
34
- this.component = { ...existingComponent };
35
- } else if (newComponent) {
36
- this.component = {
37
- key: newComponent.key ? newComponent.key : undefined,
38
- role: newComponent.role ? newComponent?.role : 'none',
39
- }
40
- if (newComponent.isGroup) {
41
- (this.component as ItemGroupComponent).items = [];
42
- }
43
- }
44
- else {
45
- this.component = { role: 'undefined' };
46
- }
47
- }
48
-
49
- getComponent() {
50
- return { ...this.component };
51
- };
52
-
53
- getComponentJSON(pretty?: boolean) {
54
- return JSON.stringify(this.component, undefined, pretty ? ' ' : undefined);
55
- };
56
-
57
- setKey(key: string | undefined) {
58
- this.component.key = key;
59
- };
60
-
61
- setRole(role: string) {
62
- this.component.role = role;
63
- };
64
-
65
- setDisplayCondition(expression: Expression | undefined) {
66
- this.component.displayCondition = expression;
67
- };
68
-
69
- setDisabled(expression: Expression | undefined) {
70
- this.component.disabled = expression;
71
- };
72
-
73
- setContent(translations: LocalizedObject[] | undefined) {
74
- this.component.content = translations ? [...translations] : undefined;
75
- };
76
-
77
- setDescription(translations: LocalizedObject[] | undefined) {
78
- this.component.description = translations ? [...translations] : undefined;
79
- };
80
-
81
- setStyles(styles: Array<{ key: string, value: string }> | undefined) {
82
- this.component.style = styles ? [...styles] : undefined;
83
- };
84
-
85
- // response components:
86
- setDType(dtype: 'string' | 'number' | 'date') {
87
- (this.component as ResponseComponent).dtype = dtype;
88
- };
89
-
90
- setProperties(props: ComponentProperties | undefined) {
91
- (this.component as ResponseComponent).properties = { ...props };
92
- };
93
-
94
- // item group component:
95
- setOrder(orderExp: Expression | undefined) {
96
- (this.component as ItemGroupComponent).order = orderExp;
97
- };
98
-
99
- addItemComponent(item: ItemComponent, atPosition?: number) {
100
- if (!(this.component as ItemGroupComponent).items) {
101
- (this.component as ItemGroupComponent).items = [];
102
- }
103
- if (atPosition !== undefined) {
104
- (this.component as ItemGroupComponent).items.splice(atPosition, 0, { ...item });
105
- } else {
106
- (this.component as ItemGroupComponent).items.push({ ...item });
107
- }
108
- };
109
-
110
- updateItemComponent(selector: string | number, updatedItem: ItemComponent) {
111
- if (!(this.component as ItemGroupComponent).items) {
112
- console.warn('items array missing on the component');
113
- return;
114
- }
115
- if (typeof (selector) === 'string') {
116
- // find by key:
117
- const ind = (this.component as ItemGroupComponent).items.findIndex(c => c.key === selector);
118
- if (ind < 0) {
119
- console.warn('could not find component with given key: ', selector);
120
- return;
121
- }
122
- (this.component as ItemGroupComponent).items[ind] = { ...updatedItem };
123
- } else if (typeof (selector) === 'number') {
124
- // find by index:
125
- (this.component as ItemGroupComponent).items[selector] = { ...updatedItem };
126
- }
127
- };
128
-
129
- removeItem(index: number) {
130
- (this.component as ItemGroupComponent).items.splice(index, 1);
131
- };
132
-
133
- }
@@ -1,18 +0,0 @@
1
- import { SurveyItemTypes } from "survey-engine/lib/data_types";
2
-
3
-
4
- export interface NewItemProps {
5
- itemKey?: string; // partial or full key depending on context
6
- isGroup?: boolean;
7
- type?: SurveyItemTypes;
8
- }
9
-
10
- export interface NewComponentProps {
11
- key?: string;
12
- isGroup?: boolean;
13
- role?: string;
14
- }
15
-
16
- export interface SurveyProperties {
17
-
18
- }