@inseefr/lunatic 3.5.0 → 3.5.1
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/components/Datepicker/Datepicker.js +3 -60
- package/components/Datepicker/Datepicker.js.map +1 -1
- package/components/Datepicker/DatepickerFields.d.ts +8 -0
- package/components/Datepicker/DatepickerFields.js +60 -0
- package/components/Datepicker/DatepickerFields.js.map +1 -0
- package/components/Duration/durationUtils.d.ts +0 -1
- package/components/Duration/durationUtils.js.map +1 -1
- package/components/Duration/getDurationFromValue.d.ts +3 -2
- package/components/Duration/getDurationFromValue.js.map +1 -1
- package/components/shared/HOC/slottableComponent.d.ts +2 -0
- package/components/shared/HOC/slottableComponent.js.map +1 -1
- package/components/type.d.ts +2 -3
- package/esm/components/Datepicker/Datepicker.js +3 -60
- package/esm/components/Datepicker/Datepicker.js.map +1 -1
- package/esm/components/Datepicker/DatepickerFields.d.ts +8 -0
- package/esm/components/Datepicker/DatepickerFields.js +57 -0
- package/esm/components/Datepicker/DatepickerFields.js.map +1 -0
- package/esm/components/Duration/durationUtils.d.ts +0 -1
- package/esm/components/Duration/durationUtils.js.map +1 -1
- package/esm/components/Duration/getDurationFromValue.d.ts +3 -2
- package/esm/components/Duration/getDurationFromValue.js.map +1 -1
- package/esm/components/shared/HOC/slottableComponent.d.ts +2 -0
- package/esm/components/shared/HOC/slottableComponent.js.map +1 -1
- package/esm/components/type.d.ts +2 -3
- package/esm/use-lunatic/commons/fill-components/fill-components.d.ts +2 -0
- package/esm/use-lunatic/commons/fill-components/fill-components.js +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/esm/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +3 -3
- package/esm/use-lunatic/commons/variables/behaviours/resizing-behaviour.js.map +1 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js +17 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
- package/esm/use-lunatic/props/getComponentTypeProps.d.ts +1 -1
- package/esm/use-lunatic/props/propOptions.d.ts +2 -1
- package/esm/use-lunatic/props/propOptions.js +23 -3
- package/esm/use-lunatic/props/propOptions.js.map +1 -1
- package/esm/use-lunatic/props/propOptions.spec.js +46 -5
- package/esm/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/esm/use-lunatic/type.d.ts +18 -4
- package/esm/use-lunatic/use-lunatic.js +2 -3
- package/esm/use-lunatic/use-lunatic.js.map +1 -1
- package/package.json +8 -1
- package/src/components/Datepicker/Datepicker.tsx +4 -117
- package/src/components/Datepicker/DatepickerFields.tsx +127 -0
- package/src/components/Duration/Duration.test.tsx +2 -2
- package/src/components/Duration/durationUtils.ts +0 -2
- package/src/components/Duration/getDurationFromValue.ts +4 -3
- package/src/components/shared/HOC/slottableComponent.tsx +4 -0
- package/src/components/type.ts +2 -2
- package/src/use-lunatic/commons/fill-components/fill-components.ts +4 -1
- package/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.ts +2 -5
- package/src/use-lunatic/commons/variables/lunatic-variables-store.spec.ts +17 -1
- package/src/use-lunatic/props/propOptions.spec.ts +71 -5
- package/src/use-lunatic/props/propOptions.ts +23 -3
- package/src/use-lunatic/type.ts +18 -4
- package/src/use-lunatic/use-lunatic.test.ts +13 -23
- package/src/use-lunatic/use-lunatic.ts +2 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/use-lunatic/commons/fill-components/fill-components.d.ts +2 -0
- package/use-lunatic/commons/fill-components/fill-components.js +1 -1
- package/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +3 -3
- package/use-lunatic/commons/variables/behaviours/resizing-behaviour.js.map +1 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.spec.js +17 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
- package/use-lunatic/props/getComponentTypeProps.d.ts +1 -1
- package/use-lunatic/props/propOptions.d.ts +2 -1
- package/use-lunatic/props/propOptions.js +23 -3
- package/use-lunatic/props/propOptions.js.map +1 -1
- package/use-lunatic/props/propOptions.spec.js +46 -5
- package/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/use-lunatic/type.d.ts +18 -4
- package/use-lunatic/use-lunatic.js +2 -3
- package/use-lunatic/use-lunatic.js.map +1 -1
|
@@ -3,74 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CustomDatepicker = void 0;
|
|
4
4
|
exports.Datepicker = Datepicker;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
const react_1 = require("react");
|
|
7
|
-
const DatepickerField_1 = require("./DatepickerField");
|
|
8
6
|
const slottableComponent_1 = require("../shared/HOC/slottableComponent");
|
|
9
7
|
const Label_1 = require("../shared/Label/Label");
|
|
10
8
|
const ComponentErrors_1 = require("../shared/ComponentErrors/ComponentErrors");
|
|
11
9
|
const Declarations_1 = require("../shared/Declarations/Declarations");
|
|
10
|
+
const DatepickerFields_1 = require("./DatepickerFields");
|
|
12
11
|
function Datepicker({ dateFormat = 'YYYY-MM-DD', response, handleChanges, errors, ...props }) {
|
|
13
12
|
return ((0, jsx_runtime_1.jsx)(exports.CustomDatepicker, { ...props, dateFormat: dateFormat ?? 'YYYY-MM-DD', onChange: (value) => handleChanges([{ name: response.name, value }]), errors: (0, ComponentErrors_1.getComponentErrors)(errors, props.id) }));
|
|
14
13
|
}
|
|
15
14
|
exports.CustomDatepicker = (0, slottableComponent_1.slottableComponent)('Datepicker', (props) => {
|
|
16
|
-
const {
|
|
15
|
+
const { id, label, errors, description, declarations } = props;
|
|
17
16
|
const labelId = `lunatic-datepicker-${id}`;
|
|
18
|
-
|
|
19
|
-
const showMonth = dateFormat.includes('MM');
|
|
20
|
-
// Raw state, we allow invalid dates to be typed
|
|
21
|
-
const [numbers, setNumbers] = (0, react_1.useState)(() => numbersFromDateString(value ?? undefined));
|
|
22
|
-
const setNumber = (index) => (value) => {
|
|
23
|
-
const newNumbers = [...numbers];
|
|
24
|
-
newNumbers[index] = value;
|
|
25
|
-
setNumbers(newNumbers);
|
|
26
|
-
onNumbersChange(newNumbers);
|
|
27
|
-
};
|
|
28
|
-
const onNumbersChange = (numbers) => {
|
|
29
|
-
const formatParts = dateFormat.split('-');
|
|
30
|
-
const hasNaNIndex = numbers.findIndex((v) => Number.isNaN(v));
|
|
31
|
-
// Date has a missing part
|
|
32
|
-
if (hasNaNIndex > -1 && hasNaNIndex <= formatParts.length - 1) {
|
|
33
|
-
onChange(null);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
// Date is not valid
|
|
37
|
-
if (dateFormat === 'YYYY-MM-DD' && !isDateValid(numbers)) {
|
|
38
|
-
onChange(null);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const result = formatParts
|
|
42
|
-
.map((v, k) => numbers[k].toString().padStart(v.length, '0'))
|
|
43
|
-
.join('-');
|
|
44
|
-
onChange(result);
|
|
45
|
-
};
|
|
46
|
-
const extraProps = {
|
|
47
|
-
readOnly,
|
|
48
|
-
disabled,
|
|
49
|
-
};
|
|
50
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "lunatic-input", children: [(0, jsx_runtime_1.jsx)(Label_1.Label, { htmlFor: id, id: labelId, description: description, children: label }), (0, jsx_runtime_1.jsx)(Declarations_1.Declarations, { type: "AFTER_QUESTION_TEXT", declarations: declarations, id: id }), (0, jsx_runtime_1.jsxs)("div", { className: "lunaticDatepickerFields", children: [showDay && ((0, jsx_runtime_1.jsx)(DatepickerField_1.DatepickerField, { id: id + 'day', label: "Jour", description: "Exemple: 14", max: 31, value: numbers[2], onChange: setNumber(2), ...extraProps })), showMonth && ((0, jsx_runtime_1.jsx)(DatepickerField_1.DatepickerField, { id: id + 'month', label: "Mois", description: "Exemple: 7", max: 12, value: numbers[1], onChange: setNumber(1), ...extraProps })), (0, jsx_runtime_1.jsx)(DatepickerField_1.DatepickerField, { id: id + 'year', label: "Ann\u00E9e", description: "Exemple: 2023", value: numbers[0], max: 9999, onChange: setNumber(0), ...extraProps })] }), (0, jsx_runtime_1.jsx)(ComponentErrors_1.ComponentErrors, { errors: errors })] }));
|
|
17
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "lunatic-input", children: [(0, jsx_runtime_1.jsx)(Label_1.Label, { htmlFor: id, id: labelId, description: description, children: label }), (0, jsx_runtime_1.jsx)(Declarations_1.Declarations, { type: "AFTER_QUESTION_TEXT", declarations: declarations, id: id }), (0, jsx_runtime_1.jsx)(DatepickerFields_1.CustomDatepickerFields, { ...props }), (0, jsx_runtime_1.jsx)(ComponentErrors_1.ComponentErrors, { errors: errors })] }));
|
|
51
18
|
});
|
|
52
|
-
function numbersFromDateString(s) {
|
|
53
|
-
if (!s) {
|
|
54
|
-
return [NaN, NaN, NaN];
|
|
55
|
-
}
|
|
56
|
-
const parts = s.split('-');
|
|
57
|
-
return [
|
|
58
|
-
parseInt(parts[0], 10),
|
|
59
|
-
parseInt(parts[1], 10),
|
|
60
|
-
parseInt(parts[2], 10),
|
|
61
|
-
];
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Check if the date provided by the user is valid (e.g. not 2001/02/29)
|
|
65
|
-
*/
|
|
66
|
-
function isDateValid(dateArray) {
|
|
67
|
-
const [year, month, day] = dateArray;
|
|
68
|
-
// do not set the date directly on new Date(), to avoid transformation on year between 0 and 99.
|
|
69
|
-
//See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#year
|
|
70
|
-
const date = new Date();
|
|
71
|
-
date.setFullYear(year, month - 1, day);
|
|
72
|
-
return (date.getFullYear() === year &&
|
|
73
|
-
date.getMonth() === month - 1 &&
|
|
74
|
-
date.getDate() === day);
|
|
75
|
-
}
|
|
76
19
|
//# sourceMappingURL=Datepicker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Datepicker.js","sourceRoot":"","sources":["../../src/components/Datepicker/Datepicker.tsx"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Datepicker.js","sourceRoot":"","sources":["../../src/components/Datepicker/Datepicker.tsx"],"names":[],"mappings":";;;AAWA,gCAeC;;AA1BD,yEAAsE;AAEtE,iDAA8C;AAC9C,+EAGmD;AACnD,sEAAmE;AAEnE,yDAA4D;AAE5D,SAAgB,UAAU,CAAC,EAC1B,UAAU,GAAG,YAAY,EACzB,QAAQ,EACR,aAAa,EACb,MAAM,EACN,GAAG,KAAK,EAC6B;IACrC,OAAO,CACN,uBAAC,wBAAgB,OACZ,KAAK,EACT,UAAU,EAAE,UAAU,IAAI,YAAY,EACtC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,EACpE,MAAM,EAAE,IAAA,oCAAkB,EAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,GAC3C,CACF,CAAC;AACH,CAAC;AAUY,QAAA,gBAAgB,GAAG,IAAA,uCAAkB,EACjD,YAAY,EACZ,CAAC,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAE/D,MAAM,OAAO,GAAG,sBAAsB,EAAE,EAAE,CAAC;IAE3C,OAAO,CACN,iCAAK,SAAS,EAAC,eAAe,aAC7B,uBAAC,aAAK,IAAC,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,YACvD,KAAK,GACC,EACR,uBAAC,2BAAY,IACZ,IAAI,EAAC,qBAAqB,EAC1B,YAAY,EAAE,YAAY,EAC1B,EAAE,EAAE,EAAE,GACL,EACF,uBAAC,yCAAsB,OAAK,KAAK,GAAI,EACrC,uBAAC,iCAAe,IAAC,MAAM,EAAE,MAAM,GAAI,IAC9B,CACN,CAAC;AACH,CAAC,CACD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LunaticComponentProps } from '../type';
|
|
2
|
+
import { LunaticError } from '../../use-lunatic/type';
|
|
3
|
+
type CustomProps = Omit<LunaticComponentProps<'Datepicker'>, 'response' | 'handleChanges' | 'errors'> & {
|
|
4
|
+
onChange: (s: string | null) => void;
|
|
5
|
+
errors?: LunaticError[];
|
|
6
|
+
};
|
|
7
|
+
export declare const CustomDatepickerFields: import("react").ComponentType<CustomProps>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomDatepickerFields = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const slottableComponent_1 = require("../shared/HOC/slottableComponent");
|
|
7
|
+
const DatepickerField_1 = require("./DatepickerField");
|
|
8
|
+
exports.CustomDatepickerFields = (0, slottableComponent_1.slottableComponent)('DatepickerFields', (props) => {
|
|
9
|
+
const { disabled, readOnly, value = '', dateFormat = 'YYYY-MM-DD', id, onChange, } = props;
|
|
10
|
+
const showDay = dateFormat.includes('DD');
|
|
11
|
+
const showMonth = dateFormat.includes('MM');
|
|
12
|
+
// Raw state, we allow invalid dates to be typed
|
|
13
|
+
const [numbers, setNumbers] = (0, react_1.useState)(() => numbersFromDateString(value ?? undefined));
|
|
14
|
+
const setNumber = (index) => (value) => {
|
|
15
|
+
const newNumbers = [...numbers];
|
|
16
|
+
newNumbers[index] = value;
|
|
17
|
+
setNumbers(newNumbers);
|
|
18
|
+
onNumbersChange(newNumbers);
|
|
19
|
+
};
|
|
20
|
+
const onNumbersChange = (numbers) => {
|
|
21
|
+
const formatParts = dateFormat.split('-');
|
|
22
|
+
const hasNaNIndex = numbers.findIndex((v) => Number.isNaN(v));
|
|
23
|
+
// Date is not valid, or date has a missing part
|
|
24
|
+
if ((dateFormat === 'YYYY-MM-DD' && !isDateValid(numbers)) ||
|
|
25
|
+
(hasNaNIndex > -1 && hasNaNIndex <= formatParts.length - 1)) {
|
|
26
|
+
onChange(null);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const result = formatParts
|
|
30
|
+
.map((v, k) => numbers[k].toString().padStart(v.length, '0'))
|
|
31
|
+
.join('-');
|
|
32
|
+
onChange(result);
|
|
33
|
+
};
|
|
34
|
+
const extraProps = {
|
|
35
|
+
readOnly,
|
|
36
|
+
disabled,
|
|
37
|
+
};
|
|
38
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "lunaticDatepickerFields", children: [showDay && ((0, jsx_runtime_1.jsx)(DatepickerField_1.DatepickerField, { id: id + 'day', label: "Jour", description: "Exemple: 14", max: 31, value: numbers[2], onChange: setNumber(2), ...extraProps })), showMonth && ((0, jsx_runtime_1.jsx)(DatepickerField_1.DatepickerField, { id: id + 'month', label: "Mois", description: "Exemple: 7", max: 12, value: numbers[1], onChange: setNumber(1), ...extraProps })), (0, jsx_runtime_1.jsx)(DatepickerField_1.DatepickerField, { id: id + 'year', label: "Ann\u00E9e", description: "Exemple: 2023", value: numbers[0], max: 9999, onChange: setNumber(0), ...extraProps })] }));
|
|
39
|
+
});
|
|
40
|
+
function numbersFromDateString(s) {
|
|
41
|
+
if (!s) {
|
|
42
|
+
return [NaN, NaN, NaN];
|
|
43
|
+
}
|
|
44
|
+
const [year, month, day] = s.split('-').map((part) => parseInt(part, 10));
|
|
45
|
+
return [year, month, day];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if the date provided by the user is valid (e.g. not 2001/02/29)
|
|
49
|
+
*/
|
|
50
|
+
function isDateValid(dateArray) {
|
|
51
|
+
const [year, month, day] = dateArray;
|
|
52
|
+
// do not set the date directly on new Date(), to avoid transformation on year between 0 and 99.
|
|
53
|
+
//See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#year
|
|
54
|
+
const date = new Date();
|
|
55
|
+
date.setFullYear(year, month - 1, day);
|
|
56
|
+
return (date.getFullYear() === year &&
|
|
57
|
+
date.getMonth() === month - 1 &&
|
|
58
|
+
date.getDate() === day);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=DatepickerFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatepickerFields.js","sourceRoot":"","sources":["../../src/components/Datepicker/DatepickerFields.tsx"],"names":[],"mappings":";;;;AAAA,iCAAiC;AACjC,yEAAsE;AAEtE,uDAAoD;AAWvC,QAAA,sBAAsB,GAAG,IAAA,uCAAkB,EACvD,kBAAkB,EAClB,CAAC,KAAK,EAAE,EAAE;IACT,MAAM,EACL,QAAQ,EACR,QAAQ,EACR,KAAK,GAAG,EAAE,EACV,UAAU,GAAG,YAAY,EACzB,EAAE,EACF,QAAQ,GACR,GAAG,KAAK,CAAC;IAEV,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE5C,gDAAgD;IAChD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAC,GAAG,EAAE,CAC3C,qBAAqB,CAAC,KAAK,IAAI,SAAS,CAAC,CACzC,CAAC;IACF,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,KAAa,EAAE,EAAE;QACtD,MAAM,UAAU,GAAG,CAAC,GAAG,OAAO,CAAmB,CAAC;QAClD,UAAU,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;QAC1B,UAAU,CAAC,UAAU,CAAC,CAAC;QACvB,eAAe,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC,CAAC;IAEF,MAAM,eAAe,GAAG,CAAC,OAAiC,EAAE,EAAE;QAC7D,MAAM,WAAW,GAAG,UAAU,CAA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version":3,"file":"durationUtils.js","sourceRoot":"","sources":["../../src/components/Duration/durationUtils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"durationUtils.js","sourceRoot":"","sources":["../../src/components/Duration/durationUtils.ts"],"names":[],"mappings":";;;AAqBA,sCAeC;AA7BY,QAAA,WAAW,GAAG;IAC1B,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IAC9D,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IAChE,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IAC/D,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;CACnD,CAAC;AAEW,QAAA,WAAW,GAAG;IAC1B,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,WAAW;IACpB,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,UAAU;CACjB,CAAC;AAEF,SAAgB,aAAa,CAC5B,KAAoB,EACpB,IAA8B;IAE9B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACd,CAAC;IACD,MAAM,KAAK,GAAG,mBAAW,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC,GAAG,CAAC;IAClB,CAAC;IACD,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC,GAAG,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DurationFormat } from '../type';
|
|
2
|
+
import { type DurationValue } from './durationUtils';
|
|
2
3
|
/**
|
|
3
4
|
* Convert a string into a duration
|
|
4
5
|
*
|
|
5
6
|
* ## Example
|
|
6
7
|
* - "P12Y5M" => {year: 12, month: 5}
|
|
7
8
|
*/
|
|
8
|
-
export declare const getDurationFromValue: (value: string | null, format:
|
|
9
|
+
export declare const getDurationFromValue: (value: string | null, format: DurationFormat) => DurationValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDurationFromValue.js","sourceRoot":"","sources":["../../src/components/Duration/getDurationFromValue.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getDurationFromValue.js","sourceRoot":"","sources":["../../src/components/Duration/getDurationFromValue.ts"],"names":[],"mappings":";;;AAGA;;;;;GAKG;AACI,MAAM,oBAAoB,GAAG,CACnC,KAAoB,EACpB,MAAsB,EACN,EAAE;IAClB,qBAAqB;IACrB,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC3C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACvC,CAAC;SAAM,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAC3B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACtC,CAAC;IAED,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC7C,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;QACzB,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/C,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAC9C,CAAC,CAAC;AAhBW,QAAA,oBAAoB,wBAgB/B;AAEF;;;;;GAKG;AACH,MAAM,eAAe,GAAG,CAAC,KAAa,EAAE,MAAsB,EAAY,EAAE;IAC3E,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACd,2BAA2B,KAAK,gCAAgC,MAAM,GAAG,CACzE,CAAC;IACH,CAAC;IACD,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,KAAK,CAAC;IAC7B,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC5C,CAAC,CAAC"}
|
|
@@ -37,6 +37,7 @@ import type { SummaryResponses, SummaryTitle } from '../../Summary/Summary';
|
|
|
37
37
|
import type { LunaticComponentProps } from '../../type';
|
|
38
38
|
import type { MarkdownLink } from '../MDLabel/MarkdownLink';
|
|
39
39
|
import type { Accordion } from '../../Accordion/Accordion';
|
|
40
|
+
import type { CustomDatepickerFields } from '../../Datepicker/DatepickerFields';
|
|
40
41
|
/**
|
|
41
42
|
* Contain the type of every customizable components.
|
|
42
43
|
*/
|
|
@@ -67,6 +68,7 @@ export type LunaticSlotComponents = {
|
|
|
67
68
|
ComboboxInput: typeof ComboboxInput;
|
|
68
69
|
ComboboxClearButton: typeof ComboboxClearButton;
|
|
69
70
|
ComboboxLabelSelection: typeof ComboboxLabelSelection;
|
|
71
|
+
DatepickerFields: typeof CustomDatepickerFields;
|
|
70
72
|
Roundabout: typeof CustomRoundabout;
|
|
71
73
|
SuggesterNotification: typeof SuggesterNotification;
|
|
72
74
|
SummaryTitle: typeof SummaryTitle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slottableComponent.js","sourceRoot":"","sources":["../../../src/components/shared/HOC/slottableComponent.tsx"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"slottableComponent.js","sourceRoot":"","sources":["../../../src/components/shared/HOC/slottableComponent.tsx"],"names":[],"mappings":";;;AA4IA,gDAkBC;;AA9JD,iCAMe;AA+Gf,MAAM,KAAK,GAAG,EAAgD,CAAC;AAE/D,MAAM,YAAY,GAAG,IAAA,qBAAa,EAAC,KAAK,CAAC,CAAC;AAEnC,MAAM,aAAa,GAAG,CAAC,EAC7B,KAAK,EACL,QAAQ,GACuD,EAAE,EAAE;IACnE,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,2DAAG,QAAQ,GAAI,CAAC;IACxB,CAAC;IACD,OAAO,CACN,uBAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAAI,KAAK,YAC1C,QAAQ,GACc,CACxB,CAAC;AACH,CAAC,CAAC;AAZW,QAAA,aAAa,iBAYxB;AAEF;;;;GAIG;AACH,SAAgB,kBAAkB,CACjC,IAAiC,EACjC,iBAAuC;IAEvC,MAAM,kBAAkB,GAAG,CAAC,KAAQ,EAAE,EAAE;QACvC,MAAM,MAAM,GAAG,IAAA,kBAAU,EAAC,YAAY,CAAC,IAAI,KAAK,CAAC;QAEjD,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;YAC9B,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAqB,CAAC;YACvD,uCAAuC;YACvC,OAAO,uBAAC,aAAa,OAAK,KAAK,GAAI,CAAC;QACrC,CAAC;QAED,uCAAuC;QACvC,OAAO,uBAAC,iBAAiB,OAAK,KAAK,GAAI,CAAC;IACzC,CAAC,CAAC;IACF,kBAAkB,CAAC,WAAW,GAAG,IAAI,CAAC;IACtC,OAAO,kBAAkB,CAAC;AAC3B,CAAC"}
|
package/components/type.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { CSSProperties, FunctionComponent, ReactNode } from 'react';
|
|
|
2
2
|
import { useLunatic } from '../use-lunatic/use-lunatic';
|
|
3
3
|
import type { LunaticChangesHandler, LunaticComponentDefinition, LunaticError, LunaticOptions, LunaticReducerState } from '../use-lunatic/type';
|
|
4
4
|
import type { InterpretedOption } from '../use-lunatic/props/propOptions';
|
|
5
|
-
type
|
|
5
|
+
export type DurationFormat = 'PTnHnM' | 'PnYnM';
|
|
6
6
|
export type VtlExpression = {
|
|
7
7
|
value: string;
|
|
8
8
|
type: 'VTL' | 'VTL|MD' | 'TXT';
|
|
@@ -69,7 +69,7 @@ export type ComponentPropsByType = {
|
|
|
69
69
|
componentType?: 'InputNumber';
|
|
70
70
|
};
|
|
71
71
|
Duration: LunaticBaseProps<string | null> & LunaticExtraProps & {
|
|
72
|
-
format:
|
|
72
|
+
format: DurationFormat;
|
|
73
73
|
response: {
|
|
74
74
|
name: string;
|
|
75
75
|
};
|
|
@@ -306,4 +306,3 @@ export type ComponentPropsByType = {
|
|
|
306
306
|
};
|
|
307
307
|
export type LunaticComponentType = keyof ComponentPropsByType;
|
|
308
308
|
export type LunaticComponentProps<T extends LunaticComponentType = LunaticComponentType> = ComponentPropsByType[T];
|
|
309
|
-
export {};
|
|
@@ -1,72 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { DatepickerField } from './DatepickerField';
|
|
4
2
|
import { slottableComponent } from '../shared/HOC/slottableComponent';
|
|
5
3
|
import { Label } from '../shared/Label/Label';
|
|
6
4
|
import { ComponentErrors, getComponentErrors, } from '../shared/ComponentErrors/ComponentErrors';
|
|
7
5
|
import { Declarations } from '../shared/Declarations/Declarations';
|
|
6
|
+
import { CustomDatepickerFields } from './DatepickerFields';
|
|
8
7
|
export function Datepicker({ dateFormat = 'YYYY-MM-DD', response, handleChanges, errors, ...props }) {
|
|
9
8
|
return (_jsx(CustomDatepicker, { ...props, dateFormat: dateFormat !== null && dateFormat !== void 0 ? dateFormat : 'YYYY-MM-DD', onChange: (value) => handleChanges([{ name: response.name, value }]), errors: getComponentErrors(errors, props.id) }));
|
|
10
9
|
}
|
|
11
10
|
export const CustomDatepicker = slottableComponent('Datepicker', (props) => {
|
|
12
|
-
const {
|
|
11
|
+
const { id, label, errors, description, declarations } = props;
|
|
13
12
|
const labelId = `lunatic-datepicker-${id}`;
|
|
14
|
-
|
|
15
|
-
const showMonth = dateFormat.includes('MM');
|
|
16
|
-
// Raw state, we allow invalid dates to be typed
|
|
17
|
-
const [numbers, setNumbers] = useState(() => numbersFromDateString(value !== null && value !== void 0 ? value : undefined));
|
|
18
|
-
const setNumber = (index) => (value) => {
|
|
19
|
-
const newNumbers = [...numbers];
|
|
20
|
-
newNumbers[index] = value;
|
|
21
|
-
setNumbers(newNumbers);
|
|
22
|
-
onNumbersChange(newNumbers);
|
|
23
|
-
};
|
|
24
|
-
const onNumbersChange = (numbers) => {
|
|
25
|
-
const formatParts = dateFormat.split('-');
|
|
26
|
-
const hasNaNIndex = numbers.findIndex((v) => Number.isNaN(v));
|
|
27
|
-
// Date has a missing part
|
|
28
|
-
if (hasNaNIndex > -1 && hasNaNIndex <= formatParts.length - 1) {
|
|
29
|
-
onChange(null);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
// Date is not valid
|
|
33
|
-
if (dateFormat === 'YYYY-MM-DD' && !isDateValid(numbers)) {
|
|
34
|
-
onChange(null);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const result = formatParts
|
|
38
|
-
.map((v, k) => numbers[k].toString().padStart(v.length, '0'))
|
|
39
|
-
.join('-');
|
|
40
|
-
onChange(result);
|
|
41
|
-
};
|
|
42
|
-
const extraProps = {
|
|
43
|
-
readOnly,
|
|
44
|
-
disabled,
|
|
45
|
-
};
|
|
46
|
-
return (_jsxs("div", { className: "lunatic-input", children: [_jsx(Label, { htmlFor: id, id: labelId, description: description, children: label }), _jsx(Declarations, { type: "AFTER_QUESTION_TEXT", declarations: declarations, id: id }), _jsxs("div", { className: "lunaticDatepickerFields", children: [showDay && (_jsx(DatepickerField, { id: id + 'day', label: "Jour", description: "Exemple: 14", max: 31, value: numbers[2], onChange: setNumber(2), ...extraProps })), showMonth && (_jsx(DatepickerField, { id: id + 'month', label: "Mois", description: "Exemple: 7", max: 12, value: numbers[1], onChange: setNumber(1), ...extraProps })), _jsx(DatepickerField, { id: id + 'year', label: "Ann\u00E9e", description: "Exemple: 2023", value: numbers[0], max: 9999, onChange: setNumber(0), ...extraProps })] }), _jsx(ComponentErrors, { errors: errors })] }));
|
|
13
|
+
return (_jsxs("div", { className: "lunatic-input", children: [_jsx(Label, { htmlFor: id, id: labelId, description: description, children: label }), _jsx(Declarations, { type: "AFTER_QUESTION_TEXT", declarations: declarations, id: id }), _jsx(CustomDatepickerFields, { ...props }), _jsx(ComponentErrors, { errors: errors })] }));
|
|
47
14
|
});
|
|
48
|
-
function numbersFromDateString(s) {
|
|
49
|
-
if (!s) {
|
|
50
|
-
return [NaN, NaN, NaN];
|
|
51
|
-
}
|
|
52
|
-
const parts = s.split('-');
|
|
53
|
-
return [
|
|
54
|
-
parseInt(parts[0], 10),
|
|
55
|
-
parseInt(parts[1], 10),
|
|
56
|
-
parseInt(parts[2], 10),
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Check if the date provided by the user is valid (e.g. not 2001/02/29)
|
|
61
|
-
*/
|
|
62
|
-
function isDateValid(dateArray) {
|
|
63
|
-
const [year, month, day] = dateArray;
|
|
64
|
-
// do not set the date directly on new Date(), to avoid transformation on year between 0 and 99.
|
|
65
|
-
//See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#year
|
|
66
|
-
const date = new Date();
|
|
67
|
-
date.setFullYear(year, month - 1, day);
|
|
68
|
-
return (date.getFullYear() === year &&
|
|
69
|
-
date.getMonth() === month - 1 &&
|
|
70
|
-
date.getDate() === day);
|
|
71
|
-
}
|
|
72
15
|
//# sourceMappingURL=Datepicker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Datepicker.js","sourceRoot":"","sources":["../../../src/components/Datepicker/Datepicker.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Datepicker.js","sourceRoot":"","sources":["../../../src/components/Datepicker/Datepicker.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EACN,eAAe,EACf,kBAAkB,GAClB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAEnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,UAAU,UAAU,CAAC,EAC1B,UAAU,GAAG,YAAY,EACzB,QAAQ,EACR,aAAa,EACb,MAAM,EACN,GAAG,KAAK,EAC6B;IACrC,OAAO,CACN,KAAC,gBAAgB,OACZ,KAAK,EACT,UAAU,EAAE,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,YAAY,EACtC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,EACpE,MAAM,EAAE,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,GAC3C,CACF,CAAC;AACH,CAAC;AAUD,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CACjD,YAAY,EACZ,CAAC,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAE/D,MAAM,OAAO,GAAG,sBAAsB,EAAE,EAAE,CAAC;IAE3C,OAAO,CACN,eAAK,SAAS,EAAC,eAAe,aAC7B,KAAC,KAAK,IAAC,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,YACvD,KAAK,GACC,EACR,KAAC,YAAY,IACZ,IAAI,EAAC,qBAAqB,EAC1B,YAAY,EAAE,YAAY,EAC1B,EAAE,EAAE,EAAE,GACL,EACF,KAAC,sBAAsB,OAAK,KAAK,GAAI,EACrC,KAAC,eAAe,IAAC,MAAM,EAAE,MAAM,GAAI,IAC9B,CACN,CAAC;AACH,CAAC,CACD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LunaticComponentProps } from '../type';
|
|
2
|
+
import { LunaticError } from '../../use-lunatic/type';
|
|
3
|
+
type CustomProps = Omit<LunaticComponentProps<'Datepicker'>, 'response' | 'handleChanges' | 'errors'> & {
|
|
4
|
+
onChange: (s: string | null) => void;
|
|
5
|
+
errors?: LunaticError[];
|
|
6
|
+
};
|
|
7
|
+
export declare const CustomDatepickerFields: import("react").ComponentType<CustomProps>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { slottableComponent } from '../shared/HOC/slottableComponent';
|
|
4
|
+
import { DatepickerField } from './DatepickerField';
|
|
5
|
+
export const CustomDatepickerFields = slottableComponent('DatepickerFields', (props) => {
|
|
6
|
+
const { disabled, readOnly, value = '', dateFormat = 'YYYY-MM-DD', id, onChange, } = props;
|
|
7
|
+
const showDay = dateFormat.includes('DD');
|
|
8
|
+
const showMonth = dateFormat.includes('MM');
|
|
9
|
+
// Raw state, we allow invalid dates to be typed
|
|
10
|
+
const [numbers, setNumbers] = useState(() => numbersFromDateString(value !== null && value !== void 0 ? value : undefined));
|
|
11
|
+
const setNumber = (index) => (value) => {
|
|
12
|
+
const newNumbers = [...numbers];
|
|
13
|
+
newNumbers[index] = value;
|
|
14
|
+
setNumbers(newNumbers);
|
|
15
|
+
onNumbersChange(newNumbers);
|
|
16
|
+
};
|
|
17
|
+
const onNumbersChange = (numbers) => {
|
|
18
|
+
const formatParts = dateFormat.split('-');
|
|
19
|
+
const hasNaNIndex = numbers.findIndex((v) => Number.isNaN(v));
|
|
20
|
+
// Date is not valid, or date has a missing part
|
|
21
|
+
if ((dateFormat === 'YYYY-MM-DD' && !isDateValid(numbers)) ||
|
|
22
|
+
(hasNaNIndex > -1 && hasNaNIndex <= formatParts.length - 1)) {
|
|
23
|
+
onChange(null);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const result = formatParts
|
|
27
|
+
.map((v, k) => numbers[k].toString().padStart(v.length, '0'))
|
|
28
|
+
.join('-');
|
|
29
|
+
onChange(result);
|
|
30
|
+
};
|
|
31
|
+
const extraProps = {
|
|
32
|
+
readOnly,
|
|
33
|
+
disabled,
|
|
34
|
+
};
|
|
35
|
+
return (_jsxs("div", { className: "lunaticDatepickerFields", children: [showDay && (_jsx(DatepickerField, { id: id + 'day', label: "Jour", description: "Exemple: 14", max: 31, value: numbers[2], onChange: setNumber(2), ...extraProps })), showMonth && (_jsx(DatepickerField, { id: id + 'month', label: "Mois", description: "Exemple: 7", max: 12, value: numbers[1], onChange: setNumber(1), ...extraProps })), _jsx(DatepickerField, { id: id + 'year', label: "Ann\u00E9e", description: "Exemple: 2023", value: numbers[0], max: 9999, onChange: setNumber(0), ...extraProps })] }));
|
|
36
|
+
});
|
|
37
|
+
function numbersFromDateString(s) {
|
|
38
|
+
if (!s) {
|
|
39
|
+
return [NaN, NaN, NaN];
|
|
40
|
+
}
|
|
41
|
+
const [year, month, day] = s.split('-').map((part) => parseInt(part, 10));
|
|
42
|
+
return [year, month, day];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if the date provided by the user is valid (e.g. not 2001/02/29)
|
|
46
|
+
*/
|
|
47
|
+
function isDateValid(dateArray) {
|
|
48
|
+
const [year, month, day] = dateArray;
|
|
49
|
+
// do not set the date directly on new Date(), to avoid transformation on year between 0 and 99.
|
|
50
|
+
//See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#year
|
|
51
|
+
const date = new Date();
|
|
52
|
+
date.setFullYear(year, month - 1, day);
|
|
53
|
+
return (date.getFullYear() === year &&
|
|
54
|
+
date.getMonth() === month - 1 &&
|
|
55
|
+
date.getDate() === day);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=DatepickerFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatepickerFields.js","sourceRoot":"","sources":["../../../src/components/Datepicker/DatepickerFields.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAWpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CACvD,kBAAkB,EAClB,CAAC,KAAK,EAAE,EAAE;IACT,MAAM,EACL,QAAQ,EACR,QAAQ,EACR,KAAK,GAAG,EAAE,EACV,UAAU,GAAG,YAAY,EACzB,EAAE,EACF,QAAQ,GACR,GAAG,KAAK,CAAC;IAEV,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE5C,gDAAgD;IAChD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,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CAAC,SAAmC;IACvD,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;IAErC,gGAAgG;IAChG,qGAAqG;IACrG,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IACxB,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAEvC,OAAO,CACN,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI;QAC3B,IAAI,CAAC,QAAQ,EAAE,KAAK,KAAK,GAAG,CAAC;QAC7B,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,CACtB,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durationUtils.js","sourceRoot":"","sources":["../../../src/components/Duration/durationUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"durationUtils.js","sourceRoot":"","sources":["../../../src/components/Duration/durationUtils.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,WAAW,GAAG;IAC1B,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IAC9D,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IAChE,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IAC/D,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;CACnD,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG;IAC1B,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,WAAW;IACpB,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,UAAU;CACjB,CAAC;AAEF,MAAM,UAAU,aAAa,CAC5B,KAAoB,EACpB,IAA8B;IAE9B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACd,CAAC;IACD,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC,GAAG,CAAC;IAClB,CAAC;IACD,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC,GAAG,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DurationFormat } from '../type';
|
|
2
|
+
import { type DurationValue } from './durationUtils';
|
|
2
3
|
/**
|
|
3
4
|
* Convert a string into a duration
|
|
4
5
|
*
|
|
5
6
|
* ## Example
|
|
6
7
|
* - "P12Y5M" => {year: 12, month: 5}
|
|
7
8
|
*/
|
|
8
|
-
export declare const getDurationFromValue: (value: string | null, format:
|
|
9
|
+
export declare const getDurationFromValue: (value: string | null, format: DurationFormat) => DurationValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDurationFromValue.js","sourceRoot":"","sources":["../../../src/components/Duration/getDurationFromValue.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDurationFromValue.js","sourceRoot":"","sources":["../../../src/components/Duration/getDurationFromValue.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CACnC,KAAoB,EACpB,MAAsB,EACN,EAAE;IAClB,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,7 @@ import type { SummaryResponses, SummaryTitle } from '../../Summary/Summary';
|
|
|
37
37
|
import type { LunaticComponentProps } from '../../type';
|
|
38
38
|
import type { MarkdownLink } from '../MDLabel/MarkdownLink';
|
|
39
39
|
import type { Accordion } from '../../Accordion/Accordion';
|
|
40
|
+
import type { CustomDatepickerFields } from '../../Datepicker/DatepickerFields';
|
|
40
41
|
/**
|
|
41
42
|
* Contain the type of every customizable components.
|
|
42
43
|
*/
|
|
@@ -67,6 +68,7 @@ export type LunaticSlotComponents = {
|
|
|
67
68
|
ComboboxInput: typeof ComboboxInput;
|
|
68
69
|
ComboboxClearButton: typeof ComboboxClearButton;
|
|
69
70
|
ComboboxLabelSelection: typeof ComboboxLabelSelection;
|
|
71
|
+
DatepickerFields: typeof CustomDatepickerFields;
|
|
70
72
|
Roundabout: typeof CustomRoundabout;
|
|
71
73
|
SuggesterNotification: typeof SuggesterNotification;
|
|
72
74
|
SummaryTitle: typeof SummaryTitle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slottableComponent.js","sourceRoot":"","sources":["../../../../src/components/shared/HOC/slottableComponent.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEN,aAAa,EAGb,UAAU,GACV,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"slottableComponent.js","sourceRoot":"","sources":["../../../../src/components/shared/HOC/slottableComponent.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEN,aAAa,EAGb,UAAU,GACV,MAAM,OAAO,CAAC;AA+Gf,MAAM,KAAK,GAAG,EAAgD,CAAC;AAE/D,MAAM,YAAY,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;AAE1C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAC7B,KAAK,EACL,QAAQ,GACuD,EAAE,EAAE;IACnE,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,4BAAG,QAAQ,GAAI,CAAC;IACxB,CAAC;IACD,OAAO,CACN,KAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,KAAK,YAC1C,QAAQ,GACc,CACxB,CAAC;AACH,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CACjC,IAAiC,EACjC,iBAAuC;IAEvC,MAAM,kBAAkB,GAAG,CAAC,KAAQ,EAAE,EAAE;;QACvC,MAAM,MAAM,GAAG,MAAA,UAAU,CAAC,YAAY,CAAC,mCAAI,KAAK,CAAC;QAEjD,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;YAC9B,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAqB,CAAC;YACvD,uCAAuC;YACvC,OAAO,KAAC,aAAa,OAAK,KAAK,GAAI,CAAC;QACrC,CAAC;QAED,uCAAuC;QACvC,OAAO,KAAC,iBAAiB,OAAK,KAAK,GAAI,CAAC;IACzC,CAAC,CAAC;IACF,kBAAkB,CAAC,WAAW,GAAG,IAAI,CAAC;IACtC,OAAO,kBAAkB,CAAC;AAC3B,CAAC"}
|
package/esm/components/type.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { CSSProperties, FunctionComponent, ReactNode } from 'react';
|
|
|
2
2
|
import { useLunatic } from '../use-lunatic/use-lunatic';
|
|
3
3
|
import type { LunaticChangesHandler, LunaticComponentDefinition, LunaticError, LunaticOptions, LunaticReducerState } from '../use-lunatic/type';
|
|
4
4
|
import type { InterpretedOption } from '../use-lunatic/props/propOptions';
|
|
5
|
-
type
|
|
5
|
+
export type DurationFormat = 'PTnHnM' | 'PnYnM';
|
|
6
6
|
export type VtlExpression = {
|
|
7
7
|
value: string;
|
|
8
8
|
type: 'VTL' | 'VTL|MD' | 'TXT';
|
|
@@ -69,7 +69,7 @@ export type ComponentPropsByType = {
|
|
|
69
69
|
componentType?: 'InputNumber';
|
|
70
70
|
};
|
|
71
71
|
Duration: LunaticBaseProps<string | null> & LunaticExtraProps & {
|
|
72
|
-
format:
|
|
72
|
+
format: DurationFormat;
|
|
73
73
|
response: {
|
|
74
74
|
name: string;
|
|
75
75
|
};
|
|
@@ -306,4 +306,3 @@ export type ComponentPropsByType = {
|
|
|
306
306
|
};
|
|
307
307
|
export type LunaticComponentType = keyof ComponentPropsByType;
|
|
308
308
|
export type LunaticComponentProps<T extends LunaticComponentType = LunaticComponentType> = ComponentPropsByType[T];
|
|
309
|
-
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { LunaticChangesHandler, LunaticComponentDefinition, LunaticOptions, LunaticReducerState, LunaticState } from '../../type';
|
|
2
2
|
import type { LunaticComponentProps } from '../../../components/type';
|
|
3
|
+
import { LunaticLogger } from '../../logger/type';
|
|
3
4
|
type FillComponentArgs = {
|
|
4
5
|
disableFilters?: boolean;
|
|
5
6
|
handleChanges: LunaticChangesHandler;
|
|
@@ -12,6 +13,7 @@ type FillComponentArgs = {
|
|
|
12
13
|
preferences: LunaticOptions['preferences'];
|
|
13
14
|
pager: LunaticReducerState['pager'];
|
|
14
15
|
variables: LunaticReducerState['variables'];
|
|
16
|
+
logger: LunaticLogger;
|
|
15
17
|
};
|
|
16
18
|
/**
|
|
17
19
|
* To make this work with TypeScript we need to call function in succession, we prefer expressiveness here over generalized approach
|
|
@@ -25,7 +25,7 @@ export const fillComponent = (component, state) => {
|
|
|
25
25
|
missingResponse: getMissingResponseProp(component, state),
|
|
26
26
|
management: state.management,
|
|
27
27
|
iterations: getIterationsProp(component, state),
|
|
28
|
-
options: getOptionsProp(interpretedProps, state.variables, state.handleChanges, state.pager.iteration, value),
|
|
28
|
+
options: getOptionsProp(interpretedProps, state.variables, state.handleChanges, state.pager.iteration, value, state.logger),
|
|
29
29
|
...getComponentTypeProps(interpretedProps, state),
|
|
30
30
|
// This is too dynamic to be typed correctly, so we allow any here
|
|
31
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fill-components.js","sourceRoot":"","sources":["../../../../src/use-lunatic/commons/fill-components/fill-components.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"fill-components.js","sourceRoot":"","sources":["../../../../src/use-lunatic/commons/fill-components/fill-components.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAkBzD;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC5B,SAAqC,EACrC,KAAwB,EACgC,EAAE;IAC1D,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACpE,MAAM,KAAK,GAAG,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC7C,OAAO;QACN,GAAG,gBAAgB;QACnB,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS;QAChC,QAAQ,EAAE,WAAW,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK;QAChE,KAAK,EAAE,KAAK;QACZ,eAAe,EAAE,sBAAsB,CAAC,SAAS,EAAE,KAAK,CAAC;QACzD,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,UAAU,EAAE,iBAAiB,CAAC,SAAS,EAAE,KAAK,CAAC;QAC/C,OAAO,EAAE,cAAc,CACtB,gBAAgB,EAChB,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,aAAa,EACnB,KAAK,CAAC,KAAK,CAAC,SAAS,EACrB,KAAK,EACL,KAAK,CAAC,MAAM,CACZ;QACD,GAAG,qBAAqB,CAAC,gBAAgB,EAAE,KAAK,CAAC;QACjD,kEAAkE;KAC3D,CAAC;AACV,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,cAAc,CAC7B,UAAwC,EACxC,KAAwB;IAExB,OAAO,UAAU;SACf,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;SACnD,MAAM,CACN,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,IAAI,CAAC,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,IAAI,CAAC,CAC1E,CAAC;AACJ,CAAC"}
|
|
@@ -20,7 +20,7 @@ export function resizingBehaviour(store, resizing) {
|
|
|
20
20
|
}
|
|
21
21
|
// Pairwise resizing
|
|
22
22
|
if ('sizeForLinksVariables' in resizingInfo) {
|
|
23
|
-
resizePairwise(store, resizingInfo
|
|
23
|
+
resizePairwise(store, resizingInfo);
|
|
24
24
|
if (!('size' in resizingInfo)) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
@@ -39,7 +39,7 @@ export function resizingBehaviour(store, resizing) {
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
function resizePairwise(store, resizingInfo
|
|
42
|
+
function resizePairwise(store, resizingInfo) {
|
|
43
43
|
// Handle expression being sent as an array or an object (ensure backward compatibility)
|
|
44
44
|
// Issue : https://github.com/InseeFr/Lunatic/issues/883
|
|
45
45
|
const sizeExpressions = Array.isArray(resizingInfo.sizeForLinksVariables)
|
|
@@ -52,7 +52,7 @@ function resizePairwise(store, resizingInfo, args) {
|
|
|
52
52
|
return forceInt(store.run(getExpressionAsString(expression)));
|
|
53
53
|
});
|
|
54
54
|
resizingInfo.linksVariables.forEach((variable) => {
|
|
55
|
-
const value = store.get(variable
|
|
55
|
+
const value = store.get(variable);
|
|
56
56
|
const resizedValue = resizeArray(
|
|
57
57
|
// The value is not an array, force an array
|
|
58
58
|
Array.isArray(value) ? value.map((i) => resizeArray(i, ySize, null)) : [], xSize, new Array(ySize).fill(null));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resizing-behaviour.js","sourceRoot":"","sources":["../../../../../src/use-lunatic/commons/variables/behaviours/resizing-behaviour.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAChC,KAA4B,EAC5B,QAAmC;IAEnC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,OAAO;IACR,CAAC;IAED,sCAAsC;IACtC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEtD,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;QACxB,sCAAsC;QACtC,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,YAAY,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QAED,oBAAoB;QACpB,IAAI,uBAAuB,IAAI,YAAY,EAAE,CAAC;YAC7C,cAAc,CAAC,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"resizing-behaviour.js","sourceRoot":"","sources":["../../../../../src/use-lunatic/commons/variables/behaviours/resizing-behaviour.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAChC,KAA4B,EAC5B,QAAmC;IAEnC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,OAAO;IACR,CAAC;IAED,sCAAsC;IACtC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEtD,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;QACxB,sCAAsC;QACtC,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,YAAY,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QAED,oBAAoB;QACpB,IAAI,uBAAuB,IAAI,YAAY,EAAE,CAAC;YAC7C,cAAc,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YACpC,IAAI,CAAC,CAAC,MAAM,IAAI,YAAY,CA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