@inseefr/lunatic 2.4.7 → 2.4.8-dynamicArray

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 (41) hide show
  1. package/lib/components/duration/duration.js +117 -0
  2. package/lib/components/duration/duration.scss +16 -0
  3. package/lib/components/duration/duration.spec.js +49 -0
  4. package/lib/components/duration/index.js +13 -0
  5. package/lib/components/duration/useDurationValues.js +124 -0
  6. package/lib/components/index.js +7 -0
  7. package/lib/components/loop/loop.js +2 -2
  8. package/lib/components/loop/roster-for-loop/roster-for-loop.js +35 -32
  9. package/lib/components/loop/roster-for-loop/roster-table.js +17 -16
  10. package/lib/components/loop/roster-for-loop/roster.scss +32 -34
  11. package/lib/components/loop/roster-for-loop/row.js +48 -19
  12. package/lib/hooks/use-did-change.js +19 -0
  13. package/lib/hooks/use-why-render.js +20 -0
  14. package/lib/src/components/duration/duration.d.ts +4 -0
  15. package/lib/src/components/duration/duration.spec.d.ts +1 -0
  16. package/lib/src/components/duration/index.d.ts +1 -0
  17. package/lib/src/components/duration/useDurationValues.d.ts +43 -0
  18. package/lib/src/components/index.d.ts +1 -0
  19. package/lib/src/components/loop/block-for-loop/block-for-loop-ochestrator.d.ts +1 -1
  20. package/lib/src/components/loop/block-for-loop/block-for-loop.d.ts +1 -1
  21. package/lib/src/components/loop/roster-for-loop/roster-for-loop-orchestrator.d.ts +1 -1
  22. package/lib/src/components/loop/roster-for-loop/roster-for-loop.d.ts +4 -4
  23. package/lib/src/components/loop/roster-for-loop/roster-table.d.ts +2 -2
  24. package/lib/src/components/type.d.ts +9 -2
  25. package/lib/src/hooks/use-did-change.d.ts +4 -0
  26. package/lib/src/hooks/use-why-render.d.ts +4 -0
  27. package/lib/src/use-lunatic/commons/use-components-from-state.d.ts +1 -2
  28. package/lib/src/use-lunatic/use-lunatic.d.ts +1 -1
  29. package/lib/stories/duration/duration.stories.js +41 -0
  30. package/lib/stories/duration/source.json +32 -0
  31. package/lib/stories/duration/source1.json +32 -0
  32. package/lib/stories/loop/block-for-loop.stories.js +1 -8
  33. package/lib/stories/loop/roster-for-loop.stories.js +8 -1
  34. package/lib/stories/loop/source-with-header.json +16 -4
  35. package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +1 -1
  36. package/lib/use-lunatic/commons/use-components-from-state.js +2 -14
  37. package/package.json +2 -2
  38. package/lib/components/loop/roster-for-loop/body.js +0 -52
  39. package/lib/components/loop/roster-for-loop/header.js +0 -34
  40. package/lib/src/components/loop/roster-for-loop/body.d.ts +0 -12
  41. package/lib/src/components/loop/roster-for-loop/header.d.ts +0 -9
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ require("./duration.scss");
9
+ var _useDurationValues2 = require("./useDurationValues");
10
+ var _commons = require("../commons");
11
+ var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../commons/components/lunatic-component-without-label"));
12
+ var _jsxRuntime = require("react/jsx-runtime");
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); }
20
+ function Duration(props) {
21
+ var value = props.value,
22
+ label = props.label,
23
+ format = props.format,
24
+ handleChange = props.handleChange,
25
+ response = props.response,
26
+ id = props.id,
27
+ preferences = props.preferences,
28
+ declarations = props.declarations,
29
+ missing = props.missing,
30
+ missingResponse = props.missingResponse,
31
+ management = props.management,
32
+ description = props.description;
33
+ var onChange = (0, _commons.useOnHandleChange)({
34
+ handleChange: handleChange,
35
+ response: response,
36
+ value: value
37
+ });
38
+ var _useDurationValues = (0, _useDurationValues2.useDurationValues)(value, format, onChange),
39
+ propsHours = _useDurationValues.propsHours,
40
+ propsMinutes = _useDurationValues.propsMinutes,
41
+ propsYears = _useDurationValues.propsYears,
42
+ propsMonths = _useDurationValues.propsMonths;
43
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_lunaticComponentWithoutLabel["default"], {
44
+ id: id,
45
+ preferences: preferences,
46
+ declarations: declarations,
47
+ value: value,
48
+ missing: missing,
49
+ missingResponse: missingResponse,
50
+ management: management,
51
+ description: description,
52
+ handleChange: handleChange,
53
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
54
+ className: "container",
55
+ children: [label, /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {}), format === 'PTnHnM' && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
56
+ className: "field-group",
57
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
58
+ className: "input-field-group",
59
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
60
+ htmlFor: "hoursInput",
61
+ className: "input-label",
62
+ children: "Heures:"
63
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({
64
+ id: "hoursInput",
65
+ type: "number"
66
+ }, propsHours), {}, {
67
+ className: "input-field"
68
+ }))]
69
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
70
+ className: "input-field-group",
71
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
72
+ htmlFor: "minutesInput",
73
+ className: "input-label",
74
+ children: "Minutes:"
75
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({
76
+ id: "minutesInput",
77
+ type: "number"
78
+ }, propsMinutes), {}, {
79
+ min: "0",
80
+ className: "input-field"
81
+ }))]
82
+ })]
83
+ }), format === 'PnYnM' && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
84
+ className: "field-group",
85
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
86
+ className: "input-field-group",
87
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
88
+ htmlFor: "yearsInput",
89
+ className: "input-label",
90
+ children: "Ann\xE9es:"
91
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({
92
+ id: "yearsInput",
93
+ type: "number"
94
+ }, propsYears), {}, {
95
+ min: "0",
96
+ className: "input-field"
97
+ }))]
98
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
99
+ className: "input-field-group",
100
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
101
+ htmlFor: "monthsInput",
102
+ className: "input-label",
103
+ children: "Mois:"
104
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({
105
+ id: "monthsInput",
106
+ type: "number"
107
+ }, propsMonths), {}, {
108
+ min: "0",
109
+ className: "input-field"
110
+ }))]
111
+ })]
112
+ })]
113
+ })
114
+ });
115
+ }
116
+ var _default = Duration;
117
+ exports["default"] = _default;
@@ -0,0 +1,16 @@
1
+ .input-field {
2
+ width: 100px;
3
+ }
4
+ .field-group {
5
+ display: flex;
6
+ }
7
+
8
+ .input-field-group {
9
+ display: flex;
10
+ align-items: first baseline;
11
+ margin: 5px;
12
+ }
13
+
14
+ .input-label {
15
+ margin-right: 5px;
16
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _react = _interopRequireDefault(require("react"));
4
+ var _react2 = require("@testing-library/react");
5
+ var _vitest = require("vitest");
6
+ var _duration = _interopRequireDefault(require("./duration"));
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ (0, _vitest.describe)('Duration component', function () {
10
+ var handleChange = _vitest.vi.fn();
11
+ (0, _vitest.it)('should render with hours and minutes inputs when format is "PTnHnM"', function () {
12
+ var _render = (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_duration["default"], {
13
+ format: "PTnHnM",
14
+ handleChange: handleChange,
15
+ id: '',
16
+ value: null,
17
+ executeExpression: function executeExpression(expression, args) {
18
+ throw new Error('Function not implemented.');
19
+ },
20
+ response: {
21
+ name: ''
22
+ }
23
+ })),
24
+ getByLabelText = _render.getByLabelText;
25
+ var hoursInput = getByLabelText('Heures:');
26
+ var minutesInput = getByLabelText('Minutes:');
27
+ (0, _vitest.expect)(hoursInput).toBeInTheDocument();
28
+ (0, _vitest.expect)(minutesInput).toBeInTheDocument();
29
+ });
30
+ (0, _vitest.it)('should render with years and months inputs when format is "PnYnM"', function () {
31
+ var _render2 = (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_duration["default"], {
32
+ format: "PnYnM",
33
+ handleChange: handleChange,
34
+ id: '',
35
+ value: null,
36
+ executeExpression: function executeExpression(expression, args) {
37
+ throw new Error('Function not implemented.');
38
+ },
39
+ response: {
40
+ name: ''
41
+ }
42
+ })),
43
+ getByLabelText = _render2.getByLabelText;
44
+ var yearsInput = getByLabelText('Années:');
45
+ var monthsInput = getByLabelText('Mois:');
46
+ (0, _vitest.expect)(yearsInput).toBeInTheDocument();
47
+ (0, _vitest.expect)(monthsInput).toBeInTheDocument();
48
+ });
49
+ });
@@ -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 _duration["default"];
10
+ }
11
+ });
12
+ var _duration = _interopRequireDefault(require("./duration"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useDurationValues = void 0;
7
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
8
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
+ function _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."); }
10
+ 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); }
11
+ 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; }
12
+ 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; } }
13
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
+ 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; }
15
+ 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; }
16
+ 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; }
17
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
18
+ 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); }
19
+ var useDurationValues = function useDurationValues(value, format, handleChange) {
20
+ var duration = parseISO8601Duration(value);
21
+ // Gestionnaire de changement pour les champs individuels (heures, minutes, mois, années)
22
+ var onChangeHandler = function onChangeHandler(key) {
23
+ return function (e) {
24
+ // Mise à jour de la valeur de la durée avec la clé dynamique
25
+ handleChange(formatISO8601Duration(format, _objectSpread(_objectSpread({}, duration), {}, _defineProperty({}, key, e.target.value))));
26
+ };
27
+ };
28
+ var propsHours = {
29
+ value: duration.hours,
30
+ onChange: onChangeHandler("hours"),
31
+ min: "0",
32
+ max: "23"
33
+ };
34
+ var propsMinutes = {
35
+ value: duration.minutes,
36
+ onChange: onChangeHandler("minutes"),
37
+ min: "0",
38
+ max: "59"
39
+ };
40
+ var propsMonths = {
41
+ value: duration.months,
42
+ onChange: onChangeHandler("months"),
43
+ min: "0",
44
+ max: "11"
45
+ };
46
+ var propsYears = {
47
+ value: duration.years,
48
+ onChange: onChangeHandler("years"),
49
+ min: "0"
50
+ };
51
+ // Retourne les propriétés pour chaque champ de durée
52
+ return {
53
+ propsHours: propsHours,
54
+ propsMonths: propsMonths,
55
+ propsYears: propsYears,
56
+ propsMinutes: propsMinutes
57
+ };
58
+ };
59
+ exports.useDurationValues = useDurationValues;
60
+ // Fonction pour parser une durée au format ISO8601 en objets individuels
61
+ var parseISO8601Duration = function parseISO8601Duration(duration) {
62
+ // Si la durée est vide, retourne des valeurs vides pour chaque champ
63
+ if (!duration) {
64
+ return {
65
+ hours: '',
66
+ minutes: '',
67
+ years: '',
68
+ months: ''
69
+ };
70
+ }
71
+ // Expression régulière pour le format heures:minutes (PTnHnM)
72
+ var regexHourMinute = /PT(\d+H)?(\d+M)?/i;
73
+ var matchHourMinute = duration.match(regexHourMinute);
74
+ // Si la durée correspond au format heures:minutes (PTnHnM)
75
+ if (matchHourMinute) {
76
+ var _matchHourMinute = _slicedToArray(matchHourMinute, 3),
77
+ hours = _matchHourMinute[1],
78
+ minutes = _matchHourMinute[2];
79
+ return {
80
+ hours: hours ? hours.replace('H', '') : '',
81
+ minutes: minutes ? minutes.replace('M', '') : '',
82
+ years: '',
83
+ months: ''
84
+ };
85
+ }
86
+ // Expression régulière pour le format années:mois (PnYnM)
87
+ var regexYearMonth = /P(\d+Y)?(\d+M)?/i;
88
+ var matchYearMonth = duration.match(regexYearMonth);
89
+ // Si la durée correspond au format années:mois (PnYnM)
90
+ if (matchYearMonth) {
91
+ var _matchYearMonth = _slicedToArray(matchYearMonth, 3),
92
+ years = _matchYearMonth[1],
93
+ months = _matchYearMonth[2];
94
+ return {
95
+ years: years ? years.replace('Y', '') : '',
96
+ months: months ? months.replace('M', '') : '',
97
+ hours: '',
98
+ minutes: ''
99
+ };
100
+ }
101
+ // Si la durée ne correspond à aucun des formats connus, retourne des valeurs vides pour chaque champ
102
+ return {
103
+ hours: '',
104
+ minutes: '',
105
+ years: '',
106
+ months: ''
107
+ };
108
+ };
109
+ // Fonction pour formatter les objets individuels en durée au format souhaité
110
+ var formatISO8601Duration = function formatISO8601Duration(format, duration) {
111
+ // Si tous les champs de durée sont vides, retourne null
112
+ if (!duration.hours && !duration.minutes && !duration.years && !duration.months) {
113
+ return null;
114
+ }
115
+ // Formatage de la durée en fonction du format spécifié
116
+ if (format === 'PTnHnM') {
117
+ return "PT".concat(duration.hours ? "".concat(duration.hours, "H") : '0H').concat(duration.minutes ? "".concat(duration.minutes, "M") : '0M');
118
+ }
119
+ if (format === 'PnYnM') {
120
+ return "P".concat(duration.years ? "".concat(duration.years, "Y") : '0Y').concat(duration.months ? "".concat(duration.months, "M") : '0M');
121
+ }
122
+ // Si le format spécifié n'est pas valide, retourne null
123
+ return null;
124
+ };
@@ -51,6 +51,12 @@ Object.defineProperty(exports, "Dropdown", {
51
51
  return _dropdown["default"];
52
52
  }
53
53
  });
