@inseefr/lunatic 3.4.11-rc.0 → 3.5.0-rc.2
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/Loop/Loop.js +7 -27
- package/components/Loop/Loop.js.map +1 -1
- package/components/RosterForLoop/RosterForLoop.js +8 -37
- package/components/RosterForLoop/RosterForLoop.js.map +1 -1
- package/components/Sequence/Sequence.d.ts +1 -1
- package/components/Subsequence/Subsequence.d.ts +1 -1
- package/components/library.d.ts +2 -2
- package/esm/components/Loop/Loop.js +7 -27
- package/esm/components/Loop/Loop.js.map +1 -1
- package/esm/components/RosterForLoop/RosterForLoop.js +8 -34
- package/esm/components/RosterForLoop/RosterForLoop.js.map +1 -1
- package/esm/components/Sequence/Sequence.d.ts +1 -1
- package/esm/components/Subsequence/Subsequence.d.ts +1 -1
- package/esm/components/library.d.ts +2 -2
- package/esm/hooks/useArticulation.d.ts +58 -0
- package/esm/hooks/useArticulation.js +81 -0
- package/esm/hooks/useArticulation.js.map +1 -0
- package/esm/i18n/dictionary.d.ts +0 -8
- package/esm/i18n/dictionary.js +0 -5
- package/esm/i18n/dictionary.js.map +1 -1
- package/esm/i18n/index.d.ts +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/type.source.js +1 -0
- package/esm/type.source.js.map +1 -1
- package/esm/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +7 -23
- package/esm/use-lunatic/commons/variables/behaviours/resizing-behaviour.js.map +1 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.d.ts +1 -3
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.js +1 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.js.map +1 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js +1 -66
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
- package/esm/use-lunatic/props/getComponentTypeProps.d.ts +4 -4
- package/esm/use-lunatic/reducer/commons/index.d.ts +1 -0
- package/esm/use-lunatic/reducer/commons/index.js +1 -0
- package/esm/use-lunatic/reducer/commons/index.js.map +1 -1
- package/esm/use-lunatic/reducer/commons/resize-array-variable.d.ts +5 -0
- package/esm/use-lunatic/reducer/commons/resize-array-variable.js +21 -0
- package/esm/use-lunatic/reducer/commons/resize-array-variable.js.map +1 -0
- 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 +0 -1
- package/esm/utils/array.d.ts +0 -4
- package/esm/utils/array.js +2 -15
- package/esm/utils/array.js.map +1 -1
- package/esm/utils/array.spec.js +1 -12
- package/esm/utils/array.spec.js.map +1 -1
- package/hooks/useArticulation.d.ts +58 -0
- package/hooks/useArticulation.js +81 -0
- package/hooks/useArticulation.js.map +1 -0
- package/i18n/dictionary.d.ts +0 -8
- package/i18n/dictionary.js +0 -5
- package/i18n/dictionary.js.map +1 -1
- package/i18n/index.d.ts +1 -1
- package/index.d.ts +1 -0
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/package.json +20 -4
- package/src/components/Loop/Loop.tsx +12 -42
- package/src/components/RosterForLoop/RosterForLoop.tsx +2 -42
- package/src/components/RosterForLoop/__snapshots__/RosterForLoop.spec.tsx.snap +0 -18
- package/src/hooks/useArticulation.ts +124 -0
- package/src/i18n/dictionary.ts +0 -5
- package/src/index.ts +1 -0
- package/src/stories/behaviour/articulation/articulation.stories.tsx +105 -0
- package/src/stories/behaviour/articulation/roundabout.json +348 -0
- package/src/stories/behaviour/performance/performance.stories.jsx +1 -1
- package/src/stories/pairwise/data.json +1 -1
- package/src/stories/pairwise/source.json +1 -3
- package/src/stories/utils/{SchemaValidator.jsx → SchemaValidator.tsx} +1 -1
- package/src/stories/utils/{orchestrator.jsx → orchestrator.tsx} +13 -9
- package/src/stories/utils/{overview.jsx → overview.tsx} +2 -0
- package/src/type.source.ts +1 -0
- package/src/use-lunatic/__snapshots__/use-lunatic.test.ts.snap +323 -0
- package/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.ts +10 -35
- package/src/use-lunatic/commons/variables/lunatic-variables-store.spec.ts +1 -68
- package/src/use-lunatic/commons/variables/lunatic-variables-store.ts +2 -4
- package/src/use-lunatic/reducer/commons/index.ts +1 -0
- package/src/use-lunatic/reducer/commons/resize-array-variable.ts +28 -0
- package/src/use-lunatic/reducer/reducerInitializer.tsx +40 -29
- package/src/use-lunatic/type.ts +0 -1
- package/src/utils/array.spec.ts +1 -18
- package/src/utils/array.ts +3 -21
- package/tsconfig.build.tsbuildinfo +1 -1
- package/type.source.js +1 -0
- package/type.source.js.map +1 -1
- package/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +6 -22
- package/use-lunatic/commons/variables/behaviours/resizing-behaviour.js.map +1 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.d.ts +1 -3
- package/use-lunatic/commons/variables/lunatic-variables-store.js +1 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.js.map +1 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.spec.js +1 -66
- package/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
- package/use-lunatic/props/getComponentTypeProps.d.ts +4 -4
- package/use-lunatic/reducer/commons/index.d.ts +1 -0
- package/use-lunatic/reducer/commons/index.js +6 -0
- package/use-lunatic/reducer/commons/index.js.map +1 -1
- package/use-lunatic/reducer/commons/resize-array-variable.d.ts +5 -0
- package/use-lunatic/reducer/commons/resize-array-variable.js +23 -0
- package/use-lunatic/reducer/commons/resize-array-variable.js.map +1 -0
- 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 +0 -1
- package/utils/array.d.ts +0 -4
- package/utils/array.js +2 -16
- package/utils/array.js.map +1 -1
- package/utils/array.spec.js +0 -11
- package/utils/array.spec.js.map +1 -1
|
@@ -38,6 +38,8 @@ const baseState = {
|
|
|
38
38
|
options: { disableFilters: false },
|
|
39
39
|
} satisfies LunaticReducerState;
|
|
40
40
|
|
|
41
|
+
const onChange = { current: () => {} };
|
|
42
|
+
|
|
41
43
|
export function reducerInitializer({
|
|
42
44
|
source,
|
|
43
45
|
data,
|
|
@@ -47,8 +49,8 @@ export function reducerInitializer({
|
|
|
47
49
|
withOverview = false,
|
|
48
50
|
disableFilters = false,
|
|
49
51
|
getReferentiel,
|
|
50
|
-
onVariableChange,
|
|
51
|
-
logger,
|
|
52
|
+
onVariableChange = onChange,
|
|
53
|
+
logger = console.error,
|
|
52
54
|
}: {
|
|
53
55
|
source: LunaticSource;
|
|
54
56
|
data: LunaticData;
|
|
@@ -58,8 +60,8 @@ export function reducerInitializer({
|
|
|
58
60
|
withOverview?: LunaticOptions['withOverview'];
|
|
59
61
|
disableFilters?: LunaticOptions['disableFilters'];
|
|
60
62
|
getReferentiel?: LunaticOptions['getReferentiel'];
|
|
61
|
-
onVariableChange
|
|
62
|
-
logger
|
|
63
|
+
onVariableChange?: RefObject<LunaticOptions['onVariableChange']>;
|
|
64
|
+
logger?: LunaticLogger;
|
|
63
65
|
}): LunaticReducerState {
|
|
64
66
|
const variables = LunaticVariablesStore.makeFromSource(
|
|
65
67
|
source,
|
|
@@ -110,11 +112,13 @@ export function reducerInitializer({
|
|
|
110
112
|
}
|
|
111
113
|
return result as any;
|
|
112
114
|
} catch (e) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
if (logger) {
|
|
116
|
+
// If there is an error interpreting a variable, return the raw expression
|
|
117
|
+
logger({
|
|
118
|
+
type: 'ERROR',
|
|
119
|
+
error: e as Error,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
118
122
|
return expressionString;
|
|
119
123
|
}
|
|
120
124
|
};
|
|
@@ -131,9 +135,9 @@ export function reducerInitializer({
|
|
|
131
135
|
const pager = {
|
|
132
136
|
page: initialPager?.page ?? 1,
|
|
133
137
|
maxPage: source.maxPage ? parseInt(source.maxPage, 10) : 1,
|
|
134
|
-
subPage:
|
|
138
|
+
subPage: initialPager?.subPage,
|
|
135
139
|
nbSubPages: undefined,
|
|
136
|
-
iteration:
|
|
140
|
+
iteration: initialPager?.iteration,
|
|
137
141
|
nbIterations: undefined,
|
|
138
142
|
lastReachedPage: lastReachedPage ?? initialPage,
|
|
139
143
|
};
|
|
@@ -143,7 +147,7 @@ export function reducerInitializer({
|
|
|
143
147
|
pager,
|
|
144
148
|
previousPager: pager,
|
|
145
149
|
pages,
|
|
146
|
-
isInLoop:
|
|
150
|
+
isInLoop: pager.subPage !== undefined,
|
|
147
151
|
updatedAt: Date.now(),
|
|
148
152
|
overview: withOverview ? buildOverview(source) : [],
|
|
149
153
|
updateBindings,
|
|
@@ -161,22 +165,29 @@ function fillPagerForLoop(state: LunaticReducerState): LunaticReducerState {
|
|
|
161
165
|
return state;
|
|
162
166
|
}
|
|
163
167
|
const { isLoop, subPages, iterations, loopDependencies } = pages[pager.page];
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
|
|
169
|
+
if (
|
|
170
|
+
// For loop, jump at the first page
|
|
171
|
+
isLoop ||
|
|
172
|
+
// For roundabout, jump at the desired iteration / subpage (only if defined)
|
|
173
|
+
(pager?.iteration !== undefined && subPages)
|
|
174
|
+
) {
|
|
175
|
+
return {
|
|
176
|
+
...state,
|
|
177
|
+
isInLoop: true,
|
|
178
|
+
pager: {
|
|
179
|
+
...pager,
|
|
180
|
+
subPage: pager?.subPage ?? 1,
|
|
181
|
+
nbSubPages: (subPages ?? []).length,
|
|
182
|
+
iteration: pager?.iteration ?? 0,
|
|
183
|
+
nbIterations: forceInt(
|
|
184
|
+
state.executeExpression(iterations, {
|
|
185
|
+
deps: loopDependencies,
|
|
186
|
+
})
|
|
187
|
+
),
|
|
188
|
+
},
|
|
189
|
+
};
|
|
166
190
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
isInLoop: true,
|
|
170
|
-
pager: {
|
|
171
|
-
...pager,
|
|
172
|
-
subPage: pager?.subPage ?? 0,
|
|
173
|
-
nbSubPages: (subPages ?? []).length,
|
|
174
|
-
iteration: pager?.iteration ?? 0,
|
|
175
|
-
nbIterations: forceInt(
|
|
176
|
-
state.executeExpression(iterations, {
|
|
177
|
-
deps: loopDependencies,
|
|
178
|
-
})
|
|
179
|
-
),
|
|
180
|
-
},
|
|
181
|
-
};
|
|
191
|
+
|
|
192
|
+
return state;
|
|
182
193
|
}
|
package/src/use-lunatic/type.ts
CHANGED
package/src/utils/array.spec.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
firstValueItem,
|
|
4
|
-
resizeArray,
|
|
5
|
-
resizeDownArrayWithIndex,
|
|
6
|
-
setAtIndex,
|
|
7
|
-
} from './array';
|
|
2
|
+
import { firstValueItem, resizeArray, setAtIndex } from './array';
|
|
8
3
|
|
|
9
4
|
describe('array', () => {
|
|
10
5
|
describe('resizeArray()', () => {
|
|
@@ -50,16 +45,4 @@ describe('array', () => {
|
|
|
50
45
|
expect(firstValueItem([null, 1, 2])).toBe(1);
|
|
51
46
|
expect(firstValueItem([null, undefined, false])).toBe(false);
|
|
52
47
|
});
|
|
53
|
-
describe('resizeDownArrayWithIndex()', () => {
|
|
54
|
-
it('should remove an element of array', () => {
|
|
55
|
-
expect(resizeDownArrayWithIndex([1, 2, 3, 4], 2)).toEqual([1, 2, 4]);
|
|
56
|
-
expect(resizeDownArrayWithIndex([1, 2, 3, 4], 0)).toEqual([2, 3, 4]);
|
|
57
|
-
expect(resizeDownArrayWithIndex([1, 2, 3, 4], 3)).toEqual([1, 2, 3]);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should not remove element (out of index)', () => {
|
|
61
|
-
expect(resizeDownArrayWithIndex([1, 2, 3, 4], -1)).toEqual([1, 2, 3, 4]);
|
|
62
|
-
expect(resizeDownArrayWithIndex([1, 2, 3, 4], 4)).toEqual([1, 2, 3, 4]);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
48
|
});
|
package/src/utils/array.ts
CHANGED
|
@@ -51,9 +51,6 @@ export function getAtIndex(arr: unknown, indexes: number[]): unknown {
|
|
|
51
51
|
return current;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
/**
|
|
55
|
-
* Cast the variable into an array and adjust the length if necessary
|
|
56
|
-
*/
|
|
57
54
|
export function resizeArray<T = unknown>(
|
|
58
55
|
array: unknown,
|
|
59
56
|
newLength: number,
|
|
@@ -66,29 +63,14 @@ export function resizeArray<T = unknown>(
|
|
|
66
63
|
if (array.length === newLength) {
|
|
67
64
|
return array;
|
|
68
65
|
}
|
|
69
|
-
return new Array(newLength).fill(defaultValue ?? null).
|
|
70
|
-
|
|
71
|
-
current,
|
|
66
|
+
return new Array(newLength).fill(defaultValue ?? null).map(function (
|
|
67
|
+
value,
|
|
72
68
|
index
|
|
73
69
|
) {
|
|
74
|
-
|
|
75
|
-
return [...step, array[index]];
|
|
76
|
-
}
|
|
77
|
-
return [...step, current];
|
|
70
|
+
return index < array.length ? array[index] : value;
|
|
78
71
|
}, []);
|
|
79
72
|
}
|
|
80
73
|
|
|
81
|
-
export function resizeDownArrayWithIndex<T = unknown>(
|
|
82
|
-
array: T[],
|
|
83
|
-
removedIndex: number
|
|
84
|
-
): T[] {
|
|
85
|
-
// the removedIndex is not in array
|
|
86
|
-
if (0 > removedIndex || array.length <= removedIndex) {
|
|
87
|
-
return array;
|
|
88
|
-
}
|
|
89
|
-
return [...array].filter((_, i) => i !== removedIndex);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
74
|
/**
|
|
93
75
|
* Return the first non-null/undefined value of an array
|
|
94
76
|
*/
|