@inseefr/lunatic 3.6.13 → 3.6.15-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/shared/Combobox/ComboboxContent.js +0 -3
- package/components/shared/Combobox/ComboboxContent.js.map +1 -1
- package/esm/components/shared/Combobox/ComboboxContent.js +1 -4
- package/esm/components/shared/Combobox/ComboboxContent.js.map +1 -1
- package/esm/hooks/useMultiMode.d.ts +49 -0
- package/esm/hooks/useMultiMode.js +83 -0
- package/esm/hooks/useMultiMode.js.map +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/type.source.d.ts +55 -1
- package/esm/use-lunatic/reducer/reducerInitializer.d.ts +2 -2
- package/esm/use-lunatic/reducer/reducerInitializer.js +31 -24
- package/esm/use-lunatic/reducer/reducerInitializer.js.map +1 -1
- package/esm/use-lunatic/type.d.ts +2 -0
- package/esm/use-lunatic/use-lunatic.js +3 -0
- package/esm/use-lunatic/use-lunatic.js.map +1 -1
- package/esm/utils/getArticulation.d.ts +61 -0
- package/esm/utils/getArticulation.js +78 -0
- package/esm/utils/getArticulation.js.map +1 -0
- package/hooks/useMultiMode.d.ts +49 -0
- package/hooks/useMultiMode.js +84 -0
- package/hooks/useMultiMode.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/package.json +19 -1
- package/src/components/shared/Combobox/ComboboxContent.tsx +6 -5
- package/src/hooks/useMultiMode.ts +102 -0
- package/src/index.ts +1 -0
- package/src/stories/behaviour/articulation/articulation.stories.tsx +90 -0
- package/src/stories/behaviour/articulation/multimode.stories.tsx +19 -0
- package/src/stories/behaviour/articulation/roundabout.json +413 -0
- package/src/stories/utils/Orchestrator.tsx +10 -0
- package/src/stories/utils/OrchestratorSidebar.tsx +25 -1
- package/src/type.source.ts +55 -1
- package/src/use-lunatic/reducer/reducerInitializer.tsx +40 -29
- package/src/use-lunatic/type.ts +2 -0
- package/src/use-lunatic/use-lunatic.ts +4 -0
- package/src/utils/getArticulation.ts +117 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/type.source.d.ts +55 -1
- package/use-lunatic/reducer/reducerInitializer.d.ts +2 -2
- package/use-lunatic/reducer/reducerInitializer.js +31 -24
- package/use-lunatic/reducer/reducerInitializer.js.map +1 -1
- package/use-lunatic/type.d.ts +2 -0
- package/use-lunatic/use-lunatic.js +3 -0
- package/use-lunatic/use-lunatic.js.map +1 -1
- package/utils/getArticulation.d.ts +61 -0
- package/utils/getArticulation.js +78 -0
- package/utils/getArticulation.js.map +1 -0
package/type.source.d.ts
CHANGED
|
@@ -224,7 +224,7 @@ export type Variable = {
|
|
|
224
224
|
dimension?: number;
|
|
225
225
|
};
|
|
226
226
|
export type VariableValue = VariableScalarValue | unknown[];
|
|
227
|
-
export type VariableScalarValue = string | number | null;
|
|
227
|
+
export type VariableScalarValue = string | number | null | boolean;
|
|
228
228
|
/**
|
|
229
229
|
* Representation of a Lunatic questionnaire.
|
|
230
230
|
*/
|
|
@@ -278,6 +278,38 @@ export type LunaticSource = {
|
|
|
278
278
|
};
|
|
279
279
|
};
|
|
280
280
|
maxPage?: string;
|
|
281
|
+
articulation?: {
|
|
282
|
+
/**
|
|
283
|
+
* id du composant roundabout
|
|
284
|
+
*/
|
|
285
|
+
source: string;
|
|
286
|
+
/**
|
|
287
|
+
* Ligne du tableau d'articulation
|
|
288
|
+
*/
|
|
289
|
+
items: {
|
|
290
|
+
/**
|
|
291
|
+
* Libellé du champs
|
|
292
|
+
*/
|
|
293
|
+
label: string;
|
|
294
|
+
/**
|
|
295
|
+
* Expression VTL
|
|
296
|
+
*/
|
|
297
|
+
value: string;
|
|
298
|
+
}[];
|
|
299
|
+
};
|
|
300
|
+
multimode?: {
|
|
301
|
+
questionnaire: {
|
|
302
|
+
rules: {
|
|
303
|
+
[k: string]: VTLExpression1;
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
leaf: {
|
|
307
|
+
source: string;
|
|
308
|
+
rules: {
|
|
309
|
+
[k: string]: VTLExpression2;
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
};
|
|
281
313
|
};
|
|
282
314
|
export type VTLExpression = {
|
|
283
315
|
/**
|
|
@@ -406,3 +438,25 @@ export type SuggesterDefinition = {
|
|
|
406
438
|
*/
|
|
407
439
|
stopWords?: string[];
|
|
408
440
|
};
|
|
441
|
+
export type VTLExpression1 = {
|
|
442
|
+
/**
|
|
443
|
+
* Valid VTL Expression
|
|
444
|
+
*/
|
|
445
|
+
value: string;
|
|
446
|
+
/**
|
|
447
|
+
* Variables used in the expression
|
|
448
|
+
*/
|
|
449
|
+
bindingDependencies?: string[];
|
|
450
|
+
type: 'VTL' | 'VTL|MD' | 'TXT';
|
|
451
|
+
};
|
|
452
|
+
export type VTLExpression2 = {
|
|
453
|
+
/**
|
|
454
|
+
* Valid VTL Expression
|
|
455
|
+
*/
|
|
456
|
+
value: string;
|
|
457
|
+
/**
|
|
458
|
+
* Variables used in the expression
|
|
459
|
+
*/
|
|
460
|
+
bindingDependencies?: string[];
|
|
461
|
+
type: 'VTL' | 'VTL|MD' | 'TXT';
|
|
462
|
+
};
|
|
@@ -11,6 +11,6 @@ export declare function reducerInitializer({ source, data, features, initialPage
|
|
|
11
11
|
disableFilters?: LunaticOptions['disableFilters'];
|
|
12
12
|
disableFiltersDescription?: LunaticOptions['disableFiltersDescription'];
|
|
13
13
|
getReferentiel?: LunaticOptions['getReferentiel'];
|
|
14
|
-
onVariableChange
|
|
15
|
-
logger
|
|
14
|
+
onVariableChange?: RefObject<LunaticOptions['onVariableChange']>;
|
|
15
|
+
logger?: LunaticLogger;
|
|
16
16
|
}): LunaticReducerState;
|
|
@@ -32,7 +32,8 @@ const baseState = {
|
|
|
32
32
|
executeExpression: () => null,
|
|
33
33
|
options: { disableFilters: false, disableFiltersDescription: true },
|
|
34
34
|
};
|
|
35
|
-
|
|
35
|
+
const onChange = { current: () => { } };
|
|
36
|
+
function reducerInitializer({ source, data, features = ['VTL'], initialPage = '1', lastReachedPage = undefined, withOverview = false, disableFilters = false, disableFiltersDescription = true, getReferentiel, onVariableChange = onChange, logger = console.error, }) {
|
|
36
37
|
const variables = lunatic_variables_store_1.LunaticVariablesStore.makeFromSource(source, data, onVariableChange, disableFilters, source.pagination !== 'question');
|
|
37
38
|
const pages = (0, commons_1.checkLoops)((0, commons_1.createMapPages)(source));
|
|
38
39
|
if (!source || !data) {
|
|
@@ -70,11 +71,13 @@ function reducerInitializer({ source, data, features = ['VTL'], initialPage = '1
|
|
|
70
71
|
return result;
|
|
71
72
|
}
|
|
72
73
|
catch (e) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
if (logger) {
|
|
75
|
+
// If there is an error interpreting a variable, return the raw expression
|
|
76
|
+
logger({
|
|
77
|
+
type: 'ERROR',
|
|
78
|
+
error: e,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
78
81
|
return expressionString;
|
|
79
82
|
}
|
|
80
83
|
};
|
|
@@ -85,9 +88,9 @@ function reducerInitializer({ source, data, features = ['VTL'], initialPage = '1
|
|
|
85
88
|
const pager = {
|
|
86
89
|
page: initialPager?.page ?? 1,
|
|
87
90
|
maxPage: source.maxPage ? parseInt(source.maxPage, 10) : 1,
|
|
88
|
-
subPage:
|
|
91
|
+
subPage: initialPager?.subPage,
|
|
89
92
|
nbSubPages: undefined,
|
|
90
|
-
iteration:
|
|
93
|
+
iteration: initialPager?.iteration,
|
|
91
94
|
nbIterations: undefined,
|
|
92
95
|
lastReachedPage: lastReachedPage ?? initialPage,
|
|
93
96
|
};
|
|
@@ -96,7 +99,7 @@ function reducerInitializer({ source, data, features = ['VTL'], initialPage = '1
|
|
|
96
99
|
pager,
|
|
97
100
|
previousPager: pager,
|
|
98
101
|
pages,
|
|
99
|
-
isInLoop:
|
|
102
|
+
isInLoop: pager.subPage !== undefined,
|
|
100
103
|
updatedAt: Date.now(),
|
|
101
104
|
overview: withOverview ? (0, overviewOnInit_1.buildOverview)(source) : [],
|
|
102
105
|
updateBindings,
|
|
@@ -113,21 +116,25 @@ function fillPagerForLoop(state) {
|
|
|
113
116
|
return state;
|
|
114
117
|
}
|
|
115
118
|
const { isLoop, subPages, iterations, loopDependencies } = pages[pager.page];
|
|
116
|
-
if (
|
|
117
|
-
|
|
119
|
+
if (
|
|
120
|
+
// For loop, jump at the first page
|
|
121
|
+
isLoop ||
|
|
122
|
+
// For roundabout, jump at the desired iteration / subpage (only if defined)
|
|
123
|
+
(pager?.iteration !== undefined && subPages)) {
|
|
124
|
+
return {
|
|
125
|
+
...state,
|
|
126
|
+
isInLoop: true,
|
|
127
|
+
pager: {
|
|
128
|
+
...pager,
|
|
129
|
+
subPage: pager?.subPage ?? 1,
|
|
130
|
+
nbSubPages: (subPages ?? []).length,
|
|
131
|
+
iteration: pager?.iteration ?? 0,
|
|
132
|
+
nbIterations: (0, number_1.forceInt)(state.executeExpression(iterations, {
|
|
133
|
+
deps: loopDependencies,
|
|
134
|
+
})),
|
|
135
|
+
},
|
|
136
|
+
};
|
|
118
137
|
}
|
|
119
|
-
return
|
|
120
|
-
...state,
|
|
121
|
-
isInLoop: true,
|
|
122
|
-
pager: {
|
|
123
|
-
...pager,
|
|
124
|
-
subPage: pager?.subPage ?? 0,
|
|
125
|
-
nbSubPages: (subPages ?? []).length,
|
|
126
|
-
iteration: pager?.iteration ?? 0,
|
|
127
|
-
nbIterations: (0, number_1.forceInt)(state.executeExpression(iterations, {
|
|
128
|
-
deps: loopDependencies,
|
|
129
|
-
})),
|
|
130
|
-
},
|
|
131
|
-
};
|
|
138
|
+
return state;
|
|
132
139
|
}
|
|
133
140
|
//# sourceMappingURL=reducerInitializer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducerInitializer.js","sourceRoot":"","sources":["../../src/use-lunatic/reducer/reducerInitializer.tsx"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"reducerInitializer.js","sourceRoot":"","sources":["../../src/use-lunatic/reducer/reducerInitializer.tsx"],"names":[],"mappings":";;AA0CA,gDAsHC;;AA1JD,0FAAqF;AACrF,wCAAwD;AACxD,yCAA2E;AAC3E,qDAAgD;AAChD,qEAAkE;AAClE,kDAA0D;AAC1D,8DAA0D;AAC1D,+CAA8C;AAC9C,8EAA2E;AAI3E,MAAM,SAAS,GAAG;IACjB,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,SAAS;IACrB,SAAS,EAAE,SAAS;IACpB,gBAAgB,EAAE,SAAS;IAC3B,YAAY,EAAE,SAAS;CACvB,CAAC;AACF,MAAM,SAAS,GAAG;IACjB,SAAS,EAAE,IAAI,+CAAqB,EAAE;IACtC,KAAK,EAAE,SAAS;IAChB,aAAa,EAAE,SAAS;IACxB,KAAK,EAAE,EAAE;IACT,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;IACrB,QAAQ,EAAE,EAAE;IACZ,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;IACxB,iBAAiB,EAAE,GAAO,EAAE,CAAC,IAAS;IACtC,OAAO,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,yBAAyB,EAAE,IAAI,EAAE;CACrC,CAAC;AAEhC,MAAM,QAAQ,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;AAEvC,SAAgB,kBAAkB,CAAC,EAClC,MAAM,EACN,IAAI,EACJ,QAAQ,GAAG,CAAC,KAAK,CAAC,EAClB,WAAW,GAAG,GAAG,EACjB,eAAe,GAAG,SAAS,EAC3B,YAAY,GAAG,KAAK,EACpB,cAAc,GAAG,KAAK,EACtB,yBAAyB,GAAG,IAAI,EAChC,cAAc,EACd,gBAAgB,GAAG,QAAQ,EAC3B,MAAM,GAAG,OAAO,CAAC,KAAK,GAatB;IACA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*/
|
|
331
331
|
handleChanges: LunaticChangesHandler;
|
|
332
|
+
/** Return the multimode state **/
|
|
333
|
+
getMultiMode: () => Record<string, boolean>;
|
|
332
334
|
};
|
|
333
335
|
/** Function taking as arguments the various changes the user has made. */
|
|
334
336
|
export type LunaticChangesHandler = (args: {
|
|
@@ -25,6 +25,7 @@ const useRefSync_1 = require("../hooks/useRefSync");
|
|
|
25
25
|
const ConsoleLogger_1 = require("./logger/ConsoleLogger");
|
|
26
26
|
const useWarnDepChange_1 = require("./hooks/useWarnDepChange");
|
|
27
27
|
const useCallbackOnNextRender_1 = require("./hooks/useCallbackOnNextRender");
|
|
28
|
+
const useMultiMode_1 = require("../hooks/useMultiMode");
|
|
28
29
|
const empty = {}; // Keep the same empty object (to avoid problem with useEffect dependencies)
|
|
29
30
|
const DEFAULT_DATA = empty;
|
|
30
31
|
const DEFAULT_FEATURES = ['VTL', 'MD'];
|
|
@@ -123,6 +124,7 @@ argOptions = empty) {
|
|
|
123
124
|
return (0, get_questionnaire_data_1.getQuestionnaireData)(state.variables, source.variables, withRefreshedCalculated, variableNames);
|
|
124
125
|
};
|
|
125
126
|
const { resetChangedData, getChangedData } = (0, use_track_changes_1.useTrackChanges)(trackChanges, state.variables, (variableNames) => getData(false, variableNames));
|
|
127
|
+
const { getMultiMode } = (0, useMultiMode_1.useMultiMode)(source, state.variables);
|
|
126
128
|
const pageTag = (0, commons_1.getPageTag)(state.pager);
|
|
127
129
|
const { isFirstPage, isLastPage } = (0, commons_1.isFirstLastPage)(state.pager);
|
|
128
130
|
const components = (0, fill_components_1.fillComponents)((0, get_components_from_state_1.getComponentsFromState)(state), {
|
|
@@ -163,6 +165,7 @@ argOptions = empty) {
|
|
|
163
165
|
// Components
|
|
164
166
|
Provider,
|
|
165
167
|
handleChanges,
|
|
168
|
+
getMultiMode,
|
|
166
169
|
};
|
|
167
170
|
}
|
|
168
171
|
//# sourceMappingURL=use-lunatic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-lunatic.js","sourceRoot":"","sources":["../src/use-lunatic/use-lunatic.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"use-lunatic.js","sourceRoot":"","sources":["../src/use-lunatic/use-lunatic.ts"],"names":[],"mappings":";;;;;AAyEA,gCA+KC;AAxPD,iCAAyD;AACzD,uCAKmB;AACnB,uCAAwD;AAExD,mDAAwB;AACxB,kDAA+C;AAC/C,uDAA0D;AAS1D,iEAAmF;AACnF,mEAA8D;AAC9D,uFAAkF;AAClF,kEAA6D;AAC7D,yEAAmE;AACnE,qDAAkD;AAClD,qEAAkE;AAClE,mFAA6E;AAC7E,+EAA2E;AAC3E,+CAA4C;AAC5C,4CAA+C;AAC/C,oDAAiD;AACjD,0DAAuD;AACvD,+DAA4D;AAC5D,6EAA0E;AAC1E,wDAAqD;AAErD,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,4EAA4E;AAC9F,MAAM,YAAY,GAAG,KAAoB,CAAC;AAC1C,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,IAAI,CAAkB,CAAC;AACxD,MAAM,mBAAmB,GAAG,CAAC,qBAAS,CAAkB,CAAC;AACzD,MAAM,gBAAgB,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEvD,MAAM,iBAAiB,GAAG,cAAC,CAAC,EAAE,CAAC;AAC/B,MAAM,eAAe,GAAG,cAAC,CAAC,EAAE,CAAC;AAE7B,MAAM,cAAc,GAAG;IACtB,cAAc,EAAE,KAAK;IACrB,yBAAyB,EAAE,IAAI;IAC/B,QAAQ,EAAE,gBAAgB;IAC1B,WAAW,EAAE,mBAAmB;IAChC,UAAU,EAAE,qBAAS;IACrB,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;IAClB,gBAAgB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC1B,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,KAAK;IACf,WAAW,EAAE,G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,eAAe;QACf,OAAO;QACP,cAAc;QACd,gBAAgB;QAChB,eAAe,EAAE,IAAA,0CAAkB,EAAC,UAAU,EAAE,KAAK,CAAC,iBAAiB,CAAC;QACxE,aAAa;QACb,QAAQ;QACR,aAAa;QACb,YAAY;KACW,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ComponentDefinition, ComponentRoundaboutDefinition, LunaticSource } from '../type.source';
|
|
2
|
+
import type { LunaticData, PageTag } from '../use-lunatic/type';
|
|
3
|
+
import { type ReactNode } from 'react';
|
|
4
|
+
type ArticulationItem = {
|
|
5
|
+
label: string;
|
|
6
|
+
value: string;
|
|
7
|
+
};
|
|
8
|
+
type Articulation = {
|
|
9
|
+
source: string;
|
|
10
|
+
items: ArticulationItem[];
|
|
11
|
+
};
|
|
12
|
+
type Item = {
|
|
13
|
+
cells: {
|
|
14
|
+
label: string;
|
|
15
|
+
value: ReactNode;
|
|
16
|
+
}[];
|
|
17
|
+
progress: number;
|
|
18
|
+
page: PageTag;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Retrieve the articulation state
|
|
22
|
+
*
|
|
23
|
+
* ## Why this hook
|
|
24
|
+
*
|
|
25
|
+
* The goal of this hook is to provide insights about a roundabout using extra information inserted in the JSON source
|
|
26
|
+
* provided to Lunatic.
|
|
27
|
+
*
|
|
28
|
+
* For instance
|
|
29
|
+
*
|
|
30
|
+
* ```
|
|
31
|
+
* "articulation": {
|
|
32
|
+
* "source": "roundabout",
|
|
33
|
+
* "items": [
|
|
34
|
+
* {
|
|
35
|
+
* "label": "Prénom",
|
|
36
|
+
* "value": "PRENOMS"
|
|
37
|
+
* },
|
|
38
|
+
* {
|
|
39
|
+
* "label": "Sexe",
|
|
40
|
+
* "value": "if SEXE = \"H\" then \"Homme\" else \"Femme\""
|
|
41
|
+
* },
|
|
42
|
+
* {
|
|
43
|
+
* "label": "Age",
|
|
44
|
+
* "value": "cast(AGE, string) || \" ans\""
|
|
45
|
+
* }
|
|
46
|
+
* ]
|
|
47
|
+
* },
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* - source is the ID of the roundabout component
|
|
51
|
+
* - items define the field to extract from the roundabout data
|
|
52
|
+
*/
|
|
53
|
+
export declare function getArticulation(source: LunaticSource & {
|
|
54
|
+
articulation: Articulation;
|
|
55
|
+
}, data: LunaticData): {
|
|
56
|
+
items: Item[];
|
|
57
|
+
};
|
|
58
|
+
export declare function findComponentById(components: ComponentDefinition[], id: string): (ComponentRoundaboutDefinition & {
|
|
59
|
+
page?: string;
|
|
60
|
+
}) | null;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getArticulation = getArticulation;
|
|
4
|
+
exports.findComponentById = findComponentById;
|
|
5
|
+
const reducerInitializer_1 = require("../use-lunatic/reducer/reducerInitializer");
|
|
6
|
+
const array_1 = require("./array");
|
|
7
|
+
const number_1 = require("./number");
|
|
8
|
+
/**
|
|
9
|
+
* Retrieve the articulation state
|
|
10
|
+
*
|
|
11
|
+
* ## Why this hook
|
|
12
|
+
*
|
|
13
|
+
* The goal of this hook is to provide insights about a roundabout using extra information inserted in the JSON source
|
|
14
|
+
* provided to Lunatic.
|
|
15
|
+
*
|
|
16
|
+
* For instance
|
|
17
|
+
*
|
|
18
|
+
* ```
|
|
19
|
+
* "articulation": {
|
|
20
|
+
* "source": "roundabout",
|
|
21
|
+
* "items": [
|
|
22
|
+
* {
|
|
23
|
+
* "label": "Prénom",
|
|
24
|
+
* "value": "PRENOMS"
|
|
25
|
+
* },
|
|
26
|
+
* {
|
|
27
|
+
* "label": "Sexe",
|
|
28
|
+
* "value": "if SEXE = \"H\" then \"Homme\" else \"Femme\""
|
|
29
|
+
* },
|
|
30
|
+
* {
|
|
31
|
+
* "label": "Age",
|
|
32
|
+
* "value": "cast(AGE, string) || \" ans\""
|
|
33
|
+
* }
|
|
34
|
+
* ]
|
|
35
|
+
* },
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* - source is the ID of the roundabout component
|
|
39
|
+
* - items define the field to extract from the roundabout data
|
|
40
|
+
*/
|
|
41
|
+
function getArticulation(source, data) {
|
|
42
|
+
const roundabout = findComponentById(source.components, source.articulation.source);
|
|
43
|
+
const { variables } = (0, reducerInitializer_1.reducerInitializer)({ source, data });
|
|
44
|
+
const iterations = (0, number_1.forceInt)(variables.run(roundabout?.iterations.value ?? '0'));
|
|
45
|
+
const rows = (0, array_1.times)(iterations, (k) => source.articulation.items.map((item) => ({
|
|
46
|
+
label: item.label,
|
|
47
|
+
value: variables.run(item.value, { iteration: [k] }),
|
|
48
|
+
})));
|
|
49
|
+
if (!roundabout) {
|
|
50
|
+
return {
|
|
51
|
+
items: [],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
items: rows.map((row, k) => ({
|
|
56
|
+
cells: row,
|
|
57
|
+
progress: (0, number_1.forceInt)(variables.get(roundabout.progressVariable, [k]) ?? -1),
|
|
58
|
+
page: (roundabout.page
|
|
59
|
+
? `${roundabout.page}.1#${k + 1}`
|
|
60
|
+
: '1'),
|
|
61
|
+
})),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function findComponentById(components, id) {
|
|
65
|
+
for (const c of components) {
|
|
66
|
+
if ('id' in c && c.id === id && c.componentType === 'Roundabout') {
|
|
67
|
+
return c;
|
|
68
|
+
}
|
|
69
|
+
if ('components' in c) {
|
|
70
|
+
const child = findComponentById(c.components, id);
|
|
71
|
+
if (child) {
|
|
72
|
+
return child;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=getArticulation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getArticulation.js","sourceRoot":"","sources":["../src/utils/getArticul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