@inseefr/lunatic 2.7.5 → 2.7.7

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 (80) hide show
  1. package/README.fr.md +1 -1
  2. package/README.md +6 -1
  3. package/lib/components/loop/block-for-loop.js +2 -0
  4. package/lib/components/loop/constant.js +10 -0
  5. package/lib/components/loop/roster-for-loop/roster-for-loop.js +42 -20
  6. package/lib/components/lunatic-components.js +45 -7
  7. package/lib/components/table/lunatic-table.js +5 -1
  8. package/lib/src/components/datepicker/lunatic-datepicker.d.ts +1 -1
  9. package/lib/src/components/loop/constant.d.ts +4 -0
  10. package/lib/src/components/loop/roster-for-loop/roster-for-loop.d.ts +1 -0
  11. package/lib/src/components/lunatic-components.d.ts +12 -5
  12. package/lib/src/components/type.d.ts +4 -1
  13. package/lib/src/use-lunatic/commons/compile-controls.d.ts +4 -3
  14. package/lib/src/use-lunatic/commons/fill-components/fill-component-required.d.ts +75 -70
  15. package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +55 -50
  16. package/lib/src/use-lunatic/commons/fill-components/fill-iterations.d.ts +31 -26
  17. package/lib/src/use-lunatic/commons/fill-components/fill-specific-expression.d.ts +680 -73
  18. package/lib/src/use-lunatic/commons/use-components-from-state.d.ts +1 -1
  19. package/lib/src/use-lunatic/commons/variables/lunatic-variables-store.d.ts +4 -1
  20. package/lib/src/use-lunatic/reducer/commons/is-loop-component.d.ts +2 -2
  21. package/lib/src/use-lunatic/reducer/controls/check-base-control.d.ts +2 -0
  22. package/lib/src/use-lunatic/reducer/{resolve-component-controls/resolve-roundabout-control.d.ts → controls/check-roundabout-control.d.ts} +2 -2
  23. package/lib/src/use-lunatic/type-source.d.ts +16 -10
  24. package/lib/src/use-lunatic/use-lunatic.d.ts +11 -5
  25. package/lib/stories/behaviour/controls/controls.stories.js +14 -7
  26. package/lib/stories/behaviour/controls/loop.json +130 -0
  27. package/lib/stories/behaviour/controls/{V2_ControlesNonNum_horsBoucle_PasPageFin.json → simple.json} +2 -2
  28. package/lib/stories/date-picker/source.json +22 -67
  29. package/lib/stories/declaration/source.json +14 -28
  30. package/lib/stories/dropdown/source.json +11 -28
  31. package/lib/stories/filter-description/source.json +3 -2
  32. package/lib/stories/input/input.stories.js +1 -8
  33. package/lib/stories/input/source.json +1 -63
  34. package/lib/stories/input-number/input-number.stories.js +2 -22
  35. package/lib/stories/input-number/source.json +4 -6
  36. package/lib/stories/loop/{block-for-loop.stories.js → loop.stories.js} +10 -8
  37. package/lib/stories/loop/roster-for-loop.stories.js +8 -2
  38. package/lib/stories/loop/source-bloc.json +10 -39
  39. package/lib/stories/loop/source-paginated.json +65 -78
  40. package/lib/stories/overview/overview.stories.js +1 -1
  41. package/lib/stories/pairwise/pairwise-links.stories.js +4 -4
  42. package/lib/stories/pairwise/{links.json → source.json} +2 -6
  43. package/lib/stories/{loop/not-paginated-loop.stories.js → question-context/question-context.stories.js} +5 -9
  44. package/lib/stories/question-context/source.json +13 -0
  45. package/lib/stories/question-explication/source.json +1 -1
  46. package/lib/stories/{loop/paginated-loop.stories.js → question-information/question-information.stories.js} +4 -4
  47. package/lib/stories/question-information/source.json +14 -0
  48. package/lib/stories/roundabout/source.json +21 -31
  49. package/lib/stories/sequence/sequence.stories.js +7 -1
  50. package/lib/stories/sequence/source.json +17 -0
  51. package/lib/stories/suggester/simple.json +1 -1
  52. package/lib/stories/table/source-colspan.json +314 -0
  53. package/lib/stories/table/table.stories.js +7 -1
  54. package/lib/stories/textarea/source.json +6 -22
  55. package/lib/use-lunatic/commons/compile-controls.js +135 -34
  56. package/lib/use-lunatic/commons/fill-components/fill-component-value.js +10 -0
  57. package/lib/use-lunatic/commons/fill-components/fill-specific-expression.js +4 -1
  58. package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +39 -15
  59. package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +16 -6
  60. package/lib/use-lunatic/hooks/use-page-has-response.js +17 -0
  61. package/lib/use-lunatic/reducer/{resolve-component-controls/resolve-simple-control.js → controls/check-base-control.js} +5 -7
  62. package/lib/use-lunatic/reducer/{resolve-component-controls/resolve-roundabout-control.js → controls/check-roundabout-control.js} +2 -3
  63. package/lib/use-lunatic/reducer/overview/overview-on-init.js +6 -4
  64. package/lib/use-lunatic/type-source.js +1 -0
  65. package/package.json +1 -1
  66. package/lib/src/use-lunatic/commons/get-errors-without-empty-value.d.ts +0 -6
  67. package/lib/src/use-lunatic/reducer/resolve-component-controls/index.d.ts +0 -1
  68. package/lib/src/use-lunatic/reducer/resolve-component-controls/resolve-component-control.d.ts +0 -6
  69. package/lib/src/use-lunatic/reducer/resolve-component-controls/resolve-simple-control.d.ts +0 -3
  70. package/lib/stories/Introduction.stories.mdx +0 -112
  71. package/lib/stories/behaviour/controls/V2_Controles_BouclesLiees_PasPageFin.json +0 -533
  72. package/lib/stories/input/source-with-question.json +0 -80
  73. package/lib/stories/input-number/source-euros.json +0 -37
  74. package/lib/stories/input-number/source-thansand.json +0 -34
  75. package/lib/stories/loop/source-not-paginated.json +0 -138
  76. package/lib/use-lunatic/commons/get-errors-without-empty-value.js +0 -24
  77. package/lib/use-lunatic/reducer/resolve-component-controls/index.js +0 -12
  78. package/lib/use-lunatic/reducer/resolve-component-controls/resolve-component-control.js +0 -38
  79. /package/lib/stories/behaviour/controls/{V2_ControlesNum_horsBoucle_PasPageFin.json → simple-numeric.json} +0 -0
  80. /package/lib/stories/pairwise/{links-componentset.json → source-componentset.json} +0 -0
