@inseefr/lunatic 2.7.4 → 2.7.6

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 (102) hide show
  1. package/README.fr.md +1 -1
  2. package/README.md +6 -1
  3. package/lib/components/commons/components/md-label/link.js +39 -34
  4. package/lib/components/commons/components/md-label/md-label.js +2 -2
  5. package/lib/components/commons/components/md-label/md-label.spec.js +71 -0
  6. package/lib/components/commons/components/md-label/router-link.js +29 -0
  7. package/lib/components/commons/components/variable-status/variable-status.js +2 -2
  8. package/lib/components/index.scss +19 -1
  9. package/lib/components/loop/block-for-loop.js +2 -0
  10. package/lib/components/loop/constant.js +10 -0
  11. package/lib/components/loop/roster-for-loop/roster-for-loop.js +42 -20
  12. package/lib/components/lunatic-components.js +45 -7
  13. package/lib/components/table/lunatic-table.js +5 -1
  14. package/lib/hooks/use-auto-focus.js +1 -1
  15. package/lib/src/components/commons/components/md-label/router-link.d.ts +6 -0
  16. package/lib/src/components/datepicker/lunatic-datepicker.d.ts +1 -1
  17. package/lib/src/components/loop/constant.d.ts +4 -0
  18. package/lib/src/components/loop/roster-for-loop/roster-for-loop.d.ts +1 -0
  19. package/lib/src/components/lunatic-components.d.ts +12 -5
  20. package/lib/src/components/type.d.ts +4 -1
  21. package/lib/src/use-lunatic/commons/compile-controls.d.ts +4 -3
  22. package/lib/src/use-lunatic/commons/fill-components/fill-component-required.d.ts +75 -70
  23. package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +55 -50
  24. package/lib/src/use-lunatic/commons/fill-components/fill-iterations.d.ts +31 -26
  25. package/lib/src/use-lunatic/commons/fill-components/fill-specific-expression.d.ts +680 -73
  26. package/lib/src/use-lunatic/commons/use-components-from-state.d.ts +1 -1
  27. package/lib/src/use-lunatic/commons/variables/lunatic-variables-store.d.ts +1 -0
  28. package/lib/src/use-lunatic/hooks/use-page-has-response.d.ts +6 -0
  29. package/lib/src/use-lunatic/reducer/commons/is-loop-component.d.ts +2 -2
  30. package/lib/src/use-lunatic/reducer/controls/check-base-control.d.ts +2 -0
  31. package/lib/src/use-lunatic/reducer/{resolve-component-controls/resolve-roundabout-control.d.ts → controls/check-roundabout-control.d.ts} +2 -2
  32. package/lib/src/use-lunatic/type-source.d.ts +16 -10
  33. package/lib/src/use-lunatic/use-lunatic.d.ts +12 -5
  34. package/lib/src/utils/suggester-workers/searching/meloto-order.d.ts +2 -1
  35. package/lib/stories/behaviour/controls/controls.stories.js +14 -7
  36. package/lib/stories/behaviour/controls/loop.json +130 -0
  37. package/lib/stories/behaviour/controls/{V2_ControlesNonNum_horsBoucle_PasPageFin.json → simple.json} +2 -2
  38. package/lib/stories/date-picker/source.json +22 -67
  39. package/lib/stories/declaration/source.json +14 -28
  40. package/lib/stories/dropdown/source.json +11 -28
  41. package/lib/stories/filter-description/source.json +3 -2
  42. package/lib/stories/input/input.stories.js +1 -8
  43. package/lib/stories/input/source.json +1 -63
  44. package/lib/stories/input-number/input-number.stories.js +2 -22
  45. package/lib/stories/input-number/source.json +4 -6
  46. package/lib/stories/loop/{block-for-loop.stories.js → loop.stories.js} +10 -8
  47. package/lib/stories/loop/roster-for-loop.stories.js +8 -2
  48. package/lib/stories/loop/source-bloc.json +10 -39
  49. package/lib/stories/loop/source-paginated.json +65 -78
  50. package/lib/stories/{loop/paginated-loop.stories.js → markdown/markdown.stories.js} +4 -4
  51. package/lib/stories/markdown/source.json +40 -0
  52. package/lib/stories/overview/overview.stories.js +1 -1
  53. package/lib/stories/pairwise/pairwise-links.stories.js +4 -4
  54. package/lib/stories/pairwise/{links.json → source.json} +2 -6
  55. package/lib/stories/question-context/question-context.stories.js +31 -0
  56. package/lib/stories/question-context/source.json +13 -0
  57. package/lib/stories/question-explication/source.json +1 -1
  58. package/lib/stories/{loop/not-paginated-loop.stories.js → question-information/question-information.stories.js} +5 -8
  59. package/lib/stories/question-information/source.json +14 -0
  60. package/lib/stories/roundabout/source.json +21 -31
  61. package/lib/stories/sequence/sequence.stories.js +7 -1
  62. package/lib/stories/sequence/source.json +17 -0
  63. package/lib/stories/suggester/simple.json +1 -1
  64. package/lib/stories/suggester/suggester-workers.stories.js +36 -1
  65. package/lib/stories/table/source-colspan.json +314 -0
  66. package/lib/stories/table/table.stories.js +7 -1
  67. package/lib/stories/textarea/source.json +6 -22
  68. package/lib/stories/utils/orchestrator.js +89 -49
  69. package/lib/stories/utils/orchestrator.scss +49 -0
  70. package/lib/stories/utils/referentiel.js +8 -4
  71. package/lib/use-lunatic/commons/compile-controls.js +135 -34
  72. package/lib/use-lunatic/commons/fill-components/fill-component-value.js +10 -0
  73. package/lib/use-lunatic/commons/fill-components/fill-specific-expression.js +4 -1
  74. package/lib/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +14 -9
  75. package/lib/use-lunatic/commons/variables/get-questionnaire-data.js +6 -1
  76. package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +25 -7
  77. package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +39 -0
  78. package/lib/use-lunatic/hooks/use-page-has-response.js +104 -0
  79. package/lib/use-lunatic/reducer/{resolve-component-controls/resolve-simple-control.js → controls/check-base-control.js} +5 -7
  80. package/lib/use-lunatic/reducer/{resolve-component-controls/resolve-roundabout-control.js → controls/check-roundabout-control.js} +2 -3
  81. package/lib/use-lunatic/reducer/overview/overview-on-init.js +6 -4
  82. package/lib/use-lunatic/type-source.js +1 -0
  83. package/lib/use-lunatic/use-lunatic.js +3 -1
  84. package/lib/utils/env.js +1 -1
  85. package/lib/utils/suggester-workers/searching/meloto-order.js +6 -5
  86. package/package.json +2 -2
  87. package/workers-release/lunatic-search-worker-0.3.0.js +1 -1
  88. package/lib/src/use-lunatic/commons/get-errors-without-empty-value.d.ts +0 -6
  89. package/lib/src/use-lunatic/reducer/resolve-component-controls/index.d.ts +0 -1
  90. package/lib/src/use-lunatic/reducer/resolve-component-controls/resolve-component-control.d.ts +0 -6
  91. package/lib/src/use-lunatic/reducer/resolve-component-controls/resolve-simple-control.d.ts +0 -3
  92. package/lib/stories/Introduction.stories.mdx +0 -112
  93. package/lib/stories/behaviour/controls/V2_Controles_BouclesLiees_PasPageFin.json +0 -533
  94. package/lib/stories/input/source-with-question.json +0 -80
  95. package/lib/stories/input-number/source-euros.json +0 -37
  96. package/lib/stories/input-number/source-thansand.json +0 -34
  97. package/lib/stories/loop/source-not-paginated.json +0 -138
  98. package/lib/use-lunatic/commons/get-errors-without-empty-value.js +0 -24
  99. package/lib/use-lunatic/reducer/resolve-component-controls/index.js +0 -12
  100. package/lib/use-lunatic/reducer/resolve-component-controls/resolve-component-control.js +0 -38
  101. /package/lib/stories/behaviour/controls/{V2_ControlesNum_horsBoucle_PasPageFin.json → simple-numeric.json} +0 -0
  102. /package/lib/stories/pairwise/{links-componentset.json → source-componentset.json} +0 -0
