@inseefr/lunatic 3.4.11-rc.0 → 3.5.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/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/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/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/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
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
|
*/
|