@inseefr/lunatic 2.6.2 → 2.6.3

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 (129) hide show
  1. package/README.md +49 -3
  2. package/lib/components/checkbox/checkbox-boolean/html/checkbox-boolean.js +3 -3
  3. package/lib/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.js +7 -1
  4. package/lib/components/checkbox/checkbox-group/checkbox-group-content.js +0 -2
  5. package/lib/components/checkbox/checkbox-group/html/checkbox-group-content.js +4 -2
  6. package/lib/components/checkbox/checkbox-group/html/checkbox-group.js +3 -3
  7. package/lib/components/checkbox/checkbox-group/lunatic-checkbox-group.js +2 -1
  8. package/lib/components/checkbox/checkbox-one/lunatic-checkbox-one.js +2 -1
  9. package/lib/components/checkbox/commons/checkbox-option.js +3 -1
  10. package/lib/components/commons/components/combo-box/combo-box-container.js +1 -2
  11. package/lib/components/commons/components/combo-box/combo-box.js +2 -2
  12. package/lib/components/commons/components/combo-box/selection/LabelOrInput.js +3 -1
  13. package/lib/components/commons/components/combo-box/selection/input.js +3 -1
  14. package/lib/components/commons/components/combo-box/selection/selection.js +3 -1
  15. package/lib/components/commons/components/errors/errors.js +12 -10
  16. package/lib/components/commons/components/errors/errors.spec.js +6 -6
  17. package/lib/components/component-set/html/__snapshots__/component-set.spec.tsx.snap +2 -0
  18. package/lib/components/component-set/html/component-set.js +2 -2
  19. package/lib/components/datepicker/html/__snapshots__/datepicker.spec.tsx.snap +2 -0
  20. package/lib/components/datepicker/html/datepicker-input.js +4 -2
  21. package/lib/components/datepicker/html/datepicker.js +3 -3
  22. package/lib/components/datepicker/lunatic-datepicker.js +2 -1
  23. package/lib/components/dropdown/lunatic-dropdown.js +2 -1
  24. package/lib/components/input/html/__snapshots__/input.spec.tsx.snap +2 -0
  25. package/lib/components/input/html/input.js +3 -3
  26. package/lib/components/input/lunatic-input.js +2 -1
  27. package/lib/components/input-number/html/__snapshots__/input-number.spec.tsx.snap +2 -2
  28. package/lib/components/input-number/html/input-number-thousand.js +4 -17
  29. package/lib/components/input-number/html/input-number.js +3 -5
  30. package/lib/components/input-number/lunatic-input-number.js +2 -3
  31. package/lib/components/lunatic-components.js +2 -11
  32. package/lib/components/radio/html/radio-group-content.js +4 -2
  33. package/lib/components/radio/html/radio-group.js +3 -3
  34. package/lib/components/radio/html/radio-option.js +3 -1
  35. package/lib/components/radio/lunatic-radio-group.js +2 -1
  36. package/lib/components/suggester/find-best-label/find-best-label.js +6 -6
  37. package/lib/components/suggester/idb-suggester/idb-suggester.js +4 -3
  38. package/lib/components/suggester/lunatic-suggester.js +7 -4
  39. package/lib/components/suggester/searching/create-searching.js +20 -39
  40. package/lib/components/switch/html/switch.js +2 -2
  41. package/lib/components/switch/lunatic-switch.js +2 -1
  42. package/lib/components/table/lunatic-table.js +2 -2
  43. package/lib/components/textarea/html/__snapshots__/textarea.spec.tsx.snap +2 -0
  44. package/lib/components/textarea/html/textarea.js +6 -4
  45. package/lib/components/textarea/lunatic-textarea.js +6 -3
  46. package/lib/hooks/use-auto-focus.js +26 -0
  47. package/lib/src/components/checkbox/checkbox-boolean/html/checkbox-boolean.d.ts +1 -1
  48. package/lib/src/components/checkbox/checkbox-group/html/checkbox-group-content.d.ts +2 -1
  49. package/lib/src/components/checkbox/checkbox-group/html/checkbox-group.d.ts +1 -1
  50. package/lib/src/components/checkbox/commons/checkbox-option.d.ts +1 -0
  51. package/lib/src/components/commons/components/combo-box/combo-box-container.d.ts +2 -2
  52. package/lib/src/components/commons/components/combo-box/combo-box.d.ts +2 -2
  53. package/lib/src/components/commons/components/combo-box/combo-box.stories.d.ts +4 -6
  54. package/lib/src/components/commons/components/combo-box/selection/LabelOrInput.d.ts +1 -0
  55. package/lib/src/components/commons/components/combo-box/selection/input.d.ts +1 -0
  56. package/lib/src/components/commons/components/combo-box/selection/selection.d.ts +2 -1
  57. package/lib/src/components/commons/components/errors/errors.d.ts +6 -3
  58. package/lib/src/components/datepicker/html/datepicker-input.d.ts +2 -1
  59. package/lib/src/components/datepicker/html/datepicker.d.ts +1 -1
  60. package/lib/src/components/dropdown/html/dropdown-writable/dropdown-writable.d.ts +1 -1
  61. package/lib/src/components/dropdown/html/dropdown.d.ts +3 -1
  62. package/lib/src/components/input/html/input.d.ts +2 -2
  63. package/lib/src/components/input-number/html/input-number-thousand.d.ts +2 -2
  64. package/lib/src/components/input-number/html/input-number.d.ts +2 -3
  65. package/lib/src/components/radio/html/radio-group-content.d.ts +2 -1
  66. package/lib/src/components/radio/html/radio-group.d.ts +1 -1
  67. package/lib/src/components/radio/html/radio-option.d.ts +1 -0
  68. package/lib/src/components/suggester/find-best-label/find-best-label.d.ts +1 -1
  69. package/lib/src/components/suggester/html/suggester.d.ts +1 -1
  70. package/lib/src/components/suggester/idb-suggester/idb-suggester.d.ts +5 -2
  71. package/lib/src/components/suggester/lunatic-suggester.d.ts +1 -1
  72. package/lib/src/components/suggester/searching/create-searching.d.ts +1 -1
  73. package/lib/src/components/switch/html/switch.d.ts +1 -1
  74. package/lib/src/components/textarea/html/textarea.d.ts +3 -2
  75. package/lib/src/components/type.d.ts +4 -3
  76. package/lib/src/hooks/use-auto-focus.d.ts +6 -0
  77. package/lib/src/use-lunatic/actions.d.ts +3 -0
  78. package/lib/src/use-lunatic/commons/fill-components/fill-component-required.d.ts +418 -0
  79. package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +20 -0
  80. package/lib/src/use-lunatic/reducer/overview/overview-on-init.d.ts +1 -0
  81. package/lib/src/use-lunatic/type.d.ts +2 -1
  82. package/lib/src/use-lunatic/use-lunatic.d.ts +8 -5
  83. package/lib/src/use-lunatic/use-suggesters.d.ts +2 -1
  84. package/lib/src/utils/suggester-workers/append-to-index/create-append-task.d.ts +1 -1
  85. package/lib/src/utils/suggester-workers/worker-path.d.ts +6 -0
  86. package/lib/stories/behaviour/cleaning/source.json +151 -0
  87. package/lib/stories/behaviour/cleaning/test.stories.js +84 -0
  88. package/lib/stories/{questionnaires-test → behaviour}/controls/controls.stories.js +5 -5
  89. package/lib/stories/{questionnaires-test → behaviour/others}/test.stories.js +7 -7
  90. package/lib/stories/{paste-questionnaire → behaviour/paste}/test.stories.js +3 -3
  91. package/lib/stories/{resizing-questionnaire → behaviour/resizing}/test.stories.js +3 -3
  92. package/lib/use-lunatic/commons/fill-components/fill-component-required.js +23 -0
  93. package/lib/use-lunatic/commons/fill-components/fill-components.js +2 -1
  94. package/lib/use-lunatic/commons/fill-components/fill-from-state.js +2 -0
  95. package/lib/use-lunatic/initial-state.js +2 -1
  96. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.js +7 -1
  97. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-resizing.js +12 -3
  98. package/lib/use-lunatic/reducer/reduce-on-init.js +4 -2
  99. package/lib/use-lunatic/use-lunatic.js +19 -8
  100. package/lib/use-lunatic/use-lunatic.test.js +34 -2
  101. package/lib/use-lunatic/use-suggesters.js +4 -3
  102. package/lib/utils/suggester-workers/append-to-index/create-append-task.js +4 -3
  103. package/lib/utils/suggester-workers/worker-path.js +29 -0
  104. package/package.json +15 -10
  105. package/scripts/build/add-workers-to-public.js +44 -0
  106. package/scripts/build/workers-paths.js +44 -0
  107. package/workers-release/lunatic-append-worker-0.3.0-experimental.js +2 -0
  108. package/workers-release/lunatic-append-worker-0.3.0-experimental.js.LICENSE.txt +34 -0
  109. package/workers-release/lunatic-label-worker-0.3.0-experimental.js +2 -0
  110. package/workers-release/lunatic-label-worker-0.3.0-experimental.js.LICENSE.txt +13 -0
  111. package/workers-release/lunatic-searching-worker-0.3.0-experimental.js +2 -0
  112. package/workers-release/lunatic-searching-worker-0.3.0-experimental.js.LICENSE.txt +34 -0
  113. package/lib/src/utils/store-tools/worker-path.d.ts +0 -1
  114. package/lib/utils/store-tools/worker-path.js +0 -13
  115. package/lib/utils/suggester-workers/create-worker.js +0 -55
  116. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNonNum_horsBoucle_PasPageFin.json +0 -0
  117. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNum_horsBoucle_PasPageFin.json +0 -0
  118. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees2_PasPageFin.json +0 -0
  119. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees_PasPageFin.json +0 -0
  120. /package/lib/stories/{questionnaires-test → behaviour}/controls/boucles-n.json +0 -0
  121. /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.json +0 -0
  122. /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.stories.js +0 -0
  123. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_DeclarationsSimples.json +0 -0
  124. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_MinMaxSum_Boucles.json +0 -0
  125. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_QuestSimple_Boucles.json +0 -0
  126. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_TCMRallyeGames.json +0 -0
  127. /package/lib/stories/{questionnaires-test → behaviour/others}/test-dylan.json +0 -0
  128. /package/lib/stories/{paste-questionnaire → behaviour/paste}/source.json +0 -0
  129. /package/lib/stories/{resizing-questionnaire → behaviour/resizing}/source.json +0 -0