@@ -3,12 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = exports.RosterMui = exports.Roster = exports.DynamicTable = exports.Default = void 0;
6
+ exports["default"] = exports.RosterMui = exports.Roster = exports.DynamicTable = exports.Default = exports.Colspan = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _orchestrator = _interopRequireDefault(require("../utils/orchestrator"));
9
9
  var _source = _interopRequireDefault(require("./source.json"));
10
10
  var _data = _interopRequireDefault(require("./data.json"));
11
11
  var _sourceRoster = _interopRequireDefault(require("./source-roster.json"));
12
+ var _sourceColspan = _interopRequireDefault(require("./source-colspan.json"));
12
13
  var _tableDynamique = _interopRequireDefault(require("./table-dynamique.json"));
13
14
  var _dataRoster = _interopRequireDefault(require("./data-roster.json"));
14
15
  var _defaultArgTypes = _interopRequireDefault(require("../utils/default-arg-types"));
@@ -44,6 +45,11 @@ Roster.args = {
44
45
  source: _sourceRoster["default"],
45
46
  data: _dataRoster["default"]
46
47
  };
48
+ var Colspan = exports.Colspan = Template.bind({});
49
+ Colspan.args = {
50
+ id: 'table',
51
+ source: _sourceColspan["default"]
52
+ };
47
53
  var RosterMui = exports.RosterMui = Template.bind({});
