@inseefr/lunatic 2.6.2-rc.1 → 2.6.3-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/lib/components/index.js +4 -4
  2. package/lib/components/loop/block-for-loop.js +6 -10
  3. package/lib/components/loop/roster-for-loop/roster-for-loop.js +27 -35
  4. package/lib/components/lunatic-components.js +16 -5
  5. package/lib/components/pairwise-links/pairwise-links.js +27 -30
  6. package/lib/components/table/lunatic-table.js +22 -13
  7. package/lib/components/table/{header.js → table-header.js} +3 -5
  8. package/lib/hooks/use-track-changes.js +50 -0
  9. package/lib/src/components/index.d.ts +2 -2
  10. package/lib/src/components/loop/block-for-loop.d.ts +3 -4
  11. package/lib/src/components/loop/roster-for-loop/roster-for-loop.d.ts +3 -4
  12. package/lib/src/components/lunatic-components.d.ts +5 -3
  13. package/lib/src/components/pairwise-links/pairwise-links.d.ts +1 -2
  14. package/lib/src/components/table/lunatic-table.d.ts +1 -1
  15. package/lib/src/components/table/{header.d.ts → table-header.d.ts} +2 -2
  16. package/lib/src/components/type.d.ts +5 -6
  17. package/lib/src/hooks/use-track-changes.d.ts +9 -0
  18. package/lib/src/use-lunatic/actions.d.ts +3 -16
  19. package/lib/src/use-lunatic/commons/compile-controls.d.ts +3 -2
  20. package/lib/src/use-lunatic/commons/component.d.ts +22 -0
  21. package/lib/src/use-lunatic/commons/fill-components/fill-component-value.d.ts +2 -3
  22. package/lib/src/use-lunatic/commons/fill-components/fill-components.d.ts +6 -0
  23. package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +107 -122
  24. package/lib/src/use-lunatic/commons/fill-components/fill-iterations.d.ts +112 -0
  25. package/lib/src/use-lunatic/commons/fill-components/fill-specific-expression.d.ts +53 -89
  26. package/lib/src/use-lunatic/commons/get-compatible-vtl-expression.d.ts +1 -0
  27. package/lib/src/use-lunatic/commons/index.d.ts +0 -3
  28. package/lib/src/use-lunatic/commons/variables/behaviours/cleaning-behaviour.d.ts +7 -0
  29. package/lib/src/use-lunatic/commons/variables/behaviours/missing-behaviour.d.ts +7 -0
  30. package/lib/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.d.ts +7 -0
  31. package/lib/src/use-lunatic/commons/variables/get-questionnaire-data.d.ts +4 -0
  32. package/lib/src/use-lunatic/commons/variables/lunatic-variables-store.d.ts +77 -0
  33. package/lib/src/use-lunatic/reducer/overview/overview-on-init.d.ts +10 -8
  34. package/lib/src/use-lunatic/reducer/reduce-handle-change.d.ts +6 -0
  35. package/lib/src/use-lunatic/reducer/reduce-on-init.d.ts +1 -12
  36. package/lib/src/use-lunatic/type-source.d.ts +7 -21
  37. package/lib/src/use-lunatic/type.d.ts +13 -11
  38. package/lib/src/use-lunatic/use-lunatic.d.ts +33 -56
  39. package/lib/src/utils/array.d.ts +6 -1
  40. package/lib/src/utils/env.d.ts +1 -0
  41. package/lib/src/utils/number.d.ts +4 -0
  42. package/lib/src/utils/variables.d.ts +5 -0
  43. package/lib/src/utils/vtl.d.ts +14 -0
  44. package/lib/use-lunatic/actions.js +3 -3
  45. package/lib/use-lunatic/commons/compile-controls.js +3 -5
  46. package/lib/use-lunatic/commons/component.js +22 -0
  47. package/lib/use-lunatic/commons/execute-condition-filter.js +1 -9
  48. package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +2 -3
  49. package/lib/use-lunatic/commons/fill-components/fill-component-value.js +21 -7
  50. package/lib/use-lunatic/commons/fill-components/fill-components.js +5 -3
  51. package/lib/use-lunatic/commons/{execute-expression/get-safety-expression.js → fill-components/fill-iterations.js} +30 -20
  52. package/lib/use-lunatic/commons/fill-components/fill-missing-response.js +6 -13
  53. package/lib/use-lunatic/commons/fill-components/fill-specific-expression.js +58 -5
  54. package/lib/use-lunatic/commons/get-compatible-vtl-expression.js +1 -0
  55. package/lib/use-lunatic/commons/index.js +0 -21
  56. package/lib/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +39 -0
  57. package/lib/use-lunatic/commons/variables/behaviours/missing-behaviour.js +47 -0
  58. package/lib/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +78 -0
  59. package/lib/use-lunatic/{reducer/reduce-handle-change/reduce-variables-array.js → commons/variables/get-questionnaire-data.js} +53 -32
  60. package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +330 -0
  61. package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +216 -0
  62. package/lib/use-lunatic/initial-state.js +5 -2
  63. package/lib/use-lunatic/reducer/overview/overview-on-change.js +1 -1
  64. package/lib/use-lunatic/reducer/{reduce-handle-change/reduce-variables-simple.js → reduce-handle-change.js} +15 -14
  65. package/lib/use-lunatic/reducer/reduce-on-init.js +89 -181
  66. package/lib/use-lunatic/reducer/reducer.js +2 -2
  67. package/lib/use-lunatic/reducer/resolve-component-controls/resolve-simple-control.js +2 -4
  68. package/lib/use-lunatic/use-lunatic.js +18 -14
  69. package/lib/use-lunatic/use-lunatic.test.js +131 -2
  70. package/lib/utils/array.js +57 -6
  71. package/lib/utils/array.spec.js +30 -0
  72. package/lib/utils/env.js +10 -0
  73. package/lib/utils/get-component-value.js +3 -9
  74. package/lib/utils/number.js +13 -1
  75. package/lib/utils/variables.js +37 -0
  76. package/lib/utils/vtl.js +100 -0
  77. package/package.json +1 -1
  78. package/lib/components/loop/utils/get-initial-nb-rows.js +0 -17
  79. package/lib/components/pairwise-links/index.js +0 -13
  80. package/lib/components/pairwise-links/orchestrator.js +0 -71
  81. package/lib/components/pairwise-links/row.js +0 -74
  82. package/lib/components/table/cell.js +0 -89
  83. package/lib/components/table/index.js +0 -13
  84. package/lib/components/table/row.js +0 -40
  85. package/lib/components/table/table-orchestrator.js +0 -35
  86. package/lib/src/components/loop/utils/get-initial-nb-rows.d.ts +0 -4
  87. package/lib/src/components/pairwise-links/index.d.ts +0 -1
  88. package/lib/src/components/pairwise-links/orchestrator.d.ts +0 -6
  89. package/lib/src/components/pairwise-links/row.d.ts +0 -7
  90. package/lib/src/components/table/cell.d.ts +0 -19
  91. package/lib/src/components/table/index.d.ts +0 -1
  92. package/lib/src/components/table/row.d.ts +0 -18
  93. package/lib/src/components/table/table-orchestrator.d.ts +0 -4
  94. package/lib/src/use-lunatic/commons/calculated-variables.d.ts +0 -8
  95. package/lib/src/use-lunatic/commons/execute-expression/create-execute-expression.d.ts +0 -9
  96. package/lib/src/use-lunatic/commons/execute-expression/create-memoizer.d.ts +0 -8
  97. package/lib/src/use-lunatic/commons/execute-expression/create-refresh-calculated.d.ts +0 -24
  98. package/lib/src/use-lunatic/commons/execute-expression/execute-expression.d.ts +0 -11
  99. package/lib/src/use-lunatic/commons/execute-expression/get-expressions-variables.d.ts +0 -7
  100. package/lib/src/use-lunatic/commons/execute-expression/get-expressions-variables.spec.d.ts +0 -1
  101. package/lib/src/use-lunatic/commons/execute-expression/get-safety-expression.d.ts +0 -6
  102. package/lib/src/use-lunatic/commons/execute-expression/index.d.ts +0 -1
  103. package/lib/src/use-lunatic/commons/get-component-value/get-component-value.d.ts +0 -6
  104. package/lib/src/use-lunatic/commons/get-component-value/index.d.ts +0 -1
  105. package/lib/src/use-lunatic/commons/get-data.d.ts +0 -26
  106. package/lib/src/use-lunatic/reducer/reduce-handle-change/index.d.ts +0 -1
  107. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.d.ts +0 -7
  108. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.spec.d.ts +0 -1
  109. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.d.ts +0 -4
  110. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-links-variable.d.ts +0 -15
  111. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-missing.d.ts +0 -7
  112. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-resizing.d.ts +0 -4
  113. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-variables-array.d.ts +0 -14
  114. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-variables-simple.d.ts +0 -9
  115. package/lib/src/use-lunatic/reducer/reduce-on-init.spec.d.ts +0 -1
  116. package/lib/src/utils/vtl/dataset-builder.d.ts +0 -5
  117. package/lib/src/utils/vtl/index.d.ts +0 -1
  118. package/lib/use-lunatic/commons/calculated-variables.js +0 -104
  119. package/lib/use-lunatic/commons/execute-expression/create-execute-expression.js +0 -233
  120. package/lib/use-lunatic/commons/execute-expression/create-execute-expression.spec.js +0 -155
  121. package/lib/use-lunatic/commons/execute-expression/create-memoizer.js +0 -63
  122. package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.js +0 -149
  123. package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.spec.js +0 -130
  124. package/lib/use-lunatic/commons/execute-expression/execute-expression.js +0 -90
  125. package/lib/use-lunatic/commons/execute-expression/execute-expression.spec.js +0 -38
  126. package/lib/use-lunatic/commons/execute-expression/get-expressions-variables.js +0 -40
  127. package/lib/use-lunatic/commons/execute-expression/get-expressions-variables.spec.js +0 -31
  128. package/lib/use-lunatic/commons/execute-expression/index.js +0 -13
  129. package/lib/use-lunatic/commons/get-component-value/get-component-value.js +0 -174
  130. package/lib/use-lunatic/commons/get-component-value/index.js +0 -13
  131. package/lib/use-lunatic/commons/get-data.js +0 -80
  132. package/lib/use-lunatic/reducer/reduce-handle-change/__mocks__/source-cleaning-loop.json +0 -792
  133. package/lib/use-lunatic/reducer/reduce-handle-change/index.js +0 -13
  134. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.js +0 -72
  135. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.spec.js +0 -46
  136. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.js +0 -115
  137. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-links-variable.js +0 -89
  138. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-missing.js +0 -88
  139. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-resizing.js +0 -110
  140. package/lib/use-lunatic/reducer/reduce-on-init.spec.js +0 -17
  141. package/lib/utils/vtl/dataset-builder.js +0 -27
  142. package/lib/utils/vtl/index.js +0 -13
  143. /package/lib/src/use-lunatic/commons/{execute-expression/create-refresh-calculated.spec.d.ts → variables/lunatic-variables-store.spec.d.ts} +0 -0
  144. /package/lib/src/{use-lunatic/commons/execute-expression/execute-expression.spec.d.ts → utils/array.spec.d.ts} +0 -0
