@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.
Files changed (104) hide show
  1. package/components/Loop/Loop.js +7 -27
  2. package/components/Loop/Loop.js.map +1 -1
  3. package/components/RosterForLoop/RosterForLoop.js +8 -37
  4. package/components/RosterForLoop/RosterForLoop.js.map +1 -1
  5. package/components/Sequence/Sequence.d.ts +1 -1
  6. package/components/Subsequence/Subsequence.d.ts +1 -1
  7. package/components/library.d.ts +2 -2
  8. package/esm/components/Loop/Loop.js +7 -27
  9. package/esm/components/Loop/Loop.js.map +1 -1
  10. package/esm/components/RosterForLoop/RosterForLoop.js +8 -34
  11. package/esm/components/RosterForLoop/RosterForLoop.js.map +1 -1
  12. package/esm/components/Sequence/Sequence.d.ts +1 -1
  13. package/esm/components/Subsequence/Subsequence.d.ts +1 -1
  14. package/esm/components/library.d.ts +2 -2
  15. package/esm/hooks/useArticulation.d.ts +58 -0
  16. package/esm/hooks/useArticulation.js +81 -0
  17. package/esm/hooks/useArticulation.js.map +1 -0
  18. package/esm/i18n/dictionary.d.ts +0 -8
  19. package/esm/i18n/dictionary.js +0 -5
  20. package/esm/i18n/dictionary.js.map +1 -1
  21. package/esm/i18n/index.d.ts +1 -1
  22. package/esm/type.source.js +1 -0
  23. package/esm/type.source.js.map +1 -1
  24. package/esm/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +7 -23
  25. package/esm/use-lunatic/commons/variables/behaviours/resizing-behaviour.js.map +1 -1
  26. package/esm/use-lunatic/commons/variables/lunatic-variables-store.d.ts +1 -3
  27. package/esm/use-lunatic/commons/variables/lunatic-variables-store.js +1 -1
  28. package/esm/use-lunatic/commons/variables/lunatic-variables-store.js.map +1 -1
  29. package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js +1 -66
  30. package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
  31. package/esm/use-lunatic/props/getComponentTypeProps.d.ts +4 -4
  32. package/esm/use-lunatic/reducer/commons/index.d.ts +1 -0
  33. package/esm/use-lunatic/reducer/commons/index.js +1 -0
  34. package/esm/use-lunatic/reducer/commons/index.js.map +1 -1
  35. package/esm/use-lunatic/reducer/commons/resize-array-variable.d.ts +5 -0
  36. package/esm/use-lunatic/reducer/commons/resize-array-variable.js +21 -0
  37. package/esm/use-lunatic/reducer/commons/resize-array-variable.js.map +1 -0
  38. package/esm/use-lunatic/reducer/reducerInitializer.d.ts +2 -2
  39. package/esm/use-lunatic/reducer/reducerInitializer.js +31 -24
  40. package/esm/use-lunatic/reducer/reducerInitializer.js.map +1 -1
  41. package/esm/use-lunatic/type.d.ts +0 -1
  42. package/esm/utils/array.d.ts +0 -4
  43. package/esm/utils/array.js +2 -15
  44. package/esm/utils/array.js.map +1 -1
  45. package/esm/utils/array.spec.js +1 -12
  46. package/esm/utils/array.spec.js.map +1 -1
  47. package/hooks/useArticulation.d.ts +58 -0
  48. package/hooks/useArticulation.js +81 -0
  49. package/hooks/useArticulation.js.map +1 -0
  50. package/i18n/dictionary.d.ts +0 -8
  51. package/i18n/dictionary.js +0 -5
  52. package/i18n/dictionary.js.map +1 -1
  53. package/i18n/index.d.ts +1 -1
  54. package/package.json +20 -4
  55. package/src/components/Loop/Loop.tsx +12 -42
  56. package/src/components/RosterForLoop/RosterForLoop.tsx +2 -42
  57. package/src/components/RosterForLoop/__snapshots__/RosterForLoop.spec.tsx.snap +0 -18
  58. package/src/hooks/useArticulation.ts +124 -0
  59. package/src/i18n/dictionary.ts +0 -5
  60. package/src/stories/behaviour/articulation/articulation.stories.tsx +105 -0
  61. package/src/stories/behaviour/articulation/roundabout.json +348 -0
  62. package/src/stories/behaviour/performance/performance.stories.jsx +1 -1
  63. package/src/stories/pairwise/data.json +1 -1
  64. package/src/stories/pairwise/source.json +1 -3
  65. package/src/stories/utils/{SchemaValidator.jsx → SchemaValidator.tsx} +1 -1
  66. package/src/stories/utils/{orchestrator.jsx → orchestrator.tsx} +13 -9
  67. package/src/stories/utils/{overview.jsx → overview.tsx} +2 -0
  68. package/src/type.source.ts +1 -0
  69. package/src/use-lunatic/__snapshots__/use-lunatic.test.ts.snap +323 -0
  70. package/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.ts +10 -35
  71. package/src/use-lunatic/commons/variables/lunatic-variables-store.spec.ts +1 -68
  72. package/src/use-lunatic/commons/variables/lunatic-variables-store.ts +2 -4
  73. package/src/use-lunatic/reducer/commons/index.ts +1 -0
  74. package/src/use-lunatic/reducer/commons/resize-array-variable.ts +28 -0
  75. package/src/use-lunatic/reducer/reducerInitializer.tsx +40 -29
  76. package/src/use-lunatic/type.ts +0 -1
  77. package/src/utils/array.spec.ts +1 -18
  78. package/src/utils/array.ts +3 -21
  79. package/tsconfig.build.tsbuildinfo +1 -1
  80. package/type.source.js +1 -0
  81. package/type.source.js.map +1 -1
  82. package/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +6 -22
  83. package/use-lunatic/commons/variables/behaviours/resizing-behaviour.js.map +1 -1
  84. package/use-lunatic/commons/variables/lunatic-variables-store.d.ts +1 -3
  85. package/use-lunatic/commons/variables/lunatic-variables-store.js +1 -1
  86. package/use-lunatic/commons/variables/lunatic-variables-store.js.map +1 -1
  87. package/use-lunatic/commons/variables/lunatic-variables-store.spec.js +1 -66
  88. package/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
  89. package/use-lunatic/props/getComponentTypeProps.d.ts +4 -4
  90. package/use-lunatic/reducer/commons/index.d.ts +1 -0
  91. package/use-lunatic/reducer/commons/index.js +6 -0
  92. package/use-lunatic/reducer/commons/index.js.map +1 -1
  93. package/use-lunatic/reducer/commons/resize-array-variable.d.ts +5 -0
  94. package/use-lunatic/reducer/commons/resize-array-variable.js +23 -0
  95. package/use-lunatic/reducer/commons/resize-array-variable.js.map +1 -0
  96. package/use-lunatic/reducer/reducerInitializer.d.ts +2 -2
  97. package/use-lunatic/reducer/reducerInitializer.js +31 -24
  98. package/use-lunatic/reducer/reducerInitializer.js.map +1 -1
  99. package/use-lunatic/type.d.ts +0 -1
  100. package/utils/array.d.ts +0 -4
  101. package/utils/array.js +2 -16
  102. package/utils/array.js.map +1 -1
  103. package/utils/array.spec.js +0 -11
  104. package/utils/array.spec.js.map +1 -1
@@ -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
  });
@@ -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).reduce(function (
70
- step,
71
- current,
66
+ return new Array(newLength).fill(defaultValue ?? null).map(function (
67
+ value,
72
68
  index
73
69
  ) {
74
- if (index < array.length) {
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
  */