case-editor-tools 1.0.0-beta.16 → 1.0.0-beta.17

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 (113) hide show
  1. package/constants/key-definitions.d.ts +14 -0
  2. package/constants/key-definitions.js +34 -0
  3. package/constants/key-definitions.js.map +1 -0
  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/expression-utils/expressionGen.d.ts +2 -0
  8. package/{src/expression-utils/expressionGen.ts → expression-utils/expressionGen.js} +29 -26
  9. package/expression-utils/expressionGen.js.map +1 -0
  10. package/expression-utils/studyEngineExpressions.d.ts +114 -0
  11. package/expression-utils/studyEngineExpressions.js +283 -0
  12. package/expression-utils/studyEngineExpressions.js.map +1 -0
  13. package/{CHANGELOG.md → index.d.ts} +0 -0
  14. package/index.js +3 -0
  15. package/index.js.map +1 -0
  16. package/item-editor-7f825952.js +522 -0
  17. package/item-editor-7f825952.js.map +1 -0
  18. package/{src/logger/index.ts → logger/index.d.ts} +1 -1
  19. package/logger/index.js +10 -0
  20. package/logger/index.js.map +1 -0
  21. package/logger/logger.d.ts +9 -0
  22. package/logger/logger.js +31 -0
  23. package/logger/logger.js.map +1 -0
  24. package/package.json +1 -1
  25. package/{src/surveys/index.ts → surveys/index.d.ts} +3 -3
  26. package/surveys/index.js +26 -0
  27. package/surveys/index.js.map +1 -0
  28. package/surveys/survey-editor/component-editor.d.ts +84 -0
  29. package/surveys/survey-editor/component-editor.js +112 -0
  30. package/surveys/survey-editor/component-editor.js.map +1 -0
  31. package/{src/surveys/survey-editor/data-types.ts → surveys/survey-editor/data-types.d.ts} +13 -18
  32. package/surveys/survey-editor/data-types.js +3 -0
  33. package/surveys/survey-editor/data-types.js.map +1 -0
  34. package/surveys/survey-editor/item-editor.d.ts +65 -0
  35. package/surveys/survey-editor/item-editor.js +13 -0
  36. package/surveys/survey-editor/item-editor.js.map +1 -0
  37. package/surveys/survey-editor/survey-editor.d.ts +43 -0
  38. package/surveys/survey-editor/survey-editor.js +231 -0
  39. package/surveys/survey-editor/survey-editor.js.map +1 -0
  40. package/surveys/survey-engine-expressions.d.ts +120 -0
  41. package/surveys/survey-engine-expressions.js +407 -0
  42. package/surveys/survey-engine-expressions.js.map +1 -0
  43. package/surveys/survey-items.d.ts +133 -0
  44. package/surveys/survey-items.js +1051 -0
  45. package/surveys/survey-items.js.map +1 -0
  46. package/surveys/types/group.d.ts +23 -0
  47. package/surveys/types/group.js +71 -0
  48. package/surveys/types/group.js.map +1 -0
  49. package/{src/surveys/types/index.ts → surveys/types/index.d.ts} +4 -4
  50. package/surveys/types/index.js +20 -0
  51. package/surveys/types/index.js.map +1 -0
  52. package/surveys/types/item-properties.d.ts +189 -0
  53. package/surveys/types/item-properties.js +3 -0
  54. package/surveys/types/item-properties.js.map +1 -0
  55. package/{src/surveys/types/item.ts → surveys/types/item.d.ts} +22 -42
  56. package/surveys/types/item.js +34 -0
  57. package/surveys/types/item.js.map +1 -0
  58. package/surveys/types/survey-definition.d.ts +19 -0
  59. package/surveys/types/survey-definition.js +60 -0
  60. package/surveys/types/survey-definition.js.map +1 -0
  61. package/surveys/utils/componentGenerators.d.ts +24 -0
  62. package/surveys/utils/componentGenerators.js +58 -0
  63. package/surveys/utils/componentGenerators.js.map +1 -0
  64. package/surveys/utils/optionDefGenerators.d.ts +69 -0
  65. package/surveys/utils/optionDefGenerators.js +169 -0
  66. package/surveys/utils/optionDefGenerators.js.map +1 -0
  67. package/surveys/utils/randomKeyGenerator.d.ts +1 -0
  68. package/{src/surveys/utils/randomKeyGenerator.ts → surveys/utils/randomKeyGenerator.js} +14 -9
  69. package/surveys/utils/randomKeyGenerator.js.map +1 -0
  70. package/surveys/utils/simple-generators.d.ts +13 -0
  71. package/surveys/utils/simple-generators.js +102 -0
  72. package/surveys/utils/simple-generators.js.map +1 -0
  73. package/surveys/utils/simple-question-editor.d.ts +14 -0
  74. package/surveys/utils/simple-question-editor.js +45 -0
  75. package/surveys/utils/simple-question-editor.js.map +1 -0
  76. package/types/duration.d.ts +9 -0
  77. package/{src/types/duration.ts → types/duration.js} +27 -30
  78. package/types/duration.js.map +1 -0
  79. package/types/expression.d.ts +4 -0
  80. package/types/expression.js +23 -0
  81. package/types/expression.js.map +1 -0
  82. package/types/study.d.ts +13 -0
  83. package/types/study.js +3 -0
  84. package/types/study.js.map +1 -0
  85. package/types/studyRules.d.ts +8 -0
  86. package/types/studyRules.js +32 -0
  87. package/types/studyRules.js.map +1 -0
  88. package/.editorconfig +0 -13
  89. package/LICENSE +0 -202
  90. package/publish.sh +0 -9
  91. package/readme.md +0 -18
  92. package/rollup.config.js +0 -49
  93. package/src/constants/key-definitions.ts +0 -14
  94. package/src/exporter/index.ts +0 -101
  95. package/src/expression-utils/studyEngineExpressions.ts +0 -359
  96. package/src/index.ts +0 -1
  97. package/src/logger/logger.ts +0 -31
  98. package/src/surveys/survey-editor/component-editor.ts +0 -133
  99. package/src/surveys/survey-editor/item-editor.ts +0 -529
  100. package/src/surveys/survey-editor/survey-editor.ts +0 -261
  101. package/src/surveys/survey-engine-expressions.ts +0 -483
  102. package/src/surveys/survey-items.ts +0 -1490
  103. package/src/surveys/types/group.ts +0 -73
  104. package/src/surveys/types/item-properties.ts +0 -204
  105. package/src/surveys/types/survey-definition.ts +0 -83
  106. package/src/surveys/utils/componentGenerators.ts +0 -76
  107. package/src/surveys/utils/optionDefGenerators.ts +0 -195
  108. package/src/surveys/utils/simple-generators.ts +0 -106
  109. package/src/surveys/utils/simple-question-editor.ts +0 -52
  110. package/src/types/expression.ts +0 -22
  111. package/src/types/study.ts +0 -17
  112. package/src/types/studyRules.ts +0 -39
  113. package/tsconfig.json +0 -100
