@inseefr/lunatic 2.6.2 → 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
@@ -96,7 +96,7 @@ Object.defineProperty(exports, "Modal", {
96
96
  Object.defineProperty(exports, "PairwiseLinks", {
97
97
  enumerable: true,
98
98
  get: function get() {
99
- return _pairwiseLinks["default"];
99
+ return _pairwiseLinks.PairwiseLinks;
100
100
  }
101
101
  });
102
102
  Object.defineProperty(exports, "QuestionContext", {
@@ -174,7 +174,7 @@ Object.defineProperty(exports, "Switch", {
174
174
  Object.defineProperty(exports, "Table", {
175
175
  enumerable: true,
176
176
  get: function get() {
177
- return _table["default"];
177
+ return _lunaticTable.LunaticTable;
178
178
  }
179
179
  });
180
180
  Object.defineProperty(exports, "Textarea", {
@@ -195,7 +195,7 @@ var _inputNumber = _interopRequireDefault(require("./input-number"));
195
195
  var _filterDescription = _interopRequireDefault(require("./filter-description"));
196
196
  var _loop = require("./loop/loop");
197
197
  var _modalControls = _interopRequireDefault(require("./modal-controls"));
198
- var _pairwiseLinks = _interopRequireDefault(require("./pairwise-links"));
198
+ var _pairwiseLinks = require("./pairwise-links/pairwise-links");
199
199
  var _radio = _interopRequireDefault(require("./radio"));
200
200
  var _rosterForLoop = require("./loop/roster-for-loop/roster-for-loop");
201
201
  var _sequence = _interopRequireDefault(require("./sequence"));
@@ -205,7 +205,7 @@ var _switch = _interopRequireDefault(require("./switch"));
205
205
  var _textarea = _interopRequireDefault(require("./textarea"));
206
206
  var _suggesterLoaderWidget = _interopRequireDefault(require("./suggester-loader-widget"));
207
207
  var _roundabout = _interopRequireDefault(require("./roundabout"));
208
- var _table = _interopRequireDefault(require("./table"));
208
+ var _lunaticTable = require("./table/lunatic-table");
209
209
  var _lunaticComponentSet = require("./component-set/lunatic-component-set");
210
210
  var _duration = _interopRequireDefault(require("./duration"));
211
211
  var _summary = require("./summary");
@@ -9,7 +9,6 @@ var _react = require("react");
9
9
  var _i18n = _interopRequireDefault(require("../../i18n"));
10
10
  var _commons = require("../commons");
11
11
  var _declarations = require("../declarations");
12
- var _getInitialNbRows = require("./utils/get-initial-nb-rows");
13
12
  var _loopButton = require("./loop-button");
14
13
  var _lunaticComponents = require("../lunatic-components");
15
14
  var _array = require("../../utils/array");
@@ -29,6 +28,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /**
29
28
  * Loop without specific markup
30
29
  */
31
30
  var BlockForLoop = (0, _commons.createCustomizableLunaticField)(function (props) {
31
+ var _lines$min, _lines$max;
32
32
  var declarations = props.declarations,
33
33
  id = props.id,
34
34
  label = props.label,
@@ -37,15 +37,11 @@ var BlockForLoop = (0, _commons.createCustomizableLunaticField)(function (props)
37
37
  value = props.value,
38
38
  iterations = props.iterations,
39
39
  getComponents = props.getComponents;
40
- var min = lines === null || lines === void 0 ? void 0 : lines.min;
41
- var max = lines === null || lines === void 0 ? void 0 : lines.max;
40
+ var min = (_lines$min = lines === null || lines === void 0 ? void 0 : lines.min) !== null && _lines$min !== void 0 ? _lines$min : 0;
41
+ var max = (_lines$max = lines === null || lines === void 0 ? void 0 : lines.max) !== null && _lines$max !== void 0 ? _lines$max : Infinity;
42
+ var canControlRows = min !== max;
42
43
  var _useState = (0, _react.useState)(function () {
43
- if (iterations) {
44
- //This should be an Integer
45
- return Number.parseInt(iterations.toString());
46
- }
47
- var initLength = (0, _getInitialNbRows.getInitialNbRows)(value);
48
- return Math.max(initLength, min);
44
+ return Math.max(iterations, min);
49
45
  }),
50
46
  _useState2 = _slicedToArray(_useState, 2),
51
47
  nbRows = _useState2[0],
@@ -94,7 +90,7 @@ var BlockForLoop = (0, _commons.createCustomizableLunaticField)(function (props)
94
90
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsDetachable, {
95
91
  declarations: declarations,
96
92
  id: id
97
- }), Number.isInteger(min) && Number.isInteger(max) && min !== max && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
93
+ }), canControlRows && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
98
94
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_loopButton.LoopButton, {
99
95
  onClick: addRow,
100
96
  disabled: nbRows === max,
@@ -10,9 +10,8 @@ var _declarations = require("../../declarations");
10
10
  var _commons = require("../../commons");
11
11
  var _loopButton = require("../loop-button");
12
12
  var _i18n = _interopRequireDefault(require("../../../i18n"));
13
- var _getInitialNbRows = require("../utils/get-initial-nb-rows");
14
13
  var _htmlTable = require("../../commons/components/html-table");
15
- var _header = _interopRequireDefault(require("../../table/header"));
14
+ var _tableHeader = require("../../table/table-header");
16
15
  var _array = require("../../../utils/array");
17
16
  var _lunaticComponents = require("../../lunatic-components");
18
17
  var _jsxRuntime = require("react/jsx-runtime");
@@ -41,12 +40,12 @@ var RosterForLoop = (0, _commons.createCustomizableLunaticField)(function (props
41
40
  declarations = props.declarations,
42
41
  label = props.label,
43
42
  headers = props.headers,
44
- id = props.id;
43
+ iterations = props.iterations,
44
+ id = props.id,
45
+ getComponents = props.getComponents;
45
46
  var min = (lines === null || lines === void 0 ? void 0 : lines.min) || DEFAULT_MIN_ROWS;
46
47
  var max = (lines === null || lines === void 0 ? void 0 : lines.max) || DEFAULT_MAX_ROWS;
47
- var _useState = (0, _react.useState)(function () {
48
- return (0, _getInitialNbRows.getInitialNbRows)(valueMap);
49
- }),
48
+ var _useState = (0, _react.useState)(iterations),
50
49
  _useState2 = _slicedToArray(_useState, 2),
51
50
  nbRows = _useState2[0],
52
51
  setNbRows = _useState2[1];
@@ -86,16 +85,32 @@ var RosterForLoop = (0, _commons.createCustomizableLunaticField)(function (props
86
85
  id: id
87
86
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_htmlTable.Table, {
88
87
  id: id,
89
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_header["default"], {
88
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_tableHeader.TableHeader, {
90
89
  header: headers,
91
90
  id: id
92
91
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Tbody, {
93
92
  id: id,
94
93
  children: (0, _array.times)(nbRows, function (n) {
95
- return /*#__PURE__*/(0, _react.createElement)(Row, _objectSpread(_objectSpread({}, props), {}, {
96
- key: n,
97
- row: n
98
- }));
94
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Tr, {
95
+ id: props.id,
96
+ row: n,
97
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_lunaticComponents.LunaticComponents, {
98
+ components: getComponents(n),
99
+ componentProps: function componentProps(c) {
100
+ return _objectSpread(_objectSpread(_objectSpread({}, props), c), {}, {
101
+ id: "".concat(c.id, "-").concat(n)
102
+ });
103
+ },
104
+ wrapper: function wrapper(_ref3) {
105
+ var id = _ref3.id,
106
+ children = _ref3.children;
107
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Td, {
108
+ id: "".concat(id, "-").concat(n),
109
+ children: children
110
+ });
111
+ }
112
+ })
113
+ });
99
114
  })
100
115
  })]
101
116
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsDetachable, {
@@ -114,27 +129,4 @@ var RosterForLoop = (0, _commons.createCustomizableLunaticField)(function (props
114
129
  })]
115
130
  });
116
131
  }, 'RosterforLoop');
117
- exports.RosterForLoop = RosterForLoop;
118
- function Row(props) {
119
- var components = props.getComponents(props.row);
120
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Tr, {
121
- id: props.id,
122
- row: props.row,
123
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_lunaticComponents.LunaticComponents, {
124
- components: components,
125
- componentProps: function componentProps(c) {
126
- return _objectSpread(_objectSpread(_objectSpread({}, props), c), {}, {
127
- id: "".concat(c.id, "-").concat(props.row)
128
- });
129
- },
130
- wrapper: function wrapper(_ref3) {
131
- var id = _ref3.id,
132
- children = _ref3.children;
133
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Td, {
134
- id: "".concat(id, "-").concat(props.row),
135
- children: children
136
- });
137
- }
138
- })
139
- });
140
- }
132
+ exports.RosterForLoop = RosterForLoop;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.LunaticComponents = LunaticComponents;
7
7
  var _react = require("react");
8
8
  var lunaticComponents = _interopRequireWildcard(require("./index"));
9
+ var _component = require("../use-lunatic/commons/component");
9
10
  var _jsxRuntime = require("react/jsx-runtime");
10
11
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
12
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -47,12 +48,22 @@ function LunaticComponents(_ref) {
47
48
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(WrapperComponent, {
48
49
  ref: WrapperComponent === _react.Fragment ? undefined : wrapperRef,
49
50
  children: components.map(function (component, k) {
50
- var props = _objectSpread(_objectSpread({}, component), componentProps === null || componentProps === void 0 ? void 0 : componentProps(component));
51
+ if ((0, _component.hasComponentType)(component)) {
52
+ var _props = _objectSpread(_objectSpread({}, component), componentProps === null || componentProps === void 0 ? void 0 : componentProps(component));
53
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
54
+ children: wrapper(_objectSpread({
55
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(LunaticComponent, _objectSpread({}, _props)),
56
+ index: k
57
+ }, _props))
58
+ }, 'id' in component ? component.id : "index-".concat(k));
59
+ }
60
+ // In some case (table for instance) we have static component that only have a label (no componentType)
51
61
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
52
- children: wrapper(_objectSpread({
53
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(LunaticComponent, _objectSpread({}, props))
54
- }, props))
55
- }, 'id' in component ? component.id : "index-".concat(k));
62
+ children: wrapper({
63
+ children: component,
64
+ index: k
65
+ })
66
+ }, "index-".concat(k));
56
67
  })
57
68
  });
