@inseefr/lunatic 3.11.2 → 3.12.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 (287) hide show
  1. package/components/Accordion/Accordion.d.ts +1 -1
  2. package/components/Datepicker/DatepickerFields.js +4 -2
  3. package/components/Datepicker/DatepickerFields.js.map +1 -1
  4. package/components/Duration/getDurationFromValue.js +3 -3
  5. package/components/Duration/getDurationFromValue.js.map +1 -1
  6. package/components/FilterDescription/FilterDescription.d.ts +1 -1
  7. package/components/LunaticComponents.d.ts +1 -1
  8. package/components/LunaticComponents.js +9 -7
  9. package/components/LunaticComponents.js.map +1 -1
  10. package/components/PairwiseLinks/PairwiseLinks.d.ts +1 -1
  11. package/components/PairwiseLinks/PairwiseLinks.js +15 -30
  12. package/components/PairwiseLinks/PairwiseLinks.js.map +1 -1
  13. package/components/PairwiseLinks/PairwiseMirror.d.ts +2 -0
  14. package/components/PairwiseLinks/PairwiseMirror.js +14 -0
  15. package/components/PairwiseLinks/PairwiseMirror.js.map +1 -0
  16. package/components/PairwiseLinks/combinations.d.ts +18 -0
  17. package/components/PairwiseLinks/combinations.js +29 -0
  18. package/components/PairwiseLinks/combinations.js.map +1 -0
  19. package/components/Radio/Radio.d.ts +1 -1
  20. package/components/Sequence/Sequence.d.ts +1 -1
  21. package/components/Subsequence/Subsequence.d.ts +1 -1
  22. package/components/Switch/Switch.d.ts +1 -1
  23. package/components/library.d.ts +6 -6
  24. package/components/type.d.ts +25 -28
  25. package/esm/components/Accordion/Accordion.d.ts +1 -1
  26. package/esm/components/Datepicker/DatepickerFields.js +4 -2
  27. package/esm/components/Datepicker/DatepickerFields.js.map +1 -1
  28. package/esm/components/Duration/getDurationFromValue.js +3 -3
  29. package/esm/components/Duration/getDurationFromValue.js.map +1 -1
  30. package/esm/components/FilterDescription/FilterDescription.d.ts +1 -1
  31. package/esm/components/LunaticComponents.d.ts +1 -1
  32. package/esm/components/LunaticComponents.js +9 -7
  33. package/esm/components/LunaticComponents.js.map +1 -1
  34. package/esm/components/PairwiseLinks/PairwiseLinks.d.ts +1 -1
  35. package/esm/components/PairwiseLinks/PairwiseLinks.js +16 -31
  36. package/esm/components/PairwiseLinks/PairwiseLinks.js.map +1 -1
  37. package/esm/components/PairwiseLinks/PairwiseMirror.d.ts +2 -0
  38. package/esm/components/PairwiseLinks/PairwiseMirror.js +10 -0
  39. package/esm/components/PairwiseLinks/PairwiseMirror.js.map +1 -0
  40. package/esm/components/PairwiseLinks/combinations.d.ts +18 -0
  41. package/esm/components/PairwiseLinks/combinations.js +24 -0
  42. package/esm/components/PairwiseLinks/combinations.js.map +1 -0
  43. package/esm/components/Radio/Radio.d.ts +1 -1
  44. package/esm/components/Sequence/Sequence.d.ts +1 -1
  45. package/esm/components/Subsequence/Subsequence.d.ts +1 -1
  46. package/esm/components/Switch/Switch.d.ts +1 -1
  47. package/esm/components/library.d.ts +6 -6
  48. package/esm/components/type.d.ts +25 -28
  49. package/esm/index.d.ts +1 -1
  50. package/esm/index.js.map +1 -1
  51. package/esm/type.source.d.ts +43 -13
  52. package/esm/type.source.js +0 -1
  53. package/esm/type.source.js.map +1 -1
  54. package/esm/use-lunatic/commons/compile-controls.js +1 -1
  55. package/esm/use-lunatic/commons/compile-controls.js.map +1 -1
  56. package/esm/use-lunatic/commons/component.d.ts +3 -2
  57. package/esm/use-lunatic/commons/component.js +5 -0
  58. package/esm/use-lunatic/commons/component.js.map +1 -1
  59. package/esm/use-lunatic/commons/fill-components/fill-component-expressions.d.ts +1 -1
  60. package/esm/use-lunatic/commons/fill-components/fill-component-expressions.js +1 -42
  61. package/esm/use-lunatic/commons/fill-components/fill-component-expressions.js.map +1 -1
  62. package/esm/use-lunatic/commons/fill-components/fill-components.js +10 -2
  63. package/esm/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
  64. package/esm/use-lunatic/commons/index.d.ts +4 -4
  65. package/esm/use-lunatic/commons/index.js +4 -4
  66. package/esm/use-lunatic/commons/index.js.map +1 -1
  67. package/esm/use-lunatic/commons/{check-loops.d.ts → pagination/check-loops.d.ts} +7 -7
  68. package/esm/use-lunatic/commons/{check-loops.js → pagination/check-loops.js} +3 -5
  69. package/esm/use-lunatic/commons/pagination/check-loops.js.map +1 -0
  70. package/{use-lunatic/commons → esm/use-lunatic/commons/pagination}/check-pager.d.ts +1 -1
  71. package/esm/use-lunatic/commons/pagination/check-pager.js.map +1 -0
  72. package/{use-lunatic/commons → esm/use-lunatic/commons/pagination}/create-map-pages.d.ts +1 -1
  73. package/esm/use-lunatic/commons/pagination/create-map-pages.js.map +1 -0
  74. package/esm/use-lunatic/commons/{is-First-last-page.d.ts → pagination/is-First-last-page.d.ts} +1 -1
  75. package/esm/use-lunatic/commons/pagination/is-First-last-page.js.map +1 -0
  76. package/{use-lunatic/commons → esm/use-lunatic/commons/pagination}/is-paginated-loop.d.ts +1 -1
  77. package/esm/use-lunatic/commons/pagination/is-paginated-loop.js.map +1 -0
  78. package/esm/use-lunatic/commons/{is-roundabout.d.ts → pagination/is-roundabout.d.ts} +1 -1
  79. package/esm/use-lunatic/commons/pagination/is-roundabout.js.map +1 -0
  80. package/esm/use-lunatic/commons/{page-navigation.d.ts → pagination/page-navigation.d.ts} +2 -2
  81. package/esm/use-lunatic/commons/{page-navigation.js → pagination/page-navigation.js} +6 -6
  82. package/esm/use-lunatic/commons/pagination/page-navigation.js.map +1 -0
  83. package/esm/use-lunatic/commons/pagination/page-navigation.spec.js.map +1 -0
  84. package/esm/use-lunatic/commons/{page-tag.d.ts → pagination/page-tag.d.ts} +8 -1
  85. package/esm/use-lunatic/commons/{page-tag.js → pagination/page-tag.js} +17 -6
  86. package/esm/use-lunatic/commons/pagination/page-tag.js.map +1 -0
  87. package/esm/use-lunatic/commons/{page-tag.spec.js → pagination/page-tag.spec.js} +9 -1
  88. package/esm/use-lunatic/commons/pagination/page-tag.spec.js.map +1 -0
  89. package/{use-lunatic/commons → esm/use-lunatic/commons/pagination}/page.d.ts +1 -1
  90. package/esm/use-lunatic/commons/{page.js → pagination/page.js} +2 -2
  91. package/esm/use-lunatic/commons/pagination/page.js.map +1 -0
  92. package/esm/use-lunatic/hooks/use-page-has-response.js +37 -21
  93. package/esm/use-lunatic/hooks/use-page-has-response.js.map +1 -1
  94. package/esm/use-lunatic/hooks/useOverview.js +2 -2
  95. package/esm/use-lunatic/hooks/useOverview.js.map +1 -1
  96. package/esm/use-lunatic/props/getComponentTypeProps.d.ts +28 -26
  97. package/esm/use-lunatic/props/getComponentTypeProps.js +3 -1
  98. package/esm/use-lunatic/props/getComponentTypeProps.js.map +1 -1
  99. package/esm/use-lunatic/props/propOptions.d.ts +9 -1
  100. package/esm/use-lunatic/props/propOptions.js +56 -1
  101. package/esm/use-lunatic/props/propOptions.js.map +1 -1
  102. package/esm/use-lunatic/props/propOptions.spec.js +220 -56
  103. package/esm/use-lunatic/props/propOptions.spec.js.map +1 -1
  104. package/esm/use-lunatic/reducer/commons/auto-explore-loop.js +3 -2
  105. package/esm/use-lunatic/reducer/commons/auto-explore-loop.js.map +1 -1
  106. package/esm/use-lunatic/reducer/overview/overviewOnInit.d.ts +1 -2
  107. package/esm/use-lunatic/reducer/overview/overviewOnInit.js +1 -1
  108. package/esm/use-lunatic/reducer/overview/overviewOnInit.js.map +1 -1
  109. package/esm/use-lunatic/reducer/reduce-go-next-page.js +4 -3
  110. package/esm/use-lunatic/reducer/reduce-go-next-page.js.map +1 -1
  111. package/esm/use-lunatic/reducer/reduce-go-previous-page.js +2 -2
  112. package/esm/use-lunatic/reducer/reduce-go-previous-page.js.map +1 -1
  113. package/esm/use-lunatic/reducer/reduce-go-to-page.js +2 -2
  114. package/esm/use-lunatic/reducer/reduce-go-to-page.js.map +1 -1
  115. package/esm/use-lunatic/reducer/reducerInitializer.js +2 -2
  116. package/esm/use-lunatic/reducer/reducerInitializer.js.map +1 -1
  117. package/esm/use-lunatic/type.d.ts +1 -1
  118. package/esm/utils/cast.js +5 -2
  119. package/esm/utils/cast.js.map +1 -1
  120. package/esm/utils/getArticulationState.js +2 -1
  121. package/esm/utils/getArticulationState.js.map +1 -1
  122. package/esm/utils/number.js +4 -4
  123. package/esm/utils/number.js.map +1 -1
  124. package/index.d.ts +1 -1
  125. package/index.js.map +1 -1
  126. package/package.json +98 -79
  127. package/src/components/Datepicker/DatepickerFields.tsx +4 -2
  128. package/src/components/Duration/getDurationFromValue.ts +3 -3
  129. package/src/components/LunaticComponents.tsx +32 -25
  130. package/src/components/PairwiseLinks/PairwiseLinks.tsx +18 -57
  131. package/src/components/PairwiseLinks/PairwiseMirror.tsx +19 -0
  132. package/src/components/PairwiseLinks/combinations.test.ts +103 -0
  133. package/src/components/PairwiseLinks/combinations.ts +34 -0
  134. package/src/components/type.ts +204 -231
  135. package/src/index.ts +1 -4
  136. package/src/stories/checkbox/checkbox.stories.tsx +13 -0
  137. package/src/stories/checkbox/sourceOneDynamicOptions.json +496 -0
  138. package/src/stories/dropdown/dropdown.stories.tsx +12 -0
  139. package/src/stories/dropdown/sourceDynamicOptions.json +496 -0
  140. package/src/stories/pairwise/pairwise.stories.tsx +17 -1
  141. package/src/stories/pairwise/sourcePairwiseLoop.json +356 -0
  142. package/src/stories/radio/radio.stories.tsx +13 -0
  143. package/src/stories/radio/sourceDynamicOptions.json +496 -0
  144. package/src/type.source.ts +45 -14
  145. package/src/use-lunatic/commons/compile-controls.ts +1 -1
  146. package/src/use-lunatic/commons/component.ts +7 -2
  147. package/src/use-lunatic/commons/fill-components/fill-component-expressions.ts +3 -46
  148. package/src/use-lunatic/commons/fill-components/fill-components.ts +9 -10
  149. package/src/use-lunatic/commons/index.ts +8 -4
  150. package/src/use-lunatic/commons/{check-loops.ts → pagination/check-loops.ts} +4 -10
  151. package/src/use-lunatic/commons/{check-pager.ts → pagination/check-pager.ts} +1 -1
  152. package/src/use-lunatic/commons/{create-map-pages.ts → pagination/create-map-pages.ts} +2 -2
  153. package/src/use-lunatic/commons/{is-First-last-page.ts → pagination/is-First-last-page.ts} +1 -1
  154. package/src/use-lunatic/commons/{is-paginated-loop.ts → pagination/is-paginated-loop.ts} +1 -1
  155. package/src/use-lunatic/commons/{is-roundabout.ts → pagination/is-roundabout.ts} +1 -1
  156. package/src/use-lunatic/commons/{page-navigation.spec.ts → pagination/page-navigation.spec.ts} +1 -1
  157. package/src/use-lunatic/commons/{page-navigation.ts → pagination/page-navigation.ts} +8 -8
  158. package/src/use-lunatic/commons/{page-tag.spec.ts → pagination/page-tag.spec.ts} +15 -2
  159. package/src/use-lunatic/commons/{page-tag.ts → pagination/page-tag.ts} +18 -7
  160. package/src/use-lunatic/commons/{page.ts → pagination/page.ts} +6 -3
  161. package/src/use-lunatic/hooks/use-page-has-response.ts +59 -28
  162. package/src/use-lunatic/hooks/useOverview.ts +6 -3
  163. package/src/use-lunatic/props/getComponentTypeProps.ts +2 -1
  164. package/src/use-lunatic/props/propOptions.spec.ts +217 -147
  165. package/src/use-lunatic/props/propOptions.ts +99 -10
  166. package/src/use-lunatic/reducer/commons/auto-explore-loop.ts +3 -2
  167. package/src/use-lunatic/reducer/overview/overviewOnInit.ts +2 -2
  168. package/src/use-lunatic/reducer/reduce-go-next-page.ts +4 -3
  169. package/src/use-lunatic/reducer/reduce-go-previous-page.ts +2 -2
  170. package/src/use-lunatic/reducer/reduce-go-to-page.ts +2 -2
  171. package/src/use-lunatic/reducer/reducerInitializer.tsx +2 -2
  172. package/src/use-lunatic/type.ts +1 -1
  173. package/src/utils/cast.ts +5 -2
  174. package/src/utils/getArticulationState.ts +2 -1
  175. package/src/utils/number.ts +4 -4
  176. package/tsconfig.build.tsbuildinfo +1 -1
  177. package/type.source.d.ts +43 -13
  178. package/type.source.js +0 -1
  179. package/type.source.js.map +1 -1
  180. package/use-lunatic/commons/compile-controls.js +1 -1
  181. package/use-lunatic/commons/compile-controls.js.map +1 -1
  182. package/use-lunatic/commons/component.d.ts +3 -2
  183. package/use-lunatic/commons/component.js +5 -0
  184. package/use-lunatic/commons/component.js.map +1 -1
  185. package/use-lunatic/commons/fill-components/fill-component-expressions.d.ts +1 -1
  186. package/use-lunatic/commons/fill-components/fill-component-expressions.js +12 -53
  187. package/use-lunatic/commons/fill-components/fill-component-expressions.js.map +1 -1
  188. package/use-lunatic/commons/fill-components/fill-components.js +9 -1
  189. package/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
  190. package/use-lunatic/commons/index.d.ts +4 -4
  191. package/use-lunatic/commons/index.js +4 -4
  192. package/use-lunatic/commons/index.js.map +1 -1
  193. package/use-lunatic/commons/{check-loops.d.ts → pagination/check-loops.d.ts} +7 -7
  194. package/use-lunatic/commons/{check-loops.js → pagination/check-loops.js} +3 -5
  195. package/use-lunatic/commons/pagination/check-loops.js.map +1 -0
  196. package/{esm/use-lunatic/commons → use-lunatic/commons/pagination}/check-pager.d.ts +1 -1
  197. package/use-lunatic/commons/pagination/check-pager.js.map +1 -0
  198. package/{esm/use-lunatic/commons → use-lunatic/commons/pagination}/create-map-pages.d.ts +1 -1
  199. package/use-lunatic/commons/pagination/create-map-pages.js.map +1 -0
  200. package/use-lunatic/commons/{is-First-last-page.d.ts → pagination/is-First-last-page.d.ts} +1 -1
  201. package/use-lunatic/commons/pagination/is-First-last-page.js.map +1 -0
  202. package/{esm/use-lunatic/commons → use-lunatic/commons/pagination}/is-paginated-loop.d.ts +1 -1
  203. package/use-lunatic/commons/pagination/is-paginated-loop.js.map +1 -0
  204. package/use-lunatic/commons/{is-roundabout.d.ts → pagination/is-roundabout.d.ts} +1 -1
  205. package/use-lunatic/commons/pagination/is-roundabout.js.map +1 -0
  206. package/use-lunatic/commons/{page-navigation.d.ts → pagination/page-navigation.d.ts} +2 -2
  207. package/use-lunatic/commons/{page-navigation.js → pagination/page-navigation.js} +6 -6
  208. package/use-lunatic/commons/pagination/page-navigation.js.map +1 -0
  209. package/use-lunatic/commons/pagination/page-navigation.spec.js.map +1 -0
  210. package/use-lunatic/commons/{page-tag.d.ts → pagination/page-tag.d.ts} +8 -1
  211. package/use-lunatic/commons/{page-tag.js → pagination/page-tag.js} +18 -6
  212. package/use-lunatic/commons/pagination/page-tag.js.map +1 -0
  213. package/use-lunatic/commons/{page-tag.spec.js → pagination/page-tag.spec.js} +8 -0
  214. package/use-lunatic/commons/pagination/page-tag.spec.js.map +1 -0
  215. package/{esm/use-lunatic/commons → use-lunatic/commons/pagination}/page.d.ts +1 -1
  216. package/use-lunatic/commons/{page.js → pagination/page.js} +2 -2
  217. package/use-lunatic/commons/pagination/page.js.map +1 -0
  218. package/use-lunatic/hooks/use-page-has-response.js +36 -21
  219. package/use-lunatic/hooks/use-page-has-response.js.map +1 -1
  220. package/use-lunatic/hooks/useOverview.js +2 -2
  221. package/use-lunatic/hooks/useOverview.js.map +1 -1
  222. package/use-lunatic/props/getComponentTypeProps.d.ts +28 -26
  223. package/use-lunatic/props/getComponentTypeProps.js +2 -1
  224. package/use-lunatic/props/getComponentTypeProps.js.map +1 -1
  225. package/use-lunatic/props/propOptions.d.ts +9 -1
  226. package/use-lunatic/props/propOptions.js +57 -2
  227. package/use-lunatic/props/propOptions.js.map +1 -1
  228. package/use-lunatic/props/propOptions.spec.js +217 -55
  229. package/use-lunatic/props/propOptions.spec.js.map +1 -1
  230. package/use-lunatic/reducer/commons/auto-explore-loop.js +6 -2
  231. package/use-lunatic/reducer/commons/auto-explore-loop.js.map +1 -1
  232. package/use-lunatic/reducer/overview/overviewOnInit.d.ts +1 -2
  233. package/use-lunatic/reducer/overview/overviewOnInit.js +1 -1
  234. package/use-lunatic/reducer/overview/overviewOnInit.js.map +1 -1
  235. package/use-lunatic/reducer/reduce-go-next-page.js +4 -3
  236. package/use-lunatic/reducer/reduce-go-next-page.js.map +1 -1
  237. package/use-lunatic/reducer/reduce-go-previous-page.js +2 -2
  238. package/use-lunatic/reducer/reduce-go-previous-page.js.map +1 -1
  239. package/use-lunatic/reducer/reduce-go-to-page.js +2 -2
  240. package/use-lunatic/reducer/reduce-go-to-page.js.map +1 -1
  241. package/use-lunatic/reducer/reducerInitializer.js +2 -2
  242. package/use-lunatic/reducer/reducerInitializer.js.map +1 -1
  243. package/use-lunatic/type.d.ts +1 -1
  244. package/utils/cast.js +5 -2
  245. package/utils/cast.js.map +1 -1
  246. package/utils/getArticulationState.js +2 -1
  247. package/utils/getArticulationState.js.map +1 -1
  248. package/utils/number.js +4 -4
  249. package/utils/number.js.map +1 -1
  250. package/esm/use-lunatic/commons/check-loops.js.map +0 -1
  251. package/esm/use-lunatic/commons/check-pager.js.map +0 -1
  252. package/esm/use-lunatic/commons/create-map-pages.js.map +0 -1
  253. package/esm/use-lunatic/commons/is-First-last-page.js.map +0 -1
  254. package/esm/use-lunatic/commons/is-paginated-loop.js.map +0 -1
  255. package/esm/use-lunatic/commons/is-roundabout.js.map +0 -1
  256. package/esm/use-lunatic/commons/page-navigation.js.map +0 -1
  257. package/esm/use-lunatic/commons/page-navigation.spec.js.map +0 -1
  258. package/esm/use-lunatic/commons/page-tag.js.map +0 -1
  259. package/esm/use-lunatic/commons/page-tag.spec.js.map +0 -1
  260. package/esm/use-lunatic/commons/page.js.map +0 -1
  261. package/use-lunatic/commons/check-loops.js.map +0 -1
  262. package/use-lunatic/commons/check-pager.js.map +0 -1
  263. package/use-lunatic/commons/create-map-pages.js.map +0 -1
  264. package/use-lunatic/commons/is-First-last-page.js.map +0 -1
  265. package/use-lunatic/commons/is-paginated-loop.js.map +0 -1
  266. package/use-lunatic/commons/is-roundabout.js.map +0 -1
  267. package/use-lunatic/commons/page-navigation.js.map +0 -1
  268. package/use-lunatic/commons/page-navigation.spec.js.map +0 -1
  269. package/use-lunatic/commons/page-tag.js.map +0 -1
  270. package/use-lunatic/commons/page-tag.spec.js.map +0 -1
  271. package/use-lunatic/commons/page.js.map +0 -1
  272. /package/esm/use-lunatic/commons/{check-pager.js → pagination/check-pager.js} +0 -0
  273. /package/esm/use-lunatic/commons/{create-map-pages.js → pagination/create-map-pages.js} +0 -0
  274. /package/esm/use-lunatic/commons/{is-First-last-page.js → pagination/is-First-last-page.js} +0 -0
  275. /package/esm/use-lunatic/commons/{is-paginated-loop.js → pagination/is-paginated-loop.js} +0 -0
  276. /package/esm/use-lunatic/commons/{is-roundabout.js → pagination/is-roundabout.js} +0 -0
  277. /package/esm/use-lunatic/commons/{page-navigation.spec.d.ts → pagination/page-navigation.spec.d.ts} +0 -0
  278. /package/esm/use-lunatic/commons/{page-navigation.spec.js → pagination/page-navigation.spec.js} +0 -0
  279. /package/esm/use-lunatic/commons/{page-tag.spec.d.ts → pagination/page-tag.spec.d.ts} +0 -0
  280. /package/use-lunatic/commons/{check-pager.js → pagination/check-pager.js} +0 -0
  281. /package/use-lunatic/commons/{create-map-pages.js → pagination/create-map-pages.js} +0 -0
  282. /package/use-lunatic/commons/{is-First-last-page.js → pagination/is-First-last-page.js} +0 -0
  283. /package/use-lunatic/commons/{is-paginated-loop.js → pagination/is-paginated-loop.js} +0 -0
  284. /package/use-lunatic/commons/{is-roundabout.js → pagination/is-roundabout.js} +0 -0
  285. /package/use-lunatic/commons/{page-navigation.spec.d.ts → pagination/page-navigation.spec.d.ts} +0 -0
  286. /package/use-lunatic/commons/{page-navigation.spec.js → pagination/page-navigation.spec.js} +0 -0
  287. /package/use-lunatic/commons/{page-tag.spec.d.ts → pagination/page-tag.spec.d.ts} +0 -0
