@inseefr/lunatic 2.7.4 → 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/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/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/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 +1 -0
- package/lib/src/utils/suggester-workers/searching/meloto-order.d.ts +2 -1
- 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 +25 -7
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +39 -0
- package/lib/use-lunatic/hooks/use-page-has-response.js +87 -0
- 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
|
@@ -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) {
|
|
@@ -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',
|
|
@@ -86,6 +92,39 @@ var _missingBehaviour = require("./behaviours/missing-behaviour");
|
|
|
86
92
|
return variables.run('Hello world');
|
|
87
93
|
}).toThrowError();
|
|
88
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
|
+
});
|
|
89
128
|
(0, _vitest.describe)('with iteration', function () {
|
|
90
129
|
(0, _vitest.it)('should handle arrays', function () {
|
|
91
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
|
+
}
|
|
@@ -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;
|
package/lib/utils/env.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.isTestEnv = isTestEnv;
|
|
|
7
7
|
function isTestEnv() {
|
|
8
8
|
try {
|
|
9
9
|
// using vitest, process.env is defined
|
|
10
|
-
return
|
|
10
|
+
return "".concat(process.env.VITEST) === 'true';
|
|
11
11
|
} catch (e) {
|
|
12
12
|
// process.env is not defined
|
|
13
13
|
// so we are not running as test so we can return false
|
|
@@ -8,16 +8,17 @@ exports.value = value;
|
|
|
8
8
|
var _prepareStringIndexation = _interopRequireDefault(require("../commons-tokenizer/prepare-string-indexation"));
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
10
|
function value(entity) {
|
|
11
|
+
var _suggestion$label;
|
|
11
12
|
var tokens = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
12
13
|
var suggestion = entity.suggestion;
|
|
13
|
-
var label = suggestion.label;
|
|
14
|
-
var prepared = (0, _prepareStringIndexation["default"])(
|
|
15
|
-
if (
|
|
14
|
+
var used = (_suggestion$label = suggestion.label) !== null && _suggestion$label !== void 0 ? _suggestion$label : suggestion.id;
|
|
15
|
+
var prepared = (0, _prepareStringIndexation["default"])(used);
|
|
16
|
+
if (used && used.length) {
|
|
16
17
|
return tokens.reduce(function (score, token, i) {
|
|
17
18
|
var index = prepared.search(token);
|
|
18
19
|
if (index >= 0) {
|
|
19
|
-
var how =
|
|
20
|
-
how /=
|
|
20
|
+
var how = used.length - index;
|
|
21
|
+
how /= used.length;
|
|
21
22
|
var weight = tokens.length - i;
|
|
22
23
|
weight /= tokens.length;
|
|
23
24
|
return score + how * weight;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inseefr/lunatic",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.5",
|
|
4
4
|
"workersVersion": "0.3.0",
|
|
5
5
|
"description": "Library of questionnaire components",
|
|
6
6
|
"repository": {
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"react-keyboard-event-handler": "^1.5.4",
|
|
84
84
|
"react-markdown": "^8.0.3",
|
|
85
85
|
"react-number-format": "^5.1.3",
|
|
86
|
-
"react-tooltip": "^
|
|
86
|
+
"react-tooltip": "^5.23.0",
|
|
87
87
|
"remove-accents": "^0.4.2",
|
|
88
88
|
"sass": "^1.58.3",
|
|
89
89
|
"snowball": "^0.3.1",
|