@@ -1,174 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
8
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
10
- function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
11
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
14
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
15
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
18
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
20
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
21
- function isInSubPage(state) {
22
- return state.pager.subPage !== undefined;
23
- }
24
-
25
- /**
26
- * Add the value from variable indexed by response name
27
- */
28
- function mergeResponse(_ref) {
29
- var map = _ref.map,
30
- response = _ref.response,
31
- variables = _ref.variables;
32
- var name = response.name;
33
- if (name in variables) {
34
- return _objectSpread(_objectSpread({}, map), {}, _defineProperty({}, name, variables[name].value));
35
- }
36
- return map;
37
- }
38
- function collecteArrayResponses(_ref2) {
39
- var components = _ref2.components,
40
- variables = _ref2.variables,
41
- _ref2$map = _ref2.map,
42
- map = _ref2$map === void 0 ? {} : _ref2$map;
43
- return components.reduce(function (sub, component) {
44
- return collecteComponentResponse({
45
- component: component,
46
- variables: variables,
47
- map: sub
48
- });
49
- }, map);
50
- }
51
- function collectCell(_ref3) {
52
- var cell = _ref3.cell,
53
- variables = _ref3.variables,
54
- map = _ref3.map;
55
- var _cell = _toArray(cell),
56
- component = _cell[0],
57
- rest = _cell.slice(1);
58
- var componentType = component.componentType;
59
- var next = map;
60
- if (componentType) {
61
- next = _objectSpread(_objectSpread({}, map), collecteComponentResponse({
62
- component: component,
63
- variables: variables,
64
- map: map
65
- }));
66
- }
67
- if (rest.length) {
68
- return collectCell({
69
- cell: rest,
70
- variables: variables,
71
- map: next
72
- });
73
- }
74
- return next;
75
- }
76
- function collectTableResponse(_ref4) {
77
- var map = _ref4.map,
78
- body = _ref4.body,
79
- variables = _ref4.variables;
80
- if (Array.isArray(body)) {
81
- return body.reduce(function (sub, cell) {
82
- if (Array.isArray(cell)) {
83
- return collectCell({
84
- cell: cell,
85
- variables: variables,
86
- map: sub
87
- });
88
- }
89
- return sub;
90
- }, map);
91
- }
92
- return map;
93
- }
94
- function collecteComponentResponse(_ref5) {
95
- var component = _ref5.component,
96
- variables = _ref5.variables,
97
- _ref5$map = _ref5.map,
98
- map = _ref5$map === void 0 ? {} : _ref5$map;
99
- if ('body' in component && component.body) {
100
- return collectTableResponse({
101
- map: map,
102
- body: component.body,
103
- variables: variables
104
- });
105
- }
106
- if ('response' in component) {
107
- return mergeResponse({
108
- map: map,
109
- response: component.response,
110
- variables: variables
111
- });
112
- }
113
- if ('components' in component) {
114
- return collecteArrayResponses({
115
- components: component.components,
116
- variables: variables,
117
- map: map
118
- });
119
- }
120
- if ('responses' in component) {
121
- // TODO : Understand this cause types doesn't match
122
- return collecteArrayResponses({
123
- components: component.responses,
124
- variables: variables,
125
- map: map
126
- });
127
- }
128
- return map;
129
- }
130
- function checkArrayForSubPage(map, state) {
131
- var pager = state.pager;
132
- var iteration = pager.iteration;
133
- return Object.entries(map).reduce(function (sub, _ref6) {
134
- var _ref7 = _slicedToArray(_ref6, 2),
135
- name = _ref7[0],
136
- value = _ref7[1];
137
- if (value && Array.isArray(value) && iteration !== undefined) {
138
- return _objectSpread(_objectSpread({}, sub), {}, _defineProperty({}, name, value[iteration]));
139
- }
140
- return _objectSpread(_objectSpread({}, sub), {}, _defineProperty({}, name, value));
141
- }, {});
142
- }
143
- function checkUseContext(map, state) {
144
- if (isInSubPage(state)) {
145
- return checkArrayForSubPage(map, state);
146
- }
147
- return map;
148
- }
149
-
150
- /**
151
- * The component provide a direct response (not a loop, roster...)
152
- */
153
- function isSimpleComponent(component) {
154
- return 'response' in component && _typeof(component.response) === 'object';
155
- }
156
-
157
- /**
158
- * Get the value from the component
159
- */
160
- function getComponentValue(component, state) {
161
- var variables = state.variables;
162
- var map = checkUseContext(collecteComponentResponse({
163
- component: component,
164
- variables: variables
165
- }), state);
166
- if (isSimpleComponent(component)) {
167
- var response = component.response;
168
- var name = response.name;
169
- return map[name];
170
- }
171
- return map;
172
- }
173
- var _default = getComponentValue;
174
- exports["default"] = _default;
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "default", {
7
- enumerable: true,
8
- get: function get() {
9
- return _getComponentValue["default"];
10
- }
11
- });
12
- var _getComponentValue = _interopRequireDefault(require("./get-component-value"));
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -1,80 +0,0 @@
1
- "use strict";
2
-
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getQuestionnaireData = void 0;
8
- var _constants = require("../../constants");
9
- var _calculatedVariables = require("./calculated-variables");
10
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
14
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
15
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
16
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
17
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
18
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
19
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
20
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
21
- /**
22
- * Extract the value from a questionnaire
23
- *
24
- * used by the "getData" method from the state at the end of a form
25
- */
26
- var getQuestionnaireData = function getQuestionnaireData(_ref) {
27
- var variables = _ref.variables,
28
- withRefreshedCalculated = _ref.withRefreshedCalculated;
29
- var builtVariables = Object.entries(variables).reduce(function (acc, _ref2) {
30
- var _ref3 = _slicedToArray(_ref2, 2),
31
- k = _ref3[0],
32
- _ref3$ = _ref3[1],
33
- value = _ref3$.value,
34
- type = _ref3$.type;
35
- // TODO: refine for management
36
- if (type === _constants.COLLECTED) return _objectSpread(_objectSpread({}, acc), {}, {
37
- COLLECTED: _objectSpread(_objectSpread({}, acc.COLLECTED), {}, _defineProperty({}, k, {
38
- EDITED: null,
39
- FORCED: null,
40
- INPUTED: null,
41
- PREVIOUS: null,
42
- COLLECTED: value
43
- }))
44
- });
45
- if (type === _constants.EXTERNAL || type === _constants.CALCULATED && !withRefreshedCalculated) return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, type, _objectSpread(_objectSpread({}, acc[type]), {}, _defineProperty({}, k, value))));
46
- return acc;
47
- }, {
48
- EXTERNAL: {},
49
- CALCULATED: {},
50
- COLLECTED: {}
51
- });
52
- if (!withRefreshedCalculated) return builtVariables;
53
- var flattenBuiltVariables = Object.entries(builtVariables).reduce(function (acc, _ref4) {
54
- var _ref5 = _slicedToArray(_ref4, 2),
55
- type = _ref5[0],
56
- v = _ref5[1];
57
- if (type === _constants.COLLECTED) {
58
- var collectedVariables = Object.entries(v).reduce(function (accCol, _ref6) {
59
- var _ref7 = _slicedToArray(_ref6, 2),
60
- k = _ref7[0],
61
- c = _ref7[1].COLLECTED;
62
- return _objectSpread(_objectSpread({}, accCol), {}, _defineProperty({}, k, c));
63
- }, {});
64
- return _objectSpread(_objectSpread({}, acc), collectedVariables);
65
- }
66
- return _objectSpread(_objectSpread({}, acc), v);
67
- }, {});
68
- var flattenCalculatedVariables = (0, _calculatedVariables.interpretAllCalculatedVariables)({
69
- variables: variables,
70
- builtVariables: flattenBuiltVariables
71
- });
72
- var calculatedVariables = Object.entries(flattenCalculatedVariables).reduce(function (acc, _ref8) {
73
- var _ref9 = _slicedToArray(_ref8, 2),
74
- k = _ref9[0],
75
- v = _ref9[1];
76
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, k, v));
77
- }, {});
78
- return _objectSpread(_objectSpread({}, builtVariables), {}, _defineProperty({}, _constants.CALCULATED, calculatedVariables));
79
- };
80
- exports.getQuestionnaireData = getQuestionnaireData;