@inseefr/lunatic 2.4.7 → 2.4.8-dynamicArray

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 (41) hide show
  1. package/lib/components/duration/duration.js +117 -0
  2. package/lib/components/duration/duration.scss +16 -0
  3. package/lib/components/duration/duration.spec.js +49 -0
  4. package/lib/components/duration/index.js +13 -0
  5. package/lib/components/duration/useDurationValues.js +124 -0
  6. package/lib/components/index.js +7 -0
  7. package/lib/components/loop/loop.js +2 -2
  8. package/lib/components/loop/roster-for-loop/roster-for-loop.js +35 -32
  9. package/lib/components/loop/roster-for-loop/roster-table.js +17 -16
  10. package/lib/components/loop/roster-for-loop/roster.scss +32 -34
  11. package/lib/components/loop/roster-for-loop/row.js +48 -19
  12. package/lib/hooks/use-did-change.js +19 -0
  13. package/lib/hooks/use-why-render.js +20 -0
  14. package/lib/src/components/duration/duration.d.ts +4 -0
  15. package/lib/src/components/duration/duration.spec.d.ts +1 -0
  16. package/lib/src/components/duration/index.d.ts +1 -0
  17. package/lib/src/components/duration/useDurationValues.d.ts +43 -0
  18. package/lib/src/components/index.d.ts +1 -0
  19. package/lib/src/components/loop/block-for-loop/block-for-loop-ochestrator.d.ts +1 -1
  20. package/lib/src/components/loop/block-for-loop/block-for-loop.d.ts +1 -1
  21. package/lib/src/components/loop/roster-for-loop/roster-for-loop-orchestrator.d.ts +1 -1
  22. package/lib/src/components/loop/roster-for-loop/roster-for-loop.d.ts +4 -4
  23. package/lib/src/components/loop/roster-for-loop/roster-table.d.ts +2 -2
  24. package/lib/src/components/type.d.ts +9 -2
  25. package/lib/src/hooks/use-did-change.d.ts +4 -0
  26. package/lib/src/hooks/use-why-render.d.ts +4 -0
  27. package/lib/src/use-lunatic/commons/use-components-from-state.d.ts +1 -2
  28. package/lib/src/use-lunatic/use-lunatic.d.ts +1 -1
  29. package/lib/stories/duration/duration.stories.js +41 -0
  30. package/lib/stories/duration/source.json +32 -0
  31. package/lib/stories/duration/source1.json +32 -0
  32. package/lib/stories/loop/block-for-loop.stories.js +1 -8
  33. package/lib/stories/loop/roster-for-loop.stories.js +8 -1
  34. package/lib/stories/loop/source-with-header.json +16 -4
  35. package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +1 -1
  36. package/lib/use-lunatic/commons/use-components-from-state.js +2 -14
  37. package/package.json +2 -2
  38. package/lib/components/loop/roster-for-loop/body.js +0 -52
  39. package/lib/components/loop/roster-for-loop/header.js +0 -34
  40. package/lib/src/components/loop/roster-for-loop/body.d.ts +0 -12
  41. package/lib/src/components/loop/roster-for-loop/header.d.ts +0 -9
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
2
 
3
- 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); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports["default"] = void 0;
8
- var _react = _interopRequireWildcard(require("react"));
7
+ var _react = require("react");
9
8
  var _htmlTable = require("../../commons/components/html-table");
10
9
  var _commons = require("../../commons");
11
10
  var _jsxRuntime = require("react/jsx-runtime");
12
- 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); }
13
- 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; }
14
11
  var emptyValue = {};
15
12
  function Row(_ref) {
16
13
  var id = _ref.id,
@@ -59,25 +56,57 @@ function Row(_ref) {
59
56
  }
60
57
  }
61
58
  }
62
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Td, {
59
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(RowCell, {
63
60
  id: idComponent,
64
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.OrchestratedComponent, {
65
- component: component,
66
- handleChange: handleChangeRow,
67
- features: features,
68
- missing: missing,
69
- shortcut: shortcut,
70
- management: management,
71
- value: value,
72
- id: idComponent,
73
- preferences: preferences,
74
- iteration: rowIndex,
75
- executeExpression: executeExpression,
76
- errors: errors
77
- })
61
+ component: component,
62
+ handleChange: handleChangeRow,
63
+ features: features,
64
+ missing: missing,
65
+ shortcut: shortcut,
66
+ management: management,
67
+ value: value,
68
+ preferences: preferences,
69
+ rowIndex: rowIndex,
70
+ executeExpression: executeExpression,
71
+ errors: errors
78
72
  }, key);