58
69
  }
@@ -3,27 +3,26 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = void 0;
7
- var _orchestrator = _interopRequireDefault(require("./orchestrator"));
6
+ exports.PairwiseLinks = void 0;
8
7
  var _declarations = require("../declarations");
9
8
  var _nothingToDisplay = _interopRequireDefault(require("../commons/components/nothing-to-display"));
9
+ var _array = require("../../utils/array");
10
+ var _react = require("react");
11
+ var _lunaticComponents = require("../lunatic-components");
10
12
  var _jsxRuntime = require("react/jsx-runtime");
11
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
+ 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); }
15
+ 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; }
16
+ 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; }
17
+ 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; }
18
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
19
+ 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); }
12
20
  var PairwiseLinks = function PairwiseLinks(_ref) {
13
21
  var declarations = _ref.declarations,
14
- components = _ref.components,
15
- handleChange = _ref.handleChange,
16
- value = _ref.value,
17
- missing = _ref.missing,
18
- shortcut = _ref.shortcut,
19
- features = _ref.features,
20
- preferences = _ref.preferences,
21
- management = _ref.management,
22
- executeExpression = _ref.executeExpression,
23
22
  xAxisIterations = _ref.xAxisIterations,
24
23
  yAxisIterations = _ref.yAxisIterations,
25
24
  id = _ref.id,
26
- symLinks = _ref.symLinks;
25
+ getComponents = _ref.getComponents;
27
26
  var nbRows = xAxisIterations * yAxisIterations;
28
27
  if (nbRows <= 1) {
29
28
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_nothingToDisplay["default"], {});
@@ -35,27 +34,25 @@ var PairwiseLinks = function PairwiseLinks(_ref) {
35
34
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsAfterText, {
36
35
  declarations: declarations,
37
36
  id: id
38
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_orchestrator["default"], {
39
- id: id,
40
- components: components,
41
- handleChange: handleChange,
42
- nbRows: nbRows,
43
- value: value,
44
- className: "pairwise-link",
45
- management: management,
46
- missing: missing,
47
- shortcut: shortcut,
48
- features: features,
49
- preferences: preferences,
50
- executeExpression: executeExpression,
51
- xAxisIterations: xAxisIterations,
52
- yAxisIterations: yAxisIterations,
53
- symLinks: symLinks
37
+ }), (0, _array.times)(xAxisIterations, function (x) {
38
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
39
+ children: (0, _array.times)(yAxisIterations, function (y) {
40
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
41
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_lunaticComponents.LunaticComponents, {
42
+ components: getComponents(x, y),
43
+ componentProps: function componentProps(props) {
44
+ return _objectSpread(_objectSpread({}, props), {}, {
45
+ id: "".concat(props.id, "-").concat(x + 1, "-").concat(y + 1, " ")
46
+ });
47
+ }
48
+ })
49
+ }, "".concat(x, "-").concat(y));
50
+ })
51
+ }, x);
54
52
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsDetachable, {
55
53
  declarations: declarations,
56
54
  id: id
57
55
  })]
