@inseefr/lunatic 3.7.7-rc.0 → 3.8.0-rc.0
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/components/Suggester/Suggester.spec.d.ts +1 -0
- package/components/Suggester/Suggester.spec.js +58 -0
- package/components/Suggester/Suggester.spec.js.map +1 -0
- package/esm/components/Suggester/Suggester.spec.d.ts +1 -0
- package/esm/components/Suggester/Suggester.spec.js +56 -0
- package/esm/components/Suggester/Suggester.spec.js.map +1 -0
- package/esm/type.source.d.ts +9 -0
- package/esm/use-lunatic/commons/compile-controls.js +2 -16
- package/esm/use-lunatic/commons/compile-controls.js.map +1 -1
- package/esm/use-lunatic/commons/component.d.ts +33 -0
- package/esm/use-lunatic/commons/component.js +37 -0
- package/esm/use-lunatic/commons/component.js.map +1 -1
- package/esm/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js.map +1 -1
- package/esm/use-lunatic/commons/variables/global-variables.d.ts +5 -0
- package/esm/use-lunatic/commons/variables/global-variables.js +7 -0
- package/esm/use-lunatic/commons/variables/global-variables.js.map +1 -0
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.d.ts +21 -9
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.js +67 -49
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.js.map +1 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js +137 -6
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
- package/esm/use-lunatic/commons/variables/models.d.ts +1 -0
- package/esm/use-lunatic/commons/variables/models.js +2 -0
- package/esm/use-lunatic/commons/variables/models.js.map +1 -0
- package/esm/use-lunatic/commons/variables/pairwise-variables.d.ts +29 -0
- package/esm/use-lunatic/commons/variables/pairwise-variables.js +196 -0
- package/esm/use-lunatic/commons/variables/pairwise-variables.js.map +1 -0
- package/esm/use-lunatic/props/getComponentTypeProps.d.ts +1 -1
- package/esm/use-lunatic/reducer/reducerInitializer.js +5 -1
- package/esm/use-lunatic/reducer/reducerInitializer.js.map +1 -1
- package/package.json +30 -1
- package/src/components/Suggester/Suggester.spec.tsx +62 -0
- package/src/stories/pairwise/pairwise.stories.tsx +7 -0
- package/src/stories/pairwise/sourceGlobalVariables.json +337 -0
- package/src/type.source.ts +9 -0
- package/src/use-lunatic/commons/compile-controls.ts +10 -42
- package/src/use-lunatic/commons/component.ts +79 -0
- package/src/use-lunatic/commons/variables/behaviours/cleaning-behaviour.ts +2 -4
- package/src/use-lunatic/commons/variables/global-variables.ts +9 -0
- package/src/use-lunatic/commons/variables/lunatic-variables-store.spec.ts +149 -6
- package/src/use-lunatic/commons/variables/lunatic-variables-store.ts +113 -50
- package/src/use-lunatic/commons/variables/models.ts +1 -0
- package/src/use-lunatic/commons/variables/pairwise-variables.ts +251 -0
- package/src/use-lunatic/reducer/reducerInitializer.tsx +5 -7
- package/tsconfig.build.tsbuildinfo +1 -1
- package/type.source.d.ts +9 -0
- package/use-lunatic/commons/compile-controls.js +4 -18
- package/use-lunatic/commons/compile-controls.js.map +1 -1
- package/use-lunatic/commons/component.d.ts +33 -0
- package/use-lunatic/commons/component.js +42 -0
- package/use-lunatic/commons/component.js.map +1 -1
- package/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js.map +1 -1
- package/use-lunatic/commons/variables/global-variables.d.ts +5 -0
- package/use-lunatic/commons/variables/global-variables.js +11 -0
- package/use-lunatic/commons/variables/global-variables.js.map +1 -0
- package/use-lunatic/commons/variables/lunatic-variables-store.d.ts +21 -9
- package/use-lunatic/commons/variables/lunatic-variables-store.js +72 -50
- package/use-lunatic/commons/variables/lunatic-variables-store.js.map +1 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.spec.js +137 -6
- package/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
- package/use-lunatic/commons/variables/models.d.ts +1 -0
- package/use-lunatic/commons/variables/models.js +3 -0
- package/use-lunatic/commons/variables/models.js.map +1 -0
- package/use-lunatic/commons/variables/pairwise-variables.d.ts +29 -0
- package/use-lunatic/commons/variables/pairwise-variables.js +199 -0
- package/use-lunatic/commons/variables/pairwise-variables.js.map +1 -0
- package/use-lunatic/props/getComponentTypeProps.d.ts +1 -1
- package/use-lunatic/reducer/reducerInitializer.js +5 -1
- package/use-lunatic/reducer/reducerInitializer.js.map +1 -1
package/type.source.d.ts
CHANGED
|
@@ -185,6 +185,15 @@ export type ComponentPairWiseLinksDefinition = ComponentDefinitionBase & {
|
|
|
185
185
|
[k: string]: string | null;
|
|
186
186
|
};
|
|
187
187
|
};
|
|
188
|
+
sourceVariables?: {
|
|
189
|
+
/** Name of the variable containing the name of the respondent */
|
|
190
|
+
name?: string;
|
|
191
|
+
/**
|
|
192
|
+
* Name of the variable containing the gender of the respondent
|
|
193
|
+
* (value of variable -> 1:male, 2: female)
|
|
194
|
+
*/
|
|
195
|
+
gender?: string;
|
|
196
|
+
};
|
|
188
197
|
components: ComponentDefinition[];
|
|
189
198
|
};
|
|
190
199
|
export type ComponentSummaryDefinition = ComponentDefinitionBase & {
|
|
@@ -5,21 +5,7 @@ const fill_component_expressions_1 = require("./fill-components/fill-component-e
|
|
|
5
5
|
const check_roundabout_control_1 = require("../reducer/controls/check-roundabout-control");
|
|
6
6
|
const check_base_control_1 = require("../reducer/controls/check-base-control");
|
|
7
7
|
const get_components_from_state_1 = require("./get-components-from-state");
|
|
8
|
-
|
|
9
|
-
* Check if the component is a Loop or a RosterForLoop
|
|
10
|
-
*/
|
|
11
|
-
const isLoopComponent = (component) => {
|
|
12
|
-
return ['Loop', 'RosterForLoop'].includes(component.componentType);
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Check if the component is a Roundabout
|
|
16
|
-
*/
|
|
17
|
-
const isRoundaboutComponent = (component) => {
|
|
18
|
-
return component.componentType === 'Roundabout';
|
|
19
|
-
};
|
|
20
|
-
const isQuestionComponent = (component) => {
|
|
21
|
-
return 'Question' === component.componentType;
|
|
22
|
-
};
|
|
8
|
+
const component_1 = require("./component");
|
|
23
9
|
/**
|
|
24
10
|
* Check if components of the current page have errors, and return a map of
|
|
25
11
|
* errors (indexed by component ID).
|
|
@@ -35,13 +21,13 @@ function checkComponents(state, components, currentErrors) {
|
|
|
35
21
|
}
|
|
36
22
|
}
|
|
37
23
|
// For Loop and RosterForLoop, inspect iterations for row controls
|
|
38
|
-
if (isRoundaboutComponent(component))
|
|
24
|
+
if ((0, component_1.isRoundaboutComponent)(component))
|
|
39
25
|
errors = checkRoundabout(state, component, errors);
|
|
40
26
|
// For Loop and RosterForLoop, inspect children
|
|
41
|
-
if (isLoopComponent(component))
|
|
27
|
+
if ((0, component_1.isLoopComponent)(component))
|
|
42
28
|
errors = checkLoop(state, component, errors);
|
|
43
29
|
// For Question, loop over children
|
|
44
|
-
if (isQuestionComponent(component))
|
|
30
|
+
if ((0, component_1.isQuestionComponent)(component))
|
|
45
31
|
errors = checkComponents(state, component.components, errors);
|
|
46
32
|
}
|
|
47
33
|
return errors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-controls.js","sourceRoot":"","sources":["../../src/use-lunatic/commons/compile-controls.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"compile-controls.js","sourceRoot":"","sources":["../../src/use-lunatic/commons/compile-controls.ts"],"names":[],"mappings":";;AA0PA,0CAgBC;AArQD,6FAAwF;AACxF,2FAAsF;AACtF,+EAA0E;AAC1E,2EAAqE;AACrE,2CAQqB;AAOrB;;;GAGG;AACH,SAAS,eAAe,CACvB,KAAuB,EACvB,UAA0D,EAC1D,aAA8C;IAE9C,IAAI,MAAM,GAAG,aAAa,IAAK,EAAqC,CAAC;IAErE,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,0CAA0C;QAC1C,IAAI,UAAU,IAAI,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YAClE,MAAM,eAAe,GAAG,aAAa,CACpC,SAAS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SAAS,gBAAgB,CAAC,MAAuC;IAChE,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACd,CAAC;IACD,mDAAmD;IACnD,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;SACzC,IAAI,EAAE;SACN,IAAI,CACJ,CAAC,KAAK,EAAE,EAAE,CACT,KAAK,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC;QACrC,KAAK,CAAC,aAAa,KAAK,QAAQ,CACjC,CAAC;IACH,OAAO,aAAa,KAAK,SAAS,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAuB;IACtD,MAAM,UAAU,GAAG,IAAA,kDAAsB,EAAC,KAAK,CAAC,CAAC;IACjD,MAAM,iBAAiB,GAAG,UAAU;SAClC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAA,qDAAwB,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;SAC9D,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE;QACrB,IAAI,iBAAiB,IAAI,SAAS,EAAE,CAAC;YACpC,OAAO,SAAS,CAAC,eAAe,IAAI,IAAI,CAAC;QAC1C,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAC;IACJ,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACzD,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1E,OAAO;QACN,aAAa;QACb,UAAU,EAAE,gBAAgB,CAAC,aAAa,CAAC;KAC3C,CAAC;AACH,CAAC"}
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { LunaticComponentDefinition } from '../type';
|
|
3
|
+
import { type DeepTranslateExpression } from './fill-components/fill-component-expressions';
|
|
4
|
+
export type ComponentDefinition = LunaticComponentDefinition;
|
|
5
|
+
export type InterpretedComponent = DeepTranslateExpression<LunaticComponentDefinition>;
|
|
6
|
+
export type InterpretedLoopComponent = DeepTranslateExpression<ComponentDefinition & {
|
|
7
|
+
componentType: 'Loop' | 'RosterForLoop';
|
|
8
|
+
}>;
|
|
9
|
+
export type InterpretedRoundaboutComponent = DeepTranslateExpression<ComponentDefinition & {
|
|
10
|
+
componentType: 'Roundabout';
|
|
11
|
+
}>;
|
|
12
|
+
export type InterpretedQuestionComponent = DeepTranslateExpression<ComponentDefinition & {
|
|
13
|
+
componentType: 'Question';
|
|
14
|
+
}>;
|
|
15
|
+
export type InterpretedPairwiseLinksComponent = DeepTranslateExpression<ComponentDefinition & {
|
|
16
|
+
componentType: 'PairwiseLinks';
|
|
17
|
+
}>;
|
|
18
|
+
/** Whether the component has a response attribute. */
|
|
3
19
|
export declare function hasResponse(component: unknown): component is {
|
|
4
20
|
response: {
|
|
5
21
|
name: string;
|
|
6
22
|
};
|
|
7
23
|
};
|
|
24
|
+
/** Whether the component has a responses attribute. */
|
|
8
25
|
export declare function hasResponses(component: unknown): component is {
|
|
9
26
|
responses?: Array<{
|
|
10
27
|
label: ReactNode;
|
|
@@ -14,9 +31,25 @@ export declare function hasResponses(component: unknown): component is {
|
|
|
14
31
|
};
|
|
15
32
|
}>;
|
|
16
33
|
};
|
|
34
|
+
/** Whether the component has a body attribute. */
|
|
17
35
|
export declare function hasBody(component: unknown): component is {
|
|
18
36
|
body: LunaticComponentDefinition<'Table'>['body'];
|
|
19
37
|
};
|
|
38
|
+
/** Whether the component has a componentType attribute. */
|
|
20
39
|
export declare function hasComponentType(component: unknown): component is {
|
|
21
40
|
componentType: string;
|
|
22
41
|
};
|
|
42
|
+
/** Whether the component is a Loop or a RosterForLoop. */
|
|
43
|
+
export declare function isLoopComponent(component: ComponentDefinition | InterpretedComponent): component is InterpretedLoopComponent;
|
|
44
|
+
/** Whether the component is a Roundabout. */
|
|
45
|
+
export declare function isRoundaboutComponent(component: ComponentDefinition | InterpretedComponent): component is InterpretedRoundaboutComponent;
|
|
46
|
+
/** Whether the component is a Question. */
|
|
47
|
+
export declare function isQuestionComponent(component: ComponentDefinition | InterpretedComponent): component is InterpretedQuestionComponent;
|
|
48
|
+
/** Whether the component is a PairwiseLinks. */
|
|
49
|
+
export declare function isPairwiseLinksComponent(component: ComponentDefinition | InterpretedComponent): component is InterpretedPairwiseLinksComponent;
|
|
50
|
+
/**
|
|
51
|
+
* Get the pairwise component if it exists.
|
|
52
|
+
*
|
|
53
|
+
* There should only be one so we return the first one we find.
|
|
54
|
+
*/
|
|
55
|
+
export declare function getPairwiseComponent(components: ComponentDefinition[]): InterpretedPairwiseLinksComponent | undefined;
|
|
@@ -4,25 +4,67 @@ exports.hasResponse = hasResponse;
|
|
|
4
4
|
exports.hasResponses = hasResponses;
|
|
5
5
|
exports.hasBody = hasBody;
|
|
6
6
|
exports.hasComponentType = hasComponentType;
|
|
7
|
+
exports.isLoopComponent = isLoopComponent;
|
|
8
|
+
exports.isRoundaboutComponent = isRoundaboutComponent;
|
|
9
|
+
exports.isQuestionComponent = isQuestionComponent;
|
|
10
|
+
exports.isPairwiseLinksComponent = isPairwiseLinksComponent;
|
|
11
|
+
exports.getPairwiseComponent = getPairwiseComponent;
|
|
12
|
+
/** Whether the component has a response attribute. */
|
|
7
13
|
function hasResponse(component) {
|
|
8
14
|
return (!!component &&
|
|
9
15
|
typeof component === 'object' &&
|
|
10
16
|
'response' in component &&
|
|
11
17
|
'name' in component.response);
|
|
12
18
|
}
|
|
19
|
+
/** Whether the component has a responses attribute. */
|
|
13
20
|
function hasResponses(component) {
|
|
14
21
|
return (!!component && typeof component === 'object' && 'responses' in component);
|
|
15
22
|
}
|
|
23
|
+
/** Whether the component has a body attribute. */
|
|
16
24
|
function hasBody(component) {
|
|
17
25
|
return (!!component &&
|
|
18
26
|
typeof component === 'object' &&
|
|
19
27
|
'body' in component &&
|
|
20
28
|
Array.isArray(component.body));
|
|
21
29
|
}
|
|
30
|
+
/** Whether the component has a componentType attribute. */
|
|
22
31
|
function hasComponentType(component) {
|
|
23
32
|
return (!!component &&
|
|
24
33
|
typeof component === 'object' &&
|
|
25
34
|
'componentType' in component &&
|
|
26
35
|
typeof component.componentType === 'string');
|
|
27
36
|
}
|
|
37
|
+
/** Whether the component is a Loop or a RosterForLoop. */
|
|
38
|
+
function isLoopComponent(component) {
|
|
39
|
+
return ['Loop', 'RosterForLoop'].includes(component.componentType);
|
|
40
|
+
}
|
|
41
|
+
/** Whether the component is a Roundabout. */
|
|
42
|
+
function isRoundaboutComponent(component) {
|
|
43
|
+
return component.componentType === 'Roundabout';
|
|
44
|
+
}
|
|
45
|
+
/** Whether the component is a Question. */
|
|
46
|
+
function isQuestionComponent(component) {
|
|
47
|
+
return component.componentType === 'Question';
|
|
48
|
+
}
|
|
49
|
+
/** Whether the component is a PairwiseLinks. */
|
|
50
|
+
function isPairwiseLinksComponent(component) {
|
|
51
|
+
return component.componentType === 'PairwiseLinks';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the pairwise component if it exists.
|
|
55
|
+
*
|
|
56
|
+
* There should only be one so we return the first one we find.
|
|
57
|
+
*/
|
|
58
|
+
function getPairwiseComponent(components) {
|
|
59
|
+
for (const component of components) {
|
|
60
|
+
if (isPairwiseLinksComponent(component))
|
|
61
|
+
return component;
|
|
62
|
+
if (isQuestionComponent(component)) {
|
|
63
|
+
const childComponent = getPairwiseComponent(component.components);
|
|
64
|
+
if (childComponent)
|
|
65
|
+
return childComponent;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
28
70
|
//# sourceMappingURL=component.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/use-lunatic/commons/component.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"component.js","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C3C,SAAgB,mBAAmB,CAClC,SAAqD;IAErD,OAAO,SAAS,CAAC,aAAa,KAAK,UAAU,CAAC;AAC/C,CAAC;AAED,gDAAgD;AAChD,SAAgB,wBAAwB,CACvC,SAAqD;IAErD,OAAO,SAAS,CAAC,aAAa,KAAK,eAAe,CAAC;AACpD,CAAC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CACnC,UAAiC;IAEjC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,IAAI,wBAAwB,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;QAC1D,IAAI,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC;YACpC,MAAM,cAAc,GAAG,oBAAoB,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;YAClE,IAAI,cAAc;gBAAE,OAAO,cAAc,CAAC;QAC3C,CAAC;IACF,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cleaning-behaviour.js","sourceRoot":"","sources":["../../../../src/use-lunatic/commons/variables/behaviours/cleaning-behaviour.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"cleaning-behaviour.js","sourceRoot":"","sources":["../../../../src/use-lunatic/commons/variables/behaviours/cleaning-behaviour.ts"],"names":[],"mappings":";;AAeA,8CAwEC;AArFD,mDAA4D;AAC5D,iDAAkD;AAGlD;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAChC,KAA4B,EAC5B,QAAmC,EACnC,eAAwC,EAAE;IAE1C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,OAAO;IACR,CAAC;IAED,wDAAwD;IACxD,KAAK,MAAM,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC/B,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACvC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,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C,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACd,CAAC;IACD,MAAM,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAE9C,8CAA8C;IAC9C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC;IACd,CAAC;IACD,MAAM,aAAa,GAAG,IAAA,aAAK,EAAC,aAAa,CAAC,CAAC;IAC3C,IAAI,aAAa,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACd,CAAC;IAED,0DAA0D;IAC1D,KAAK,CAAC,GAAG,CACR,YAAY,EACZ,aAAa,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;QAC9B,kFAAkF;QAClF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC;QACd,CAAC;QACD,yDAAyD;QACzD,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,uEAAuE;QACvE,OAAO,IAAA,kBAAU,EAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC,CAAC,CACF,CAAC;IACF,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IterationLevel } from './models';
|
|
2
|
+
/** Special variable that will take the current iteration value. */
|
|
3
|
+
export declare const GLOBAL_ITERATION_INDEX = "GLOBAL_ITERATION_INDEX";
|
|
4
|
+
/** Manually compute the global iteration index from current iteration level. */
|
|
5
|
+
export declare function computeGlobalIterationIndexValue(iteration: IterationLevel): (string | number)[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GLOBAL_ITERATION_INDEX = void 0;
|
|
4
|
+
exports.computeGlobalIterationIndexValue = computeGlobalIterationIndexValue;
|
|
5
|
+
/** Special variable that will take the current iteration value. */
|
|
6
|
+
exports.GLOBAL_ITERATION_INDEX = 'GLOBAL_ITERATION_INDEX';
|
|
7
|
+
/** Manually compute the global iteration index from current iteration level. */
|
|
8
|
+
function computeGlobalIterationIndexValue(iteration) {
|
|
9
|
+
return [exports.GLOBAL_ITERATION_INDEX, iteration[0] + 1];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=global-variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-variables.js","sourceRoot":"","sources":["../../../src/use-lunatic/commons/variables/global-variables.ts"],"names":[],"mappings":";;;AAMA,4EAEC;AAND,mEAAmE;AACtD,QAAA,sBAAsB,GAAG,wBAAwB,CAAC;AAE/D,gFAAgF;AAChF,SAAgB,gCAAgC,CAAC,SAAyB;IACzE,OAAO,CAAC,8BAAsB,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LunaticData, LunaticOptions, LunaticSource } from '../../type';
|
|
2
2
|
import type { RefObject } from 'react';
|
|
3
|
-
|
|
3
|
+
import { IterationLevel } from './models';
|
|
4
4
|
export type EventArgs = {
|
|
5
5
|
change: {
|
|
6
6
|
/** Name of the changed variable. */
|
|
@@ -35,7 +35,11 @@ export declare class LunaticVariablesStore {
|
|
|
35
35
|
autoCommit: boolean;
|
|
36
36
|
updatedAt: Timekey;
|
|
37
37
|
constructor();
|
|
38
|
-
static makeFromSource(source: LunaticSource, data: LunaticData,
|
|
38
|
+
static makeFromSource(source: LunaticSource, data: LunaticData, options?: {
|
|
39
|
+
changeHandler?: RefObject<LunaticOptions['onVariableChange']>;
|
|
40
|
+
disableCleaning?: boolean;
|
|
41
|
+
autoCommit?: boolean;
|
|
42
|
+
}): LunaticVariablesStore;
|
|
39
43
|
/**
|
|
40
44
|
* Create a new store from an object (useful for testing)
|
|
41
45
|
*/
|
|
@@ -65,6 +69,14 @@ export declare class LunaticVariablesStore {
|
|
|
65
69
|
shapeFrom?: string | string[];
|
|
66
70
|
dimension?: number;
|
|
67
71
|
}): LunaticVariable;
|
|
72
|
+
/**
|
|
73
|
+
* Register global variable
|
|
74
|
+
*/
|
|
75
|
+
setGlobal(name: string, { dependencies, globalDependencies, shapeFrom, }: {
|
|
76
|
+
dependencies?: string[];
|
|
77
|
+
globalDependencies?: Map<unknown, string>;
|
|
78
|
+
shapeFrom?: string | string[];
|
|
79
|
+
}): LunaticVariable;
|
|
68
80
|
/**
|
|
69
81
|
* Run a VTL expression
|
|
70
82
|
*/
|
|
@@ -84,7 +96,7 @@ export declare class LunaticVariablesStore {
|
|
|
84
96
|
get interpretCount(): number;
|
|
85
97
|
debug(): void;
|
|
86
98
|
}
|
|
87
|
-
declare class LunaticVariable {
|
|
99
|
+
export declare class LunaticVariable {
|
|
88
100
|
/** Last time the value was updated (changed). */
|
|
89
101
|
updatedAt: Map<string | undefined, number>;
|
|
90
102
|
/** Last time the store was updated (changed). */
|
|
@@ -95,8 +107,6 @@ declare class LunaticVariable {
|
|
|
95
107
|
private value;
|
|
96
108
|
/** List of direct dependencies, ex: ['FULLNAME', 'FIRSTNAME', 'LASTNAME']. */
|
|
97
109
|
private dependencies?;
|
|
98
|
-
/** List of deep dependencies, exploring the variables used in calculated variables, ex: ['FIRSTNAME', 'LASTNAME']. */
|
|
99
|
-
private baseDependencies?;
|
|
100
110
|
/** Expression for calculated variable. */
|
|
101
111
|
readonly expression?: string;
|
|
102
112
|
/** Dictionary holding all the available variables. */
|
|
@@ -105,6 +115,10 @@ declare class LunaticVariable {
|
|
|
105
115
|
private readonly iterationDepth?;
|
|
106
116
|
/** For calculated variable, shape is copied from another variable. */
|
|
107
117
|
private readonly shapeFrom?;
|
|
118
|
+
/** Whether this is a global variable with custom computation rules. */
|
|
119
|
+
private readonly isGlobal?;
|
|
120
|
+
/** Name of variables needed for global variables computation rules. */
|
|
121
|
+
private readonly globalDependencies?;
|
|
108
122
|
/** Keep a record of variable name (optional, used for debug). */
|
|
109
123
|
readonly name?: string;
|
|
110
124
|
/** Count the number of calculation. */
|
|
@@ -120,6 +134,8 @@ declare class LunaticVariable {
|
|
|
120
134
|
name?: string;
|
|
121
135
|
dimension?: number;
|
|
122
136
|
storeUpdatedAt: Timekey;
|
|
137
|
+
isGlobal?: boolean;
|
|
138
|
+
globalDependencies?: Map<unknown, string>;
|
|
123
139
|
});
|
|
124
140
|
getValue(iteration?: IterationLevel): unknown;
|
|
125
141
|
/**
|
|
@@ -132,10 +148,6 @@ declare class LunaticVariable {
|
|
|
132
148
|
private updateTimestamps;
|
|
133
149
|
private setValueForArray;
|
|
134
150
|
private getSavedValue;
|
|
135
|
-
/**
|
|
136
|
-
* Get a list of transitive dependencies (leaf of the dependency tree)
|
|
137
|
-
*/
|
|
138
|
-
private getBaseDependencies;
|
|
139
151
|
private getDependencies;
|
|
140
152
|
private getDependenciesValues;
|
|
141
153
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LunaticVariablesStore = void 0;
|
|
3
|
+
exports.LunaticVariable = exports.LunaticVariablesStore = void 0;
|
|
4
4
|
const vtl_1 = require("../../../utils/vtl");
|
|
5
5
|
const env_1 = require("../../../utils/env");
|
|
6
6
|
const variables_1 = require("../../../utils/variables");
|
|
@@ -10,10 +10,10 @@ const missing_behaviour_1 = require("./behaviours/missing-behaviour");
|
|
|
10
10
|
const array_1 = require("../../../utils/array");
|
|
11
11
|
const number_1 = require("../../../utils/number");
|
|
12
12
|
const errors_1 = require("./errors");
|
|
13
|
+
const pairwise_variables_1 = require("./pairwise-variables");
|
|
14
|
+
const global_variables_1 = require("./global-variables");
|
|
13
15
|
/** Interpret counter. Used for testing purpose. */
|
|
14
16
|
let interpretCount = 0;
|
|
15
|
-
/** Special variable that will take the current iteration value. */
|
|
16
|
-
const iterationVariableName = 'GLOBAL_ITERATION_INDEX';
|
|
17
17
|
/**
|
|
18
18
|
* Represent a point in time (more precise than Date)
|
|
19
19
|
*/
|
|
@@ -35,11 +35,8 @@ class LunaticVariablesStore {
|
|
|
35
35
|
constructor() {
|
|
36
36
|
interpretCount = 0;
|
|
37
37
|
}
|
|
38
|
-
static makeFromSource(source, data,
|
|
39
|
-
|
|
40
|
-
disableCleaning,
|
|
41
|
-
// Do not delay resizing / cleaning
|
|
42
|
-
autoCommit) {
|
|
38
|
+
static makeFromSource(source, data, options = {}) {
|
|
39
|
+
const { changeHandler, disableCleaning, autoCommit } = options;
|
|
43
40
|
const store = new LunaticVariablesStore();
|
|
44
41
|
if (typeof window !== 'undefined') {
|
|
45
42
|
window.lunaticStore = store; // Allow access to the store from the console
|
|
@@ -50,6 +47,12 @@ class LunaticVariablesStore {
|
|
|
50
47
|
if (autoCommit) {
|
|
51
48
|
store.autoCommit = autoCommit;
|
|
52
49
|
}
|
|
50
|
+
// Setup pairwise global variables if there is a pairwise component
|
|
51
|
+
const pairwiseVariables = (0, pairwise_variables_1.computePairwiseGlobalVariables)(source);
|
|
52
|
+
for (const pairwiseVariable of pairwiseVariables) {
|
|
53
|
+
const { name, dependencies, globalDependencies, shapeFrom } = pairwiseVariable;
|
|
54
|
+
store.setGlobal(name, { dependencies, globalDependencies, shapeFrom });
|
|
55
|
+
}
|
|
53
56
|
// Source data (picked from "variables" in the source.json)s
|
|
54
57
|
const sourceValues = {};
|
|
55
58
|
// Starting data for the form (merged with data.json or injected data)
|
|
@@ -69,6 +72,9 @@ class LunaticVariablesStore {
|
|
|
69
72
|
for (const variable of source.variables) {
|
|
70
73
|
switch (variable.variableType) {
|
|
71
74
|
case 'CALCULATED':
|
|
75
|
+
// In some cases, we have calculated variables in the source that are
|
|
76
|
+
// not used in the questionnaire (those variables are executed out of
|
|
77
|
+
// Lunatic.), so there is no need to add them to the dictionary.
|
|
72
78
|
if (variable.isIgnoredByLunatic)
|
|
73
79
|
break;
|
|
74
80
|
store.setCalculated(variable.name, variable.expression.value, {
|
|
@@ -184,6 +190,26 @@ class LunaticVariablesStore {
|
|
|
184
190
|
this.updatedAt.touch();
|
|
185
191
|
return variable;
|
|
186
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Register global variable
|
|
195
|
+
*/
|
|
196
|
+
setGlobal(name, { dependencies, globalDependencies, shapeFrom, }) {
|
|
197
|
+
if (this.dictionary.has(name)) {
|
|
198
|
+
return this.dictionary.get(name);
|
|
199
|
+
}
|
|
200
|
+
const variable = new LunaticVariable({
|
|
201
|
+
dictionary: this.dictionary,
|
|
202
|
+
shapeFrom,
|
|
203
|
+
dependencies,
|
|
204
|
+
name,
|
|
205
|
+
storeUpdatedAt: this.updatedAt,
|
|
206
|
+
isGlobal: true,
|
|
207
|
+
globalDependencies,
|
|
208
|
+
});
|
|
209
|
+
this.dictionary.set(name, variable);
|
|
210
|
+
this.updatedAt.touch();
|
|
211
|
+
return variable;
|
|
212
|
+
}
|
|
187
213
|
/**
|
|
188
214
|
* Run a VTL expression
|
|
189
215
|
*/
|
|
@@ -235,8 +261,6 @@ class LunaticVariable {
|
|
|
235
261
|
value;
|
|
236
262
|
/** List of direct dependencies, ex: ['FULLNAME', 'FIRSTNAME', 'LASTNAME']. */
|
|
237
263
|
dependencies;
|
|
238
|
-
/** List of deep dependencies, exploring the variables used in calculated variables, ex: ['FIRSTNAME', 'LASTNAME']. */
|
|
239
|
-
baseDependencies;
|
|
240
264
|
/** Expression for calculated variable. */
|
|
241
265
|
expression;
|
|
242
266
|
/** Dictionary holding all the available variables. */
|
|
@@ -245,6 +269,10 @@ class LunaticVariable {
|
|
|
245
269
|
iterationDepth;
|
|
246
270
|
/** For calculated variable, shape is copied from another variable. */
|
|
247
271
|
shapeFrom;
|
|
272
|
+
/** Whether this is a global variable with custom computation rules. */
|
|
273
|
+
isGlobal;
|
|
274
|
+
/** Name of variables needed for global variables computation rules. */
|
|
275
|
+
globalDependencies;
|
|
248
276
|
/** Keep a record of variable name (optional, used for debug). */
|
|
249
277
|
name;
|
|
250
278
|
/** Count the number of calculation. */
|
|
@@ -253,7 +281,13 @@ class LunaticVariable {
|
|
|
253
281
|
dimension;
|
|
254
282
|
constructor(args) {
|
|
255
283
|
if (args.expression && !args.dictionary) {
|
|
256
|
-
throw new Error(
|
|
284
|
+
throw new Error('A calculated variable needs a dictionary to retrieve his deps');
|
|
285
|
+
}
|
|
286
|
+
if (args.isGlobal && args.dependencies && !args.dictionary) {
|
|
287
|
+
throw new Error('A global variable with dependencies needs a dictionary to retrieve its deps');
|
|
288
|
+
}
|
|
289
|
+
if (args.isGlobal && !args.name) {
|
|
290
|
+
throw new Error('A global variable needs a name to fetch its logic');
|
|
257
291
|
}
|
|
258
292
|
this.expression = args.expression;
|
|
259
293
|
this.dictionary = args.dictionary;
|
|
@@ -264,10 +298,12 @@ class LunaticVariable {
|
|
|
264
298
|
this.name = args.name ?? args.expression;
|
|
265
299
|
this.dimension = args.dimension;
|
|
266
300
|
this.storeUpdatedAt = args.storeUpdatedAt;
|
|
301
|
+
this.isGlobal = args.isGlobal || false;
|
|
302
|
+
this.globalDependencies = args.globalDependencies || undefined;
|
|
267
303
|
}
|
|
268
304
|
getValue(iteration) {
|
|
269
|
-
// The variable is not calculated
|
|
270
|
-
if (!this.expression) {
|
|
305
|
+
// The variable is not calculated or a global variable
|
|
306
|
+
if (!this.expression && !this.isGlobal) {
|
|
271
307
|
return this.getSavedValue(iteration);
|
|
272
308
|
}
|
|
273
309
|
const shapeFromValue = this.shapeFrom
|
|
@@ -315,16 +351,24 @@ class LunaticVariable {
|
|
|
315
351
|
shapeDimension < iteration.length) {
|
|
316
352
|
iteration = iteration.slice(0, shapeDimension);
|
|
317
353
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
354
|
+
if (this.isGlobal) {
|
|
355
|
+
// compute global variable thanks to specific rule
|
|
356
|
+
const value = (0, pairwise_variables_1.computePairwiseGlobalVariableValue)(this.name, iteration, this.globalDependencies, this.dictionary);
|
|
357
|
+
this.setValue(value, { iteration });
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
// compute thanks to VTL expression
|
|
361
|
+
// Uncomment this if you want to track the number of calculation
|
|
362
|
+
// this.calculatedCount++;
|
|
363
|
+
// Remember the value
|
|
364
|
+
try {
|
|
365
|
+
this.setValue((0, vtl_1.interpretVTL)(this.expression, bindings), {
|
|
366
|
+
iteration: iteration,
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
catch {
|
|
370
|
+
throw new errors_1.VTLInterpretationError(this.expression, bindings);
|
|
371
|
+
}
|
|
328
372
|
}
|
|
329
373
|
this.updateTimestamps(iteration, 'calculatedAt');
|
|
330
374
|
return this.getSavedValue(iteration);
|
|
@@ -392,31 +436,6 @@ class LunaticVariable {
|
|
|
392
436
|
}
|
|
393
437
|
return current;
|
|
394
438
|
}
|
|
395
|
-
/**
|
|
396
|
-
* Get a list of transitive dependencies (leaf of the dependency tree)
|
|
397
|
-
*/
|
|
398
|
-
getBaseDependencies() {
|
|
399
|
-
// Find the dependencies of the dependencies
|
|
400
|
-
const reducer = (acc, variableName) => {
|
|
401
|
-
if (acc.has(variableName)) {
|
|
402
|
-
return acc;
|
|
403
|
-
}
|
|
404
|
-
const deps = this.dictionary?.get(variableName)?.getDependencies();
|
|
405
|
-
if (!deps || deps.length === 0) {
|
|
406
|
-
acc.add(variableName);
|
|
407
|
-
}
|
|
408
|
-
else {
|
|
409
|
-
deps?.reduce(reducer, acc);
|
|
410
|
-
}
|
|
411
|
-
return acc;
|
|
412
|
-
};
|
|
413
|
-
if (this.baseDependencies === undefined) {
|
|
414
|
-
this.baseDependencies = [
|
|
415
|
-
...this.getDependencies().reduce(reducer, new Set()),
|
|
416
|
-
];
|
|
417
|
-
}
|
|
418
|
-
return this.baseDependencies;
|
|
419
|
-
}
|
|
420
439
|
getDependencies() {
|
|
421
440
|
// Calculate dependencies from expression on the fly if necessary
|
|
422
441
|
if (this.dependencies === undefined) {
|
|
@@ -427,8 +446,10 @@ class LunaticVariable {
|
|
|
427
446
|
getDependenciesValues(iteration) {
|
|
428
447
|
try {
|
|
429
448
|
return Object.fromEntries(this.getDependencies().map((dep) => {
|
|
430
|
-
|
|
431
|
-
|
|
449
|
+
// The variable is a global variable with no dependency that we can
|
|
450
|
+
// manually compute on the fly.
|
|
451
|
+
if (dep === global_variables_1.GLOBAL_ITERATION_INDEX && iteration) {
|
|
452
|
+
return (0, global_variables_1.computeGlobalIterationIndexValue)(iteration);
|
|
432
453
|
}
|
|
433
454
|
const dependencyIteration = (0, number_1.isNumber)(this.iterationDepth) && Array.isArray(iteration)
|
|
434
455
|
? [iteration[this.iterationDepth]]
|
|
@@ -493,6 +514,7 @@ class LunaticVariable {
|
|
|
493
514
|
0);
|
|
494
515
|
}
|
|
495
516
|
}
|
|
517
|
+
exports.LunaticVariable = LunaticVariable;
|
|
496
518
|
function arrayDimension(arr) {
|
|
497
519
|
if (!Array.isArray(arr)) {
|
|
498
520
|
return 0;
|