79
73
  })
80
74
  });
81
75
  }
76
+
77
+ /**
78
+ * Memoïzed version of a cell (for optimisation)
79
+ */
80
+ var RowCell = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
81
+ var id = _ref2.id,
82
+ component = _ref2.component,
83
+ handleChange = _ref2.handleChange,
84
+ features = _ref2.features,
85
+ missing = _ref2.missing,
86
+ shortcut = _ref2.shortcut,
87
+ management = _ref2.management,
88
+ value = _ref2.value,
89
+ preferences = _ref2.preferences,
90
+ rowIndex = _ref2.rowIndex,
91
+ executeExpression = _ref2.executeExpression,
92
+ errors = _ref2.errors;
93
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Td, {
94
+ id: id,
95
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_commons.OrchestratedComponent, {
96
+ component: component,
97
+ handleChange: handleChange,
98
+ features: features,
99
+ missing: missing,
100
+ shortcut: shortcut,
101
+ management: management,
102
+ value: value,
103
+ id: id,
104
+ preferences: preferences,
105
+ iteration: rowIndex,
106
+ executeExpression: executeExpression,
107
+ errors: errors
108
+ })
109
+ });
110
+ });
82
111
  var _default = Row;
83
112
  exports["default"] = _default;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useDidChange = useDidChange;
7
+ var _react = require("react");
8
+ /**
9
+ * Hook for debug purpose that log the data that changed between 2 renders
10
+ */
11
+ function useDidChange(obj, suffix) {
12
+ var ref = (0, _react.useRef)(obj);
13
+ for (var key in obj) {
14
+ if (obj[key] !== ref.current[key]) {
15
+ console.log("\"".concat(key, "\" has changed ").concat(suffix !== null && suffix !== void 0 ? suffix : ''), obj[key]);
16
+ }
17
+ }
18
+ ref.current = obj;
19
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useWhyRender = useWhyRender;
7
+ var _react = require("react");
8
+ /**
9
+ * Debugging hook that log what changed between 2 renders
10
+ */
11
+ function useWhyRender(props) {
12
+ var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
13
+ var propsRef = (0, _react.useRef)(props);
14
+ for (var key in props) {
15
+ if (propsRef.current[key] !== props[key]) {
16
+ console.log("".concat(prefix, ": ").concat(key, " changed"));
17
+ }
18
+ }
19
+ propsRef.current = props;
20
+ }
@@ -0,0 +1,4 @@
1
+ import './duration.scss';
2
+ import { LunaticComponentProps } from '../type';
3
+ declare function Duration(props: LunaticComponentProps<'Duration'>): import("react/jsx-runtime").JSX.Element;
4
+ export default Duration;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { default } from "./duration";
@@ -0,0 +1,43 @@
1
+ export declare const useDurationValues: (value: string | null, format: Formats, handleChange: (v: string | null) => void) => {
2
+ propsHours: {
3
+ value: string;
4
+ onChange: (e: {
5
+ target: {
6
+ value: string;
7
+ };
8
+ }) => void;
9
+ min: string;
10
+ max: string;
11
+ };
12
+ propsMonths: {
13
+ value: string;
14
+ onChange: (e: {
15
+ target: {
16
+ value: string;
17
+ };
18
+ }) => void;
19
+ min: string;
20
+ max: string;
21
+ };
22
+ propsYears: {
23
+ value: string;
24
+ onChange: (e: {
25
+ target: {
26
+ value: string;
27
+ };
28
+ }) => void;
29
+ min: string;
30
+ };
31
+ propsMinutes: {
32
+ value: string;
33
+ onChange: (e: {
34
+ target: {
35
+ value: string;
36
+ };
37
+ }) => void;
38
+ min: string;
39
+ max: string;
40
+ };
41
+ };
42
+ type Formats = "PTnHnM" | "PnYnM";
43
+ export {};
@@ -22,5 +22,6 @@ export { default as SuggesterLoaderWidget } from './suggester-loader-widget';
22
22
  export { default as Roundabout } from './roundabout';
23
23
  export { default as Table } from './table';
24
24
  export { default as ComponentSet } from './component-set';
25
+ export { default as Duration } from "./duration";
25
26
  export { default as QuestionInformation } from './questions/question-information';
26
27
  export { default as QuestionContext } from './questions/question-context';
@@ -42,7 +42,7 @@ declare const BlockForLoopOrchestrator: ({ id, components, nbRows, valueMap, han
42
42
  bindingDependencies?: string[] | undefined;
43
43
  } | undefined) => T;
44
44
  value: Record<string, unknown[]>;
45
- headers?: {
45
+ header?: {
46
46
  label: import("react").ReactNode;
47
47
  }[] | undefined;
48
48
  paginatedLoop?: boolean | undefined;
@@ -13,7 +13,7 @@ declare const _default: React.ComponentType<import("../../type").LunaticBaseProp
13
13
  bindingDependencies?: string[] | undefined;
14
14
  } | undefined) => T;
