@inseefr/lunatic 2.7.3 → 2.7.5
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/components/commons/components/combo-box/combo-box.stories.js +0 -3
- package/lib/components/commons/components/md-label/link.js +39 -34
- package/lib/components/commons/components/md-label/md-label.js +2 -2
- package/lib/components/commons/components/md-label/md-label.spec.js +71 -0
- package/lib/components/commons/components/md-label/router-link.js +29 -0
- package/lib/components/commons/components/variable-status/variable-status.js +2 -2
- package/lib/components/datepicker/html/DatepickerField.js +1 -1
- package/lib/components/datepicker/html/__snapshots__/datepicker.spec.tsx.snap +3 -0
- package/lib/components/datepicker/html/datepicker.js +7 -6
- package/lib/components/datepicker/html/datepicker.spec.js +2 -2
- package/lib/components/datepicker/lunatic-datepicker.js +4 -4
- package/lib/components/index.scss +19 -1
- package/lib/hooks/use-auto-focus.js +1 -1
- package/lib/src/components/commons/components/md-label/router-link.d.ts +6 -0
- package/lib/src/components/datepicker/html/datepicker.d.ts +1 -1
- package/lib/src/components/datepicker/lunatic-datepicker.d.ts +1 -1
- package/lib/src/components/type.d.ts +1 -1
- package/lib/src/use-lunatic/commons/variables/lunatic-variables-store.d.ts +1 -0
- package/lib/src/use-lunatic/hooks/use-page-has-response.d.ts +6 -0
- package/lib/src/use-lunatic/use-lunatic.d.ts +3 -2
- package/lib/src/utils/suggester-workers/searching/meloto-order.d.ts +2 -1
- package/lib/stories/date-picker/datepicker.stories.js +4 -4
- package/lib/stories/markdown/markdown.stories.js +32 -0
- package/lib/stories/markdown/source.json +40 -0
- package/lib/stories/suggester/suggester-workers.stories.js +36 -1
- package/lib/stories/utils/orchestrator.js +89 -49
- package/lib/stories/utils/orchestrator.scss +49 -0
- package/lib/stories/utils/referentiel.js +8 -4
- package/lib/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +14 -9
- package/lib/use-lunatic/commons/variables/get-questionnaire-data.js +6 -1
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +33 -9
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +44 -0
- package/lib/use-lunatic/hooks/use-page-has-response.js +87 -0
- package/lib/use-lunatic/reducer/reduce-on-init.js +1 -1
- package/lib/use-lunatic/use-lunatic.js +3 -1
- package/lib/utils/env.js +1 -1
- package/lib/utils/suggester-workers/searching/meloto-order.js +6 -5
- package/package.json +2 -2
- package/workers-release/lunatic-search-worker-0.3.0.js +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"maxPages": "1",
|
|
3
|
+
"components": [
|
|
4
|
+
{
|
|
5
|
+
"componentType": "Sequence",
|
|
6
|
+
"page": "1",
|
|
7
|
+
"conditionFilter": { "value": "true", "type": "VTL" },
|
|
8
|
+
"label": { "value": "\"Sequence example\"", "type": "VTL|MD" },
|
|
9
|
+
"declarations": [
|
|
10
|
+
{
|
|
11
|
+
"id": "kb9hi4j0-krnoclfe",
|
|
12
|
+
"declarationType": "INSTRUCTION",
|
|
13
|
+
"position": "BEFORE_QUESTION_TEXT",
|
|
14
|
+
"label": {
|
|
15
|
+
"value": "\"Déclaration Before with [internal link](/docs)\"",
|
|
16
|
+
"type": "VTL|MD"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"id": "kb9hi4j0-krnoclfe",
|
|
21
|
+
"declarationType": "INSTRUCTION",
|
|
22
|
+
"position": "AFTER_QUESTION_TEXT",
|
|
23
|
+
"label": {
|
|
24
|
+
"value": "\"Déclaration AFTER with [tooltip link](https://google.com 'une infobule avec du texte très très long pour voir ce que cela donne Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.') \"",
|
|
25
|
+
"type": "VTL|MD"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "kb9hi4j0-krnoclfe",
|
|
30
|
+
"declarationType": "HELP",
|
|
31
|
+
"position": "DETACHABLE",
|
|
32
|
+
"label": {
|
|
33
|
+
"value": "\"Declaration Detachable with [external link](https://inseefr.github.io/Lunatic/)\"",
|
|
34
|
+
"type": "VTL|MD"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
@@ -42,6 +42,30 @@ function fetchFake() {
|
|
|
42
42
|
return r.json();
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
+
function fetchPCS2020() {
|
|
46
|
+
return fetch('/libelles-pcs-2020.json').then(function (r) {
|
|
47
|
+
return r.json();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
var infoPCS2020 = {
|
|
51
|
+
name: 'libelle-pcs2020',
|
|
52
|
+
fields: [{
|
|
53
|
+
name: 'id',
|
|
54
|
+
rules: ['[\\w]+'],
|
|
55
|
+
language: 'French',
|
|
56
|
+
min: 2
|
|
57
|
+
}],
|
|
58
|
+
queryParser: {
|
|
59
|
+
type: 'tokenized',
|
|
60
|
+
params: {
|
|
61
|
+
language: 'French',
|
|
62
|
+
pattern: '[\\w]+'
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
meloto: true,
|
|
66
|
+
version: '1',
|
|
67
|
+
stopWords: ['a', 'au', 'dans', 'de', 'des', 'du', 'en', 'er', 'la', 'le', 'ou', 'sur', 'd', 'l', 'aux', 'dans', 'un', 'une', 'pour', 'avec', 'chez', 'par', 'les']
|
|
68
|
+
};
|
|
45
69
|
var infoFake = {
|
|
46
70
|
name: 'fake',
|
|
47
71
|
fields: [{
|
|
@@ -77,7 +101,7 @@ var infoNaf = {
|
|
|
77
101
|
}
|
|
78
102
|
},
|
|
79
103
|
version: '1',
|
|
80
|
-
meloto:
|
|
104
|
+
meloto: true
|
|
81
105
|
};
|
|
82
106
|
function loadOne(_x, _x2) {
|
|
83
107
|
return _loadOne.apply(this, arguments);
|
|
@@ -186,6 +210,17 @@ var Template = function Template(args) {
|
|
|
186
210
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
187
211
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("ul", {
|
|
188
212
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
213
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
214
|
+
type: "button",
|
|
215
|
+
value: "load PCS2020",
|
|
216
|
+
onClick: function onClick() {
|
|
217
|
+
return loadOne(infoPCS2020, fetchPCS2020);
|
|
218
|
+
}
|
|
219
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Search, {
|
|
220
|
+
storeInfo: infoPCS2020,
|
|
221
|
+
defaultValue: "st"
|
|
222
|
+
})]
|
|
223
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
189
224
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
190
225
|
type: "button",
|
|
191
226
|
value: "load NAF",
|
|
@@ -47,38 +47,29 @@ function DevOptions(_ref) {
|
|
|
47
47
|
}
|
|
48
48
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
49
49
|
className: "dev-options",
|
|
50
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
className: "conteneur",
|
|
50
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
51
|
+
style: {
|
|
52
|
+
display: 'flex'
|
|
53
|
+
},
|
|
55
54
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Button, {
|
|
56
55
|
onClick: function onClick() {
|
|
57
56
|
return _logger.Logger.log(getData(true));
|
|
58
57
|
},
|
|
59
|
-
children: "Get
|
|
58
|
+
children: "Get Data"
|
|
60
59
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Button, {
|
|
61
60
|
onClick: function onClick() {
|
|
62
61
|
return goToPage({
|
|
63
62
|
page: "".concat(toPage)
|
|
64
63
|
});
|
|
65
64
|
},
|
|
66
|
-
children: "Go to
|
|
67
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Button, {
|
|
68
|
-
onClick: function onClick() {
|
|
69
|
-
return goToPage({
|
|
70
|
-
page: "".concat(lastReachedPage)
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
children: "Go to lastReachedPage : ".concat(lastReachedPage)
|
|
74
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Input, {
|
|
75
|
-
id: "page-to-jump",
|
|
76
|
-
value: toPage,
|
|
77
|
-
handleChange: handleChange,
|
|
78
|
-
min: 1,
|
|
79
|
-
label: 'Page',
|
|
80
|
-
description: 'the page where you want to jump'
|
|
65
|
+
children: "Go to \"".concat(toPage, "\"")
|
|
81
66
|
})]
|
|
67
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Input, {
|
|
68
|
+
id: "page-to-jump",
|
|
69
|
+
value: toPage,
|
|
70
|
+
handleChange: handleChange,
|
|
71
|
+
min: 1,
|
|
72
|
+
label: 'Page to reach : '
|
|
82
73
|
})]
|
|
83
74
|
});
|
|
84
75
|
}
|
|
@@ -91,7 +82,8 @@ function Pager(_ref2) {
|
|
|
91
82
|
isFirst = _ref2.isFirst,
|
|
92
83
|
pageTag = _ref2.pageTag,
|
|
93
84
|
maxPage = _ref2.maxPage,
|
|
94
|
-
getData = _ref2.getData
|
|
85
|
+
getData = _ref2.getData,
|
|
86
|
+
pager = _ref2.pager;
|
|
95
87
|
if (maxPage && maxPage > 1) {
|
|
96
88
|
var Button = lunatic.Button;
|
|
97
89
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
@@ -105,13 +97,35 @@ function Pager(_ref2) {
|
|
|
105
97
|
onClick: goNext,
|
|
106
98
|
disabled: isLast,
|
|
107
99
|
children: "Next"
|
|
100
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
101
|
+
style: {
|
|
102
|
+
fontSize: '.8em',
|
|
103
|
+
opacity: 0.7,
|
|
104
|
+
marginTop: '.3em'
|
|
105
|
+
},
|
|
106
|
+
children: "You can use PgDown / PgUp shortcut"
|
|
108
107
|
})]
|
|
109
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
110
|
-
children: ["PAGE: ", pageTag]
|
|
111
108
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(DevOptions, {
|
|
112
109
|
goToPage: goToPage,
|
|
113
110
|
getData: getData,
|
|
114
111
|
lastReachedPage: lastReachedPage
|
|
112
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
113
|
+
className: "story-pager",
|
|
114
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
|
|
115
|
+
children: "Pager"
|
|
116
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("ul", {
|
|
117
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
118
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
119
|
+
children: "PageTag:"
|
|
120
|
+
}), " ", JSON.stringify(pageTag)]
|
|
121
|
+
}), Object.keys(pager).map(function (key) {
|
|
122
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
123
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("strong", {
|
|
124
|
+
children: [key, ":"]
|
|
125
|
+
}), " ", JSON.stringify(pager[key])]
|
|
126
|
+
}, key);
|
|
127
|
+
})]
|
|
128
|
+
})]
|
|
115
129
|
})]
|
|
116
130
|
});
|
|
117
131
|
}
|
|
@@ -220,9 +234,32 @@ function OrchestratorForStories(_ref3) {
|
|
|
220
234
|
});
|
|
221
235
|
} else goNextPage();
|
|
222
236
|
}, [compileControls, errorActive, goNextPage, pageTag]);
|
|
237
|
+
|
|
238
|
+
// Allow PageDown / PageUp shortcut to ease navigation
|
|
239
|
+
(0, _react.useEffect)(function () {
|
|
240
|
+
var listener = function listener(e) {
|
|
241
|
+
var stopPropagation = false;
|
|
242
|
+
if (e.key === 'PageDown') {
|
|
243
|
+
handleGoNext();
|
|
244
|
+
stopPropagation = true;
|
|
245
|
+
}
|
|
246
|
+
if (e.key === 'PageUp') {
|
|
247
|
+
goPreviousPage();
|
|
248
|
+
stopPropagation = true;
|
|
249
|
+
}
|
|
250
|
+
if (stopPropagation) {
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
e.stopPropagation();
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
document.addEventListener('keydown', listener);
|
|
256
|
+
return function () {
|
|
257
|
+
document.removeEventListener('keydown', listener);
|
|
258
|
+
};
|
|
259
|
+
}, [handleGoNext, goPreviousPage]);
|
|
223
260
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Provider, {
|
|
224
261
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
225
|
-
className: "container",
|
|
262
|
+
className: "container story-with-sidebar",
|
|
226
263
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
227
264
|
className: "components",
|
|
228
265
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_2.LunaticComponents, {
|
|
@@ -237,30 +274,33 @@ function OrchestratorForStories(_ref3) {
|
|
|
237
274
|
}, storeName ? getStoreInfo(storeName) : {});
|
|
238
275
|
}
|
|
239
276
|
})
|
|
240
|
-
}), /*#__PURE__*/(0, _jsxRuntime.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
children: "
|
|
263
|
-
|
|
277
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("aside", {
|
|
278
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Pager, {
|
|
279
|
+
goPrevious: goPreviousPage,
|
|
280
|
+
goNext: handleGoNext,
|
|
281
|
+
goToPage: goToPage,
|
|
282
|
+
lastReachedPage: lastReachedPage,
|
|
283
|
+
isLast: isLastPage,
|
|
284
|
+
isFirst: isFirstPage,
|
|
285
|
+
pageTag: pageTag,
|
|
286
|
+
maxPage: maxPage,
|
|
287
|
+
getData: getData,
|
|
288
|
+
pager: pager
|
|
289
|
+
}), showOverview && /*#__PURE__*/(0, _jsxRuntime.jsx)(_overview.Overview, {
|
|
290
|
+
overview: overview,
|
|
291
|
+
goToPage: goToPage
|
|
292
|
+
}), errorsForModal && /*#__PURE__*/(0, _jsxRuntime.jsx)(lunatic.Modal, {
|
|
293
|
+
errors: errorsForModal.currentErrors,
|
|
294
|
+
goNext: skip,
|
|
295
|
+
onClose: closeModal,
|
|
296
|
+
isCritical: errorsForModal.isCritical
|
|
297
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_waiting["default"], {
|
|
298
|
+
status: waiting,
|
|
299
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
300
|
+
className: "waiting-orchestrator",
|
|
301
|
+
children: "Initialisation des donn\xE9es de suggestion..."
|
|
302
|
+
})
|
|
303
|
+
})]
|
|
264
304
|
})]
|
|
265
305
|
})
|
|
266
306
|
});
|
|
@@ -2,4 +2,53 @@
|
|
|
2
2
|
background-color: antiquewhite;
|
|
3
3
|
padding: 5px 5px;
|
|
4
4
|
border: solid burlywood 2px;
|
|
5
|
+
display: grid;
|
|
6
|
+
grid-template-columns: 1fr;
|
|
7
|
+
gap: 1rem;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.story-with-sidebar {
|
|
11
|
+
font-family: sans-serif;
|
|
12
|
+
display: grid;
|
|
13
|
+
height: 100%;
|
|
14
|
+
grid-template-columns: 1fr 300px;
|
|
15
|
+
align-items: flex-start;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.story-with-sidebar aside label {
|
|
19
|
+
display: block;
|
|
20
|
+
font-weight: bold;
|
|
21
|
+
margin-bottom: .3em;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.story-with-sidebar aside {
|
|
25
|
+
display: grid;
|
|
26
|
+
grid-template-columns: 1fr;
|
|
27
|
+
gap: 1rem;
|
|
28
|
+
padding: 1rem;
|
|
29
|
+
box-shadow: 0 4px 3px rgba(0, 0, 0, 0.07), 0px 2px 2px rgba(0, 0, 0, 0.06);
|
|
30
|
+
background-color: #f1f5f9;
|
|
31
|
+
|
|
32
|
+
.pagination {
|
|
33
|
+
margin-top: 0;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.story-pager h3 {
|
|
38
|
+
font-size: 1rem;
|
|
39
|
+
padding-bottom: .3rem;
|
|
40
|
+
margin-bottom: .5rem;
|
|
41
|
+
border-bottom: solid 1px rgba(0, 0, 0, 0.3);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.story-pager ul {
|
|
45
|
+
margin: 0;
|
|
46
|
+
padding: 0 0 0 20px;
|
|
47
|
+
line-height: 1.4;
|
|
48
|
+
font-size: 0.9rem;
|
|
49
|
+
color: rgba(0, 0, 0, 0.75)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.story-pager ul strong {
|
|
53
|
+
color: #000;
|
|
5
54
|
}
|
|
@@ -14,19 +14,23 @@ var getReferentiel = exports.getReferentiel = /*#__PURE__*/function () {
|
|
|
14
14
|
while (1) switch (_context.prev = _context.next) {
|
|
15
15
|
case 0:
|
|
16
16
|
_context.t0 = name;
|
|
17
|
-
_context.next = _context.t0 === 'naf-rev2-stop' ?
|
|
17
|
+
_context.next = _context.t0 === 'libelle-pcs2020' ? 3 : _context.t0 === 'naf-rev2-stop' ? 4 : _context.t0 === 'naf-rev2' ? 4 : _context.t0 === 'cog-communes' ? 5 : 6;
|
|
18
18
|
break;
|
|
19
19
|
case 3:
|
|
20
|
-
return _context.abrupt("return", fetch('
|
|
20
|
+
return _context.abrupt("return", fetch('/libelles-pcs-2020.json').then(function (r) {
|
|
21
21
|
return r.json();
|
|
22
22
|
}));
|
|
23
23
|
case 4:
|
|
24
|
-
return _context.abrupt("return", fetch('https://inseefr.github.io/Lunatic/storybook/
|
|
24
|
+
return _context.abrupt("return", fetch('https://inseefr.github.io/Lunatic/storybook/naf-rev2.json').then(function (r) {
|
|
25
25
|
return r.json();
|
|
26
26
|
}));
|
|
27
27
|
case 5:
|
|
28
|
-
|
|
28
|
+
return _context.abrupt("return", fetch('https://inseefr.github.io/Lunatic/storybook/communes-2019.json').then(function (r) {
|
|
29
|
+
return r.json();
|
|
30
|
+
}));
|
|
29
31
|
case 6:
|
|
32
|
+
throw new Error("Unkonw r\xE9f\xE9rentiel ".concat(name));
|
|
33
|
+
case 7:
|
|
30
34
|
case "end":
|
|
31
35
|
return _context.stop();
|
|
32
36
|
}
|
|
@@ -24,16 +24,21 @@ function cleaningBehaviour(store, cleaning) {
|
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
for (var variableName in cleaningInfo) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
try {
|
|
28
|
+
var _initialValues$variab;
|
|
29
|
+
var skipCleaning = store.run(cleaningInfo[variableName], {
|
|
30
|
+
iteration: e.detail.iteration
|
|
31
|
+
});
|
|
32
|
+
if (skipCleaning) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
store.set(variableName, (_initialValues$variab = initialValues[variableName]) !== null && _initialValues$variab !== void 0 ? _initialValues$variab : null, {
|
|
36
|
+
iteration: e.detail.iteration
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
// If we have an error, skip this cleaning
|
|
40
|
+
console.error(e);
|
|
33
41
|
}
|
|
34
|
-
store.set(variableName, (_initialValues$variab = initialValues[variableName]) !== null && _initialValues$variab !== void 0 ? _initialValues$variab : null, {
|
|
35
|
-
iteration: e.detail.iteration
|
|
36
|
-
});
|
|
37
42
|
}
|
|
38
43
|
});
|
|
39
44
|
}
|
|
@@ -53,7 +53,12 @@ function getQuestionnaireData(store, variables) {
|
|
|
53
53
|
COLLECTED: store.get(variable.name)
|
|
54
54
|
});
|
|
55
55
|
} else {
|
|
56
|
-
|
|
56
|
+
try {
|
|
57
|
+
result[variable.variableType][variable.name] = store.get(variable.name);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
// Error can happen when calculating variable, send null to prevent crashing the mehod
|
|
60
|
+
result[variable.variableType][variable.name] = null;
|
|
61
|
+
}
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
} catch (err) {
|
|
@@ -259,27 +259,45 @@ var LunaticVariable = /*#__PURE__*/function () {
|
|
|
259
259
|
}, {
|
|
260
260
|
key: "setValue",
|
|
261
261
|
value: function setValue(value, iteration) {
|
|
262
|
-
var _this = this;
|
|
263
262
|
if (value === this.getSavedValue(iteration)) {
|
|
264
263
|
return false;
|
|
265
264
|
}
|
|
266
265
|
// Decompose arrays, to only update items that changed
|
|
267
266
|
if (Array.isArray(value) && !Array.isArray(iteration)) {
|
|
268
|
-
return
|
|
269
|
-
return _this.setValue(v, [k]);
|
|
270
|
-
}).find(function (v) {
|
|
271
|
-
return v;
|
|
272
|
-
});
|
|
267
|
+
return this.setValueForArray(value);
|
|
273
268
|
}
|
|
274
269
|
// We want to save a value at a specific iteration, but the value is not an array yet
|
|
275
270
|
if (iteration !== undefined && !Array.isArray(this.value)) {
|
|
276
271
|
this.value = [];
|
|
277
272
|
}
|
|
278
273
|
this.value = !Array.isArray(iteration) ? value : (0, _array.setAtIndex)(this.value, iteration, value);
|
|
279
|
-
|
|
274
|
+
if (value === undefined) {
|
|
275
|
+
this.updatedAt["delete"](iteration === null || iteration === void 0 ? void 0 : iteration.join('.'));
|
|
276
|
+
} else {
|
|
277
|
+
this.updatedAt.set(iteration === null || iteration === void 0 ? void 0 : iteration.join('.'), performance.now());
|
|
278
|
+
}
|
|
280
279
|
this.updatedAt.set(undefined, performance.now());
|
|
281
280
|
return true;
|
|
282
281
|
}
|
|
282
|
+
}, {
|
|
283
|
+
key: "setValueForArray",
|
|
284
|
+
value: function setValueForArray(value) {
|
|
285
|
+
var _this = this;
|
|
286
|
+
var savedValue = this.getSavedValue();
|
|
287
|
+
var oldSize = Array.isArray(savedValue) ? savedValue.length : -1;
|
|
288
|
+
var newSize = value.length;
|
|
289
|
+
// Update every item of the array and look if we changed one item
|
|
290
|
+
var oneValueChanged = (0, _array.times)(Math.max(oldSize, newSize), function (k) {
|
|
291
|
+
return _this.setValue(value[k], [k]);
|
|
292
|
+
}).find(function (v) {
|
|
293
|
+
return v;
|
|
294
|
+
}) !== undefined;
|
|
295
|
+
// New array is smaller, shorten the array
|
|
296
|
+
if (oldSize > newSize && Array.isArray(this.value)) {
|
|
297
|
+
this.value = this.value.slice(0, newSize);
|
|
298
|
+
}
|
|
299
|
+
return oneValueChanged;
|
|
300
|
+
}
|
|
283
301
|
}, {
|
|
284
302
|
key: "getSavedValue",
|
|
285
303
|
value: function getSavedValue(iteration) {
|
|
@@ -319,12 +337,18 @@ var LunaticVariable = /*#__PURE__*/function () {
|
|
|
319
337
|
var _this2 = this;
|
|
320
338
|
try {
|
|
321
339
|
return Object.fromEntries(this.getDependencies().map(function (dep) {
|
|
322
|
-
var _this2$dictionary;
|
|
340
|
+
var _this2$dictionary, _this2$dictionary$get;
|
|
323
341
|
if (dep === iterationVariableName && iteration) {
|
|
324
342
|
return [dep, iteration[0]];
|
|
325
343
|
}
|
|
326
344
|
var dependencyIteration = (0, _number.isNumber)(_this2.iterationDepth) && Array.isArray(iteration) ? [iteration[_this2.iterationDepth]] : iteration;
|
|
327
|
-
|
|
345
|
+
|
|
346
|
+
// The variable is not registered in the variable dictionary
|
|
347
|
+
// Happens when calculating unquoted VTL expression
|
|
348
|
+
if (!_this2.dictionary || !((_this2$dictionary = _this2.dictionary) !== null && _this2$dictionary !== void 0 && _this2$dictionary.has(dep))) {
|
|
349
|
+
throw new Error("Unknown variable \"".concat(dep, "\" in expression ").concat(_this2.expression));
|
|
350
|
+
}
|
|
351
|
+
return [dep, (_this2$dictionary$get = _this2.dictionary.get(dep)) === null || _this2$dictionary$get === void 0 ? void 0 : _this2$dictionary$get.getValue(dependencyIteration)];
|
|
328
352
|
}));
|
|
329
353
|
} catch (e) {
|
|
330
354
|
if (e instanceof RangeError) {
|
|
@@ -14,6 +14,12 @@ var _missingBehaviour = require("./behaviours/missing-behaviour");
|
|
|
14
14
|
variables.set('FIRSTNAME', 'John');
|
|
15
15
|
(0, _vitest.expect)(variables.get('FIRSTNAME')).toEqual('John');
|
|
16
16
|
});
|
|
17
|
+
(0, _vitest.it)('should handle array correctly', function () {
|
|
18
|
+
variables.set('AGE', [10, 20, 30]);
|
|
19
|
+
(0, _vitest.expect)(variables.get('AGE')).toEqual([10, 20, 30]);
|
|
20
|
+
variables.set('AGE', [10, 20]);
|
|
21
|
+
(0, _vitest.expect)(variables.get('AGE')).toEqual([10, 20]);
|
|
22
|
+
});
|
|
17
23
|
(0, _vitest.it)('should create a store from an object', function () {
|
|
18
24
|
var store = _lunaticVariablesStore.LunaticVariablesStore.makeFromObject({
|
|
19
25
|
name: 'John',
|
|
@@ -81,6 +87,44 @@ var _missingBehaviour = require("./behaviours/missing-behaviour");
|
|
|
81
87
|
variables.set('FIRSTNAME', 'Jane');
|
|
82
88
|
(0, _vitest.expect)(variables.run('FIRSTNAME || " " || LASTNAME')).toEqual('Jane Doe');
|
|
83
89
|
});
|
|
90
|
+
(0, _vitest.it)('should throw an exception when calculated incorrect VTL', function () {
|
|
91
|
+
(0, _vitest.expect)(function () {
|
|
92
|
+
return variables.run('Hello world');
|
|
93
|
+
}).toThrowError();
|
|
94
|
+
});
|
|
95
|
+
(0, _vitest.describe)('event listener', function () {
|
|
96
|
+
(0, _vitest.it)('should trigger onChange', function () {
|
|
97
|
+
variables.set('FIRSTNAME', 'John');
|
|
98
|
+
var spy = _vitest.vi.fn();
|
|
99
|
+
variables.on('change', function (e) {
|
|
100
|
+
return spy(e.detail.name, e.detail.value);
|
|
101
|
+
});
|
|
102
|
+
variables.set('FIRSTNAME', 'Jane');
|
|
103
|
+
(0, _vitest.expect)(spy).toHaveBeenCalledWith('FIRSTNAME', 'Jane');
|
|
104
|
+
});
|
|
105
|
+
(0, _vitest.it)('should trigger onChange on array', function () {
|
|
106
|
+
variables.set('AGE', [18, 23, 24]);
|
|
107
|
+
var spy = _vitest.vi.fn();
|
|
108
|
+
variables.on('change', function (e) {
|
|
109
|
+
return spy(e.detail.name, e.detail.value);
|
|
110
|
+
});
|
|
111
|
+
variables.set('AGE', [18, 23]);
|
|
112
|
+
(0, _vitest.expect)(spy).toHaveBeenCalledWith('AGE', [18, 23]);
|
|
113
|
+
variables.set('AGE', [18, 25]);
|
|
114
|
+
(0, _vitest.expect)(spy).toHaveBeenCalledWith('AGE', [18, 25]);
|
|
115
|
+
});
|
|
116
|
+
(0, _vitest.it)('should not trigger onChange when value does not change', function () {
|
|
117
|
+
variables.set('FIRSTNAME', 'John');
|
|
118
|
+
variables.set('AGE', [18, 20]);
|
|
119
|
+
var spy = _vitest.vi.fn();
|
|
120
|
+
variables.on('change', function (e) {
|
|
121
|
+
return spy(e.detail.name, e.detail.value);
|
|
122
|
+
});
|
|
123
|
+
variables.set('FIRSTNAME', 'John');
|
|
124
|
+
variables.set('AGE', [18, 20]);
|
|
125
|
+
(0, _vitest.expect)(spy).not.toHaveBeenCalled();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
84
128
|
(0, _vitest.describe)('with iteration', function () {
|
|
85
129
|
(0, _vitest.it)('should handle arrays', function () {
|
|
86
130
|
variables.set('FIRSTNAME', ['John', 'Jane']);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.usePageHasResponse = usePageHasResponse;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
/**
|
|
13
|
+
* Check if a page has one response (value is filled for at least one field)
|
|
14
|
+
*/
|
|
15
|
+
function usePageHasResponse(components, executeExpression) {
|
|
16
|
+
return (0, _react.useCallback)(function () {
|
|
17
|
+
if (!Array.isArray(components)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
var _iterator = _createForOfIteratorHelper(components),
|
|
21
|
+
_step;
|
|
22
|
+
try {
|
|
23
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
24
|
+
var component = _step.value;
|
|
25
|
+
// Some components are considered as "filled" by default
|
|
26
|
+
if (['PairwiseLinks', 'Roundabout'].includes(component.componentType)) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
// We found a value in one of the root component
|
|
30
|
+
if ('value' in component && !isEmpty(component.value)) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
// For rosterForLoop we need to inspect child components
|
|
34
|
+
if ('components' in component && Array.isArray(component.components) && !isSubComponentsEmpty(component.components, executeExpression)) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} catch (err) {
|
|
39
|
+
_iterator.e(err);
|
|
40
|
+
} finally {
|
|
41
|
+
_iterator.f();
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}, [components, executeExpression]);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Check if a value is empty
|
|
49
|
+
* - null ou undefined ou ''
|
|
50
|
+
* - for arrays, every item must be empty
|
|
51
|
+
* - for objects, every value must be empty
|
|
52
|
+
*/
|
|
53
|
+
function isEmpty(value) {
|
|
54
|
+
// Array is empty if all items are empty
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
// We find one value that is not empty
|
|
57
|
+
return value.find(function (v) {
|
|
58
|
+
return !isEmpty(v);
|
|
59
|
+
}) === undefined;
|
|
60
|
+
}
|
|
61
|
+
// For object inspect each values
|
|
62
|
+
if (_typeof(value) === 'object' && value !== null) {
|
|
63
|
+
return isEmpty(Object.values(value));
|
|
64
|
+
}
|
|
65
|
+
return !value;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* For complex component we need to inspect child components, interpret the response value
|
|
70
|
+
*/
|
|
71
|
+
function isSubComponentsEmpty(components, executeExpression) {
|
|
72
|
+
var _iterator2 = _createForOfIteratorHelper(components),
|
|
73
|
+
_step2;
|
|
74
|
+
try {
|
|
75
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
76
|
+
var component = _step2.value;
|
|
77
|
+
if ('response' in component && !isEmpty(executeExpression(component.response.name))) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} catch (err) {
|
|
82
|
+
_iterator2.e(err);
|
|
83
|
+
} finally {
|
|
84
|
+
_iterator2.f();
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
@@ -112,7 +112,7 @@ function reduceOnInit(state, action) {
|
|
|
112
112
|
return result;
|
|
113
113
|
} catch (e) {
|
|
114
114
|
// If there is an error interpreting a variable, return the raw expression
|
|
115
|
-
console.error("Cannot interpret expression : ".concat(expressionString));
|
|
115
|
+
console.error("Cannot interpret expression : ".concat(expressionString), e);
|
|
116
116
|
return expressionString;
|
|
117
117
|
}
|
|
118
118
|
};
|
|
@@ -19,6 +19,7 @@ var _reducer = _interopRequireDefault(require("./reducer"));
|
|
|
19
19
|
var _useSuggesters = require("./use-suggesters");
|
|
20
20
|
var _getQuestionnaireData = require("./commons/variables/get-questionnaire-data");
|
|
21
21
|
var _useTrackChanges2 = require("../hooks/use-track-changes");
|
|
22
|
+
var _usePageHasResponse = require("./hooks/use-page-has-response");
|
|
22
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
23
24
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
24
25
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
@@ -212,7 +213,8 @@ function useLunatic(source) {
|
|
|
212
213
|
overview: buildedOverview,
|
|
213
214
|
loopVariables: (0, _useLoopVariables.useLoopVariables)(pager, state.pages),
|
|
214
215
|
getChangedData: getChangedData,
|
|
215
|
-
resetChangedData: resetChangedData
|
|
216
|
+
resetChangedData: resetChangedData,
|
|
217
|
+
hasPageResponse: (0, _usePageHasResponse.usePageHasResponse)(components, executeExpression)
|
|
216
218
|
};
|
|
217
219
|
}
|
|
218
220
|
var _default = exports["default"] = useLunatic;
|