package/README.fr.md CHANGED
@@ -13,7 +13,7 @@ Lunatic est une librairie front-end sous forme de hook react et de librairies de
13
13
  - [Storybook](https://inseefr.github.io/Lunatic/storybook), branche `main`
14
14
  - [Storybook v1](https://inseefr.github.io/Lunatic/storybook-v1), branche `v1-main`
15
15
  - [Storybook Beta](https://inseefr.github.io/Lunatic/storybook-beta), branche `develop`
16
- - [Documentation](https://inseefr.github.io/Lunatic/fr/)
16
+ - [Documentation](https://inseefr.github.io/Lunatic/)
17
17
 
18
18
  ## Sommaire
19
19
 
package/README.md CHANGED
@@ -13,7 +13,7 @@ Lunatic is a front-end library in the form of a React hook and component librari
13
13
  - [Storybook 2.7](https://inseefr.github.io/Lunatic/storybook-2.7), branch `2.7`
14
14
  - [Storybook 2.6](https://inseefr.github.io/Lunatic/storybook-2.6), branch `2.6`
15
15
  - [Storybook v1](https://inseefr.github.io/Lunatic/storybook-0.3.9), branch `v1-main`
16
- - [Documentation](https://inseefr.github.io/Lunatic/en/)
16
+ - [Documentation](https://inseefr.github.io/Lunatic/)
17
17
 
18
18
  ## Table of Contents
19
19
 
@@ -22,12 +22,17 @@ Lunatic is a front-end library in the form of a React hook and component librari
22
22
  - [Usage](#usage)
23
23
  - [The useLunatic Hook](#the-uselunatic-hook)
24
24
  - [Components](#components)
25
+ - [Workers](#workers)
26
+ - [General](#general)
27
+ - [How it works](#how-it-works)
25
28
  - [Customization](#customization)
26
29
  - [Internal Working](#internal-working)
27
30
  - [General Functioning](#general-functioning)
28
31
  - [Pages and Pager](#pages-and-pager)
29
32
  - [VTL Execution](#vtl-execution)
30
33
  - [Convention and Best Practices](#convention-and-best-practices)
34
+ - [Stable Branchs](#stable-branchs)
35
+ - [Commits and feature branches](#commits-and-feature-branches)
31
36
 
32
37
  ## Usage
33
38
 
@@ -12,6 +12,7 @@ var _commons = require("../commons");
12
12
  var _declarations = require("../declarations");
13
13
  var _lunaticComponents = require("../lunatic-components");
14
14
  var _loopButton = require("./loop-button");
15
+ var _constant = require("./constant");
15
16
  var _jsxRuntime = require("react/jsx-runtime");
16
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
18
  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; }
@@ -80,6 +81,7 @@ var BlockForLoop = exports.BlockForLoop = (0, _commons.createCustomizableLunatic
80
81
  id: id
81
82
  }), (0, _array.times)(nbRows, function (n) {
82
83
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_lunaticComponents.LunaticComponents, {
84
+ blocklist: _constant.blockedInLoopComponents,
83
85
  components: getComponents(n),
84
86
  componentProps: function componentProps(c) {
85
87
  return _objectSpread(_objectSpread(_objectSpread({}, props), c), {}, {
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.blockedInLoopComponents = void 0;
7
+ /**
8
+ * List of components blocked in non-paginated loop
9
+ */
10
+ var blockedInLoopComponents = exports.blockedInLoopComponents = ['RosterForLoop', 'Loop', 'PairwiseLinks', 'Roundabout', 'CheckboxGroup'];
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.RosterForLoop = void 0;
8
8
  var _react = require("react");
9
+ require("./roster.scss");
9
10
  var _declarations = require("../../declarations");
10
11
  var _commons = require("../../commons");
11
12
  var _loopButton = require("../loop-button");
@@ -14,6 +15,8 @@ var _htmlTable = require("../../commons/components/html-table");
14
15
  var _tableHeader = require("../../table/table-header");
15
16
  var _array = require("../../../utils/array");
16
17
  var _lunaticComponents = require("../../lunatic-components");
18
+ var _constant = require("../constant");
19
+ var _errors = require("../../commons/components/errors/errors");
17
20
  var _jsxRuntime = require("react/jsx-runtime");
18
21
  var _excluded = ["value", "lines", "handleChange", "declarations", "label", "headers", "iterations", "id", "getComponents"];
19
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -80,6 +83,7 @@ var RosterForLoop = exports.RosterForLoop = (0, _commons.createCustomizableLunat
80
83
  if (nbRows === 0) {
81
84
  return null;
82
85
  }
86
+ var cols = 0;
83
87
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
84
88
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsBeforeText, {
85
89
  declarations: declarations,
@@ -95,28 +99,46 @@ var RosterForLoop = exports.RosterForLoop = (0, _commons.createCustomizableLunat
95
99
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Tbody, {
96
100
  id: id,
97
101
  children: (0, _array.times)(nbRows, function (n) {
98
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Tr, {
99
- id: props.id,
100
- row: n,
101
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_lunaticComponents.LunaticComponents, {
102
- components: getComponents(n),
103
- componentProps: function componentProps(c) {
104
- return _objectSpread(_objectSpread(_objectSpread({}, otherProps), c), {}, {
105
- id: "".concat(c.id, "-").concat(n)
106
- });
107
- },
108
- wrapper: function wrapper(_ref3) {
109
- var id = _ref3.id,
110
- children = _ref3.children;
111
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Td, {
112
- id: "".concat(id, "-").concat(n),
113
- children: children
114
- });
115
- }
116
- })
117
- }, n);
102
+ var components = getComponents(n);
103
+ var lineErrors = (0, _errors.getComponentErrors)(props.errors, "".concat(id, "-").concat(n));
104
+ var hasLineErrors = !!(lineErrors !== null && lineErrors !== void 0 && lineErrors.length);
105
+ cols = components.length;
106
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
107
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Tr, {
108
+ id: props.id,
109
+ row: n,
110
+ className: hasLineErrors ? 'lunatic-row-has-error' : undefined,
111
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_lunaticComponents.LunaticComponents, {
112
+ blocklist: _constant.blockedInLoopComponents,
113
+ components: components,
114
+ componentProps: function componentProps(c) {
115
+ return _objectSpread(_objectSpread(_objectSpread({}, otherProps), c), {}, {
116
+ id: "".concat(c.id, "-").concat(n)
117
+ });
118
+ },
119
+ wrapper: function wrapper(_ref3) {
120
+ var id = _ref3.id,
121
+ children = _ref3.children;
122
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Td, {
123
+ id: "".concat(id, "-").concat(n),
124
+ children: children
125
+ });
126
+ }
127
+ })
128
+ }, n), hasLineErrors && /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", {
129
+ className: "lunatic-errors",
130
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
131
+ colSpan: cols,
132
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
133
+ errors: lineErrors
134
+ })
135
+ })
136
+ })]
137
+ });
118
138
  })
119
139
  })]
140
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.Errors, {
141
+ errors: (0, _errors.getComponentErrors)(props.errors, id)
120
142
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsDetachable, {
121
143
  declarations: declarations,
122
144
  id: id
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.LunaticComponents = LunaticComponents;
7
+ exports.hasLabel = hasLabel;
7
8
  var _react = require("react");
8
9
  var lunaticComponents = _interopRequireWildcard(require("./index"));
9
10
  var _useAutoFocus = require("../hooks/use-auto-focus");
@@ -24,6 +25,7 @@ function LunaticComponents(_ref) {
24
25
  var components = _ref.components,
25
26
  autoFocusKey = _ref.autoFocusKey,
26
27
  componentProps = _ref.componentProps,
28
+ blocklist = _ref.blocklist,
27
29
  _ref$wrapper = _ref.wrapper,
28
30
  wrapper = _ref$wrapper === void 0 ? function (_ref2) {
29
31
  var children = _ref2.children;
@@ -40,21 +42,48 @@ function LunaticComponents(_ref) {
40
42
  ref: WrapperComponent === _react.Fragment ? undefined : wrapperRef,
41
43
  children: components.map(function (component, k) {
42
44
  if ((0, _component.hasComponentType)(component)) {
45
+ if (blocklist && blocklist.includes(component.componentType)) {
46
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
47
+ children: wrapper(_objectSpread({
48
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
49
+ style: {
50
+ color: 'red'
51
+ },
52
+ children: ["Component \"", component.componentType, "\" is not allowed here"]
53
+ }),
54
+ index: k
55
+ }, component))
56
+ }, computeId(component, k));
57
+ }
43
58
  var _props = _objectSpread(_objectSpread({}, component), componentProps === null || componentProps === void 0 ? void 0 : componentProps(component));
44
59
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
45
60
  children: wrapper(_objectSpread({
46
61
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(LunaticComponent, _objectSpread({}, _props)),
47
62
  index: k
48
63
  }, _props))
49
- }, 'id' in component ? component.id : "index-".concat(k));
64
+ }, computeId(component, k));
50
65
  }
66
+
51
67
  // In some case (table for instance) we have static component that only have a label (no componentType)
52
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
53
- children: wrapper({
54
- children: component,
55
- index: k
56
- })
57
- }, "index-".concat(k));
68
+ if (hasLabel(component)) {
69
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
70
+ children: wrapper(_objectSpread(_objectSpread({}, component), {}, {
71
+ children: component.label,
72
+ index: k
73
+ }))
74
+ }, k);
75
+ }
76
+
77
+ // Component is a ReactNode
78
+ if ( /*#__PURE__*/(0, _react.isValidElement)(component)) {
79
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {
80
+ children: wrapper({
81
+ children: component,
82
+ index: k
83
+ })
84
+ }, k);
85
+ }
86
+ return null;
58
87
  })
59
88
  });
60
89
  }
@@ -62,4 +91,13 @@ function LunaticComponent(props) {
62
91
  // Component is too dynamic to be typed
63
92
  var Component = lunaticComponents[props.componentType];
64
93
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, _objectSpread({}, props));
94
+ }
95
+ function computeId(component, fallback) {
96
+ if ('id' in component && typeof component.id === 'string') {
97
+ return component.id;
98
+ }
99
+ return fallback;
100
+ }
101
+ function hasLabel(component) {
102
+ return !!component && _typeof(component) === 'object' && 'label' in component && /*#__PURE__*/(0, _react.isValidElement)(component.label);
65
103
  }
@@ -48,11 +48,15 @@ function LunaticTable(props) {
48
48
  components: row,
49
49
  wrapper: function wrapper(_ref) {
50
50
  var children = _ref.children,
51
- index = _ref.index;
51
+ index = _ref.index,
52
+ colspan = _ref.colspan,
53
+ rowspan = _ref.rowspan;
52
54
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Td, {
53
55
  id: id,
54
56
  row: rowIndex,
55
57
  index: index,
58
+ colSpan: colspan,
59
+ rowSpan: rowspan,
56
60
  children: children
57
61
  });
58
62
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  declare const _default: import("react").ComponentType<import("../type").LunaticBaseProps<string | null> & {
3
- dateFormat: "YYYY-MM-DD" | "YYYY-MM" | "YYYY";
3
+ dateFormat: "YYYY-MM-DD" | "YYYY" | "YYYY-MM";
4
4
  min?: string | undefined;
5
5
  max?: string | undefined;
6
6
  response: {
@@ -0,0 +1,4 @@
1
+ /**
2
+ * List of components blocked in non-paginated loop
3
+ */
4
+ export declare const blockedInLoopComponents: string[];
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import './roster.scss';
2
3
  /**
3
4
  * Loop displayed as a table
4
5
  */
@@ -1,15 +1,22 @@
1
1
  import { type PropsWithChildren, type ReactElement, type ReactNode } from 'react';
2
2
  import type { FilledLunaticComponentProps } from '../use-lunatic/commons/fill-components/fill-components';
3
- type Props<T extends Record<string, unknown>> = {
4
- components: (FilledLunaticComponentProps | ReactElement)[];
3
+ type Props<T extends FilledLunaticComponentProps, V = undefined> = {
4
+ components: (FilledLunaticComponentProps | ReactElement | {
5
+ label: string;
6
+ [key: string]: unknown;
7
+ })[];
5
8
  autoFocusKey?: string;
6
- componentProps?: (component: FilledLunaticComponentProps) => T;
7
- wrapper?: (props: PropsWithChildren<FilledLunaticComponentProps & T & {
9
+ componentProps?: (component: FilledLunaticComponentProps) => V;
10
+ blocklist?: string[];
11
+ wrapper?: (props: PropsWithChildren<FilledLunaticComponentProps & T & V & {
8
12
  index: number;
9
13
  }>) => ReactNode;
10
14
  };
11
15
  /**
12
16
  * Entry point for orchestrators, this component display the list of fields
13
17
  */
14
- export declare function LunaticComponents<T extends Record<string, unknown>>({ components, autoFocusKey, componentProps, wrapper, }: Props<T>): import("react/jsx-runtime").JSX.Element;
18
+ export declare function LunaticComponents<T extends FilledLunaticComponentProps, V = undefined>({ components, autoFocusKey, componentProps, blocklist, wrapper, }: Props<T, V>): import("react/jsx-runtime").JSX.Element;
19
+ export declare function hasLabel(component: unknown): component is {
20
+ label: ReactNode;
21
+ } & FilledLunaticComponentProps;
15
22
  export {};
@@ -124,7 +124,10 @@ type ComponentPropsByType = {
124
124
  rowspan?: number;
125
125
  colspan?: number;
126
126
  }>;
127
- body: FilledLunaticComponentProps[][];
127
+ body: (FilledLunaticComponentProps & {
128
+ colspan?: number;
129
+ rowspan?: number;
130
+ })[][];
128
131
  executeExpression: LunaticState['executeExpression'];
129
132
  iteration: LunaticState['pager']['iteration'];
130
133
  };
@@ -1,8 +1,9 @@
1
1
  import type { LunaticError, LunaticState } from '../type';
2
2
  export type StateForControls = Pick<LunaticState, 'pager' | 'pages' | 'isInLoop' | 'executeExpression'>;
3
- type ControlsResult = {
3
+ /**
4
+ * Check controls for currently visible components and output errors
5
+ */
6
+ export declare function compileControls(state: StateForControls): {
4
7
  currentErrors: Record<string, LunaticError[]> | undefined;
5
8
  isCritical: boolean;
6
9
  };
7
- export declare function compileControls(state: StateForControls): ControlsResult;
8
- export {};