@inseefr/lunatic 3.4.11-rc.0 → 3.4.11-rc.1
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/Roundabout/CustomRoundabout.d.ts +1 -1
- package/components/Roundabout/CustomRoundabout.js +4 -3
- package/components/Roundabout/CustomRoundabout.js.map +1 -1
- package/components/Roundabout/roundabout.spec.js +3 -1
- package/components/Roundabout/roundabout.spec.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/Roundabout/CustomRoundabout.d.ts +1 -1
- package/esm/components/Roundabout/CustomRoundabout.js +4 -3
- package/esm/components/Roundabout/CustomRoundabout.js.map +1 -1
- package/esm/components/Roundabout/roundabout.spec.js +3 -1
- package/esm/components/Roundabout/roundabout.spec.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/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/main.css +10 -0
- package/esm/main.css.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.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/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/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/main.css +10 -0
- package/main.css.map +1 -1
- package/package.json +8 -1
- 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/components/Roundabout/CustomRoundabout.tsx +13 -4
- package/src/components/Roundabout/roundabout.spec.tsx +3 -0
- package/src/css/components/Roundabout.scss +10 -0
- package/src/i18n/dictionary.ts +0 -5
- package/src/stories/pairwise/data.json +1 -1
- package/src/stories/pairwise/source.json +1 -3
- package/src/stories/roundabout/source.json +4 -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 +1 -3
- 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/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.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/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
|
@@ -1855,6 +1855,329 @@ exports[`use-lunatic() > overview > with loop > should handle initialPage 1`] =
|
|
|
1855
1855
|
]
|
|
1856
1856
|
`;
|
|
1857
1857
|
|
|
1858
|
+
exports[`use-lunatic() > overview > with loop > should handle lastReachedPage 1`] = `
|
|
1859
|
+
[
|
|
1860
|
+
{
|
|
1861
|
+
"children": [
|
|
1862
|
+
{
|
|
1863
|
+
"children": [],
|
|
1864
|
+
"current": false,
|
|
1865
|
+
"description": undefined,
|
|
1866
|
+
"id": "lujqeci5",
|
|
1867
|
+
"label": <MDLabel
|
|
1868
|
+
expression="Votre santé"
|
|
1869
|
+
/>,
|
|
1870
|
+
"page": "2",
|
|
1871
|
+
"reached": true,
|
|
1872
|
+
"type": "Subsequence",
|
|
1873
|
+
},
|
|
1874
|
+
{
|
|
1875
|
+
"children": [],
|
|
1876
|
+
"current": false,
|
|
1877
|
+
"description": undefined,
|
|
1878
|
+
"id": "lujqbyzl",
|
|
1879
|
+
"label": <MDLabel
|
|
1880
|
+
expression="Votre logement"
|
|
1881
|
+
/>,
|
|
1882
|
+
"page": "3",
|
|
1883
|
+
"reached": true,
|
|
1884
|
+
"type": "Subsequence",
|
|
1885
|
+
},
|
|
1886
|
+
],
|
|
1887
|
+
"current": true,
|
|
1888
|
+
"description": undefined,
|
|
1889
|
+
"id": "lujqfpva",
|
|
1890
|
+
"label": <MDLabel
|
|
1891
|
+
expression="I - Séquence 1"
|
|
1892
|
+
/>,
|
|
1893
|
+
"page": "1",
|
|
1894
|
+
"reached": true,
|
|
1895
|
+
"type": "Sequence",
|
|
1896
|
+
},
|
|
1897
|
+
{
|
|
1898
|
+
"children": [
|
|
1899
|
+
{
|
|
1900
|
+
"children": [],
|
|
1901
|
+
"current": false,
|
|
1902
|
+
"description": undefined,
|
|
1903
|
+
"id": "lulbmyhr",
|
|
1904
|
+
"label": <MDLabel
|
|
1905
|
+
expression="Commentaire sur composition du logement"
|
|
1906
|
+
/>,
|
|
1907
|
+
"page": "8",
|
|
1908
|
+
"reached": true,
|
|
1909
|
+
"type": "Subsequence",
|
|
1910
|
+
},
|
|
1911
|
+
],
|
|
1912
|
+
"current": false,
|
|
1913
|
+
"description": undefined,
|
|
1914
|
+
"id": "lujqrqmp",
|
|
1915
|
+
"label": <MDLabel
|
|
1916
|
+
expression="II - Habitants du logement"
|
|
1917
|
+
/>,
|
|
1918
|
+
"page": "5",
|
|
1919
|
+
"reached": true,
|
|
1920
|
+
"type": "Sequence",
|
|
1921
|
+
},
|
|
1922
|
+
{
|
|
1923
|
+
"children": [
|
|
1924
|
+
{
|
|
1925
|
+
"children": [],
|
|
1926
|
+
"current": false,
|
|
1927
|
+
"description": undefined,
|
|
1928
|
+
"id": "lujykwaz",
|
|
1929
|
+
"label": <MDLabel
|
|
1930
|
+
expression="Caractéristiques de Quentin"
|
|
1931
|
+
/>,
|
|
1932
|
+
"page": "10.1#1",
|
|
1933
|
+
"reached": true,
|
|
1934
|
+
"type": "Subsequence",
|
|
1935
|
+
},
|
|
1936
|
+
{
|
|
1937
|
+
"children": [],
|
|
1938
|
+
"current": false,
|
|
1939
|
+
"description": undefined,
|
|
1940
|
+
"id": "lujykwaz",
|
|
1941
|
+
"label": <MDLabel
|
|
1942
|
+
expression="Caractéristiques de Luna"
|
|
1943
|
+
/>,
|
|
1944
|
+
"page": "10.1#2",
|
|
1945
|
+
"reached": true,
|
|
1946
|
+
"type": "Subsequence",
|
|
1947
|
+
},
|
|
1948
|
+
{
|
|
1949
|
+
"children": [],
|
|
1950
|
+
"current": false,
|
|
1951
|
+
"description": undefined,
|
|
1952
|
+
"id": "lujykwaz",
|
|
1953
|
+
"label": <MDLabel
|
|
1954
|
+
expression="Caractéristiques de Paul"
|
|
1955
|
+
/>,
|
|
1956
|
+
"page": "10.1#3",
|
|
1957
|
+
"reached": true,
|
|
1958
|
+
"type": "Subsequence",
|
|
1959
|
+
},
|
|
1960
|
+
{
|
|
1961
|
+
"children": [],
|
|
1962
|
+
"current": false,
|
|
1963
|
+
"description": undefined,
|
|
1964
|
+
"id": "lujyik5q",
|
|
1965
|
+
"label": <MDLabel
|
|
1966
|
+
expression="Autres caractéristiques de Luna : filtrée pour le premier individu"
|
|
1967
|
+
/>,
|
|
1968
|
+
"page": "11.1#2",
|
|
1969
|
+
"reached": true,
|
|
1970
|
+
"type": "Subsequence",
|
|
1971
|
+
},
|
|
1972
|
+
{
|
|
1973
|
+
"children": [],
|
|
1974
|
+
"current": false,
|
|
1975
|
+
"description": undefined,
|
|
1976
|
+
"id": "luk0swcz",
|
|
1977
|
+
"label": <MDLabel
|
|
1978
|
+
expression="Encore d'autres caractéristiques de Luna : filtrée pour le premier individu"
|
|
1979
|
+
/>,
|
|
1980
|
+
"page": "11.2#2",
|
|
1981
|
+
"reached": true,
|
|
1982
|
+
"type": "Subsequence",
|
|
1983
|
+
},
|
|
1984
|
+
{
|
|
1985
|
+
"children": [],
|
|
1986
|
+
"current": false,
|
|
1987
|
+
"description": undefined,
|
|
1988
|
+
"id": "lujyik5q",
|
|
1989
|
+
"label": <MDLabel
|
|
1990
|
+
expression="Autres caractéristiques de Paul : filtrée pour le premier individu"
|
|
1991
|
+
/>,
|
|
1992
|
+
"page": "11.1#3",
|
|
1993
|
+
"reached": false,
|
|
1994
|
+
"type": "Subsequence",
|
|
1995
|
+
},
|
|
1996
|
+
{
|
|
1997
|
+
"children": [],
|
|
1998
|
+
"current": false,
|
|
1999
|
+
"description": undefined,
|
|
2000
|
+
"id": "luk0swcz",
|
|
2001
|
+
"label": <MDLabel
|
|
2002
|
+
expression="Encore d'autres caractéristiques de Paul : filtrée pour le premier individu"
|
|
2003
|
+
/>,
|
|
2004
|
+
"page": "11.2#3",
|
|
2005
|
+
"reached": false,
|
|
2006
|
+
"type": "Subsequence",
|
|
2007
|
+
},
|
|
2008
|
+
],
|
|
2009
|
+
"current": false,
|
|
2010
|
+
"description": undefined,
|
|
2011
|
+
"id": "lujyi4pe",
|
|
2012
|
+
"label": <MDLabel
|
|
2013
|
+
expression="III - Détail des individus"
|
|
2014
|
+
/>,
|
|
2015
|
+
"page": "9",
|
|
2016
|
+
"reached": true,
|
|
2017
|
+
"type": "Sequence",
|
|
2018
|
+
},
|
|
2019
|
+
{
|
|
2020
|
+
"children": [
|
|
2021
|
+
{
|
|
2022
|
+
"children": [],
|
|
2023
|
+
"current": false,
|
|
2024
|
+
"description": undefined,
|
|
2025
|
+
"id": "lumfc98o",
|
|
2026
|
+
"label": <MDLabel
|
|
2027
|
+
expression="Belle sous-séquence pour Quentin"
|
|
2028
|
+
/>,
|
|
2029
|
+
"page": "12.2#1",
|
|
2030
|
+
"reached": false,
|
|
2031
|
+
"type": "Subsequence",
|
|
2032
|
+
},
|
|
2033
|
+
{
|
|
2034
|
+
"children": [],
|
|
2035
|
+
"current": false,
|
|
2036
|
+
"description": undefined,
|
|
2037
|
+
"id": "lumfe3bj",
|
|
2038
|
+
"label": <MDLabel
|
|
2039
|
+
expression="Autre belle sous-seq"
|
|
2040
|
+
/>,
|
|
2041
|
+
"page": "12.3#1",
|
|
2042
|
+
"reached": false,
|
|
2043
|
+
"type": "Subsequence",
|
|
2044
|
+
},
|
|
2045
|
+
],
|
|
2046
|
+
"current": false,
|
|
2047
|
+
"description": undefined,
|
|
2048
|
+
"id": "luk1ojt5",
|
|
2049
|
+
"label": <MDLabel
|
|
2050
|
+
expression="IV - Belle séquence pour Quentin"
|
|
2051
|
+
/>,
|
|
2052
|
+
"page": "12.1#1",
|
|
2053
|
+
"reached": false,
|
|
2054
|
+
"type": "Sequence",
|
|
2055
|
+
},
|
|
2056
|
+
{
|
|
2057
|
+
"children": [],
|
|
2058
|
+
"current": false,
|
|
2059
|
+
"description": undefined,
|
|
2060
|
+
"id": "lulbelgr",
|
|
2061
|
+
"label": <MDLabel
|
|
2062
|
+
expression="V - Autre séquence pour Quentin"
|
|
2063
|
+
/>,
|
|
2064
|
+
"page": "12.4#1",
|
|
2065
|
+
"reached": false,
|
|
2066
|
+
"type": "Sequence",
|
|
2067
|
+
},
|
|
2068
|
+
{
|
|
2069
|
+
"children": [
|
|
2070
|
+
{
|
|
2071
|
+
"children": [],
|
|
2072
|
+
"current": false,
|
|
2073
|
+
"description": undefined,
|
|
2074
|
+
"id": "lumfc98o",
|
|
2075
|
+
"label": <MDLabel
|
|
2076
|
+
expression="Belle sous-séquence pour Luna"
|
|
2077
|
+
/>,
|
|
2078
|
+
"page": "12.2#2",
|
|
2079
|
+
"reached": false,
|
|
2080
|
+
"type": "Subsequence",
|
|
2081
|
+
},
|
|
2082
|
+
{
|
|
2083
|
+
"children": [],
|
|
2084
|
+
"current": false,
|
|
2085
|
+
"description": undefined,
|
|
2086
|
+
"id": "lumfe3bj",
|
|
2087
|
+
"label": <MDLabel
|
|
2088
|
+
expression="Autre belle sous-seq"
|
|
2089
|
+
/>,
|
|
2090
|
+
"page": "12.3#2",
|
|
2091
|
+
"reached": false,
|
|
2092
|
+
"type": "Subsequence",
|
|
2093
|
+
},
|
|
2094
|
+
],
|
|
2095
|
+
"current": false,
|
|
2096
|
+
"description": undefined,
|
|
2097
|
+
"id": "luk1ojt5",
|
|
2098
|
+
"label": <MDLabel
|
|
2099
|
+
expression="IV - Belle séquence pour Luna"
|
|
2100
|
+
/>,
|
|
2101
|
+
"page": "12.1#2",
|
|
2102
|
+
"reached": false,
|
|
2103
|
+
"type": "Sequence",
|
|
2104
|
+
},
|
|
2105
|
+
{
|
|
2106
|
+
"children": [],
|
|
2107
|
+
"current": false,
|
|
2108
|
+
"description": undefined,
|
|
2109
|
+
"id": "lulbelgr",
|
|
2110
|
+
"label": <MDLabel
|
|
2111
|
+
expression="V - Autre séquence pour Luna"
|
|
2112
|
+
/>,
|
|
2113
|
+
"page": "12.4#2",
|
|
2114
|
+
"reached": false,
|
|
2115
|
+
"type": "Sequence",
|
|
2116
|
+
},
|
|
2117
|
+
{
|
|
2118
|
+
"children": [
|
|
2119
|
+
{
|
|
2120
|
+
"children": [],
|
|
2121
|
+
"current": false,
|
|
2122
|
+
"description": undefined,
|
|
2123
|
+
"id": "lumfc98o",
|
|
2124
|
+
"label": <MDLabel
|
|
2125
|
+
expression="Belle sous-séquence pour Paul"
|
|
2126
|
+
/>,
|
|
2127
|
+
"page": "12.2#3",
|
|
2128
|
+
"reached": false,
|
|
2129
|
+
"type": "Subsequence",
|
|
2130
|
+
},
|
|
2131
|
+
{
|
|
2132
|
+
"children": [],
|
|
2133
|
+
"current": false,
|
|
2134
|
+
"description": undefined,
|
|
2135
|
+
"id": "lumfe3bj",
|
|
2136
|
+
"label": <MDLabel
|
|
2137
|
+
expression="Autre belle sous-seq"
|
|
2138
|
+
/>,
|
|
2139
|
+
"page": "12.3#3",
|
|
2140
|
+
"reached": false,
|
|
2141
|
+
"type": "Subsequence",
|
|
2142
|
+
},
|
|
2143
|
+
],
|
|
2144
|
+
"current": false,
|
|
2145
|
+
"description": undefined,
|
|
2146
|
+
"id": "luk1ojt5",
|
|
2147
|
+
"label": <MDLabel
|
|
2148
|
+
expression="IV - Belle séquence pour Paul"
|
|
2149
|
+
/>,
|
|
2150
|
+
"page": "12.1#3",
|
|
2151
|
+
"reached": false,
|
|
2152
|
+
"type": "Sequence",
|
|
2153
|
+
},
|
|
2154
|
+
{
|
|
2155
|
+
"children": [],
|
|
2156
|
+
"current": false,
|
|
2157
|
+
"description": undefined,
|
|
2158
|
+
"id": "lulbelgr",
|
|
2159
|
+
"label": <MDLabel
|
|
2160
|
+
expression="V - Autre séquence pour Paul"
|
|
2161
|
+
/>,
|
|
2162
|
+
"page": "12.4#3",
|
|
2163
|
+
"reached": false,
|
|
2164
|
+
"type": "Sequence",
|
|
2165
|
+
},
|
|
2166
|
+
{
|
|
2167
|
+
"children": [],
|
|
2168
|
+
"current": false,
|
|
2169
|
+
"description": undefined,
|
|
2170
|
+
"id": "COMMENT-SEQ",
|
|
2171
|
+
"label": <MDLabel
|
|
2172
|
+
expression="Commentaire"
|
|
2173
|
+
/>,
|
|
2174
|
+
"page": "13",
|
|
2175
|
+
"reached": false,
|
|
2176
|
+
"type": "Sequence",
|
|
2177
|
+
},
|
|
2178
|
+
]
|
|
2179
|
+
`;
|
|
2180
|
+
|
|
1858
2181
|
exports[`use-lunatic() > overview > with loop > should work with loop 1`] = `
|
|
1859
2182
|
[
|
|
1860
2183
|
{
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { LunaticVariablesStore } from '../lunatic-variables-store';
|
|
2
2
|
import type { LunaticSource } from '../../../type';
|
|
3
3
|
import { forceInt } from '../../../../utils/number';
|
|
4
|
+
import { resizeArrayVariable } from '../../../reducer/commons';
|
|
4
5
|
import { getExpressionAsString } from '../../../../utils/vtl';
|
|
5
|
-
import { resizeArray
|
|
6
|
+
import { resizeArray } from '../../../../utils/array';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Resizing behaviour for the store
|
|
@@ -41,20 +42,8 @@ export function resizingBehaviour(
|
|
|
41
42
|
const newSize = forceInt(store.run(resizingInfo.size));
|
|
42
43
|
for (const variableName of resizingInfo.variables) {
|
|
43
44
|
const value = store.get(variableName);
|
|
44
|
-
if (Array.isArray(value)
|
|
45
|
-
store.set(
|
|
46
|
-
variableName,
|
|
47
|
-
resizeDownArrayWithIndex(value, e.detail.removedIndex),
|
|
48
|
-
{
|
|
49
|
-
cause: 'resizing',
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
if (
|
|
54
|
-
!e.detail.removedIndex &&
|
|
55
|
-
(!Array.isArray(value) || value.length !== newSize)
|
|
56
|
-
) {
|
|
57
|
-
store.set(variableName, resizeArray(value, newSize, null), {
|
|
45
|
+
if (!Array.isArray(value) || value.length !== newSize) {
|
|
46
|
+
store.set(variableName, resizeArrayVariable(value, newSize, null), {
|
|
58
47
|
cause: 'resizing',
|
|
59
48
|
});
|
|
60
49
|
}
|
|
@@ -72,7 +61,6 @@ function resizePairwise(
|
|
|
72
61
|
},
|
|
73
62
|
args: {
|
|
74
63
|
iteration?: number[];
|
|
75
|
-
removedIndex?: number;
|
|
76
64
|
}
|
|
77
65
|
) {
|
|
78
66
|
// Handle expression being sent as an array or an object (ensure backward compatibility)
|
|
@@ -90,25 +78,12 @@ function resizePairwise(
|
|
|
90
78
|
});
|
|
91
79
|
resizingInfo.linksVariables.forEach((variable) => {
|
|
92
80
|
const value = store.get(variable, args.iteration);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
: [],
|
|
100
|
-
removedIndex
|
|
101
|
-
);
|
|
102
|
-
} else {
|
|
103
|
-
resizedValue = resizeArray(
|
|
104
|
-
// The value is not an array, force an array
|
|
105
|
-
Array.isArray(value)
|
|
106
|
-
? value.map((i) => resizeArray(i, ySize, null))
|
|
107
|
-
: [],
|
|
108
|
-
xSize,
|
|
109
|
-
new Array(ySize).fill(null)
|
|
110
|
-
);
|
|
111
|
-
}
|
|
81
|
+
const resizedValue = resizeArray(
|
|
82
|
+
// The value is not an array, force an array
|
|
83
|
+
Array.isArray(value) ? value.map((i) => resizeArray(i, ySize, null)) : [],
|
|
84
|
+
xSize,
|
|
85
|
+
new Array(ySize).fill(null)
|
|
86
|
+
);
|
|
112
87
|
store.set(variable, resizedValue);
|
|
113
88
|
});
|
|
114
89
|
}
|
|
@@ -281,28 +281,6 @@ describe('lunatic-variables-store', () => {
|
|
|
281
281
|
cause: 'resizing',
|
|
282
282
|
});
|
|
283
283
|
});
|
|
284
|
-
|
|
285
|
-
it('should resize variables with Index', () => {
|
|
286
|
-
variables.set('PRENOM', ['John', 'Jane', 'Marc']);
|
|
287
|
-
variables.set('AGE', [20, 30, 40]);
|
|
288
|
-
const spy = vi.fn();
|
|
289
|
-
variables.on('change', (e) => spy(e.detail));
|
|
290
|
-
resizingBehaviour(variables, {
|
|
291
|
-
PRENOM: {
|
|
292
|
-
size: 'count(PRENOM)',
|
|
293
|
-
variables: ['AGE'],
|
|
294
|
-
},
|
|
295
|
-
});
|
|
296
|
-
variables.set('PRENOM', ['John', 'Marc'], { removedIndex: 1 });
|
|
297
|
-
expect((variables.get('PRENOM') as string[]).length).toEqual(2);
|
|
298
|
-
expect((variables.get('AGE') as string[]).length).toEqual(2);
|
|
299
|
-
expect(spy).toHaveBeenLastCalledWith({
|
|
300
|
-
name: 'AGE',
|
|
301
|
-
value: [20, 40],
|
|
302
|
-
cause: 'resizing',
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
|
|
306
284
|
it('should resize pairwise with the array syntax', () => {
|
|
307
285
|
variables.set('PRENOM', []);
|
|
308
286
|
variables.set('LINKS', [[]]);
|
|
@@ -338,29 +316,7 @@ describe('lunatic-variables-store', () => {
|
|
|
338
316
|
[null, null, null],
|
|
339
317
|
]);
|
|
340
318
|
});
|
|
341
|
-
it('should
|
|
342
|
-
variables.set('PRENOM', ['John', 'Jane', 'Marc']);
|
|
343
|
-
variables.set('LINKS', [
|
|
344
|
-
[null, 2, 4],
|
|
345
|
-
[1, null, 2],
|
|
346
|
-
[3, 2, null],
|
|
347
|
-
]);
|
|
348
|
-
resizingBehaviour(variables, {
|
|
349
|
-
PRENOM: {
|
|
350
|
-
sizeForLinksVariables: {
|
|
351
|
-
xAxisSize: 'count(PRENOM)',
|
|
352
|
-
yAxisSize: 'count(PRENOM)',
|
|
353
|
-
},
|
|
354
|
-
linksVariables: ['LINKS'],
|
|
355
|
-
},
|
|
356
|
-
});
|
|
357
|
-
variables.set('PRENOM', ['John', 'Marc'], { removedIndex: 1 });
|
|
358
|
-
expect(variables.get('LINKS') as string[][]).toEqual([
|
|
359
|
-
[null, 4],
|
|
360
|
-
[3, null],
|
|
361
|
-
]);
|
|
362
|
-
});
|
|
363
|
-
it('should handle both: pairwise and normal resize', () => {
|
|
319
|
+
it('should handle both pairwise and normal resize', () => {
|
|
364
320
|
variables.set('PRENOM', []);
|
|
365
321
|
variables.set('NOM', []);
|
|
366
322
|
variables.set('LINKS', [[]]);
|
|
@@ -380,29 +336,6 @@ describe('lunatic-variables-store', () => {
|
|
|
380
336
|
]);
|
|
381
337
|
expect(variables.get('NOM') as string[]).toEqual([null, null, null]);
|
|
382
338
|
});
|
|
383
|
-
it('should handle both: pairwise and normal resize with index', () => {
|
|
384
|
-
variables.set('PRENOM', ['John', 'Jane', 'Marc']);
|
|
385
|
-
variables.set('AGE', [40, 30, 20]);
|
|
386
|
-
variables.set('LINKS', [
|
|
387
|
-
[null, 2, 4],
|
|
388
|
-
[1, null, 2],
|
|
389
|
-
[3, 2, null],
|
|
390
|
-
]);
|
|
391
|
-
resizingBehaviour(variables, {
|
|
392
|
-
PRENOM: {
|
|
393
|
-
sizeForLinksVariables: ['count(PRENOM)', 'count(PRENOM)'],
|
|
394
|
-
linksVariables: ['LINKS'],
|
|
395
|
-
size: 'count(PRENOM)',
|
|
396
|
-
variables: ['AGE'],
|
|
397
|
-
},
|
|
398
|
-
});
|
|
399
|
-
variables.set('PRENOM', ['John', 'Marc'], { removedIndex: 1 });
|
|
400
|
-
expect(variables.get('LINKS') as string[][]).toEqual([
|
|
401
|
-
[null, 4],
|
|
402
|
-
[3, null],
|
|
403
|
-
]);
|
|
404
|
-
expect(variables.get('AGE') as string[]).toEqual([40, 20]);
|
|
405
|
-
});
|
|
406
339
|
});
|
|
407
340
|
|
|
408
341
|
describe('cleaning', () => {
|
|
@@ -33,8 +33,6 @@ export type EventArgs = {
|
|
|
33
33
|
value: unknown;
|
|
34
34
|
/** Iteration changed (for array). */
|
|
35
35
|
iteration?: IterationLevel | undefined;
|
|
36
|
-
/** removedIndex: when resize an array directly with only one handleChange (remove one line in tableLoop) */
|
|
37
|
-
removedIndex?: number;
|
|
38
36
|
/** What triggered this change. */
|
|
39
37
|
cause?: 'resizing' | 'cleaning';
|
|
40
38
|
/** Extra sent when setting the variable. */
|
|
@@ -125,7 +123,7 @@ export class LunaticVariablesStore {
|
|
|
125
123
|
public set(
|
|
126
124
|
name: string,
|
|
127
125
|
value: unknown,
|
|
128
|
-
args: Pick<EventArgs['change'], 'iteration' | 'cause'
|
|
126
|
+
args: Pick<EventArgs['change'], 'iteration' | 'cause'> = {}
|
|
129
127
|
): LunaticVariable {
|
|
130
128
|
if (!this.dictionary.has(name)) {
|
|
131
129
|
this.dictionary.set(
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cast the variable into an array and adjust the length if necessary
|
|
3
|
+
*/
|
|
4
|
+
function resizeArrayVariable<T = unknown>(
|
|
5
|
+
array: unknown,
|
|
6
|
+
length: number,
|
|
7
|
+
defaultValue?: T
|
|
8
|
+
): T[] {
|
|
9
|
+
if (!Array.isArray(array)) {
|
|
10
|
+
// create the array
|
|
11
|
+
return new Array(length).fill(defaultValue);
|
|
12
|
+
} else if (array.length !== length) {
|
|
13
|
+
// renew array end keep previous values
|
|
14
|
+
return new Array(length).fill(defaultValue).reduce(function (
|
|
15
|
+
step,
|
|
16
|
+
current,
|
|
17
|
+
index
|
|
18
|
+
) {
|
|
19
|
+
if (index < array.length) {
|
|
20
|
+
return [...step, array[index]];
|
|
21
|
+
}
|
|
22
|
+
return [...step, current];
|
|
23
|
+
}, []);
|
|
24
|
+
}
|
|
25
|
+
return array;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default resizeArrayVariable;
|
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
|
*/
|