@inseefr/lunatic 2.6.3-rc.1 → 2.6.3

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 (257) hide show
  1. package/README.md +49 -3
  2. package/lib/components/checkbox/checkbox-boolean/html/checkbox-boolean.js +3 -3
  3. package/lib/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.js +7 -1
  4. package/lib/components/checkbox/checkbox-group/checkbox-group-content.js +0 -2
  5. package/lib/components/checkbox/checkbox-group/html/checkbox-group-content.js +4 -2
  6. package/lib/components/checkbox/checkbox-group/html/checkbox-group.js +3 -3
  7. package/lib/components/checkbox/checkbox-group/lunatic-checkbox-group.js +2 -1
  8. package/lib/components/checkbox/checkbox-one/lunatic-checkbox-one.js +2 -1
  9. package/lib/components/checkbox/commons/checkbox-option.js +3 -1
  10. package/lib/components/commons/components/combo-box/combo-box-container.js +1 -2
  11. package/lib/components/commons/components/combo-box/combo-box.js +2 -2
  12. package/lib/components/commons/components/combo-box/selection/LabelOrInput.js +3 -1
  13. package/lib/components/commons/components/combo-box/selection/input.js +3 -1
  14. package/lib/components/commons/components/combo-box/selection/selection.js +3 -1
  15. package/lib/components/commons/components/errors/errors.js +12 -10
  16. package/lib/components/commons/components/errors/errors.spec.js +6 -6
  17. package/lib/components/component-set/html/__snapshots__/component-set.spec.tsx.snap +2 -0
  18. package/lib/components/component-set/html/component-set.js +2 -2
  19. package/lib/components/datepicker/html/__snapshots__/datepicker.spec.tsx.snap +2 -0
  20. package/lib/components/datepicker/html/datepicker-input.js +4 -2
  21. package/lib/components/datepicker/html/datepicker.js +3 -3
  22. package/lib/components/datepicker/lunatic-datepicker.js +2 -1
  23. package/lib/components/dropdown/lunatic-dropdown.js +2 -1
  24. package/lib/components/index.js +4 -4
  25. package/lib/components/input/html/__snapshots__/input.spec.tsx.snap +2 -0
  26. package/lib/components/input/html/input.js +3 -3
  27. package/lib/components/input/lunatic-input.js +2 -1
  28. package/lib/components/input-number/html/__snapshots__/input-number.spec.tsx.snap +2 -2
  29. package/lib/components/input-number/html/input-number-thousand.js +4 -17
  30. package/lib/components/input-number/html/input-number.js +3 -5
  31. package/lib/components/input-number/lunatic-input-number.js +2 -3
  32. package/lib/components/loop/block-for-loop.js +10 -6
  33. package/lib/components/loop/roster-for-loop/roster-for-loop.js +35 -27
  34. package/lib/components/loop/utils/get-initial-nb-rows.js +17 -0
  35. package/lib/components/lunatic-components.js +7 -27
  36. package/lib/components/pairwise-links/index.js +13 -0
  37. package/lib/components/pairwise-links/orchestrator.js +71 -0
  38. package/lib/components/pairwise-links/pairwise-links.js +30 -27
  39. package/lib/components/pairwise-links/row.js +74 -0
  40. package/lib/components/radio/html/radio-group-content.js +4 -2
  41. package/lib/components/radio/html/radio-group.js +3 -3
  42. package/lib/components/radio/html/radio-option.js +3 -1
  43. package/lib/components/radio/lunatic-radio-group.js +2 -1
  44. package/lib/components/suggester/find-best-label/find-best-label.js +6 -6
  45. package/lib/components/suggester/idb-suggester/idb-suggester.js +4 -3
  46. package/lib/components/suggester/lunatic-suggester.js +7 -4
  47. package/lib/components/suggester/searching/create-searching.js +20 -39
  48. package/lib/components/switch/html/switch.js +2 -2
  49. package/lib/components/switch/lunatic-switch.js +2 -1
  50. package/lib/components/table/cell.js +89 -0
  51. package/lib/components/table/{table-header.js → header.js} +5 -3
  52. package/lib/components/table/index.js +13 -0
  53. package/lib/components/table/lunatic-table.js +15 -24
  54. package/lib/components/table/row.js +40 -0
  55. package/lib/components/table/table-orchestrator.js +35 -0
  56. package/lib/components/textarea/html/__snapshots__/textarea.spec.tsx.snap +2 -0
  57. package/lib/components/textarea/html/textarea.js +6 -4
  58. package/lib/components/textarea/lunatic-textarea.js +6 -3
  59. package/lib/hooks/use-auto-focus.js +26 -0
  60. package/lib/src/components/checkbox/checkbox-boolean/html/checkbox-boolean.d.ts +1 -1
  61. package/lib/src/components/checkbox/checkbox-group/html/checkbox-group-content.d.ts +2 -1
  62. package/lib/src/components/checkbox/checkbox-group/html/checkbox-group.d.ts +1 -1
  63. package/lib/src/components/checkbox/commons/checkbox-option.d.ts +1 -0
  64. package/lib/src/components/commons/components/combo-box/combo-box-container.d.ts +2 -2
  65. package/lib/src/components/commons/components/combo-box/combo-box.d.ts +2 -2
  66. package/lib/src/components/commons/components/combo-box/combo-box.stories.d.ts +4 -6
  67. package/lib/src/components/commons/components/combo-box/selection/LabelOrInput.d.ts +1 -0
  68. package/lib/src/components/commons/components/combo-box/selection/input.d.ts +1 -0
  69. package/lib/src/components/commons/components/combo-box/selection/selection.d.ts +2 -1
  70. package/lib/src/components/commons/components/errors/errors.d.ts +6 -3
  71. package/lib/src/components/datepicker/html/datepicker-input.d.ts +2 -1
  72. package/lib/src/components/datepicker/html/datepicker.d.ts +1 -1
  73. package/lib/src/components/dropdown/html/dropdown-writable/dropdown-writable.d.ts +1 -1
  74. package/lib/src/components/dropdown/html/dropdown.d.ts +3 -1
  75. package/lib/src/components/index.d.ts +2 -2
  76. package/lib/src/components/input/html/input.d.ts +2 -2
  77. package/lib/src/components/input-number/html/input-number-thousand.d.ts +2 -2
  78. package/lib/src/components/input-number/html/input-number.d.ts +2 -3
  79. package/lib/src/components/loop/block-for-loop.d.ts +4 -3
  80. package/lib/src/components/loop/roster-for-loop/roster-for-loop.d.ts +4 -3
  81. package/lib/src/components/loop/utils/get-initial-nb-rows.d.ts +4 -0
  82. package/lib/src/components/lunatic-components.d.ts +3 -5
  83. package/lib/src/components/pairwise-links/index.d.ts +1 -0
  84. package/lib/src/components/pairwise-links/orchestrator.d.ts +6 -0
  85. package/lib/src/components/pairwise-links/pairwise-links.d.ts +2 -1
  86. package/lib/src/components/pairwise-links/row.d.ts +7 -0
  87. package/lib/src/components/radio/html/radio-group-content.d.ts +2 -1
  88. package/lib/src/components/radio/html/radio-group.d.ts +1 -1
  89. package/lib/src/components/radio/html/radio-option.d.ts +1 -0
  90. package/lib/src/components/suggester/find-best-label/find-best-label.d.ts +1 -1
  91. package/lib/src/components/suggester/html/suggester.d.ts +1 -1
  92. package/lib/src/components/suggester/idb-suggester/idb-suggester.d.ts +5 -2
  93. package/lib/src/components/suggester/lunatic-suggester.d.ts +1 -1
  94. package/lib/src/components/suggester/searching/create-searching.d.ts +1 -1
  95. package/lib/src/components/switch/html/switch.d.ts +1 -1
  96. package/lib/src/components/table/cell.d.ts +19 -0
  97. package/lib/src/components/table/{table-header.d.ts → header.d.ts} +2 -2
  98. package/lib/src/components/table/index.d.ts +1 -0
  99. package/lib/src/components/table/lunatic-table.d.ts +1 -1
  100. package/lib/src/components/table/row.d.ts +18 -0
  101. package/lib/src/components/table/table-orchestrator.d.ts +4 -0
  102. package/lib/src/components/textarea/html/textarea.d.ts +3 -2
  103. package/lib/src/components/type.d.ts +9 -7
  104. package/lib/src/hooks/use-auto-focus.d.ts +6 -0
  105. package/lib/src/use-lunatic/actions.d.ts +19 -3
  106. package/lib/src/use-lunatic/commons/calculated-variables.d.ts +8 -0
  107. package/lib/src/use-lunatic/commons/compile-controls.d.ts +2 -3
  108. package/lib/src/use-lunatic/commons/execute-expression/create-execute-expression.d.ts +9 -0
  109. package/lib/src/use-lunatic/commons/execute-expression/create-memoizer.d.ts +8 -0
  110. package/lib/src/use-lunatic/commons/execute-expression/create-refresh-calculated.d.ts +24 -0
  111. package/lib/src/use-lunatic/commons/execute-expression/execute-expression.d.ts +11 -0
  112. package/lib/src/use-lunatic/commons/execute-expression/get-expressions-variables.d.ts +7 -0
  113. package/lib/src/use-lunatic/commons/execute-expression/get-expressions-variables.spec.d.ts +1 -0
  114. package/lib/src/use-lunatic/commons/execute-expression/get-safety-expression.d.ts +6 -0
  115. package/lib/src/use-lunatic/commons/execute-expression/index.d.ts +1 -0
  116. package/lib/src/use-lunatic/commons/fill-components/fill-component-required.d.ts +418 -0
  117. package/lib/src/use-lunatic/commons/fill-components/fill-component-value.d.ts +3 -2
  118. package/lib/src/use-lunatic/commons/fill-components/fill-components.d.ts +0 -6
  119. package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +142 -107
  120. package/lib/src/use-lunatic/commons/fill-components/fill-specific-expression.d.ts +89 -53
  121. package/lib/src/use-lunatic/commons/get-compatible-vtl-expression.d.ts +0 -1
  122. package/lib/src/use-lunatic/commons/get-component-value/get-component-value.d.ts +6 -0
  123. package/lib/src/use-lunatic/commons/get-component-value/index.d.ts +1 -0
  124. package/lib/src/use-lunatic/commons/get-data.d.ts +26 -0
  125. package/lib/src/use-lunatic/commons/index.d.ts +3 -0
  126. package/lib/src/use-lunatic/reducer/overview/overview-on-init.d.ts +9 -10
  127. package/lib/src/use-lunatic/reducer/reduce-handle-change/index.d.ts +1 -0
  128. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.d.ts +7 -0
  129. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.spec.d.ts +1 -0
  130. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.d.ts +4 -0
  131. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-links-variable.d.ts +15 -0
  132. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-missing.d.ts +7 -0
  133. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-resizing.d.ts +4 -0
  134. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-variables-array.d.ts +14 -0
  135. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-variables-simple.d.ts +9 -0
  136. package/lib/src/use-lunatic/reducer/reduce-on-init.d.ts +12 -1
  137. package/lib/src/use-lunatic/reducer/reduce-on-init.spec.d.ts +1 -0
  138. package/lib/src/use-lunatic/type-source.d.ts +21 -7
  139. package/lib/src/use-lunatic/type.d.ts +12 -13
  140. package/lib/src/use-lunatic/use-lunatic.d.ts +62 -36
  141. package/lib/src/use-lunatic/use-suggesters.d.ts +2 -1
  142. package/lib/src/utils/array.d.ts +1 -6
  143. package/lib/src/utils/number.d.ts +0 -4
  144. package/lib/src/utils/suggester-workers/append-to-index/create-append-task.d.ts +1 -1
  145. package/lib/src/utils/suggester-workers/worker-path.d.ts +6 -0
  146. package/lib/src/utils/vtl/dataset-builder.d.ts +5 -0
  147. package/lib/src/utils/vtl/index.d.ts +1 -0
  148. package/lib/stories/behaviour/cleaning/source.json +151 -0
  149. package/lib/stories/behaviour/cleaning/test.stories.js +84 -0
  150. package/lib/stories/{questionnaires-test → behaviour}/controls/controls.stories.js +5 -5
  151. package/lib/stories/{questionnaires-test → behaviour/others}/test.stories.js +7 -7
  152. package/lib/stories/{paste-questionnaire → behaviour/paste}/test.stories.js +3 -3
  153. package/lib/stories/{resizing-questionnaire → behaviour/resizing}/test.stories.js +3 -3
  154. package/lib/use-lunatic/actions.js +3 -3
  155. package/lib/use-lunatic/commons/calculated-variables.js +104 -0
  156. package/lib/use-lunatic/commons/compile-controls.js +5 -3
  157. package/lib/use-lunatic/commons/execute-condition-filter.js +9 -1
  158. package/lib/use-lunatic/commons/execute-expression/create-execute-expression.js +233 -0
  159. package/lib/use-lunatic/commons/execute-expression/create-execute-expression.spec.js +155 -0
  160. package/lib/use-lunatic/commons/execute-expression/create-memoizer.js +63 -0
  161. package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.js +149 -0
  162. package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.spec.js +130 -0
  163. package/lib/use-lunatic/commons/execute-expression/execute-expression.js +90 -0
  164. package/lib/use-lunatic/commons/execute-expression/execute-expression.spec.js +38 -0
  165. package/lib/use-lunatic/commons/execute-expression/get-expressions-variables.js +40 -0
  166. package/lib/use-lunatic/commons/execute-expression/get-expressions-variables.spec.js +31 -0
  167. package/lib/use-lunatic/commons/{fill-components/fill-iterations.js → execute-expression/get-safety-expression.js} +20 -30
  168. package/lib/use-lunatic/commons/execute-expression/index.js +13 -0
  169. package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +3 -2
  170. package/lib/use-lunatic/{reducer/reduce-handle-change.js → commons/fill-components/fill-component-required.js} +8 -14
  171. package/lib/use-lunatic/commons/fill-components/fill-component-value.js +7 -21
  172. package/lib/use-lunatic/commons/fill-components/fill-components.js +4 -5
  173. package/lib/use-lunatic/commons/fill-components/fill-from-state.js +2 -0
  174. package/lib/use-lunatic/commons/fill-components/fill-missing-response.js +13 -6
  175. package/lib/use-lunatic/commons/fill-components/fill-specific-expression.js +5 -58
  176. package/lib/use-lunatic/commons/get-compatible-vtl-expression.js +0 -1
  177. package/lib/use-lunatic/commons/get-component-value/get-component-value.js +174 -0
  178. package/lib/use-lunatic/commons/get-component-value/index.js +13 -0
  179. package/lib/use-lunatic/commons/get-data.js +80 -0
  180. package/lib/use-lunatic/commons/index.js +21 -0
  181. package/lib/use-lunatic/initial-state.js +4 -6
  182. package/lib/use-lunatic/reducer/overview/overview-on-change.js +1 -1
  183. package/lib/use-lunatic/reducer/reduce-handle-change/__mocks__/source-cleaning-loop.json +792 -0
  184. package/lib/use-lunatic/reducer/reduce-handle-change/index.js +13 -0
  185. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.js +78 -0
  186. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.spec.js +46 -0
  187. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.js +115 -0
  188. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-links-variable.js +89 -0
  189. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-missing.js +88 -0
  190. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-resizing.js +119 -0
  191. package/lib/use-lunatic/{commons/variables/get-questionnaire-data.js → reducer/reduce-handle-change/reduce-variables-array.js} +32 -53
  192. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-variables-simple.js +28 -0
  193. package/lib/use-lunatic/reducer/reduce-on-init.js +184 -90
  194. package/lib/use-lunatic/reducer/reduce-on-init.spec.js +17 -0
  195. package/lib/use-lunatic/reducer/reducer.js +2 -2
  196. package/lib/use-lunatic/reducer/resolve-component-controls/resolve-simple-control.js +4 -2
  197. package/lib/use-lunatic/use-lunatic.js +29 -22
  198. package/lib/use-lunatic/use-lunatic.test.js +36 -133
  199. package/lib/use-lunatic/use-suggesters.js +4 -3
  200. package/lib/utils/array.js +6 -57
  201. package/lib/utils/get-component-value.js +9 -3
  202. package/lib/utils/number.js +1 -13
  203. package/lib/utils/suggester-workers/append-to-index/create-append-task.js +4 -3
  204. package/lib/utils/suggester-workers/worker-path.js +29 -0
  205. package/lib/utils/vtl/dataset-builder.js +27 -0
  206. package/lib/utils/vtl/index.js +13 -0
  207. package/package.json +15 -10
  208. package/scripts/build/add-workers-to-public.js +44 -0
  209. package/scripts/build/workers-paths.js +44 -0
  210. package/workers-release/lunatic-append-worker-0.3.0-experimental.js +2 -0
  211. package/workers-release/lunatic-append-worker-0.3.0-experimental.js.LICENSE.txt +34 -0
  212. package/workers-release/lunatic-label-worker-0.3.0-experimental.js +2 -0
  213. package/workers-release/lunatic-label-worker-0.3.0-experimental.js.LICENSE.txt +13 -0
  214. package/workers-release/lunatic-searching-worker-0.3.0-experimental.js +2 -0
  215. package/workers-release/lunatic-searching-worker-0.3.0-experimental.js.LICENSE.txt +34 -0
  216. package/lib/hooks/use-track-changes.js +0 -50
  217. package/lib/src/hooks/use-track-changes.d.ts +0 -9
  218. package/lib/src/use-lunatic/commons/component.d.ts +0 -22
  219. package/lib/src/use-lunatic/commons/fill-components/fill-iterations.d.ts +0 -112
  220. package/lib/src/use-lunatic/commons/variables/behaviours/cleaning-behaviour.d.ts +0 -7
  221. package/lib/src/use-lunatic/commons/variables/behaviours/missing-behaviour.d.ts +0 -7
  222. package/lib/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.d.ts +0 -7
  223. package/lib/src/use-lunatic/commons/variables/get-questionnaire-data.d.ts +0 -4
  224. package/lib/src/use-lunatic/commons/variables/lunatic-variables-store.d.ts +0 -77
  225. package/lib/src/use-lunatic/reducer/reduce-handle-change.d.ts +0 -6
  226. package/lib/src/utils/env.d.ts +0 -1
  227. package/lib/src/utils/store-tools/worker-path.d.ts +0 -1
  228. package/lib/src/utils/variables.d.ts +0 -5
  229. package/lib/src/utils/vtl.d.ts +0 -14
  230. package/lib/use-lunatic/commons/component.js +0 -22
  231. package/lib/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +0 -39
  232. package/lib/use-lunatic/commons/variables/behaviours/missing-behaviour.js +0 -47
  233. package/lib/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +0 -78
  234. package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +0 -330
  235. package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +0 -216
  236. package/lib/utils/array.spec.js +0 -30
  237. package/lib/utils/env.js +0 -10
  238. package/lib/utils/store-tools/worker-path.js +0 -13
  239. package/lib/utils/suggester-workers/create-worker.js +0 -55
  240. package/lib/utils/variables.js +0 -37
  241. package/lib/utils/vtl.js +0 -100
  242. /package/lib/src/use-lunatic/commons/{variables/lunatic-variables-store.spec.d.ts → execute-expression/create-refresh-calculated.spec.d.ts} +0 -0
  243. /package/lib/src/{utils/array.spec.d.ts → use-lunatic/commons/execute-expression/execute-expression.spec.d.ts} +0 -0
  244. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNonNum_horsBoucle_PasPageFin.json +0 -0
  245. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNum_horsBoucle_PasPageFin.json +0 -0
  246. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees2_PasPageFin.json +0 -0
  247. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees_PasPageFin.json +0 -0
  248. /package/lib/stories/{questionnaires-test → behaviour}/controls/boucles-n.json +0 -0
  249. /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.json +0 -0
  250. /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.stories.js +0 -0
  251. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_DeclarationsSimples.json +0 -0
  252. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_MinMaxSum_Boucles.json +0 -0
  253. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_QuestSimple_Boucles.json +0 -0
  254. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_TCMRallyeGames.json +0 -0
  255. /package/lib/stories/{questionnaires-test → behaviour/others}/test-dylan.json +0 -0
  256. /package/lib/stories/{paste-questionnaire → behaviour/paste}/source.json +0 -0
  257. /package/lib/stories/{resizing-questionnaire → behaviour/resizing}/source.json +0 -0
