@inseefr/lunatic 0.3.1-experimental → 0.3.5-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 -259
- 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 +12 -12
- 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 +4 -2
- 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 +47 -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 +23 -5
- package/src/utils/to-expose/index.js +11 -11
- package/src/utils/to-expose/state.js +23 -15
package/src/utils/lib/index.js
CHANGED
|
@@ -221,28 +221,28 @@ const getIterations = ({ component, bindings, featuresWithoutMD }) => {
|
|
|
221
221
|
export const splitPage = (currentPage = '1', depth) => {
|
|
222
222
|
const currentPageWithDepth = depth
|
|
223
223
|
? currentPage
|
|
224
|
-
|
|
224
|
+
?.split('.')
|
|
225
225
|
.slice(0, depth + 1) // scoped
|
|
226
226
|
.join('.')
|
|
227
227
|
: currentPage;
|
|
228
228
|
|
|
229
229
|
const currentPageWithoutIteration = currentPageWithDepth
|
|
230
|
-
|
|
230
|
+
?.split('#')
|
|
231
231
|
.slice(0, -1)
|
|
232
232
|
.join('#');
|
|
233
233
|
|
|
234
234
|
const currentPageWithoutAnyIteration = currentPageWithDepth
|
|
235
|
-
|
|
235
|
+
?.split('.')
|
|
236
236
|
.map((e) => e.split('#')[0])
|
|
237
237
|
.join('.');
|
|
238
238
|
|
|
239
239
|
const currentRootPage = currentPageWithoutIteration
|
|
240
|
-
|
|
240
|
+
?.split('.')
|
|
241
241
|
.slice(0, -1)
|
|
242
242
|
.join('.');
|
|
243
243
|
|
|
244
244
|
const [currentComponentIndex, currentIteration] = currentPageWithDepth
|
|
245
|
-
|
|
245
|
+
?.split('.')
|
|
246
246
|
.pop()
|
|
247
247
|
.split('#')
|
|
248
248
|
.map((c) => parseInt(c, 10));
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
const getBindingsDependenciesCalculated = (variables) => {
|
|
2
|
+
if (!variables) return {};
|
|
3
|
+
return variables.reduce((acc, { name, bindingDependencies, shapeFrom }) => {
|
|
4
|
+
if (shapeFrom && bindingDependencies)
|
|
5
|
+
return { ...acc, [name]: [...bindingDependencies, shapeFrom] };
|
|
6
|
+
if (bindingDependencies) return { ...acc, [name]: bindingDependencies };
|
|
7
|
+
if (shapeFrom) return { ...acc, [name]: [shapeFrom] };
|
|
8
|
+
return acc;
|
|
9
|
+
}, {});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const getAllDeps = (deps) => (variablesCalcDeps) => {
|
|
13
|
+
if (!deps || !variablesCalcDeps) return [];
|
|
14
|
+
return deps.reduce((acc, dep) => {
|
|
15
|
+
const depsOfDep = variablesCalcDeps[dep];
|
|
16
|
+
if (Array.isArray(depsOfDep)) {
|
|
17
|
+
return [...acc, dep, ...getAllDeps(depsOfDep)(variablesCalcDeps)];
|
|
18
|
+
}
|
|
19
|
+
return [...acc, dep];
|
|
20
|
+
}, []);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const getNestedVarsInFilterOrControl = (element) => {
|
|
24
|
+
if (element && Array.isArray(element?.bindingDependencies))
|
|
25
|
+
return element?.bindingDependencies;
|
|
26
|
+
return [];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const getNestedVarsInComponent = (component) => {
|
|
30
|
+
const {
|
|
31
|
+
componentType,
|
|
32
|
+
bindingDependencies = [],
|
|
33
|
+
conditionFilter,
|
|
34
|
+
controls = [],
|
|
35
|
+
} = component;
|
|
36
|
+
var bindings = [
|
|
37
|
+
...bindingDependencies, // bindingDependencies of Component
|
|
38
|
+
...getNestedVarsInFilterOrControl(conditionFilter), // bindingDependencies of its conditionFilter
|
|
39
|
+
...controls.reduce(
|
|
40
|
+
(acc, c) => [...acc, ...getNestedVarsInFilterOrControl(c)],
|
|
41
|
+
[]
|
|
42
|
+
), // bindingDependencies of its controls
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
if (componentType === 'Loop') {
|
|
46
|
+
const { components, loopDependencies } = component;
|
|
47
|
+
if (Array.isArray(loopDependencies))
|
|
48
|
+
bindings = [...bindings, ...loopDependencies];
|
|
49
|
+
if (Array.isArray(components)) {
|
|
50
|
+
bindings = components.reduce(
|
|
51
|
+
(acc, c) => [...acc, ...getNestedVarsInComponent(c)],
|
|
52
|
+
[...bindings]
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return bindings;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const getNestedVars =
|
|
61
|
+
(components = []) =>
|
|
62
|
+
(variables) => {
|
|
63
|
+
const variableCalculatedDependencies =
|
|
64
|
+
getBindingsDependenciesCalculated(variables);
|
|
65
|
+
const depsVarsTemp = components
|
|
66
|
+
.reduce((acc, c) => {
|
|
67
|
+
return [...acc, ...getNestedVarsInComponent(c)];
|
|
68
|
+
}, [])
|
|
69
|
+
.filter((v, i, a) => a.indexOf(v) === i);
|
|
70
|
+
return getAllDeps(depsVarsTemp)(variableCalculatedDependencies).filter(
|
|
71
|
+
(v, i, a) => a.indexOf(v) === i
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const getUsefullVariablesFromSource = (variables) => (nestedVars) => {
|
|
76
|
+
return variables.filter(({ variableType, name }) => {
|
|
77
|
+
if (variableType === 'CALCULATED' && !nestedVars.includes(name))
|
|
78
|
+
return false;
|
|
79
|
+
if (variableType === 'COLLECTED' && !nestedVars.includes(name))
|
|
80
|
+
return false;
|
|
81
|
+
return true;
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const getSplitQuestionnaireSource = (source) => {
|
|
86
|
+
const { components, variables, ...rest } = source;
|
|
87
|
+
var split = [];
|
|
88
|
+
var currentComponents = [];
|
|
89
|
+
var previousPage = null;
|
|
90
|
+
components.map((c) => {
|
|
91
|
+
const { componentType, page } = c;
|
|
92
|
+
// splitting by Sequence or Loop
|
|
93
|
+
if (
|
|
94
|
+
(componentType === 'Sequence' || componentType === 'Loop') &&
|
|
95
|
+
previousPage !== page
|
|
96
|
+
) {
|
|
97
|
+
if (currentComponents.length > 0) split.push(currentComponents);
|
|
98
|
+
currentComponents = [c];
|
|
99
|
+
} else {
|
|
100
|
+
currentComponents.push(c);
|
|
101
|
+
}
|
|
102
|
+
previousPage = page;
|
|
103
|
+
return null;
|
|
104
|
+
});
|
|
105
|
+
if (currentComponents.length > 0) split.push(currentComponents);
|
|
106
|
+
|
|
107
|
+
return split.reduce((prev, currentSource) => {
|
|
108
|
+
const firstPage = currentSource[0].page;
|
|
109
|
+
const maxPage = currentSource[currentSource.length - 1].page;
|
|
110
|
+
const nestedVars = getNestedVars(currentSource)(variables);
|
|
111
|
+
const newVariables = getUsefullVariablesFromSource(variables)(nestedVars);
|
|
112
|
+
|
|
113
|
+
return [
|
|
114
|
+
...prev,
|
|
115
|
+
{
|
|
116
|
+
...rest,
|
|
117
|
+
variables: newVariables,
|
|
118
|
+
firstPage,
|
|
119
|
+
maxPage,
|
|
120
|
+
components: currentSource,
|
|
121
|
+
},
|
|
122
|
+
];
|
|
123
|
+
}, []);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const getRootPageInSources = (sources) => {
|
|
127
|
+
return sources.map((source) => {
|
|
128
|
+
const { components } = source;
|
|
129
|
+
return components.reduce((acc, { page }) => {
|
|
130
|
+
if (page) return [...acc, page];
|
|
131
|
+
return acc;
|
|
132
|
+
}, []);
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const mergeStateData = (oldData, newData) => {
|
|
137
|
+
return {
|
|
138
|
+
COLLECTED: { ...oldData.COLLECTED, ...newData.COLLECTED },
|
|
139
|
+
CALCULATED: { ...oldData.CALCULATED, ...newData.CALCULATED },
|
|
140
|
+
EXTERNAL: { ...oldData.EXTERNAL, ...newData.EXTERNAL },
|
|
141
|
+
};
|
|
142
|
+
};
|
|
@@ -3,7 +3,8 @@ import { composeFilters, createFilterStopWords } from './filters';
|
|
|
3
3
|
import filterStemmer from './filters/filter-stemmer';
|
|
4
4
|
import filterLength from './filters/filter-length';
|
|
5
5
|
import filterSynonyms from './filters/filter-synonyms';
|
|
6
|
-
import
|
|
6
|
+
import filterAccents from './filters/filter-accents';
|
|
7
|
+
import filterToLower from './filters/filter-to-lower';
|
|
7
8
|
import filterDouble from './filters/filter-double';
|
|
8
9
|
|
|
9
10
|
function createMapFieldsTokenizer(fields, filters) {
|
|
@@ -20,9 +21,10 @@ function createFilterTokens(fields, stopWords) {
|
|
|
20
21
|
const filterStopWords = createFilterStopWords(stopWords);
|
|
21
22
|
const getFilters = composeFilters(
|
|
22
23
|
filterDouble,
|
|
23
|
-
|
|
24
|
+
filterAccents,
|
|
24
25
|
filterStemmer,
|
|
25
26
|
filterSynonyms,
|
|
27
|
+
filterToLower,
|
|
26
28
|
filterStopWords,
|
|
27
29
|
filterLength
|
|
28
30
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import removeAccents from 'remove-accents';
|
|
2
2
|
|
|
3
|
-
function
|
|
3
|
+
function filterAccents(tokens = []) {
|
|
4
4
|
return tokens.map(function (token) {
|
|
5
5
|
if (typeof token === 'string') {
|
|
6
6
|
return removeAccents(token).toLowerCase();
|
|
@@ -9,4 +9,4 @@ function filterAccentsToLower(tokens = []) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export default
|
|
12
|
+
export default filterAccents;
|
|
@@ -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);
|
|
@@ -92,41 +92,60 @@ export const buildNewValue =
|
|
|
92
92
|
return lastValue === value ? null : value;
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
// Separate methods to avoid perf issue on collect simplest use case
|
|
96
|
+
const getCollectedAndExternal = (preferences) => (variables) => {
|
|
96
97
|
const { COLLECTED } = variables;
|
|
97
|
-
|
|
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(
|
|
98
105
|
(acc, [k, { values }]) => ({ ...acc, [k]: values.COLLECTED }),
|
|
99
106
|
{}
|
|
100
107
|
);
|
|
101
108
|
return { ...collected, ...variables.EXTERNAL };
|
|
102
109
|
};
|
|
103
110
|
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
+
};
|
|
110
121
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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;
|
|
129
|
+
|
|
130
|
+
if (isDev) {
|
|
131
|
+
console.log('Start var calculation');
|
|
132
|
+
var start = new Date().getTime();
|
|
133
|
+
}
|
|
115
134
|
|
|
116
|
-
|
|
135
|
+
const { COLLECTED, EXTERNAL, CALCULATED: calculatedVariables } = variables;
|
|
117
136
|
|
|
118
|
-
|
|
137
|
+
const updatedVars = Object.keys(updatedValues);
|
|
119
138
|
|
|
120
|
-
|
|
139
|
+
const bindings = getCollectedAndExternal(preferences)(variables);
|
|
121
140
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
141
|
+
const CALCULATED = getCalculatedVariables(calculatedVariables)({
|
|
142
|
+
bindings,
|
|
143
|
+
updatedVars,
|
|
144
|
+
logFunction,
|
|
145
|
+
});
|
|
127
146
|
|
|
128
|
-
|
|
129
|
-
|
|
147
|
+
if (isDev)
|
|
148
|
+
console.log(`End var calculation: ${new Date().getTime() - start} ms`);
|
|
130
149
|
|
|
131
|
-
|
|
132
|
-
};
|
|
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';
|