48
54
  RosterMui.args = {
49
55
  id: 'table',
@@ -4,34 +4,18 @@
4
4
  "id": "name",
5
5
  "componentType": "Textarea",
6
6
  "label": {
7
- "value": "\"What you say\"",
7
+ "value": "\"Label\"",
8
+ "type": "VTL|MD"
9
+ },
10
+ "description": {
11
+ "value": "\"Description\"",
8
12
  "type": "VTL|MD"
9
13
  },
10
14
  "conditionFilter": { "value": "true", "type": "VTL" },
11
15
  "maxLength": 30,
12
16
  "response": {
13
17
  "name": "SOMETHING"
14
- },
15
- "declarations": [
16
- {
17
- "id": "kb9hi4j0-krnoclfe",
18
- "declarationType": "INSTRUCTION",
19
- "position": "BEFORE_QUESTION_TEXT",
20
- "label": {
21
- "value": "\"## Can you say something, please?\nwhat you want't.\n\"",
22
- "type": "VTL|MD"
23
- }
24
- },
25
- {
26
- "id": "kb9hi4j0-krnoclfe",
27
- "declarationType": "HELP",
28
- "position": "AFTER_QUESTION_TEXT",
29
- "label": {
30
- "value": "\"For example,hello World!\"",
31
- "type": "VTL|MD"
32
- }
33
- }
34
- ]
18
+ }
35
19
  }
36
20
  ],
37
21
  "variables": [
@@ -47,38 +47,29 @@ function DevOptions(_ref) {
47
47
  }
48
48
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
49
49
  className: "dev-options",
50
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
51
- className: "title",
52
- children: "Options d\xE9veloppeur"
53
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
54
- className: "conteneur",
50
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
51
+ style: {
52
+ display: 'flex'
53
+ },
55
54
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Button, {
56
55
  onClick: function onClick() {
57
56
  return _logger.Logger.log(getData(true));
58
57
  },
59
- children: "Get State"
58
+ children: "Get Data"
60
59
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Button, {
61
60
  onClick: function onClick() {
62
61
  return goToPage({
63
62
  page: "".concat(toPage)
64
63
  });
65
64
  },
66
- children: "Go to page ".concat(toPage)
67
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Button, {
68
- onClick: function onClick() {
69
- return goToPage({
70
- page: "".concat(lastReachedPage)
71
- });
72
- },
73
- children: "Go to lastReachedPage : ".concat(lastReachedPage)
74
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Input, {
75
- id: "page-to-jump",
76
- value: toPage,
77
- handleChange: handleChange,
78
- min: 1,
79
- label: 'Page',
80
- description: 'the page where you want to jump'
65
+ children: "Go to \"".concat(toPage, "\"")
81
66
  })]
67
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Input, {
68
+ id: "page-to-jump",
69
+ value: toPage,
70
+ handleChange: handleChange,
71
+ min: 1,
72
+ label: 'Page to reach : '
82
73
  })]