54
+ Object.defineProperty(exports, "Duration", {
55
+ enumerable: true,
56
+ get: function get() {
57
+ return _duration["default"];
58
+ }
59
+ });
54
60
  Object.defineProperty(exports, "FilterDescription", {
55
61
  enumerable: true,
56
62
  get: function get() {
@@ -182,6 +188,7 @@ var _suggesterLoaderWidget = _interopRequireDefault(require("./suggester-loader-
182
188
  var _roundabout = _interopRequireDefault(require("./roundabout"));
183
189
  var _table = _interopRequireDefault(require("./table"));
184
190
  var _componentSet = _interopRequireDefault(require("./component-set"));
191
+ var _duration = _interopRequireDefault(require("./duration"));
185
192
  var _questionInformation = _interopRequireDefault(require("./questions/question-information"));
186
193
  var _questionContext = _interopRequireDefault(require("./questions/question-context"));
187
194
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -24,7 +24,7 @@ function Loop(props) {
24
24
  value = props.value,
25
25
  executeExpression = props.executeExpression,
26
26
  componentType = props.componentType,
27
- headers = props.headers,
27
+ header = props.header,
28
28
  shortcut = props.shortcut,
29
29
  management = props.management,
30
30
  missing = props.missing,
@@ -68,7 +68,7 @@ function Loop(props) {
68
68
  shortcut: shortcut,
69
69
  features: features,
70
70
  preferences: preferences,
71
- headers: headers,
71
+ header: header,
72
72
  errors: errors
73
73
  });
74
74
  default:
@@ -1,21 +1,19 @@
1
1
  "use strict";
2
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
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports["default"] = void 0;
8
- var _react = _interopRequireWildcard(require("react"));
9
- var _declarations = require("../../declarations");
10
- var _rosterTable = _interopRequireDefault(require("./roster-table"));
7
+ var _react = require("react");
11
8
  var _commons = require("../../commons");
9
+ var _lunaticComponentWithLabel = _interopRequireDefault(require("../../commons/components/lunatic-component-with-label"));
10
+ var _rosterTable = _interopRequireDefault(require("./roster-table"));
12
11
  var _handleRowButton = _interopRequireDefault(require("../commons/handle-row-button"));
13
12
  var _i18n = _interopRequireDefault(require("../../../i18n"));
14
13
  var _getInitLength = _interopRequireDefault(require("../commons/get-init-length"));
14
+ var _useRefSync = require("../../../hooks/use-ref-sync");
15
15
  var _jsxRuntime = require("react/jsx-runtime");
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
- 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); }
18
- 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; }
19
17
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
20
18
  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."); }
21
19
  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); }