58
56
  });
59
57
  };
60
- var _default = PairwiseLinks;
61
- exports["default"] = _default;
58
+ exports.PairwiseLinks = PairwiseLinks;
@@ -3,22 +3,20 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.LunaticTable = LunaticTable;
6
7
  exports["default"] = void 0;
7
8
  var _htmlTable = require("../commons/components/html-table");
8
- var _header = _interopRequireDefault(require("./header"));
9
9
  var _lunaticComponentWithLabel = _interopRequireDefault(require("../commons/components/lunatic-component-with-label"));
10
- var _tableOrchestrator = _interopRequireDefault(require("./table-orchestrator"));
11
10
  var _commons = require("../commons");
11
+ var _lunaticComponents = require("../lunatic-components");
12
+ var _tableHeader = require("./table-header");
12
13
  var _jsxRuntime = require("react/jsx-runtime");
13
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
15
  function LunaticTable(props) {
15
16
  var id = props.id,
16
17
  handleChange = props.handleChange,
17
- value = props.value,
18
18
  body = props.body,
19
19
  header = props.header,
20
- executeExpression = props.executeExpression,
21
- iteration = props.iteration,
22
20
  errors = props.errors,
23
21
  missing = props.missing,
24
22
  declarations = props.declarations,
@@ -37,17 +35,28 @@ function LunaticTable(props) {
37
35
  handleChange: handleChange,
38
36
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_htmlTable.Table, {
39
37
  id: id,
40
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_header["default"], {
38
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_tableHeader.TableHeader, {
41
39
  id: id,
42
40
  header: header
43
41
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Tbody, {
44
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_tableOrchestrator["default"], {
45
- id: id,
46
- body: body,
47
- executeExpression: executeExpression,
48
- handleChange: handleChange,
49
- iteration: iteration,
50
- value: value
42
+ children: body.map(function (row, rowIndex) {
43
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Tr, {
44
+ id: id,
45
+ row: rowIndex,
46
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_lunaticComponents.LunaticComponents, {
47
+ components: row,
48
+ wrapper: function wrapper(_ref) {
49
+ var children = _ref.children,
50
+ index = _ref.index;
51
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Td, {
52
+ id: id,
53
+ row: rowIndex,
54
+ index: index,
55
+ children: children
56
+ });
57
+ }
58
+ })
59
+ }, rowIndex);
51
60
  })
52
61
  })]
53
62
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = void 0;
6
+ exports.TableHeader = TableHeader;
7
7
  var _htmlTable = require("../commons/components/html-table");
8
8
  var _jsxRuntime = require("react/jsx-runtime");
9
- function Header(_ref) {
9
+ function TableHeader(_ref) {
10
10
  var id = _ref.id,
11
11
  header = _ref.header;
12
12
  if (!Array.isArray(header)) {
@@ -33,6 +33,4 @@ function Header(_ref) {
33
33
  children: content
34
34
  })
35
35
  });
36
- }
37
- var _default = Header;
38
- exports["default"] = _default;
36
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useTrackChanges = useTrackChanges;
7
+ var _react = require("react");
8
+ var _useRefSync = require("./use-ref-sync");
9
+ /**
10
+ * Allow tracking changed while interacting with Lunatic forms
11
+ */
12
+ function useTrackChanges(enabled, store, getData) {
13
+ // Saves the list of changed variable
14
+ var changedVariables = (0, _react.useRef)(new Set());
15
+ // Use ref to avoid dependencies in useCallback
16
+ var enabledRef = (0, _useRefSync.useRefSync)(enabled);
17
+ var getDataRef = (0, _useRefSync.useRefSync)(getData);
18
+ (0, _react.useEffect)(function () {
19
+ if (!enabled || !store) {
20
+ return;
21
+ }
22
+ var handleChange = function handleChange(e) {
23
+ changedVariables.current.add(e.detail.name);
24
+ };
25
+ store.on('change', handleChange);
26
+ return function () {
27
+ return store.off('change', handleChange);
28
+ };
29
+ }, [enabled, store]);
30
+
31
+ // Reset list of changed variables
32
+ var resetChangedData = (0, _react.useCallback)(function () {
33
+ changedVariables.current.clear();
34
+ }, [changedVariables]);
35
+ var getChangedData = (0, _react.useCallback)(function () {
36
+ var reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
37
+ if (!enabledRef.current) {
38
+ throw new Error('getChangedData() cannot be used without enabling tracking mode, add "trackChanges: true" to useLunatic options');
39
+ }
40
+ var data = getDataRef.current(Array.from(changedVariables.current));
41
+ if (reset) {
42
+ resetChangedData();
43
+ }
44
+ return data;
45
+ }, [enabledRef, getDataRef, resetChangedData]);
46
+ return {
47
+ getChangedData: getChangedData,
48
+ resetChangedData: resetChangedData
49
+ };
50
+ }
@@ -10,7 +10,7 @@ export { default as InputNumber } from './input-number';
10
10
  export { default as FilterDescription } from './filter-description';
