@inseefr/lunatic 0.3.0-experimental → 0.3.4-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 +218 -260
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/component-wrapper/controls/validators/datepicker.js +25 -14
- package/src/components/component-wrapper/missing/component.js +37 -17
- package/src/components/datepicker/component.js +8 -12
- package/src/components/declarations/wrappers/input-declarations-wrapper.js +31 -9
- package/src/components/dropdown/commons/components/dropdown.js +21 -0
- package/src/components/dropdown/dropdown-edit/dropdown-edit.js +4 -1
- package/src/components/dropdown/dropdown-simple/dropdown.js +3 -1
- package/src/components/input/input-number.js +2 -1
- package/src/components/loop-constructor/block/index.js +1 -1
- package/src/components/loop-constructor/index.js +1 -1
- package/src/components/loop-constructor/roster/index.js +1 -1
- package/src/components/loop-constructor/wrapper/body-component.js +3 -0
- package/src/components/loop-constructor/wrapper/build-components.js +33 -33
- package/src/components/loop-constructor/wrapper/index.js +1 -1
- package/src/components/suggester/components/panel/option-container.js +1 -1
- package/src/components/suggester/components/suggester-content.js +42 -42
- package/src/components/suggester/components/suggester.js +43 -3
- package/src/components/suggester/idb-suggester.js +7 -1
- package/src/components/suggester/lunatic-suggester.js +1 -0
- package/src/components/suggester/suggester-wrapper.js +9 -3
- package/src/components/table/table.js +3 -1
- package/src/stories/loop-constructor/README.md +27 -27
- package/src/stories/loop-constructor/data-input-forced.json +64 -64
- package/src/stories/loop-constructor/data-input.json +100 -100
- package/src/stories/loop-constructor/data-loop-forced.json +66 -66
- package/src/stories/loop-constructor/data-loop-static-forced.json +66 -66
- package/src/stories/loop-constructor/data-loop-static.json +81 -81
- package/src/stories/loop-constructor/data-loop.json +81 -81
- package/src/stories/loop-constructor/data-roster-forced.json +68 -68
- package/src/stories/loop-constructor/data-roster.json +83 -83
- package/src/stories/loop-constructor/loop-constructor.stories.js +180 -180
- package/src/stories/questionnaire/arithmetic-management.json +47 -0
- package/src/stories/questionnaire/logement-queen.json +23389 -22705
- package/src/stories/questionnaire/logement-s2.json +46027 -44536
- package/src/stories/questionnaire/questionnaire.stories.js +46 -13
- package/src/stories/questionnaire/update-external/data.json +1 -0
- package/src/stories/questionnaire/update-external/questionnaire.json +75 -0
- package/src/stories/suggester/data.json +4 -1
- package/src/stories/suggester/suggester-workers.stories.js +4 -1
- package/src/stories/utils/orchestrator-split.js +119 -0
- package/src/stories/utils/orchestrator.js +12 -3
- package/src/tests/utils/to-expose/handler/results/res-input-edited.json +158 -158
- package/src/tests/utils/to-expose/state/state.spec.js +59 -59
- package/src/utils/lib/index.js +1 -0
- package/src/utils/lib/pagination/navigation/shared.js +5 -5
- package/src/utils/lib/splitting.js +142 -0
- package/src/utils/suggester-workers/commons-tokenizer/create-entity-tokenizer.js +4 -2
- package/src/utils/suggester-workers/commons-tokenizer/filters/{filter-accents-to-lower.js → filter-accents.js} +2 -2
- package/src/utils/suggester-workers/commons-tokenizer/filters/{filter-accents-to-lower.spec.js → filter-accents.spec.js} +1 -1
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-synonyms.js +27 -1
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.js +10 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.spec.js +12 -0
- package/src/utils/suggester-workers/commons-tokenizer/index.js +1 -1
- package/src/utils/to-expose/handler.js +67 -28
- package/src/utils/to-expose/hooks/filter-components.js +106 -106
- package/src/utils/to-expose/hooks/index.js +2 -1
- package/src/utils/to-expose/hooks/lunatic-split.js +421 -0
- package/src/utils/to-expose/hooks/lunatic.js +39 -7
- package/src/utils/to-expose/index.js +11 -11
- package/src/utils/to-expose/state.js +23 -15
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
const MAPS_FROM_ARRAY = new Map(); // Pour éviter de recalculer une map à chaque fois
|
|
2
|
+
|
|
3
|
+
function filterFromObject(tokens, synonyms) {
|
|
2
4
|
return tokens.reduce(function (prec, token) {
|
|
3
5
|
if (token in synonyms) {
|
|
4
6
|
return [...prec, token, ...synonyms[token]];
|
|
@@ -7,4 +9,28 @@ function filterSynonyms(tokens, { synonyms }) {
|
|
|
7
9
|
}, []);
|
|
8
10
|
}
|
|
9
11
|
|
|
12
|
+
function buildSynonymsMap(array) {
|
|
13
|
+
return array.reduce(function (map, { source, target }) {
|
|
14
|
+
return { ...map, [source]: target };
|
|
15
|
+
}, {});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function filterFromArray(tokens, synonyms) {
|
|
19
|
+
if (!MAPS_FROM_ARRAY.has(synonyms)) {
|
|
20
|
+
MAPS_FROM_ARRAY.set(synonyms, buildSynonymsMap(synonyms));
|
|
21
|
+
}
|
|
22
|
+
return filterFromObject(tokens, MAPS_FROM_ARRAY.get(synonyms));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function filterSynonyms(tokens, { synonyms }) {
|
|
26
|
+
if (Array.isArray(synonyms) && synonyms.length) {
|
|
27
|
+
return filterFromArray(tokens, synonyms);
|
|
28
|
+
}
|
|
29
|
+
if (typeof synonyms === 'object') {
|
|
30
|
+
return filterFromObject(tokens, synonyms);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return tokens;
|
|
34
|
+
}
|
|
35
|
+
|
|
10
36
|
export default filterSynonyms;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import filterToLower from './filter-to-lower';
|
|
2
|
+
|
|
3
|
+
describe('filter-to-lower', function () {
|
|
4
|
+
it('UN', function () {
|
|
5
|
+
const tokens = ['UN', 'no'];
|
|
6
|
+
const results = filterToLower(tokens);
|
|
7
|
+
expect(Array.isArray(results)).toBe(true);
|
|
8
|
+
expect(results.length).toBe(2);
|
|
9
|
+
expect(results[0]).toBe('un');
|
|
10
|
+
expect(results[1]).toBe('no');
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -4,5 +4,5 @@ export { default as prepareStringIndexation } from './prepare-string-indexation'
|
|
|
4
4
|
export { default as filterStemmer } from './filters/filter-stemmer';
|
|
5
5
|
export { default as filterLength } from './filters/filter-length';
|
|
6
6
|
export { default as filterDouble } from './filters/filter-double';
|
|
7
|
-
export { default as
|
|
7
|
+
export { default as filterAccents } from './filters/filter-accents';
|
|
8
8
|
export { default as getRegExpFromPattern } from './get-regexp-from-pattern';
|
|
@@ -43,10 +43,10 @@ export const updateQuestionnaire =
|
|
|
43
43
|
{ newVariables: variables, refs: [] }
|
|
44
44
|
);
|
|
45
45
|
const { newVariables, refs: r } = varsAndRefs;
|
|
46
|
-
const newVariablesWithCalculated =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
const newVariablesWithCalculated = addCalculatedVars(
|
|
47
|
+
newVariables,
|
|
48
|
+
updatedValues
|
|
49
|
+
)(logFunction, preferences);
|
|
50
50
|
const collectedVars = newVariables[C.COLLECTED];
|
|
51
51
|
const newComponents = components.map((c) => {
|
|
52
52
|
if (r.includes(c.id)) return buildFilledComponent(collectedVars)(c);
|
|
@@ -59,6 +59,26 @@ export const updateQuestionnaire =
|
|
|
59
59
|
};
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
export const updateExternals =
|
|
63
|
+
(questionnaire) => (logFunction) => (updatedValues) => {
|
|
64
|
+
const { variables, ...other } = questionnaire;
|
|
65
|
+
const { EXTERNAL } = variables;
|
|
66
|
+
const newVariables = {
|
|
67
|
+
...variables,
|
|
68
|
+
EXTERNAL: { ...EXTERNAL, ...updatedValues },
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const newVariablesWithCalculated = addCalculatedVars(
|
|
72
|
+
newVariables,
|
|
73
|
+
updatedValues
|
|
74
|
+
)(logFunction);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
...other,
|
|
78
|
+
variables: newVariablesWithCalculated,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
62
82
|
export const buildNewValue =
|
|
63
83
|
(preferences) => (valueType) => (oldValues) => (value) => {
|
|
64
84
|
if (preferences.length === 1) return value;
|
|
@@ -72,41 +92,60 @@ export const buildNewValue =
|
|
|
72
92
|
return lastValue === value ? null : value;
|
|
73
93
|
};
|
|
74
94
|
|
|
75
|
-
|
|
95
|
+
// Separate methods to avoid perf issue on collect simplest use case
|
|
96
|
+
const getCollectedAndExternal = (preferences) => (variables) => {
|
|
76
97
|
const { COLLECTED } = variables;
|
|
77
|
-
|
|
98
|
+
if (preferences.length === 1 && preferences[0] === 'COLLECTED')
|
|
99
|
+
return getCollectedAndExternalSimple(COLLECTED);
|
|
100
|
+
return getCollectedAndExternalByPreferences(preferences)(COLLECTED);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const getCollectedAndExternalSimple = (variables) => {
|
|
104
|
+
const collected = Object.entries(variables).reduce(
|
|
78
105
|
(acc, [k, { values }]) => ({ ...acc, [k]: values.COLLECTED }),
|
|
79
106
|
{}
|
|
80
107
|
);
|
|
81
108
|
return { ...collected, ...variables.EXTERNAL };
|
|
82
109
|
};
|
|
83
110
|
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
111
|
+
const getCollectedAndExternalByPreferences = (preferences) => (variables) => {
|
|
112
|
+
const collected = Object.entries(variables).reduce((acc, [k, { values }]) => {
|
|
113
|
+
const v = preferences.reduce((acc, p) => {
|
|
114
|
+
const value = values[p];
|
|
115
|
+
return [null, ''].includes(value) ? acc : value;
|
|
116
|
+
}, null);
|
|
117
|
+
return { ...acc, [k]: v };
|
|
118
|
+
}, {});
|
|
119
|
+
return { ...collected, ...variables.EXTERNAL };
|
|
120
|
+
};
|
|
90
121
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
122
|
+
const addCalculatedVars =
|
|
123
|
+
(variables, updatedValues) => (logFunction, preferences) => {
|
|
124
|
+
if (
|
|
125
|
+
!variables[C.CALCULATED] ||
|
|
126
|
+
Object.keys(variables[C.CALCULATED]).length === 0
|
|
127
|
+
)
|
|
128
|
+
return variables;
|
|
95
129
|
|
|
96
|
-
|
|
130
|
+
if (isDev) {
|
|
131
|
+
console.log('Start var calculation');
|
|
132
|
+
var start = new Date().getTime();
|
|
133
|
+
}
|
|
97
134
|
|
|
98
|
-
|
|
135
|
+
const { COLLECTED, EXTERNAL, CALCULATED: calculatedVariables } = variables;
|
|
99
136
|
|
|
100
|
-
|
|
137
|
+
const updatedVars = Object.keys(updatedValues);
|
|
101
138
|
|
|
102
|
-
|
|
103
|
-
bindings,
|
|
104
|
-
updatedVars,
|
|
105
|
-
logFunction,
|
|
106
|
-
});
|
|
139
|
+
const bindings = getCollectedAndExternal(preferences)(variables);
|
|
107
140
|
|
|
108
|
-
|
|
109
|
-
|
|
141
|
+
const CALCULATED = getCalculatedVariables(calculatedVariables)({
|
|
142
|
+
bindings,
|
|
143
|
+
updatedVars,
|
|
144
|
+
logFunction,
|
|
145
|
+
});
|
|
110
146
|
|
|
111
|
-
|
|
112
|
-
};
|
|
147
|
+
if (isDev)
|
|
148
|
+
console.log(`End var calculation: ${new Date().getTime() - start} ms`);
|
|
149
|
+
|
|
150
|
+
return { EXTERNAL, COLLECTED, CALCULATED };
|
|
151
|
+
};
|
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
import { interpret } from '../interpret';
|
|
2
|
-
import { isDev, buildVectorialBindings } from '../../lib';
|
|
3
|
-
|
|
4
|
-
let cache = {};
|
|
5
|
-
|
|
6
|
-
const customFilterPagination = ({ page }, pagination, currentPage) => {
|
|
7
|
-
return pagination ? currentPage
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const filterComponents = ({ components, updatedVars, features, bindings }) => {
|
|
11
|
-
const localCache = {};
|
|
12
|
-
const filtered = components.filter(({ conditionFilter }) => {
|
|
13
|
-
if (!conditionFilter || !conditionFilter.value) return true;
|
|
14
|
-
const { bindingDependencies, value } = conditionFilter;
|
|
15
|
-
if (localCache[value] !== undefined) return localCache[value];
|
|
16
|
-
if (
|
|
17
|
-
(!bindingDependencies ||
|
|
18
|
-
!updatedVars.some((t) => bindingDependencies.includes(t))) &&
|
|
19
|
-
cache[value] !== undefined
|
|
20
|
-
)
|
|
21
|
-
return cache[value];
|
|
22
|
-
const vectorialBindings = buildVectorialBindings(bindings);
|
|
23
|
-
const inter = interpret(features)(vectorialBindings)(value);
|
|
24
|
-
localCache[value] = inter;
|
|
25
|
-
return inter;
|
|
26
|
-
});
|
|
27
|
-
cache = { ...cache, ...localCache };
|
|
28
|
-
return filtered;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const buildComponents = ({
|
|
32
|
-
components,
|
|
33
|
-
management,
|
|
34
|
-
bindings,
|
|
35
|
-
features,
|
|
36
|
-
page,
|
|
37
|
-
pagination,
|
|
38
|
-
todo,
|
|
39
|
-
}) => {
|
|
40
|
-
if (management && !pagination) return components;
|
|
41
|
-
|
|
42
|
-
if (management && pagination)
|
|
43
|
-
return components.filter((c) =>
|
|
44
|
-
customFilterPagination(c, pagination, page)
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
if (isDev) {
|
|
48
|
-
console.log('Start filter');
|
|
49
|
-
var start = new Date().getTime();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const updatedVars = Object.keys(todo);
|
|
53
|
-
|
|
54
|
-
if (!pagination) {
|
|
55
|
-
const filtered = filterComponents({
|
|
56
|
-
components,
|
|
57
|
-
updatedVars,
|
|
58
|
-
features,
|
|
59
|
-
bindings,
|
|
60
|
-
});
|
|
61
|
-
if (isDev) console.log(`End filter: ${new Date().getTime() - start} ms`);
|
|
62
|
-
return filtered;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const pageComponents = components.filter((c) =>
|
|
66
|
-
customFilterPagination(c, pagination, page)
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const pageComponentsFiltered = filterComponents({
|
|
70
|
-
components: pageComponents,
|
|
71
|
-
updatedVars,
|
|
72
|
-
features,
|
|
73
|
-
bindings,
|
|
74
|
-
});
|
|
75
|
-
if (isDev) console.log(`End filter: ${new Date().getTime() - start}`);
|
|
76
|
-
return pageComponentsFiltered;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
let oldComponents = [];
|
|
80
|
-
let memoryTodo = {};
|
|
81
|
-
|
|
82
|
-
export const useFilterComponents = ({
|
|
83
|
-
questionnaire,
|
|
84
|
-
management,
|
|
85
|
-
bindings,
|
|
86
|
-
features,
|
|
87
|
-
page,
|
|
88
|
-
pagination,
|
|
89
|
-
todo,
|
|
90
|
-
}) => {
|
|
91
|
-
if (Object.keys(todo).length > 0) {
|
|
92
|
-
memoryTodo = todo;
|
|
93
|
-
return oldComponents;
|
|
94
|
-
}
|
|
95
|
-
const components = buildComponents({
|
|
96
|
-
components: questionnaire.components,
|
|
97
|
-
management,
|
|
98
|
-
bindings,
|
|
99
|
-
features,
|
|
100
|
-
page,
|
|
101
|
-
pagination,
|
|
102
|
-
todo: memoryTodo,
|
|
103
|
-
});
|
|
104
|
-
oldComponents = components;
|
|
105
|
-
return components;
|
|
106
|
-
};
|
|
1
|
+
import { interpret } from '../interpret';
|
|
2
|
+
import { isDev, buildVectorialBindings } from '../../lib';
|
|
3
|
+
|
|
4
|
+
let cache = {};
|
|
5
|
+
|
|
6
|
+
const customFilterPagination = ({ page }, pagination, currentPage) => {
|
|
7
|
+
return pagination ? currentPage?.split('.')[0] === page : true;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const filterComponents = ({ components, updatedVars, features, bindings }) => {
|
|
11
|
+
const localCache = {};
|
|
12
|
+
const filtered = components.filter(({ conditionFilter }) => {
|
|
13
|
+
if (!conditionFilter || !conditionFilter.value) return true;
|
|
14
|
+
const { bindingDependencies, value } = conditionFilter;
|
|
15
|
+
if (localCache[value] !== undefined) return localCache[value];
|
|
16
|
+
if (
|
|
17
|
+
(!bindingDependencies ||
|
|
18
|
+
!updatedVars.some((t) => bindingDependencies.includes(t))) &&
|
|
19
|
+
cache[value] !== undefined
|
|
20
|
+
)
|
|
21
|
+
return cache[value];
|
|
22
|
+
const vectorialBindings = buildVectorialBindings(bindings);
|
|
23
|
+
const inter = interpret(features)(vectorialBindings)(value);
|
|
24
|
+
localCache[value] = inter;
|
|
25
|
+
return inter;
|
|
26
|
+
});
|
|
27
|
+
cache = { ...cache, ...localCache };
|
|
28
|
+
return filtered;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const buildComponents = ({
|
|
32
|
+
components,
|
|
33
|
+
management,
|
|
34
|
+
bindings,
|
|
35
|
+
features,
|
|
36
|
+
page,
|
|
37
|
+
pagination,
|
|
38
|
+
todo,
|
|
39
|
+
}) => {
|
|
40
|
+
if (management && !pagination) return components;
|
|
41
|
+
|
|
42
|
+
if (management && pagination)
|
|
43
|
+
return components.filter((c) =>
|
|
44
|
+
customFilterPagination(c, pagination, page)
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
if (isDev) {
|
|
48
|
+
console.log('Start filter');
|
|
49
|
+
var start = new Date().getTime();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const updatedVars = Object.keys(todo);
|
|
53
|
+
|
|
54
|
+
if (!pagination) {
|
|
55
|
+
const filtered = filterComponents({
|
|
56
|
+
components,
|
|
57
|
+
updatedVars,
|
|
58
|
+
features,
|
|
59
|
+
bindings,
|
|
60
|
+
});
|
|
61
|
+
if (isDev) console.log(`End filter: ${new Date().getTime() - start} ms`);
|
|
62
|
+
return filtered;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const pageComponents = components.filter((c) =>
|
|
66
|
+
customFilterPagination(c, pagination, page)
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const pageComponentsFiltered = filterComponents({
|
|
70
|
+
components: pageComponents,
|
|
71
|
+
updatedVars,
|
|
72
|
+
features,
|
|
73
|
+
bindings,
|
|
74
|
+
});
|
|
75
|
+
if (isDev) console.log(`End filter: ${new Date().getTime() - start}`);
|
|
76
|
+
return pageComponentsFiltered;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
let oldComponents = [];
|
|
80
|
+
let memoryTodo = {};
|
|
81
|
+
|
|
82
|
+
export const useFilterComponents = ({
|
|
83
|
+
questionnaire,
|
|
84
|
+
management,
|
|
85
|
+
bindings,
|
|
86
|
+
features,
|
|
87
|
+
page,
|
|
88
|
+
pagination,
|
|
89
|
+
todo,
|
|
90
|
+
}) => {
|
|
91
|
+
if (Object.keys(todo).length > 0) {
|
|
92
|
+
memoryTodo = todo;
|
|
93
|
+
return oldComponents;
|
|
94
|
+
}
|
|
95
|
+
const components = buildComponents({
|
|
96
|
+
components: questionnaire.components,
|
|
97
|
+
management,
|
|
98
|
+
bindings,
|
|
99
|
+
features,
|
|
100
|
+
page,
|
|
101
|
+
pagination,
|
|
102
|
+
todo: memoryTodo,
|
|
103
|
+
});
|
|
104
|
+
oldComponents = components;
|
|
105
|
+
return components;
|
|
106
|
+
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from './lunatic';
|
|
1
|
+
export { default as useLunatic } from './lunatic';
|
|
2
|
+
export { default as useLunaticSplit } from './lunatic-split';
|