@@ -10,12 +10,6 @@ var _reactNumberFormat = require("react-number-format");
10
10
  var _i18n = require("../../../i18n");
11
11
  var _jsxRuntime = require("react/jsx-runtime");
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
14
- 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."); }
15
- 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); }
16
- 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; }
17
- 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; } }
18
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
13
  var InputNumberThousand = function InputNumberThousand(_ref) {
20
14
  var id = _ref.id,
21
15
  onChange = _ref.onChange,
@@ -24,14 +18,9 @@ var InputNumberThousand = function InputNumberThousand(_ref) {
24
18
  readOnly = _ref.readOnly,
25
19
  required = _ref.required,
26
20
  labelId = _ref.labelId,
27
- min = _ref.min,
28
21
  max = _ref.max,
29
- decimals = _ref.decimals;
30
- // Decimals is a number indicates the number behind the separator of decimals
31
- // Computing step attribute of input according to decimal number
32
- var _useState = (0, _react.useState)(decimals ? 1 / Math.pow(10, decimals) : 1),
33
- _useState2 = _slicedToArray(_useState, 1),
34
- step = _useState2[0];
22
+ decimals = _ref.decimals,
23
+ invalid = _ref.invalid;
35
24
  var handleChange = (0, _react.useCallback)(function (e) {
36
25
  var _e$floatValue;
37
26
  var val = (_e$floatValue = e.floatValue) !== null && _e$floatValue !== void 0 ? _e$floatValue : null;
@@ -49,9 +38,6 @@ var InputNumberThousand = function InputNumberThousand(_ref) {
49
38
  }),
50
39
  onValueChange: handleChange,
51
40
  value: value !== null && value !== void 0 ? value : '',
52
- min: min,
53
- max: max,
54
- step: step,
55
41
  "aria-labelledby": labelId,
56
42
  disabled: disabled,
57
43
  readOnly: readOnly,
@@ -63,7 +49,8 @@ var InputNumberThousand = function InputNumberThousand(_ref) {
63
49
  decimalScale: decimals,
64
50
  allowLeadingZeros: true,
65
51
  thousandSeparator: _i18n.inputNumberPropsI18N.thousandSeparator,
66
- inputMode: decimals ? 'decimal' : 'numeric'
52
+ inputMode: decimals ? 'decimal' : 'numeric',
53
+ "aria-invalid": invalid
67
54
  });
68
55
  };
69
56
  var _default = InputNumberThousand;
@@ -20,7 +20,6 @@ function InputNumber(_ref) {
20
20
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
21
21
  _ref$readOnly = _ref.readOnly,
22
22
  readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
23
- min = _ref.min,
24
23
  max = _ref.max,
25
24
  _ref$decimals = _ref.decimals,
26
25
  decimals = _ref$decimals === void 0 ? 0 : _ref$decimals,
@@ -46,14 +45,13 @@ function InputNumber(_ref) {
46
45
  readOnly: readOnly,
47
46
  required: required,
48
47
  labelId: labelId,
49
- min: min,
50
48
  max: max,
51
- decimals: decimals
49
+ decimals: decimals,
50
+ invalid: !!errors
52
51
  }), unit && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
53
52
  children: unit
54
53
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
55
- errors: errors,
56
- activeId: id
54
+ errors: errors
57
55
  })]