15
15
  value: Record<string, unknown[]>;
16
- headers?: {
16
+ header?: {
17
17
  label: React.ReactNode;
18
18
  }[] | undefined;
19
19
  paginatedLoop?: boolean | undefined;
@@ -42,7 +42,7 @@ declare const RosterForLoopOrchestrator: ({ id, components, nbRows, valueMap, ha
42
42
  bindingDependencies?: string[] | undefined;
43
43
  } | undefined) => T;
44
44
  value: Record<string, unknown[]>;
45
- headers?: {
45
+ header?: {
46
46
  label: import("react").ReactNode;
47
47
  }[] | undefined;
48
48
  paginatedLoop?: boolean | undefined;
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- declare const _default: React.ComponentType<import("../../type").LunaticBaseProps<unknown> & {
1
+ /// <reference types="react" />
2
+ declare const _default: import("react").ComponentType<import("../../type").LunaticBaseProps<unknown> & {
3
3
  lines: {
4
4
  min: number;
5
5
  max: number;
@@ -13,8 +13,8 @@ declare const _default: React.ComponentType<import("../../type").LunaticBaseProp
13
13
  bindingDependencies?: string[] | undefined;
14
14
  } | undefined) => T;
15
15
  value: Record<string, unknown[]>;
16
- headers?: {
17
- label: React.ReactNode;
16
+ header?: {
17
+ label: import("react").ReactNode;
18
18
  }[] | undefined;
19
19
  paginatedLoop?: boolean | undefined;
20
20
  }>;
@@ -8,6 +8,6 @@ type Props = {
8
8
  index: number;
9
9
  [k: string]: unknown;
10
10
  }) => void;
11
- } & Pick<LunaticComponentProps<'RosterForLoop'>, 'id' | 'components' | 'executeExpression' | 'headers' | 'value' | 'management' | 'missing' | 'shortcut' | 'errors'>;
12
- declare function RosterTable({ components, nbRows, executeExpression, id, headers, value: valueMap, shortcut, missing, management, handleChange, }: Props): import("react/jsx-runtime").JSX.Element;
11
+ } & Pick<LunaticComponentProps<'RosterForLoop'>, 'id' | 'components' | 'executeExpression' | 'header' | 'value' | 'missing' | 'errors'>;
12
+ declare function RosterTable({ components, nbRows, executeExpression, id, header, value: valueMap, missing, handleChange, }: Props): import("react/jsx-runtime").JSX.Element;
13
13
  export default RosterTable;