11
11
  export { Loop } from './loop/loop';
12
12
  export { default as Modal } from './modal-controls';
13
- export { default as PairwiseLinks } from './pairwise-links';
13
+ export { PairwiseLinks } from './pairwise-links/pairwise-links';
14
14
  export { default as Radio } from './radio';
15
15
  export { RosterForLoop } from './loop/roster-for-loop/roster-for-loop';
16
16
  export { default as Sequence } from './sequence';
@@ -20,7 +20,7 @@ export { default as Switch } from './switch';
20
20
  export { default as Textarea } from './textarea';
21
21
  export { default as SuggesterLoaderWidget } from './suggester-loader-widget';
22
22
  export { default as Roundabout } from './roundabout';
23
- export { default as Table } from './table';
23
+ export { LunaticTable as Table } from './table/lunatic-table';
24
24
  export { LunaticComponentSet as ComponentSet } from './component-set/lunatic-component-set';
25
25
  export { default as Duration } from './duration';
26
26
  export { Summary } from './summary';
@@ -7,13 +7,12 @@ export declare const BlockForLoop: import("react").ComponentType<import("../type
7
7
  min: number;
8
8
  max: number;
9
9
  };
10
- iterations?: number | undefined;
10
+ iterations: number;
11
11
  getComponents: (n: number) => import("../../use-lunatic/commons/fill-components/fill-components").FilledLunaticComponentProps[];
