@inseefr/lunatic 2.6.3 → 2.6.4
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/hooks/use-auto-focus.js +1 -1
- package/lib/src/utils/suggester-workers/searching/meloto-order.d.ts +2 -1
- package/lib/stories/suggester/suggester-workers.stories.js +36 -1
- package/lib/stories/suggester/suggester.stories.js +8 -4
- package/lib/utils/suggester-workers/searching/meloto-order.js +6 -5
- package/package.json +1 -1
- package/workers-release/lunatic-searching-worker-0.3.0-experimental.js +1 -1
|
@@ -16,7 +16,7 @@ function useAutoFocus(wrapperRef, key) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
// First look for invalid fields, then all fields
|
|
19
|
-
var firstFocusableElement = (_ref = (_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.querySelector('button[aria-invalid], [href][aria-invalid], input[aria-invalid], select[aria-invalid], textarea[aria-invalid], [tabindex][aria-invalid]:not([tabindex="-1"])')) !== null && _ref !== void 0 ? _ref : (_wrapperRef$current2 = wrapperRef.current) === null || _wrapperRef$current2 === void 0 ? void 0 : _wrapperRef$current2.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
|
|
19
|
+
var firstFocusableElement = (_ref = (_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.querySelector('button[aria-invalid="true"], [href][aria-invalid="true"], input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"], [tabindex][aria-invalid="true"]:not([tabindex="-1"])')) !== null && _ref !== void 0 ? _ref : (_wrapperRef$current2 = wrapperRef.current) === null || _wrapperRef$current2 === void 0 ? void 0 : _wrapperRef$current2.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
|
|
20
20
|
|
|
21
21
|
// The first element can be focusable
|
|
22
22
|
if (firstFocusableElement) {
|
|
@@ -43,6 +43,30 @@ function fetchFake() {
|
|
|
43
43
|
return r.json();
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
+
function fetchPCS2020() {
|
|
47
|
+
return fetch('/libelles-pcs-2020.json').then(function (r) {
|
|
48
|
+
return r.json();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
var infoPCS2020 = {
|
|
52
|
+
name: 'libelle-pcs2020',
|
|
53
|
+
fields: [{
|
|
54
|
+
name: 'id',
|
|
55
|
+
rules: ['[\\w]+'],
|
|
56
|
+
language: 'French',
|
|
57
|
+
min: 2
|
|
58
|
+
}],
|
|
59
|
+
queryParser: {
|
|
60
|
+
type: 'tokenized',
|
|
61
|
+
params: {
|
|
62
|
+
language: 'French',
|
|
63
|
+
pattern: '[\\w]+'
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
meloto: true,
|
|
67
|
+
version: '1',
|
|
68
|
+
stopWords: ['a', 'au', 'dans', 'de', 'des', 'du', 'en', 'er', 'la', 'le', 'ou', 'sur', 'd', 'l', 'aux', 'dans', 'un', 'une', 'pour', 'avec', 'chez', 'par', 'les']
|
|
69
|
+
};
|
|
46
70
|
var infoFake = {
|
|
47
71
|
name: 'fake',
|
|
48
72
|
fields: [{
|
|
@@ -78,7 +102,7 @@ var infoNaf = {
|
|
|
78
102
|
}
|
|
79
103
|
},
|
|
80
104
|
version: '1',
|
|
81
|
-
meloto:
|
|
105
|
+
meloto: true
|
|
82
106
|
};
|
|
83
107
|
function loadOne(_x, _x2) {
|
|
84
108
|
return _loadOne.apply(this, arguments);
|
|
@@ -187,6 +211,17 @@ var Template = function Template(args) {
|
|
|
187
211
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
188
212
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("ul", {
|
|
189
213
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
214
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
215
|
+
type: "button",
|
|
216
|
+
value: "load PCS2020",
|
|
217
|
+
onClick: function onClick() {
|
|
218
|
+
return loadOne(infoPCS2020, fetchPCS2020);
|
|
219
|
+
}
|
|
220
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Search, {
|
|
221
|
+
storeInfo: infoPCS2020,
|
|
222
|
+
defaultValue: "st"
|
|
223
|
+
})]
|
|
224
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
190
225
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
191
226
|
type: "button",
|
|
192
227
|
value: "load NAF",
|
|
@@ -42,19 +42,23 @@ function _getReferentiel() {
|
|
|
42
42
|
while (1) switch (_context.prev = _context.next) {
|
|
43
43
|
case 0:
|
|
44
44
|
_context.t0 = name;
|
|
45
|
-
_context.next = _context.t0 === '
|
|
45
|
+
_context.next = _context.t0 === 'libelle-pcs2020' ? 3 : _context.t0 === 'naf-rev2' ? 4 : _context.t0 === 'cog-communes' ? 5 : 6;
|
|
46
46
|
break;
|
|
47
47
|
case 3:
|
|
48
|
-
return _context.abrupt("return", fetch('
|
|
48
|
+
return _context.abrupt("return", fetch('/libelles-pcs-2020.json').then(function (r) {
|
|
49
49
|
return r.json();
|
|
50
50
|
}));
|
|
51
51
|
case 4:
|
|
52
|
-
return _context.abrupt("return", fetch('https://inseefr.github.io/Lunatic/storybook/
|
|
52
|
+
return _context.abrupt("return", fetch('https://inseefr.github.io/Lunatic/storybook/naf-rev2.json').then(function (r) {
|
|
53
53
|
return r.json();
|
|
54
54
|
}));
|
|
55
55
|
case 5:
|
|
56
|
-
|
|
56
|
+
return _context.abrupt("return", fetch('https://inseefr.github.io/Lunatic/storybook/communes-2019.json').then(function (r) {
|
|
57
|
+
return r.json();
|
|
58
|
+
}));
|
|
57
59
|
case 6:
|
|
60
|
+
throw new Error("Unkonw r\xE9f\xE9rentiel ".concat(name));
|
|
61
|
+
case 7:
|
|
58
62
|
case "end":
|
|
59
63
|
return _context.stop();
|
|
60
64
|
}
|
|
@@ -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;
|