58
56
  });
59
57
  }
@@ -7,6 +7,7 @@ exports["default"] = void 0;
7
7
  var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../commons/components/lunatic-component-without-label"));
8
8
  var _useOnHandleChange = _interopRequireDefault(require("../commons/use-on-handle-change"));
9
9
  var _inputNumber = _interopRequireDefault(require("./html/input-number"));
10
+ var _errors = require("../commons/components/errors/errors");
10
11
  var _jsxRuntime = require("react/jsx-runtime");
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
13
  function LunaticInputNumber(props) {
@@ -22,7 +23,6 @@ function LunaticInputNumber(props) {
22
23
  missing = props.missing,
23
24
  missingResponse = props.missingResponse,
24
25
  management = props.management,
25
- min = props.min,
26
26
  max = props.max,
27
27
  decimals = props.decimals,
28
28
  unit = props.unit,
@@ -51,12 +51,11 @@ function LunaticInputNumber(props) {
51
51
  label: label,
52
52
  disabled: disabled,
53
53
  readOnly: readOnly,
54
- min: min,
55
54
  max: max,
56
55
  decimals: decimals,
57
56
  unit: unit,
58
57
  required: required,
59
- errors: errors
58
+ errors: (0, _errors.getComponentErrors)(errors, id)
60
59
  })
61
60
  });