@@ -0,0 +1,13 @@
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 _reduceHandleChange["default"];
10
+ }
11
+ });
12
+ var _reduceHandleChange = _interopRequireDefault(require("./reduce-handle-change"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _commons = require("../../commons");
8
+ var _object = require("../../../utils/object");
9
+ 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); }
10
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
11
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
15
+ 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; }
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
+ /**
22
+ * Reset variables to null using the cleaning definition in the source.json
23
+ */
24
+ function reduceCleaning(state, action) {
25
+ var response = action.payload.response;
26
+ var executeExpression = state.executeExpression,
27
+ cleaning = state.cleaning,
28
+ variables = state.variables,
29
+ pager = state.pager;
30
+ var iteration = pager.iteration;
31
+ var updateBindings = function updateBindings(variableName, newValue) {
32
+ var _action$payload$args, _action$payload$args$;
33
+ state.updateBindings(variableName, newValue);
34
+ (_action$payload$args = action.payload.args) === null || _action$payload$args === void 0 || (_action$payload$args$ = _action$payload$args.onChange) === null || _action$payload$args$ === void 0 ? void 0 : _action$payload$args$.call(_action$payload$args, {
35
+ name: variableName
36
+ }, newValue, action.payload.args);
37
+ };
38
+ if (!response || !(response.name in cleaning)) {
39
+ return state;
40
+ }
41
+ var expressions = cleaning[response.name];
42
+ var cleanedVariables = (0, _object.objectMap)(expressions, function (variableName, skipExpression) {
43
+ var skipCleaning = executeExpression((0, _commons.getCompatibleVTLExpression)(skipExpression), {
44
+ iteration: iteration
45
+ });
46
+ if (skipCleaning || !(variableName in variables)) {
47
+ return null;
48
+ }
49
+ var variableRoot = variables[variableName];
50
+ var initialValue = cleanedValue(variables[variableName], iteration);
51
+ updateBindings(variableName.toString(), initialValue);
52
+ return [variableName, _objectSpread(_objectSpread({}, variableRoot), {}, {
53
+ value: initialValue
54
+ })];
55
+ });
56
+ //TODO lastReachedPage cleaning
57
+ return _objectSpread(_objectSpread({}, state), {}, {
58
+ variables: _objectSpread(_objectSpread({}, variables), cleanedVariables)
59
+ });
60
+ }
61
+ function cleanedValue(variable, iteration) {
62
+ var _initialValue$iterati;
63
+ var initialValue = null;
64
+ if (variable.variable && 'values' in variable.variable) {
65
+ var _variable$variable$va;
66
+ initialValue = (_variable$variable$va = variable.variable.values.COLLECTED) !== null && _variable$variable$va !== void 0 ? _variable$variable$va : null;
67
+ }
68
+ if (!iteration || !Array.isArray(variable.value)) {
69
+ return initialValue;
70
+ }
71
+
72
+ // Within an iteration we only want to clean the value for this specific iteration
73
+ var newValue = _toConsumableArray(variable.value);
74
+ newValue[iteration] = Array.isArray(initialValue) ? (_initialValue$iterati = initialValue[iteration]) !== null && _initialValue$iterati !== void 0 ? _initialValue$iterati : null : null;
75
+ return newValue;
76
+ }
77
+ var _default = reduceCleaning;
78
+ exports["default"] = _default;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _lunatic = require("../../../../tests/utils/lunatic");
5
+ var _sourceCleaningLoop = _interopRequireDefault(require("./__mocks__/source-cleaning-loop.json"));
6
+ var _reduceCleaning = _interopRequireDefault(require("./reduce-cleaning"));
7
+ var _actions = require("../../actions");
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ (0, _vitest.describe)('reduceCleaning', function () {
10
+ (0, _vitest.it)('should clean variable', function () {
11
+ var state = (0, _lunatic.generateState)(_sourceCleaningLoop["default"], {
12
+ PRENOMREP: ['John', 'Jane'],
13
+ VITICI: ['1', null],
14
+ NBF: [1, 2]
15
+ });
16
+ var newState = (0, _reduceCleaning["default"])(state, {
17
+ type: _actions.ActionKind.HANDLE_CHANGE,
18
+ payload: {
19
+ response: {
20
+ name: 'PRENOMREP'
21
+ },
22
+ value: ['Jane']
23
+ }
24
+ });
25
+ (0, _vitest.expect)(newState.variables['NBF'].value).toEqual([null]);
26
+ });
27
+ (0, _vitest.it)('should clean within a loop', function () {
28
+ var state = (0, _lunatic.generateState)(_sourceCleaningLoop["default"], {
29
+ PRENOMREP: ['John', 'Jane'],
30
+ VITICI: ['1', null],
31
+ NBF: [1, 2]
32
+ }, {
33
+ initialPage: '2.2#2'
34
+ });
35
+ var newState = (0, _reduceCleaning["default"])(state, {
36
+ type: _actions.ActionKind.HANDLE_CHANGE,
37
+ payload: {
38
+ response: {
39
+ name: 'VITICI'
40
+ },
41
+ value: '1'
42
+ }
43
+ });
44
+ (0, _vitest.expect)(newState.variables['NBF'].value).toEqual([1, null]);
45
+ });
46
+ });
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _toNumber2 = require("../../../utils/to-number");
8
+ var _compose = _interopRequireDefault(require("../../commons/compose"));
9
+ var _reduceCleaning = _interopRequireDefault(require("./reduce-cleaning"));
10
+ var _reduceLinksVariable = _interopRequireDefault(require("./reduce-links-variable"));
11
+ var _reduceMissing = _interopRequireDefault(require("./reduce-missing"));
12
+ var _reduceResizing = _interopRequireDefault(require("./reduce-resizing"));
13
+ var _reduceVariablesArray = _interopRequireDefault(require("./reduce-variables-array"));
14
+ var _reduceVariablesSimple = _interopRequireDefault(require("./reduce-variables-simple"));
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
16
+ 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); }
17
+ 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; }
18
+ 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; }
19
+ 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; }
20
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
21
+ 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); }
22
+ function isOnSubPage(pager) {
23
+ var subPage = pager.subPage;
24
+ return subPage !== undefined;
25
+ }
26
+
27
+ /**
28
+ * Met à jour les variables collectés
29
+ */
30
+ function updateVariables(state, action) {
31
+ var payload = action.payload;
32
+ var response = payload.response,
33
+ value = payload.value,
34
+ _payload$args = payload.args,
35
+ args = _payload$args === void 0 ? {} : _payload$args;
36
+ var name = response.name;
37
+ var loop = args.loop,
38
+ index = args.index,
39
+ length = args.length,
40
+ linksIterations = args.linksIterations,
41
+ symLinks = args.symLinks,
42
+ paginatedLoop = args.paginatedLoop,
43
+ shallowIteration = args.shallowIteration,
44
+ lengths = args.lengths;
45
+ var pager = state.pager,
46
+ variables = state.variables;
47
+ if (linksIterations !== undefined) {
48
+ var variablesNext = (0, _reduceLinksVariable["default"])(variables, {
49
+ name: name,
50
+ value: typeof value === 'string' ? value : '',
51
+ linksIterations: linksIterations,
52
+ symLinks: symLinks,
53
+ lengths: lengths
54
+ });
55
+ return _objectSpread(_objectSpread({}, state), {}, {
56
+ variables: variablesNext
57
+ });
58
+ } else if (loop && paginatedLoop && index && length) {
59
+ var _variablesNext = (0, _reduceVariablesArray["default"])(variables, {
60
+ name: name,
61
+ value: value,
62
+ index: index,
63
+ length: length
64
+ });
65
+ return _objectSpread(_objectSpread({}, state), {}, {
66
+ variables: _variablesNext
67
+ });
68
+ } else if (isOnSubPage(pager)) {
69
+ var _variablesNext2 = (0, _reduceVariablesArray["default"])(variables, {
70
+ name: name,
71
+ value: value,
72
+ index: pager.iteration,
73
+ length: pager.nbIterations
74
+ });
75
+ return _objectSpread(_objectSpread({}, state), {}, {
76
+ variables: _variablesNext2
77
+ });
78
+ } else {
79
+ var _toNumber;
80
+ var _variablesNext3 = (0, _reduceVariablesSimple["default"])(variables, {
81
+ name: name,
82
+ value: value
83
+ });
84
+ if (loop) return _objectSpread(_objectSpread({}, state), {}, {
85
+ variables: _variablesNext3,
86
+ pager: _objectSpread(_objectSpread({}, pager), {}, {
87
+ shallowIteration: (_toNumber = (0, _toNumber2.toNumber)(shallowIteration)) !== null && _toNumber !== void 0 ? _toNumber : undefined
88
+ })
89
+ });
90
+ return _objectSpread(_objectSpread({}, state), {}, {
91
+ variables: _variablesNext3
92
+ });
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Met à jour les bindings (maps des valeurs)
98
+ */
99
+ function updateBindings(state, action) {
100
+ var payload = action.payload;
101
+ var response = payload.response;
102
+ var name = response.name;
103
+ var ub = state.updateBindings;
104
+ var variables = state.variables;
105
+ var variable = variables[name];
106
+ var value = variable.value;
107
+ ub(name, value);
108
+ return state;
109
+ }
110
+ var reducers = (0, _compose["default"])(updateVariables, updateBindings, _reduceResizing["default"], _reduceMissing["default"], _reduceCleaning["default"]);
111
+ function reduceHandleChange(state, action) {
112
+ return reducers(state, action);
113
+ }
114
+ var _default = reduceHandleChange;
115
+ exports["default"] = _default;
@@ -0,0 +1,89 @@
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["default"] = void 0;
8
+ var _commons = require("../commons");
9
+ 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; }
10
+ 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; }
11
+ 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; }
12
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
13
+ 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); }
14
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
15
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
16
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
17
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
18
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
19
+ 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."); }
20
+ 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); }
21
+ 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; }
22
+ 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; } }
23
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
24
+ function reduceOne(variables, _ref) {
25
+ var name = _ref.name,
26
+ value = _ref.value,
27
+ linksIterations = _ref.linksIterations,
28
+ lengths = _ref.lengths;
29
+ if (name in variables && linksIterations && lengths) {
30
+ var variable = variables[name];
31
+ var v = variable.value;
32
+ var _linksIterations = _slicedToArray(linksIterations, 2),
33
+ x = _linksIterations[0],
34
+ y = _linksIterations[1];
35
+ var _lengths = _slicedToArray(lengths, 2),
36
+ lx = _lengths[0],
37
+ ly = _lengths[1];
38
+ if (Array.isArray(v)) {
39
+ var next = (0, _commons.resizeArrayVariable)(_toConsumableArray(v), lx, []);
40
+ next[x] = (0, _commons.resizeArrayVariable)(_toConsumableArray(next[x]), ly, null);
41
+ next[x][y] = value;
42
+ return _objectSpread(_objectSpread({}, variables), {}, _defineProperty({}, name, _objectSpread(_objectSpread({}, variable), {}, {
43
+ value: next
44
+ })));
45
+ }
46
+ }
47
+ return variables;
48
+ }
49
+
50
+ /**
51
+ * Update the link variable in pair wise situation
52
+ *
53
+ * If person1 is "parent" of person2 we have to update person2 as a "child" of person1
54
+ */
55
+ function reduceLinksVariable(variables, _ref2) {
56
+ var name = _ref2.name,
57
+ value = _ref2.value,
58
+ linksIterations = _ref2.linksIterations,
59
+ symLinks = _ref2.symLinks,
60
+ lengths = _ref2.lengths;
61
+ if (symLinks && name in symLinks && linksIterations) {
62
+ var symValue = symLinks[name][value];
63
+ var _linksIterations2 = _slicedToArray(linksIterations, 2),
64
+ x = _linksIterations2[0],
65
+ y = _linksIterations2[1];
66
+ var symIteration = [y, x];
67
+ if (symValue) {
68
+ return reduceOne(reduceOne(variables, {
69
+ name: name,
70
+ value: value,
71
+ linksIterations: linksIterations,
72
+ lengths: lengths
73
+ }), {
74
+ name: name,
75
+ value: symValue,
76
+ linksIterations: symIteration,
77
+ lengths: lengths
78
+ });
79
+ }
80
+ }
81
+ return reduceOne(variables, {
82
+ name: name,
83
+ value: value,
84
+ linksIterations: linksIterations,
85
+ lengths: lengths
86
+ });
87
+ }
88
+ var _default = reduceLinksVariable;
89
+ exports["default"] = _default;
@@ -0,0 +1,88 @@
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["default"] = void 0;
8
+ var _reduceCleaning = _interopRequireDefault(require("./reduce-cleaning"));
9
+ var _actions = require("../../actions");
10
+ var _excluded = ["value"];
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
+ 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; }
13
+ 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; }
14
+ 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; }
15
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
16
+ 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); }
17
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
18
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
19
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
20
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
21
+ 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); }
22
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
23
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
24
+ 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; }
25
+ /**
26
+ * Find the new value for a variable from the state
27
+ *
28
+ * If we are in a loop we only want to null the value corresponding to the iteration
29
+ */
30
+ function buildMissingValue(state, oldValue) {
31
+ var iteration = state.pager.iteration;
32
+ // The question is a root question
33
+ if (iteration === undefined) {
34
+ return null;
35
+ }
36
+
37
+ // We are in an iteration
38
+ // If the value is not an array, do nothing
39
+ if (!Array.isArray(oldValue)) {
40
+ return oldValue;
41
+ }
42
+ // Otherwise, null the value for the iteration
43
+ var newValue = _toConsumableArray(oldValue);
44
+ newValue[iteration] = null;
45
+ return newValue;
46
+ }
47
+
48
+ /**
49
+ * Update value for missing variables
50
+ */
51
+ function reduceMissing(state, action) {
52
+ var name = action.payload.response.name;
53
+ var missingBlock = state.missingBlock;
54
+ if (name in missingBlock) {
55
+ var variables = state.variables,
56
+ updateBindings = state.updateBindings;
57
+ var toClean = missingBlock[name];
58
+ var delta = toClean.reduce(function (acc, variableName) {
59
+ var _variables$variableNa = variables[variableName],
60
+ value = _variables$variableNa.value,
61
+ rest = _objectWithoutProperties(_variables$variableNa, _excluded);
62
+ updateBindings(variableName, null);
63
+ var newValue = buildMissingValue(state, value);
64
+ return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, variableName, _objectSpread(_objectSpread({}, rest), {}, {
65
+ value: newValue
66
+ })));
67
+ }, {});
68
+ var newStateAfterMissing = _objectSpread(_objectSpread({}, state), {}, {
69
+ variables: _objectSpread(_objectSpread({}, variables), delta)
70
+ });
71
+ // If missing clean variable which is also into cleaning case,
72
+ // we have to handle theses cleanings
73
+ // To check: do we have with this trick or triggering handle change action?
74
+ return toClean.reduce(function (acc, v) {
75
+ return (0, _reduceCleaning["default"])(acc, {
76
+ type: _actions.ActionKind.HANDLE_CHANGE,
77
+ payload: _objectSpread(_objectSpread({}, action.payload), {}, {
78
+ response: {
79
+ name: v
80
+ }
81
+ })
82
+ });
83
+ }, newStateAfterMissing);
84
+ }
85
+ return state;
86
+ }
87
+ var _default = reduceMissing;
88
+ exports["default"] = _default;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _commons = require("../../commons");
8
+ var _commons2 = require("../commons");
9
+ 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); }
10
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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 _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; } }
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 refillValue(size, precSize, value) {
22
+ return (0, _commons2.resizeArrayVariable)(value, size, null);
23
+ }
24
+ function reduceResizingVariables(_ref) {
25
+ var size = _ref.size,
26
+ variableArray = _ref.variableArray,
27
+ variables = _ref.variables,
28
+ executeExpression = _ref.executeExpression,
29
+ updateBindings = _ref.updateBindings;
30
+ if (size === undefined) {
31
+ return {};
32
+ }
33
+ var sizeValue = executeExpression((0, _commons.getCompatibleVTLExpression)(size));
34
+ return variableArray.reduce(function (acc, v) {
35
+ if (v in variables) {
36
+ var value = variables[v].value;
37
+ var precSize = Array.isArray(value) ? value.length : 0;
38
+ var newValue = refillValue(sizeValue, precSize, value);
39
+ updateBindings(v, newValue);
40
+ return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, v, _objectSpread(_objectSpread({}, variables[v]), {}, {
41
+ value: newValue
42
+ })));
43
+ }
44
+ return acc;
45
+ }, {});
46
+ }
47
+ function reduceResizingLinksVariables(_ref2) {
48
+ var sizeForLinksVariables = _ref2.sizeForLinksVariables,
49
+ linksVariables = _ref2.linksVariables,
50
+ variables = _ref2.variables,
51
+ executeExpression = _ref2.executeExpression,
52
+ updateBindings = _ref2.updateBindings;
53
+ if (Array.isArray(sizeForLinksVariables) && linksVariables) {
54
+ var _sizeForLinksVariable = sizeForLinksVariables.map(function (s) {
55
+ return executeExpression((0, _commons.getCompatibleVTLExpression)(s));
56
+ }),
57
+ _sizeForLinksVariable2 = _slicedToArray(_sizeForLinksVariable, 2),
58
+ xSize = _sizeForLinksVariable2[0],
59
+ ySize = _sizeForLinksVariable2[1];
60
+ return linksVariables.reduce(function (acc, v) {
61
+ var value = variables[v].value;
62
+ // The value is not an array, skip it
63
+ if (!Array.isArray(value)) {
64
+ return acc;
65
+ }
66
+ var newValue = (0, _commons2.resizeArrayVariable)(value.map(function (i) {
67
+ return (0, _commons2.resizeArrayVariable)(i, ySize, null);
68
+ }), xSize, new Array(ySize).fill(null));
69
+ updateBindings(v, newValue);
70
+ return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, v, _objectSpread(_objectSpread({}, variables[v]), {}, {
71
+ value: newValue
72
+ })));
73
+ }, {});
74
+ }
75
+ return {};
76
+ }
77
+ function reduceResizing(state, action) {
78
+ var _action$payload$args;
79
+ var name = action.payload.response.name;
80
+ var onChange = (_action$payload$args = action.payload.args) === null || _action$payload$args === void 0 ? void 0 : _action$payload$args.onChange;
81
+ var resizing = state.resizing,
82
+ variables = state.variables;
83
+ var updateBindings = function updateBindings(variableName, newValue) {
84
+ var _action$payload$args2, _action$payload$args3;
85
+ state.updateBindings(variableName, newValue);
86
+ (_action$payload$args2 = action.payload.args) === null || _action$payload$args2 === void 0 || (_action$payload$args3 = _action$payload$args2.onChange) === null || _action$payload$args3 === void 0 ? void 0 : _action$payload$args3.call(_action$payload$args2, {
87
+ name: variableName
88
+ }, newValue, action.payload.args);
89
+ };
90
+ if (name in resizing) {
91
+ var _resizing$name = resizing[name],
92
+ size = _resizing$name.size,
93
+ variableArray = _resizing$name.variables,
94
+ sizeForLinksVariables = _resizing$name.sizeForLinksVariables,
95
+ linksVariables = _resizing$name.linksVariables;
96
+ var executeExpression = state.executeExpression;
97
+ var newLinksVariables = reduceResizingLinksVariables({
98
+ sizeForLinksVariables: sizeForLinksVariables,
99
+ linksVariables: linksVariables,
100
+ variables: variables,
101
+ executeExpression: executeExpression,
102
+ updateBindings: updateBindings
103
+ });
104
+ var newVariables = reduceResizingVariables({
105
+ size: size,
106
+ variableArray: variableArray,
107
+ variables: variables,
108
+ executeExpression: executeExpression,
109
+ updateBindings: updateBindings,
110
+ onChange: onChange
111
+ });
112
+ return _objectSpread(_objectSpread({}, state), {}, {
113
+ variables: _objectSpread(_objectSpread(_objectSpread({}, variables), newLinksVariables), newVariables)
114
+ });
115
+ }
116
+ return state;
117
+ }
118
+ var _default = reduceResizing;
119
+ exports["default"] = _default;