@inseefr/lunatic 3.0.0-rc.26 → 3.0.0-rc.28
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/LunaticComponents.d.ts +7 -11
- package/lib/components/LunaticComponents.js +4 -1
- package/lib/components/LunaticComponents.js.map +1 -1
- package/lib/components/Table/Table.js.map +1 -1
- package/lib/components/library.d.ts +1 -1
- package/lib/components/shared/HOC/slottableComponent.d.ts +2 -2
- package/lib/components/shared/MDLabel/MDLabel.js +4 -1
- package/lib/components/shared/MDLabel/MDLabel.js.map +1 -1
- package/lib/components/shared/MDLabel/MDLabel.spec.js +4 -1
- package/lib/components/shared/MDLabel/MDLabel.spec.js.map +1 -1
- package/lib/components/shared/Table/Tbody.spec.js +0 -1
- package/lib/components/shared/Table/Tbody.spec.js.map +1 -1
- package/lib/components/shared/Table/Td.spec.js +0 -1
- package/lib/components/shared/Table/Td.spec.js.map +1 -1
- package/lib/components/type.d.ts +12 -12
- package/lib/hooks/useKeyboardKey.js +1 -0
- package/lib/hooks/useKeyboardKey.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/use-lunatic/actions.d.ts +4 -53
- package/lib/use-lunatic/actions.js +0 -7
- package/lib/use-lunatic/actions.js.map +1 -1
- package/lib/use-lunatic/commons/check-loops.d.ts +2 -2
- package/lib/use-lunatic/commons/check-loops.js.map +1 -1
- package/lib/use-lunatic/commons/check-pager.d.ts +2 -2
- package/lib/use-lunatic/commons/check-pager.js.map +1 -1
- package/lib/use-lunatic/commons/compile-controls.d.ts +2 -2
- package/lib/use-lunatic/commons/compile-controls.js +5 -3
- package/lib/use-lunatic/commons/compile-controls.js.map +1 -1
- package/lib/use-lunatic/commons/create-map-pages.d.ts +2 -2
- package/lib/use-lunatic/commons/create-map-pages.js.map +1 -1
- package/lib/use-lunatic/commons/execute-condition-filter.d.ts +2 -2
- package/lib/use-lunatic/commons/execute-condition-filter.js +3 -4
- package/lib/use-lunatic/commons/execute-condition-filter.js.map +1 -1
- package/lib/use-lunatic/commons/fill-components/fill-component-expressions.d.ts +614 -6
- package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +6 -13
- package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js.map +1 -1
- package/lib/use-lunatic/commons/fill-components/fill-component-expressions.spec.js +1 -1
- package/lib/use-lunatic/commons/fill-components/fill-component-expressions.spec.js.map +1 -1
- package/lib/use-lunatic/commons/fill-components/fill-components.d.ts +19 -17
- package/lib/use-lunatic/commons/fill-components/fill-components.js +29 -29
- package/lib/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/lib/use-lunatic/commons/get-components-from-state.d.ts +2 -3
- package/lib/use-lunatic/commons/get-components-from-state.js +1 -2
- package/lib/use-lunatic/commons/get-components-from-state.js.map +1 -1
- package/lib/use-lunatic/commons/index.d.ts +0 -3
- package/lib/use-lunatic/commons/index.js +0 -3
- package/lib/use-lunatic/commons/index.js.map +1 -1
- package/lib/use-lunatic/commons/is-First-last-page.d.ts +2 -2
- package/lib/use-lunatic/commons/is-First-last-page.js.map +1 -1
- package/lib/use-lunatic/commons/page-navigation.d.ts +3 -3
- package/lib/use-lunatic/commons/page-navigation.js.map +1 -1
- package/lib/use-lunatic/commons/page-navigation.spec.js.map +1 -1
- package/lib/use-lunatic/commons/page-tag.d.ts +4 -4
- package/lib/use-lunatic/commons/page-tag.js.map +1 -1
- package/lib/use-lunatic/commons/page.d.ts +3 -3
- package/lib/use-lunatic/commons/page.js +2 -1
- package/lib/use-lunatic/commons/page.js.map +1 -1
- package/lib/use-lunatic/hooks/use-loop-variables.d.ts +2 -2
- package/lib/use-lunatic/hooks/use-loop-variables.js.map +1 -1
- package/lib/use-lunatic/hooks/use-page-has-response.d.ts +2 -2
- package/lib/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/lib/use-lunatic/hooks/useOverview.d.ts +2 -2
- package/lib/use-lunatic/hooks/useOverview.js.map +1 -1
- package/lib/use-lunatic/props/propComponentType.d.ts +9 -0
- package/lib/use-lunatic/{commons/fill-components/fill-specific-expression.js → props/propComponentType.js} +21 -27
- package/lib/use-lunatic/props/propComponentType.js.map +1 -0
- package/lib/use-lunatic/props/propIterations.d.ts +7 -0
- package/lib/use-lunatic/props/propIterations.js +26 -0
- package/lib/use-lunatic/props/propIterations.js.map +1 -0
- package/lib/use-lunatic/props/propMissingResponse.d.ts +9 -0
- package/lib/use-lunatic/props/propMissingResponse.js +13 -0
- package/lib/use-lunatic/props/propMissingResponse.js.map +1 -0
- package/lib/use-lunatic/props/propValue.d.ts +6 -0
- package/lib/use-lunatic/props/propValue.js +28 -0
- package/lib/use-lunatic/props/propValue.js.map +1 -0
- package/lib/use-lunatic/{commons/fill-components/fill-component-value.spec.js → props/propValue.spec.js} +6 -6
- package/lib/use-lunatic/props/propValue.spec.js.map +1 -0
- package/lib/use-lunatic/reducer/commons/auto-explore-loop.d.ts +2 -2
- package/lib/use-lunatic/reducer/commons/auto-explore-loop.js.map +1 -1
- package/lib/use-lunatic/reducer/commons/validate-condition-filter.d.ts +2 -2
- package/lib/use-lunatic/reducer/commons/validate-condition-filter.js.map +1 -1
- package/lib/use-lunatic/reducer/controls/check-base-control.d.ts +2 -2
- package/lib/use-lunatic/reducer/controls/check-base-control.js.map +1 -1
- package/lib/use-lunatic/reducer/controls/check-roundabout-control.d.ts +2 -2
- package/lib/use-lunatic/reducer/controls/check-roundabout-control.js.map +1 -1
- package/lib/use-lunatic/reducer/overview/overviewOnInit.d.ts +4 -105
- package/lib/use-lunatic/reducer/overview/overviewOnInit.js +1 -12
- package/lib/use-lunatic/reducer/overview/overviewOnInit.js.map +1 -1
- package/lib/use-lunatic/reducer/reduce-go-next-page.d.ts +2 -2
- package/lib/use-lunatic/reducer/reduce-go-next-page.js.map +1 -1
- package/lib/use-lunatic/reducer/reduce-go-previous-page.d.ts +2 -3
- package/lib/use-lunatic/reducer/reduce-go-previous-page.js +1 -2
- package/lib/use-lunatic/reducer/reduce-go-previous-page.js.map +1 -1
- package/lib/use-lunatic/reducer/reduce-go-to-page.d.ts +2 -3
- package/lib/use-lunatic/reducer/reduce-go-to-page.js +1 -2
- package/lib/use-lunatic/reducer/reduce-go-to-page.js.map +1 -1
- package/lib/use-lunatic/reducer/reduce-handle-change.d.ts +2 -2
- package/lib/use-lunatic/reducer/reduce-handle-change.js.map +1 -1
- package/lib/use-lunatic/reducer/reducer.d.ts +2 -3
- package/lib/use-lunatic/reducer/reducer.js +3 -10
- package/lib/use-lunatic/reducer/reducer.js.map +1 -1
- package/lib/use-lunatic/reducer/reducerInitializer.d.ts +10 -0
- package/lib/use-lunatic/reducer/{reduce-on-init.js → reducerInitializer.js} +70 -72
- package/lib/use-lunatic/reducer/reducerInitializer.js.map +1 -0
- package/lib/use-lunatic/type.d.ts +80 -49
- package/lib/use-lunatic/use-lunatic.d.ts +22 -65
- package/lib/use-lunatic/use-lunatic.js +69 -74
- package/lib/use-lunatic/use-lunatic.js.map +1 -1
- package/lib/utils/object.d.ts +1 -0
- package/lib/utils/object.js +6 -0
- package/lib/utils/object.js.map +1 -1
- package/package.json +2 -1
- package/lib/stories/behaviour/cleaning/source-loop.json +0 -130
- package/lib/stories/behaviour/resizing/source-resizing-cleaning.json +0 -171
- package/lib/stories/overview/dataLoop.json +0 -189
- package/lib/stories/overview/source.json +0 -28
- package/lib/stories/overview/sourceLoop.json +0 -1423
- package/lib/stories/questionnaires/logement/source.json +0 -31762
- package/lib/stories/questionnaires2023/simpsons/source.json +0 -4728
- package/lib/use-lunatic/commons/fill-components/fill-component-required.d.ts +0 -442
- package/lib/use-lunatic/commons/fill-components/fill-component-required.js +0 -13
- package/lib/use-lunatic/commons/fill-components/fill-component-required.js.map +0 -1
- package/lib/use-lunatic/commons/fill-components/fill-component-value.d.ts +0 -5
- package/lib/use-lunatic/commons/fill-components/fill-component-value.js +0 -34
- package/lib/use-lunatic/commons/fill-components/fill-component-value.js.map +0 -1
- package/lib/use-lunatic/commons/fill-components/fill-component-value.spec.js.map +0 -1
- package/lib/use-lunatic/commons/fill-components/fill-from-state.d.ts +0 -770
- package/lib/use-lunatic/commons/fill-components/fill-from-state.js +0 -18
- package/lib/use-lunatic/commons/fill-components/fill-from-state.js.map +0 -1
- package/lib/use-lunatic/commons/fill-components/fill-iterations.d.ts +0 -124
- package/lib/use-lunatic/commons/fill-components/fill-iterations.js +0 -36
- package/lib/use-lunatic/commons/fill-components/fill-iterations.js.map +0 -1
- package/lib/use-lunatic/commons/fill-components/fill-management.d.ts +0 -6
- package/lib/use-lunatic/commons/fill-components/fill-management.js +0 -9
- package/lib/use-lunatic/commons/fill-components/fill-management.js.map +0 -1
- package/lib/use-lunatic/commons/fill-components/fill-missing-response.d.ts +0 -12
- package/lib/use-lunatic/commons/fill-components/fill-missing-response.js +0 -20
- package/lib/use-lunatic/commons/fill-components/fill-missing-response.js.map +0 -1
- package/lib/use-lunatic/commons/fill-components/fill-pagination.d.ts +0 -9
- package/lib/use-lunatic/commons/fill-components/fill-pagination.js +0 -10
- package/lib/use-lunatic/commons/fill-components/fill-pagination.js.map +0 -1
- package/lib/use-lunatic/commons/fill-components/fill-specific-expression.d.ts +0 -1268
- package/lib/use-lunatic/commons/fill-components/fill-specific-expression.js.map +0 -1
- package/lib/use-lunatic/commons/fill-components/index.d.ts +0 -1
- package/lib/use-lunatic/commons/fill-components/index.js +0 -2
- package/lib/use-lunatic/commons/fill-components/index.js.map +0 -1
- package/lib/use-lunatic/commons/use-components-from-state.d.ts +0 -4
- package/lib/use-lunatic/commons/use-components-from-state.js +0 -15
- package/lib/use-lunatic/commons/use-components-from-state.js.map +0 -1
- package/lib/use-lunatic/initial-state.d.ts +0 -3
- package/lib/use-lunatic/initial-state.js +0 -39
- package/lib/use-lunatic/initial-state.js.map +0 -1
- package/lib/use-lunatic/reducer/index.d.ts +0 -1
- package/lib/use-lunatic/reducer/index.js +0 -2
- package/lib/use-lunatic/reducer/index.js.map +0 -1
- package/lib/use-lunatic/reducer/reduce-on-init.d.ts +0 -4
- package/lib/use-lunatic/reducer/reduce-on-init.js.map +0 -1
- package/lib/use-lunatic/reducer/reduce-on-set-waiting.d.ts +0 -4
- package/lib/use-lunatic/reducer/reduce-on-set-waiting.js +0 -8
- package/lib/use-lunatic/reducer/reduce-on-set-waiting.js.map +0 -1
- package/lib/use-lunatic/use-lunatic.test.d.ts +0 -1
- package/lib/use-lunatic/use-lunatic.test.js +0 -280
- package/lib/use-lunatic/use-lunatic.test.js.map +0 -1
- /package/lib/use-lunatic/{commons/fill-components/fill-component-value.spec.d.ts → props/propValue.spec.d.ts} +0 -0
|
@@ -1,59 +1,36 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {} from '../actions';
|
|
3
|
-
import { checkLoops, createMapPages, isFirstLastPage } from '../commons';
|
|
4
|
-
import compose from '../commons/compose';
|
|
5
|
-
import { getPagerFromPageTag } from '../commons/page-tag';
|
|
6
|
-
import { reduceOverviewOnInit } from './overview/overviewOnInit';
|
|
7
2
|
import { LunaticVariablesStore } from '../commons/variables/lunatic-variables-store';
|
|
3
|
+
import { checkLoops, createMapPages } from '../commons';
|
|
4
|
+
import { getExpressionAsString, getExpressionType } from '../../utils/vtl';
|
|
8
5
|
import { MD, VTL } from '../../utils/constants';
|
|
9
6
|
import { MDLabel } from '../../components/shared/MDLabel/MDLabel';
|
|
10
|
-
import {
|
|
7
|
+
import { getPagerFromPageTag } from '../commons/page-tag';
|
|
8
|
+
import { buildOverview } from './overview/overviewOnInit';
|
|
11
9
|
import { forceInt } from '../../utils/number';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const { page } = pager;
|
|
18
|
-
if (page in pages) {
|
|
19
|
-
const { isLoop, subPages, iterations, loopDependencies } = pages[page];
|
|
20
|
-
if (isLoop) {
|
|
21
|
-
return {
|
|
22
|
-
...state,
|
|
23
|
-
isInLoop: true,
|
|
24
|
-
pager: {
|
|
25
|
-
...pager,
|
|
26
|
-
subPage: initialPager?.subPage ?? 0,
|
|
27
|
-
nbSubPages: (subPages ?? []).length,
|
|
28
|
-
iteration: initialPager?.iteration ?? 0,
|
|
29
|
-
nbIterations: forceInt(state.executeExpression(iterations, {
|
|
30
|
-
deps: loopDependencies,
|
|
31
|
-
})),
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return state;
|
|
37
|
-
}
|
|
38
|
-
function reduceOnInit(state, action) {
|
|
39
|
-
const { payload } = action;
|
|
40
|
-
const { source, data, initialPage, lastReachedPage, handleChange, preferences, savingType, management, shortcut, activeControls, goToPage, goNextPage, goPreviousPage, } = payload;
|
|
41
|
-
if (!source || !data) {
|
|
42
|
-
return state;
|
|
43
|
-
}
|
|
44
|
-
const variables = LunaticVariablesStore.makeFromSource(source, data);
|
|
45
|
-
const pages = checkLoops(createMapPages(source));
|
|
46
|
-
const { maxPage, cleaning = {}, missingBlock = {} } = source;
|
|
47
|
-
const initialPager = getPagerFromPageTag(initialPage);
|
|
48
|
-
const pager = {
|
|
49
|
-
page: initialPager?.page ?? 1,
|
|
50
|
-
maxPage: parseInt(maxPage, 10),
|
|
10
|
+
const baseState = {
|
|
11
|
+
variables: new LunaticVariablesStore(),
|
|
12
|
+
pager: {
|
|
13
|
+
page: 1,
|
|
14
|
+
maxPage: 1,
|
|
51
15
|
subPage: undefined,
|
|
52
16
|
nbSubPages: undefined,
|
|
53
17
|
iteration: undefined,
|
|
18
|
+
shallowIteration: undefined,
|
|
54
19
|
nbIterations: undefined,
|
|
55
|
-
|
|
56
|
-
}
|
|
20
|
+
},
|
|
21
|
+
pages: {},
|
|
22
|
+
isInLoop: false,
|
|
23
|
+
updatedAt: Date.now(),
|
|
24
|
+
overview: [],
|
|
25
|
+
updateBindings: () => { },
|
|
26
|
+
executeExpression: () => null,
|
|
27
|
+
};
|
|
28
|
+
export function reducerInitializer({ source, data, features = ['VTL'], initialPage = '1', lastReachedPage = undefined, withOverview = false, }) {
|
|
29
|
+
const variables = LunaticVariablesStore.makeFromSource(source, data);
|
|
30
|
+
const pages = checkLoops(createMapPages(source));
|
|
31
|
+
if (!source || !data) {
|
|
32
|
+
return baseState;
|
|
33
|
+
}
|
|
57
34
|
const executeExpression = (expression, args = {}) => {
|
|
58
35
|
// This is kept to ensure backward compatibility
|
|
59
36
|
if (args?.bindingDependencies) {
|
|
@@ -61,8 +38,7 @@ function reduceOnInit(state, action) {
|
|
|
61
38
|
}
|
|
62
39
|
// Remove above code on next update
|
|
63
40
|
const expressionType = getExpressionType(expression);
|
|
64
|
-
|
|
65
|
-
if (!features.includes(VTL) || !expressionType.includes(VTL)) {
|
|
41
|
+
if (!features?.includes(VTL) || !expressionType.includes(VTL)) {
|
|
66
42
|
return expression;
|
|
67
43
|
}
|
|
68
44
|
const expressionString = getExpressionAsString(expression);
|
|
@@ -89,29 +65,51 @@ function reduceOnInit(state, action) {
|
|
|
89
65
|
const updateBindings = (variableName, value, options) => {
|
|
90
66
|
variables.set(variableName, value, options);
|
|
91
67
|
};
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
68
|
+
const initialPager = getPagerFromPageTag(initialPage);
|
|
69
|
+
const pager = {
|
|
70
|
+
page: initialPager?.page ?? 1,
|
|
71
|
+
maxPage: source.maxPage ? parseInt(source.maxPage, 10) : 1,
|
|
72
|
+
subPage: undefined,
|
|
73
|
+
nbSubPages: undefined,
|
|
74
|
+
iteration: undefined,
|
|
75
|
+
nbIterations: undefined,
|
|
76
|
+
lastReachedPage: lastReachedPage ?? initialPage,
|
|
77
|
+
};
|
|
78
|
+
return fillPagerForLoop({
|
|
79
|
+
variables,
|
|
101
80
|
pager,
|
|
102
|
-
|
|
81
|
+
pages,
|
|
82
|
+
isInLoop: false,
|
|
83
|
+
updatedAt: Date.now(),
|
|
84
|
+
overview: withOverview ? buildOverview(source) : [],
|
|
103
85
|
updateBindings,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
86
|
+
executeExpression,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check if there is a loop and populate the pager accordingly
|
|
91
|
+
**/
|
|
92
|
+
function fillPagerForLoop(state) {
|
|
93
|
+
const { pager, pages } = state;
|
|
94
|
+
if (!(pager.page in pages)) {
|
|
95
|
+
return state;
|
|
96
|
+
}
|
|
97
|
+
const { isLoop, subPages, iterations, loopDependencies } = pages[pager.page];
|
|
98
|
+
if (!isLoop) {
|
|
99
|
+
return state;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
...state,
|
|
103
|
+
isInLoop: true,
|
|
104
|
+
pager: {
|
|
105
|
+
...pager,
|
|
106
|
+
subPage: pager?.subPage ?? 0,
|
|
107
|
+
nbSubPages: (subPages ?? []).length,
|
|
108
|
+
iteration: pager?.iteration ?? 0,
|
|
109
|
+
nbIterations: forceInt(state.executeExpression(iterations, {
|
|
110
|
+
deps: loopDependencies,
|
|
111
|
+
})),
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
export default reducers;
|
|
117
|
-
//# sourceMappingURL=reduce-on-init.js.map
|
|
115
|
+
//# sourceMappingURL=reducerInitializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reducerInitializer.js","sourceRoot":"","sources":["../../../src/use-lunatic/reducer/reducerInitializer.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OA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AU,EAAE,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,MAAM;YACnC,SAAS,EAAE,KAAK,EAAE,SAAS,IAAI,CAAC;YAChC,YAAY,EAAE,QAAQ,CACrB,KAAK,CAAC,iBAAiB,CAAC,UAAU,EAAE;gBACnC,IAAI,EAAE,gBAAgB;aACtB,CAAC,CACF;SACD;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
import type { ComponentType, ControlType,
|
|
1
|
+
import type { FunctionComponent, PropsWithChildren, ReactNode } from 'react';
|
|
2
|
+
import type { ComponentType, ControlType, Variable } from './type-source';
|
|
3
3
|
import type { LunaticVariablesStore } from './commons/variables/lunatic-variables-store';
|
|
4
|
+
import type { IndexEntry } from '../utils/search/SearchInterface';
|
|
5
|
+
import type { InterpretedLunaticOverviewItem } from './hooks/useOverview';
|
|
6
|
+
import type { LunaticComponentProps } from '../components/type';
|
|
4
7
|
export type LunaticComponentDefinition<T extends ComponentType['componentType'] = ComponentType['componentType']> = ComponentType & {
|
|
5
8
|
componentType: T;
|
|
6
9
|
};
|
|
@@ -34,7 +37,6 @@ export type LunaticExpression = {
|
|
|
34
37
|
type: ExpressionType;
|
|
35
38
|
bindingDependencies?: string[];
|
|
36
39
|
};
|
|
37
|
-
export type TODO = unknown;
|
|
38
40
|
export type PageTag = `${number}.${number}#${number}` | `${number}`;
|
|
39
41
|
export type LunaticVariable = Variable;
|
|
40
42
|
export type LunaticCollectedValue = Partial<{
|
|
@@ -54,9 +56,21 @@ export type LunaticStateVariable = {
|
|
|
54
56
|
CalculatedLinked?: LunaticVariable[];
|
|
55
57
|
};
|
|
56
58
|
}[LunaticVariable['variableType']];
|
|
57
|
-
export type
|
|
58
|
-
|
|
59
|
+
export type LunaticPager = {
|
|
60
|
+
lastReachedPage?: PageTag;
|
|
61
|
+
maxPage: number;
|
|
62
|
+
nbSubPages?: number;
|
|
63
|
+
page: number;
|
|
64
|
+
subPage?: number;
|
|
65
|
+
iteration?: number;
|
|
66
|
+
nbIterations?: number;
|
|
67
|
+
shallowIteration?: number;
|
|
68
|
+
linksIterations?: number[];
|
|
69
|
+
};
|
|
70
|
+
export type LunaticReducerState = {
|
|
59
71
|
variables: LunaticVariablesStore;
|
|
72
|
+
overview: LunaticOverviewItem[];
|
|
73
|
+
pager: LunaticPager;
|
|
60
74
|
pages: {
|
|
61
75
|
[key: number | string]: {
|
|
62
76
|
components: ComponentType[];
|
|
@@ -72,37 +86,50 @@ export type LunaticState = {
|
|
|
72
86
|
subPages: string[];
|
|
73
87
|
};
|
|
74
88
|
};
|
|
89
|
+
executeExpression: <T extends unknown = unknown>(expression: unknown, args?: {
|
|
90
|
+
iteration?: number | number[];
|
|
91
|
+
bindingDependencies?: string[];
|
|
92
|
+
deps?: string[];
|
|
93
|
+
}) => T;
|
|
94
|
+
isInLoop: boolean;
|
|
95
|
+
updatedAt: number;
|
|
96
|
+
updateBindings: (variableName: string, value: unknown, options: {
|
|
97
|
+
iteration?: number[];
|
|
98
|
+
}) => unknown;
|
|
99
|
+
};
|
|
100
|
+
export type LunaticOptions = {
|
|
101
|
+
features?: ('MD' | 'VTL')[];
|
|
102
|
+
preferences?: ['COLLECTED'];
|
|
103
|
+
savingType?: 'COLLECTED';
|
|
104
|
+
onChange?: LunaticChangeHandler;
|
|
105
|
+
management?: boolean;
|
|
106
|
+
shortcut?: boolean;
|
|
107
|
+
initialPage?: PageTag;
|
|
108
|
+
lastReachedPage?: PageTag;
|
|
109
|
+
autoSuggesterLoading?: boolean;
|
|
110
|
+
getReferentiel?: (name: string) => Promise<Array<IndexEntry>>;
|
|
111
|
+
activeControls?: boolean;
|
|
112
|
+
withOverview?: boolean;
|
|
113
|
+
missing?: boolean;
|
|
114
|
+
missingStrategy?: () => void;
|
|
115
|
+
missingShortcut?: {
|
|
116
|
+
dontKnow: string;
|
|
117
|
+
refused: string;
|
|
118
|
+
};
|
|
119
|
+
dontKnowButton?: string;
|
|
120
|
+
refusedButton?: string;
|
|
121
|
+
trackChanges?: boolean;
|
|
122
|
+
};
|
|
123
|
+
export type LunaticState = {
|
|
124
|
+
pager: LunaticPager;
|
|
125
|
+
overview: InterpretedLunaticOverviewItem[];
|
|
126
|
+
pageTag: PageTag;
|
|
127
|
+
updatedAt: number;
|
|
128
|
+
Provider: FunctionComponent<PropsWithChildren>;
|
|
75
129
|
isInLoop: boolean;
|
|
130
|
+
loopVariables: string[];
|
|
76
131
|
isFirstPage: boolean;
|
|
77
132
|
isLastPage: boolean;
|
|
78
|
-
features: ['VTL'] | ['VTL', 'MD'];
|
|
79
|
-
preferences: ['COLLECTED'];
|
|
80
|
-
savingType: 'COLLECTED';
|
|
81
|
-
cleaning: LunaticSource['cleaning'];
|
|
82
|
-
missingBlock: {
|
|
83
|
-
[variable: string]: string[];
|
|
84
|
-
};
|
|
85
|
-
resizing: {
|
|
86
|
-
[variable: string]: {
|
|
87
|
-
size: string;
|
|
88
|
-
variables: string[];
|
|
89
|
-
sizeForLinksVariables?: unknown;
|
|
90
|
-
linksVariables?: string[];
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
overview: LunaticOverviewItem[];
|
|
94
|
-
pager: {
|
|
95
|
-
lastReachedPage?: PageTag;
|
|
96
|
-
maxPage: number;
|
|
97
|
-
nbSubPages?: number;
|
|
98
|
-
page: number;
|
|
99
|
-
subPage?: number;
|
|
100
|
-
iteration?: number;
|
|
101
|
-
nbIterations?: number;
|
|
102
|
-
shallowIteration?: number;
|
|
103
|
-
linksIterations?: number[];
|
|
104
|
-
};
|
|
105
|
-
waiting: boolean;
|
|
106
133
|
errors?: {
|
|
107
134
|
[page: string]: {
|
|
108
135
|
[id: string]: LunaticError[];
|
|
@@ -112,22 +139,6 @@ export type LunaticState = {
|
|
|
112
139
|
[id: string]: LunaticError[];
|
|
113
140
|
};
|
|
114
141
|
modalErrors?: Record<string, LunaticError[]>;
|
|
115
|
-
handleChange: (response: {
|
|
116
|
-
name: string;
|
|
117
|
-
}, value: any, args?: {
|
|
118
|
-
iteration?: number[];
|
|
119
|
-
}) => void;
|
|
120
|
-
executeExpression: <T extends unknown = unknown>(expression: unknown, args?: {
|
|
121
|
-
iteration?: number | number[];
|
|
122
|
-
bindingDependencies?: string[];
|
|
123
|
-
deps?: string[];
|
|
124
|
-
}) => T;
|
|
125
|
-
updateBindings: (variableName: string, value: unknown, options: {
|
|
126
|
-
iteration?: number[];
|
|
127
|
-
}) => unknown;
|
|
128
|
-
activeControls: boolean;
|
|
129
|
-
shortcut?: boolean;
|
|
130
|
-
management?: boolean;
|
|
131
142
|
goToPage: (page: {
|
|
132
143
|
page: PageTag | number;
|
|
133
144
|
iteration?: number;
|
|
@@ -136,4 +147,24 @@ export type LunaticState = {
|
|
|
136
147
|
}) => void;
|
|
137
148
|
goNextPage: () => void;
|
|
138
149
|
goPreviousPage: () => void;
|
|
150
|
+
compileControls: () => {
|
|
151
|
+
currentErrors: Record<string, LunaticError[]> | undefined;
|
|
152
|
+
isCritical: boolean;
|
|
153
|
+
};
|
|
154
|
+
getComponents: (params?: {
|
|
155
|
+
only?: LunaticComponentProps['componentType'];
|
|
156
|
+
except?: LunaticComponentProps['componentType'];
|
|
157
|
+
}) => LunaticComponentProps[];
|
|
158
|
+
getData: (withRefreshedCalculated: boolean, variableNames?: string[]) => LunaticData;
|
|
159
|
+
getChangedData: (reset: boolean) => LunaticData;
|
|
160
|
+
resetChangedData: () => void;
|
|
161
|
+
hasPageResponse: () => boolean;
|
|
162
|
+
testing: {
|
|
163
|
+
handleChange: LunaticChangeHandler;
|
|
164
|
+
};
|
|
139
165
|
};
|
|
166
|
+
export type LunaticChangeHandler = (response: {
|
|
167
|
+
name: string;
|
|
168
|
+
}, value: any, args?: {
|
|
169
|
+
iteration?: number[];
|
|
170
|
+
}) => void;
|
|
@@ -1,45 +1,21 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type {
|
|
2
|
+
import type { LunaticChangeHandler, LunaticData, LunaticOptions, PageTag } from './type';
|
|
3
3
|
import type { LunaticSource } from './type-source';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
savingType?: LunaticState['savingType'];
|
|
18
|
-
onChange?: LunaticState['handleChange'];
|
|
19
|
-
management?: boolean;
|
|
20
|
-
shortcut?: boolean;
|
|
21
|
-
initialPage?: PageTag;
|
|
22
|
-
lastReachedPage?: PageTag;
|
|
23
|
-
autoSuggesterLoading?: boolean;
|
|
24
|
-
getReferentiel?: (name: string) => Promise<Array<IndexEntry>>;
|
|
25
|
-
activeControls?: boolean;
|
|
26
|
-
withOverview?: boolean;
|
|
27
|
-
missing?: boolean;
|
|
28
|
-
missingStrategy?: () => void;
|
|
29
|
-
missingShortcut?: {
|
|
30
|
-
dontKnow: string;
|
|
31
|
-
refused: string;
|
|
32
|
-
};
|
|
33
|
-
dontKnowButton?: string;
|
|
34
|
-
refusedButton?: string;
|
|
35
|
-
trackChanges?: boolean;
|
|
36
|
-
}): {
|
|
37
|
-
getComponents: ({ only, except, }?: {
|
|
38
|
-
only?: LunaticComponentProps['componentType'];
|
|
39
|
-
except?: LunaticComponentProps['componentType'];
|
|
40
|
-
}) => LunaticComponentProps[];
|
|
4
|
+
declare function useLunatic(source: LunaticSource, data?: LunaticData, argOptions?: LunaticOptions): {
|
|
5
|
+
pageTag: PageTag;
|
|
6
|
+
isFirstPage: boolean;
|
|
7
|
+
isLastPage: boolean;
|
|
8
|
+
updatedAt: number;
|
|
9
|
+
pager: import("./type").LunaticPager;
|
|
10
|
+
isInLoop: boolean;
|
|
11
|
+
overview: import("./hooks/useOverview").InterpretedLunaticOverviewItem[];
|
|
12
|
+
loopVariables: string[];
|
|
13
|
+
getComponents: (params?: {
|
|
14
|
+
only?: "Sequence" | "Subsequence" | "RosterForLoop" | "Loop" | "Table" | "InputNumber" | "Datepicker" | "Duration" | "CheckboxGroup" | "CheckboxBoolean" | "Radio" | "FilterDescription" | "Dropdown" | "PairwiseLinks" | "Roundabout" | "Suggester" | "Input" | "Textarea" | "CheckboxOne" | "Question" | "Switch" | "Summary" | undefined;
|
|
15
|
+
except?: "Sequence" | "Subsequence" | "RosterForLoop" | "Loop" | "Table" | "InputNumber" | "Datepicker" | "Duration" | "CheckboxGroup" | "CheckboxBoolean" | "Radio" | "FilterDescription" | "Dropdown" | "PairwiseLinks" | "Roundabout" | "Suggester" | "Input" | "Textarea" | "CheckboxOne" | "Question" | "Switch" | "Summary" | undefined;
|
|
16
|
+
} | undefined) => import("..").LunaticComponentProps[];
|
|
41
17
|
goPreviousPage: () => void;
|
|
42
|
-
goNextPage: (
|
|
18
|
+
goNextPage: () => void;
|
|
43
19
|
goToPage: (page: {
|
|
44
20
|
page: number | PageTag;
|
|
45
21
|
iteration?: number | undefined;
|
|
@@ -50,22 +26,7 @@ declare function useLunatic(source: LunaticSource, data: Partial<Record<"EXTERNA
|
|
|
50
26
|
currentErrors: Record<string, import("./type").LunaticError[]> | undefined;
|
|
51
27
|
isCritical: boolean;
|
|
52
28
|
};
|
|
53
|
-
|
|
54
|
-
isFirstPage: boolean;
|
|
55
|
-
isLastPage: boolean;
|
|
56
|
-
pager: {
|
|
57
|
-
lastReachedPage?: PageTag | undefined;
|
|
58
|
-
maxPage: number;
|
|
59
|
-
nbSubPages?: number | undefined;
|
|
60
|
-
page: number;
|
|
61
|
-
subPage?: number | undefined;
|
|
62
|
-
iteration?: number | undefined;
|
|
63
|
-
nbIterations?: number | undefined;
|
|
64
|
-
shallowIteration?: number | undefined;
|
|
65
|
-
linksIterations?: number[] | undefined;
|
|
66
|
-
};
|
|
67
|
-
waiting: boolean;
|
|
68
|
-
getData: (withRefreshedCalculated: boolean, variableNames?: string[]) => Partial<Record<"EXTERNAL" | "CALCULATED", Record<string, unknown>> & {
|
|
29
|
+
getData: (withRefreshedCalculated: boolean, variableNames?: string[] | undefined) => Partial<Record<"EXTERNAL" | "CALCULATED", Record<string, unknown>> & {
|
|
69
30
|
COLLECTED: Record<string, Partial<{
|
|
70
31
|
COLLECTED: unknown;
|
|
71
32
|
EDITED: unknown;
|
|
@@ -74,16 +35,6 @@ declare function useLunatic(source: LunaticSource, data: Partial<Record<"EXTERNA
|
|
|
74
35
|
PREVIOUS: unknown;
|
|
75
36
|
}>>;
|
|
76
37
|
}>;
|
|
77
|
-
Provider: import("react").FunctionComponent<{
|
|
78
|
-
children?: import("react").ReactNode;
|
|
79
|
-
}>;
|
|
80
|
-
onChange: (response: {
|
|
81
|
-
name: string;
|
|
82
|
-
}, value: any, args?: {
|
|
83
|
-
iteration?: number[] | undefined;
|
|
84
|
-
} | undefined) => void;
|
|
85
|
-
overview: import("./hooks/useOverview").InterpretedLunaticOverviewItem[];
|
|
86
|
-
loopVariables: string[];
|
|
87
38
|
getChangedData: (reset?: boolean) => Partial<Record<"EXTERNAL" | "CALCULATED", Record<string, unknown>> & {
|
|
88
39
|
COLLECTED: Record<string, Partial<{
|
|
89
40
|
COLLECTED: unknown;
|
|
@@ -95,5 +46,11 @@ declare function useLunatic(source: LunaticSource, data: Partial<Record<"EXTERNA
|
|
|
95
46
|
}>;
|
|
96
47
|
resetChangedData: () => void;
|
|
97
48
|
hasPageResponse: () => boolean;
|
|
49
|
+
Provider: import("react").FunctionComponent<{
|
|
50
|
+
children?: import("react").ReactNode;
|
|
51
|
+
}>;
|
|
52
|
+
testing: {
|
|
53
|
+
handleChange: LunaticChangeHandler;
|
|
54
|
+
};
|
|
98
55
|
};
|
|
99
56
|
export default useLunatic;
|
|
@@ -1,35 +1,54 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useReducer } from 'react';
|
|
2
2
|
import * as actions from './actions';
|
|
3
|
-
import { getPageTag, isFirstLastPage
|
|
3
|
+
import { getPageTag, isFirstLastPage } from './commons';
|
|
4
4
|
import D from '../i18n';
|
|
5
5
|
import { COLLECTED } from '../utils/constants';
|
|
6
|
-
import INITIAL_STATE from './initial-state';
|
|
7
6
|
import { createLunaticProvider } from './lunatic-context';
|
|
8
7
|
import { compileControls as compileControlsLib } from './commons/compile-controls';
|
|
9
8
|
import { useLoopVariables } from './hooks/use-loop-variables';
|
|
10
|
-
import reducer from './reducer';
|
|
11
9
|
import { getQuestionnaireData } from './commons/variables/get-questionnaire-data';
|
|
12
10
|
import { useTrackChanges } from '../hooks/use-track-changes';
|
|
13
11
|
import { usePageHasResponse } from './hooks/use-page-has-response';
|
|
14
12
|
import { registerSuggesters } from '../utils/search/SuggestersDatabase';
|
|
15
13
|
import { useRefSync } from '../hooks/useRefSync';
|
|
16
14
|
import { useOverview } from './hooks/useOverview';
|
|
15
|
+
import { reducerInitializer } from './reducer/reducerInitializer';
|
|
16
|
+
import { getComponentsFromState } from './commons/get-components-from-state';
|
|
17
|
+
import { fillComponents } from './commons/fill-components/fill-components';
|
|
18
|
+
import { reducer } from './reducer/reducer';
|
|
19
|
+
import { mergeDefault } from '../utils/object';
|
|
17
20
|
const empty = {}; // Keep the same empty object (to avoid problem with useEffect dependencies)
|
|
18
|
-
const emptyFn = () => { };
|
|
19
21
|
const DEFAULT_DATA = empty;
|
|
20
22
|
const DEFAULT_FEATURES = ['VTL', 'MD'];
|
|
21
23
|
const DEFAULT_PREFERENCES = [COLLECTED];
|
|
22
24
|
const DEFAULT_SHORTCUT = { dontKnow: '', refused: '' };
|
|
23
25
|
const DEFAULT_DONT_KNOW = D.DK;
|
|
24
26
|
const DEFAULT_REFUSED = D.RF;
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
const defaultOptions = {
|
|
28
|
+
features: DEFAULT_FEATURES,
|
|
29
|
+
preferences: DEFAULT_PREFERENCES,
|
|
30
|
+
savingType: COLLECTED,
|
|
31
|
+
onChange: () => { },
|
|
32
|
+
management: false,
|
|
33
|
+
shortcut: false,
|
|
34
|
+
initialPage: '1',
|
|
35
|
+
lastReachedPage: undefined,
|
|
36
|
+
autoSuggesterLoading: false,
|
|
37
|
+
activeControls: false,
|
|
38
|
+
// Calculate an overview of every sequence (will be exposed as "overview")
|
|
39
|
+
withOverview: false,
|
|
40
|
+
missing: false,
|
|
41
|
+
missingStrategy: () => { },
|
|
42
|
+
missingShortcut: DEFAULT_SHORTCUT,
|
|
43
|
+
dontKnowButton: DEFAULT_DONT_KNOW,
|
|
44
|
+
refusedButton: DEFAULT_REFUSED,
|
|
45
|
+
trackChanges: false,
|
|
46
|
+
};
|
|
47
|
+
function useLunatic(source, data = DEFAULT_DATA, argOptions = empty) {
|
|
48
|
+
const options = mergeDefault(argOptions, defaultOptions);
|
|
49
|
+
const { management, missing, missingStrategy, shortcut, missingShortcut, dontKnowButton, refusedButton, onChange, trackChanges, preferences, } = options;
|
|
50
|
+
const [state, dispatch] = useReducer(reducer, { ...options, source, data }, reducerInitializer);
|
|
51
|
+
const getReferentielRef = useRefSync(options.getReferentiel);
|
|
33
52
|
// Register the list of suggesters
|
|
34
53
|
useEffect(() => {
|
|
35
54
|
if (source.suggesters && getReferentielRef.current) {
|
|
@@ -54,9 +73,9 @@ withOverview = false, missing = false, missingStrategy = emptyFn, missingShortcu
|
|
|
54
73
|
dontKnowButton,
|
|
55
74
|
refusedButton,
|
|
56
75
|
]);
|
|
57
|
-
const compileControls =
|
|
58
|
-
return compileControlsLib(
|
|
59
|
-
}
|
|
76
|
+
const compileControls = () => {
|
|
77
|
+
return compileControlsLib(state);
|
|
78
|
+
};
|
|
60
79
|
const goPreviousPage = useCallback(function () {
|
|
61
80
|
dispatch(actions.goPreviousPage());
|
|
62
81
|
}, [dispatch]);
|
|
@@ -66,18 +85,6 @@ withOverview = false, missing = false, missingStrategy = emptyFn, missingShortcu
|
|
|
66
85
|
const goToPage = useCallback(function (payload) {
|
|
67
86
|
dispatch(actions.goToPage(payload));
|
|
68
87
|
}, [dispatch]);
|
|
69
|
-
const getComponents = useCallback(function ({ only, except, } = {}) {
|
|
70
|
-
if (only && except) {
|
|
71
|
-
throw new Error('"only" and "except" cannot be used together in getComponents()');
|
|
72
|
-
}
|
|
73
|
-
if (only) {
|
|
74
|
-
return components.filter((c) => only.includes(c.componentType ?? ''));
|
|
75
|
-
}
|
|
76
|
-
if (except) {
|
|
77
|
-
return components.filter((c) => !except.includes(c.componentType ?? ''));
|
|
78
|
-
}
|
|
79
|
-
return components;
|
|
80
|
-
}, [components]);
|
|
81
88
|
const handleChange = useCallback((response, value, args) => {
|
|
82
89
|
dispatch(actions.handleChange(typeof response === 'string' ? response : response.name, value, args?.iteration));
|
|
83
90
|
onChange(response, value, args);
|
|
@@ -86,66 +93,54 @@ withOverview = false, missing = false, missingStrategy = emptyFn, missingShortcu
|
|
|
86
93
|
return getQuestionnaireData(state.variables, source.variables, withRefreshedCalculated, variableNames);
|
|
87
94
|
};
|
|
88
95
|
const { resetChangedData, getChangedData } = useTrackChanges(trackChanges, state.variables, (variableNames) => getData(false, variableNames));
|
|
89
|
-
const pageTag = getPageTag(pager);
|
|
90
|
-
const { isFirstPage, isLastPage } = isFirstLastPage(pager);
|
|
91
|
-
|
|
92
|
-
dispatch(actions.onInit({
|
|
93
|
-
source,
|
|
94
|
-
data,
|
|
95
|
-
initialPage,
|
|
96
|
-
lastReachedPage,
|
|
97
|
-
features,
|
|
98
|
-
preferences,
|
|
99
|
-
savingType,
|
|
100
|
-
management,
|
|
101
|
-
shortcut,
|
|
102
|
-
handleChange,
|
|
103
|
-
activeControls,
|
|
104
|
-
goToPage,
|
|
105
|
-
goNextPage,
|
|
106
|
-
goPreviousPage,
|
|
107
|
-
withOverview,
|
|
108
|
-
}));
|
|
109
|
-
}, [
|
|
110
|
-
source,
|
|
111
|
-
data,
|
|
112
|
-
initialPage,
|
|
113
|
-
features,
|
|
114
|
-
preferences,
|
|
115
|
-
savingType,
|
|
116
|
-
management,
|
|
117
|
-
shortcut,
|
|
96
|
+
const pageTag = getPageTag(state.pager);
|
|
97
|
+
const { isFirstPage, isLastPage } = isFirstLastPage(state.pager);
|
|
98
|
+
const components = fillComponents(getComponentsFromState(state), {
|
|
118
99
|
handleChange,
|
|
119
|
-
|
|
120
|
-
withOverview,
|
|
100
|
+
preferences,
|
|
121
101
|
goToPage,
|
|
102
|
+
shortcut,
|
|
122
103
|
goNextPage,
|
|
123
104
|
goPreviousPage,
|
|
124
|
-
|
|
125
|
-
|
|
105
|
+
management,
|
|
106
|
+
...state,
|
|
107
|
+
});
|
|
108
|
+
const getComponents = ({ only, except, } = {}) => {
|
|
109
|
+
if (only && except) {
|
|
110
|
+
throw new Error('"only" and "except" cannot be used together in getComponents()');
|
|
111
|
+
}
|
|
112
|
+
if (only) {
|
|
113
|
+
return components.filter((c) => only.includes(c.componentType ?? ''));
|
|
114
|
+
}
|
|
115
|
+
if (except) {
|
|
116
|
+
return components.filter((c) => !except.includes(c.componentType ?? ''));
|
|
117
|
+
}
|
|
118
|
+
return components;
|
|
119
|
+
};
|
|
126
120
|
return {
|
|
121
|
+
pageTag,
|
|
122
|
+
isFirstPage,
|
|
123
|
+
isLastPage,
|
|
124
|
+
updatedAt: state.updatedAt,
|
|
125
|
+
pager: state.pager,
|
|
126
|
+
isInLoop: state.isInLoop,
|
|
127
|
+
overview: useOverview(state, [pageTag]),
|
|
128
|
+
loopVariables: useLoopVariables(state.pager, state.pages),
|
|
129
|
+
// Methods
|
|
127
130
|
getComponents,
|
|
128
131
|
goPreviousPage,
|
|
129
132
|
goNextPage,
|
|
130
133
|
goToPage,
|
|
131
134
|
compileControls,
|
|
132
|
-
pageTag,
|
|
133
|
-
isFirstPage,
|
|
134
|
-
isLastPage,
|
|
135
|
-
pager,
|
|
136
|
-
waiting,
|
|
137
135
|
getData,
|
|
138
|
-
Provider,
|
|
139
|
-
onChange: handleChange,
|
|
140
|
-
overview: useOverview({
|
|
141
|
-
executeExpression,
|
|
142
|
-
overview,
|
|
143
|
-
pager,
|
|
144
|
-
}, [pageTag]),
|
|
145
|
-
loopVariables: useLoopVariables(pager, state.pages),
|
|
146
136
|
getChangedData,
|
|
147
137
|
resetChangedData,
|
|
148
|
-
hasPageResponse: usePageHasResponse(components, executeExpression),
|
|
138
|
+
hasPageResponse: usePageHasResponse(components, state.executeExpression),
|
|
139
|
+
// Components
|
|
140
|
+
Provider,
|
|
141
|
+
testing: {
|
|
142
|
+
handleChange,
|
|
143
|
+
},
|
|
149
144
|
};
|
|
150
145
|
}
|
|
151
146
|
export default useLunatic;
|