@inseefr/lunatic 2.7.3 → 2.7.4

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.
@@ -34,9 +34,6 @@ var LabelRenderer = function LabelRenderer(_ref) {
34
34
  });
35
35
  };
36
36
  var Template = function Template(args) {
37
- console.log({
38
- args: args
39
- });
40
37
  var _useState = (0, _react.useState)(args.value),
41
38
  _useState2 = _slicedToArray(_useState, 2),
42
39
  localValue = _useState2[0],
@@ -23,7 +23,7 @@ function DatepickerField(_ref) {
23
23
  onChange(e.target.valueAsNumber);
24
24
  };
25
25
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
26
- className: (0, _classnames["default"])('lunaticDatepickerField', !max && 'lunaticDatepickerFieldLarge'),
26
+ className: (0, _classnames["default"])('lunaticDatepickerField', (!max || max > 999) && 'lunaticDatepickerFieldLarge'),
27
27
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
28
28
  htmlFor: id,
29
29
  children: [label, /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
@@ -65,6 +65,7 @@ exports[`Datepicker > should render properly with format YYYY 1`] = `
65
65
  </label>
66
66
  <input
67
67
  id="datepickeryear"
68
+ max="9999"
68
69
  min="1"
69
70
  type="number"
70
71
  value="1999"
@@ -140,6 +141,7 @@ exports[`Datepicker > should render properly with format YYYY-MM 1`] = `
140
141
  </label>
141
142
  <input
142
143
  id="datepickeryear"
144
+ max="9999"
143
145
  min="1"
144
146
  type="number"
145
147
  value="1999"
@@ -215,6 +217,7 @@ exports[`Datepicker > should render properly with format YYYY-MM-DD 1`] = `
215
217
  </label>
216
218
  <input
217
219
  id="datepickeryear"
220
+ max="9999"
218
221
  min="1"
219
222
  type="number"
220
223
  value="1999"
@@ -30,16 +30,16 @@ function Datepicker(_ref) {
30
30
  readOnly = _ref.readOnly,
31
31
  _ref$value = _ref.value,
32
32
  value = _ref$value === void 0 ? '' : _ref$value,
33
- _ref$format = _ref.format,
34
- format = _ref$format === void 0 ? 'YYYY-MM-DD' : _ref$format,
33
+ _ref$dateFormat = _ref.dateFormat,
34
+ dateFormat = _ref$dateFormat === void 0 ? 'YYYY-MM-DD' : _ref$dateFormat,
35
35
  onChange = _ref.onChange,
36
36
  id = _ref.id,
37
37
  label = _ref.label,
38
38
  errors = _ref.errors,
39
39
  description = _ref.description;
40
40
  var labelId = "lunatic-datepicker-".concat(id);
41
- var showDay = format.includes('DD');
42
- var showMonth = format.includes('MM');
41
+ var showDay = dateFormat.includes('DD');
42
+ var showMonth = dateFormat.includes('MM');
43
43
 
44
44
  // Raw state, we allow invalid dates to be typed
45
45
  var _useState = (0, _react.useState)(function () {
@@ -57,7 +57,7 @@ function Datepicker(_ref) {
57
57
  };
58
58
  };
59
59
  var handleChange = function handleChange(numbers) {
60
- var formatParts = format.split('-');
60
+ var formatParts = dateFormat.split('-');
61
61
  var hasNaNIndex = numbers.findIndex(function (v) {
62
62
  return Number.isNaN(v);
63
63
  });
@@ -69,7 +69,7 @@ function Datepicker(_ref) {
69
69
  }
70
70
 
71
71
  // Date is not valid
72
- if (format === 'YYYY-MM-DD' && !isDateValid(numbers)) {
72
+ if (dateFormat === 'YYYY-MM-DD' && !isDateValid(numbers)) {
73
73
  onChange(null);
74
74
  return;
75
75
  }
@@ -110,6 +110,7 @@ function Datepicker(_ref) {
110
110
  label: "Ann\xE9e",
111
111
  description: "Exemple: 2023",
112
112
  value: numbers[0],
113
+ max: 9999,
113
114
  onChange: setNumber(0)
114
115
  }, extraProps))]
115
116
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
@@ -49,7 +49,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
49
49
  });
50
50
  (0, _vitest.it)('handle change correctly for format YYYY-MM', function () {
51
51
  (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_datepicker["default"], {
52
- format: "YYYY-MM",
52
+ dateFormat: "YYYY-MM",
53
53
  value: "1999-01",
54
54
  id: "datepicker",
55
55
  "aria-labelledby": "datepicker",
@@ -70,7 +70,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
70
70
  });
71
71
  (0, _vitest.it)('handle change correctly for year YYYY', function () {
72
72
  (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_datepicker["default"], {
73
- format: "YYYY",
73
+ dateFormat: "YYYY",
74
74
  value: "1999",
75
75
  id: "datepicker",
76
76
  "aria-labelledby": "datepicker",
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _datepicker = _interopRequireDefault(require("./html/datepicker"));
8
7
  var _commons = require("../commons");
8
+ var _errors = require("../commons/components/errors/errors");
9
9
  var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../commons/components/lunatic-component-without-label"));
10
10
  var _useOnHandleChange = _interopRequireDefault(require("../commons/use-on-handle-change"));
11
- var _errors = require("../commons/components/errors/errors");
11
+ var _datepicker = _interopRequireDefault(require("./html/datepicker"));
12
12
  var _jsxRuntime = require("react/jsx-runtime");
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
14
  var LunaticDatepicker = function LunaticDatepicker(props) {
@@ -28,7 +28,7 @@ var LunaticDatepicker = function LunaticDatepicker(props) {
28
28
  missing = props.missing,
29
29
  missingResponse = props.missingResponse,
30
30
  management = props.management,
31
- format = props.format;
31
+ dateFormat = props.dateFormat;
32
32
  var onChange = (0, _useOnHandleChange["default"])({
33
33
  handleChange: handleChange,
34
34
  response: response,
@@ -45,7 +45,7 @@ var LunaticDatepicker = function LunaticDatepicker(props) {
45
45
  description: description,
46
46
  handleChange: handleChange,
47
47
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_datepicker["default"], {
48
- format: format,
48
+ dateFormat: dateFormat,
49
49
  disabled: disabled,
50
50
  readOnly: readOnly,
51
51
  value: value !== null && value !== void 0 ? value : '',
@@ -12,7 +12,7 @@ type Props = {
12
12
  id?: string;
13
13
  value?: string;
14
14
  onChange: (s: string | null) => void;
15
- format?: string;
15
+ dateFormat?: string;
16
16
  };
17
17
  declare const _default: import("react").ComponentType<Props>;
18
18
  export default _default;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  declare const _default: import("react").ComponentType<import("../type").LunaticBaseProps<string | null> & {
3
- format: "YYYY-MM-DD" | "YYYY-MM" | "YYYY";
3
+ dateFormat: "YYYY-MM-DD" | "YYYY-MM" | "YYYY";
4
4
  min?: string | undefined;
5
5
  max?: string | undefined;
6
6
  response: {
@@ -129,7 +129,7 @@ type ComponentPropsByType = {
129
129
  iteration: LunaticState['pager']['iteration'];
130
130
  };
131
131
  Datepicker: LunaticBaseProps<string | null> & {
132
- format: 'YYYY-MM-DD' | 'YYYY-MM' | 'YYYY';
132
+ dateFormat: 'YYYY-MM-DD' | 'YYYY-MM' | 'YYYY';
133
133
  min?: string;
134
134
  max?: string;
135
135
  response: {
@@ -111,7 +111,7 @@ declare function useLunatic(source: LunaticSource, data: LunaticData | undefined
111
111
  iteration: number | undefined;
112
112
  };
113
113
  Datepicker: import("../components/type").LunaticBaseProps<string | null> & {
114
- format: "YYYY-MM-DD" | "YYYY-MM" | "YYYY";
114
+ dateFormat: "YYYY-MM-DD" | "YYYY-MM" | "YYYY";
115
115
  min?: string | undefined;
116
116
  max?: string | undefined;
117
117
  response: {
@@ -356,7 +356,7 @@ declare function useLunatic(source: LunaticSource, data: LunaticData | undefined
356
356
  iteration: number | undefined;
357
357
  };
358
358
  Datepicker: import("../components/type").LunaticBaseProps<string | null> & {
359
- format: "YYYY-MM-DD" | "YYYY-MM" | "YYYY";
359
+ dateFormat: "YYYY-MM-DD" | "YYYY-MM" | "YYYY";
360
360
  min?: string | undefined;
361
361
  max?: string | undefined;
362
362
  response: {
@@ -4,15 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = exports.Basic = void 0;
7
- var _datepicker = _interopRequireDefault(require("../../components/datepicker"));
8
7
  var _addonActions = require("@storybook/addon-actions");
8
+ var _datepicker = _interopRequireDefault(require("../../components/datepicker"));
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
10
  var _default = exports["default"] = {
11
11
  title: 'Components/Datepicker',
12
12
  component: _datepicker["default"],
13
13
  args: {
14
14
  value: '1920-02-01',
15
- format: 'YYYY-MM-DD',
15
+ dateFormat: 'YYYY-MM-DD',
16
16
  handleChange: (0, _addonActions.action)('handleChange'),
17
17
  response: {
18
18
  name: 'date'
@@ -20,11 +20,11 @@ var _default = exports["default"] = {
20
20
  },
21
21
  parameters: {
22
22
  controls: {
23
- include: ['format', 'readOnly', 'disabled']
23
+ include: ['dateFormat', 'readOnly', 'disabled']
24
24
  }
25
25
  },
26
26
  argTypes: {
27
- format: {
27
+ dateFormat: {
28
28
  control: 'radio',
29
29
  options: ['YYYY-MM-DD', 'YYYY-MM', 'YYYY']
30
30
  },
@@ -319,12 +319,18 @@ var LunaticVariable = /*#__PURE__*/function () {
319
319
  var _this2 = this;
320
320
  try {
321
321
  return Object.fromEntries(this.getDependencies().map(function (dep) {
322
- var _this2$dictionary;
322
+ var _this2$dictionary, _this2$dictionary$get;
323
323
  if (dep === iterationVariableName && iteration) {
324
324
  return [dep, iteration[0]];
325
325
  }
326
326
  var dependencyIteration = (0, _number.isNumber)(_this2.iterationDepth) && Array.isArray(iteration) ? [iteration[_this2.iterationDepth]] : iteration;
327
- return [dep, (_this2$dictionary = _this2.dictionary) === null || _this2$dictionary === void 0 || (_this2$dictionary = _this2$dictionary.get(dep)) === null || _this2$dictionary === void 0 ? void 0 : _this2$dictionary.getValue(dependencyIteration)];
327
+
328
+ // The variable is not registered in the variable dictionary
329
+ // Happens when calculating unquoted VTL expression
330
+ if (!_this2.dictionary || !((_this2$dictionary = _this2.dictionary) !== null && _this2$dictionary !== void 0 && _this2$dictionary.has(dep))) {
331
+ throw new Error("Unknown variable \"".concat(dep, "\" in expression ").concat(_this2.expression));
332
+ }
333
+ return [dep, (_this2$dictionary$get = _this2.dictionary.get(dep)) === null || _this2$dictionary$get === void 0 ? void 0 : _this2$dictionary$get.getValue(dependencyIteration)];
328
334
  }));
329
335
  } catch (e) {
330
336
  if (e instanceof RangeError) {
@@ -81,6 +81,11 @@ var _missingBehaviour = require("./behaviours/missing-behaviour");
81
81
  variables.set('FIRSTNAME', 'Jane');
82
82
  (0, _vitest.expect)(variables.run('FIRSTNAME || " " || LASTNAME')).toEqual('Jane Doe');
83
83
  });
84
+ (0, _vitest.it)('should throw an exception when calculated incorrect VTL', function () {
85
+ (0, _vitest.expect)(function () {
86
+ return variables.run('Hello world');
87
+ }).toThrowError();
88
+ });
84
89
  (0, _vitest.describe)('with iteration', function () {
85
90
  (0, _vitest.it)('should handle arrays', function () {
86
91
  variables.set('FIRSTNAME', ['John', 'Jane']);
@@ -112,7 +112,7 @@ function reduceOnInit(state, action) {
112
112
  return result;
113
113
  } catch (e) {
114
114
  // If there is an error interpreting a variable, return the raw expression
115
- console.error("Cannot interpret expression : ".concat(expressionString));
115
+ console.error("Cannot interpret expression : ".concat(expressionString), e);
116
116
  return expressionString;
117
117
  }
118
118
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "2.7.3",
3
+ "version": "2.7.4",
4
4
  "workersVersion": "0.3.0",
5
5
  "description": "Library of questionnaire components",
6
6
  "repository": {