62
61
  }
@@ -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 _useAutoFocus = require("../hooks/use-auto-focus");
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; }
@@ -32,18 +33,8 @@ function LunaticComponents(_ref) {
32
33
  } : _ref$wrapper;
33
34
  var wrapperRef = (0, _react.useRef)(null);
34
35
  var hasComponents = components.length > 0;
35
- (0, _react.useEffect)(function () {
36
- var _wrapperRef$current;
37
- if (!autoFocusKey || !hasComponents || !wrapperRef.current) {
38
- return;
39
- }
40
- var firstFocusableElement = (_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
41
- // The first element can be focusable
42
- if (firstFocusableElement) {
43
- return firstFocusableElement.focus();
44
- }
45
- }, [autoFocusKey, hasComponents]);
46
36
  var WrapperComponent = autoFocusKey ? 'div' : _react.Fragment;
37
+ (0, _useAutoFocus.useAutoFocus)(wrapperRef, hasComponents ? autoFocusKey : undefined);
47
38
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(WrapperComponent, {
48
39
  ref: WrapperComponent === _react.Fragment ? undefined : wrapperRef,
49
40
  children: components.map(function (component, k) {
@@ -20,7 +20,8 @@ function RadioGroupContent(_ref) {
20
20
  checkboxStyle = _ref$checkboxStyle === void 0 ? false : _ref$checkboxStyle,
21
21
  shortcut = _ref.shortcut,
22
22
  disabled = _ref.disabled,
23
- readOnly = _ref.readOnly;
23
+ readOnly = _ref.readOnly,
24
+ invalid = _ref.invalid;
24
25
  var onKeyDown = (0, _commons.useOptionsKeydown)(options, onClick);
25
26
  var maxIndex = options.length;
26
27
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
@@ -43,7 +44,8 @@ function RadioGroupContent(_ref) {
43
44
  codeModality: shortcut ? codeModality : undefined,
44
45
  shortcut: shortcut,
45
46
  disabled: disabled,
46
- readOnly: readOnly
47
+ readOnly: readOnly,
48
+ invalid: invalid
47
49
  }, radioId);
48
50
  })
49
51
  });
@@ -35,10 +35,10 @@ function RadioGroup(_ref) {
35
35
  options: options,
36
36
  shortcut: shortcut,
37
37
  disabled: disabled,
38
- readOnly: readOnly
38
+ readOnly: readOnly,
39
+ invalid: !!errors
39
40
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
40
- errors: errors,
41
- activeId: id
41
+ errors: errors
42
42
  })]
43
43
  });
44
44
  }