12
12
  executeExpression: <T extends unknown = unknown>(expression: unknown, args?: {
13
- iteration?: number | undefined;
14
- linksIterations?: number[] | undefined;
15
- logging?: import("../../use-lunatic/commons/execute-expression/create-execute-expression").ExpressionLogger | undefined;
13
+ iteration?: number | number[] | undefined;
16
14
  bindingDependencies?: string[] | undefined;
15
+ deps?: string[] | undefined;
17
16
  } | undefined) => T;
18
17
  value: Record<string, unknown[]>;
19
18
  headers?: {
@@ -7,13 +7,12 @@ export declare const RosterForLoop: import("react").ComponentType<import("../../
7
7
  min: number;
8
8
  max: number;
9
9
  };
10
- iterations?: number | undefined;
10
+ iterations: number;
11
11
  getComponents: (n: number) => import("../../../use-lunatic/commons/fill-components/fill-components").FilledLunaticComponentProps[];
12
12
  executeExpression: <T extends unknown = unknown>(expression: unknown, args?: {
13
- iteration?: number | undefined;
14
- linksIterations?: number[] | undefined;
15
- logging?: import("../../../use-lunatic/commons/execute-expression/create-execute-expression").ExpressionLogger | undefined;
13
+ iteration?: number | number[] | undefined;
16
14
  bindingDependencies?: string[] | undefined;
15
+ deps?: string[] | undefined;
17
16
  } | undefined) => T;
18
17
  value: Record<string, unknown[]>;
19
18
  headers?: {
@@ -1,10 +1,12 @@
1
- import { type PropsWithChildren, type ReactNode } from 'react';
1
+ import { type PropsWithChildren, type ReactElement, type ReactNode } from 'react';
2
2
  import type { FilledLunaticComponentProps } from '../use-lunatic/commons/fill-components/fill-components';
3
3
  type Props<T extends Record<string, unknown>> = {
4
- components: FilledLunaticComponentProps[];
4
+ components: (FilledLunaticComponentProps | ReactElement)[];
5
5
  autoFocusKey?: string;
6
6
  componentProps?: (component: FilledLunaticComponentProps) => T;
7
- wrapper?: (props: PropsWithChildren<FilledLunaticComponentProps & T>) => ReactNode;
7
+ wrapper?: (props: PropsWithChildren<FilledLunaticComponentProps & T & {
8
+ index: number;
9
+ }>) => ReactNode;
8
10
  };
9
11
  /**
10
12
  * Entry point for orchestrators, this component display the list of fields
@@ -1,3 +1,2 @@
1
1
  import type { LunaticComponentProps } from '../type';
2
- declare const PairwiseLinks: ({ declarations, components, handleChange, value, missing, shortcut, features, preferences, management, executeExpression, xAxisIterations, yAxisIterations, id, symLinks, }: LunaticComponentProps<'PairwiseLinks'>) => import("react/jsx-runtime").JSX.Element;
3
- export default PairwiseLinks;
2
+ export declare const PairwiseLinks: ({ declarations, xAxisIterations, yAxisIterations, id, getComponents, }: LunaticComponentProps<'PairwiseLinks'>) => import("react/jsx-runtime").JSX.Element;
@@ -1,3 +1,3 @@
1
1
  import type { LunaticComponentProps } from '../type';
2
- declare function LunaticTable(props: LunaticComponentProps<'Table'>): import("react/jsx-runtime").JSX.Element;
2
+ export declare function LunaticTable(props: LunaticComponentProps<'Table'>): import("react/jsx-runtime").JSX.Element;
3
3
  export default LunaticTable;
@@ -7,5 +7,5 @@ type Props = {
7
7
  rowspan?: number;
8
8
  }>;
9
9
  };
10
- declare function Header({ id, header }: Props): import("react/jsx-runtime").JSX.Element | null;
11
- export default Header;
10
+ export declare function TableHeader({ id, header }: Props): import("react/jsx-runtime").JSX.Element | null;
11
+ export {};
@@ -1,4 +1,4 @@
1
- import type { LunaticComponentDefinition, LunaticError, LunaticExpression, LunaticState } from '../use-lunatic/type';
1
+ import type { LunaticComponentDefinition, LunaticError, LunaticState } from '../use-lunatic/type';
2
2
  import type { CSSProperties, FunctionComponent, ReactNode } from 'react';
3
3
  import { SuggesterStatus } from '../use-lunatic/use-suggesters';
4
4
  import useLunatic from '../use-lunatic';
@@ -94,7 +94,7 @@ type ComponentPropsByType = {
94
94
  min: number;
95
95
  max: number;
96
96
  };
97
- iterations?: number;
97
+ iterations: number;
98
98
  getComponents: (n: number) => FilledLunaticComponentProps[];
99
99
  executeExpression: LunaticState['executeExpression'];
100
100
  value: Record<string, unknown[]>;
@@ -108,7 +108,7 @@ type ComponentPropsByType = {
108
108
  min: number;
109
109
  max: number;
110
110
  };
111
- iterations?: number;
111
+ iterations: number;
112
112
  getComponents: (n: number) => FilledLunaticComponentProps[];
113
113
  executeExpression: LunaticState['executeExpression'];
114
114
  value: Record<string, unknown[]>;
@@ -124,9 +124,7 @@ type ComponentPropsByType = {
124
124
  rowspan?: number;
125
125
  colspan?: number;
126
126
  }>;
127
- body: Array<Array<{
128
- label: LunaticExpression;
129
- }>>;
127
+ body: FilledLunaticComponentProps[][];
130
128
  executeExpression: LunaticState['executeExpression'];
131
129
  iteration: LunaticState['pager']['iteration'];
132
130
  };
@@ -234,6 +232,7 @@ type ComponentPropsByType = {
234
232
  yAxisIterations: number;
235
233
  symLinks: Record<string, Record<string, string>>;
236
234
  value: Record<string, unknown[]>;
235
+ getComponents: (x: number, y: number) => FilledLunaticComponentProps[];
237
236
  };
238
237
  Suggester: LunaticBaseProps<string | null> & {
239
238
  storeName: string;
@@ -0,0 +1,9 @@
1
+ import type { LunaticVariablesStore } from '../use-lunatic/commons/variables/lunatic-variables-store';
2
+ import type { LunaticData } from '../use-lunatic/type';
3
+ /**
4
+ * Allow tracking changed while interacting with Lunatic forms
5
+ */
6
+ export declare function useTrackChanges(enabled: boolean, store: LunaticVariablesStore, getData: (names: string[]) => LunaticData): {
7
+ getChangedData: (reset?: boolean) => LunaticData;
8
+ resetChangedData: () => void;
9
+ };
@@ -13,22 +13,9 @@ export declare enum ActionKind {
13
13
  export type ActionHandleChange = {
14
14
  type: ActionKind.HANDLE_CHANGE;
15
15
  payload: {
16
- response: {
17
- name: string;
18
- };
16
+ name: string;
19
17
  value: unknown;
20
- args?: {
21
- loop?: boolean;
22
- length?: number;
23
- index?: number;
24
- linksIterations?: number[];
25
- symLinks?: {
26
- [variableName: string]: Record<string, string>;
27
- };
28
- paginatedLoop?: unknown;
29
- shallowIteration?: unknown;
30
- lengths?: number[];
31
- };
18
+ iteration?: number[];
32
19
  };
33
20
  };
34
21
  export type ActionGoToPage = {
@@ -116,7 +103,7 @@ export declare const onInit: (payload: {
116
103
  }) => ActionInit & {
117
104
  type: ActionKind.ON_INIT;
118
105
  };
119
- export declare const handleChange: (response: ActionHandleChange['payload']['response'], value: ActionHandleChange['payload']['value'], args: ActionHandleChange['payload']['args']) => Action;
106
+ export declare const handleChange: (name: ActionHandleChange['payload']['name'], value: ActionHandleChange['payload']['value'], iteration: ActionHandleChange['payload']['iteration']) => Action;
120
107
  export declare const onSetWaiting: (status: boolean) => Action;
121
108
  export declare const updateState: (payload: {
122
109
  getSuggesterStatus: (name: string) => {
@@ -1,7 +1,8 @@
1
1
  import type { LunaticError, LunaticState } from '../type';
2
2
  export type StateForControls = Pick<LunaticState, 'pager' | 'pages' | 'isInLoop' | 'executeExpression'>;
3
- declare function computeErrors(state: StateForControls): {
3
+ type ControlsResult = {
4
4
  currentErrors: Record<string, LunaticError[]> | undefined;
5
5
  isCritical: boolean;
6
6
  };
7
- export default computeErrors;
7
+ export declare function compileControls(state: StateForControls): ControlsResult;
8
+ export {};