83
74
  });
84
75
  }
@@ -91,7 +82,8 @@ function Pager(_ref2) {
91
82
  isFirst = _ref2.isFirst,
92
83
  pageTag = _ref2.pageTag,
93
84
  maxPage = _ref2.maxPage,
94
- getData = _ref2.getData;
85
+ getData = _ref2.getData,
86
+ pager = _ref2.pager;
95
87
  if (maxPage && maxPage > 1) {
96
88
  var Button = lunatic.Button;
97
89
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
@@ -105,13 +97,35 @@ function Pager(_ref2) {
105
97
  onClick: goNext,
106
98
  disabled: isLast,
107
99
  children: "Next"
100
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
101
+ style: {
102
+ fontSize: '.8em',
103
+ opacity: 0.7,
104
+ marginTop: '.3em'
105
+ },
106
+ children: "You can use PgDown / PgUp shortcut"
108
107
  })]
109
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
110
- children: ["PAGE: ", pageTag]
111
108
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(DevOptions, {
112
109
  goToPage: goToPage,
113
110
  getData: getData,
114
111
  lastReachedPage: lastReachedPage
112
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
113
+ className: "story-pager",
114
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
115
+ children: "Pager"
116
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("ul", {
117
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
118
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
119
+ children: "PageTag:"
120
+ }), " ", JSON.stringify(pageTag)]
121
+ }), Object.keys(pager).map(function (key) {
122
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
123
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("strong", {
124
+ children: [key, ":"]
125
+ }), " ", JSON.stringify(pager[key])]
126
+ }, key);
127
+ })]
128
+ })]
115
129
  })]
116
130
  });
117
131
  }
@@ -220,9 +234,32 @@ function OrchestratorForStories(_ref3) {
220
234
  });
221
235
  } else goNextPage();
222
236
  }, [compileControls, errorActive, goNextPage, pageTag]);
237
+
238
+ // Allow PageDown / PageUp shortcut to ease navigation
239
+ (0, _react.useEffect)(function () {
240
+ var listener = function listener(e) {
241
+ var stopPropagation = false;
242
+ if (e.key === 'PageDown') {
243
+ handleGoNext();
244
+ stopPropagation = true;
245
+ }
246
+ if (e.key === 'PageUp') {
247
+ goPreviousPage();
248
+ stopPropagation = true;
249
+ }
250
+ if (stopPropagation) {
251
+ e.preventDefault();
252
+ e.stopPropagation();
253
+ }
254
+ };
255
+ document.addEventListener('keydown', listener);
256
+ return function () {
257
+ document.removeEventListener('keydown', listener);
258
+ };
259
+ }, [handleGoNext, goPreviousPage]);
223
260
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Provider, {
224
261
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
225
- className: "container",
262
+ className: "container story-with-sidebar",
226
263
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
227
264
  className: "components",
228
265
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_2.LunaticComponents, {
@@ -237,30 +274,33 @@ function OrchestratorForStories(_ref3) {
237
274
  }, storeName ? getStoreInfo(storeName) : {});
238
275
  }
239
276
  })