@@ -30,7 +30,8 @@ function RadioOption(_ref) {
30
30
  description = _ref.description,
31
31
  shortcut = _ref.shortcut,
32
32
  codeModality = _ref.codeModality,
33
- readOnly = _ref.readOnly;
33
+ readOnly = _ref.readOnly,
34
+ invalid = _ref.invalid;
34
35
  var spanEl = (0, _react.useRef)(null);
35
36
  var Icon = getIcon(checked, checkboxStyle);
36
37
  var tabIndex = checked ? 0 : -1;
@@ -75,6 +76,7 @@ function RadioOption(_ref) {
75
76
  onKeyDown: handleKeyDown,
76
77
  "aria-labelledby": labelledBy,
77
78
  ref: spanEl,
79
+ "aria-invalid": invalid,
78
80
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, {}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_commons.Label, {
79
81
  id: labelledBy,
80
82
  htmlFor: id,
@@ -8,6 +8,7 @@ var _radioGroup = _interopRequireDefault(require("./html/radio-group"));
8
8
  var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../commons/components/lunatic-component-without-label"));
9
9
  var _useOnHandleChange = _interopRequireDefault(require("../commons/use-on-handle-change"));
10
10
  var _commons = require("../commons");
11
+ var _errors = require("../commons/components/errors/errors");
11
12
  var _jsxRuntime = require("react/jsx-runtime");
12
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
14
  function LunaticRadioGroup(props) {
@@ -52,7 +53,7 @@ function LunaticRadioGroup(props) {
52
53
  value: value,
53
54
  onSelect: onChange,
54
55
  checkboxStyle: checkboxStyle,
55
- errors: errors,
56
+ errors: (0, _errors.getComponentErrors)(errors, id),
56
57
  label: label,
57
58
  className: className,
58
59
  shortcut: shortcut,
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _createWorker = require("../../../utils/suggester-workers/create-worker");
7
+ var _createWorkerTs = require("../../../utils/suggester-workers/create-worker-ts");
8
+ var _workerPath = require("../../../utils/suggester-workers/worker-path");
8
9
  // @ts-ignore
9
10
 
10
- var WORKER_PATH = process.env.LUNATIC_LABEL_WORKER_PATH || process.env.REACT_APP_LUNATIC_LABEL_WORKER_PATH || '';
11
11
  var WORKER;
12
12
  var TASKS = new Map();
13
13
  function getIdTask() {
@@ -17,9 +17,9 @@ function getIdTask() {
17
17
  }
18
18
  return id;
19
19
  }
20
- function getWorker() {
20
+ function getWorker(workersBasePath) {
21
21
  if (!WORKER) {
22
- WORKER = (0, _createWorker.createWorker)(WORKER_PATH);
22
+ WORKER = (0, _createWorkerTs.createWorker)((0, _workerPath.getWorkerPath)(_workerPath.WorkerEnum.LABEL, workersBasePath));
23
23
  WORKER.addEventListener('message', function (e) {
24
24
  var data = e.data;
25
25
  var response = data.response,
@@ -31,10 +31,10 @@ function getWorker() {
31
31
  }
32
32
  return WORKER;
33
33
  }
34
- function findBestLabel(option, search) {
34
+ function findBestLabel(option, search, workersBasePath) {
35
35
  return new Promise(function (resolve) {
36
36
  var idTask = getIdTask();
37
- var worker = getWorker();
37
+ var worker = getWorker(workersBasePath);
38
38
  TASKS.set(idTask, function (response) {
39
39
  resolve(response);
40
40
  TASKS["delete"](idTask);
@@ -32,17 +32,18 @@ function IDBSuggester(_ref) {
32
32
  description = _ref.description,
33
33
  getSuggesterStatus = _ref.getSuggesterStatus,
34
34
  errors = _ref.errors,
35
- readOnly = _ref.readOnly;
35
+ readOnly = _ref.readOnly,
36
+ workersBasePath = _ref.workersBasePath;
36
37
  var _useState = (0, _react.useState)(undefined),
37
38
  _useState2 = _slicedToArray(_useState, 2),
38
39
  store = _useState2[0],
39
40
  setStore = _useState2[1];
40
41
  var searching = (0, _react.useMemo)(function () {
41
42
  if (store) {
42
- return (0, _searching["default"])(storeName, idbVersion);
43
+ return (0, _searching["default"])(storeName, idbVersion, workersBasePath);
43
44
  }
44
45
  return undefined;
45
- }, [storeName, idbVersion, store]);
46
+ }, [storeName, idbVersion, store, workersBasePath]);
46
47
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_suggesterStatus.SuggesterStatus, {
47
48
  storeName: storeName,
48
49
  getSuggesterStatus: getSuggesterStatus,
@@ -4,9 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _idbSuggester = require("./idb-suggester");
7
+ var _errors = require("../commons/components/errors/errors");
8
8
  var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../commons/components/lunatic-component-without-label"));
9
9
  var _useOnHandleChange = _interopRequireDefault(require("../commons/use-on-handle-change"));
10
+ var _idbSuggester = require("./idb-suggester");
10
11
  var _jsxRuntime = require("react/jsx-runtime");
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
13
  function LunaticSuggester(_ref) {
@@ -30,7 +31,8 @@ function LunaticSuggester(_ref) {
30
31
  management = _ref.management,
31
32
  response = _ref.response,
32
33
  className = _ref.className,
33
- getSuggesterStatus = _ref.getSuggesterStatus;
34
+ getSuggesterStatus = _ref.getSuggesterStatus,
35
+ workersBasePath = _ref.workersBasePath;
34
36
  var onChange = (0, _useOnHandleChange["default"])({
35
37
  handleChange: handleChange,
36
38
  response: response,
@@ -55,11 +57,12 @@ function LunaticSuggester(_ref) {
55
57
  disabled: disabled,
56
58
  id: id,
57
59
  value: value,
58
- errors: errors,
60
+ errors: (0, _errors.getComponentErrors)(errors, id),
59
61
  label: label,
60
62
  getSuggesterStatus: getSuggesterStatus,
61
63
  className: className,
62
- readOnly: readOnly
64
+ readOnly: readOnly,
65
+ workersBasePath: workersBasePath
63
66
  })
64
67
  });
65
68
  }
@@ -6,56 +6,37 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports["default"] = void 0;
8
8
  exports.isWorkerCompatible = isWorkerCompatible;
9
- var _createWorker = require("../../../utils/suggester-workers/create-worker");
9
+ var _createWorkerTs = require("../../../utils/suggester-workers/create-worker-ts");
10
+ var _workerPath = require("../../../utils/suggester-workers/worker-path");
10
11
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
11
12
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
12
13
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } // @ts-ignore
13
- var WORKER_PATH = process.env.LUNATIC_SEARCH_WORKER_PATH || process.env.REACT_APP_LUNATIC_SEARCH_WORKER_PATH;
14
14
  function isWorkerCompatible() {
15
15
  return !!window.Worker;
16
16
  }
17
- var searching = function searching(worker) {
18
- return function (search, name, version) {
19
- if (!WORKER_PATH) {
20
- throw new Error("Worker path is required for suggester's searches.");
21
- }
22
- if (isWorkerCompatible()) {
23
- return new Promise(function (resolve) {
24
- try {
25
- if (worker) {
26
- worker.terminate();
27
- }
28
- worker = (0, _createWorker.createWorker)(WORKER_PATH);
29
- worker.postMessage({
30
- search: search,
31
- name: name,
32
- version: version
33
- });
34
- worker.addEventListener('message', function (e) {
35
- var _worker;
36
- var data = e.data;
37
- resolve(data);
38
- (_worker = worker) === null || _worker === void 0 ? void 0 : _worker.terminate();
39
- worker = undefined;
40
- });
41
- } catch (e) {
42
- //TODO
43
- }
44
- });
45
- }
46
- // TODO
47
- return Promise.reject('No worker found');
48
- };
49
- };
50
- function createSearching(name, version) {
51
- var worker = undefined;
52
- var searching_ = searching(worker);
17
+ function getWorker(resolve, workersBasePath) {
18
+ var WORKER = (0, _createWorkerTs.createWorker)((0, _workerPath.getWorkerPath)(_workerPath.WorkerEnum.SEARCH, workersBasePath));
19
+ WORKER.addEventListener('message', function (e) {
20
+ var data = e.data;
21
+ resolve(data);
22
+ WORKER === null || WORKER === void 0 ? void 0 : WORKER.terminate();
23
+ });
24
+ return WORKER;
25
+ }
26
+ function createSearching(name, version, workersBasePath) {
53
27
  return /*#__PURE__*/function () {
54
28
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(search) {
55
29
  return _regeneratorRuntime().wrap(function _callee$(_context) {
56
30
  while (1) switch (_context.prev = _context.next) {
57
31
  case 0:
58
- return _context.abrupt("return", searching_(search, name, version));
32
+ return _context.abrupt("return", new Promise(function (resolve) {
33
+ var worker = getWorker(resolve, workersBasePath);
34
+ worker.postMessage({
35
+ search: search,
36
+ name: name,
37
+ version: version
38
+ });
39
+ }));
59
40
  case 1:
60
41
  case "end":
61
42
  return _context.stop();
@@ -45,6 +45,7 @@ function Switch(_ref) {
45
45
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
46
46
  role: "switch",
47
47
  "aria-checked": checked,
48
+ "aria-invalid": !!errors,
48
49
  tabIndex: 0,
49
50
  className: (0, _classnames["default"])('lunatic-switch-container', {
50
51
  disabled: disabled,
@@ -63,8 +64,7 @@ function Switch(_ref) {
63
64
  children: labelTrue
64
65
  })]
65
66
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
66
- errors: errors,
67
- activeId: id
67
+ errors: errors
68
68
  })]
69
69
  });
70
70
  }
@@ -7,6 +7,7 @@ exports["default"] = void 0;
7
7
  var _switch = _interopRequireDefault(require("./html/switch"));
8
8
  var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../commons/components/lunatic-component-without-label"));
9
9
  var _useOnHandleChange = _interopRequireDefault(require("../commons/use-on-handle-change"));
10
+ var _errors = require("../commons/components/errors/errors");
10
11
  var _jsxRuntime = require("react/jsx-runtime");
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
13
  var defaultLabel = {
@@ -50,7 +51,7 @@ function LunaticSwitch(_ref) {
50
51
  onClick: onClick,
51
52
  statusLabel: statusLabel,
52
53
  label: label,
53
- errors: errors
54
+ errors: (0, _errors.getComponentErrors)(errors, id)
54
55
  })
55
56
  });
56
57
  }
@@ -9,6 +9,7 @@ var _header = _interopRequireDefault(require("./header"));
9
9
  var _lunaticComponentWithLabel = _interopRequireDefault(require("../commons/components/lunatic-component-with-label"));
10
10
  var _tableOrchestrator = _interopRequireDefault(require("./table-orchestrator"));
11
11
  var _commons = require("../commons");
12
+ var _errors = require("../commons/components/errors/errors");
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) {
@@ -51,8 +52,7 @@ function LunaticTable(props) {
51
52
  })
52
53
  })]
53
54
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
54
- errors: errors,
55
- activeId: id
55
+ errors: (0, _errors.getComponentErrors)(errors, id)
56
56
  })]
57
57
  });
58
58
  }
@@ -6,6 +6,7 @@ exports[`Textarea > renders without crashing 1`] = `
6
6
  class="lunatic-textarea"
7
7
  >
8
8
  <textarea
9
+ aria-invalid="false"
9
10
  id="input"
10
11
  >
11
12
  input
@@ -20,6 +21,7 @@ exports[`Textarea > should handle readOnly 1`] = `
20
21
  class="lunatic-textarea"
21
22
  >
22
23
  <textarea
24
+ aria-invalid="false"
23
25
  id="textarea"
24
26
  readonly=""
25
27
  >
@@ -19,7 +19,8 @@ function Textarea(_ref) {
19
19
  label = _ref.label,
20
20
  description = _ref.description,
21
21
  errors = _ref.errors,
22
- readOnly = _ref.readOnly;
22
+ readOnly = _ref.readOnly,
23
+ required = _ref.required;
23
24
  var labelId = "label-".concat(id);
24
25
  var handleChange = (0, _react.useCallback)(function (e) {
25
26
  onChange(e.target.value);
@@ -32,6 +33,7 @@ function Textarea(_ref) {
32
33
  description: description,
33
34
  children: label
34
35
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("textarea", {
36
+ required: required,
35
37
  id: id,
36
38
  rows: rows,
37
39
  maxLength: maxLength,
@@ -39,10 +41,10 @@ function Textarea(_ref) {
39
41
  onChange: handleChange,
40
42
  value: checkValue(value),
41
43
  placeholder: placeholder,
42
- readOnly: readOnly
44
+ readOnly: readOnly,
45
+ "aria-invalid": !!errors
43
46
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
44
- errors: errors,
45
- activeId: id
47
+ errors: errors
46
48
  })]
47
49
  });
48
50
  }
@@ -8,6 +8,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
8
8
  var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../commons/components/lunatic-component-without-label"));
9
9
  var _useOnHandleChange = _interopRequireDefault(require("../commons/use-on-handle-change"));
10
10
  var _textarea = _interopRequireDefault(require("./html/textarea"));
11
+ var _errors = require("../commons/components/errors/errors");
11
12
  var _jsxRuntime = require("react/jsx-runtime");
12
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
14
  var LunaticTextarea = function LunaticTextarea(props) {
@@ -27,7 +28,8 @@ var LunaticTextarea = function LunaticTextarea(props) {
27
28
  missing = props.missing,
28
29
  missingResponse = props.missingResponse,
29
30
  management = props.management,
30
- readOnly = props.readOnly;
31
+ readOnly = props.readOnly,
32
+ required = props.required;
31
33
  var onChange = (0, _useOnHandleChange["default"])({
32
34
  handleChange: handleChange,
33
35
  response: response,
@@ -52,8 +54,9 @@ var LunaticTextarea = function LunaticTextarea(props) {
52
54
  value: value,
53
55
  placeholder: placeHolder,
54
56
  label: label,
55
- errors: errors,
56
- readOnly: readOnly
57
+ errors: (0, _errors.getComponentErrors)(errors, id),
58
+ readOnly: readOnly,
59
+ required: required
57
60
  })
58
61
  });
59
62
  };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAutoFocus = useAutoFocus;
7
+ var _react = require("react");
8
+ /**
9
+ * Focus the first focusable element in the wrapper when the "key" changes and is defined
10
+ */
11
+ function useAutoFocus(wrapperRef, key) {
12
+ (0, _react.useEffect)(function () {
13
+ var _ref, _wrapperRef$current, _wrapperRef$current2;
14
+ if (!key || !wrapperRef.current) {
15
+ return;
16
+ }
17
+
18
+ // First look for invalid fields, then all fields
19
+ var firstFocusableElement = (_ref = (_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.querySelector('button[aria-invalid], [href][aria-invalid], input[aria-invalid], select[aria-invalid], textarea[aria-invalid], [tabindex][aria-invalid]:not([tabindex="-1"])')) !== null && _ref !== void 0 ? _ref : (_wrapperRef$current2 = wrapperRef.current) === null || _wrapperRef$current2 === void 0 ? void 0 : _wrapperRef$current2.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
20
+
21
+ // The first element can be focusable
22
+ if (firstFocusableElement) {
23
+ return firstFocusableElement.focus();
24
+ }
25
+ }, [key, wrapperRef]);
26
+ }
@@ -7,7 +7,7 @@ type Props = {
7
7
  onClick?: (b: boolean) => void;
8
8
  label?: ReactNode;
9
9
  description?: ReactNode;
10
- errors?: Record<string, LunaticError[]>;
10
+ errors?: LunaticError[];
11
11
  };
12
12
  declare const _default: import("react").ComponentType<Props>;
13
13
  export default _default;
@@ -3,6 +3,7 @@ type Props = {
3
3
  options: CheckboxGroupOption[];
4
4
  id: string;
5
5
  shortcut?: boolean;
6
+ invalid?: boolean;
6
7
  };
7
- declare function CheckboxGroupContent({ options, id, shortcut }: Props): import("react/jsx-runtime").JSX.Element;
8
+ declare function CheckboxGroupContent({ options, id, shortcut, invalid }: Props): import("react/jsx-runtime").JSX.Element;
8
9
  export default CheckboxGroupContent;
@@ -4,7 +4,7 @@ import type { LunaticError } from '../../../../use-lunatic/type';
4
4
  import { type CheckboxGroupOption } from '../lunatic-checkbox-group';
5
5
  type Props = {
6
6
  options: CheckboxGroupOption[];
7
- errors?: Record<string, LunaticError[]>;
7
+ errors?: LunaticError[];
8
8
  id: string;
9
9
  label?: ReactNode;
10
10
  description?: ReactNode;
@@ -10,6 +10,7 @@ export type CheckboxOptionProps = {
10
10
  description?: LunaticBaseProps['description'];
11
11
  codeModality?: string;
12
12
  shortcut?: boolean;
13
+ invalid?: boolean;
13
14
  };
14
15
  declare const _default: import("react").ComponentType<CheckboxOptionProps>;
15
16
  export default _default;
@@ -1,11 +1,11 @@
1
1
  import type { PropsWithChildren } from 'react';
2
- import type { LunaticBaseProps } from '../../../type';
2
+ import type { LunaticError } from '../../../../use-lunatic/type';
3
3
  type Props = PropsWithChildren<{
4
4
  classNamePrefix?: string;
5
5
  className?: string;
6
6
  id?: string;
7
7
  classStyle?: string;
8
- errors?: LunaticBaseProps['errors'];
8
+ errors?: LunaticError[];
9
9
  }>;
10
10
  declare const _default: import("react").ComponentType<Props>;
11
11
  export default _default;