@@ -32,12 +30,13 @@ function RosterforLoop(_ref) {
32
30
  label = _ref.label,
33
31
  components = _ref.components,
34
32
  executeExpression = _ref.executeExpression,
35
- headers = _ref.headers,
33
+ header = _ref.header,
36
34
  missing = _ref.missing,
37
- shortcut = _ref.shortcut,
38
35
  id = _ref.id,
39
36
  management = _ref.management,
40
- errors = _ref.errors;
37
+ errors = _ref.errors,
38
+ missingResponse = _ref.missingResponse,
39
+ description = _ref.description;
41
40
  var min = (lines === null || lines === void 0 ? void 0 : lines.min) || DEFAULT_MIN_ROWS;
42
41
  var max = (lines === null || lines === void 0 ? void 0 : lines.max) || DEFAULT_MAX_ROWS;
43
42
  var _useState = (0, _react.useState)(function () {
@@ -47,19 +46,21 @@ function RosterforLoop(_ref) {
47
46
  nbRows = _useState2[0],
48
47
  setNbRows = _useState2[1];
49
48
  var showButtons = min && max && min !== max;
49
+ var valueMapRef = (0, _useRefSync.useRefSync)(valueMap);
50
+ var nbRowsRef = (0, _useRefSync.useRefSync)(nbRows);
50
51
  var addRow = (0, _react.useCallback)(function () {
51
52
  if (nbRows < max) {
52
53
  setNbRows(nbRows + 1);
53
54
  }
54
55
  }, [max, nbRows]);
55
56
  var handleChangeLoop = (0, _react.useCallback)(function (response, value, args) {
56
- var v = valueMap[response.name];
57
+ var v = valueMapRef.current[response.name];
57
58
  v[args.index] = value;
58
59
  handleChange(response, v, {
59
60
  loop: true,
60
- length: nbRows
61
+ length: nbRowsRef.current
61
62
  }); // TODO: a retaper pour déplacer cette compléxité
62
- }, [handleChange, nbRows, valueMap]);
63
+ }, [handleChange, nbRowsRef, valueMapRef]);
63
64
  var removeRow = (0, _react.useCallback)(function () {
64
65
  if (nbRows > 1) {
65
66
  var newNbRows = nbRows - 1;
@@ -79,32 +80,34 @@ function RosterforLoop(_ref) {
79
80
  }, [nbRows, handleChange, valueMap]);
80
81
  if (nbRows > 0) {
81
82
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
82
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsBeforeText, {
83
- declarations: declarations,
84
- id: id
85
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsAfterText, {
86
- declarations: declarations,
87
- id: id
88
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_rosterTable["default"], {
83
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_lunaticComponentWithLabel["default"], {
89
84
  id: id,
90
- components: components,
91
- nbRows: nbRows,
92
- executeExpression: executeExpression,
93
- headers: headers,
94
- handleChange: handleChangeLoop,
95
- value: valueMap,
96
- management: management,
97
- missing: missing,
98
- shortcut: shortcut,
99
- errors: errors
100
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsDetachable, {
85
+ label: label,
101
86
  declarations: declarations,
102
- id: id
87
+ missing: missing,
88
+ missingResponse: missingResponse,
89
+ management: management,
90
+ description: description,
91
+ handleChange: handleChange,
92
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_rosterTable["default"], {
93
+ id: id,
94
+ components: components,
95
+ nbRows: nbRows,
96
+ executeExpression: executeExpression,
97
+ header: header,
98
+ handleChange: handleChangeLoop,
99
+ value: valueMap,
100
+ missing: missing,
101
+ errors: errors
102
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
103
+ errors: errors,
104
+ activeId: id
105
+ })]
103
106
  }), showButtons && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
104
107
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_handleRowButton["default"], {
105
108
  onClick: addRow,
106
109
  disabled: nbRows === max,
107
- children: label || _i18n["default"].DEFAULT_BUTTON_ADD
110
+ children: _i18n["default"].DEFAULT_BUTTON_ADD
108
111
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_handleRowButton["default"], {
109
112
  onClick: removeRow,
110
113
  disabled: nbRows === min,
@@ -4,43 +4,44 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _react = _interopRequireDefault(require("react"));
8
7
  var _htmlTable = require("../../commons/components/html-table");
9
- var _header = _interopRequireDefault(require("./header"));
10
- var _body = _interopRequireDefault(require("./body"));
8
+ var _header = _interopRequireDefault(require("../../table/header"));
11
9
  require("./roster.scss");
12
10
  var _commons = require("../../commons");
11
+ var _rosterForLoopOrchestrator = _interopRequireDefault(require("./roster-for-loop-orchestrator"));
13
12
  var _jsxRuntime = require("react/jsx-runtime");
14
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
+ var preferences = ['COLLECTED'];
15
15
  function RosterTable(_ref) {
16
16
  var components = _ref.components,
17
17
  nbRows = _ref.nbRows,
18
18
  executeExpression = _ref.executeExpression,
19
19
  id = _ref.id,
20
- headers = _ref.headers,
20
+ header = _ref.header,
21
21
  valueMap = _ref.value,
22
- shortcut = _ref.shortcut,
23
22
  missing = _ref.missing,
24
- management = _ref.management,
25
23
  handleChange = _ref.handleChange;
26
24
  if (nbRows <= 0) {
27
25
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.NothingToDisplay, {});
28
26
  }
29
27
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_htmlTable.Table, {
30
28
  id: id,
29
+ className: "rosterTable",
31
30
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_header["default"], {
32
- header: headers,
31
+ header: header,
33
32
  id: id
34
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_body["default"], {
33
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Tbody, {
35
34
  id: id,
36
- components: components,
37
- handleChange: handleChange,
38
- nbRows: nbRows,
39
- value: valueMap,
40
- management: management,
41
- missing: missing,
42
- shortcut: shortcut,
43
- executeExpression: executeExpression
35
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_rosterForLoopOrchestrator["default"], {
36
+ id: "roster-".concat(id),
37
+ components: components,
38
+ nbRows: nbRows,
39
+ handleChange: handleChange,
40
+ executeExpression: executeExpression,
41
+ valueMap: valueMap,
42
+ missing: missing,
43
+ preferences: preferences
44
+ })
44
45
  })]
45
46
  });
46
47
  }
@@ -1,39 +1,37 @@
1
- // .lunatic-component {
2
- // .table-lunatic {
3
- // table-layout: fixed;
4
- // border-collapse: collapse;
5
- // margin-top: 0.3em;
6
- // margin-bottom: 0.3em;
7
- // & td,
8
- // th {
9
- // border: 0.15em solid var(--color-primary-dark);
10
- // padding: 0.2em;
11
- // }
12
- // & td {
13
- // .field,
14
- // .field-with-tooltip {
15
- // display: flex;
16
- // justify-content: center;
17
- // align-items: center;
18
- // }
19
- // }
20
- // }
1
+ .lunatic-component {
2
+ .rosterTable {
3
+ border-collapse: separate;
4
+ border-spacing: 0;
5
+ thead {
6
+ position: sticky;
7
+ background-color: var(--color-primary-contrast-text);
8
+ z-index: 1;
9
+ top: 0;
10
+ th {
11
+ border-top: 2px solid;
12
+ border-bottom: 2px solid;
13
+ border-right: 2px solid;
14
+ }
15
+ th:first-child {
16
+ border-left: 2px solid;
17
+ }
18
+ }
19
+ tbody {
20
+ th {
21
+ border-top: 1px solid;
22
+ border-bottom: 1px solid;
23
+ border-right: 1px solid;
24
+ }
21
25
 
22
- // .table-lunatic .tooltip-lunatic img {
23
- // height: 20px;
24
- // width: 20px;
25
- // }
26
- // }
26
+ td {
27
+ border-bottom: 1px solid;
28
+ border-right: 1px solid;
29
+ }
27
30
 
28
- .lunatic-table {
29
- table-layout: fixed;
30
- border-collapse: collapse;
31
- margin-top: 0.3em;
32
- margin-bottom: 0.3em;
33
- .lunatic-table-thead {
34
- .lunatic-table-th {
35
- border: 0.15em solid var(--color-primary-dark);
36
- padding: 0.2em;
31
+ th:first-child,
32
+ td:first-child {
33
+ border-left: 1px solid;
34
+ }
37
35
  }
38
36
  }
39
37
  }