240
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Pager, {
241
- goPrevious: goPreviousPage,
242
- goNext: handleGoNext,
243
- goToPage: goToPage,
244
- lastReachedPage: lastReachedPage,
245
- isLast: isLastPage,
246
- isFirst: isFirstPage,
247
- pageTag: pageTag,
248
- maxPage: maxPage,
249
- getData: getData
250
- }), showOverview && /*#__PURE__*/(0, _jsxRuntime.jsx)(_overview.Overview, {
251
- overview: overview,
252
- goToPage: goToPage
253
- }), errorsForModal && /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Modal, {
254
- errors: errorsForModal.currentErrors,
255
- goNext: skip,
256
- onClose: closeModal,
257
- isCritical: errorsForModal.isCritical
258
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_waiting["default"], {
259
- status: waiting,
260
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
261
- className: "waiting-orchestrator",
262
- children: "Initialisation des donn\xE9es de suggestion..."
263
- })
277
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("aside", {
278
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Pager, {
279
+ goPrevious: goPreviousPage,
280
+ goNext: handleGoNext,
281
+ goToPage: goToPage,
282
+ lastReachedPage: lastReachedPage,
283
+ isLast: isLastPage,
284
+ isFirst: isFirstPage,
285
+ pageTag: pageTag,
286
+ maxPage: maxPage,
287
+ getData: getData,
288
+ pager: pager
289
+ }), showOverview && /*#__PURE__*/(0, _jsxRuntime.jsx)(_overview.Overview, {
290
+ overview: overview,
291
+ goToPage: goToPage
292
+ }), errorsForModal && /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Modal, {
293
+ errors: errorsForModal.currentErrors,
294
+ goNext: skip,
295
+ onClose: closeModal,
296
+ isCritical: errorsForModal.isCritical
297
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_waiting["default"], {
298
+ status: waiting,
299
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
300
+ className: "waiting-orchestrator",
301
+ children: "Initialisation des donn\xE9es de suggestion..."
302
+ })
303
+ })]
264
304
  })]
265
305
  })
266
306
  });
@@ -2,4 +2,53 @@
2
2
  background-color: antiquewhite;
3
3
  padding: 5px 5px;
4
4
  border: solid burlywood 2px;
5
+ display: grid;
6
+ grid-template-columns: 1fr;
7
+ gap: 1rem;
8
+ }
9
+
10
+ .story-with-sidebar {
11
+ font-family: sans-serif;
12
+ display: grid;
13
+ height: 100%;
14
+ grid-template-columns: 1fr 300px;
15
+ align-items: flex-start;
16
+ }
17
+
18
+ .story-with-sidebar aside label {
19
+ display: block;
20
+ font-weight: bold;
21
+ margin-bottom: .3em;
22
+ }
23
+
24
+ .story-with-sidebar aside {
25
+ display: grid;
26
+ grid-template-columns: 1fr;
27
+ gap: 1rem;
28
+ padding: 1rem;
29
+ box-shadow: 0 4px 3px rgba(0, 0, 0, 0.07), 0px 2px 2px rgba(0, 0, 0, 0.06);
30
+ background-color: #f1f5f9;
31
+
32
+ .pagination {
33
+ margin-top: 0;
34
+ }
35
+ }
36
+
37
+ .story-pager h3 {
38
+ font-size: 1rem;
39
+ padding-bottom: .3rem;
40
+ margin-bottom: .5rem;
41
+ border-bottom: solid 1px rgba(0, 0, 0, 0.3);
42
+ }
43
+
44
+ .story-pager ul {
45
+ margin: 0;
46
+ padding: 0 0 0 20px;
47
+ line-height: 1.4;
48
+ font-size: 0.9rem;
49
+ color: rgba(0, 0, 0, 0.75)
50
+ }
51
+
52
+ .story-pager ul strong {
53
+ color: #000;
5
54
  }