@@ -5,6 +5,7 @@ import type {
5
5
  LunaticReducerState,
6
6
  } from '../../type';
7
7
  import { isObject } from '../../../utils/object';
8
+ import { castBool, castNumber, castString } from '../../../utils/cast';
8
9
 
9
10
  const VTL_ATTRIBUTES = [
10
11
  ['label', null],
@@ -37,51 +38,6 @@ const VTL_ATTRIBUTES = [
37
38
  // List of property that can be simple string instead of expressions
38
39
  const allowString = new Set(['unit']);
39
40
 
40
- function castNumber(v: unknown): number {
41
- if (typeof v === 'number') {
42
- return v;
43
- }
44
- if (typeof v === 'string') {
45
- return parseInt(v, 10);
46
- }
47
- if (Array.isArray(v) && v.length > 0) {
48
- return castNumber(v[0]);
49
- }
50
- if (v === null) {
51
- return 0;
52
- }
53
- throw new Error(`Cannot cast "${v}" to number`);
54
- }
55
-
56
- function castBool(v: unknown): boolean {
57
- if (typeof v === 'boolean') {
58
- return v;
59
- }
60
- if (Array.isArray(v) && v.length > 0) {
61
- return castBool(v[0]);
62
- }
63
- if (Array.isArray(v)) {
64
- return false;
65
- }
66
- return Boolean(v);
67
- }
68
-
69
- function castString(v: unknown): string {
70
- if (typeof v === 'string') {
71
- return v;
72
- }
73
- if (typeof v === 'number') {
74
- return v.toString();
75
- }
76
- if (Array.isArray(v)) {
77
- return v.map(castString).join(', ');
78
- }
79
- if (!v) {
80
- return '';
81
- }
82
- return v.toString();
83
- }
84
-
85
41
  // Utility type to replace all expression from an object into a translated version
86
42
  type UntranslatedProperties =
87
43
  | 'expressions'
@@ -91,7 +47,8 @@ type UntranslatedProperties =
91
47
  | 'controls'
92
48
  | 'conditionFilter'
93
49
  | 'conditionReadOnly'
94
- | 'components';
50
+ | 'components'
51
+ | 'optionFilter';
95
52
  export type DeepTranslateExpression<T> = T extends LunaticExpression
96
53
  ? ReactNode
97
54
  : T extends (infer ElementType)[]
@@ -11,7 +11,7 @@ import type { LunaticComponentProps } from '../../../components/type';
11
11
  import { getMissingResponseProp } from '../../props/propMissingResponse';
12
12
  import { getValueProp } from '../../props/propValue';
13
13
  import { getIterationsProp } from '../../props/propIterations';
14
- import { getOptionsProp } from '../../props/propOptions';
14
+ import { computeOptionsFromComponent } from '../../props/propOptions';
15
15
  import { LunaticLogger } from '../../logger/type';
16
16
  import { VTLScalarExpression } from '../../../type.source';
17
17
 
@@ -80,16 +80,15 @@ export const fillComponent = (
80
80
  missingResponse: getMissingResponseProp(component, state),
81
81
  management: state.management,
82
82
  iterations: getIterationsProp(component, state),
83
- options: getOptionsProp(
84
- interpretedProps,
85
- state.variables,
86
- state.handleChanges,
87
- state.pager.iteration,
83
+ options: computeOptionsFromComponent(interpretedProps, {
84
+ variables: state.variables,
85
+ handleChanges: state.handleChanges,
86
+ pagerIteration: state.pager.iteration,
88
87
  value,
89
- state.logger,
90
- state.disableFilters,
91
- shouldBeFiltered
92
- ),
88
+ logger: state.logger,
89
+ disableFilters: state.disableFilters,
90
+ shouldParentBeFiltered: shouldBeFiltered,
91
+ }),
93
92
  ...getComponentTypeProps(interpretedProps, state),
94
93
  // This is too dynamic to be typed correctly, so we allow any here
95
94
  } as any;
@@ -1,6 +1,10 @@
1
- export { default as checkLoops } from './check-loops';
2
- export { default as createMapPages } from './create-map-pages';
1
+ export { default as checkLoops } from './pagination/check-loops';
2
+ export { default as createMapPages } from './pagination/create-map-pages';
3
3
  export { default as executeConditionFilter } from './execute-condition-filter';
4
4
  export { default as getCompatibleVTLExpression } from './get-compatible-vtl-expression';
5
- export { default as isFirstLastPage } from './is-First-last-page';
6
- export { getNewReachedPage, getPageTag, isNewReachedPage } from './page-tag';
5
+ export { default as isFirstLastPage } from './pagination/is-First-last-page';
6
+ export {
7
+ getNewReachedPage,
8
+ getPageTag,
9
+ isNewReachedPage,
10
+ } from './pagination/page-tag';
@@ -4,7 +4,7 @@ import type {
4
4
  LunaticComponentDefinition,
5
5
  LunaticExpression,
6
6
  LunaticReducerState,
7
- } from '../type';
7
+ } from '../../type';
8
8
 
9
9
  /**
10
10
  * Extract the list of subpages linked to a component
@@ -22,7 +22,7 @@ function extractSubPages(
22
22
  (pages, component) => {
23
23
  const { page } = component;
24
24
 
25
- if (page && pages.indexOf(page) === -1) {
25
+ if (page && !pages.includes(page)) {
26
26
  return [...pages, page];
27
27
  }
28
28
  return pages;
@@ -33,35 +33,29 @@ function extractSubPages(
33
33
 
34
34
  function extractLoop(components: LunaticComponentDefinition[] = []) {
35
35
  return components.reduce(
36
- function (
37
- { isLoop, subPages, iterations, loopDependencies, roundabout },
38
- component
39
- ) {
36
+ function ({ isLoop, subPages, iterations, loopDependencies }, component) {
40
37
  const currentIsLoop = isPaginatedLoop(component);
41
38
  const currentIsRoundabout = isRoundabout(component);
42
39
  if (currentIsLoop || currentIsRoundabout) {
43
40
  return {
44
41
  isLoop: isLoop || currentIsLoop,
45
- roundabout: roundabout || currentIsRoundabout,
46
42
  subPages: extractSubPages(component, subPages),
47
43
  iterations: iterations || component.iterations,
48
44
  loopDependencies: loopDependencies || undefined,
49
45
  };
50
46
  }
51
- return { isLoop, subPages, iterations, roundabout };
47
+ return { isLoop, subPages, iterations };
52
48
  },
53
49
  {
54
50
  isLoop: false,
55
51
  subPages: undefined,
56
52
  iterations: undefined,
57
53
  loopDependencies: undefined,
58
- roundabout: undefined,
59
54
  } as {
60
55
  isLoop: boolean;
61
56
  iterations?: LunaticExpression;
62
57
  loopDependencies?: string[];
63
58
  subPages?: string[];
64
- roundabout?: boolean;
65
59
  }
66
60
  );
67
61
  }
@@ -1,4 +1,4 @@
1
- import type { LunaticReducerState } from '../type';
1
+ import type { LunaticReducerState } from '../../type';
2
2
 
3
3
  /**
4
4
  * Reset the pager at his initial state
@@ -1,7 +1,7 @@
1
1
  import isPaginatedLoop from './is-paginated-loop';
2
2
  import isRoundabout from './is-roundabout';
3
- import type { LunaticReducerState, LunaticSource } from '../type';
4
- import type { ItemOf } from '../../type.utils';
3
+ import type { LunaticReducerState, LunaticSource } from '../../type';
4
+ import type { ItemOf } from '../../../type.utils';
5
5
 
6
6
  function isUnpaginated(questionnaire: { maxPage?: unknown }): boolean {
7
7
  const { maxPage } = questionnaire;
@@ -1,4 +1,4 @@
1
- import type { LunaticReducerState } from '../type';
1
+ import type { LunaticReducerState } from '../../type';
2
2
 
3
3
  function isFirstLastPage(pager: LunaticReducerState['pager']) {
4
4
  const { page, maxPage } = pager;
@@ -1,4 +1,4 @@
1
- import type { LunaticComponentDefinition } from '../type';
1
+ import type { LunaticComponentDefinition } from '../../type';
2
2
 
3
3
  function isPaginatedLoop(
4
4
  component: LunaticComponentDefinition
@@ -1,4 +1,4 @@
1
- import type { LunaticComponentDefinition } from '../type';
1
+ import type { LunaticComponentDefinition } from '../../type';
2
2
 
3
3
  export default function isRoundabout(
4
4
  component: LunaticComponentDefinition
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
  import { getNextPager, getPrevPager } from './page-navigation';
3
- import type { LunaticReducerState } from '../type';
3
+ import type { LunaticReducerState } from '../../type';
4
4
 
5
5
  describe('page-navigation', () => {
6
6
  describe('getNextPager', () => {
@@ -1,5 +1,5 @@
1
- import type { LunaticReducerState } from '../type';
2
- import type { LunaticComponentType } from '../../components/type';
1
+ import type { LunaticReducerState } from '../../type';
2
+ import type { LunaticComponentType } from '../../../components/type';
3
3
 
4
4
  const resetIteration = {
5
5
  subPage: undefined,
@@ -18,9 +18,9 @@ export function getNextPager(
18
18
  // Increment the page or subPage
19
19
  // eslint-disable-next-line prefer-const
20
20
  let [page, subPage] =
21
- pager.subPage !== undefined
22
- ? [pager.page, pager.subPage + 1]
23
- : [pager.page + 1, undefined];
21
+ pager.subPage === undefined
22
+ ? [pager.page + 1, undefined]
23
+ : [pager.page, pager.subPage + 1];
24
24
  let iteration = pager.iteration;
25
25
 
26
26
  // We reached the end of the questionnaire
@@ -77,9 +77,9 @@ export function getPrevPager(
77
77
  // Decrement the page or subPage
78
78
  // eslint-disable-next-line prefer-const
79
79
  let [page, subPage] =
80
- pager.subPage !== undefined
81
- ? [pager.page, pager.subPage - 1]
82
- : [pager.page - 1, undefined];
80
+ pager.subPage === undefined
81
+ ? [pager.page - 1, undefined]
82
+ : [pager.page, pager.subPage - 1];
83
83
  let iteration = pager.iteration;
84
84
  const moveUpOnStart =
85
85
  parent === 'Roundabout' && pager.nbIterations && pager.nbIterations > 1;
@@ -1,6 +1,10 @@
1
1
  import { describe, it, expect } from 'vitest';
2
- import { getPagerFromPageTag, pageTagComparator } from './page-tag';
3
- import type { PageTag } from '../type';
2
+ import {
3
+ addIterationToPage,
4
+ getPagerFromPageTag,
5
+ pageTagComparator,
6
+ } from './page-tag';
7
+ import type { PageTag } from '../../type';
4
8
 
5
9
  describe('page-tag', () => {
6
10
  describe('getPagerFromPageTag', () => {
@@ -18,6 +22,15 @@ describe('page-tag', () => {
18
22
  });
19
23
  });
20
24
 
25
+ describe('addIterationToPage', () => {
26
+ it('should add itereation to simple page', () => {
27
+ expect(addIterationToPage('2', 0)).toEqual('2#1');
28
+ expect(addIterationToPage('2.1', 0)).toEqual('2.1#1');
29
+ expect(addIterationToPage('2', 1)).toEqual('2#2');
30
+ expect(addIterationToPage('2.1', 1)).toEqual('2.1#2');
31
+ });
32
+ });
33
+
21
34
  it.each([
22
35
  ['4.1', '4.2', -1],
23
36
  ['4.2#1', '4.2#1', 0],
@@ -1,4 +1,15 @@
1
- import type { LunaticReducerState, PageTag } from '../type';
1
+ import type { LunaticReducerState, PageTag } from '../../type';
2
+
3
+ /**
4
+ * Add iteration to existing pageTag (with subpage, use for overview)
5
+ * @param pageTag
6
+ * @param iteration
7
+ * @returns
8
+ */
9
+ export function addIterationToPage(page: string, iteration?: number): PageTag {
10
+ if (iteration === undefined) return page as PageTag;
11
+ return `${page}#${iteration + 1}` as PageTag;
12
+ }
2
13
 
3
14
  /**
4
15
  * Generate page name from the pager
@@ -38,12 +49,12 @@ export function getPagerFromPageTag(pageTag: string | number = 1) {
38
49
  },
39
50
  ] = match;
40
51
  if (!subPagePlusUn) {
41
- return { page: parseInt(page, 10) };
52
+ return { page: Number.parseInt(page, 10) };
42
53
  }
43
54
  return {
44
- page: parseInt(page, 10),
45
- subPage: parseInt(subPagePlusUn, 10) - 1,
46
- iteration: parseInt(iterationPlusUn, 10) - 1,
55
+ page: Number.parseInt(page, 10),
56
+ subPage: Number.parseInt(subPagePlusUn, 10) - 1,
57
+ iteration: Number.parseInt(iterationPlusUn, 10) - 1,
47
58
  };
48
59
  }
49
60
 
@@ -66,8 +77,8 @@ export function getNewReachedPage(
66
77
  * - 0 if a is the same as b
67
78
  */
68
79
  export function pageTagComparator(a: PageTag, b: PageTag) {
69
- const pageA = a.split(/\D/).map((v) => parseInt(v, 10));
70
- const pageB = b.split(/\D/).map((v) => parseInt(v, 10));
80
+ const pageA = a.split(/\D/).map((v) => Number.parseInt(v, 10));
81
+ const pageB = b.split(/\D/).map((v) => Number.parseInt(v, 10));
71
82
  // [0, 2, 1] is used to extract the significant part of the pageTag part (start with page, then iteration, then subpage)
72
83
  for (const index of [0, 2, 1]) {
73
84
  if (pageA[index] !== pageB[index]) {
@@ -1,6 +1,9 @@
1
- import type { LunaticComponentDefinition, LunaticReducerState } from '../type';
2
- import { getComponentsFromState } from './get-components-from-state';
3
- import executeConditionFilter from './execute-condition-filter';
1
+ import type {
2
+ LunaticComponentDefinition,
3
+ LunaticReducerState,
4
+ } from '../../type';
5
+ import { getComponentsFromState } from '../get-components-from-state';
6
+ import executeConditionFilter from '../execute-condition-filter';
4
7
 
5
8
  export function getPageId({
6
9
  subPage,
@@ -15,6 +15,54 @@ export function usePageHasResponse(
15
15
  }, [components, executeExpression]);
16
16
  }
17
17
 
18
+ const hasMissingResponse = (component: LunaticComponentProps): boolean => {
19
+ if ('missingResponse' in component && component.missingResponse?.value)
20
+ return true;
21
+ return false;
22
+ };
23
+
24
+ const hasArbitraryValue = (component: LunaticComponentProps): boolean => {
25
+ if ('arbitraryValue' in component && component.arbitraryValue !== undefined)
26
+ return true;
27
+ return false;
28
+ };
29
+
30
+ const hasOneResponseInQuestion = (
31
+ component: LunaticComponentProps<'Question'>,
32
+ executeExpression: LunaticReducerState['executeExpression']
33
+ ): boolean => {
34
+ return (
35
+ 'components' in component &&
36
+ Array.isArray(component.components) &&
37
+ hasOneResponse(component.components, executeExpression)
38
+ );
39
+ };
40
+
41
+ // For Table, we have to extract components from its body and apply isSubComponentsEmpty function
42
+ const hasOneResponseInTable = (
43
+ component: LunaticComponentProps<'Table'>,
44
+ executeExpression: LunaticReducerState['executeExpression']
45
+ ): boolean => {
46
+ const childrenComponent = component.body.reduce((_, row) => {
47
+ const componentsInRow = row.filter(
48
+ (cell) => isObject(cell) && 'componentType' in cell
49
+ );
50
+ return [..._, ...componentsInRow];
51
+ }, [] as LunaticComponentProps[]);
52
+ return !isSubComponentsEmpty(childrenComponent, executeExpression);
53
+ };
54
+
55
+ const hasOneResponseInRosterForLoop = (
56
+ component: LunaticComponentProps<'RosterForLoop'>,
57
+ executeExpression: LunaticReducerState['executeExpression']
58
+ ): boolean => {
59
+ return (
60
+ 'components' in component &&
61
+ Array.isArray(component.components) &&
62
+ !isSubComponentsEmpty(component.components, executeExpression)
63
+ );
64
+ };
65
+
18
66
  function hasOneResponse(
19
67
  components: LunaticComponentProps[],
20
68
  executeExpression: LunaticReducerState['executeExpression']
@@ -35,29 +83,17 @@ function hasOneResponse(
35
83
  }
36
84
 
37
85
  // We have a missing response for this component
38
- if (
39
- 'missingResponse' in component &&
40
- component.missingResponse &&
41
- component.missingResponse.value
42
- ) {
43
- return true;
44
- }
86
+ if (hasMissingResponse(component)) return true;
45
87
 
46
88
  // We have an arbitrary response for this component
47
- if ('arbitraryValue' in component && component.arbitraryValue) {
48
- return true;
49
- }
89
+ if (hasArbitraryValue(component)) return true;
50
90
 
51
91
  // For Table, we have to extract components from its body and apply isSubComponentsEmpty function
52
- if (component.componentType === 'Table') {
53
- // Body is array for array (row), each "cell" could be an Label or Component, so we filter array.
54
- const childrenComponent = component.body.reduce((_, row) => {
55
- const componentsInRow = row.filter(
56
- (cell) => isObject(cell) && 'componentType' in cell
57
- );
58
- return [..._, ...componentsInRow];
59
- }, [] as LunaticComponentProps[]);
60
- return !isSubComponentsEmpty(childrenComponent, executeExpression);
92
+ if (
93
+ component.componentType === 'Table' &&
94
+ hasOneResponseInTable(component, executeExpression)
95
+ ) {
96
+ return true;
61
97
  }
62
98
 
63
99
  // We found a value in one of the root component. Used for Loop
@@ -68,19 +104,14 @@ function hasOneResponse(
68
104
  // For Question, we need to check subcomponents
69
105
  if (
70
106
  component.componentType === 'Question' &&
71
- 'components' in component &&
72
- Array.isArray(component.components) &&
73
- hasOneResponse(component.components, executeExpression)
74
- ) {
107
+ hasOneResponseInQuestion(component, executeExpression)
108
+ )
75
109
  return true;
76
- }
77
110
 
78
111
  // For rosterForLoop we need to inspect child components
79
112
  if (
80
113
  component.componentType === 'RosterForLoop' &&
81
- 'components' in component &&
82
- Array.isArray(component.components) &&
83
- !isSubComponentsEmpty(component.components, executeExpression)
114
+ hasOneResponseInRosterForLoop(component, executeExpression)
84
115
  ) {
85
116
  return true;
86
117
  }
@@ -99,7 +130,7 @@ function isEmpty(value: unknown): boolean {
99
130
  // Array is empty if all items are empty
100
131
  if (Array.isArray(value)) {
101
132
  // We find one value that is not empty
102
- return value.find((v) => !isEmpty(v)) === undefined;
133
+ return !value.some((v) => !isEmpty(v));
103
134
  }
104
135
  // For object inspect each values
105
136
  if (typeof value === 'object' && value !== null) {
@@ -5,7 +5,11 @@ import type {
5
5
  PageTag,
6
6
  } from '../type';
7
7
  import { type DependencyList, type ReactNode, useMemo } from 'react';
8
- import { getPageTag, pageTagComparator } from '../commons/page-tag';
8
+ import {
9
+ addIterationToPage,
10
+ getPageTag,
11
+ pageTagComparator,
12
+ } from '../commons/pagination/page-tag';
9
13
 
10
14
  export type InterpretedLunaticOverviewItem = {
11
15
  id: string;
@@ -126,8 +130,7 @@ const interpretOverviewItem = (
126
130
  }
127
131
 
128
132
  // Append the item to the list of items
129
- const page =
130
- `${item.pageTag}${iteration !== undefined ? `#${iteration + 1}` : ''}` as PageTag;
133
+ const page = addIterationToPage(item.pageTag, iteration);
131
134
 
132
135
  const reached =
133
136
  pageTagComparator(state.pager ? getPageTag(state.pager) : '-1', page) >= 0;
@@ -33,7 +33,7 @@ function getRoundaboutProps(
33
33
  }));
34
34
  return {
35
35
  items: items,
36
- page: parseInt(component.page ?? '1', 10),
36
+ page: Number.parseInt(component.page ?? '1', 10),
37
37
  };
38
38
  }
39
39
 
@@ -121,6 +121,7 @@ function getPairwiseProps(
121
121
  state: State
122
122
  ) {
123
123
  return {
124
+ size: state.pager.nbIterations ?? component.xAxisIterations,
124
125
  getComponents: (x: number, y: number) => {
125
126
  if (x === y) {
126
127
  return [];