@inseefr/lunatic 2.7.12 → 2.7.13

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.
@@ -73,7 +73,11 @@ var BlockForLoop = exports.BlockForLoop = (0, _commons.createCustomizableLunatic
73
73
  return null;
74
74
  }
75
75
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
76
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsBeforeText, {
76
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Label, {
77
+ htmlFor: id,
78
+ id: "label-".concat(id),
79
+ children: label
80
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsBeforeText, {
77
81
  declarations: declarations,
78
82
  id: id
79
83
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsAfterText, {
@@ -96,7 +100,7 @@ var BlockForLoop = exports.BlockForLoop = (0, _commons.createCustomizableLunatic
96
100
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_loopButton.LoopButton, {
97
101
  onClick: addRow,
98
102
  disabled: nbRows === max,
99
- children: label || _i18n["default"].DEFAULT_BUTTON_ADD
103
+ children: _i18n["default"].DEFAULT_BUTTON_ADD
100
104
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_loopButton.LoopButton, {
101
105
  onClick: removeRow,
102
106
  disabled: nbRows === 1,
@@ -2,6 +2,13 @@
2
2
 
3
3
  exports[`RosterForLoop > renders the right number of columns 1`] = `
4
4
  <div>
5
+ <label
6
+ class="lunatic-label"
7
+ for="table"
8
+ id="label-table"
9
+ >
10
+ Ceci est un test
11
+ </label>
5
12
  <table
6
13
  class="lunatic-table"
7
14
  id="table-table"
@@ -77,7 +84,7 @@ exports[`RosterForLoop > renders the right number of columns 1`] = `
77
84
  <input
78
85
  class="button-lunatic"
79
86
  type="button"
80
- value="Ceci est un test"
87
+ value="Add row"
81
88
  />
82
89
  <input
83
90
  class="button-lunatic"
@@ -18,7 +18,7 @@ var _lunaticComponents = require("../../lunatic-components");
18
18
  var _constant = require("../constant");
19
19
  var _errors = require("../../commons/components/errors/errors");
20
20
  var _jsxRuntime = require("react/jsx-runtime");
21
- var _excluded = ["value", "lines", "handleChange", "declarations", "label", "headers", "iterations", "id", "getComponents"];
21
+ var _excluded = ["value", "lines", "handleChange", "declarations", "header", "iterations", "id", "getComponents", "label"];
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
23
23
  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; }
24
24
  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; }
@@ -44,11 +44,11 @@ var RosterForLoop = exports.RosterForLoop = (0, _commons.createCustomizableLunat
44
44
  lines = props.lines,
45
45
  handleChange = props.handleChange,
46
46
  declarations = props.declarations,
47
- label = props.label,
48
- headers = props.headers,
47
+ header = props.header,
49
48
  iterations = props.iterations,
50
49
  id = props.id,
51
50
  getComponents = props.getComponents,
51
+ label = props.label,
52
52
  otherProps = _objectWithoutProperties(props, _excluded);
53
53
  var min = (lines === null || lines === void 0 ? void 0 : lines.min) || DEFAULT_MIN_ROWS;
54
54
  var max = (lines === null || lines === void 0 ? void 0 : lines.max) || DEFAULT_MAX_ROWS;
@@ -85,7 +85,11 @@ var RosterForLoop = exports.RosterForLoop = (0, _commons.createCustomizableLunat
85
85
  }
86
86
  var cols = 0;
87
87
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
88
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsBeforeText, {
88
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Label, {
89
+ htmlFor: id,
90
+ id: "label-".concat(id),
91
+ children: label
92
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsBeforeText, {
89
93
  declarations: declarations,
90
94
  id: id
91
95
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsAfterText, {
@@ -94,7 +98,7 @@ var RosterForLoop = exports.RosterForLoop = (0, _commons.createCustomizableLunat
94
98
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_htmlTable.Table, {
95
99
  id: id,
96
100
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_tableHeader.TableHeader, {
97
- header: headers,
101
+ header: header,
98
102
  id: id
99
103
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Tbody, {
100
104
  id: id,
@@ -146,7 +150,7 @@ var RosterForLoop = exports.RosterForLoop = (0, _commons.createCustomizableLunat
146
150
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_loopButton.LoopButton, {
147
151
  onClick: addRow,
148
152
  disabled: nbRows === max,
149
- children: label || _i18n["default"].DEFAULT_BUTTON_ADD
153
+ children: _i18n["default"].DEFAULT_BUTTON_ADD
150
154
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_loopButton.LoopButton, {
151
155
  onClick: removeRow,
152
156
  disabled: nbRows === min,
@@ -15,7 +15,7 @@ export declare const BlockForLoop: import("react").ComponentType<import("../type
15
15
  deps?: string[] | undefined;
16
16
  } | undefined) => T;
17
17
  value: Record<string, unknown[]>;
18
- headers?: {
18
+ header?: {
19
19
  label: import("react").ReactNode;
20
20
  }[] | undefined;
21
21
  paginatedLoop?: boolean | undefined;
@@ -16,7 +16,7 @@ export declare const RosterForLoop: import("react").ComponentType<import("../../
16
16
  deps?: string[] | undefined;
17
17
  } | undefined) => T;
18
18
  value: Record<string, unknown[]>;
19
- headers?: {
19
+ header?: {
20
20
  label: import("react").ReactNode;
21
21
  }[] | undefined;
22
22
  paginatedLoop?: boolean | undefined;
@@ -98,7 +98,7 @@ type ComponentPropsByType = {
98
98
  getComponents: (n: number) => FilledLunaticComponentProps[];
99
99
  executeExpression: LunaticState['executeExpression'];
100
100
  value: Record<string, unknown[]>;
101
- headers?: Array<{
101
+ header?: Array<{
102
102
  label: ReactNode;
103
103
  }>;
104
104
  paginatedLoop?: boolean;
@@ -112,7 +112,7 @@ type ComponentPropsByType = {
112
112
  getComponents: (n: number) => FilledLunaticComponentProps[];
113
113
  executeExpression: LunaticState['executeExpression'];
114
114
  value: Record<string, unknown[]>;
115
- headers?: Array<{
115
+ header?: Array<{
116
116
  label: ReactNode;
117
117
  }>;
118
118
  paginatedLoop?: boolean;
@@ -72,7 +72,7 @@ declare function useLunatic(source: LunaticSource, data: LunaticData | undefined
72
72
  deps?: string[] | undefined;
73
73
  } | undefined) => T;
74
74
  value: Record<string, unknown[]>;
75
- headers?: {
75
+ header?: {
76
76
  label: import("react").ReactNode;
77
77
  }[] | undefined;
78
78
  paginatedLoop?: boolean | undefined;
@@ -90,7 +90,7 @@ declare function useLunatic(source: LunaticSource, data: LunaticData | undefined
90
90
  deps?: string[] | undefined;
91
91
  } | undefined) => T;
92
92
  value: Record<string, unknown[]>;
93
- headers?: {
93
+ header?: {
94
94
  label: import("react").ReactNode;
95
95
  }[] | undefined;
96
96
  paginatedLoop?: boolean | undefined;
@@ -320,7 +320,7 @@ declare function useLunatic(source: LunaticSource, data: LunaticData | undefined
320
320
  deps?: string[] | undefined;
321
321
  } | undefined) => T;
322
322
  value: Record<string, unknown[]>;
323
- headers?: {
323
+ header?: {
324
324
  label: import("react").ReactNode;
325
325
  }[] | undefined;
326
326
  paginatedLoop?: boolean | undefined;
@@ -338,7 +338,7 @@ declare function useLunatic(source: LunaticSource, data: LunaticData | undefined
338
338
  deps?: string[] | undefined;
339
339
  } | undefined) => T;
340
340
  value: Record<string, unknown[]>;
341
- headers?: {
341
+ header?: {
342
342
  label: import("react").ReactNode;
343
343
  }[] | undefined;
344
344
  paginatedLoop?: boolean | undefined;
@@ -14,7 +14,7 @@
14
14
  {
15
15
  "id": "loop-prenom",
16
16
  "componentType": "RosterForLoop",
17
- "headers": [
17
+ "header": [
18
18
  { "headerCell": true, "label": "Prénom" },
19
19
  { "headerCell": true, "label": "Age" }
20
20
  ],
@@ -21,15 +21,15 @@ var getReferentiel = exports.getReferentiel = /*#__PURE__*/function () {
21
21
  return r.json();
22
22
  }));
23
23
  case 4:
24
- return _context.abrupt("return", fetch('https://inseefr.github.io/Lunatic/storybook/naf-rev2.json').then(function (r) {
24
+ return _context.abrupt("return", fetch('/naf-rev2.json').then(function (r) {
25
25
  return r.json();
26
26
  }));
27
27
  case 5:
28
- return _context.abrupt("return", fetch('https://inseefr.github.io/Lunatic/storybook/communes-2019.json').then(function (r) {
28
+ return _context.abrupt("return", fetch('/communes-2019.json').then(function (r) {
29
29
  return r.json();
30
30
  }));
31
31
  case 6:
32
- throw new Error("Unkonw r\xE9f\xE9rentiel ".concat(name));
32
+ throw new Error("Unknown r\xE9f\xE9rentiel ".concat(name));
33
33
  case 7:
34
34
  case "end":
35
35
  return _context.stop();
@@ -24,7 +24,7 @@ var VTL_ATTRIBUTES = ['label', 'options.label', 'responses.label', 'hierarchy.la
24
24
  // Disable controls compilation
25
25
  // 'controls.control',
26
26
  // 'controls.errorMessage',
27
- 'controls.iterations', 'lines.min', 'lines.max', 'xAxisIterations', 'yAxisIterations', 'conditionFilter', 'headers.label', 'header.label', 'disabled', 'readOnly'];
27
+ 'controls.iterations', 'lines.min', 'lines.max', 'xAxisIterations', 'yAxisIterations', 'conditionFilter', 'header.label', 'disabled', 'readOnly'];
28
28
 
29
29
  // Utility type to replace all expression from an object into a translated version
30
30
 
@@ -387,8 +387,13 @@ var LunaticVariable = /*#__PURE__*/function () {
387
387
  var _this4 = this,
388
388
  _this$calculatedAt$ge;
389
389
  var dependenciesUpdatedAt = Math.max.apply(Math, [0].concat(_toConsumableArray(this.getDependencies().map(function (dep) {
390
- var _this4$dictionary$get, _this4$dictionary;
391
- return (_this4$dictionary$get = (_this4$dictionary = _this4.dictionary) === null || _this4$dictionary === void 0 || (_this4$dictionary = _this4$dictionary.get(dep)) === null || _this4$dictionary === void 0 ? void 0 : _this4$dictionary.updatedAt.get(iteration === null || iteration === void 0 ? void 0 : iteration.join('.'))) !== null && _this4$dictionary$get !== void 0 ? _this4$dictionary$get : 0;
390
+ var _ref2, _this4$dictionary$get, _this4$dictionary, _this4$dictionary2;
391
+ return (// Check when a value at the same iteration was calculated
392
+ (_ref2 = (_this4$dictionary$get = (_this4$dictionary = _this4.dictionary) === null || _this4$dictionary === void 0 || (_this4$dictionary = _this4$dictionary.get(dep)) === null || _this4$dictionary === void 0 ? void 0 : _this4$dictionary.updatedAt.get(iteration === null || iteration === void 0 ? void 0 : iteration.join('.'))) !== null && _this4$dictionary$get !== void 0 ? _this4$dictionary$get : // For aggregated value (max / min) look the global updatedAt time
393
+ (_this4$dictionary2 = _this4.dictionary) === null || _this4$dictionary2 === void 0 || (_this4$dictionary2 = _this4$dictionary2.get(dep)) === null || _this4$dictionary2 === void 0 ? void 0 : _this4$dictionary2.updatedAt.get(undefined)) !== null && _ref2 !== void 0 ? _ref2 :
394
+ // Otherwise this is a static value that never changes
395
+ 0
396
+ );
392
397
  }))));
393
398
  return dependenciesUpdatedAt > ((_this$calculatedAt$ge = this.calculatedAt.get(iteration === null || iteration === void 0 ? void 0 : iteration.join('.'))) !== null && _this$calculatedAt$ge !== void 0 ? _this$calculatedAt$ge : -1);
394
399
  }
@@ -199,6 +199,19 @@ var _lunaticVariablesStore = require("./lunatic-variables-store");
199
199
  });
200
200
  (0, _vitest.expect)(variables.get('FULLNAME')).toEqual(['John 1', 'Jane 2']);
201
201
  });
202
+ (0, _vitest.it)('should handle aggregate functions', function () {
203
+ variables.set('AGE', [1, 2, 3]);
204
+ variables.setCalculated('MAXAGE', 'max(AGE)');
205
+ variables.setCalculated('AGE_AND_MAX', 'AGE + MAXAGE', {
206
+ shapeFrom: 'AGE'
207
+ });
208
+ (0, _vitest.expect)(variables.get('AGE_AND_MAX', [0])).toEqual(4);
209
+ variables.set('AGE', 12, {
210
+ iteration: [1]
211
+ });
212
+ (0, _vitest.expect)(variables.get('AGE', [1])).toEqual(12);
213
+ (0, _vitest.expect)(variables.get('AGE_AND_MAX', [0])).toEqual(13);
214
+ });
202
215
  });
203
216
  (0, _vitest.describe)('resizing', function () {
204
217
  (0, _vitest.it)('should resize variables', function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "2.7.12",
3
+ "version": "2.7.13",
4
4
  "workersVersion": "0.3.0",
5
5
  "description": "Library of questionnaire components",
6
6
  "repository": {