@@ -14,19 +14,23 @@ var getReferentiel = exports.getReferentiel = /*#__PURE__*/function () {
14
14
  while (1) switch (_context.prev = _context.next) {
15
15
  case 0:
16
16
  _context.t0 = name;
17
- _context.next = _context.t0 === 'naf-rev2-stop' ? 3 : _context.t0 === 'naf-rev2' ? 3 : _context.t0 === 'cog-communes' ? 4 : 5;
17
+ _context.next = _context.t0 === 'libelle-pcs2020' ? 3 : _context.t0 === 'naf-rev2-stop' ? 4 : _context.t0 === 'naf-rev2' ? 4 : _context.t0 === 'cog-communes' ? 5 : 6;
18
18
  break;
19
19
  case 3:
20
- return _context.abrupt("return", fetch('https://inseefr.github.io/Lunatic/storybook/naf-rev2.json').then(function (r) {
20
+ return _context.abrupt("return", fetch('/libelles-pcs-2020.json').then(function (r) {
21
21
  return r.json();
22
22
  }));
23
23
  case 4:
24
- return _context.abrupt("return", fetch('https://inseefr.github.io/Lunatic/storybook/communes-2019.json').then(function (r) {
24
+ return _context.abrupt("return", fetch('https://inseefr.github.io/Lunatic/storybook/naf-rev2.json').then(function (r) {
25
25
  return r.json();
26
26
  }));
27
27
  case 5:
28
- throw new Error("Unkonw r\xE9f\xE9rentiel ".concat(name));
28
+ return _context.abrupt("return", fetch('https://inseefr.github.io/Lunatic/storybook/communes-2019.json').then(function (r) {
29
+ return r.json();
30
+ }));
29
31
  case 6:
32
+ throw new Error("Unkonw r\xE9f\xE9rentiel ".concat(name));
33
+ case 7:
30
34
  case "end":
31
35
  return _context.stop();
32
36
  }
@@ -1,71 +1,172 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.compileControls = compileControls;
7
8
  var _commons = require("../reducer/commons");
8
- var _resolveComponentControls = require("../reducer/resolve-component-controls");
9
9
  var _replaceComponentSequence = require("../replace-component-sequence");
10
10
  var _typeSource = require("../type-source");
11
11
  var _fillComponentExpressions = _interopRequireDefault(require("./fill-components/fill-component-expressions"));
12
12
  var _getComponentsFromState = _interopRequireDefault(require("./get-components-from-state"));
13
- var _getErrorsWithoutEmptyValue = _interopRequireDefault(require("./get-errors-without-empty-value"));
13
+ var _checkRoundaboutControl = require("../reducer/controls/check-roundabout-control");
14
+ var _checkBaseControl = require("../reducer/controls/check-base-control");
14
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
16
16
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
17
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
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
19
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
20
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 _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
22
+ 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); }
23
+ 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; }
21
24
  /**
22
- * Check if components of current page have errors
25
+ * Check if components of the current page have errors, and return a map of error (indexed by component ID)
23
26
  */
24
- function validateComponents(state, components) {
25
- var pager = state.pager;
26
- return components.reduce(function (errors, component) {
27
- var controls = component.controls,
28
- id = component.id;
29
- if (Array.isArray(controls)) {
30
- var componentErrors = (0, _resolveComponentControls.resolveComponentControls)(state, controls);
31
- var shallowIteration = pager.shallowIteration;
32
- var idC = shallowIteration !== undefined ? "".concat(id, "-").concat(shallowIteration) : id;
33
- return (0, _getErrorsWithoutEmptyValue["default"])(_objectSpread(_objectSpread({}, errors), {}, _defineProperty({}, idC, componentErrors)));
27
+ function checkComponents(state, components) {
28
+ var errors = {};
29
+ var _iterator = _createForOfIteratorHelper(components),
30
+ _step;
31
+ try {
32
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
33
+ var component = _step.value;
34
+ var controls = component.controls,
35
+ id = component.id;
36
+ // The component has global level controls
37
+ if (Array.isArray(controls)) {
38
+ var componentErrors = checkControls(controls.filter(function (c) {
39
+ return c.type !== _typeSource.ControlTypeEnum.row;
40
+ }), state.executeExpression, state.pager);
41
+ if (componentErrors.length > 0) {
42
+ errors[id] = componentErrors;
43
+ }
44
+ }
45
+
46
+ // For loop, inspect children
47
+ if ((0, _commons.isLoopComponent)(component)) {
48
+ var _component$controls;
49
+ var rowControls = (_component$controls = component.controls) === null || _component$controls === void 0 ? void 0 : _component$controls.filter(function (c) {
50
+ return c.type === _typeSource.ControlTypeEnum.row;
51
+ });
52
+ if (rowControls !== null && rowControls !== void 0 && rowControls.length) {
53
+ errors = checkComponentInLoop(state, _objectSpread(_objectSpread({}, component), {}, {
54
+ controls: rowControls
55
+ }), errors);
56
+ }
57
+ var _iterator2 = _createForOfIteratorHelper(component.components),
58
+ _step2;
59
+ try {
60
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
61
+ var child = _step2.value;
62
+ errors = checkComponentInLoop(state, child, errors);
63
+ }
64
+ } catch (err) {
65
+ _iterator2.e(err);
66
+ } finally {
67
+ _iterator2.f();
68
+ }
69
+ }
70
+ }
71
+ } catch (err) {
72
+ _iterator.e(err);
73
+ } finally {
74
+ _iterator.f();
75
+ }
76
+ return errors;
77
+ }
78
+ function checkControls(controls, executeExpression, pager) {
79
+ return controls.map(function (control) {
80
+ switch (control.type) {
81
+ case _typeSource.ControlTypeEnum.roundabout:
82
+ return (0, _checkRoundaboutControl.checkRoundaboutControl)(control, executeExpression);
83
+ default:
84
+ return (0, _checkBaseControl.checkBaseControl)(control, executeExpression, pager);
34
85
  }
86
+ }).filter(function (error) {
87
+ return error !== undefined;
88
+ });
89
+ }
35
90
 
36
- //Thanks to init which split basic Loops, we only go into unPaginatedLoops
37
- if ((0, _commons.isLoopComponent)(component)) {
38
- var _components = component.components;
39
- var recurs = validateComponents(state, _components);
40
- return (0, _getErrorsWithoutEmptyValue["default"])(_objectSpread(_objectSpread({}, errors), recurs));
91
+ /**
92
+ * Figure out the number of iterations of a component
93
+ */
94
+ function computeIterations(component, executeExpression) {
95
+ if ('iterations' in component) {
96
+ return executeExpression(component.iterations.value);
97
+ }
98
+ if ('response' in component) {
99
+ var value = executeExpression(component.response.name);
100
+ if (Array.isArray(value)) {
101
+ return value.length;
41
102
  }
42
- // Keep previous errors to allow multiple controls in same page (multiple question/component in the same page)
103
+ }
104
+ // Look at the first component
105
+ if ('components' in component) {
106
+ return computeIterations(component.components[0], executeExpression);
107
+ }
108
+ return 0;
109
+ }
110
+
111
+ /**
112
+ * Check controls on a component for each iteration
113
+ * Errors are returned using a map of id suffixed with the iteration index (ex: {prenom-1: [], prenom-3: []})
114
+ */
115
+ function checkComponentInLoop(state, component, errors) {
116
+ // The component has no controls, skip it
117
+ if (!Array.isArray(component.controls)) {
43
118
  return errors;
44
- }, {});
119
+ }
120
+
121
+ // Execute control for each iteration
122
+ var iterations = computeIterations(component, state.executeExpression);
123
+ for (var i = 0; i < iterations; i++) {
124
+ // Create a pager representing the iteration we want to check
125
+ var iterationPager = _objectSpread(_objectSpread({}, state.pager), {}, {
126
+ iteration: i,
127
+ nbIterations: iterations
128
+ });
129
+ // The component is filtered on this iteration, skip it
130
+ if (component.conditionFilter && !state.executeExpression(component.conditionFilter.value, iterationPager)) {
131
+ continue;
132
+ }
133
+ var componentErrors = checkControls(component.controls, state.executeExpression, iterationPager);
134
+ if (componentErrors.length > 0) {
135
+ errors["".concat(component.id, "-").concat(i)] = componentErrors;
136
+ }
137
+ }
138
+ return errors;
45
139
  }
46
- function isCriticalErrors(errors) {
47
- if (errors) {
48
- return Object.values(errors).flat().reduce(function (status, _ref) {
49
- var criticality = _ref.criticality,
50
- typeOfControl = _ref.typeOfControl;
51
- return status || typeOfControl === _typeSource.TypeOfControl.FORMAT || criticality.startsWith(_typeSource.Criticality.ERROR);
52
- }, false);
140
+
141
+ /**
142
+ * Check if there is a critical error (type: "Error" and criticality: "Format")
143
+ */
144
+ function hasCriticalError(errors) {
145
+ if (!errors) {
146
+ return false;
53
147
  }
54
- return false;
148
+ // Look for at least one critical error in the list
149
+ var criticalError = Object.values(errors).flat().find(function (error) {
150
+ return error.criticality.startsWith(_typeSource.Criticality.ERROR) || error.typeOfControl === _typeSource.TypeOfControl.FORMAT;
151
+ });
152
+ return criticalError !== undefined;
55
153
  }
154
+
155
+ /**
156
+ * Check controls for currently visible components and output errors
157
+ */
56
158
  function compileControls(state) {
57
159
  var components = (0, _replaceComponentSequence.replaceComponentSequence)((0, _getComponentsFromState["default"])(state));
58
160
  var componentFiltered = components.map(function (component) {
59
161
  return (0, _fillComponentExpressions["default"])(component, state);
60
- }).filter(function (_ref2) {
61
- var conditionFilter = _ref2.conditionFilter;
162
+ }).filter(function (_ref) {
163
+ var conditionFilter = _ref.conditionFilter;
62
164
  return conditionFilter !== null && conditionFilter !== void 0 ? conditionFilter : true;
63
165
  });
64
- var errors = validateComponents(state, componentFiltered);
166
+ var errors = checkComponents(state, componentFiltered);
65
167
  var currentErrors = Object.keys(errors).length > 0 ? errors : undefined;
66
- var isCritical = isCriticalErrors(currentErrors);
67
168
  return {
68
169
  currentErrors: currentErrors,
69
- isCritical: isCritical
170
+ isCritical: hasCriticalError(currentErrors)
70
171
  };
71
172
  }
@@ -32,5 +32,15 @@ function getValueForComponent(component, state) {
32
32
  if ((0, _component.hasResponse)(component)) {
33
33
  return state.variables.get(component.response.name, iteration);
34
34
  }
35
+ // For loop, value will be a map of child component values
36
+ if ('components' in component) {
37
+ return Object.fromEntries(component.components.map(function (c) {
38
+ return 'response' in c ? c.response.name : null;
39
+ }).filter(function (name) {
40
+ return name !== null;
41
+ }).map(function (name) {
42
+ return [name, state.variables.get(name)];
43
+ }));
44
+ }
35
45
  return null;
36
46
  }
@@ -114,7 +114,10 @@ function fillTable(component, state) {
114
114
  if ((0, _component.hasComponentType)(component)) {
115
115
  return (0, _fillComponents.fillComponent)(component, state);
116
116
  }
117
- return state.executeExpression((0, _vtl.getVTLCompatibleValue)(component.label));
117
+ // We can have a non typed component with extra attributes (colspan, rowspan)
118
+ return _objectSpread(_objectSpread({}, component), {}, {
119
+ label: state.executeExpression((0, _vtl.getVTLCompatibleValue)(component.label))
120
+ });
118
121
  });
119
122
  })
120
123
  });
@@ -24,16 +24,21 @@ function cleaningBehaviour(store, cleaning) {
24
24
  return;
25
25
  }
26
26
  for (var variableName in cleaningInfo) {
27
- var _initialValues$variab;
28
- var skipCleaning = store.run(cleaningInfo[variableName], {
29
- iteration: e.detail.iteration
30
- });
31
- if (skipCleaning) {
32
- continue;
27
+ try {
28
+ var _initialValues$variab;
29
+ var skipCleaning = store.run(cleaningInfo[variableName], {
30
+ iteration: e.detail.iteration
31
+ });
32
+ if (skipCleaning) {
33
+ continue;
34
+ }
35
+ store.set(variableName, (_initialValues$variab = initialValues[variableName]) !== null && _initialValues$variab !== void 0 ? _initialValues$variab : null, {
36
+ iteration: e.detail.iteration
37
+ });
38
+ } catch (e) {
39
+ // If we have an error, skip this cleaning
40
+ console.error(e);
33
41
  }
34
- store.set(variableName, (_initialValues$variab = initialValues[variableName]) !== null && _initialValues$variab !== void 0 ? _initialValues$variab : null, {
35
- iteration: e.detail.iteration
36
- });
37
42
  }
38
43
  });
39
44
  }
@@ -53,7 +53,12 @@ function getQuestionnaireData(store, variables) {
53
53
  COLLECTED: store.get(variable.name)
54
54
  });
55
55
  } else {
56
- result[variable.variableType][variable.name] = store.get(variable.name);
56
+ try {
57
+ result[variable.variableType][variable.name] = store.get(variable.name);
58
+ } catch (e) {
59
+ // Error can happen when calculating variable, send null to prevent crashing the mehod
60
+ result[variable.variableType][variable.name] = null;
61
+ }
57
62
  }
58
63
  }
59
64
  } catch (err) {