@@ -0,0 +1,120 @@
1
+ import { Expression } from "survey-engine/lib/data_types";
2
+ import { Duration } from "../types/duration";
3
+ export declare const NativeSurveyEngineExpressions: {
4
+ getters: {
5
+ getContext: () => Expression;
6
+ getResponses: () => Expression;
7
+ getRenderedItems: () => Expression;
8
+ getAttribute: (objectRef: Expression, attributeName: string) => Expression;
9
+ getArrayItemAtIndex: (arrayRef: Expression, index: number) => Expression;
10
+ getArrayItemByKey: (arrayRef: Expression, itemKey: string) => Expression;
11
+ getObjByHierarchicalKey: (objectRef: Expression, itemKey: string) => Expression;
12
+ getNestedObjectByKey: (objectRef: Expression, itemKey: string) => Expression;
13
+ };
14
+ previousResponses: {
15
+ getItemsByKey: (itemKey: string) => Expression;
16
+ getLastItemByKey: (itemKey: string) => Expression;
17
+ getAllResponsesForSurveyKey: (surveyKey: string) => Expression;
18
+ filterResponsesByIncludesKeys: (responsesRef: Expression, itemKey: string, searchKeys: string) => Expression;
19
+ filterResponsesByValue: (responsesRef: Expression, itemKey: string, expectedValue: string) => Expression;
20
+ getLastFromSurveyItemResponses: (responsesRef: Expression) => Expression;
21
+ };
22
+ isDefined: (arg: Expression) => Expression;
23
+ hasResponse: (itemKey: string, responseKey: string) => Expression;
24
+ getResponseItem: (itemKey: string, responseKey: string) => Expression;
25
+ getResponseValueAsNum: (itemKey: string, responseKey: string) => Expression;
26
+ getResponseValueAsStr: (itemKey: string, responseKey: string) => Expression;
27
+ checkResponseValueWithRegex: (itemKey: string, responseKey: string, regexPattern: string) => Expression;
28
+ responseHasKeysAny: (itemKey: string, responseKey: string, ...optionKeys: string[]) => Expression;
29
+ responseHasKeysAll: (itemKey: string, responseKey: string, ...optionKeys: string[]) => Expression;
30
+ responseHasOnlyKeysOtherThan: (itemKey: string, responseKey: string, ...optionKeys: string[]) => Expression;
31
+ getSurveyItemValidation: (itemKey: string, validationKey: string) => Expression;
32
+ dateResponseDiffFromNow: (itemKey: string, responseKey: string, unit: 'years' | 'months' | 'days' | 'hours' | 'minutes' | 'seconds', ignoreSign?: boolean | undefined) => Expression;
33
+ countResponseItems: (itemKey: string, responseKey: string) => Expression;
34
+ compare: {
35
+ eq: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
36
+ lt: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
37
+ lte: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
38
+ gt: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
39
+ gte: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
40
+ };
41
+ logic: {
42
+ or: (...args: Expression[]) => Expression;
43
+ and: (...args: Expression[]) => Expression;
44
+ not: (arg: Expression) => Expression;
45
+ };
46
+ getSecondsSince: (referenceTime: Expression) => Expression;
47
+ timestampWithOffset: (delta: Duration, reference?: number | Expression | undefined) => Expression;
48
+ };
49
+ export declare const SurveyEngine: {
50
+ singleChoice: {
51
+ any: (itemKey: string, ...optionKeys: string[]) => Expression;
52
+ none: (itemKey: string, ...optionKeys: string[]) => Expression;
53
+ getDateValue: (itemKey: string, optionKey: string) => Expression;
54
+ getNumValue: (itemKey: string, optionKey: string) => Expression;
55
+ regexCheck: (itemKey: string, optionKey: string, pattern: string) => Expression;
56
+ };
57
+ multipleChoice: {
58
+ any: (itemKey: string, ...optionKeys: string[]) => Expression;
59
+ none: (itemKey: string, ...optionKeys: string[]) => Expression;
60
+ all: (itemKey: string, ...optionKeys: string[]) => Expression;
61
+ selectionCount: (itemKey: string) => Expression;
62
+ getDateValue: (itemKey: string, optionKey: string) => Expression;
63
+ getNumValue: (itemKey: string, optionKey: string) => Expression;
64
+ regexCheck: (itemKey: string, optionKey: string, pattern: string) => Expression;
65
+ };
66
+ textInput: {
67
+ regexCheck: (itemKey: string, pattern: string) => Expression;
68
+ };
69
+ multilineTextInput: {
70
+ regexCheck: (itemKey: string, pattern: string) => Expression;
71
+ };
72
+ datePicker: {
73
+ get: (itemKey: string) => Expression;
74
+ };
75
+ hasParticipantFlag: (key: string, value: string) => Expression;
76
+ getters: {
77
+ getContext: () => Expression;
78
+ getResponses: () => Expression;
79
+ getRenderedItems: () => Expression;
80
+ getAttribute: (objectRef: Expression, attributeName: string) => Expression;
81
+ getArrayItemAtIndex: (arrayRef: Expression, index: number) => Expression;
82
+ getArrayItemByKey: (arrayRef: Expression, itemKey: string) => Expression;
83
+ getObjByHierarchicalKey: (objectRef: Expression, itemKey: string) => Expression;
84
+ getNestedObjectByKey: (objectRef: Expression, itemKey: string) => Expression;
85
+ };
86
+ previousResponses: {
87
+ getItemsByKey: (itemKey: string) => Expression;
88
+ getLastItemByKey: (itemKey: string) => Expression;
89
+ getAllResponsesForSurveyKey: (surveyKey: string) => Expression;
90
+ filterResponsesByIncludesKeys: (responsesRef: Expression, itemKey: string, searchKeys: string) => Expression;
91
+ filterResponsesByValue: (responsesRef: Expression, itemKey: string, expectedValue: string) => Expression;
92
+ getLastFromSurveyItemResponses: (responsesRef: Expression) => Expression;
93
+ };
94
+ isDefined: (arg: Expression) => Expression;
95
+ hasResponse: (itemKey: string, responseKey: string) => Expression;
96
+ getResponseItem: (itemKey: string, responseKey: string) => Expression;
97
+ getResponseValueAsNum: (itemKey: string, responseKey: string) => Expression;
98
+ getResponseValueAsStr: (itemKey: string, responseKey: string) => Expression;
99
+ checkResponseValueWithRegex: (itemKey: string, responseKey: string, regexPattern: string) => Expression;
100
+ responseHasKeysAny: (itemKey: string, responseKey: string, ...optionKeys: string[]) => Expression;
101
+ responseHasKeysAll: (itemKey: string, responseKey: string, ...optionKeys: string[]) => Expression;
102
+ responseHasOnlyKeysOtherThan: (itemKey: string, responseKey: string, ...optionKeys: string[]) => Expression;
103
+ getSurveyItemValidation: (itemKey: string, validationKey: string) => Expression;
104
+ dateResponseDiffFromNow: (itemKey: string, responseKey: string, unit: 'years' | 'months' | 'days' | 'hours' | 'minutes' | 'seconds', ignoreSign?: boolean | undefined) => Expression;
105
+ countResponseItems: (itemKey: string, responseKey: string) => Expression;
106
+ compare: {
107
+ eq: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
108
+ lt: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
109
+ lte: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
110
+ gt: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
111
+ gte: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
112
+ };
113
+ logic: {
114
+ or: (...args: Expression[]) => Expression;
115
+ and: (...args: Expression[]) => Expression;
116
+ not: (arg: Expression) => Expression;
117
+ };
118
+ getSecondsSince: (referenceTime: Expression) => Expression;
119
+ timestampWithOffset: (delta: Duration, reference?: number | Expression | undefined) => Expression;
120
+ };
@@ -0,0 +1,407 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var constants_keyDefinitions = require('../constants/key-definitions.js');
6
+ var types_duration = require('../types/duration.js');
7
+ var expressionUtils_expressionGen = require('../expression-utils/expressionGen.js');
8
+
9
+ /**
10
+ * Logical OR expression
11
+ * @returns expression that return true if any of the arguments evaluates to true
12
+ */
13
+ const or = (...args) => expressionUtils_expressionGen.generateExpression('or', undefined, ...args);
14
+ /**
15
+ * Logical AND expression
16
+ * @returns expression that return true if all of the arguments evaluates to true
17
+ */
18
+ const and = (...args) => expressionUtils_expressionGen.generateExpression('and', undefined, ...args);
19
+ /**
20
+ * Logical NOT expression
21
+ * @returns expression that negates the argument - true if arg is false, false if arg is true
22
+ */
23
+ const not = (arg) => expressionUtils_expressionGen.generateExpression('not', undefined, arg);
24
+ /**
25
+ * [===] Equality check
26
+ * @returns expression that return true of both arguments are equal
27
+ */
28
+ const eq = (val1, val2) => expressionUtils_expressionGen.generateExpression('eq', undefined, val1, val2);
29
+ /**
30
+ * [<] val1 is less than val2?
31
+ * @param val1
32
+ * @param val2
33
+ * @returns
34
+ */
35
+ const lt = (val1, val2) => expressionUtils_expressionGen.generateExpression('lt', undefined, val1, val2);
36
+ /**
37
+ * [<=] val1 is less than or equal to val2?
38
+ * @param val1
39
+ * @param val2
40
+ * @returns
41
+ */
42
+ const lte = (val1, val2) => expressionUtils_expressionGen.generateExpression('lte', undefined, val1, val2);
43
+ /**
44
+ * [>] val1 is greater than val2?
45
+ * @param val1
46
+ * @param val2
47
+ * @returns
48
+ */
49
+ const gt = (val1, val2) => expressionUtils_expressionGen.generateExpression('gt', undefined, val1, val2);
50
+ /**
51
+ * [>=] val1 is greater than or equal to val2?
52
+ * @param val1
53
+ * @param val2
54
+ * @returns
55
+ */
56
+ const gte = (val1, val2) => expressionUtils_expressionGen.generateExpression('gte', undefined, val1, val2);
57
+ /**
58
+ * Generate a timestamp value (POSIX timestamp). T = T_ref + delta. If 'reference' is not defined, the current time will be used as a reference.
59
+ * @param delta offset for the timestamp generation
60
+ * @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)
61
+ * @returns
62
+ */
63
+ const timestampWithOffset = (delta, reference) => expressionUtils_expressionGen.generateExpression('timestampWithOffset', undefined, types_duration.durationObjectToSeconds(delta), reference ? reference : undefined);
64
+ /**
65
+ * Extract value from a response if exits parsed as a number
66
+ * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
67
+ * @param responseKey full key of the response slot inside the item (e.g. rg.num)
68
+ * @returns expression that returns the value or undefined
69
+ */
70
+ const getResponseValueAsNum = (itemKey, responseKey) => {
71
+ return expressionUtils_expressionGen.generateExpression('getResponseValueAsNum', 'float', itemKey, responseKey);
72
+ };
73
+ /**
74
+ * Extract value from a response if exits as string
75
+ * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
76
+ * @param responseKey full key of the response slot inside the item (e.g. rg.input)
77
+ * @returns expression that returns the value or undefined
78
+ */
79
+ const getResponseValueAsStr = (itemKey, responseKey) => {
80
+ return expressionUtils_expressionGen.generateExpression('getResponseValueAsStr', 'string', itemKey, responseKey);
81
+ };
82
+ /**
83
+ * Count the number of existing response items inside the slot
84
+ * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
85
+ * @param responseKey full key of the response slot inside the item (e.g. rg.mcg)
86
+ * @returns expression that returns the number of items of the response slot
87
+ */
88
+ const countResponseItems = (itemKey, responseKey) => {
89
+ return expressionUtils_expressionGen.generateExpression('countResponseItems', undefined, itemKey, responseKey);
90
+ };
91
+ /**
92
+ * Evaluates an expression and checks if the return value is defined
93
+ * @param arg Expression with a potentially undefined return value
94
+ * @returns
95
+ */
96
+ const isDefined = (arg) => {
97
+ return expressionUtils_expressionGen.generateExpression('isDefined', undefined, arg);
98
+ };
99
+ /**
100
+ * Reference to the context variable storing e.g. participant infos
101
+ * @returns
102
+ */
103
+ const getContext = () => {
104
+ return expressionUtils_expressionGen.generateExpression('getContext', undefined);
105
+ };
106
+ /**
107
+ * Reference to the current response array
108
+ * @returns
109
+ */
110
+ const getResponses = () => {
111
+ return expressionUtils_expressionGen.generateExpression('getResponses', undefined);
112
+ };
113
+ /**
114
+ * Reference to the list of currently active survey questions
115
+ * @returns
116
+ */
117
+ const getRenderedItems = () => {
118
+ return expressionUtils_expressionGen.generateExpression('getRenderedItems', undefined);
119
+ };
120
+ /**
121
+ * Extract value of an attribute of the referenced object
122
+ * @param objectRef expression that references an object
123
+ * @param attributeName name of the attribute to be extracted
124
+ * @returns
125
+ */
126
+ const getAttribute = (objectRef, attributeName) => {
127
+ return expressionUtils_expressionGen.generateExpression('getAttribute', undefined, objectRef, attributeName);
128
+ };
129
+ /**
130
+ * Extract value at index
131
+ * @param arrayRef expression that references an array
132
+ * @param index position in the array
133
+ * @returns
134
+ */
135
+ const getArrayItemAtIndex = (arrayRef, index) => {
136
+ return expressionUtils_expressionGen.generateExpression('getArrayItemAtIndex', undefined, arrayRef, index);
137
+ };
138
+ /**
139
+ * Extract value with a specific key
140
+ * @param arrayRef expression that references an array
141
+ * @param itemKey key of the target item
142
+ * @returns
143
+ */
144
+ const getArrayItemByKey = (arrayRef, itemKey) => {
145
+ return expressionUtils_expressionGen.generateExpression('getArrayItemByKey', undefined, arrayRef, itemKey);
146
+ };
147
+ /**
148
+ * Extract value with a specific key from the hierarchical tree
149
+ * @param objectRef expression that references the root object
150
+ * @param itemKey key of the target item
151
+ * @returns
152
+ */
153
+ const getObjByHierarchicalKey = (objectRef, itemKey) => {
154
+ return expressionUtils_expressionGen.generateExpression('getObjByHierarchicalKey', undefined, objectRef, itemKey);
155
+ };
156
+ /**
157
+ * Extract value with a specific key from the tree
158
+ * @param objectRef expression that references the root object
159
+ * @param itemKey key of the target item
160
+ * @returns
161
+ */
162
+ const getNestedObjectByKey = (objectRef, itemKey) => {
163
+ return expressionUtils_expressionGen.generateExpression('getNestedObjectByKey', undefined, objectRef, itemKey);
164
+ };
165
+ /**
166
+ * Retrieve items by the same key from the previous responses arrays
167
+ * @param itemKey key of the target item
168
+ * @returns
169
+ */
170
+ const findPreviousSurveyResponsesByKey = (itemKey) => {
171
+ return expressionUtils_expressionGen.generateExpression('findPreviousSurveyResponsesByKey', undefined, itemKey);
172
+ };
173
+ /**
174
+ * Retrieve all previous responses for a specific survey key
175
+ * @param surveyKey key of the target survey
176
+ * @returns
177
+ */
178
+ const getPreviousResponses = (surveyKey) => {
179
+ return expressionUtils_expressionGen.generateExpression('getPreviousResponses', undefined, surveyKey);
180
+ };
181
+ /**
182
+ * Retrieve last item for a specific key from the previous responses arrays
183
+ * @param itemKey key of the target item
184
+ * @returns
185
+ */
186
+ const getLastFromSurveyResponses = (itemKey) => {
187
+ return expressionUtils_expressionGen.generateExpression('getLastFromSurveyResponses', undefined, itemKey);
188
+ };
189
+ const filterResponsesByIncludesKeys = (responsesRef, itemKey, searchKeys) => {
190
+ return expressionUtils_expressionGen.generateExpression('filterResponsesByIncludesKeys', undefined, responsesRef, itemKey, ...searchKeys);
191
+ };
192
+ const filterResponsesByValue = (responsesRef, itemKey, expectedValue) => {
193
+ return expressionUtils_expressionGen.generateExpression('filterResponsesByValue', undefined, responsesRef, itemKey, expectedValue);
194
+ };
195
+ /**
196
+ * Given a list of previous responses (list of single responses), retrieve the latest one.
197
+ * @param responsesRef expression that references a list of response items
198
+ * @returns
199
+ */
200
+ const getLastFromSurveyItemResponses = (responsesRef) => {
201
+ return expressionUtils_expressionGen.generateExpression('getLastFromSurveyItemResponses', undefined, responsesRef);
202
+ };
203
+ /**
204
+ * Calculate time difference between "now" and the reference time in seconds
205
+ * @param referenceTime expression that should return a time (in POSIX timestamp form)
206
+ * @returns expression returns undefined if rerefence time is evaluated to undefined
207
+ */
208
+ const getSecondsSince = (referenceTime) => {
209
+ return expressionUtils_expressionGen.generateExpression('getSecondsSince', undefined, referenceTime);
210
+ };
211
+ /**
212
+ * Get response object for a specific item and slot
213
+ * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
214
+ * @param responseKey full key of the response slot inside the item (e.g. rg.num)
215
+ * @returns
216
+ */
217
+ const getResponseItem = (itemKey, responseKey) => {
218
+ return expressionUtils_expressionGen.generateExpression('getResponseItem', undefined, itemKey, responseKey);
219
+ };
220
+ /**
221
+ * Check if an item has a specific response object (by key)
222
+ * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
223
+ * @param responseKey full key of the response slot inside the item (e.g. rg.num)
224
+ * @returns
225
+ */
226
+ const hasResponse = (itemKey, responseKey) => {
227
+ return expressionUtils_expressionGen.generateExpression('hasResponse', undefined, itemKey, responseKey);
228
+ };
229
+ /**
230
+ * Evaluate if regex expression is fulfilled on the responses value attribute
231
+ * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
232
+ * @param responseKey full key of the response slot inside the item (e.g. rg.input)
233
+ * @param regexPattern regex pattern to check value against
234
+ * @returns
235
+ */
236
+ const checkResponseValueWithRegex = (itemKey, responseKey, regexPattern) => {
237
+ return expressionUtils_expressionGen.generateExpression('checkResponseValueWithRegex', undefined, itemKey, responseKey, regexPattern);
238
+ };
239
+ /**
240
+ * Check if any of the following options is selected
241
+ * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
242
+ * @param responseKey full key of the response slot inside the item (e.g. rg.scg)
243
+ * @param optionKeys keys of the option that should be selected
244
+ * @returns
245
+ */
246
+ const responseHasKeysAny = (itemKey, responseKey, ...optionKeys) => {
247
+ return expressionUtils_expressionGen.generateExpression('responseHasKeysAny', undefined, itemKey, responseKey, ...optionKeys);
248
+ };
249
+ /**
250
+ * Check if all of the following options are selected
251
+ * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
252
+ * @param responseKey full key of the response slot inside the item (e.g. rg.scg)
253
+ * @param optionKeys keys of the option that should be selected
254
+ * @returns
255
+ */
256
+ const responseHasKeysAll = (itemKey, responseKey, ...optionKeys) => {
257
+ return expressionUtils_expressionGen.generateExpression('responseHasKeysAll', undefined, itemKey, responseKey, ...optionKeys);
258
+ };
259
+ /**
260
+ * Check if only other options were selected
261
+ * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
262
+ * @param responseKey full key of the response slot inside the item (e.g. rg.scg)
263
+ * @param optionKeys keys of the option that shouldn't be selected
264
+ * @returns
265
+ */
266
+ const responseHasOnlyKeysOtherThan = (itemKey, responseKey, ...optionKeys) => {
267
+ return expressionUtils_expressionGen.generateExpression('responseHasOnlyKeysOtherThan', undefined, itemKey, responseKey, ...optionKeys);
268
+ };
269
+ /**
270
+ * To use evaluated validations rules, we can reference them with this method.
271
+ * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
272
+ * @param validationKey key of the validation rule
273
+ * @returns
274
+ */
275
+ const getSurveyItemValidation = (itemKey, validationKey) => {
276
+ return expressionUtils_expressionGen.generateExpression('getSurveyItemValidation', undefined, itemKey, validationKey);
277
+ };
278
+ /**
279
+ * Calculate difference of a selected date input and current timestamp with selected unit
280
+ * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
281
+ * @param responseKey full key of the response slot inside the item (e.g. rg.input)
282
+ * @param unit in which unit should the difference be returned
283
+ * @param ignoreSign if set to true, sign (+/-) is ignored and the absolute value of the difference is returned
284
+ * @returns
285
+ */
286
+ const dateResponseDiffFromNow = (itemKey, responseKey, unit, ignoreSign) => {
287
+ return expressionUtils_expressionGen.generateExpression('dateResponseDiffFromNow', undefined, itemKey, responseKey, unit, ignoreSign ? 1 : undefined);
288
+ };
289
+ /**
290
+ * Check participant flags object if contains the specified key value pair
291
+ * @param key retrieve participant flag's value for this key
292
+ * @param value string value to be checked for a match
293
+ * @returns
294
+ */
295
+ const hasParticipantFlag = (key, value) => {
296
+ return eq(getAttribute(getAttribute(getContext(), 'participantFlags'), key), value);
297
+ };
298
+ /**
299
+ * Counts the number of selected options in a multiple choice question
300
+ * @param itemKey full key of the survey item (e.g. SURVEY.GROUP.QUESTIONKEY)
301
+ * @returns
302
+ */
303
+ const multipleChoiceSelectionCount = (itemKey) => {
304
+ return countResponseItems(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey].join('.'));
305
+ };
306
+ const getDatePickerResponseValue = (itemKey) => {
307
+ return getResponseValueAsNum(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.datePickerKey].join('.'));
308
+ };
309
+ const singleChoiceOptionsSelected = (itemKey, ...optionKeys) => responseHasKeysAll(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.singleChoiceKey].join('.'), ...optionKeys);
310
+ const multipleChoiceOptionsSelected = (itemKey, ...optionKeys) => responseHasKeysAny(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey].join('.'), ...optionKeys);
311
+ const multipleChoiceAllOfTheseSelected = (itemKey, ...optionKeys) => responseHasKeysAll(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey].join('.'), ...optionKeys);
312
+ const multipleChoiceOnlyOtherKeysSelected = (itemKey, ...optionKeys) => responseHasOnlyKeysOtherThan(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey].join('.'), ...optionKeys);
313
+ const singleChoiceOnlyOtherOptionSelected = (itemKey, ...optionKeys) => responseHasOnlyKeysOtherThan(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.singleChoiceKey].join('.'), ...optionKeys);
314
+ const singleChoiceGetNumOptionValue = (itemKey, optionKey) => {
315
+ return getResponseValueAsNum(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.singleChoiceKey, optionKey].join('.'));
316
+ };
317
+ const multipleChoiceGetNumOptionValue = (itemKey, optionKey) => {
318
+ return getResponseValueAsNum(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey, optionKey].join('.'));
319
+ };
320
+ const singleChoiceTextInputRegexCheck = (itemKey, optionKey, pattern) => {
321
+ return checkResponseValueWithRegex(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.singleChoiceKey, optionKey].join('.'), pattern);
322
+ };
323
+ const mulitpleChoiceTextInputRegexCheck = (itemKey, optionKey, pattern) => {
324
+ return checkResponseValueWithRegex(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey, optionKey].join('.'), pattern);
325
+ };
326
+ const textInputRegexCheck = (itemKey, pattern) => {
327
+ return checkResponseValueWithRegex(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.inputKey].join('.'), pattern);
328
+ };
329
+ const multilineTextInputRegexCheck = (itemKey, pattern) => {
330
+ return checkResponseValueWithRegex(itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.inputKey].join('.'), pattern);
331
+ };
332
+ const NativeSurveyEngineExpressions = {
333
+ getters: {
334
+ // root data reference:
335
+ getContext,
336
+ getResponses,
337
+ getRenderedItems,
338
+ // object access:
339
+ getAttribute,
340
+ getArrayItemAtIndex,
341
+ getArrayItemByKey,
342
+ getObjByHierarchicalKey,
343
+ getNestedObjectByKey,
344
+ },
345
+ // query methods for previous names:
346
+ previousResponses: {
347
+ getItemsByKey: findPreviousSurveyResponsesByKey,
348
+ getLastItemByKey: getLastFromSurveyResponses,
349
+ getAllResponsesForSurveyKey: getPreviousResponses,
350
+ filterResponsesByIncludesKeys,
351
+ filterResponsesByValue,
352
+ getLastFromSurveyItemResponses,
353
+ },
354
+ // client side shortcut methods:
355
+ isDefined,
356
+ hasResponse,
357
+ getResponseItem,
358
+ getResponseValueAsNum,
359
+ getResponseValueAsStr,
360
+ checkResponseValueWithRegex,
361
+ responseHasKeysAny,
362
+ responseHasKeysAll,
363
+ responseHasOnlyKeysOtherThan,
364
+ getSurveyItemValidation,
365
+ dateResponseDiffFromNow,
366
+ countResponseItems,
367
+ compare: {
368
+ eq,
369
+ lt,
370
+ lte,
371
+ gt,
372
+ gte,
373
+ },
374
+ logic: {
375
+ or,
376
+ and,
377
+ not,
378
+ },
379
+ // Other
380
+ getSecondsSince,
381
+ timestampWithOffset,
382
+ };
383
+ const SurveyEngine = Object.assign(Object.assign({}, NativeSurveyEngineExpressions), { singleChoice: {
384
+ any: singleChoiceOptionsSelected,
385
+ none: singleChoiceOnlyOtherOptionSelected,
386
+ getDateValue: singleChoiceGetNumOptionValue,
387
+ getNumValue: singleChoiceGetNumOptionValue,
388
+ regexCheck: singleChoiceTextInputRegexCheck,
389
+ }, multipleChoice: {
390
+ any: multipleChoiceOptionsSelected,
391
+ none: multipleChoiceOnlyOtherKeysSelected,
392
+ all: multipleChoiceAllOfTheseSelected,
393
+ selectionCount: multipleChoiceSelectionCount,
394
+ getDateValue: multipleChoiceGetNumOptionValue,
395
+ getNumValue: multipleChoiceGetNumOptionValue,
396
+ regexCheck: mulitpleChoiceTextInputRegexCheck,
397
+ }, textInput: {
398
+ regexCheck: textInputRegexCheck,
399
+ }, multilineTextInput: {
400
+ regexCheck: multilineTextInputRegexCheck,
401
+ }, datePicker: {
402
+ get: getDatePickerResponseValue,
403
+ }, hasParticipantFlag });
404
+
405
+ exports.NativeSurveyEngineExpressions = NativeSurveyEngineExpressions;
406
+ exports.SurveyEngine = SurveyEngine;
407
+ //# sourceMappingURL=survey-engine-expressions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"survey-engine-expressions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,133 @@
1
+ import { ItemGroupComponent, Expression, ComponentProperties, ItemComponent, SurveyItem, ExpressionArg } from "survey-engine/lib/data_types";
2
+ import { ClozeQuestionProps, DateInputQuestionProps, GenericQuestionProps, MultiLineTextInput, NumericInputQuestionProps, OptionDef, ResponsiveBipolarLikertArrayProps, ResponsiveBipolarLikertArrayQuestionProps, ResponsiveSingleChoiceArrayProps, ResponsiveSingleChoiceArrayQuestionProps, TextInputQuestionProps } from "./types/item-properties";
3
+ interface OptionQuestionProps extends GenericQuestionProps {
4
+ responseOptions: Array<OptionDef>;
5
+ }
6
+ interface LikertGroupQuestionProps extends GenericQuestionProps {
7
+ rows: Array<LikertGroupRow>;
8
+ scaleOptions: Array<{
9
+ key: string;
10
+ className?: string;
11
+ content: Map<string, string>;
12
+ }>;
13
+ stackOnSmallScreen?: boolean;
14
+ }
15
+ interface NumericSliderProps extends GenericQuestionProps {
16
+ sliderLabel: Map<string, string>;
17
+ noResponseLabel: Map<string, string>;
18
+ min?: number | ExpressionArg;
19
+ max?: number | ExpressionArg;
20
+ stepSize?: number | ExpressionArg;
21
+ }
22
+ interface DisplayProps {
23
+ parentKey: string;
24
+ itemKey: string;
25
+ content: Array<ItemComponent>;
26
+ condition?: Expression;
27
+ }
28
+ export declare const initSingleChoiceGroup: (key: string, optionItems: OptionDef[], order?: Expression | undefined) => ItemGroupComponent;
29
+ export declare const initMultipleChoiceGroup: (key: string, optionItems: OptionDef[], order?: Expression | undefined) => ItemGroupComponent;
30
+ 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;
31
+ export declare const initSliderCategoricalGroup: (key: string, optionItems: OptionDef[], order?: Expression | undefined, groupDisabled?: Expression | undefined) => ItemGroupComponent;
32
+ interface HeaderRow {
33
+ role: 'headerRow';
34
+ key: string;
35
+ displayCondition?: Expression;
36
+ disabled?: Expression;
37
+ cells: Array<{
38
+ role: 'text';
39
+ key: string;
40
+ content?: Map<string, string>;
41
+ description?: Map<string, string>;
42
+ }>;
43
+ }
44
+ interface RadioRow {
45
+ role: 'radioRow';
46
+ key: string;
47
+ displayCondition?: Expression;
48
+ disabled?: Expression;
49
+ cells: Array<{
50
+ role: 'label' | 'option';
51
+ key: string;
52
+ content?: Map<string, string>;
53
+ description?: Map<string, string>;
54
+ }>;
55
+ }
56
+ export interface ResponseRowCell {
57
+ role: 'label' | 'check' | 'input' | 'numberInput' | 'dropDownGroup';
58
+ key: string;
59
+ content?: Map<string, string>;
60
+ description?: Map<string, string>;
61
+ properties?: ComponentProperties;
62
+ items?: Array<{
63
+ role: 'option';
64
+ key: string;
65
+ content?: Map<string, string>;
66
+ disabled?: Expression;
67
+ displayCondition?: Expression;
68
+ }>;
69
+ }
70
+ interface ResponseRow {
71
+ role: 'responseRow';
72
+ key: string;
73
+ displayCondition?: Expression;
74
+ disabled?: Expression;
75
+ cells: Array<ResponseRowCell>;
76
+ }
77
+ declare type MatrixRow = HeaderRow | RadioRow | ResponseRow;
78
+ export declare const initMatrixQuestion: (key: string, rows: Array<MatrixRow>, order?: Expression | undefined) => ItemGroupComponent;
79
+ interface EQ5DHealthSliderProps {
80
+ role: 'eq5d-health-indicator';
81
+ key: string;
82
+ displayCondition?: Expression;
83
+ disabled?: Expression;
84
+ instructionText: Map<string, string>;
85
+ valueBoxText: Map<string, string>;
86
+ maxHealthText: Map<string, string>;
87
+ minHealthText: Map<string, string>;
88
+ }
89
+ export declare const initEQ5DHealthIndicatorQuestion: (props: EQ5DHealthSliderProps) => ItemGroupComponent;
90
+ interface LikertGroupRow {
91
+ key: string;
92
+ content: Map<string, string>;
93
+ descriptions?: ItemComponent[];
94
+ hideTopBorder?: boolean;
95
+ hideLabels?: boolean;
96
+ optionDisabled?: Array<{
97
+ optionKey: string;
98
+ exp: Expression;
99
+ }>;
100
+ displayCondition?: Expression;
101
+ }
102
+ export declare const initLikertScaleGroup: (key: string, rows: Array<LikertGroupRow>, scaleOptions: {
103
+ key: string;
104
+ className?: string | undefined;
105
+ content: Map<string, string>;
106
+ }[], stackOnSmallScreen?: boolean | undefined, displayCondition?: Expression | undefined) => ItemGroupComponent;
107
+ export declare const initResponsiveSingleChoiceArray: (rgKey: string, props: ResponsiveSingleChoiceArrayProps, displayCondition?: Expression | undefined) => ItemGroupComponent;
108
+ export declare const initResponsiveBipolarLikertArray: (rgKey: string, props: ResponsiveBipolarLikertArrayProps, displayCondition?: Expression | undefined) => ItemGroupComponent;
109
+ export declare const initLikertScaleItem: (key: string, options: {
110
+ key: string;
111
+ className?: string | undefined;
112
+ content?: Map<string, string> | undefined;
113
+ disabled?: Expression | undefined;
114
+ }[], stackOnSmallScreen?: boolean | undefined, displayCondition?: Expression | undefined) => ItemGroupComponent;
115
+ export declare const SurveyItems: {
116
+ singleChoice: (props: OptionQuestionProps) => SurveyItem;
117
+ responsiveSingleChoiceArray: (props: ResponsiveSingleChoiceArrayQuestionProps) => SurveyItem;
118
+ responsiveBipolarLikertArray: (props: ResponsiveBipolarLikertArrayQuestionProps) => SurveyItem;
119
+ multipleChoice: (props: OptionQuestionProps) => SurveyItem;
120
+ dateInput: (props: DateInputQuestionProps) => SurveyItem;
121
+ textInput: (props: TextInputQuestionProps) => SurveyItem;
122
+ clozeQuestion: (props: ClozeQuestionProps) => SurveyItem;
123
+ numericInput: (props: NumericInputQuestionProps) => SurveyItem;
124
+ multilineTextInput: (props: MultiLineTextInput) => SurveyItem;
125
+ dropDown: (props: OptionQuestionProps) => SurveyItem;
126
+ numericSlider: (props: NumericSliderProps) => SurveyItem;
127
+ display: (props: DisplayProps) => SurveyItem;
128
+ surveyEnd: (parentKey: string, content: Map<string, string>, condition?: Expression | undefined) => SurveyItem;
129
+ old: {
130
+ simpleLikertGroup: (props: LikertGroupQuestionProps) => SurveyItem;
131
+ };
132
+ };
133
+ export {};