@inseefr/lunatic 2.5.2-rc1-beta → 2.5.2

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.
@@ -48,6 +48,7 @@ function ComboBoxContent(_ref) {
48
48
  }, [onKeyDown]);
49
49
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_comboBoxContentBox["default"], {
50
50
  classNamePrefix: classNamePrefix,
51
+ focused: focused,
51
52
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
52
53
  className: (0, _classnames["default"])("".concat(classNamePrefix !== null && classNamePrefix !== void 0 ? classNamePrefix : 'lunatic', "-combo-box-content"), {
53
54
  focused: focused
@@ -120,6 +120,7 @@ function ComboBox(_ref) {
120
120
  }
121
121
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_comboBoxContainer["default"], {
122
122
  id: id,
123
+ className: className,
123
124
  classStyle: classStyle,
124
125
  classNamePrefix: classNamePrefix,
125
126
  errors: errors,
@@ -2,4 +2,4 @@
2
2
  * Extract the value associated with a component
3
3
  * If the component expect multiple values (it has a responses property) then extract a map of values
4
4
  */
5
- export declare function getComponentValue<T = unknown>(component: unknown, valueMap: Record<string, unknown>, rowIndex?: number): T;
5
+ export declare function getComponentValue(component: unknown, valueMap: Record<string, unknown>, rowIndex?: number): unknown;
@@ -0,0 +1 @@
1
+ export {};
@@ -4,31 +4,33 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getComponentValue = getComponentValue;
7
- var _object = require("./object");
8
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); }
9
8
  /**
10
9
  * Extract the value associated with a component
11
10
  * If the component expect multiple values (it has a responses property) then extract a map of values
12
11
  */
13
12
  function getComponentValue(component, valueMap, rowIndex) {
14
- var value = undefined;
15
13
  if (hasResponse(component)) {
16
- var valueArray = valueMap[component.response.name];
17
- if (Array.isArray(valueArray)) {
18
- value = valueArray[rowIndex !== null && rowIndex !== void 0 ? rowIndex : 0] || '';
14
+ var value = valueMap[component.response.name];
15
+ if (Array.isArray(value)) {
16
+ return value[rowIndex !== null && rowIndex !== void 0 ? rowIndex : 0];
19
17
  }
18
+ return value;
20
19
  }
21
20
 
22
21
  // For checkbox group we need to send the map of values
23
22
  if (hasResponses(component)) {
24
- value = (0, _object.objectMap)(valueMap, function (k, v) {
25
- if (Array.isArray(v)) {
26
- return [k, v[rowIndex !== null && rowIndex !== void 0 ? rowIndex : 0]];
23
+ var _component$responses$, _component$responses;
24
+ return Object.fromEntries((_component$responses$ = (_component$responses = component.responses) === null || _component$responses === void 0 ? void 0 : _component$responses.map(function (_ref) {
25
+ var response = _ref.response;
26
+ var value = valueMap[response.name];
27
+ if (Array.isArray(value)) {
28
+ return [response.name, value[rowIndex !== null && rowIndex !== void 0 ? rowIndex : 0]];
27
29
  }
28
- return [k, v];
29
- });
30
+ return [response.name, value];
31
+ })) !== null && _component$responses$ !== void 0 ? _component$responses$ : []);
30
32
  }
31
- return value;
33
+ return undefined;
32
34
  }
33
35
  function hasResponse(component) {
34
36
  return !!component && _typeof(component) === 'object' && 'response' in component && 'name' in component.response;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _getComponentValue = require("./get-component-value");
5
+ (0, _vitest.describe)('getComponentValue', function () {
6
+ var componentWithResponse = {
7
+ response: {
8
+ name: 'prenom'
9
+ }
10
+ };
11
+ var componentWithResponses = {
12
+ responses: [componentWithResponse, {
13
+ response: {
14
+ name: 'nom'
15
+ }
16
+ }]
17
+ };
18
+ (0, _vitest.it)('Should work with simple response', function () {
19
+ (0, _vitest.expect)((0, _getComponentValue.getComponentValue)(componentWithResponse, {
20
+ prenom: 'John'
21
+ })).toBe('John');
22
+ (0, _vitest.expect)((0, _getComponentValue.getComponentValue)(componentWithResponse, {})).toBe(undefined);
23
+ (0, _vitest.expect)((0, _getComponentValue.getComponentValue)({}, {
24
+ prenom: 'John'
25
+ })).toBe(undefined);
26
+ });
27
+ (0, _vitest.it)('Should work with simple response as Array', function () {
28
+ (0, _vitest.expect)((0, _getComponentValue.getComponentValue)(componentWithResponse, {
29
+ prenom: ['John', 'Renaud']
30
+ }, 1)).toBe('Renaud');
31
+ (0, _vitest.expect)((0, _getComponentValue.getComponentValue)(componentWithResponse, {
32
+ prenom: ['John', 'Renaud']
33
+ }, 3)).toBe(undefined);
34
+ });
35
+ (0, _vitest.it)('Should work with responses', function () {
36
+ (0, _vitest.expect)((0, _getComponentValue.getComponentValue)(componentWithResponses, {
37
+ prenom: 'John'
38
+ })).toMatchObject({
39
+ prenom: 'John',
40
+ nom: undefined
41
+ });
42
+ (0, _vitest.expect)((0, _getComponentValue.getComponentValue)(componentWithResponses, {
43
+ prenom: ['John', 'Renaud'],
44
+ nom: ['Insee', 'Metallica']
45
+ }, 1)).toMatchObject({
46
+ prenom: 'Renaud',
47
+ nom: 'Metallica'
48
+ });
49
+ (0, _vitest.expect)((0, _getComponentValue.getComponentValue)(componentWithResponses, {
50
+ prenom: ['John', 'Renaud'],
51
+ nom: 'Insee'
52
+ }, 1)).toMatchObject({
53
+ prenom: 'Renaud',
54
+ nom: 'Insee'
55
+ });
56
+ });
57
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "2.5.2-rc1-beta",
3
+ "version": "2.5.2",
4
4
  "workersVersion": "0.2.5-experimental",
5
5
  "description": "Library of questionnaire components",
6
6
  "repository": {
@@ -24,6 +24,7 @@
24
24
  ],
25
25
  "license": "MIT",
26
26
  "main": "lib/index.js",
27
+ "types": "lib/src/index.d.ts",
27
28
  "files": [
28
29
  "lib"
29
30
  ],