@inseefr/lunatic 2.5.0-fast-forward → 2.5.0-fix-last-reached-page
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.
- package/README.md +26 -26
- package/lib/components/duration/duration.js +52 -0
- package/lib/components/duration/duration.scss +17 -0
- package/lib/components/duration/durationInput.js +72 -0
- package/lib/components/duration/durationUtils.js +31 -0
- package/lib/components/duration/formatDuration.js +28 -0
- package/lib/components/duration/formatDuration.spec.js +38 -0
- package/lib/components/duration/getDurationFromValue.js +64 -0
- package/lib/components/duration/index.js +13 -0
- package/lib/components/index.js +7 -0
- package/lib/components/loop/block-for-loop/block-for-loop.js +5 -7
- package/lib/components/modal-controls/modal-controls.js +3 -5
- package/lib/components/table/table-orchestrator.js +0 -1
- package/lib/src/components/duration/duration.d.ts +4 -0
- package/lib/src/components/duration/durationInput.d.ts +7 -0
- package/lib/src/components/duration/durationUtils.d.ts +30 -0
- package/lib/src/components/duration/formatDuration.d.ts +2 -0
- package/lib/src/components/duration/formatDuration.spec.d.ts +1 -0
- package/lib/src/components/duration/getDurationFromValue.d.ts +8 -0
- package/lib/src/components/duration/index.d.ts +1 -0
- package/lib/src/components/index.d.ts +1 -0
- package/lib/src/components/loop/block-for-loop/block-for-loop.d.ts +3 -3
- package/lib/src/components/modal-controls/modal-controls.d.ts +1 -1
- package/lib/src/components/table/table-orchestrator.d.ts +1 -1
- package/lib/src/components/type.d.ts +7 -0
- package/lib/src/use-lunatic/actions.d.ts +2 -2
- package/lib/src/use-lunatic/commons/index.d.ts +6 -7
- package/lib/src/use-lunatic/reducer/reduce-on-init.spec.d.ts +1 -0
- package/lib/src/use-lunatic/use-lunatic.d.ts +12 -0
- package/lib/src/utils/object.d.ts +1 -0
- package/lib/stories/duration/duration.stories.js +41 -0
- package/lib/stories/duration/source.json +32 -0
- package/lib/stories/duration/source1.json +32 -0
- package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.spec.js +2 -0
- package/lib/use-lunatic/commons/index.js +6 -13
- package/lib/use-lunatic/reducer/reduce-on-init.js +3 -3
- package/lib/use-lunatic/reducer/reduce-on-init.spec.js +17 -0
- package/lib/use-lunatic/use-lunatic.js +1 -2
- package/lib/utils/object.js +6 -0
- package/package.json +1 -1
- package/lib/src/utils/store-tools/auto-load.d.ts +0 -6
- package/lib/use-lunatic/commons/load-suggesters.js +0 -158
- package/lib/utils/store-tools/auto-load.js +0 -162
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Lunatic
|
|
4
4
|
|
|
5
|
-
[](https://github.com/InseeFr/Lunatic/actions/workflows/quality.yml)
|
|
6
6
|
[](https://badge.fury.io/js/%40inseefr%2Flunatic)
|
|
7
7
|
[](https://sonarcloud.io/dashboard?id=InseeFr_Lunatic)
|
|
8
8
|
[](https://sonarcloud.io/dashboard?id=InseeFr_Lunatic)
|
|
@@ -10,37 +10,36 @@
|
|
|
10
10
|
|
|
11
11
|
Lunatic est une librairie front-end sous forme de hook react et de librairies de composants pour générer un questionnaire à partir du format de données [Lunatic-Model](https://github.com/InseeFr/Lunatic-Model).
|
|
12
12
|
|
|
13
|
-
- [Storybook
|
|
14
|
-
- [Storybook v1](https://inseefr.github.io/Lunatic/storybook-v1)
|
|
15
|
-
- [Storybook Beta](https://inseefr.github.io/Lunatic/storybook-beta)
|
|
16
|
-
- [Editeur Lunatic](https://inseefr.github.io/Lunatic/editor/)
|
|
13
|
+
- [Storybook](https://inseefr.github.io/Lunatic/storybook), branche `main`
|
|
14
|
+
- [Storybook v1](https://inseefr.github.io/Lunatic/storybook-v1), branche `v1-main`
|
|
15
|
+
- [Storybook Beta](https://inseefr.github.io/Lunatic/storybook-beta), branche `develop`
|
|
17
16
|
- [Documentation](https://inseefr.github.io/Lunatic/fr/)
|
|
18
17
|
|
|
19
18
|
## Sommaire
|
|
20
19
|
|
|
21
20
|
- [Lunatic](#lunatic)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
- [Sommaire](#sommaire)
|
|
22
|
+
- [Utilisation](#utilisation)
|
|
23
|
+
- [Le hook useLunatic](#le-hook-uselunatic)
|
|
24
|
+
- [Les composants](#les-composants)
|
|
25
|
+
- [Personnalisation](#personnalisation)
|
|
26
|
+
- [Fonctionnement interne](#fonctionnement-interne)
|
|
27
|
+
- [Fonctionnement général](#fonctionnement-général)
|
|
28
|
+
- [pages et pager](#pages-et-pager)
|
|
29
|
+
- [Exécution du VTL](#exécution-du-vtl)
|
|
30
|
+
- [Convention et bonnes pratiques](#convention-et-bonnes-pratiques)
|
|
32
31
|
|
|
33
32
|
## Utilisation
|
|
34
33
|
|
|
35
34
|
Pour commencer il faut installer lunatic
|
|
36
35
|
|
|
37
36
|
```bash
|
|
38
|
-
yarn add @inseefr/lunatic@2.0
|
|
37
|
+
yarn add @inseefr/lunatic@2.5.0
|
|
39
38
|
```
|
|
40
39
|
|
|
41
40
|
### Le hook useLunatic
|
|
42
41
|
|
|
43
|
-
Ensuite, à l'endroit où vous souhaitez afficher le formulaire il faudra utiliser le hook `useLunatic`.
|
|
42
|
+
Ensuite, à l'endroit où vous souhaitez afficher le formulaire il faudra utiliser le hook `useLunatic`.
|
|
44
43
|
|
|
45
44
|
```js
|
|
46
45
|
import { useLunatic } from '@inseefr/lunatic';
|
|
@@ -56,8 +55,9 @@ Ce hook prend 3 paramètres :
|
|
|
56
55
|
- **features** (défaut `['VTL', 'MD']`), permet de définir les fonctionnalité supportées
|
|
57
56
|
- **preferences** (défaut `['COLLECTED']`)
|
|
58
57
|
- **onChange** (défaut `() => {}`), permet d'ajouter une logique à appliquer lorsqu'une réponse est modifiée (doit être mémoïsé car est utilisé comme dépendance d'un useCallback en interne)
|
|
59
|
-
- **management** (défaut `false`)
|
|
58
|
+
- **management** (défaut `false`) : Non implémenté encore, permettra de gérer plusieurs état d'une même variable (utilisation par des postes de reprise)
|
|
60
59
|
- **initialPage** (défaut `'1'`), permet de définir la page de départ
|
|
60
|
+
- **lastReachedPage** (défaut `undefined`) permet de définir quelle est la page la plus lointaine déjà atteinte
|
|
61
61
|
- **autoSuggesterLoading** (défaut `false`)
|
|
62
62
|
- **suggesters**
|
|
63
63
|
- **suggesterFetcher** (défaut `fetch`), méthode utilisée pour récupérer les données du suggester
|
|
@@ -68,7 +68,7 @@ Et retourne un objet permettant de piloter le questionnaire :
|
|
|
68
68
|
- `getComponents()`, renvoie les composants à afficher pour la page courante
|
|
69
69
|
- `goPreviousPage()`, permet d'aller à la page précédente
|
|
70
70
|
- `goNextPage()`, permet d'aller à la page suivante
|
|
71
|
-
- `goToPage(page: string)`, permet d'aller à une page arbitraire
|
|
71
|
+
- `goToPage({ page: string })`, permet d'aller à une page arbitraire
|
|
72
72
|
- `getErrors()`, renvoie les erreurs
|
|
73
73
|
- `getModalErrors()`, renvoie les erreurs dans les modales
|
|
74
74
|
- `getCurrentErrors()`, renvoie les erreurs de la page courante
|
|
@@ -120,14 +120,14 @@ Par défaut les composants offerts par Lunatic sont plutôt simples avec un styl
|
|
|
120
120
|
|
|
121
121
|
```jsx
|
|
122
122
|
const custom = {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
123
|
+
Input: MyCustomInput,
|
|
124
|
+
InputNumber: MyCustomInputNumber,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
function App({ source, data }) {
|
|
128
|
+
const {} = useLunatic(source, data, { custom });
|
|
126
129
|
|
|
127
|
-
|
|
128
|
-
const {} = useLunatic(source, data, {custom})
|
|
129
|
-
|
|
130
|
-
// ...
|
|
130
|
+
// ...
|
|
131
131
|
}
|
|
132
132
|
```
|
|
133
133
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
require("./duration.scss");
|
|
8
|
+
var _commons = require("../commons");
|
|
9
|
+
var _lunaticComponentWithoutLabel = _interopRequireDefault(require("../commons/components/lunatic-component-without-label"));
|
|
10
|
+
var _durationInput = _interopRequireDefault(require("./durationInput"));
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
function Duration(props) {
|
|
14
|
+
var value = props.value,
|
|
15
|
+
label = props.label,
|
|
16
|
+
format = props.format,
|
|
17
|
+
handleChange = props.handleChange,
|
|
18
|
+
response = props.response,
|
|
19
|
+
id = props.id,
|
|
20
|
+
preferences = props.preferences,
|
|
21
|
+
declarations = props.declarations,
|
|
22
|
+
missing = props.missing,
|
|
23
|
+
missingResponse = props.missingResponse,
|
|
24
|
+
management = props.management,
|
|
25
|
+
description = props.description;
|
|
26
|
+
var onChange = (0, _commons.useOnHandleChange)({
|
|
27
|
+
handleChange: handleChange,
|
|
28
|
+
response: response,
|
|
29
|
+
value: value !== null && value !== void 0 ? value : ''
|
|
30
|
+
});
|
|
31
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_lunaticComponentWithoutLabel["default"], {
|
|
32
|
+
id: id,
|
|
33
|
+
preferences: preferences,
|
|
34
|
+
declarations: declarations,
|
|
35
|
+
value: value,
|
|
36
|
+
missing: missing,
|
|
37
|
+
missingResponse: missingResponse,
|
|
38
|
+
management: management,
|
|
39
|
+
description: description,
|
|
40
|
+
handleChange: handleChange,
|
|
41
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
42
|
+
className: "container",
|
|
43
|
+
children: [label, /*#__PURE__*/(0, _jsxRuntime.jsx)(_durationInput["default"], {
|
|
44
|
+
value: value,
|
|
45
|
+
format: format,
|
|
46
|
+
onChange: onChange
|
|
47
|
+
})]
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
var _default = Duration;
|
|
52
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _object = require("../../utils/object");
|
|
10
|
+
var _formatDuration = require("./formatDuration");
|
|
11
|
+
var _getDurationFromValue = require("./getDurationFromValue");
|
|
12
|
+
var _durationUtils = require("./durationUtils");
|
|
13
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
+
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; }
|
|
15
|
+
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; }
|
|
16
|
+
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; }
|
|
17
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
18
|
+
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); }
|
|
19
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
20
|
+
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."); }
|
|
21
|
+
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); }
|
|
22
|
+
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; }
|
|
23
|
+
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; } }
|
|
24
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
25
|
+
var DurationInput = function DurationInput(_ref) {
|
|
26
|
+
var value = _ref.value,
|
|
27
|
+
format = _ref.format,
|
|
28
|
+
onChange = _ref.onChange;
|
|
29
|
+
// We need to keep an internal state since one field can be empty (null value in duration)
|
|
30
|
+
// but we still send "0" and we don't want the field to display "0"
|
|
31
|
+
var _useState = (0, _react.useState)((0, _getDurationFromValue.getDurationFromValue)(value, format)),
|
|
32
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
+
duration = _useState2[0],
|
|
34
|
+
setDuration = _useState2[1];
|
|
35
|
+
|
|
36
|
+
// Generate handler for a specific unit field (year, month...)
|
|
37
|
+
var changeHandler = function changeHandler(unit) {
|
|
38
|
+
return function (e) {
|
|
39
|
+
if (!e.target.checkValidity()) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
var fieldValue = Number.isNaN(e.target.valueAsNumber) ? null : e.target.valueAsNumber;
|
|
43
|
+
var newDuration = _objectSpread(_objectSpread({}, duration), {}, _defineProperty({}, unit, fieldValue));
|
|
44
|
+
onChange((0, _formatDuration.formatDuration)(newDuration));
|
|
45
|
+
setDuration(newDuration);
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
49
|
+
className: "field-group",
|
|
50
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
51
|
+
className: "input-field-group",
|
|
52
|
+
children: (0, _object.objectKeys)(duration).map(function (unit) {
|
|
53
|
+
var _duration$unit;
|
|
54
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
55
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
|
|
56
|
+
htmlFor: "".concat(unit, "Input"),
|
|
57
|
+
className: "input-label",
|
|
58
|
+
children: _durationUtils.labelByUnit[unit]
|
|
59
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread({
|
|
60
|
+
id: "".concat(unit, "Input"),
|
|
61
|
+
type: "number",
|
|
62
|
+
value: (_duration$unit = duration[unit]) !== null && _duration$unit !== void 0 ? _duration$unit : '',
|
|
63
|
+
className: "input-field",
|
|
64
|
+
onChange: changeHandler(unit)
|
|
65
|
+
}, _durationUtils.propsByUnit[unit]))]
|
|
66
|
+
}, unit);
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
var _default = DurationInput;
|
|
72
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.propsByUnit = exports.labelByUnit = void 0;
|
|
7
|
+
var propsByUnit = {
|
|
8
|
+
hours: {
|
|
9
|
+
min: '0',
|
|
10
|
+
max: '23'
|
|
11
|
+
},
|
|
12
|
+
minutes: {
|
|
13
|
+
min: '0',
|
|
14
|
+
max: '59'
|
|
15
|
+
},
|
|
16
|
+
months: {
|
|
17
|
+
min: '0',
|
|
18
|
+
max: '11'
|
|
19
|
+
},
|
|
20
|
+
years: {
|
|
21
|
+
min: '0'
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.propsByUnit = propsByUnit;
|
|
25
|
+
var labelByUnit = {
|
|
26
|
+
hours: 'Heures :',
|
|
27
|
+
minutes: 'Minutes :',
|
|
28
|
+
months: 'Mois : ',
|
|
29
|
+
years: 'Années :'
|
|
30
|
+
};
|
|
31
|
+
exports.labelByUnit = labelByUnit;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.formatDuration = void 0;
|
|
7
|
+
var formatDuration = function formatDuration(duration) {
|
|
8
|
+
var prefix = 'hours' in duration && 'minutes' in duration ? 'PT' : 'P';
|
|
9
|
+
// The duration has no numeric value (all nulls), then return null
|
|
10
|
+
if (Object.values(duration).filter(function (v) {
|
|
11
|
+
return v !== null;
|
|
12
|
+
}).length === 0) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Recreate unit so we can control the unit order for formatting
|
|
17
|
+
var units = ['years', 'months', 'hours', 'minutes'];
|
|
18
|
+
var durationParts = '';
|
|
19
|
+
for (var _i = 0, _units = units; _i < _units.length; _i++) {
|
|
20
|
+
var unit = _units[_i];
|
|
21
|
+
if (unit in duration) {
|
|
22
|
+
var _duration$unit;
|
|
23
|
+
durationParts += ((_duration$unit = duration[unit]) !== null && _duration$unit !== void 0 ? _duration$unit : 0) + unit[0].toUpperCase();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return prefix + durationParts;
|
|
27
|
+
};
|
|
28
|
+
exports.formatDuration = formatDuration;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _formatDuration = require("./formatDuration");
|
|
5
|
+
(0, _vitest.describe)('formatDuration', function () {
|
|
6
|
+
(0, _vitest.it)('should format time correctly', function () {
|
|
7
|
+
(0, _vitest.expect)((0, _formatDuration.formatDuration)({
|
|
8
|
+
hours: 12,
|
|
9
|
+
minutes: 15
|
|
10
|
+
})).toEqual('PT12H15M');
|
|
11
|
+
(0, _vitest.expect)((0, _formatDuration.formatDuration)({
|
|
12
|
+
hours: 14,
|
|
13
|
+
minutes: 50
|
|
14
|
+
})).toEqual('PT14H50M');
|
|
15
|
+
(0, _vitest.expect)((0, _formatDuration.formatDuration)({
|
|
16
|
+
hours: null,
|
|
17
|
+
minutes: null
|
|
18
|
+
})).toEqual(null);
|
|
19
|
+
});
|
|
20
|
+
(0, _vitest.it)('should format date correctly', function () {
|
|
21
|
+
(0, _vitest.expect)((0, _formatDuration.formatDuration)({
|
|
22
|
+
years: 12,
|
|
23
|
+
months: 15
|
|
24
|
+
})).toEqual('P12Y15M');
|
|
25
|
+
(0, _vitest.expect)((0, _formatDuration.formatDuration)({
|
|
26
|
+
years: 14,
|
|
27
|
+
months: 50
|
|
28
|
+
})).toEqual('P14Y50M');
|
|
29
|
+
(0, _vitest.expect)((0, _formatDuration.formatDuration)({
|
|
30
|
+
years: 14,
|
|
31
|
+
months: null
|
|
32
|
+
})).toEqual('P14Y0M');
|
|
33
|
+
(0, _vitest.expect)((0, _formatDuration.formatDuration)({
|
|
34
|
+
years: null,
|
|
35
|
+
months: null
|
|
36
|
+
})).toEqual(null);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDurationFromValue = void 0;
|
|
7
|
+
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
|
8
|
+
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."); }
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
11
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
/**
|
|
14
|
+
* Convert a string into a duration
|
|
15
|
+
*
|
|
16
|
+
* ## Example
|
|
17
|
+
* - "P12Y5M" => {year: 12, month: 5}
|
|
18
|
+
*/
|
|
19
|
+
var getDurationFromValue = function getDurationFromValue(value, format) {
|
|
20
|
+
// Handle nulls value
|
|
21
|
+
if (value === null && format === 'PTnHnM') {
|
|
22
|
+
return {
|
|
23
|
+
hours: null,
|
|
24
|
+
minutes: null
|
|
25
|
+
};
|
|
26
|
+
} else if (value === null) {
|
|
27
|
+
return {
|
|
28
|
+
years: null,
|
|
29
|
+
months: null
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
var match = matchFromFormat(value, format);
|
|
33
|
+
if (format === 'PTnHnM') {
|
|
34
|
+
return {
|
|
35
|
+
hours: match[0],
|
|
36
|
+
minutes: match[1]
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
years: match[0],
|
|
41
|
+
months: match[1]
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Generate a regexp from the format to extract the numbers from the string
|
|
47
|
+
*
|
|
48
|
+
* ## Example :
|
|
49
|
+
* - "P12Y3M" => [12, 3]
|
|
50
|
+
*/
|
|
51
|
+
exports.getDurationFromValue = getDurationFromValue;
|
|
52
|
+
var matchFromFormat = function matchFromFormat(value, format) {
|
|
53
|
+
var regex = new RegExp(format.replaceAll('n', '(\\d+)'));
|
|
54
|
+
var match = value.match(regex);
|
|
55
|
+
if (!match) {
|
|
56
|
+
throw new Error("Invalid duration value \"".concat(value, "\" does not match the format \"").concat(format, "\""));
|
|
57
|
+
}
|
|
58
|
+
var _match = _toArray(match),
|
|
59
|
+
_ = _match[0],
|
|
60
|
+
matches = _match.slice(1);
|
|
61
|
+
return matches.map(function (v) {
|
|
62
|
+
return parseInt(v, 10);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _duration["default"];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _duration = _interopRequireDefault(require("./duration"));
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
package/lib/components/index.js
CHANGED
|
@@ -51,6 +51,12 @@ Object.defineProperty(exports, "Dropdown", {
|
|
|
51
51
|
return _dropdown["default"];
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
+
Object.defineProperty(exports, "Duration", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function get() {
|
|
57
|
+
return _duration["default"];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
54
60
|
Object.defineProperty(exports, "FilterDescription", {
|
|
55
61
|
enumerable: true,
|
|
56
62
|
get: function get() {
|
|
@@ -194,6 +200,7 @@ var _suggesterLoaderWidget = _interopRequireDefault(require("./suggester-loader-
|
|
|
194
200
|
var _roundabout = _interopRequireDefault(require("./roundabout"));
|
|
195
201
|
var _table = _interopRequireDefault(require("./table"));
|
|
196
202
|
var _componentSet = _interopRequireDefault(require("./component-set"));
|
|
203
|
+
var _duration = _interopRequireDefault(require("./duration"));
|
|
197
204
|
var _summary = require("./summary");
|
|
198
205
|
var _questionInformation = _interopRequireDefault(require("./questions/question-information"));
|
|
199
206
|
var _questionContext = _interopRequireDefault(require("./questions/question-context"));
|
|
@@ -5,17 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = void 0;
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _i18n = _interopRequireDefault(require("../../../i18n"));
|
|
9
10
|
var _commons = require("../../commons");
|
|
10
11
|
var _declarations = require("../../declarations");
|
|
11
|
-
var _blockForLoopOchestrator = _interopRequireDefault(require("./block-for-loop-ochestrator"));
|
|
12
|
-
var _handleRowButton = _interopRequireDefault(require("../commons/handle-row-button"));
|
|
13
|
-
var _i18n = _interopRequireDefault(require("../../../i18n"));
|
|
14
12
|
var _getInitLength = _interopRequireDefault(require("../commons/get-init-length"));
|
|
13
|
+
var _handleRowButton = _interopRequireDefault(require("../commons/handle-row-button"));
|
|
14
|
+
var _blockForLoopOchestrator = _interopRequireDefault(require("./block-for-loop-ochestrator"));
|
|
15
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
|
-
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); }
|
|
18
|
-
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; }
|
|
19
17
|
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; }
|
|
20
18
|
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; }
|
|
21
19
|
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; }
|
|
@@ -120,7 +118,7 @@ function BlockForLoop(_ref) {
|
|
|
120
118
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_declarations.DeclarationsDetachable, {
|
|
121
119
|
declarations: declarations,
|
|
122
120
|
id: id
|
|
123
|
-
}), min && max && min !== max && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
121
|
+
}), Number.isInteger(min) && Number.isInteger(max) && min !== max && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
124
122
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_handleRowButton["default"], {
|
|
125
123
|
onClick: addRow,
|
|
126
124
|
disabled: nbRows === max,
|
|
@@ -5,13 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
8
|
var _closeOrSkip = _interopRequireDefault(require("./close-or-skip"));
|
|
10
9
|
var _modalContainer = _interopRequireDefault(require("./modal-container"));
|
|
11
10
|
require("./modal-controls.scss");
|
|
12
11
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
-
|
|
14
|
-
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; }
|
|
12
|
+
var _react = require("react");
|
|
15
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
16
14
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
17
15
|
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."); }
|
|
@@ -25,7 +23,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
25
23
|
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; }
|
|
26
24
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
27
25
|
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); }
|
|
28
|
-
function
|
|
26
|
+
function ErrorItem(_ref) {
|
|
29
27
|
var criticality = _ref.criticality,
|
|
30
28
|
errorMessage = _ref.errorMessage;
|
|
31
29
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
@@ -36,7 +34,7 @@ function Error(_ref) {
|
|
|
36
34
|
function ComponentErrors(_ref2) {
|
|
37
35
|
var errors = _ref2.errors;
|
|
38
36
|
var content = errors.map(function (error, index) {
|
|
39
|
-
return /*#__PURE__*/(0, _react.createElement)(
|
|
37
|
+
return /*#__PURE__*/(0, _react.createElement)(ErrorItem, _objectSpread(_objectSpread({}, error), {}, {
|
|
40
38
|
key: index
|
|
41
39
|
}));
|
|
42
40
|
}, []);
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
7
|
var _row = _interopRequireDefault(require("./row"));
|
|
9
8
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Formats } from './durationUtils';
|
|
2
|
+
declare const DurationInput: ({ value, format, onChange, }: {
|
|
3
|
+
value: string | null;
|
|
4
|
+
format: Formats;
|
|
5
|
+
onChange: (s: string | null) => void;
|
|
6
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default DurationInput;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type DurationValue = {
|
|
2
|
+
hours?: number | null;
|
|
3
|
+
minutes?: number | null;
|
|
4
|
+
years?: number | null;
|
|
5
|
+
months?: number | null;
|
|
6
|
+
};
|
|
7
|
+
export type Formats = 'PTnHnM' | 'PnYnM';
|
|
8
|
+
export declare const propsByUnit: {
|
|
9
|
+
hours: {
|
|
10
|
+
min: string;
|
|
11
|
+
max: string;
|
|
12
|
+
};
|
|
13
|
+
minutes: {
|
|
14
|
+
min: string;
|
|
15
|
+
max: string;
|
|
16
|
+
};
|
|
17
|
+
months: {
|
|
18
|
+
min: string;
|
|
19
|
+
max: string;
|
|
20
|
+
};
|
|
21
|
+
years: {
|
|
22
|
+
min: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare const labelByUnit: {
|
|
26
|
+
hours: string;
|
|
27
|
+
minutes: string;
|
|
28
|
+
months: string;
|
|
29
|
+
years: string;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Formats, DurationValue } from './durationUtils';
|
|
2
|
+
/**
|
|
3
|
+
* Convert a string into a duration
|
|
4
|
+
*
|
|
5
|
+
* ## Example
|
|
6
|
+
* - "P12Y5M" => {year: 12, month: 5}
|
|
7
|
+
*/
|
|
8
|
+
export declare const getDurationFromValue: (value: string | null, format: Formats) => DurationValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./duration";
|
|
@@ -22,6 +22,7 @@ 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 { Summary } from './summary';
|
|
26
27
|
export { default as QuestionInformation } from './questions/question-information';
|
|
27
28
|
export { default as QuestionContext } from './questions/question-context';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
declare const _default:
|
|
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;
|
|
@@ -14,7 +14,7 @@ declare const _default: React.ComponentType<import("../../type").LunaticBaseProp
|
|
|
14
14
|
} | undefined) => T;
|
|
15
15
|
value: Record<string, unknown[]>;
|
|
16
16
|
headers?: {
|
|
17
|
-
label:
|
|
17
|
+
label: import("react").ReactNode;
|
|
18
18
|
}[] | undefined;
|
|
19
19
|
paginatedLoop?: boolean | undefined;
|
|
20
20
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { LunaticComponentProps } from '../type';
|
|
2
|
-
type Props =
|
|
2
|
+
type Props = Pick<LunaticComponentProps<'Table'>, 'body' | 'id' | 'executeExpression' | 'value' | 'handleChange' | 'iteration'>;
|
|
3
3
|
declare function TableOrchestrator({ body, id, executeExpression, value: valueMap, handleChange, iteration, }: Props): import("react/jsx-runtime").JSX.Element | null;
|
|
4
4
|
export default TableOrchestrator;
|