@inseefr/lunatic 0.3.6-experimental → 0.3.7-experimental
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/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/package.json +3 -2
- package/src/components/index.js +2 -0
- package/src/components/suggester/components/create-on-keydown-callback.js +28 -28
- package/src/stories/checkbox-group/data-vtl.json +102 -102
- package/src/utils/to-expose/handler.js +14 -12
- package/src/utils/to-expose/hooks/lunatic-split.js +2 -5
- package/src/utils/to-expose/hooks/lunatic.js +2 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inseefr/lunatic",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7-experimental",
|
|
4
4
|
"workersVersion": "0.2.1-experimental",
|
|
5
5
|
"description": "Library of questionnaire components",
|
|
6
6
|
"repository": {
|
|
@@ -50,7 +50,8 @@
|
|
|
50
50
|
"library"
|
|
51
51
|
],
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@inseefr/trevas": "^0.1.
|
|
53
|
+
"@inseefr/trevas": "^0.1.12",
|
|
54
|
+
"array-flat-polyfill": "^1.0.1",
|
|
54
55
|
"date-fns": "^2.25.0",
|
|
55
56
|
"lodash.camelcase": "^4.3.0",
|
|
56
57
|
"lodash.debounce": "^4.0.8",
|
package/src/components/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { actions } from '../state-management';
|
|
2
|
-
import { BINDED_KEYS } from '../commons-tools';
|
|
3
|
-
|
|
4
|
-
function create(dispatch) {
|
|
5
|
-
return function (e) {
|
|
6
|
-
const { key } = e;
|
|
7
|
-
switch (key) {
|
|
8
|
-
case BINDED_KEYS.Tab:
|
|
9
|
-
e.stopPropagation();
|
|
10
|
-
// e.preventDefault();
|
|
11
|
-
dispatch(actions.onKeyDown(key));
|
|
12
|
-
break;
|
|
13
|
-
case BINDED_KEYS.ArrowDown:
|
|
14
|
-
case BINDED_KEYS.ArrowUp:
|
|
15
|
-
case BINDED_KEYS.Home:
|
|
16
|
-
case BINDED_KEYS.End:
|
|
17
|
-
case BINDED_KEYS.Enter:
|
|
18
|
-
case BINDED_KEYS.Escape:
|
|
19
|
-
e.preventDefault();
|
|
20
|
-
e.stopPropagation();
|
|
21
|
-
dispatch(actions.onKeyDown(key));
|
|
22
|
-
break;
|
|
23
|
-
default:
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default create;
|
|
1
|
+
import { actions } from '../state-management';
|
|
2
|
+
import { BINDED_KEYS } from '../commons-tools';
|
|
3
|
+
|
|
4
|
+
function create(dispatch) {
|
|
5
|
+
return function (e) {
|
|
6
|
+
const { key } = e;
|
|
7
|
+
switch (key) {
|
|
8
|
+
case BINDED_KEYS.Tab:
|
|
9
|
+
e.stopPropagation();
|
|
10
|
+
// e.preventDefault();
|
|
11
|
+
dispatch(actions.onKeyDown(key));
|
|
12
|
+
break;
|
|
13
|
+
case BINDED_KEYS.ArrowDown:
|
|
14
|
+
case BINDED_KEYS.ArrowUp:
|
|
15
|
+
case BINDED_KEYS.Home:
|
|
16
|
+
case BINDED_KEYS.End:
|
|
17
|
+
case BINDED_KEYS.Enter:
|
|
18
|
+
case BINDED_KEYS.Escape:
|
|
19
|
+
e.preventDefault();
|
|
20
|
+
e.stopPropagation();
|
|
21
|
+
dispatch(actions.onKeyDown(key));
|
|
22
|
+
break;
|
|
23
|
+
default:
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default create;
|
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
{
|
|
2
|
-
"components": [
|
|
3
|
-
{
|
|
4
|
-
"id": "gg",
|
|
5
|
-
"componentType": "CheckboxGroup",
|
|
6
|
-
"label": "➡ 1. What are the pet names that the Simpsons family had?",
|
|
7
|
-
"missingResponse": { "name": "PET_MISSING" },
|
|
8
|
-
"responses": [
|
|
9
|
-
{
|
|
10
|
-
"id": "j334akov-QOP-jbgd8qmn",
|
|
11
|
-
"label": "Santa's Little Helper",
|
|
12
|
-
"response": {
|
|
13
|
-
"name": "PET1"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"id": "j334akov-QOP-jbgd60vl",
|
|
18
|
-
"label": "Snowball I",
|
|
19
|
-
"response": {
|
|
20
|
-
"name": "PET2"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"id": "j334akov-QOP-jbgda2jo",
|
|
25
|
-
"label": "Coltrane",
|
|
26
|
-
"response": {
|
|
27
|
-
"name": "PET3"
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"id": "j334akov-QOP-jbgdfssy",
|
|
32
|
-
"label": "NAME || \" the Helper Monkey\"",
|
|
33
|
-
"response": {
|
|
34
|
-
"name": "PET4"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
],
|
|
40
|
-
"variables": [
|
|
41
|
-
{
|
|
42
|
-
"variableType": "COLLECTED",
|
|
43
|
-
"name": "PET1",
|
|
44
|
-
"componentRef": "gg",
|
|
45
|
-
"values": {
|
|
46
|
-
"PREVIOUS": null,
|
|
47
|
-
"COLLECTED": true,
|
|
48
|
-
"FORCED": false,
|
|
49
|
-
"EDITED": null,
|
|
50
|
-
"INPUTED": null
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
"variableType": "COLLECTED",
|
|
55
|
-
"name": "PET2",
|
|
56
|
-
"componentRef": "gg",
|
|
57
|
-
"values": {
|
|
58
|
-
"PREVIOUS": null,
|
|
59
|
-
"COLLECTED": true,
|
|
60
|
-
"FORCED": null,
|
|
61
|
-
"EDITED": null,
|
|
62
|
-
"INPUTED": null
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
"variableType": "COLLECTED",
|
|
67
|
-
"name": "PET3",
|
|
68
|
-
"componentRef": "gg",
|
|
69
|
-
"values": {
|
|
70
|
-
"PREVIOUS": null,
|
|
71
|
-
"COLLECTED": null,
|
|
72
|
-
"FORCED": null,
|
|
73
|
-
"EDITED": null,
|
|
74
|
-
"INPUTED": null
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"variableType": "COLLECTED",
|
|
79
|
-
"name": "PET4",
|
|
80
|
-
"componentRef": "gg",
|
|
81
|
-
"values": {
|
|
82
|
-
"PREVIOUS": null,
|
|
83
|
-
"COLLECTED": null,
|
|
84
|
-
"FORCED": null,
|
|
85
|
-
"EDITED": null,
|
|
86
|
-
"INPUTED": null
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
"variableType": "COLLECTED",
|
|
91
|
-
"name": "PET_MISSING",
|
|
92
|
-
"componentRef": "gg",
|
|
93
|
-
"values": {
|
|
94
|
-
"PREVIOUS": null,
|
|
95
|
-
"COLLECTED": null,
|
|
96
|
-
"FORCED": null,
|
|
97
|
-
"EDITED": null,
|
|
98
|
-
"INPUTED": null
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
]
|
|
102
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"components": [
|
|
3
|
+
{
|
|
4
|
+
"id": "gg",
|
|
5
|
+
"componentType": "CheckboxGroup",
|
|
6
|
+
"label": "➡ 1. What are the pet names that the Simpsons family had?",
|
|
7
|
+
"missingResponse": { "name": "PET_MISSING" },
|
|
8
|
+
"responses": [
|
|
9
|
+
{
|
|
10
|
+
"id": "j334akov-QOP-jbgd8qmn",
|
|
11
|
+
"label": "Santa's Little Helper",
|
|
12
|
+
"response": {
|
|
13
|
+
"name": "PET1"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "j334akov-QOP-jbgd60vl",
|
|
18
|
+
"label": "Snowball I",
|
|
19
|
+
"response": {
|
|
20
|
+
"name": "PET2"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"id": "j334akov-QOP-jbgda2jo",
|
|
25
|
+
"label": "Coltrane",
|
|
26
|
+
"response": {
|
|
27
|
+
"name": "PET3"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"id": "j334akov-QOP-jbgdfssy",
|
|
32
|
+
"label": "NAME || \" the Helper Monkey\"",
|
|
33
|
+
"response": {
|
|
34
|
+
"name": "PET4"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"variables": [
|
|
41
|
+
{
|
|
42
|
+
"variableType": "COLLECTED",
|
|
43
|
+
"name": "PET1",
|
|
44
|
+
"componentRef": "gg",
|
|
45
|
+
"values": {
|
|
46
|
+
"PREVIOUS": null,
|
|
47
|
+
"COLLECTED": true,
|
|
48
|
+
"FORCED": false,
|
|
49
|
+
"EDITED": null,
|
|
50
|
+
"INPUTED": null
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"variableType": "COLLECTED",
|
|
55
|
+
"name": "PET2",
|
|
56
|
+
"componentRef": "gg",
|
|
57
|
+
"values": {
|
|
58
|
+
"PREVIOUS": null,
|
|
59
|
+
"COLLECTED": true,
|
|
60
|
+
"FORCED": null,
|
|
61
|
+
"EDITED": null,
|
|
62
|
+
"INPUTED": null
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"variableType": "COLLECTED",
|
|
67
|
+
"name": "PET3",
|
|
68
|
+
"componentRef": "gg",
|
|
69
|
+
"values": {
|
|
70
|
+
"PREVIOUS": null,
|
|
71
|
+
"COLLECTED": null,
|
|
72
|
+
"FORCED": null,
|
|
73
|
+
"EDITED": null,
|
|
74
|
+
"INPUTED": null
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"variableType": "COLLECTED",
|
|
79
|
+
"name": "PET4",
|
|
80
|
+
"componentRef": "gg",
|
|
81
|
+
"values": {
|
|
82
|
+
"PREVIOUS": null,
|
|
83
|
+
"COLLECTED": null,
|
|
84
|
+
"FORCED": null,
|
|
85
|
+
"EDITED": null,
|
|
86
|
+
"INPUTED": null
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"variableType": "COLLECTED",
|
|
91
|
+
"name": "PET_MISSING",
|
|
92
|
+
"componentRef": "gg",
|
|
93
|
+
"values": {
|
|
94
|
+
"PREVIOUS": null,
|
|
95
|
+
"COLLECTED": null,
|
|
96
|
+
"FORCED": null,
|
|
97
|
+
"EDITED": null,
|
|
98
|
+
"INPUTED": null
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
@@ -60,7 +60,7 @@ export const updateQuestionnaire =
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
export const updateExternals =
|
|
63
|
-
(questionnaire) => (logFunction
|
|
63
|
+
(questionnaire) => (logFunction) => (updatedValues) => {
|
|
64
64
|
const { variables, ...other } = questionnaire;
|
|
65
65
|
const { EXTERNAL } = variables;
|
|
66
66
|
const newVariables = {
|
|
@@ -71,7 +71,8 @@ export const updateExternals =
|
|
|
71
71
|
const newVariablesWithCalculated = addCalculatedVars(
|
|
72
72
|
newVariables,
|
|
73
73
|
updatedValues
|
|
74
|
-
)(logFunction
|
|
74
|
+
)(logFunction);
|
|
75
|
+
|
|
75
76
|
return {
|
|
76
77
|
...other,
|
|
77
78
|
variables: newVariablesWithCalculated,
|
|
@@ -93,29 +94,30 @@ export const buildNewValue =
|
|
|
93
94
|
|
|
94
95
|
// Separate methods to avoid perf issue on collect simplest use case
|
|
95
96
|
const getCollectedAndExternal = (preferences) => (variables) => {
|
|
96
|
-
const { COLLECTED
|
|
97
|
+
const { COLLECTED } = variables;
|
|
97
98
|
if (preferences.length === 1 && preferences[0] === 'COLLECTED')
|
|
98
|
-
return
|
|
99
|
-
return
|
|
100
|
-
...getCollectedAndExternalByPreferences(preferences)(COLLECTED),
|
|
101
|
-
...EXTERNAL,
|
|
102
|
-
};
|
|
99
|
+
return getCollectedAndExternalSimple(COLLECTED);
|
|
100
|
+
return getCollectedAndExternalByPreferences(preferences)(COLLECTED);
|
|
103
101
|
};
|
|
104
102
|
|
|
105
|
-
const getCollectedAndExternalSimple = (variables) =>
|
|
106
|
-
Object.entries(variables).reduce(
|
|
103
|
+
const getCollectedAndExternalSimple = (variables) => {
|
|
104
|
+
const collected = Object.entries(variables).reduce(
|
|
107
105
|
(acc, [k, { values }]) => ({ ...acc, [k]: values.COLLECTED }),
|
|
108
106
|
{}
|
|
109
107
|
);
|
|
108
|
+
return { ...collected, ...variables.EXTERNAL };
|
|
109
|
+
};
|
|
110
110
|
|
|
111
|
-
const getCollectedAndExternalByPreferences = (preferences) => (variables) =>
|
|
112
|
-
Object.entries(variables).reduce((acc, [k, { values }]) => {
|
|
111
|
+
const getCollectedAndExternalByPreferences = (preferences) => (variables) => {
|
|
112
|
+
const collected = Object.entries(variables).reduce((acc, [k, { values }]) => {
|
|
113
113
|
const v = preferences.reduce((acc, p) => {
|
|
114
114
|
const value = values[p];
|
|
115
115
|
return [null, ''].includes(value) ? acc : value;
|
|
116
116
|
}, null);
|
|
117
117
|
return { ...acc, [k]: v };
|
|
118
118
|
}, {});
|
|
119
|
+
return { ...collected, ...variables.EXTERNAL };
|
|
120
|
+
};
|
|
119
121
|
|
|
120
122
|
const addCalculatedVars =
|
|
121
123
|
(variables, updatedValues) => (logFunction, preferences) => {
|
|
@@ -361,14 +361,11 @@ const useLunaticSplit = (
|
|
|
361
361
|
|
|
362
362
|
useEffect(() => {
|
|
363
363
|
if (Object.keys(todoExternals).length !== 0) {
|
|
364
|
-
const newQ = updateExternals(questionnaire)(logFunction
|
|
365
|
-
todoExternals
|
|
366
|
-
);
|
|
367
|
-
setBindings(getBindings(newQ));
|
|
364
|
+
const newQ = updateExternals(questionnaire)(logFunction)(todoExternals);
|
|
368
365
|
setQuestionnaire(newQ);
|
|
369
366
|
setTodoExternals({});
|
|
370
367
|
}
|
|
371
|
-
}, [todoExternals, logFunction, questionnaire
|
|
368
|
+
}, [todoExternals, logFunction, questionnaire]);
|
|
372
369
|
|
|
373
370
|
const cancelModal = () => {
|
|
374
371
|
setModalContent(null);
|
|
@@ -216,14 +216,11 @@ const useLunatic = (
|
|
|
216
216
|
|
|
217
217
|
useEffect(() => {
|
|
218
218
|
if (Object.keys(todoExternals).length !== 0) {
|
|
219
|
-
const newQ = updateExternals(questionnaire)(logFunction
|
|
220
|
-
todoExternals
|
|
221
|
-
);
|
|
222
|
-
setBindings(getBindings(newQ));
|
|
219
|
+
const newQ = updateExternals(questionnaire)(logFunction)(todoExternals);
|
|
223
220
|
setQuestionnaire(newQ);
|
|
224
221
|
setTodoExternals({});
|
|
225
222
|
}
|
|
226
|
-
}, [todoExternals, logFunction, questionnaire
|
|
223
|
+
}, [todoExternals, logFunction, questionnaire]);
|
|
227
224
|
|
|
228
225
|
const cancelModal = () => {
|
|
229
226
|
setModalContent(null);
|