@@ -2,6 +2,7 @@ import { LunaticComponentDefinition, LunaticError, LunaticExpression, LunaticSta
2
2
  import { CSSProperties, FunctionComponent, ReactNode } from 'react';
3
3
  import { SuggesterStatus } from '../use-lunatic/use-suggesters';
4
4
  import useLunatic from '../use-lunatic';
5
+ type Formats = 'PTnHnM' | 'PnYnM';
5
6
  export type LunaticBaseProps<ValueType = unknown> = {
6
7
  id: string;
7
8
  handleChange: (response: {
@@ -60,6 +61,12 @@ type ComponentPropsByType = {
60
61
  name: string;
61
62
  };
62
63
  };
64
+ Duration: LunaticBaseProps<string | null> & {
65
+ format: Formats;
66
+ response: {
67
+ name: string;
68
+ };
69
+ };
63
70
  Input: LunaticBaseProps<string> & {
64
71
  maxLength?: number;
65
72
  value: null | string;
@@ -83,7 +90,7 @@ type ComponentPropsByType = {
83
90
  components: LunaticComponentDefinition[];
84
91
  executeExpression: LunaticState['executeExpression'];
85
92
  value: Record<string, unknown[]>;
86
- headers?: Array<{
93
+ header?: Array<{
87
94
  label: ReactNode;
88
95
  }>;
89
96
  paginatedLoop?: boolean;
@@ -97,7 +104,7 @@ type ComponentPropsByType = {
97
104
  components: LunaticComponentDefinition[];
98
105
  executeExpression: LunaticState['executeExpression'];
99
106
  value: Record<string, unknown[]>;
100
- headers?: Array<{
107
+ header?: Array<{
101
108
  label: ReactNode;
102
109
  }>;
103
110
  paginatedLoop?: boolean;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Hook for debug purpose that log the data that changed between 2 renders
3
+ */
4
+ export declare function useDidChange(obj: Record<string, unknown>, suffix?: string): void;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Debugging hook that log what changed between 2 renders
3
+ */
4
+ export declare function useWhyRender(props: Record<string, any>, prefix?: string): void;
@@ -1,4 +1,3 @@
1
1
  import { LunaticState } from '../type';
2
- import { LunaticComponentProps } from './fill-components/fill-components';
3
- declare function useComponentsFromState(state: LunaticState): LunaticComponentProps[];
2
+ declare function useComponentsFromState(state: LunaticState): import("./fill-components/fill-components").LunaticComponentProps<"Sequence" | "Subsequence" | "RosterForLoop" | "Loop" | "Table" | "Input" | "InputNumber" | "Datepicker" | "CheckboxGroup" | "CheckboxOne" | "CheckboxBoolean" | "Radio" | "Dropdown" | "Textarea" | "FilterDescription" | "PairwiseLinks" | "ComponentSet" | "Roundabout">[];
4
3
  export default useComponentsFromState;
@@ -24,7 +24,7 @@ declare function useLunatic(source: LunaticSource, data: LunaticData | undefined
24
24
  dontKnowButton?: string;
25
25
  refusedButton?: string;
26
26
  }): {
27
- getComponents: () => import("./commons/fill-components/fill-components").LunaticComponentProps[];
27
+ getComponents: () => import("./commons/fill-components/fill-components").LunaticComponentProps<"Sequence" | "Subsequence" | "RosterForLoop" | "Loop" | "Table" | "Input" | "InputNumber" | "Datepicker" | "CheckboxGroup" | "CheckboxOne" | "CheckboxBoolean" | "Radio" | "Dropdown" | "Textarea" | "FilterDescription" | "PairwiseLinks" | "ComponentSet" | "Roundabout">[];
28
28
  goPreviousPage: () => void;
29
29
  goNextPage: (payload?: {}) => void;
30
30
  goToPage: (payload?: {}) => void;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = exports.PnYnM = exports.PTnHnM = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _defaultArgTypes = _interopRequireDefault(require("../utils/default-arg-types"));
9
+ var _orchestrator = _interopRequireDefault(require("../utils/orchestrator"));
10
+ var _source = _interopRequireDefault(require("./source"));
11
+ var _source2 = _interopRequireDefault(require("./source1"));
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
+ 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); }
15
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
19
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
20
+ var stories = {
21
+ title: 'Components/Duration',
22
+ component: _orchestrator["default"],
23
+ argTypes: _defaultArgTypes["default"]
24
+ };
25
+ var _default = stories;
26
+ exports["default"] = _default;
27
+ var Template = function Template(args) {
28
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_orchestrator["default"], _objectSpread({}, args));
29
+ };
30
+ var PnYnM = Template.bind({});
31
+ exports.PnYnM = PnYnM;
32
+ PnYnM.args = {
33
+ id: 'durationAnnéesMois',
34
+ source: _source["default"]
35
+ };
36
+ var PTnHnM = Template.bind({});
37
+ exports.PTnHnM = PTnHnM;
38
+ PTnHnM.args = {
39
+ id: 'durationHeureMinute',
40
+ source: _source2["default"]
41
+ };
@@ -0,0 +1,32 @@
1
+ {
2
+ "components": [
3
+ {
4
+ "id": "kxi788",
5
+ "componentType": "Duration",
6
+ "mandatory": false,
7
+ "format": "PnYnM",
8
+ "page": "1",
9
+ "maxPage": "1",
10
+ "label": {
11
+ "value": "\"➡ 1. \" || \"Duration \"",
12
+ "type": "VTL|MD"
13
+ },
14
+ "description": { "value": "\"Description\"", "type": "VTL|MD" },
15
+ "conditionFilter": { "value": "true", "type": "VTL" },
16
+ "response": { "name": "DUREE" }
17
+ }
18
+ ],
19
+ "variables": [
20
+ {
21
+ "variableType": "COLLECTED",
22
+ "name": "DUREE",
23
+ "values": {
24
+ "PREVIOUS": null,
25
+ "COLLECTED": null,
26
+ "FORCED": null,
27
+ "EDITED": null,
28
+ "INPUTED": null
29
+ }
30
+ }
31
+ ]
32
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "components": [
3
+ {
4
+ "id": "kxi788",
5
+ "componentType": "Duration",
6
+ "mandatory": false,
7
+ "format": "PTnHnM",
8
+ "page": "1",
9
+ "maxPage": "1",
10
+ "label": {
11
+ "value": "\"➡ 1. \" || \"Duration \"",
12
+ "type": "VTL|MD"
13
+ },
14
+ "description": { "value": "\"Description\"", "type": "VTL|MD" },
15
+ "conditionFilter": { "value": "true", "type": "VTL" },
16
+ "response": { "name": "DUREE" }
17
+ }
18
+ ],
19
+ "variables": [
20
+ {
21
+ "variableType": "COLLECTED",
22
+ "name": "DUREE",
23
+ "values": {
24
+ "PREVIOUS": null,
25
+ "COLLECTED": "PT12H50M",
26
+ "FORCED": null,
27
+ "EDITED": null,
28
+ "INPUTED": null
29
+ }
30
+ }
31
+ ]
32
+ }
@@ -3,11 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = exports.WithHeader = exports.Default = void 0;
6
+ exports["default"] = exports.Default = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _orchestrator = _interopRequireDefault(require("../utils/orchestrator"));
9
9
  var _sourceBloc = _interopRequireDefault(require("./source-bloc.json"));
10
- var _sourceWithHeader = _interopRequireDefault(require("./source-with-header.json"));
11
10
  var _defaultArgTypes = _interopRequireDefault(require("../utils/default-arg-types"));
12
11
  var _jsxRuntime = require("react/jsx-runtime");
13
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -32,10 +31,4 @@ exports.Default = Default;
32
31
  Default.args = {
33
32
  id: 'bloc-for-loop',
34
33
  source: _sourceBloc["default"]
35
- };
36
- var WithHeader = Template.bind({});
37
- exports.WithHeader = WithHeader;
38
- WithHeader.args = {
39
- id: 'bloc-for-loop-headers',
40
- source: _sourceWithHeader["default"]
41
34
  };
@@ -3,11 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = exports.Default = void 0;
6
+ exports["default"] = exports.WithHeader = exports.Default = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _orchestrator = _interopRequireDefault(require("../utils/orchestrator"));
9
9
  var _sourceRoster = _interopRequireDefault(require("./source-roster"));
10
10
  var _defaultArgTypes = _interopRequireDefault(require("../utils/default-arg-types"));
11
+ var _sourceWithHeader = _interopRequireDefault(require("./source-with-header.json"));
11
12
  var _jsxRuntime = require("react/jsx-runtime");
12
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
14
  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); }
@@ -31,4 +32,10 @@ exports.Default = Default;
31
32
  Default.args = {
32
33
  id: 'roster-for-loop',
33
34
  source: _sourceRoster["default"]
35
+ };
36
+ var WithHeader = Template.bind({});
37
+ exports.WithHeader = WithHeader;
38
+ WithHeader.args = {
39
+ id: 'roster-for-loop-headers',
40
+ source: _sourceWithHeader["default"]
34
41
  };
@@ -14,16 +14,28 @@
14
14
  {
15
15
  "id": "loop-prenom",
16
16
  "componentType": "RosterForLoop",
17
- "headers": [
18
- { "headerCell": true, "label": "Prénom" },
19
- { "headerCell": true, "label": "Age" }
17
+ "header": [
18
+ {
19
+ "headerCell": true,
20
+ "label": {
21
+ "value": "Prénom",
22
+ "type": "VTL|MD"
23
+ }
24
+ },
25
+ {
26
+ "headerCell": true,
27
+ "label": {
28
+ "value": "Age",
29
+ "type": "VTL|MD"
30
+ }
31
+ }
20
32
  ],
21
33
  "label": { "value": "\"Ajouter un individu\"", "type": "VTL|MD" },
22
34
  "conditionFilter": { "value": "true", "type": "VTL" },
23
35
  "bindingDependencies": ["PRENOM", "AGE"],
24
36
  "lines": {
25
37
  "min": { "value": 1, "type": "VTL" },
26
- "max": { "value": 10, "type": "VTL" }
38
+ "max": { "value": 1000, "type": "VTL" }
27
39
  },
28
40
  "page": "1",
29
41
  "components": [
@@ -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', 'iterations', 'xAxisIterations', 'yAxisIterations', 'conditionFilter', 'headers.label', 'header.label'];
27
+ 'controls.iterations', 'lines.min', 'lines.max', 'iterations', 'xAxisIterations', 'yAxisIterations', 'conditionFilter', 'header.label'];
28
28
 
29
29
  // Utility type to replace all expression from an object into a translated version
30
30
 
@@ -8,18 +8,8 @@ var _react = require("react");
8
8
  var _getComponentsFromState = _interopRequireDefault(require("./get-components-from-state"));
9
9
  var _fillComponents = _interopRequireDefault(require("./fill-components"));
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
- 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."); }
13
- 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); }
14
- 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; }
15
- 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; } }
16
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
11
  function useComponentsFromState(state) {
18
- var _useState = (0, _react.useState)([]),
19
- _useState2 = _slicedToArray(_useState, 2),
20
- componentsFilled = _useState2[0],
21
- setComponentsFilled = _useState2[1];
22
- (0, _react.useEffect)(function () {
12
+ return (0, _react.useMemo)(function () {
23
13
  var pager = state.pager,
24
14
  pages = state.pages,
25
15
  isInLoop = state.isInLoop;
@@ -29,13 +19,11 @@ function useComponentsFromState(state) {
29
19
  isInLoop: isInLoop
30
20
  });
31
21
  var filled = (0, _fillComponents["default"])(components, state);
32
- var filtered = filled.filter(function (_ref) {
22
+ return filled.filter(function (_ref) {
33
23
  var conditionFilter = _ref.conditionFilter;
34
24
  return conditionFilter !== undefined ? conditionFilter : true;
35
25
  });
36
- setComponentsFilled(filtered);
37
26
  }, [state]);
38
- return componentsFilled;
39
27
  }
40
28
  var _default = useComponentsFromState;
41
29
  exports["default"] = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "2.4.7",
3
+ "version": "2.4.8-dynamicArray",
4
4
  "workersVersion": "0.2.5-experimental",
5
5
  "description": "Library of questionnaire components",
6
6
  "repository": {
@@ -52,7 +52,7 @@
52
52
  "library"
53
53
  ],
54
54
  "dependencies": {
55
- "@inseefr/trevas": "^0.1.17",
55
+ "@inseefr/trevas": "^0.1.18",
56
56
  "@inseefr/vtl-2.0-antlr-tools": "^0.1.0-bundle",
57
57
  "antlr4": "4.11.0",
58
58
  "classnames": "^2.3.1",
@@ -1,52 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _htmlTable = require("../../commons/components/html-table");
9
- var _rosterForLoopOrchestrator = _interopRequireDefault(require("./roster-for-loop-orchestrator"));
10
- var _jsxRuntime = require("react/jsx-runtime");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
- 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); }
13
- 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; }
14
- 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); }
15
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
19
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
20
- function Body(_ref) {
21
- var id = _ref.id,
22
- components = _ref.components,
23
- nbRows = _ref.nbRows,
24
- executeExpression = _ref.executeExpression,
25
- handleChange = _ref.handleChange,
26
- valueMap = _ref.value,
27
- missing = _ref.missing;
28
- var handleChangeRow = (0, _react.useCallback)(function (response, value, args) {
29
- handleChange(response, value, _objectSpread(_objectSpread({}, args), {}, {
30
- loop: true,
31
- length: nbRows
32
- }));
33
- }, [nbRows, handleChange]);
34
- if (nbRows <= 0) {
35
- return null;
36
- }
37
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_htmlTable.Tbody, {
38
- id: id,
39
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_rosterForLoopOrchestrator["default"], {
40
- id: "roster-".concat(id),
41
- components: components,
42
- nbRows: nbRows,
43
- handleChange: handleChangeRow,
44
- executeExpression: executeExpression,
45
- valueMap: valueMap,
46
- missing: missing,
47
- preferences: ['COLLECTED']
48
- })
49
- });
50
- }
51
- var _default = Body;
52
- exports["default"] = _default;