@inseefr/lunatic 2.0.0-rc9 → 2.0.0-v2test

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 (731) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +25 -22
  3. package/lib/components/button/button.scss +24 -0
  4. package/lib/components/button/index.js +13 -0
  5. package/lib/components/button/lunatic-button.js +52 -0
  6. package/lib/components/checkbox/checkbox-boolean/checkbox-boolean.js +29 -0
  7. package/lib/components/checkbox/checkbox-boolean/index.js +13 -0
  8. package/lib/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.js +40 -0
  9. package/lib/components/checkbox/checkbox-group/checkbox-group.js +84 -0
  10. package/lib/components/checkbox/checkbox-group/checkbox.scss +4 -0
  11. package/lib/components/checkbox/checkbox-group/index.js +13 -0
  12. package/lib/components/checkbox/checkbox-group/lunatic-checkbox-group.js +35 -0
  13. package/lib/components/checkbox/checkbox-one/index.js +13 -0
  14. package/lib/components/checkbox/checkbox-one/lunatic-checkbox-one.js +27 -0
  15. package/lib/components/checkbox/commons/checkbox-option.js +55 -0
  16. package/lib/components/checkbox/commons/checkbox-option.scss +3 -0
  17. package/lib/components/checkbox/commons/index.js +13 -0
  18. package/lib/components/checkbox/index.js +27 -0
  19. package/lib/components/commons/build-style-object.js +25 -0
  20. package/lib/components/commons/components/combo-box/combo-box-container.js +31 -0
  21. package/lib/components/commons/components/combo-box/combo-box-content.js +60 -0
  22. package/lib/components/commons/components/combo-box/combo-box.js +190 -0
  23. package/lib/components/commons/components/combo-box/combo-box.scss +205 -0
  24. package/lib/components/commons/components/combo-box/index.js +13 -0
  25. package/lib/components/commons/components/combo-box/panel/index.js +13 -0
  26. package/lib/components/commons/components/combo-box/panel/option-container.js +62 -0
  27. package/lib/components/commons/components/combo-box/panel/panel-container.js +26 -0
  28. package/lib/components/commons/components/combo-box/panel/panel.js +61 -0
  29. package/lib/components/commons/components/combo-box/selection/delete.js +53 -0
  30. package/lib/components/commons/components/combo-box/selection/displayLabelOrInput.js +22 -0
  31. package/lib/components/commons/components/combo-box/selection/index.js +13 -0
  32. package/lib/components/commons/components/combo-box/selection/input.js +55 -0
  33. package/lib/components/commons/components/combo-box/selection/label-selection.js +32 -0
  34. package/lib/components/commons/components/combo-box/selection/selection-container.js +35 -0
  35. package/lib/components/commons/components/combo-box/selection/selection.js +61 -0
  36. package/lib/components/commons/components/combo-box/state-management/actions.js +82 -0
  37. package/lib/components/commons/components/combo-box/state-management/combo-box-context.js +16 -0
  38. package/lib/components/commons/components/combo-box/state-management/index.js +33 -0
  39. package/lib/components/commons/components/combo-box/state-management/initial-state.js +14 -0
  40. package/lib/components/commons/components/combo-box/state-management/reducer/index.js +13 -0
  41. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-blur.js +20 -0
  42. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-change.js +22 -0
  43. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-delete.js +21 -0
  44. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-focus.js +20 -0
  45. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-init.js +40 -0
  46. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-keydown/index.js +13 -0
  47. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-keydown/keyboard-key-codes.js +18 -0
  48. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-keydown/on-arrow-down.js +32 -0
  49. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-keydown/on-arrow-up.js +32 -0
  50. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-keydown/on-end.js +25 -0
  51. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-keydown/on-enter.js +21 -0
  52. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-keydown/on-escape.js +20 -0
  53. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-keydown/on-home.js +25 -0
  54. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-keydown/on-tab.js +20 -0
  55. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-keydown/reduce-on-keydown.js +40 -0
  56. package/lib/components/commons/components/combo-box/state-management/reducer/reduce-on-select.js +22 -0
  57. package/lib/components/commons/components/combo-box/state-management/reducer/reducer.js +41 -0
  58. package/lib/components/commons/components/create-lunatic-component/create-lunatic-component.js +64 -0
  59. package/lib/components/commons/components/create-lunatic-component/index.js +11 -0
  60. package/lib/components/commons/components/default-label-renderer.js +44 -0
  61. package/lib/components/commons/components/default-option-renderer.js +36 -0
  62. package/lib/components/commons/components/dragger/dragger.js +92 -0
  63. package/lib/components/commons/components/dragger/dragger.scss +8 -0
  64. package/lib/components/commons/components/dragger/index.js +13 -0
  65. package/lib/components/commons/components/errors/errors.js +41 -0
  66. package/lib/components/commons/components/errors/errors.scss +5 -0
  67. package/lib/components/commons/components/errors/index.js +13 -0
  68. package/lib/components/commons/components/fab/fab.js +48 -0
  69. package/lib/components/commons/components/fab/fab.scss +32 -0
  70. package/lib/components/commons/components/fab/index.js +13 -0
  71. package/lib/components/commons/components/field-container/field-container.js +39 -0
  72. package/lib/components/commons/components/field-container/field-container.scss +0 -0
  73. package/lib/components/commons/components/field-container/index.js +13 -0
  74. package/lib/components/commons/components/fieldset.js +18 -0
  75. package/lib/components/commons/components/fieldset.scss +5 -0
  76. package/lib/components/commons/components/html-table/index.js +48 -0
  77. package/lib/components/commons/components/html-table/table.js +29 -0
  78. package/lib/components/commons/components/html-table/tbody.js +29 -0
  79. package/lib/components/commons/components/html-table/td.js +41 -0
  80. package/lib/components/commons/components/html-table/th.js +39 -0
  81. package/lib/components/commons/components/html-table/thead.js +29 -0
  82. package/lib/components/commons/components/html-table/tr.js +31 -0
  83. package/lib/components/commons/components/is-network/index.js +13 -0
  84. package/lib/components/commons/components/is-network/is-network.js +51 -0
  85. package/lib/components/commons/components/is-network/use-online-status.js +46 -0
  86. package/lib/components/commons/components/label.js +27 -0
  87. package/lib/components/commons/components/lunatic-component.js +55 -0
  88. package/lib/components/commons/components/lunatic-fieldset-component.js +49 -0
  89. package/lib/components/commons/components/md-label/index.js +13 -0
  90. package/lib/components/commons/components/md-label/link.js +51 -0
  91. package/lib/components/commons/components/md-label/md-label.js +44 -0
  92. package/lib/components/commons/components/missing/index.js +13 -0
  93. package/lib/components/commons/components/missing/missing.js +76 -0
  94. package/lib/components/commons/components/missing/missing.scss +30 -0
  95. package/lib/components/commons/components/nothing-to-display.js +13 -0
  96. package/lib/components/commons/components/orchestrated-component.js +59 -0
  97. package/{src/components/tooltip → lib/components/commons/components/variable-status}/img/edited.png +0 -0
  98. package/{src/components/tooltip → lib/components/commons/components/variable-status}/img/forced.png +0 -0
  99. package/lib/components/commons/components/variable-status/img/index.js +20 -0
  100. package/lib/components/commons/components/variable-status/index.js +13 -0
  101. package/lib/components/commons/components/variable-status/variable-status.js +78 -0
  102. package/lib/components/commons/components/variable-status/variable-status.scss +39 -0
  103. package/lib/components/commons/create-customizable-field.js +26 -0
  104. package/lib/components/commons/create-row-orchestrator.js +53 -0
  105. package/lib/components/commons/icons/checkbox-checked.icon.js +36 -0
  106. package/lib/components/commons/icons/checkbox-unchecked.icon.js +36 -0
  107. package/lib/components/commons/icons/closed.icon.js +33 -0
  108. package/lib/components/commons/icons/cross.icon.js +33 -0
  109. package/lib/components/commons/icons/index.js +76 -0
  110. package/lib/components/commons/icons/load.icon.js +33 -0
  111. package/lib/components/commons/icons/lunatic-icon.js +19 -0
  112. package/lib/components/commons/icons/lunatic-icon.scss +3 -0
  113. package/lib/components/commons/icons/network.icon.js +33 -0
  114. package/lib/components/commons/icons/on-drag.icon.js +33 -0
  115. package/lib/components/commons/icons/opened.icon.js +33 -0
  116. package/lib/components/commons/icons/radio-checked.icon.js +36 -0
  117. package/lib/components/commons/icons/radio-unchecked.icon.js +36 -0
  118. package/lib/components/commons/index.js +138 -0
  119. package/lib/components/commons/prop-types/declarations.js +19 -0
  120. package/lib/components/commons/prop-types/index.js +41 -0
  121. package/lib/components/commons/prop-types/lines.js +13 -0
  122. package/lib/components/commons/prop-types/options.js +13 -0
  123. package/lib/components/commons/prop-types/response.js +13 -0
  124. package/lib/components/commons/prop-types/value-type.js +14 -0
  125. package/lib/components/commons/safety-label.js +26 -0
  126. package/lib/components/commons/use-document-add-event-listener.js +84 -0
  127. package/lib/components/commons/use-on-handle-change.js +19 -0
  128. package/lib/components/commons/use-options-keydown.js +24 -0
  129. package/lib/components/commons/use-previous.js +16 -0
  130. package/lib/components/components.js +163 -0
  131. package/lib/components/datepicker/datepicker.js +45 -0
  132. package/lib/components/datepicker/datepicker.scss +1 -0
  133. package/lib/components/datepicker/index.js +13 -0
  134. package/lib/components/datepicker/lunatic-datepicker.js +27 -0
  135. package/lib/components/declarations/declaration.js +19 -0
  136. package/lib/components/declarations/declarations-after-text.js +20 -0
  137. package/lib/components/declarations/declarations-before-text.js +20 -0
  138. package/lib/components/declarations/declarations-detachable.js +20 -0
  139. package/lib/components/declarations/declarations.js +51 -0
  140. package/lib/components/declarations/declarations.scss +36 -0
  141. package/lib/components/declarations/index.js +43 -0
  142. package/lib/components/dropdown/dropdown-simple/dropdown-simple.js +36 -0
  143. package/lib/components/dropdown/dropdown-simple/index.js +13 -0
  144. package/lib/components/dropdown/dropdown-simple/simple-label-renderer.js +43 -0
  145. package/lib/components/dropdown/dropdown-simple/simple-option-renderer.js +35 -0
  146. package/lib/components/dropdown/dropdown-writable/dropdown-writable.js +59 -0
  147. package/lib/components/dropdown/dropdown-writable/filter-tools/filter-options.js +36 -0
  148. package/lib/components/dropdown/dropdown-writable/filter-tools/letters-matching.js +29 -0
  149. package/lib/components/dropdown/dropdown-writable/filter-tools/match.js +22 -0
  150. package/lib/components/dropdown/dropdown-writable/filter-tools/prepare-prefix.js +13 -0
  151. package/lib/components/dropdown/dropdown-writable/index.js +13 -0
  152. package/lib/components/dropdown/dropdown-writable/writable-label-renderer.js +43 -0
  153. package/lib/components/dropdown/dropdown-writable/writable-option-renderer.js +136 -0
  154. package/lib/components/dropdown/dropdown.js +47 -0
  155. package/lib/components/dropdown/dropdown.scss +41 -0
  156. package/lib/components/dropdown/index.js +13 -0
  157. package/lib/components/dropdown/lunatic-dropdown.js +53 -0
  158. package/lib/components/filter-description/component.js +20 -0
  159. package/lib/components/filter-description/index.js +13 -0
  160. package/lib/components/index.js +28 -0
  161. package/lib/components/index.scss +136 -0
  162. package/lib/components/input/index.js +13 -0
  163. package/lib/components/input/input.js +49 -0
  164. package/lib/components/input/input.scss +32 -0
  165. package/lib/components/input/lunatic-input.js +30 -0
  166. package/lib/components/input-number/index.js +13 -0
  167. package/lib/components/input-number/input-number.js +51 -0
  168. package/lib/components/input-number/input-number.scss +7 -0
  169. package/lib/components/input-number/lunatic-input-number.js +26 -0
  170. package/lib/components/loop/block-for-loop/block-for-loop-ochestrator.js +12 -0
  171. package/lib/components/loop/block-for-loop/block-for-loop.js +140 -0
  172. package/lib/components/loop/block-for-loop/index.js +13 -0
  173. package/lib/components/loop/block-for-loop/row.js +68 -0
  174. package/lib/components/loop/commons/get-init-length.js +16 -0
  175. package/lib/components/loop/commons/handle-row-button.js +20 -0
  176. package/lib/components/loop/commons/index.js +20 -0
  177. package/lib/components/loop/commons/row-component.js +65 -0
  178. package/lib/components/loop/index.js +13 -0
  179. package/lib/components/loop/loop.js +84 -0
  180. package/lib/components/loop/roster-for-loop/body.js +57 -0
  181. package/lib/components/loop/roster-for-loop/header.js +35 -0
  182. package/lib/components/loop/roster-for-loop/index.js +13 -0
  183. package/lib/components/loop/roster-for-loop/roster-for-loop-orchestrator.js +12 -0
  184. package/lib/components/loop/roster-for-loop/roster-for-loop.js +124 -0
  185. package/lib/components/loop/roster-for-loop/roster-table.js +50 -0
  186. package/lib/components/loop/roster-for-loop/roster.scss +42 -0
  187. package/lib/components/loop/roster-for-loop/row.js +75 -0
  188. package/lib/components/modal-controls/close-or-skip.js +40 -0
  189. package/lib/components/modal-controls/index.js +13 -0
  190. package/lib/components/modal-controls/modal-container.js +19 -0
  191. package/lib/components/modal-controls/modal-controls.js +71 -0
  192. package/lib/components/modal-controls/modal-controls.scss +48 -0
  193. package/lib/components/pairwise-links/index.js +13 -0
  194. package/lib/components/pairwise-links/orchestrator.js +72 -0
  195. package/lib/components/pairwise-links/pairwise-links.js +68 -0
  196. package/lib/components/pairwise-links/row.js +80 -0
  197. package/lib/components/radio/index.js +13 -0
  198. package/lib/components/radio/lunatic-radio-group.js +37 -0
  199. package/lib/components/radio/radio-group.js +41 -0
  200. package/lib/components/radio/radio-option.js +80 -0
  201. package/lib/components/radio/radio.scss +66 -0
  202. package/lib/components/sequence/index.js +13 -0
  203. package/lib/components/sequence/sequence.js +33 -0
  204. package/lib/components/sequence/sequence.scss +10 -0
  205. package/lib/components/subsequence/index.js +13 -0
  206. package/lib/components/subsequence/subsequence.js +31 -0
  207. package/lib/components/suggester/check-store.js +115 -0
  208. package/lib/components/suggester/default-style.scss +125 -0
  209. package/lib/components/suggester/find-best-label/find-best-label.js +55 -0
  210. package/lib/components/suggester/find-best-label/index.js +13 -0
  211. package/lib/components/suggester/idb-suggester.js +75 -0
  212. package/lib/components/suggester/index.js +13 -0
  213. package/lib/components/suggester/lunatic-suggester.js +80 -0
  214. package/lib/components/suggester/searching/create-searching.js +75 -0
  215. package/lib/components/suggester/searching/index.js +13 -0
  216. package/lib/components/suggester/suggester.js +138 -0
  217. package/lib/components/suggester-loader-widget/index.js +13 -0
  218. package/lib/components/suggester-loader-widget/loader-row.js +123 -0
  219. package/lib/components/suggester-loader-widget/loader.js +139 -0
  220. package/lib/components/suggester-loader-widget/progress.js +38 -0
  221. package/lib/components/suggester-loader-widget/tools/action-tool.js +28 -0
  222. package/lib/components/suggester-loader-widget/tools/index.js +20 -0
  223. package/lib/components/suggester-loader-widget/tools/tools.js +16 -0
  224. package/lib/components/suggester-loader-widget/widget-container.js +39 -0
  225. package/lib/components/suggester-loader-widget/widget.js +140 -0
  226. package/lib/components/suggester-loader-widget/widget.scss +176 -0
  227. package/lib/components/switch/index.js +13 -0
  228. package/lib/components/switch/lunatic-switch.js +47 -0
  229. package/lib/components/switch/switch.js +78 -0
  230. package/lib/components/switch/switch.scss +47 -0
  231. package/lib/components/table/cell.js +88 -0
  232. package/lib/components/table/components/cell.js +88 -0
  233. package/lib/components/table/components/header.js +41 -0
  234. package/lib/components/table/components/row.js +41 -0
  235. package/lib/components/table/components/table.js +31 -0
  236. package/lib/components/table/components/table.scss +27 -0
  237. package/lib/components/table/index.js +13 -0
  238. package/lib/components/table/lunatic-table.js +77 -0
  239. package/lib/components/table/table-orchestrator.js +47 -0
  240. package/lib/components/textarea/index.js +13 -0
  241. package/lib/components/textarea/lunatic-textarea.js +39 -0
  242. package/lib/components/textarea/textarea.js +42 -0
  243. package/lib/components/textarea/textarea.scss +8 -0
  244. package/lib/constants/component-types.js +8 -0
  245. package/lib/constants/declarations.js +28 -0
  246. package/lib/constants/event-types.js +29 -0
  247. package/lib/constants/index.js +60 -0
  248. package/lib/constants/supported-preferences.js +13 -0
  249. package/lib/constants/value-types.js +16 -0
  250. package/lib/constants/variable-types.js +12 -0
  251. package/lib/i18n/build-dictionary.js +50 -0
  252. package/lib/i18n/dictionary.js +34 -0
  253. package/lib/i18n/index.js +13 -0
  254. package/lib/index.js +21 -4040
  255. package/lib/stories/Introduction.stories.mdx +114 -0
  256. package/lib/stories/checkboxBoolean/checkboxBoolean.stories.js +27 -0
  257. package/lib/stories/checkboxBoolean/source.json +36 -0
  258. package/lib/stories/checkboxOne/checkboxOne.stories.js +27 -0
  259. package/lib/stories/checkboxOne/source.json +36 -0
  260. package/lib/stories/custom-mui/checkbox-boolean-mui.js +31 -0
  261. package/lib/stories/custom-mui/checkbox-group-mui.js +66 -0
  262. package/lib/stories/custom-mui/checkbox-one-mui.js +13 -0
  263. package/lib/stories/custom-mui/index.js +111 -0
  264. package/lib/stories/custom-mui/input-mui.js +51 -0
  265. package/lib/stories/custom-mui/input-number-mui.js +39 -0
  266. package/lib/stories/custom-mui/radio-mui.js +59 -0
  267. package/lib/stories/custom-mui/suggester-mui/index.js +13 -0
  268. package/lib/stories/custom-mui/suggester-mui/suggester-mui.js +290 -0
  269. package/lib/stories/custom-mui/switch-mui.js +41 -0
  270. package/lib/stories/custom-mui/table-mui.js +25 -0
  271. package/lib/stories/custom-mui/tbody-mui.js +21 -0
  272. package/lib/stories/custom-mui/td-mui.js +23 -0
  273. package/lib/stories/custom-mui/textarea-mui.js +42 -0
  274. package/lib/stories/custom-mui/th-mui.js +22 -0
  275. package/lib/stories/custom-mui/thead-mui.js +21 -0
  276. package/lib/stories/custom-mui/tr-mui.js +31 -0
  277. package/lib/stories/date-picker/data.json +3 -0
  278. package/lib/stories/date-picker/datepicker.stories.js +31 -0
  279. package/lib/stories/date-picker/source.json +91 -0
  280. package/lib/stories/dropdown/data.json +16 -0
  281. package/lib/stories/dropdown/dropdown.stories.js +32 -0
  282. package/lib/stories/dropdown/source.json +122 -0
  283. package/lib/stories/filter-description/filter-description.stories.js +49 -0
  284. package/lib/stories/filter-description/source-options.json +81 -0
  285. package/lib/stories/filter-description/source.json +11 -0
  286. package/lib/stories/input/data.json +1 -0
  287. package/lib/stories/input/input.stories.js +29 -0
  288. package/lib/stories/input/source.json +28 -0
  289. package/lib/stories/input-number/input-number.stories.js +34 -0
  290. package/lib/stories/input-number/source-euros.json +38 -0
  291. package/lib/stories/input-number/source.json +37 -0
  292. package/lib/stories/pairwise/data.json +12 -0
  293. package/lib/stories/pairwise/links.json +270 -0
  294. package/lib/stories/pairwise/pairwise-links.stories.js +30 -0
  295. package/lib/stories/paste-questionnaire/source.json +6290 -0
  296. package/lib/stories/paste-questionnaire/test.stories.js +83 -0
  297. package/lib/stories/questionnaires/logement/data.json +2686 -0
  298. package/lib/stories/questionnaires/logement/logement.stories.js +75 -0
  299. package/lib/stories/questionnaires/logement/source-sequence.json +34181 -0
  300. package/lib/stories/questionnaires/logement/source-sum.json +34612 -0
  301. package/lib/stories/questionnaires/logement/source.json +34191 -0
  302. package/lib/stories/questionnaires/recensement/data.json +12 -0
  303. package/lib/stories/questionnaires/recensement/recensement.stories.js +58 -0
  304. package/lib/stories/questionnaires/recensement/source.json +15202 -0
  305. package/lib/stories/questionnaires/rp/data.json +5 -0
  306. package/lib/stories/questionnaires/rp/rp.stories.js +36 -0
  307. package/lib/stories/questionnaires/rp/source.json +262 -0
  308. package/lib/stories/questionnaires/simpsons/simpsons.stories.js +63 -0
  309. package/lib/stories/questionnaires/simpsons/source.json +6290 -0
  310. package/lib/stories/questionnaires-test/V2_DeclarationsSimples.json +848 -0
  311. package/lib/stories/questionnaires-test/V2_MinMaxSum_Boucles.json +509 -0
  312. package/lib/stories/questionnaires-test/V2_QuestSimple_Boucles.json +4091 -0
  313. package/lib/stories/questionnaires-test/V2_TCMRallyeGames.json +2892 -0
  314. package/lib/stories/questionnaires-test/controls/V2_ControlesNonNum_horsBoucle_PasPageFin.json +666 -0
  315. package/lib/stories/questionnaires-test/controls/V2_ControlesNum_horsBoucle_PasPageFin.json +1957 -0
  316. package/lib/stories/questionnaires-test/controls/V2_Controles_BouclesLiees2_PasPageFin.json +709 -0
  317. package/lib/stories/questionnaires-test/controls/V2_Controles_BouclesLiees_PasPageFin.json +533 -0
  318. package/lib/stories/questionnaires-test/controls/boucles-n.json +202 -0
  319. package/lib/stories/questionnaires-test/controls/controls.stories.js +96 -0
  320. package/lib/stories/questionnaires-test/test-dylan.json +558 -0
  321. package/lib/stories/questionnaires-test/test.stories.js +92 -0
  322. package/lib/stories/radio/radio.stories.js +27 -0
  323. package/lib/stories/radio/source.json +36 -0
  324. package/lib/stories/roster-for-loop/roster-for-loop.stories.js +34 -0
  325. package/lib/stories/roster-for-loop/source-with-header.json +127 -0
  326. package/lib/stories/roster-for-loop/source.json +114 -0
  327. package/lib/stories/suggester/source.json +234 -0
  328. package/lib/stories/suggester/suggester-workers.stories.js +201 -0
  329. package/lib/stories/suggester/suggester.stories.js +49 -0
  330. package/{src/stories/checkbox-one → lib/stories/switch}/README.md +31 -31
  331. package/lib/stories/switch/SwitchMaterialUI.js +41 -0
  332. package/{src/stories/checkbox-boolean/data.json → lib/stories/switch/data-forced.json} +48 -48
  333. package/lib/stories/switch/data.json +80 -0
  334. package/lib/stories/switch/switch.js +85 -0
  335. package/lib/stories/table/data-roster.json +1 -0
  336. package/lib/stories/table/data.json +1 -0
  337. package/{src/stories/table/data-roster.json → lib/stories/table/source-roster.json} +504 -461
  338. package/{src/stories/table/data-default.json → lib/stories/table/source.json} +19 -19
  339. package/lib/stories/table/table-dynamique.json +67 -0
  340. package/lib/stories/table/table.stories.js +57 -0
  341. package/lib/stories/utils/custom-lunatic.scss +28 -0
  342. package/lib/stories/utils/default-arg-types.js +22 -0
  343. package/lib/stories/utils/options.js +32 -0
  344. package/lib/stories/utils/orchestrator.js +165 -0
  345. package/lib/stories/utils/waiting/index.js +13 -0
  346. package/lib/stories/utils/waiting/preloader.svg +1 -0
  347. package/lib/stories/utils/waiting/waiting.js +30 -0
  348. package/lib/stories/utils/waiting/waiting.scss +21 -0
  349. package/lib/tests/sample.spec.js +7 -0
  350. package/lib/use-lunatic/actions.js +90 -0
  351. package/lib/use-lunatic/commons/calculated-variables.js +100 -0
  352. package/lib/use-lunatic/commons/check-loops.js +87 -0
  353. package/lib/use-lunatic/commons/compose.js +24 -0
  354. package/lib/use-lunatic/commons/create-map-pages.js +87 -0
  355. package/lib/use-lunatic/commons/execute-condition-filter.js +27 -0
  356. package/lib/use-lunatic/commons/execute-expression/create-execute-expression.js +265 -0
  357. package/lib/use-lunatic/commons/execute-expression/create-memoizer.js +57 -0
  358. package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.js +138 -0
  359. package/lib/use-lunatic/commons/execute-expression/execute-expression.js +87 -0
  360. package/lib/use-lunatic/commons/execute-expression/get-expressions-variables.js +37 -0
  361. package/lib/use-lunatic/commons/execute-expression/get-safety-expression.js +30 -0
  362. package/lib/use-lunatic/commons/execute-expression/index.js +13 -0
  363. package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +123 -0
  364. package/lib/use-lunatic/commons/fill-components/fill-component-value.js +22 -0
  365. package/lib/use-lunatic/commons/fill-components/fill-components.js +34 -0
  366. package/lib/use-lunatic/commons/fill-components/fill-errors.js +27 -0
  367. package/lib/use-lunatic/commons/fill-components/fill-from-state.js +24 -0
  368. package/lib/use-lunatic/commons/fill-components/fill-management.js +23 -0
  369. package/lib/use-lunatic/commons/fill-components/fill-missing-response.js +32 -0
  370. package/lib/use-lunatic/commons/fill-components/fill-pagination.js +21 -0
  371. package/lib/use-lunatic/commons/fill-components/index.js +13 -0
  372. package/lib/use-lunatic/commons/get-compatible-vtl-expression.js +25 -0
  373. package/lib/use-lunatic/commons/get-component-value/get-component-value.js +177 -0
  374. package/lib/use-lunatic/commons/get-component-value/index.js +13 -0
  375. package/lib/use-lunatic/commons/get-components-from-state.js +40 -0
  376. package/lib/use-lunatic/commons/get-data.js +75 -0
  377. package/lib/use-lunatic/commons/get-errors-without-empty-value.js +22 -0
  378. package/lib/use-lunatic/commons/index.js +109 -0
  379. package/lib/use-lunatic/commons/is-First-last-page.js +18 -0
  380. package/lib/use-lunatic/commons/is-paginated-loop.js +13 -0
  381. package/lib/use-lunatic/commons/load-suggesters.js +154 -0
  382. package/lib/use-lunatic/commons/page-tag.js +64 -0
  383. package/lib/use-lunatic/commons/use-components-from-state.js +41 -0
  384. package/lib/use-lunatic/index.js +13 -0
  385. package/lib/use-lunatic/initial-state.js +41 -0
  386. package/lib/use-lunatic/reducer/commons/index.js +36 -0
  387. package/lib/use-lunatic/reducer/commons/is-empty-on-empty-page.js +35 -0
  388. package/lib/use-lunatic/reducer/commons/resize-array-variable.js +38 -0
  389. package/lib/use-lunatic/reducer/commons/validate-condition-filter.js +29 -0
  390. package/lib/use-lunatic/reducer/index.js +13 -0
  391. package/lib/use-lunatic/reducer/reduce-go-next-page.js +183 -0
  392. package/lib/use-lunatic/reducer/reduce-go-previous-page.js +145 -0
  393. package/lib/use-lunatic/reducer/reduce-go-to-page.js +50 -0
  394. package/lib/use-lunatic/reducer/reduce-handle-change/index.js +13 -0
  395. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.js +61 -0
  396. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.js +129 -0
  397. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-links-variable.js +81 -0
  398. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-missing.js +70 -0
  399. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-resizing.js +99 -0
  400. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-variables-array.js +41 -0
  401. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-variables-simple.js +25 -0
  402. package/lib/use-lunatic/reducer/reduce-on-init.js +225 -0
  403. package/lib/use-lunatic/reducer/reduce-on-set-waiting.js +21 -0
  404. package/lib/use-lunatic/reducer/reducer.js +38 -0
  405. package/lib/use-lunatic/reducer/validate-controls/create-controls-reducer.js +60 -0
  406. package/lib/use-lunatic/reducer/validate-controls/create-modal-controls-reducer.js +84 -0
  407. package/lib/use-lunatic/reducer/validate-controls/index.js +20 -0
  408. package/lib/use-lunatic/reducer/validate-controls/validation-utils.js +60 -0
  409. package/lib/use-lunatic/use-lunatic.js +170 -0
  410. package/lib/utils/constants/features.js +12 -0
  411. package/lib/utils/constants/index.js +60 -0
  412. package/lib/utils/constants/links.js +10 -0
  413. package/lib/utils/constants/missing.js +10 -0
  414. package/lib/utils/constants/variable-status.js +16 -0
  415. package/lib/utils/constants/variable-types.js +8 -0
  416. package/lib/utils/idb-tools/clear-store.js +42 -0
  417. package/lib/utils/idb-tools/create-db-opener.js +47 -0
  418. package/lib/utils/idb-tools/create-open-db.js +29 -0
  419. package/lib/utils/idb-tools/get-entity.js +21 -0
  420. package/lib/utils/idb-tools/get-idb.js +13 -0
  421. package/lib/utils/idb-tools/idb-bulk-insert.js +134 -0
  422. package/lib/utils/idb-tools/index.js +64 -0
  423. package/lib/utils/idb-tools/insert-entity.js +21 -0
  424. package/lib/utils/idb-tools/open-db.js +24 -0
  425. package/lib/utils/idb-tools/open-or-create-db.js +42 -0
  426. package/lib/utils/is-element.js +10 -0
  427. package/lib/utils/store-tools/auto-load.js +168 -0
  428. package/lib/utils/store-tools/clear-store-data.js +35 -0
  429. package/lib/utils/store-tools/clear-store-info.js +35 -0
  430. package/lib/utils/store-tools/constantes.js +31 -0
  431. package/lib/utils/store-tools/create/create.js +53 -0
  432. package/lib/utils/store-tools/create/index.js +20 -0
  433. package/lib/utils/store-tools/create/update-store-info.js +27 -0
  434. package/lib/utils/store-tools/get-store-count.js +24 -0
  435. package/lib/utils/store-tools/index.js +54 -0
  436. package/lib/utils/store-tools/open-or-create-store.js +50 -0
  437. package/lib/utils/store-tools/use-store-index.js +60 -0
  438. package/lib/utils/suggester-workers/append-to-index/append.js +80 -0
  439. package/lib/utils/suggester-workers/append-to-index/append.worker.js +27 -0
  440. package/lib/utils/suggester-workers/append-to-index/create-append-task.js +58 -0
  441. package/lib/utils/suggester-workers/append-to-index/index.js +20 -0
  442. package/lib/utils/suggester-workers/append-to-index/prepare-entities.js +88 -0
  443. package/lib/utils/suggester-workers/append-to-index/store-messages.js +45 -0
  444. package/lib/utils/suggester-workers/commons-tokenizer/create-entity-tokenizer.js +54 -0
  445. package/lib/utils/suggester-workers/commons-tokenizer/create-fields-tokenizer.js +77 -0
  446. package/lib/utils/suggester-workers/commons-tokenizer/create-filter-stop-words.js +36 -0
  447. package/lib/utils/suggester-workers/commons-tokenizer/filters/compose-filters.js +21 -0
  448. package/lib/utils/suggester-workers/commons-tokenizer/filters/create-filter-stop-words.js +36 -0
  449. package/lib/utils/suggester-workers/commons-tokenizer/filters/create-filter-stop-words.spec.js +14 -0
  450. package/lib/utils/suggester-workers/commons-tokenizer/filters/filter-accents.js +19 -0
  451. package/lib/utils/suggester-workers/commons-tokenizer/filters/filter-accents.spec.js +16 -0
  452. package/lib/utils/suggester-workers/commons-tokenizer/filters/filter-double.js +25 -0
  453. package/lib/utils/suggester-workers/commons-tokenizer/filters/filter-double.spec.js +23 -0
  454. package/lib/utils/suggester-workers/commons-tokenizer/filters/filter-length.js +15 -0
  455. package/lib/utils/suggester-workers/commons-tokenizer/filters/filter-length.spec.js +23 -0
  456. package/lib/utils/suggester-workers/commons-tokenizer/filters/filter-stemmer.js +23 -0
  457. package/lib/utils/suggester-workers/commons-tokenizer/filters/filter-stemmer.spec.js +16 -0
  458. package/lib/utils/suggester-workers/commons-tokenizer/filters/filter-synonyms.js +53 -0
  459. package/lib/utils/suggester-workers/commons-tokenizer/filters/filter-synonyms.spec.js +14 -0
  460. package/lib/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.js +16 -0
  461. package/lib/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.spec.js +14 -0
  462. package/lib/utils/suggester-workers/commons-tokenizer/filters/index.js +20 -0
  463. package/lib/utils/suggester-workers/commons-tokenizer/filters/stop-words.js +9 -0
  464. package/lib/utils/suggester-workers/commons-tokenizer/get-regexp-from-pattern.js +14 -0
  465. package/lib/utils/suggester-workers/commons-tokenizer/get-stemmer.js +23 -0
  466. package/lib/utils/suggester-workers/commons-tokenizer/index.js +69 -0
  467. package/lib/utils/suggester-workers/commons-tokenizer/prepare-string-indexation.js +18 -0
  468. package/lib/utils/suggester-workers/commons-tokenizer/soft-tokenizer.js +12 -0
  469. package/lib/utils/suggester-workers/create-worker.js +54 -0
  470. package/lib/utils/suggester-workers/find-best-label/find-best-label.js +63 -0
  471. package/lib/utils/suggester-workers/find-best-label/find-best-label.worker.js +53 -0
  472. package/lib/utils/suggester-workers/find-best-label/index.js +1 -0
  473. package/lib/utils/suggester-workers/find-best-label/tokenize.js +45 -0
  474. package/lib/utils/suggester-workers/find-best-label/tokenize.spec.js +24 -0
  475. package/lib/utils/suggester-workers/searching/compute-score.js +51 -0
  476. package/lib/utils/suggester-workers/searching/get-db.js +50 -0
  477. package/lib/utils/suggester-workers/searching/index.js +13 -0
  478. package/lib/utils/suggester-workers/searching/order/create-alphanumeric-orderer.js +28 -0
  479. package/lib/utils/suggester-workers/searching/order/index.js +25 -0
  480. package/lib/utils/suggester-workers/searching/query-parser/index.js +20 -0
  481. package/lib/utils/suggester-workers/searching/query-parser/query-parser-soft.js +12 -0
  482. package/lib/utils/suggester-workers/searching/query-parser/query-parser-soft.spec.js +26 -0
  483. package/lib/utils/suggester-workers/searching/query-parser/query-parser-tokenized.js +35 -0
  484. package/lib/utils/suggester-workers/searching/resolve-query-parser.js +59 -0
  485. package/lib/utils/suggester-workers/searching/search-in-index.js +22 -0
  486. package/lib/utils/suggester-workers/searching/searching.js +135 -0
  487. package/lib/utils/suggester-workers/searching/searching.worker.js +20 -0
  488. package/lib/utils/vtl/dataset-builder.js +24 -0
  489. package/lib/utils/vtl/index.js +13 -0
  490. package/package.json +163 -140
  491. package/lib/index.js.map +0 -1
  492. package/src/components/breadcrumb/breadcrumb.scss +0 -22
  493. package/src/components/breadcrumb/component.js +0 -29
  494. package/src/components/breadcrumb/index.js +0 -1
  495. package/src/components/button/button.scss +0 -26
  496. package/src/components/button/component.js +0 -25
  497. package/src/components/button/index.js +0 -1
  498. package/src/components/checkbox/boolean.js +0 -139
  499. package/src/components/checkbox/checkbox.scss +0 -43
  500. package/src/components/checkbox/group.js +0 -168
  501. package/src/components/checkbox/index.js +0 -3
  502. package/src/components/checkbox/one.js +0 -27
  503. package/src/components/components.js +0 -15
  504. package/src/components/datepicker/component.js +0 -10
  505. package/src/components/datepicker/datepicker.scss +0 -16
  506. package/src/components/datepicker/index.js +0 -1
  507. package/src/components/declarations/component.js +0 -38
  508. package/src/components/declarations/declarations.scss +0 -34
  509. package/src/components/declarations/index.js +0 -1
  510. package/src/components/declarations/wrappers/index.js +0 -3
  511. package/src/components/declarations/wrappers/input-declarations-wrapper.js +0 -162
  512. package/src/components/declarations/wrappers/list-declarations-wrapper.js +0 -159
  513. package/src/components/declarations/wrappers/simple-declarations-wrapper.js +0 -54
  514. package/src/components/dropdown/commons/actions.js +0 -56
  515. package/src/components/dropdown/commons/children-to-option.js +0 -9
  516. package/src/components/dropdown/commons/cleaner-callbacks.js +0 -58
  517. package/src/components/dropdown/commons/components/closed.icon.js +0 -24
  518. package/src/components/dropdown/commons/components/dropdown-container.js +0 -169
  519. package/src/components/dropdown/commons/components/label.js +0 -21
  520. package/src/components/dropdown/commons/components/opened.icon.js +0 -24
  521. package/src/components/dropdown/commons/components/panel.js +0 -78
  522. package/src/components/dropdown/commons/event-callbacks/index.js +0 -5
  523. package/src/components/dropdown/commons/event-callbacks/on-keydown-callback.js +0 -30
  524. package/src/components/dropdown/commons/event-callbacks/on-mousedown-callback.js +0 -11
  525. package/src/components/dropdown/commons/reducer.js +0 -149
  526. package/src/components/dropdown/commons/tools/index.js +0 -17
  527. package/src/components/dropdown/component.js +0 -117
  528. package/src/components/dropdown/dropdown-edit/cross.icon.js +0 -20
  529. package/src/components/dropdown/dropdown-edit/dropdown-edit.js +0 -174
  530. package/src/components/dropdown/dropdown-edit/icone.js +0 -33
  531. package/src/components/dropdown/dropdown-edit/index.js +0 -11
  532. package/src/components/dropdown/dropdown-edit/option.js +0 -62
  533. package/src/components/dropdown/dropdown-edit/prefix-tools.js +0 -51
  534. package/src/components/dropdown/dropdown-simple/dropdown.js +0 -155
  535. package/src/components/dropdown/dropdown-simple/index.js +0 -20
  536. package/src/components/dropdown/dropdown-simple/option.js +0 -15
  537. package/src/components/dropdown/dropdown.scss +0 -183
  538. package/src/components/dropdown/index.js +0 -1
  539. package/src/components/filter-description/component.js +0 -41
  540. package/src/components/filter-description/index.js +0 -1
  541. package/src/components/index.js +0 -4
  542. package/src/components/index.scss +0 -76
  543. package/src/components/input/index.js +0 -2
  544. package/src/components/input/input-number.js +0 -228
  545. package/src/components/input/input.js +0 -10
  546. package/src/components/input/input.scss +0 -27
  547. package/src/components/loops/index.js +0 -2
  548. package/src/components/loops/loop/build-components.js +0 -33
  549. package/src/components/loops/loop/component.js +0 -88
  550. package/src/components/loops/loop/index.js +0 -1
  551. package/src/components/loops/loop/loop.scss +0 -17
  552. package/src/components/loops/roster/build-components.js +0 -26
  553. package/src/components/loops/roster/component.js +0 -199
  554. package/src/components/loops/roster/index.js +0 -1
  555. package/src/components/progress-bar/component.js +0 -28
  556. package/src/components/progress-bar/index.js +0 -1
  557. package/src/components/progress-bar/progress-bar.scss +0 -54
  558. package/src/components/radio/component.js +0 -8
  559. package/src/components/radio/index.js +0 -1
  560. package/src/components/radio/radio.scss +0 -24
  561. package/src/components/sequence/component.js +0 -41
  562. package/src/components/sequence/index.js +0 -1
  563. package/src/components/sequence/sequence.scss +0 -15
  564. package/src/components/subsequence/component.js +0 -48
  565. package/src/components/subsequence/index.js +0 -1
  566. package/src/components/subsequence/subsequence.scss +0 -15
  567. package/src/components/table/index.js +0 -1
  568. package/src/components/table/table.js +0 -160
  569. package/src/components/table/table.scss +0 -23
  570. package/src/components/textarea/component.js +0 -10
  571. package/src/components/textarea/index.js +0 -1
  572. package/src/components/textarea/textarea.scss +0 -16
  573. package/src/components/tooltip/img/index.js +0 -4
  574. package/src/components/tooltip/index.js +0 -1
  575. package/src/components/tooltip/response.js +0 -42
  576. package/src/components/tooltip/tooltip.scss +0 -35
  577. package/src/constants/component-types.js +0 -1
  578. package/src/constants/declarations.js +0 -14
  579. package/src/constants/index.js +0 -4
  580. package/src/constants/supported-preferences.js +0 -10
  581. package/src/constants/value-types.js +0 -5
  582. package/src/constants/variable-types.js +0 -4
  583. package/src/stories/breadcrumb/README.md +0 -14
  584. package/src/stories/breadcrumb/breadcrumb.stories.js +0 -33
  585. package/src/stories/button/README.md +0 -14
  586. package/src/stories/button/button.stories.js +0 -63
  587. package/src/stories/checkbox-boolean/README.md +0 -27
  588. package/src/stories/checkbox-boolean/checkbox-boolean.stories.js +0 -33
  589. package/src/stories/checkbox-group/README.md +0 -29
  590. package/src/stories/checkbox-group/checkbox-group.stories.js +0 -81
  591. package/src/stories/checkbox-group/data-vtl.json +0 -89
  592. package/src/stories/checkbox-group/data.json +0 -89
  593. package/src/stories/checkbox-one/checkbox-one.stories.js +0 -77
  594. package/src/stories/checkbox-one/data-vtl.json +0 -33
  595. package/src/stories/checkbox-one/data.json +0 -33
  596. package/src/stories/datepicker/README.md +0 -31
  597. package/src/stories/datepicker/data.json +0 -28
  598. package/src/stories/datepicker/datepicker.stories.js +0 -65
  599. package/src/stories/declarations/README.md +0 -19
  600. package/src/stories/declarations/declarations.stories.js +0 -112
  601. package/src/stories/dropdown/README.md +0 -44
  602. package/src/stories/dropdown/data-naf.json +0 -6963
  603. package/src/stories/dropdown/data-props.json +0 -81
  604. package/src/stories/dropdown/data.json +0 -78
  605. package/src/stories/dropdown/dropdown.stories.js +0 -65
  606. package/src/stories/filter-description/README.md +0 -15
  607. package/src/stories/filter-description/filter-description.stories.js +0 -70
  608. package/src/stories/input/README.md +0 -33
  609. package/src/stories/input/data.json +0 -28
  610. package/src/stories/input/input.stories.js +0 -67
  611. package/src/stories/input-number/README.md +0 -37
  612. package/src/stories/input-number/data.json +0 -30
  613. package/src/stories/input-number/input-number.stories.js +0 -75
  614. package/src/stories/loops/README.md +0 -29
  615. package/src/stories/loops/custom-lunatic.scss +0 -786
  616. package/src/stories/loops/data-loop-deeper.json +0 -298
  617. package/src/stories/loops/data-loop.json +0 -213
  618. package/src/stories/loops/data-roster.json +0 -69
  619. package/src/stories/loops/img/arrow.png +0 -0
  620. package/src/stories/loops/img/check_box.svg +0 -1
  621. package/src/stories/loops/img/check_box_outline.svg +0 -1
  622. package/src/stories/loops/img/lunatic-logo.png +0 -0
  623. package/src/stories/loops/img/menu-down.svg +0 -1
  624. package/src/stories/loops/img/menu-up.svg +0 -1
  625. package/src/stories/loops/img/radio_button_checked.svg +0 -1
  626. package/src/stories/loops/img/radio_button_unchecked.svg +0 -1
  627. package/src/stories/loops/loop.stories.js +0 -56
  628. package/src/stories/loops/vqs.json +0 -846
  629. package/src/stories/progress-bar/README.md +0 -13
  630. package/src/stories/progress-bar/progress-bar.stories.js +0 -24
  631. package/src/stories/radio/README.md +0 -31
  632. package/src/stories/radio/data-vtl.json +0 -32
  633. package/src/stories/radio/data.json +0 -32
  634. package/src/stories/radio/radio.stories.js +0 -81
  635. package/src/stories/sequence/README.md +0 -18
  636. package/src/stories/sequence/sequence.stories.js +0 -58
  637. package/src/stories/subsequence/README.md +0 -18
  638. package/src/stories/subsequence/subsequence.stories.js +0 -58
  639. package/src/stories/table/README.md +0 -29
  640. package/src/stories/table/data-one-axis-one-measure.json +0 -124
  641. package/src/stories/table/data-one-axis-two-measures.json +0 -193
  642. package/src/stories/table/data-one-hierarchical-axis.json +0 -204
  643. package/src/stories/table/data-two-axis-one-measure.json +0 -492
  644. package/src/stories/table/table.stories.js +0 -77
  645. package/src/stories/textarea/README.md +0 -33
  646. package/src/stories/textarea/data.json +0 -28
  647. package/src/stories/textarea/textarea.stories.js +0 -67
  648. package/src/stories/tooltip-response/README.md +0 -14
  649. package/src/stories/tooltip-response/tooltip.stories.js +0 -43
  650. package/src/stories/utils/options.js +0 -21
  651. package/src/stories/utils/orchestrator.js +0 -52
  652. package/src/tests/components/breadcrumb.spec.js +0 -13
  653. package/src/tests/components/button.spec.js +0 -11
  654. package/src/tests/components/checkbox-boolean.spec.js +0 -40
  655. package/src/tests/components/checkbox-group.spec.js +0 -48
  656. package/src/tests/components/checkbox-one.spec.js +0 -32
  657. package/src/tests/components/datepicker.spec.js +0 -22
  658. package/src/tests/components/declarations-wrappers/input-declarations-wrapper.spec.js +0 -65
  659. package/src/tests/components/declarations-wrappers/list-declarations-wrapper.spec.js +0 -47
  660. package/src/tests/components/declarations-wrappers/simple-declarations-wrapper.spec.js +0 -21
  661. package/src/tests/components/declarations.spec.js +0 -46
  662. package/src/tests/components/input-number.spec.js +0 -173
  663. package/src/tests/components/input.spec.js +0 -18
  664. package/src/tests/components/progress-bar.spec.js +0 -15
  665. package/src/tests/components/radio.spec.js +0 -27
  666. package/src/tests/components/sequence.spec.js +0 -9
  667. package/src/tests/components/subsequence.spec.js +0 -9
  668. package/src/tests/components/table.spec.js +0 -11
  669. package/src/tests/components/textarea.spec.js +0 -18
  670. package/src/tests/components/tooltip.spec.js +0 -25
  671. package/src/tests/setup/setupTests.js +0 -4
  672. package/src/tests/utils/lib/alphabet.spec.js +0 -36
  673. package/src/tests/utils/lib/checkbox/group.spec.js +0 -72
  674. package/src/tests/utils/lib/decorator/title-decorator.spec.js +0 -12
  675. package/src/tests/utils/lib/items-positioning.spec.js +0 -17
  676. package/src/tests/utils/lib/label-position.spec.js +0 -22
  677. package/src/tests/utils/lib/loops/bindings.spec.js +0 -60
  678. package/src/tests/utils/lib/loops/shared.spec.js +0 -77
  679. package/src/tests/utils/lib/responses.spec.js +0 -58
  680. package/src/tests/utils/lib/style.spec.js +0 -26
  681. package/src/tests/utils/lib/table/roster.spec.js +0 -25
  682. package/src/tests/utils/lib/tooltip/build-response.spec.js +0 -95
  683. package/src/tests/utils/lib/tooltip/content.spec.js +0 -109
  684. package/src/tests/utils/to-expose/handler/handler.spec.js +0 -86
  685. package/src/tests/utils/to-expose/handler/questionnaire.json +0 -154
  686. package/src/tests/utils/to-expose/handler/results/index.js +0 -6
  687. package/src/tests/utils/to-expose/handler/results/res-double.json +0 -157
  688. package/src/tests/utils/to-expose/handler/results/res-input-collected.json +0 -154
  689. package/src/tests/utils/to-expose/handler/results/res-input-edited.json +0 -157
  690. package/src/tests/utils/to-expose/handler/results/res-loop.json +0 -157
  691. package/src/tests/utils/to-expose/handler/results/res-matrix.json +0 -157
  692. package/src/tests/utils/to-expose/handler/results/res-responses.json +0 -157
  693. package/src/tests/utils/to-expose/init-questionnaire/data.json +0 -12
  694. package/src/tests/utils/to-expose/init-questionnaire/init-questionnaire.spec.js +0 -19
  695. package/src/tests/utils/to-expose/init-questionnaire/questionnaire.json +0 -129
  696. package/src/tests/utils/to-expose/init-questionnaire/result.json +0 -162
  697. package/src/tests/utils/to-expose/interpret.spec.js +0 -42
  698. package/src/tests/utils/to-expose/state/questionnaire.json +0 -61
  699. package/src/tests/utils/to-expose/state/results.js +0 -78
  700. package/src/tests/utils/to-expose/state/state.spec.js +0 -59
  701. package/src/utils/lib/alphabet.js +0 -1
  702. package/src/utils/lib/checkbox/group.js +0 -21
  703. package/src/utils/lib/checkbox/index.js +0 -1
  704. package/src/utils/lib/decorator/index.js +0 -1
  705. package/src/utils/lib/decorator/title-decorator.js +0 -16
  706. package/src/utils/lib/index.js +0 -12
  707. package/src/utils/lib/label-position.js +0 -12
  708. package/src/utils/lib/loops/bindings.js +0 -47
  709. package/src/utils/lib/loops/index.js +0 -2
  710. package/src/utils/lib/loops/shared.js +0 -43
  711. package/src/utils/lib/memo-check.js +0 -24
  712. package/src/utils/lib/options-positioning.js +0 -9
  713. package/src/utils/lib/prop-types/declarations.js +0 -22
  714. package/src/utils/lib/prop-types/index.js +0 -5
  715. package/src/utils/lib/prop-types/lines.js +0 -6
  716. package/src/utils/lib/prop-types/options.js +0 -8
  717. package/src/utils/lib/prop-types/response.js +0 -6
  718. package/src/utils/lib/prop-types/value-type.js +0 -9
  719. package/src/utils/lib/responses.js +0 -9
  720. package/src/utils/lib/style.js +0 -10
  721. package/src/utils/lib/table/index.js +0 -1
  722. package/src/utils/lib/table/roster.js +0 -18
  723. package/src/utils/lib/tooltip/build-response.js +0 -23
  724. package/src/utils/lib/tooltip/content.js +0 -52
  725. package/src/utils/lib/tooltip/index.js +0 -5
  726. package/src/utils/to-expose/handler.js +0 -99
  727. package/src/utils/to-expose/hook.js +0 -55
  728. package/src/utils/to-expose/index.js +0 -10
  729. package/src/utils/to-expose/init-questionnaire.js +0 -114
  730. package/src/utils/to-expose/interpret.js +0 -32
  731. package/src/utils/to-expose/state.js +0 -58
package/lib/index.js CHANGED
@@ -1,4047 +1,28 @@
1
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
2
 
3
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
-
5
- var React = require('react');
6
- var React__default = _interopDefault(React);
7
- var PropTypes = _interopDefault(require('prop-types'));
8
- var camelCase = _interopDefault(require('lodash.camelcase'));
9
- var isEqual = _interopDefault(require('lodash.isequal'));
10
- var vtl2_1Engine = require('@inseefr/vtl-2.1-engine');
11
- var debounce = require('debounce');
12
- var removeAccents = _interopDefault(require('remove-accents'));
13
-
14
- var lunatic = /*#__PURE__*/Object.freeze({
15
- __proto__: null,
16
- get Breadcrumb () { return Breadcrumb; },
17
- get Button () { return Button; },
18
- get CheckboxGroup () { return group; },
19
- get CheckboxOne () { return one; },
20
- get CheckboxBoolean () { return boolean; },
21
- get Datepicker () { return component; },
22
- get Declarations () { return Declarations; },
23
- get Dropdown () { return component$1; },
24
- get Input () { return input; },
25
- get InputNumber () { return inputNumber; },
26
- get FilterDescription () { return FilterDescription; },
27
- get ProgressBar () { return ProgressBar; },
28
- get Radio () { return component$2; },
29
- get RosterForLoop () { return component$4; },
30
- get Loop () { return component$3; },
31
- get Sequence () { return component$5; },
32
- get Subsequence () { return component$6; },
33
- get Textarea () { return component$7; },
34
- get TooltipResponse () { return TooltipResponse; }
35
- });
36
-
37
- // Declaration position
38
- var BEFORE_QUESTION_TEXT = 'BEFORE_QUESTION_TEXT';
39
- var AFTER_QUESTION_TEXT = 'AFTER_QUESTION_TEXT';
40
- var DETACHABLE = 'DETACHABLE'; // Declaration types
41
-
42
- var INSTRUCTION = 'INSTRUCTION';
43
- var COMMENT = 'COMMENT';
44
- var HELP = 'HELP';
45
- var WARNING = 'WARNING';
46
- var MESSAGE_FILTER = 'MESSAGE_FILTER';
47
- var STATEMENT = 'STATEMENT';
48
-
49
- var PREVIOUS = 'PREVIOUS';
50
- var COLLECTED = 'COLLECTED';
51
- var FORCED = 'FORCED';
52
- var EDITED = 'EDITED';
53
- var INPUTED = 'INPUTED';
54
-
55
- var EXTERNAL = 'EXTERNAL';
56
- var CALCULATED = 'CALCULATED'; // Already define in value-types
57
- //export const COLLECTED = 'COLLECTED';
58
-
59
- var declarations = PropTypes.arrayOf(PropTypes.shape({
60
- id: PropTypes.string.isRequired,
61
- declarationType: PropTypes.oneOf([INSTRUCTION, COMMENT, HELP, WARNING, MESSAGE_FILTER, STATEMENT]),
62
- position: PropTypes.oneOf([BEFORE_QUESTION_TEXT, AFTER_QUESTION_TEXT, DETACHABLE]),
63
- label: PropTypes.string.isRequired
64
- })).isRequired;
65
-
66
- var options = PropTypes.arrayOf(PropTypes.shape({
67
- label: PropTypes.string.isRequired,
68
- value: PropTypes.string.isRequired
69
- }));
70
-
71
- var response = PropTypes.shape({
72
- name: PropTypes.string,
73
- values: PropTypes.shape({})
74
- });
75
-
76
- var valueType = PropTypes.oneOf(['COLLECTED', 'PREVIOUS', 'FORCED', 'EDITED', 'INPUTED']);
77
-
78
- var lines = PropTypes.shape({
79
- min: PropTypes.number,
80
- max: PropTypes.number
81
- });
82
-
83
- var buildTooltip = function buildTooltip(response) {
84
- if (!response || !response.values || Object.keys(response.values).length === 0) return {};
85
- var values = response.values;
86
- var edited = values[EDITED];
87
- var forced = values[FORCED];
88
- var collected = values[COLLECTED];
89
-
90
- if (has(edited)) {
91
- if (!has(forced)) return {
92
- content: [{
93
- key: 'Brute',
94
- value: collected || ' - '
95
- }],
96
- imgName: 'editedImg'
97
- };
98
- return {
99
- content: [{
100
- key: 'Brute',
101
- value: collected || ' - '
102
- }, {
103
- key: 'Correction automatique',
104
- value: forced
105
- }],
106
- imgName: 'editedImg'
107
- };
108
- }
109
-
110
- if (has(forced)) return {
111
- content: [{
112
- key: 'Brute',
113
- value: collected || ' - '
114
- }],
115
- imgName: 'forcedImg'
116
- };
117
- return {};
118
- };
119
-
120
- var has = function has(status) {
121
- return status !== undefined && status !== null;
122
- };
123
-
124
- function _defineProperty(obj, key, value) {
125
- if (key in obj) {
126
- Object.defineProperty(obj, key, {
127
- value: value,
128
- enumerable: true,
129
- configurable: true,
130
- writable: true
131
- });
132
- } else {
133
- obj[key] = value;
134
- }
135
-
136
- return obj;
137
- }
138
-
139
- function _extends() {
140
- _extends = Object.assign || function (target) {
141
- for (var i = 1; i < arguments.length; i++) {
142
- var source = arguments[i];
143
-
144
- for (var key in source) {
145
- if (Object.prototype.hasOwnProperty.call(source, key)) {
146
- target[key] = source[key];
147
- }
148
- }
149
- }
150
-
151
- return target;
152
- };
153
-
154
- return _extends.apply(this, arguments);
155
- }
156
-
157
- function ownKeys(object, enumerableOnly) {
158
- var keys = Object.keys(object);
159
-
160
- if (Object.getOwnPropertySymbols) {
161
- var symbols = Object.getOwnPropertySymbols(object);
162
- if (enumerableOnly) symbols = symbols.filter(function (sym) {
163
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
164
- });
165
- keys.push.apply(keys, symbols);
166
- }
167
-
168
- return keys;
169
- }
170
-
171
- function _objectSpread2(target) {
172
- for (var i = 1; i < arguments.length; i++) {
173
- var source = arguments[i] != null ? arguments[i] : {};
174
-
175
- if (i % 2) {
176
- ownKeys(Object(source), true).forEach(function (key) {
177
- _defineProperty(target, key, source[key]);
178
- });
179
- } else if (Object.getOwnPropertyDescriptors) {
180
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
181
- } else {
182
- ownKeys(Object(source)).forEach(function (key) {
183
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
184
- });
185
- }
186
- }
187
-
188
- return target;
189
- }
190
-
191
- function _objectWithoutPropertiesLoose(source, excluded) {
192
- if (source == null) return {};
193
- var target = {};
194
- var sourceKeys = Object.keys(source);
195
- var key, i;
196
-
197
- for (i = 0; i < sourceKeys.length; i++) {
198
- key = sourceKeys[i];
199
- if (excluded.indexOf(key) >= 0) continue;
200
- target[key] = source[key];
201
- }
202
-
203
- return target;
204
- }
205
-
206
- function _objectWithoutProperties(source, excluded) {
207
- if (source == null) return {};
208
-
209
- var target = _objectWithoutPropertiesLoose(source, excluded);
210
-
211
- var key, i;
212
-
213
- if (Object.getOwnPropertySymbols) {
214
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
215
-
216
- for (i = 0; i < sourceSymbolKeys.length; i++) {
217
- key = sourceSymbolKeys[i];
218
- if (excluded.indexOf(key) >= 0) continue;
219
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
220
- target[key] = source[key];
221
- }
222
- }
223
-
224
- return target;
225
- }
226
-
227
- function _slicedToArray(arr, i) {
228
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
229
- }
230
-
231
- function _toArray(arr) {
232
- return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
233
- }
234
-
235
- function _toConsumableArray(arr) {
236
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
237
- }
238
-
239
- function _arrayWithoutHoles(arr) {
240
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
241
- }
242
-
243
- function _arrayWithHoles(arr) {
244
- if (Array.isArray(arr)) return arr;
245
- }
246
-
247
- function _iterableToArray(iter) {
248
- if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
249
- }
250
-
251
- function _iterableToArrayLimit(arr, i) {
252
- if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
253
- var _arr = [];
254
- var _n = true;
255
- var _d = false;
256
- var _e = undefined;
257
-
258
- try {
259
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
260
- _arr.push(_s.value);
261
-
262
- if (i && _arr.length === i) break;
263
- }
264
- } catch (err) {
265
- _d = true;
266
- _e = err;
267
- } finally {
268
- try {
269
- if (!_n && _i["return"] != null) _i["return"]();
270
- } finally {
271
- if (_d) throw _e;
272
- }
273
- }
274
-
275
- return _arr;
276
- }
277
-
278
- function _unsupportedIterableToArray(o, minLen) {
279
- if (!o) return;
280
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
281
- var n = Object.prototype.toString.call(o).slice(8, -1);
282
- if (n === "Object" && o.constructor) n = o.constructor.name;
283
- if (n === "Map" || n === "Set") return Array.from(o);
284
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
285
- }
286
-
287
- function _arrayLikeToArray(arr, len) {
288
- if (len == null || len > arr.length) len = arr.length;
289
-
290
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
291
-
292
- return arr2;
293
- }
294
-
295
- function _nonIterableSpread() {
296
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
297
- }
298
-
299
- function _nonIterableRest() {
300
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
301
- }
302
-
303
- var buildMultiTooltipResponse = function buildMultiTooltipResponse(options) {
304
- return function (response) {
305
- if (!response || Object.keys(response).length === 0 || !options) return {};
306
- var name = response.name,
307
- values = response.values;
308
- var newValues = Object.entries(values).reduce(function (acc, _ref) {
309
- var _ref2 = _slicedToArray(_ref, 2),
310
- k = _ref2[0],
311
- v = _ref2[1];
312
-
313
- return v === null ? _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, k, v)) : _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, k, options.find(function (o) {
314
- return o.value === v;
315
- }).label));
316
- }, {});
317
- return {
318
- name: name,
319
- values: newValues
320
- };
321
- };
322
- };
323
- var buildBooleanTooltipResponse = function buildBooleanTooltipResponse(response) {
324
- if (!response || Object.keys(response).length === 0) return {};
325
- var name = response.name,
326
- values = response.values;
327
- var newValues = Object.entries(values).reduce(function (acc, _ref3) {
328
- var _ref4 = _slicedToArray(_ref3, 2),
329
- k = _ref4[0],
330
- v = _ref4[1];
331
-
332
- return v === null ? _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, k, v)) : _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, k, v ? 'Vrai' : 'Faux'));
333
- }, {});
334
- return {
335
- name: name,
336
- values: newValues
337
- };
338
- };
339
-
340
- var getAlphabet = function getAlphabet() {
341
- return 'abcdefghijklmnopqrstuvwxyz'.split('');
342
- };
343
-
344
- var getLabelPositionClass = function getLabelPositionClass(position) {
345
- switch (position) {
346
- case 'LEFT':
347
- return 'label-left';
348
-
349
- case 'BOTTOM':
350
- return 'label-bottom';
351
-
352
- case 'RIGHT':
353
- return 'label-right';
354
-
355
- default:
356
- return 'label-top';
357
- }
358
- };
359
-
360
- var getItemsPositioningClass = function getItemsPositioningClass(positioning) {
361
- switch (positioning) {
362
- case 'HORIZONTAL':
363
- return 'horizontal-options';
364
-
365
- case 'VERTICAL':
366
- default:
367
- return '';
368
- }
369
- };
370
-
371
- var getResponseName = function getResponseName(response) {
372
- return response && response.name || '';
373
- };
374
- var getResponseByPreference = function getResponseByPreference(preferences) {
375
- return function (response) {
376
- if (!(response && response.values)) return '';
377
- return preferences.reduce(function (acc, p) {
378
- var value = response.values[p];
379
- return value !== null ? value : acc;
380
- }, '');
381
- };
382
- };
383
-
384
- var buildStyleObject = function buildStyleObject(obj) {
385
- return obj ? Object.entries(obj).reduce(function (_, _ref) {
386
- var _ref2 = _slicedToArray(_ref, 2),
387
- key = _ref2[0],
388
- value = _ref2[1];
389
-
390
- if (key.startsWith(':')) _[key] = buildStyleObject(value);else _[camelCase(key)] = value;
391
- return _;
392
- }, {}) : {};
393
- };
394
-
395
- var isResponseEmpty = function isResponseEmpty(response) {
396
- return Object.values(response.values).filter(function (v) {
397
- return v !== null;
398
- }).length === 0;
399
- };
400
-
401
- var getRosterInitLines = function getRosterInitLines(cells) {
402
- return Array.isArray(cells) ? cells.reduce(function (_, line) {
403
- return [].concat(_toConsumableArray(_), [line.reduce(function (__, component) {
404
- if (!component.response || __) return __;
405
- return !isResponseEmpty(component.response);
406
- }, false)]);
407
- }, []).filter(function (b) {
408
- return b;
409
- }).length : 0;
410
- };
411
-
412
- var buildBindingsForDeeperComponents = function buildBindingsForDeeperComponents(index) {
413
- return function (bindings) {
414
- return bindings ? Object.entries(bindings).reduce(function (_, _ref) {
415
- var _ref2 = _slicedToArray(_ref, 2),
416
- name = _ref2[0],
417
- value = _ref2[1];
418
-
419
- if (Array.isArray(value)) return _objectSpread2(_objectSpread2({}, _), {}, _defineProperty({}, name, value[index] || null));
420
- return _objectSpread2(_objectSpread2({}, _), {}, _defineProperty({}, name, value));
421
- }, {}) : {};
422
- };
423
- };
424
-
425
- var getDefaultDatasetStructure = function getDefaultDatasetStructure(name, value) {
426
- return _defineProperty({}, name, {
427
- dataStructure: {},
428
- dataPoints: _defineProperty({}, name, value)
429
- });
430
- };
431
-
432
- var buildVectorialBindings = function buildVectorialBindings(bindings) {
433
- return bindings ? Object.entries(bindings).reduce(function (_, _ref4) {
434
- var _ref5 = _slicedToArray(_ref4, 2),
435
- name = _ref5[0],
436
- value = _ref5[1];
437
-
438
- if (Array.isArray(value)) return _objectSpread2(_objectSpread2({}, _), getDefaultDatasetStructure(name, value));
439
- return _objectSpread2(_objectSpread2({}, _), {}, _defineProperty({}, name, value));
440
- }, {}) : {};
441
- };
442
- var displayLoop = function displayLoop(dependencyList) {
443
- return function (bindings) {
444
- if (!Array.isArray(dependencyList) || !bindings) return false;
445
- return !(dependencyList.map(function (iv) {
446
- return Array.isArray(bindings[iv][0]) ? bindings[iv][0].flat()[0] : bindings[iv][0];
447
- }).filter(function (v) {
448
- return v;
449
- }).length === 0);
450
- };
451
- };
452
- var displayLoopQuestion = function displayLoopQuestion(dependencyList) {
453
- return function (bindings) {
454
- if (!Array.isArray(dependencyList) || !bindings) return false;
455
- return !(dependencyList.map(function (iv) {
456
- return Array.isArray(bindings[iv]) ? bindings[iv].flat()[0] : bindings[iv];
457
- }).filter(function (v) {
458
- return v;
459
- }).length === 0);
460
- };
461
- };
462
-
463
- var getRosterForLoopInitLines = function getRosterForLoopInitLines(components) {
464
- return Array.isArray(components) ? components.reduce(function (_, c) {
465
- return c.response && c.response.values[COLLECTED] && c.response.values[COLLECTED].length > _ ? c.response.values[COLLECTED].length : _;
466
- }, 0) : 0;
467
- };
468
- var getInvolvedVariables = function getInvolvedVariables(parentComponents) {
469
- return Array.isArray(parentComponents) ? parentComponents.reduce(function (_, c) {
470
- var response = c.response,
471
- responses = c.responses,
472
- components = c.components,
473
- depth = c.depth;
474
- if (response && response.name) return [].concat(_toConsumableArray(_), [{
475
- name: response.name,
476
- depth: depth
477
- }]);
478
- if (responses || components) return [].concat(_toConsumableArray(_), [getInvolvedVariables(responses || components)]);
479
- return _;
480
- }, []).flat() : [];
481
- };
482
- var lastRosterForLoopLineIsEmpty = function lastRosterForLoopLineIsEmpty(bindings) {
483
- return function (involvedVariables) {
484
- return bindings && involvedVariables ? involvedVariables.map(function (iv) {
485
- return iv.name;
486
- }).filter(function (iv) {
487
- return bindings[iv] && bindings[iv][bindings[iv].length - 1];
488
- }).length === 0 : true;
489
- };
490
- };
491
- var buildEmptyValue = function buildEmptyValue(depth) {
492
- if (!depth || depth === 1) return null;
493
- return new Array(depth - 1).fill(null).reduce(function (acc) {
494
- return new Array(1).fill(acc);
495
- }, null);
496
- };
497
-
498
- var areEqual = function areEqual(prevProps, props) {
499
- var bindingDependencies = props.bindingDependencies;
500
-
501
- if (Array.isArray(bindingDependencies) && bindingDependencies.length > 0) {
502
- var oldB = prevProps.bindings;
503
- var newB = props.bindings;
504
- return !bindingDependencies.map(function (d) {
505
- return isEqual(oldB[d], newB[d]);
506
- }).includes(false);
507
- }
508
-
509
- return VarsHasBeenUpdated(prevProps, props);
510
- };
511
-
512
- var VarsHasBeenUpdated = function VarsHasBeenUpdated(prevProps, props) {
513
- var oldR = prevProps.response,
514
- oldRs = prevProps.responses,
515
- oldC = prevProps.cells;
516
- var newR = props.response,
517
- newRs = props.responses,
518
- newC = props.cells;
519
- if (!newR && !newRs && !newC) return true;
520
- return newR && isEqual(oldR, newR) || newRs && isEqual(oldRs, newRs) || newC && isEqual(oldC, newC);
521
- };
522
-
523
- var responseToClean = function responseToClean(response) {
524
- return function (preferences) {
525
- if (!preferences || !response.values) return false;
526
- var values = response.values;
527
- if (!values) return false;
528
-
529
- var cutedValues = _objectSpread2(_objectSpread2({}, values), {}, _defineProperty({}, preferences[preferences.length - 1], null));
530
-
531
- return Object.values(cutedValues).filter(function (v) {
532
- return v !== null;
533
- }).length === 0;
534
- };
535
- };
536
- var responsesToClean = function responsesToClean(responses) {
537
- return function (preferences) {
538
- return function (key) {
539
- if (!preferences || !key) return false;
540
- var values = responses.find(function (r) {
541
- return r.response.name === key;
542
- }).response.values;
543
- if (!values) return false;
544
-
545
- var cutedValues = _objectSpread2(_objectSpread2({}, values), {}, _defineProperty({}, preferences[preferences.length - 1], null));
546
-
547
- return Object.values(cutedValues).filter(function (v) {
548
- return v !== null;
549
- }).length === 0;
550
- };
551
- };
552
- };
553
-
554
- function styleInject(css, ref) {
555
- if ( ref === void 0 ) ref = {};
556
- var insertAt = ref.insertAt;
557
-
558
- if (!css || typeof document === 'undefined') { return; }
559
-
560
- var head = document.head || document.getElementsByTagName('head')[0];
561
- var style = document.createElement('style');
562
- style.type = 'text/css';
563
-
564
- if (insertAt === 'top') {
565
- if (head.firstChild) {
566
- head.insertBefore(style, head.firstChild);
567
- } else {
568
- head.appendChild(style);
569
- }
570
- } else {
571
- head.appendChild(style);
572
- }
573
-
574
- if (style.styleSheet) {
575
- style.styleSheet.cssText = css;
576
- } else {
577
- style.appendChild(document.createTextNode(css));
578
- }
579
- }
580
-
581
- var css_248z = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.breadcrumb-lunatic {\n width: 100%;\n height: 40px;\n box-sizing: border-box;\n border-radius: 0px;\n background-color: #e80a4d;\n color: white;\n font-weight: bold;\n font-size: 130%;\n padding-left: 10px;\n display: flex;\n align-items: center; }\n\n.breadcrumb-element-lunatic:before {\n content: '>';\n color: white;\n margin-left: 0.4em;\n margin-right: 0.4em; }\n";
582
- styleInject(css_248z);
583
-
584
- var Breadcrumb = function Breadcrumb(_ref) {
585
- var elements = _ref.elements,
586
- style = _ref.style;
587
- return /*#__PURE__*/React__default.createElement("div", {
588
- "aria-label": "breadcrumb",
589
- className: "breadcrumb-lunatic",
590
- style: buildStyleObject(style)
591
- }, elements.map(function (e, i) {
592
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, {
593
- key: "breadcrumb-".concat(e.toLowerCase())
594
- }, e && /*#__PURE__*/React__default.createElement("span", {
595
- className: i !== 0 ? 'breadcrumb-element-lunatic' : undefined
596
- }, e));
597
- }));
598
- };
599
-
600
- Breadcrumb.propTypes = {
601
- elements: PropTypes.arrayOf(PropTypes.string).isRequired,
602
- style: PropTypes.object
603
- };
604
-
605
- var css_248z$1 = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.button-lunatic {\n width: 100%;\n color: white;\n border-color: #e80a4d;\n background-color: #e80a4d;\n font-size: 1.5em;\n font-weight: bold;\n padding: 0.4em; }\n .button-lunatic:hover, .button-lunatic:focus:hover {\n color: #e80a4d;\n background-color: white;\n border-color: #e80a4d; }\n .button-lunatic:focus {\n outline: none;\n background-color: #e07898;\n border-color: #e07898; }\n .button-lunatic:disabled {\n background: #dddddd;\n color: #e80a4d; }\n";
606
- styleInject(css_248z$1);
607
-
608
- var Button = function Button(_ref) {
609
- var label = _ref.label,
610
- value = _ref.value,
611
- onClick = _ref.onClick,
612
- disabled = _ref.disabled,
613
- style = _ref.style;
614
- return /*#__PURE__*/React__default.createElement("button", {
615
- type: "button",
616
- "aria-label": label || 'button',
617
- className: "button-lunatic",
618
- style: buildStyleObject(style),
619
- disabled: disabled,
620
- onClick: onClick
621
- }, value);
622
- };
623
-
624
- Button.propTypes = {
625
- value: PropTypes.string.isRequired,
626
- disabled: PropTypes.bool,
627
- onClick: PropTypes.func.isRequired
628
- };
629
-
630
- var interpret = function interpret(features) {
631
- return function (bindings, doNotReplaceNullBindings) {
632
- return function (expression) {
633
- if (!expression) return '';
634
- if (!Array.isArray(features)) return expression;
635
-
636
- if (features.includes('VTL')) {
637
- try {
638
- var VTLExpr = vtl2_1Engine.interpret(expression, doNotReplaceNullBindings ? replaceNullBindings(bindings) : bindings);
639
- if (!VTLExpr) return expression;
640
- return VTLExpr;
641
- } catch (e) {
642
- return expression;
643
- }
644
- }
645
-
646
- return expression;
647
- };
648
- };
649
- };
650
- var replaceNullBindings = function replaceNullBindings(bindings) {
651
- return bindings ? Object.entries(bindings).reduce(function (acc, _ref) {
652
- var _ref2 = _slicedToArray(_ref, 2),
653
- key = _ref2[0],
654
- value = _ref2[1];
655
-
656
- return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, value === null ? key : value));
657
- }, {}) : {};
658
- };
659
-
660
- var mergeQuestionnaireAndData = function mergeQuestionnaireAndData(questionnaire) {
661
- return function (data) {
662
- if (!questionnaire || !questionnaire.components) return {};
663
- if (questionnaire.components.length === 0) return questionnaire;
664
-
665
- var components = questionnaire.components,
666
- variables = questionnaire.variables,
667
- props = _objectWithoutProperties(questionnaire, ["components", "variables"]);
668
-
669
- var vars = buildVars(data || {})(variables);
670
- var filledComponents = buildFilledComponents(vars[COLLECTED])(components)(0);
671
- return _objectSpread2(_objectSpread2({}, props), {}, {
672
- components: filledComponents,
673
- variables: vars
674
- });
675
- };
676
- };
677
-
678
- var buildVars = function buildVars(data) {
679
- return function (variables) {
680
- if (!Array.isArray(variables)) return {};
681
- var collectedData = data.COLLECTED;
682
- var collected = variables.filter(function (_ref) {
683
- var variableType = _ref.variableType;
684
- return variableType === COLLECTED;
685
- }).reduce(function (acc, _ref2) {
686
- var values = _ref2.values,
687
- name = _ref2.name,
688
- componentRef = _ref2.componentRef;
689
- var d = collectedData && collectedData[name] || {};
690
- return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, name, {
691
- componentRef: componentRef,
692
- values: _objectSpread2(_objectSpread2({}, values), d)
693
- }));
694
- }, {});
695
- var EXTERNAL$1 = variables.filter(function (_ref3) {
696
- var variableType = _ref3.variableType;
697
- return variableType === EXTERNAL;
698
- }).reduce(function (_, v) {
699
- return _objectSpread2(_objectSpread2({}, _), initExternalVariable(v)(data));
700
- }, {});
701
- return {
702
- EXTERNAL: EXTERNAL$1,
703
- COLLECTED: collected,
704
- CALCULATED: variables.filter(function (_ref4) {
705
- var variableType = _ref4.variableType;
706
- return variableType === CALCULATED;
707
- }).reduce(function (_, v) {
708
- return _objectSpread2(_objectSpread2({}, _), initCalculatedVariable(v)(_objectSpread2(_objectSpread2({}, EXTERNAL$1), collected)));
709
- }, {})
710
- };
711
- };
712
- };
713
-
714
- var buildFilledComponents = function buildFilledComponents(vars) {
715
- return function (components) {
716
- return function (depth) {
717
- return components.map(function (c) {
718
- var component = _objectSpread2({
719
- depth: depth
720
- }, c);
721
-
722
- return buildFilledComponent(vars)(component);
723
- });
724
- };
725
- };
726
- };
727
-
728
- var buildFilledComponent = function buildFilledComponent(vars) {
729
- return function (component) {
730
- if (component.response) return buildResponseComponent(vars)(component);else if (component.responses) return buildResponsesComponent(vars)(component);else if (component.cells) return buildCellsComponent(vars)(component);else if (component.components) return buildComponentsComponent(vars)(component);
731
- return component;
732
- };
733
- };
734
- var buildResponseComponent = function buildResponseComponent(vars) {
735
- return function (c) {
736
- return _objectSpread2(_objectSpread2({}, c), {}, {
737
- response: {
738
- name: c.response.name,
739
- values: vars[c.response.name].values
740
- }
741
- });
742
- };
743
- };
744
- var buildResponsesComponent = function buildResponsesComponent(vars) {
745
- return function (c) {
746
- var responses = c.responses,
747
- rest = _objectWithoutProperties(c, ["responses"]);
748
-
749
- var filledResponses = responses.map(function (r) {
750
- return buildResponseComponent(vars)(r);
751
- });
752
- return _objectSpread2(_objectSpread2({}, rest), {}, {
753
- responses: filledResponses
754
- });
755
- };
756
- };
757
- var buildCellsComponent = function buildCellsComponent(vars) {
758
- return function (c) {
759
- var cells = c.cells,
760
- depth = c.depth,
761
- rest = _objectWithoutProperties(c, ["cells", "depth"]);
762
-
763
- var filledCells = cells.map(function (row) {
764
- return buildFilledComponents(vars)(row)(depth);
765
- });
766
- return _objectSpread2(_objectSpread2({}, rest), {}, {
767
- depth: depth,
768
- cells: filledCells
769
- });
770
- };
771
- };
772
- var buildComponentsComponent = function buildComponentsComponent(vars) {
773
- return function (component) {
774
- var components = component.components,
775
- depth = component.depth,
776
- rest = _objectWithoutProperties(component, ["components", "depth"]);
777
-
778
- var filledComponents = buildFilledComponents(vars)(components)(depth + 1);
779
- return _objectSpread2(_objectSpread2({}, rest), {}, {
780
- depth: depth,
781
- components: filledComponents
782
- });
783
- };
784
- };
785
-
786
- var initExternalVariable = function initExternalVariable(_ref5) {
787
- var name = _ref5.name;
788
- return function (data) {
789
- return _defineProperty({}, name, data && data.EXTERNAL && data.EXTERNAL[name] || null);
790
- };
791
- };
792
-
793
- var initCalculatedVariable = function initCalculatedVariable(_ref7) {
794
- var name = _ref7.name,
795
- expression = _ref7.expression;
796
- return function (data) {
797
- var bindings = Object.entries(data).reduce(function (acc, _ref8) {
798
- var _ref9 = _slicedToArray(_ref8, 2),
799
- key = _ref9[0],
800
- value = _ref9[1];
801
-
802
- return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, typeof value === 'string' || value === null ? value : value.values[COLLECTED]));
803
- }, {});
804
- return _defineProperty({}, name, {
805
- expression: expression,
806
- value: interpret(['VTL'])(bindings)(expression)
807
- });
808
- };
809
- };
810
-
811
- var supportedPreferences = [PREVIOUS, COLLECTED, FORCED, EDITED, INPUTED];
812
-
813
- var updateQuestionnaire = function updateQuestionnaire(valueType) {
814
- return function (questionnaire) {
815
- return function (preferences) {
816
- return function (updatedValues) {
817
- if (!supportedPreferences.includes(valueType) || preferences.length === 0 || !updatedValues) return questionnaire;
818
-
819
- var variables = questionnaire.variables,
820
- components = questionnaire.components,
821
- other = _objectWithoutProperties(questionnaire, ["variables", "components"]);
822
-
823
- if (!components || components.length === 0) return questionnaire;
824
- var varsAndRefs = Object.entries(updatedValues).reduce(function (acc, _ref) {
825
- var _ref2 = _slicedToArray(_ref, 2),
826
- key = _ref2[0],
827
- value = _ref2[1];
828
-
829
- var _acc$newVariables = acc.newVariables,
830
- COLLECTED = _acc$newVariables.COLLECTED,
831
- otherVars = _objectWithoutProperties(_acc$newVariables, ["COLLECTED"]),
832
- refs = acc.refs;
833
-
834
- var _COLLECTED$key = COLLECTED[key],
835
- componentRef = _COLLECTED$key.componentRef,
836
- values = _COLLECTED$key.values;
837
- var updated = {
838
- componentRef: componentRef,
839
- values: _objectSpread2(_objectSpread2({}, values), {}, _defineProperty({}, valueType, buildNewValue(preferences)(valueType)(values)(value)))
840
- };
841
-
842
- var newCollected = _objectSpread2(_objectSpread2({}, COLLECTED), {}, _defineProperty({}, key, updated));
843
-
844
- return {
845
- newVariables: _objectSpread2(_objectSpread2({}, otherVars), {}, {
846
- COLLECTED: newCollected
847
- }),
848
- refs: [].concat(_toConsumableArray(refs), [componentRef])
849
- };
850
- }, {
851
- newVariables: variables,
852
- refs: []
853
- });
854
- var newVariables = varsAndRefs.newVariables,
855
- r = varsAndRefs.refs;
856
- var newVariablesWithCalculated = valueType === COLLECTED ? addCalculatedVars(newVariables) : newVariables;
857
- var collectedVars = newVariables[COLLECTED];
858
- var newComponents = components.map(function (c) {
859
- if (r.includes(c.id)) return buildFilledComponent(collectedVars)(c);
860
- return c;
861
- });
862
- return _objectSpread2(_objectSpread2({}, other), {}, {
863
- variables: newVariablesWithCalculated,
864
- components: newComponents
865
- });
866
- };
867
- };
868
- };
869
- };
870
-
871
- var buildNewValue = function buildNewValue(preferences) {
872
- return function (valueType) {
873
- return function (oldValues) {
874
- return function (value) {
875
- if (preferences.length === 1) return value;
876
- var index = preferences.indexOf(valueType);
877
- if (index < 1) return value;
878
- var valuesByPreference = preferences.slice(0, index).map(function (p) {
879
- return oldValues[p];
880
- }).filter(function (v) {
881
- return v !== null;
882
- });
883
- var lastValue = valuesByPreference[valuesByPreference.length - 1];
884
- return lastValue === value ? null : value;
885
- };
886
- };
887
- };
888
- };
889
-
890
- var addCalculatedVars = function addCalculatedVars(variables) {
891
- if (!variables[CALCULATED] || Object.keys(variables[CALCULATED]).length === 0) return variables;
892
- var COLLECTED$1 = variables.COLLECTED,
893
- EXTERNAL = variables.EXTERNAL,
894
- CALCULATED$1 = variables.CALCULATED;
895
- var collected = Object.entries(COLLECTED$1).reduce(function (acc, _ref3) {
896
- var _ref4 = _slicedToArray(_ref3, 2),
897
- key = _ref4[0],
898
- values = _ref4[1].values;
899
-
900
- return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, values[COLLECTED]));
901
- }, {});
902
- var bindings = buildVectorialBindings(_objectSpread2(_objectSpread2({}, collected), EXTERNAL));
903
- var calculated = Object.entries(CALCULATED$1).reduce(function (acc, _ref5) {
904
- var _ref6 = _slicedToArray(_ref5, 2),
905
- key = _ref6[0],
906
- expression = _ref6[1].expression;
907
-
908
- // Assume that a calculated variable has a first level scope
909
- // If we need to handle deep calculated variables, we have to
910
- // update the shape of bindings, grouping vars by type
911
- var res = interpret(['VTL'])(bindings)(expression);
912
- var value = Array.isArray(res) ? res.join(',') : res;
913
- return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, {
914
- expression: expression,
915
- value: value
916
- }));
917
- }, {});
918
- return {
919
- EXTERNAL: EXTERNAL,
920
- COLLECTED: COLLECTED$1,
921
- CALCULATED: calculated
922
- };
923
- };
924
-
925
- var getState = function getState(questionnaire) {
926
- var _ref;
927
-
928
- var variables = questionnaire.variables;
929
- return _ref = {}, _defineProperty(_ref, CALCULATED, getCalculatedFromVariables(variables)), _defineProperty(_ref, COLLECTED, getCollectedState(questionnaire)), _defineProperty(_ref, EXTERNAL, getExternalFromVariables(variables)), _ref;
930
- };
931
- var getCollectedState = function getCollectedState(questionnaire) {
932
- var variables = questionnaire.variables;
933
- return variables && variables[COLLECTED] && Object.entries(variables[COLLECTED]).reduce(function (acc, _ref2) {
934
- var _ref3 = _slicedToArray(_ref2, 2),
935
- name = _ref3[0],
936
- values = _ref3[1].values;
937
-
938
- return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, name, values));
939
- }, {}) || {};
940
- };
941
-
942
- var getCalculatedFromVariables = function getCalculatedFromVariables(variables) {
943
- return variables && variables[CALCULATED] ? Object.entries(variables[CALCULATED]).reduce(function (_, _ref4) {
944
- var _ref5 = _slicedToArray(_ref4, 2),
945
- name = _ref5[0],
946
- value = _ref5[1].value;
947
-
948
- return _objectSpread2(_objectSpread2({}, _), {}, _defineProperty({}, name, value));
949
- }, {}) : {};
950
- };
951
-
952
- var getExternalFromVariables = function getExternalFromVariables(variables) {
953
- return variables && variables[EXTERNAL] || {};
954
- };
955
-
956
- var getCollectedStateByValueType = function getCollectedStateByValueType(questionnaire) {
957
- return function (valueType, displayNull) {
958
- return ['PREVIOUS', 'COLLECTED', 'FORCED', 'EDITED', 'INPUTED'].includes(valueType) ? Object.entries(getCollectedState(questionnaire)).reduce(function (_, v) {
959
- if (displayNull || v[1][valueType] !== null) return _objectSpread2(_objectSpread2({}, _), {}, _defineProperty({}, v[0], v[1][valueType]));
960
- return _;
961
- }, {}) : {};
962
- };
963
- };
964
- var getBindings = function getBindings(questionnaire) {
965
- var variables = questionnaire.variables;
966
- return _objectSpread2(_objectSpread2(_objectSpread2({}, getCollectedStateByValueType(questionnaire)('COLLECTED', true)), getCalculatedFromVariables(variables)), getExternalFromVariables(variables));
967
- };
968
-
969
- var filterComponents = function filterComponents(components, management, bindings, features) {
970
- return components.filter(function (_ref) {
971
- var conditionFilter = _ref.conditionFilter;
972
- return management || !conditionFilter ? true : interpret(features)(bindings, true)(conditionFilter) === 'normal';
973
- });
974
- };
975
-
976
- var useLunatic = function useLunatic(source, data, _ref2) {
977
- var _ref2$savingType = _ref2.savingType,
978
- savingType = _ref2$savingType === void 0 ? COLLECTED : _ref2$savingType,
979
- _ref2$preferences = _ref2.preferences,
980
- preferences = _ref2$preferences === void 0 ? [COLLECTED] : _ref2$preferences,
981
- _ref2$features = _ref2.features,
982
- features = _ref2$features === void 0 ? ['VTL'] : _ref2$features,
983
- _ref2$management = _ref2.management,
984
- management = _ref2$management === void 0 ? false : _ref2$management;
985
-
986
- var _useState = React.useState(mergeQuestionnaireAndData(source)(data || {})),
987
- _useState2 = _slicedToArray(_useState, 2),
988
- questionnaire = _useState2[0],
989
- setQuestionnaire = _useState2[1];
990
-
991
- var _useState3 = React.useState({}),
992
- _useState4 = _slicedToArray(_useState3, 2),
993
- todo = _useState4[0],
994
- setTodo = _useState4[1];
995
-
996
- var handleChange = React.useCallback(function (updatedValue) {
997
- setTodo(updatedValue);
998
- }, []);
999
- React.useEffect(function () {
1000
- if (Object.keys(todo).length !== 0) {
1001
- var newQ = updateQuestionnaire(savingType)(questionnaire)(preferences)(todo);
1002
- setQuestionnaire(newQ);
1003
- setTodo({});
1004
- }
1005
- }, [todo, preferences, questionnaire, savingType, features, management]);
1006
- var bindings = getBindings(questionnaire);
1007
- var components = filterComponents(questionnaire.components, management, bindings, features);
1008
- return {
1009
- questionnaire: questionnaire,
1010
- handleChange: handleChange,
1011
- components: components,
1012
- bindings: bindings
1013
- };
1014
- };
1015
-
1016
- var css_248z$2 = "@charset \"UTF-8\";\n.declaration-instruction {\n font-style: italic;\n font-size: 80%; }\n\n.declaration-comment {\n font-size: 80%; }\n\n.declaration-statement {\n font-style: italic;\n font-size: 80%;\n color: blue; }\n\n.declaration-help {\n font-style: italic;\n font-size: 80%;\n color: green; }\n\n.declaration-warning {\n font-style: bold;\n font-size: 80%;\n color: red; }\n\n.declaration-message_filter {\n font-size: 100%;\n color: #494242; }\n .declaration-message_filter:before {\n content: '→ '; }\n";
1017
- styleInject(css_248z$2);
1018
-
1019
- var Declarations = function Declarations(_ref) {
1020
- var id = _ref.id,
1021
- type = _ref.type,
1022
- declarations = _ref.declarations,
1023
- features = _ref.features,
1024
- bindings = _ref.bindings;
1025
- var filtered = declarations.filter(function (_ref2) {
1026
- var position = _ref2.position;
1027
- return position === type;
1028
- });
1029
- return /*#__PURE__*/React__default.createElement("div", {
1030
- id: "declarations-".concat(id, "-").concat(type),
1031
- className: "declarations-lunatic"
1032
- }, filtered.map(function (_ref3) {
1033
- var idD = _ref3.id,
1034
- label = _ref3.label,
1035
- declarationType = _ref3.declarationType;
1036
- return /*#__PURE__*/React__default.createElement("div", {
1037
- key: "".concat(idD),
1038
- className: "declaration-lunatic declaration-".concat(declarationType.toLowerCase())
1039
- }, interpret(features)(bindings)(label));
1040
- }));
1041
- };
1042
-
1043
- Declarations.defaultProps = {
1044
- type: 'AFTER_QUESTION_TEXT',
1045
- declarations: [],
1046
- features: [],
1047
- bindings: {}
1048
- };
1049
- Declarations.propTypes = {
1050
- id: PropTypes.string.isRequired,
1051
- type: PropTypes.string,
1052
- declarations: declarations,
1053
- features: PropTypes.arrayOf(PropTypes.string),
1054
- bindings: PropTypes.object
1055
- };
1056
-
1057
- var img = new Image(); img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAAGEMEXHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAABjUExURf///8Xn9XrH6Va44zKp3Eiy4GW+5b7j9Kja8Bme2CSj2p7W7vH5/UGv34XM69vw+czq9iCh2ZbT7bfg82W94+33/Njt92zB5k+14XPE6On2+4vN6sLl9Mno9i+n3Cum2wAAAIfAWccAAAAhdFJOU///////////////////////////////////////////AJ/B0CEAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAEVSURBVChTVVIBcsMgDFODm2JKIFnTbvv/Ryfb0F11Z4ptWYBSYL8wFBk34A7kLwDCUIbBfkcIHppsM2tIVy61exRoQ0LFaa2NhLSiP7l/MA7no6rsdd+UI5SINQSvZKVsBXSB7N4plnFRyihxxrFdtxeep5qwYRFZx1ZK6735IMrmJSQOZR9sXKWZSKeaVdQVfftOirdG8kHjhXlFxZ0ZWezpwrclo4Q69ZUWZj28BPyobmbCQPYxR6HdE53leLyBpGIGEELHP7GGtB/DIyds+mathZ/BEBefyNSRMJxDwRggcXbMlSlGsPM9uWHpgKnRgPB/zBCd/yStLB3z1hK6wO+8zn7o+7sx47v/s9oOdgdoLAD8AWlNC8M57XWRAAAAAElFTkSuQmCC';
1058
-
1059
- var img$1 = new Image(); img$1.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAZCAMAAAFiGY6DAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAABUUExURf///6zc8Uiy4PH5/d/x+b7j9Bme2DKp3CSj2la442W+5YnN61O34nrH6Z7W7tDr9yCh2bfg8+33/HPE6EGv35bT7U+14czq9nDD56XZ7+n2+wAAAJWny4EAAAAcdFJOU////////////////////////////////////wAXsuLXAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABKElEQVQoU2VSC3bDIAwzJRM0hCb0ldfd/6STDFm7TgnEX2GbGHExQ4PZoc0scT0MgC/6xkqZ+tC0x6y4E4zlU5VAs8I2Wrv0/PL/xzih4gKsCJVB1RZKsvXYrJntG7gXrM/ddgZ3JPDtBRHFSQYG1Ylgy9cUhStwdaGKO6tAdX0wCQi5tUyzK6oYYNHB+aDDBXhHcjtu09uHKgfTYGTUXMRDtCOU7HUU8ShH1CdWdj1FoS/3k+4vyB3Se6KV8tv6Bamm2Z3d+GWvuNmel4WC7A9+OUcV9AKr5PHEJHIxavjui4mOisf0/B7uiqwTrp9/gisa0wuycLTs3zlI2yl7QpTvDR8FlXy3jWq3hqBYjYpXPy/A7Lmu33GIMR1r3z6OPnFngYFXbfYDTw4LkdQNpj4AAAAASUVORK5CYII=';
1060
-
1061
- var img$2 = /*#__PURE__*/Object.freeze({
1062
- __proto__: null,
1063
- editedImg: img,
1064
- forcedImg: img$1
1065
- });
1066
-
1067
- var css_248z$3 = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n/* Tooltip container */\n.tooltip-lunatic {\n position: relative;\n display: inline-block;\n align-items: center; }\n\n/* Tooltip text */\n.tooltip-lunatic .tooltip-text {\n visibility: hidden;\n width: 20em;\n background-color: #e80a4d;\n color: #fff;\n padding: 5px 0;\n border-radius: 6px;\n text-align: left;\n /* Position the tooltip text */\n position: absolute;\n z-index: 1;\n bottom: 120%;\n left: -10em;\n /* Fade in tooltip */\n opacity: 0;\n transition: opacity 0.3s; }\n\n/* Show the tooltip text when you mouse over the tooltip container */\n.tooltip-lunatic:hover .tooltip-text {\n visibility: visible;\n opacity: 1; }\n";
1068
- styleInject(css_248z$3);
1069
-
1070
- var TooltipResponse = function TooltipResponse(_ref) {
1071
- var id = _ref.id,
1072
- response = _ref.response;
1073
-
1074
- var _useState = React.useState(function () {
1075
- return buildTooltip(response);
1076
- }),
1077
- _useState2 = _slicedToArray(_useState, 2),
1078
- tooltipElements = _useState2[0],
1079
- setTooltipElements = _useState2[1];
1080
-
1081
- React.useEffect(function () {
1082
- setTooltipElements(buildTooltip(response));
1083
- }, [response]);
1084
- var content = tooltipElements.content,
1085
- imgName = tooltipElements.imgName;
1086
- if (!content) return null;
1087
- return /*#__PURE__*/React__default.createElement("div", {
1088
- className: "tooltip-lunatic"
1089
- }, /*#__PURE__*/React__default.createElement("img", {
1090
- id: id,
1091
- alt: "img-tooltip",
1092
- src: img$2[imgName].src || img$2[imgName]
1093
- }), /*#__PURE__*/React__default.createElement("span", {
1094
- className: "tooltip-text"
1095
- }, /*#__PURE__*/React__default.createElement("ul", null, content.map(function (_ref2) {
1096
- var key = _ref2.key,
1097
- value = _ref2.value;
1098
- return /*#__PURE__*/React__default.createElement("li", {
1099
- key: "tooltip-".concat(id, "-content-").concat(key)
1100
- }, "".concat(key, " : ").concat(value));
1101
- }))));
1102
- };
1103
-
1104
- TooltipResponse.defaultProps = {
1105
- response: {}
1106
- };
1107
- TooltipResponse.propTypes = {
1108
- id: PropTypes.string,
1109
- response: response
1110
- };
1111
-
1112
- var css_248z$4 = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.checkbox-group {\n border: 0.1em solid #e80a4d; }\n\n.checkbox-lunatic {\n margin: 0;\n margin-right: 1em;\n margin-left: 1em;\n margin-top: 0.5em; }\n .checkbox-lunatic:focus {\n outline: none; }\n .checkbox-lunatic:checked + label {\n border: 0.1em solid #e80a4d;\n padding: 0.3em; }\n .checkbox-lunatic:focus {\n box-shadow: 0 0 0.3em 0.3em #e80a4d; }\n\n.checkbox-lunatic-no-margin {\n margin: 0;\n margin-right: 1em;\n margin-left: 0;\n margin-top: 0.5em; }\n .checkbox-lunatic-no-margin:focus {\n outline: none; }\n .checkbox-lunatic-no-margin:checked + label {\n border: 0.1em solid #e80a4d;\n padding: 0.3em; }\n\n.checkbox-modality {\n margin-top: 1em; }\n\n.checkbox-boolean-modality {\n margin-top: 1em; }\n\n.checkbox-alone {\n margin-left: 0;\n margin-top: 0.5em; }\n";
1113
- styleInject(css_248z$4);
1114
-
1115
- var CheckboxGroup = function CheckboxGroup(_ref) {
1116
- var id = _ref.id,
1117
- label = _ref.label,
1118
- preferences = _ref.preferences,
1119
- responses = _ref.responses,
1120
- handleChange = _ref.handleChange,
1121
- disabled = _ref.disabled,
1122
- focused = _ref.focused,
1123
- keyboardSelection = _ref.keyboardSelection,
1124
- positioning = _ref.positioning,
1125
- declarations = _ref.declarations,
1126
- features = _ref.features,
1127
- bindings = _ref.bindings,
1128
- management = _ref.management,
1129
- style = _ref.style;
1130
- var fieldsetStyle = style.fieldsetStyle,
1131
- modalityStyle = style.modalityStyle;
1132
- var inputRef = React.useRef();
1133
-
1134
- var specificHandleChange = function specificHandleChange(e) {
1135
- var _Object$entries$ = _slicedToArray(Object.entries(e)[0], 2),
1136
- key = _Object$entries$[0],
1137
- value = _Object$entries$[1];
1138
-
1139
- if (value === false && responsesToClean(responses)(preferences)(key)) handleChange(_defineProperty({}, key, null));else handleChange(e);
1140
- };
1141
-
1142
- React.useEffect(function () {
1143
- if (focused) inputRef.current.focus();
1144
- }, [focused]);
1145
- var checkedArray = [];
1146
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Declarations, {
1147
- id: id,
1148
- type: BEFORE_QUESTION_TEXT,
1149
- declarations: declarations,
1150
- features: features,
1151
- bindings: bindings
1152
- }), /*#__PURE__*/React__default.createElement("fieldset", {
1153
- key: "checkbox-".concat(id),
1154
- className: "checkbox-group",
1155
- style: buildStyleObject(fieldsetStyle)
1156
- }, /*#__PURE__*/React__default.createElement("legend", null, interpret(features)(bindings)(label)), /*#__PURE__*/React__default.createElement(Declarations, {
1157
- id: id,
1158
- type: AFTER_QUESTION_TEXT,
1159
- declarations: declarations,
1160
- features: features,
1161
- bindings: bindings
1162
- }), responses.map(function (_ref2, i) {
1163
- var modId = _ref2.id,
1164
- modLabel = _ref2.label,
1165
- response = _ref2.response;
1166
- var checked = getResponseByPreference(preferences)(response);
1167
- if (checked) checkedArray.push(modId);
1168
- var toRef = i === 0 || checkedArray[0] && checkedArray[0] === modId;
1169
- var interpretedLabel = interpret(features)(bindings)(modLabel);
1170
- return /*#__PURE__*/React__default.createElement("div", {
1171
- className: "".concat(getItemsPositioningClass(positioning)),
1172
- key: "checkbox-".concat(id, "-").concat(modId)
1173
- }, /*#__PURE__*/React__default.createElement("div", {
1174
- className: "field-container"
1175
- }, /*#__PURE__*/React__default.createElement("div", {
1176
- className: "".concat(management ? 'field-with-tooltip' : 'field')
1177
- }, /*#__PURE__*/React__default.createElement("div", {
1178
- className: "checkbox-modality ".concat(checked ? 'content-checked' : '')
1179
- }, /*#__PURE__*/React__default.createElement("input", {
1180
- type: "checkbox",
1181
- id: "checkbox-".concat(id, "-").concat(modId),
1182
- ref: toRef ? inputRef : null,
1183
- key: "checkbox-".concat(id, "-").concat(modId),
1184
- "aria-labelledby": "input-label-".concat(id, "-").concat(modId),
1185
- className: "checkbox-lunatic",
1186
- checked: checked,
1187
- disabled: disabled,
1188
- onChange: function onChange(e) {
1189
- specificHandleChange(_defineProperty({}, getResponseName(response), e.target.checked));
1190
- }
1191
- }), /*#__PURE__*/React__default.createElement("label", {
1192
- htmlFor: "checkbox-".concat(id, "-").concat(modId),
1193
- id: "input-label-".concat(id, "-").concat(modId),
1194
- style: checked ? buildStyleObject(modalityStyle) : {}
1195
- }, keyboardSelection ? "".concat(getAlphabet()[i].toUpperCase(), " - ").concat(interpretedLabel) : interpretedLabel))), management && /*#__PURE__*/React__default.createElement("div", {
1196
- className: "tooltip"
1197
- }, /*#__PURE__*/React__default.createElement(TooltipResponse, {
1198
- id: id,
1199
- response: buildBooleanTooltipResponse(response)
1200
- }))));
1201
- })), /*#__PURE__*/React__default.createElement(Declarations, {
1202
- id: id,
1203
- type: DETACHABLE,
1204
- declarations: declarations,
1205
- features: features,
1206
- bindings: bindings
1207
- }));
1208
- };
1209
-
1210
- CheckboxGroup.defaultProps = {
1211
- label: '',
1212
- preferences: ['COLLECTED'],
1213
- responses: [],
1214
- disabled: false,
1215
- focused: false,
1216
- keyboardSelection: false,
1217
- positioning: 'DEFAULT',
1218
- declarations: [],
1219
- features: [],
1220
- bindings: {},
1221
- management: false,
1222
- style: {
1223
- fieldsetStyle: {},
1224
- modalityStyle: {}
1225
- }
1226
- };
1227
- CheckboxGroup.propTypes = {
1228
- id: PropTypes.string.isRequired,
1229
- label: PropTypes.string,
1230
- preferences: PropTypes.arrayOf(valueType),
1231
- response: response,
1232
- handleChange: PropTypes.func.isRequired,
1233
- disabled: PropTypes.bool,
1234
- focused: PropTypes.bool,
1235
- keyboardSelection: PropTypes.bool,
1236
- positioning: PropTypes.oneOf(['DEFAULT', 'HORIZONTAL', 'VERTICAL']),
1237
- declarations: declarations,
1238
- features: PropTypes.arrayOf(PropTypes.string),
1239
- bindings: PropTypes.object,
1240
- management: PropTypes.bool,
1241
- style: PropTypes.object
1242
- };
1243
- var group = /*#__PURE__*/React__default.memo(CheckboxGroup, areEqual);
1244
-
1245
- var CheckboxBoolean = function CheckboxBoolean(_ref) {
1246
- var id = _ref.id,
1247
- label = _ref.label,
1248
- preferences = _ref.preferences,
1249
- response = _ref.response,
1250
- handleChange = _ref.handleChange,
1251
- disabled = _ref.disabled,
1252
- positioning = _ref.positioning,
1253
- focused = _ref.focused,
1254
- declarations = _ref.declarations,
1255
- features = _ref.features,
1256
- bindings = _ref.bindings,
1257
- management = _ref.management,
1258
- style = _ref.style;
1259
- var inputRef = React.useRef();
1260
-
1261
- var specificHandleChange = function specificHandleChange(e) {
1262
- var _Object$entries$ = _slicedToArray(Object.entries(e)[0], 2),
1263
- key = _Object$entries$[0],
1264
- value = _Object$entries$[1];
1265
-
1266
- if (value === false && responseToClean(response)(preferences)) handleChange(_defineProperty({}, key, null));else handleChange(e);
1267
- };
1268
-
1269
- React.useEffect(function () {
1270
- if (focused) inputRef.current.focus();
1271
- }, [focused]);
1272
- var isVertical = positioning === 'VERTICAL';
1273
- var isHorizontal = positioning === 'HORIZONTAL';
1274
- var input = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("input", {
1275
- type: "checkbox",
1276
- id: "checkbox-boolean-".concat(id),
1277
- ref: inputRef,
1278
- title: label ? label : 'empty-label',
1279
- className: "checkbox-boolean-lunatic".concat(isVertical ? '-no-margin' : ''),
1280
- style: buildStyleObject(style),
1281
- checked: getResponseByPreference(preferences)(response),
1282
- disabled: disabled,
1283
- onChange: function onChange(e) {
1284
- specificHandleChange(_defineProperty({}, getResponseName(response), e.target.checked));
1285
- }
1286
- }), label && /*#__PURE__*/React__default.createElement("label", {
1287
- htmlFor: "checkbox-boolean-".concat(id)
1288
- }, isHorizontal ? interpret(features)(bindings)(label) : ''));
1289
- return /*#__PURE__*/React__default.createElement("div", {
1290
- key: "checkbox-boolean-".concat(id),
1291
- className: "checkbox-boolean-modality"
1292
- }, /*#__PURE__*/React__default.createElement(Declarations, {
1293
- id: id,
1294
- type: BEFORE_QUESTION_TEXT,
1295
- declarations: declarations,
1296
- features: features,
1297
- bindings: bindings
1298
- }), label && !isHorizontal && /*#__PURE__*/React__default.createElement("label", {
1299
- htmlFor: "checkbox-boolean-".concat(id)
1300
- }, interpret(features)(bindings)(label)), /*#__PURE__*/React__default.createElement(Declarations, {
1301
- id: id,
1302
- type: AFTER_QUESTION_TEXT,
1303
- declarations: declarations,
1304
- features: features,
1305
- bindings: bindings
1306
- }), /*#__PURE__*/React__default.createElement("div", {
1307
- className: "field-container"
1308
- }, /*#__PURE__*/React__default.createElement("div", {
1309
- className: "".concat(management ? 'field-with-tooltip' : 'field')
1310
- }, isVertical ? /*#__PURE__*/React__default.createElement("div", null, input) : input), management && /*#__PURE__*/React__default.createElement("div", {
1311
- className: "tooltip"
1312
- }, /*#__PURE__*/React__default.createElement(TooltipResponse, {
1313
- id: id,
1314
- response: buildBooleanTooltipResponse(response)
1315
- }))), /*#__PURE__*/React__default.createElement(Declarations, {
1316
- id: id,
1317
- type: DETACHABLE,
1318
- declarations: declarations,
1319
- features: features,
1320
- bindings: bindings
1321
- }));
1322
- };
1323
-
1324
- CheckboxBoolean.defaultProps = {
1325
- label: '',
1326
- preferences: ['COLLECTED'],
1327
- response: {},
1328
- disabled: false,
1329
- positioning: 'DEFAULT',
1330
- focused: false,
1331
- declarations: [],
1332
- features: [],
1333
- bindings: {},
1334
- management: false,
1335
- style: {}
1336
- };
1337
- CheckboxBoolean.propTypes = {
1338
- id: PropTypes.string.isRequired,
1339
- label: PropTypes.string,
1340
- preferences: PropTypes.arrayOf(valueType),
1341
- response: response,
1342
- handleChange: PropTypes.func.isRequired,
1343
- disabled: PropTypes.bool,
1344
- positioning: PropTypes.oneOf(['DEFAULT', 'HORIZONTAL', 'VERTICAL']),
1345
- focused: PropTypes.bool,
1346
- declarations: declarations,
1347
- features: PropTypes.arrayOf(PropTypes.string),
1348
- bindings: PropTypes.object,
1349
- management: PropTypes.bool,
1350
- style: PropTypes.object
1351
- };
1352
- var boolean = /*#__PURE__*/React__default.memo(CheckboxBoolean, areEqual);
1353
-
1354
- var InputDeclarationsWrapper = function InputDeclarationsWrapper(_ref) {
1355
- var id = _ref.id,
1356
- label = _ref.label,
1357
- preferences = _ref.preferences,
1358
- response = _ref.response,
1359
- placeholder = _ref.placeholder,
1360
- handleChange = _ref.handleChange,
1361
- maxLength = _ref.maxLength,
1362
- readOnly = _ref.readOnly,
1363
- disabled = _ref.disabled,
1364
- autoComplete = _ref.autoComplete,
1365
- labelPosition = _ref.labelPosition,
1366
- mandatory = _ref.mandatory,
1367
- declarations = _ref.declarations,
1368
- features = _ref.features,
1369
- bindings = _ref.bindings,
1370
- focused = _ref.focused,
1371
- management = _ref.management,
1372
- style = _ref.style,
1373
- type = _ref.type,
1374
- roleType = _ref.roleType;
1375
- var inputRef = React.useRef();
1376
-
1377
- var _useState = React.useState(function () {
1378
- return getResponseByPreference(preferences)(response);
1379
- }),
1380
- _useState2 = _slicedToArray(_useState, 2),
1381
- value = _useState2[0],
1382
- setValue = _useState2[1];
1383
-
1384
- React.useEffect(function () {
1385
- if (focused) inputRef.current.focus();
1386
- }, [focused]);
1387
- React.useEffect(function () {
1388
- return setValue(getResponseByPreference(preferences)(response));
1389
- }, [response, preferences]);
1390
-
1391
- var _onChange = debounce.debounce(function (v) {
1392
- handleChange(_defineProperty({}, getResponseName(response), v));
1393
- }, 200);
1394
-
1395
- var Component = roleType === 'textarea' ? 'textarea' : 'input';
1396
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Declarations, {
1397
- id: id,
1398
- type: BEFORE_QUESTION_TEXT,
1399
- declarations: declarations,
1400
- features: features,
1401
- bindings: bindings
1402
- }), /*#__PURE__*/React__default.createElement("div", {
1403
- className: getLabelPositionClass(labelPosition)
1404
- }, label && /*#__PURE__*/React__default.createElement("label", {
1405
- htmlFor: "".concat(roleType, "-").concat(id),
1406
- id: "".concat(roleType, "-label-").concat(id),
1407
- className: "".concat(mandatory ? 'mandatory' : '')
1408
- }, interpret(features)(bindings)(label)), /*#__PURE__*/React__default.createElement(Declarations, {
1409
- id: id,
1410
- type: AFTER_QUESTION_TEXT,
1411
- declarations: declarations,
1412
- features: features,
1413
- bindings: bindings
1414
- }), /*#__PURE__*/React__default.createElement("div", {
1415
- className: "field-container"
1416
- }, /*#__PURE__*/React__default.createElement("div", {
1417
- className: "".concat(management ? 'field-with-tooltip' : 'field')
1418
- }, /*#__PURE__*/React__default.createElement(Component, {
1419
- type: type,
1420
- id: "".concat(roleType, "-").concat(id),
1421
- ref: inputRef,
1422
- value: value,
1423
- placeholder: placeholder,
1424
- autoComplete: autoComplete ? 'on' : 'off',
1425
- className: "".concat(roleType, "-lunatic"),
1426
- style: buildStyleObject(style),
1427
- readOnly: readOnly,
1428
- disabled: disabled,
1429
- maxLength: maxLength || 524288,
1430
- required: mandatory,
1431
- "aria-required": mandatory,
1432
- onChange: function onChange(_ref2) {
1433
- var v = _ref2.target.value;
1434
- setValue(v);
1435
-
1436
- _onChange(v);
1437
- }
1438
- })), management && /*#__PURE__*/React__default.createElement("div", {
1439
- className: "tooltip"
1440
- }, /*#__PURE__*/React__default.createElement(TooltipResponse, {
1441
- id: id,
1442
- response: response
1443
- })))), /*#__PURE__*/React__default.createElement(Declarations, {
1444
- id: id,
1445
- type: DETACHABLE,
1446
- declarations: declarations,
1447
- features: features,
1448
- bindings: bindings
1449
- }));
1450
- };
1451
-
1452
- InputDeclarationsWrapper.defaultProps = {
1453
- label: '',
1454
- preferences: ['COLLECTED'],
1455
- response: {},
1456
- placeholder: '',
1457
- readOnly: false,
1458
- disabled: false,
1459
- autoComplete: false,
1460
- labelPosition: 'DEFAULT',
1461
- mandatory: false,
1462
- focused: false,
1463
- declarations: [],
1464
- features: [],
1465
- bindings: {},
1466
- management: false,
1467
- style: {}
1468
- };
1469
- InputDeclarationsWrapper.propTypes = {
1470
- id: PropTypes.string.isRequired,
1471
- label: PropTypes.string,
1472
- preferences: PropTypes.arrayOf(valueType),
1473
- response: response,
1474
- placeholder: PropTypes.string,
1475
- handleChange: PropTypes.func.isRequired,
1476
- readOnly: PropTypes.bool,
1477
- disabled: PropTypes.bool,
1478
- maxLength: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
1479
- autoComplete: PropTypes.bool,
1480
- labelPosition: PropTypes.oneOf(['DEFAULT', 'TOP', 'BOTTOM', 'LEFT', 'RIGHT']),
1481
- mandatory: PropTypes.bool,
1482
- focused: PropTypes.bool,
1483
- declarations: declarations,
1484
- features: PropTypes.arrayOf(PropTypes.string),
1485
- bindings: PropTypes.object,
1486
- management: PropTypes.bool,
1487
- style: PropTypes.object,
1488
- type: PropTypes.oneOf(['text', 'date', null]),
1489
- roleType: PropTypes.oneOf(['input', 'datepicker', 'textarea'])
1490
- };
1491
-
1492
- var ListDeclarationsWrapper = function ListDeclarationsWrapper(_ref) {
1493
- var id = _ref.id,
1494
- label = _ref.label,
1495
- preferences = _ref.preferences,
1496
- response = _ref.response,
1497
- options = _ref.options,
1498
- handleChange = _ref.handleChange,
1499
- disabled = _ref.disabled,
1500
- focused = _ref.focused,
1501
- keyboardSelection = _ref.keyboardSelection,
1502
- declarations = _ref.declarations,
1503
- features = _ref.features,
1504
- bindings = _ref.bindings,
1505
- management = _ref.management,
1506
- style = _ref.style,
1507
- positioning = _ref.positioning,
1508
- type = _ref.type;
1509
- var inputRef = React.useRef();
1510
- React.useEffect(function () {
1511
- if (focused) inputRef.current.focus();
1512
- }, [focused]);
1513
- var fieldsetStyle = style.fieldsetStyle,
1514
- modalityStyle = style.modalityStyle;
1515
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Declarations, {
1516
- id: id,
1517
- type: BEFORE_QUESTION_TEXT,
1518
- declarations: declarations,
1519
- features: features,
1520
- bindings: bindings
1521
- }), /*#__PURE__*/React__default.createElement("div", {
1522
- className: "field-container"
1523
- }, /*#__PURE__*/React__default.createElement("div", {
1524
- className: "".concat(management ? 'field-with-tooltip' : 'field')
1525
- }, /*#__PURE__*/React__default.createElement("fieldset", {
1526
- key: "".concat(type, "-").concat(id),
1527
- className: "".concat(type, "-group"),
1528
- style: buildStyleObject(fieldsetStyle)
1529
- }, /*#__PURE__*/React__default.createElement("legend", null, interpret(features)(bindings)(label)), /*#__PURE__*/React__default.createElement(Declarations, {
1530
- id: id,
1531
- type: AFTER_QUESTION_TEXT,
1532
- declarations: declarations,
1533
- features: features,
1534
- bindings: bindings
1535
- }), options.map(function (_ref2, i) {
1536
- var optionLabel = _ref2.label,
1537
- optionValue = _ref2.value;
1538
- var checked = getResponseByPreference(preferences)(response) === optionValue;
1539
- var interpretedLabel = interpret(features)(bindings)(optionLabel);
1540
- return /*#__PURE__*/React__default.createElement("div", {
1541
- key: "".concat(type, "-").concat(id, "-").concat(optionValue),
1542
- className: "".concat(type, "-modality ").concat(getItemsPositioningClass(positioning))
1543
- }, /*#__PURE__*/React__default.createElement("input", {
1544
- type: type,
1545
- name: "".concat(type, "-").concat(id),
1546
- ref: i === 0 || checked ? inputRef : null,
1547
- id: "".concat(type, "-").concat(id, "-").concat(optionValue),
1548
- "aria-labelledby": "input-label-".concat(id, "-").concat(optionValue),
1549
- className: "".concat(type, "-lunatic"),
1550
- style: buildStyleObject(style),
1551
- checked: checked,
1552
- disabled: disabled,
1553
- onChange: function onChange() {
1554
- return handleChange(_defineProperty({}, getResponseName(response), optionValue));
1555
- }
1556
- }), /*#__PURE__*/React__default.createElement("label", {
1557
- htmlFor: "".concat(type, "-").concat(id, "-").concat(optionValue),
1558
- id: "input-label-".concat(id, "-").concat(optionValue),
1559
- style: checked ? buildStyleObject(modalityStyle) : {}
1560
- }, keyboardSelection ? "".concat(getAlphabet()[i].toUpperCase(), " - ").concat(interpretedLabel) : interpretedLabel));
1561
- }))), management && /*#__PURE__*/React__default.createElement("div", {
1562
- className: "tooltip"
1563
- }, /*#__PURE__*/React__default.createElement(TooltipResponse, {
1564
- id: id,
1565
- response: buildMultiTooltipResponse(options)(response)
1566
- }))), /*#__PURE__*/React__default.createElement(Declarations, {
1567
- id: id,
1568
- type: DETACHABLE,
1569
- declarations: declarations,
1570
- features: features,
1571
- bindings: bindings
1572
- }));
1573
- };
1574
-
1575
- ListDeclarationsWrapper.defaultProps = {
1576
- label: '',
1577
- preferences: ['COLLECTED'],
1578
- response: {},
1579
- options: [],
1580
- disabled: false,
1581
- focused: false,
1582
- keyboardSelection: false,
1583
- positioning: 'DEFAULT',
1584
- declarations: [],
1585
- features: [],
1586
- bindings: {},
1587
- management: false,
1588
- style: {
1589
- fieldsetStyle: {},
1590
- modalityStyle: {}
1591
- }
1592
- };
1593
- ListDeclarationsWrapper.propTypes = {
1594
- id: PropTypes.string.isRequired,
1595
- label: PropTypes.string,
1596
- preferences: PropTypes.arrayOf(valueType),
1597
- response: response,
1598
- options: options,
1599
- handleChange: PropTypes.func.isRequired,
1600
- disabled: PropTypes.bool,
1601
- focused: PropTypes.bool,
1602
- keyboardSelection: PropTypes.bool,
1603
- positioning: PropTypes.oneOf(['DEFAULT', 'HORIZONTAL', 'VERTICAL']),
1604
- declarations: declarations,
1605
- features: PropTypes.arrayOf(PropTypes.string),
1606
- bindings: PropTypes.object,
1607
- management: PropTypes.bool,
1608
- style: PropTypes.object,
1609
- type: PropTypes.oneOf(['radio', 'checkbox'])
1610
- };
1611
-
1612
- var SimpleDeclarationsWrapper = function SimpleDeclarationsWrapper(_ref) {
1613
- var id = _ref.id,
1614
- declarations = _ref.declarations,
1615
- features = _ref.features,
1616
- bindings = _ref.bindings,
1617
- children = _ref.children;
1618
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Declarations, {
1619
- id: id,
1620
- type: BEFORE_QUESTION_TEXT,
1621
- declarations: declarations,
1622
- features: features,
1623
- bindings: bindings
1624
- }), children, /*#__PURE__*/React__default.createElement(Declarations, {
1625
- id: id,
1626
- type: AFTER_QUESTION_TEXT,
1627
- declarations: declarations,
1628
- features: features,
1629
- bindings: bindings
1630
- }), /*#__PURE__*/React__default.createElement(Declarations, {
1631
- id: id,
1632
- type: DETACHABLE,
1633
- declarations: declarations,
1634
- features: features,
1635
- bindings: bindings
1636
- }));
1637
- };
1638
-
1639
- SimpleDeclarationsWrapper.defaultProps = {
1640
- declarations: [],
1641
- features: [],
1642
- bindings: {}
1643
- };
1644
- SimpleDeclarationsWrapper.propTypes = {
1645
- id: PropTypes.string.isRequired,
1646
- declarations: declarations,
1647
- features: PropTypes.arrayOf(PropTypes.string),
1648
- bindings: PropTypes.object,
1649
- children: PropTypes.element.isRequired
1650
- };
1651
-
1652
- var CheckboxOne = function CheckboxOne(props) {
1653
- var specificHandleChange = function specificHandleChange(e) {
1654
- var preferences = props.preferences,
1655
- values = props.response.values,
1656
- handleChange = props.handleChange;
1657
-
1658
- var _Object$entries$ = _slicedToArray(Object.entries(e)[0], 2),
1659
- key = _Object$entries$[0],
1660
- value = _Object$entries$[1];
1661
-
1662
- if (values[preferences[preferences.length - 1]] === value) handleChange(_defineProperty({}, key, null));else handleChange(e);
1663
- };
1664
-
1665
- return /*#__PURE__*/React__default.createElement(ListDeclarationsWrapper, _extends({
1666
- type: "checkbox"
1667
- }, props, {
1668
- handleChange: specificHandleChange
1669
- }));
1670
- };
1671
-
1672
- var one = /*#__PURE__*/React__default.memo(CheckboxOne, areEqual);
1673
-
1674
- var css_248z$5 = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.datepicker-lunatic {\n width: 100%;\n box-sizing: border-box;\n border: solid 2px #e80a4d;\n border-radius: 10px;\n padding: 5px; }\n .datepicker-lunatic:focus {\n outline: none;\n box-shadow: 0 0 10px #e80a4d; }\n .datepicker-lunatic:read-only {\n background-color: #ebebe4; }\n";
1675
- styleInject(css_248z$5);
1676
-
1677
- var Datepicker = function Datepicker(props) {
1678
- return /*#__PURE__*/React__default.createElement(InputDeclarationsWrapper, _extends({
1679
- type: "date",
1680
- roleType: "datepicker"
1681
- }, props));
1682
- };
1683
-
1684
- var component = /*#__PURE__*/React__default.memo(Datepicker, areEqual);
1685
-
1686
- function createCommonjsModule(fn, module) {
1687
- return module = { exports: {} }, fn(module, module.exports), module.exports;
1688
- }
1689
-
1690
- var classnames = createCommonjsModule(function (module) {
1691
- /*!
1692
- Copyright (c) 2017 Jed Watson.
1693
- Licensed under the MIT License (MIT), see
1694
- http://jedwatson.github.io/classnames
1695
- */
1696
- /* global define */
1697
-
1698
- (function () {
1699
-
1700
- var hasOwn = {}.hasOwnProperty;
1701
-
1702
- function classNames () {
1703
- var classes = [];
1704
-
1705
- for (var i = 0; i < arguments.length; i++) {
1706
- var arg = arguments[i];
1707
- if (!arg) continue;
1708
-
1709
- var argType = typeof arg;
1710
-
1711
- if (argType === 'string' || argType === 'number') {
1712
- classes.push(arg);
1713
- } else if (Array.isArray(arg) && arg.length) {
1714
- var inner = classNames.apply(null, arg);
1715
- if (inner) {
1716
- classes.push(inner);
1717
- }
1718
- } else if (argType === 'object') {
1719
- for (var key in arg) {
1720
- if (hasOwn.call(arg, key) && arg[key]) {
1721
- classes.push(key);
1722
- }
1723
- }
1724
- }
1725
- }
1726
-
1727
- return classes.join(' ');
1728
- }
1729
-
1730
- if ( module.exports) {
1731
- classNames.default = classNames;
1732
- module.exports = classNames;
1733
- } else {
1734
- window.classNames = classNames;
1735
- }
1736
- }());
1737
- });
1738
-
1739
- var SHOW_PANEL = "dropdown/show-panel";
1740
- var showPanel = function showPanel() {
1741
- return {
1742
- type: SHOW_PANEL
1743
- };
1744
- };
1745
- var HIDE_PANEL = "dropdown/hide-panel";
1746
- var hidePanel = function hidePanel() {
1747
- return {
1748
- type: HIDE_PANEL
1749
- };
1750
- };
1751
- var SET_ACTIVE_OPTION = "dropdown/set-active-option";
1752
- var setActiveOption = function setActiveOption(index) {
1753
- return {
1754
- type: SET_ACTIVE_OPTION,
1755
- payload: {
1756
- index: index
1757
- }
1758
- };
1759
- };
1760
- var SET_OPTIONS = "dropdown/set-options";
1761
- var setOptions = function setOptions(options) {
1762
- return {
1763
- type: SET_OPTIONS,
1764
- payload: {
1765
- options: options
1766
- }
1767
- };
1768
- };
1769
- var SET_VALUE = "dropdown/set-value";
1770
- var setValue = function setValue(value) {
1771
- return {
1772
- type: SET_VALUE,
1773
- payload: {
1774
- value: value
1775
- }
1776
- };
1777
- };
1778
- var SET_FOCUSED = "dropdown/set-focused";
1779
- var setFocused = function setFocused(focused) {
1780
- return {
1781
- type: SET_FOCUSED,
1782
- payload: {
1783
- focused: focused
1784
- }
1785
- };
1786
- };
1787
- var SET_SELECTED_OPTION = "dropdown/set-selectted-option";
1788
- var setSelectedOption = function setSelectedOption(option) {
1789
- return {
1790
- type: SET_SELECTED_OPTION,
1791
- payload: {
1792
- option: option
1793
- }
1794
- };
1795
- };
1796
- var RESET_SELECTION = "dropdown/reset-selection";
1797
- var resetSelection = function resetSelection(option) {
1798
- return {
1799
- type: RESET_SELECTION
1800
- };
1801
- };
1802
- /* */
1803
-
1804
- var ARROW_UP_PRESSED = "dropdown/arrow-up-ressed";
1805
- var arrowUpPressed = function arrowUpPressed() {
1806
- return {
1807
- type: ARROW_UP_PRESSED
1808
- };
1809
- };
1810
- /* */
1811
-
1812
- var ARROW_DOWN_PRESSED = "dropdown/arrow-down-pressed";
1813
- var arrowDownPressed = function arrowDownPressed() {
1814
- return {
1815
- type: ARROW_DOWN_PRESSED
1816
- };
1817
- };
1818
- /* */
1819
-
1820
- var ENTER_PRESSED = "dropdown/enter-pressed";
1821
- var enterPressed = function enterPressed(callback) {
1822
- return {
1823
- type: ENTER_PRESSED,
1824
- payload: {
1825
- callback: callback
1826
- }
1827
- };
1828
- };
1829
- /* */
1830
-
1831
- var SET_PREFIX = "dropdown/set-prefix";
1832
- var setPrefix = function setPrefix(prefix) {
1833
- return {
1834
- type: SET_PREFIX,
1835
- payload: {
1836
- prefix: prefix
1837
- }
1838
- };
1839
- };
1840
-
1841
- /**
1842
- *
1843
- */
1844
-
1845
- function Panel(_ref) {
1846
- var _ref$options = _ref.options,
1847
- options = _ref$options === void 0 ? [] : _ref$options,
1848
- display = _ref.display,
1849
- handleActive = _ref.handleActive,
1850
- prefix = _ref.prefix,
1851
- activeIndex = _ref.activeIndex,
1852
- selectedOption = _ref.selectedOption,
1853
- onSelect = _ref.onSelect,
1854
- idDropdown = _ref.idDropdown,
1855
- Option = _ref.optionComponent;
1856
- var ulRef = React.useRef();
1857
- return display ? /*#__PURE__*/React__default.createElement("div", {
1858
- className: "lunatic-dropdown-panel-container"
1859
- }, /*#__PURE__*/React__default.createElement("ul", {
1860
- className: "lunatic-dropdown-panel",
1861
- ref: ulRef,
1862
- tabIndex: "-1"
1863
- }, options.map(function (_ref2, index) {
1864
- var label = _ref2.label,
1865
- value = _ref2.value;
1866
- return /*#__PURE__*/React__default.createElement("li", {
1867
- key: value,
1868
- id: "".concat(idDropdown, "-option-").concat(value),
1869
- onMouseEnter: function onMouseEnter() {
1870
- return handleActive(index);
1871
- },
1872
- onMouseDown: function onMouseDown(e) {
1873
- e.stopPropagation();
1874
- e.preventDefault();
1875
-
1876
- if (e.button === 0) {
1877
- onSelect({
1878
- label: label,
1879
- value: value
1880
- });
1881
- }
1882
- }
1883
- }, /*#__PURE__*/React__default.createElement(Option, {
1884
- label: label,
1885
- value: value,
1886
- prefix: prefix,
1887
- active: activeIndex === index,
1888
- selected: selectedOption && selectedOption.value === value
1889
- }));
1890
- }))) : null;
1891
- }
1892
-
1893
- var propTypesOption = PropTypes.shape({
1894
- label: PropTypes.string,
1895
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.number, PropTypes.symbol, PropTypes.bool])
1896
- });
1897
- Panel.propTypes = {
1898
- idDropdown: PropTypes.string.isRequired,
1899
- prefix: PropTypes.string,
1900
- onSelect: PropTypes.func,
1901
- handleActive: PropTypes.func.isRequired,
1902
- activeIndex: PropTypes.number,
1903
- selectedOption: propTypesOption,
1904
- display: PropTypes.bool.isRequired,
1905
- options: PropTypes.arrayOf(propTypesOption)
1906
- };
1907
- Panel.defaultProps = {
1908
- options: [],
1909
- onSelect: function onSelect() {
1910
- return null;
1911
- },
1912
- selectedOption: undefined
1913
- };
1914
-
1915
- function Icon(_ref) {
1916
- var _ref$height = _ref.height,
1917
- height = _ref$height === void 0 ? 20 : _ref$height,
1918
- _ref$width = _ref.width,
1919
- width = _ref$width === void 0 ? 20 : _ref$width,
1920
- _ref$color = _ref.color,
1921
- color = _ref$color === void 0 ? "#aaa" : _ref$color;
1922
- return /*#__PURE__*/React__default.createElement("svg", {
1923
- xmlns: "http://www.w3.org/2000/svg",
1924
- width: width,
1925
- height: height,
1926
- x: "0",
1927
- y: "0",
1928
- enableBackground: "new 0 0 292.362 292.362",
1929
- version: "1.1",
1930
- viewBox: "0 0 292.362 292.362",
1931
- xmlSpace: "preserve"
1932
- }, /*#__PURE__*/React__default.createElement("path", {
1933
- fill: color,
1934
- d: "M286.935 69.377c-3.614-3.617-7.898-5.424-12.848-5.424H18.274c-4.952 0-9.233 1.807-12.85 5.424C1.807 72.998 0 77.279 0 82.228c0 4.948 1.807 9.229 5.424 12.847l127.907 127.907c3.621 3.617 7.902 5.428 12.85 5.428s9.233-1.811 12.847-5.428L286.935 95.074c3.613-3.617 5.427-7.898 5.427-12.847 0-4.948-1.814-9.229-5.427-12.85z"
1935
- }));
1936
- }
1937
-
1938
- function Icon$1(_ref) {
1939
- var _ref$height = _ref.height,
1940
- height = _ref$height === void 0 ? 20 : _ref$height,
1941
- _ref$width = _ref.width,
1942
- width = _ref$width === void 0 ? 20 : _ref$width,
1943
- _ref$color = _ref.color,
1944
- color = _ref$color === void 0 ? "#aaa" : _ref$color;
1945
- return /*#__PURE__*/React__default.createElement("svg", {
1946
- xmlns: "http://www.w3.org/2000/svg",
1947
- width: width,
1948
- height: height,
1949
- x: "0",
1950
- y: "0",
1951
- enableBackground: "new 0 0 292.362 292.362",
1952
- version: "1.1",
1953
- viewBox: "0 0 292.362 292.362",
1954
- xmlSpace: "preserve"
1955
- }, /*#__PURE__*/React__default.createElement("path", {
1956
- fill: color,
1957
- d: "M286.935 197.286L159.028 69.379c-3.613-3.617-7.895-5.424-12.847-5.424s-9.233 1.807-12.85 5.424L5.424 197.286C1.807 200.9 0 205.184 0 210.132s1.807 9.233 5.424 12.847c3.621 3.617 7.902 5.428 12.85 5.428h255.813c4.949 0 9.233-1.811 12.848-5.428 3.613-3.613 5.427-7.898 5.427-12.847s-1.814-9.232-5.427-12.846z"
1958
- }));
1959
- }
1960
-
1961
- var Label = function Label(_ref) {
1962
- var content = _ref.content,
1963
- focused = _ref.focused,
1964
- mandatory = _ref.mandatory;
1965
- return /*#__PURE__*/React__default.createElement("div", {
1966
- className: classnames('lunatic-dropdown-label', {
1967
- focused: focused,
1968
- mandatory: mandatory
1969
- })
1970
- }, content);
1971
- };
1972
-
1973
- Label.defaultProps = {
1974
- mandatory: false
1975
- };
1976
- Label.propTypes = {
1977
- content: PropTypes.string.isRequired,
1978
- focused: PropTypes.bool.isRequired,
1979
- mandatory: PropTypes.bool
1980
- };
1981
-
1982
- var CLEANER_CALLBACKS = {};
1983
- /**
1984
- *
1985
- * @param {...any} execpt identifiants de dropdownn a ne pas appliquer
1986
- */
1987
-
1988
- var applyAll = function applyAll() {
1989
- for (var _len = arguments.length, execpt = new Array(_len), _key = 0; _key < _len; _key++) {
1990
- execpt[_key] = arguments[_key];
1991
- }
1992
-
1993
- Object.entries(CLEANER_CALLBACKS).forEach(function (_ref) {
1994
- var _ref2 = _slicedToArray(_ref, 2),
1995
- k = _ref2[0],
1996
- todo = _ref2[1];
1997
-
1998
- if (execpt.indexOf(k) === -1) {
1999
- apply(k);
2000
- }
2001
- });
2002
- };
2003
- /**
2004
- * Applique une fonction pour l'identifiant transmis
2005
- * @param {string} id
2006
- */
2007
-
2008
- var apply = function apply(id) {
2009
- if (id in CLEANER_CALLBACKS && typeof CLEANER_CALLBACKS[id] === "function") {
2010
- CLEANER_CALLBACKS[id]();
2011
- }
2012
- };
2013
- /**
2014
- *
2015
- * @param {string} id
2016
- * @param {function} callback
2017
- */
2018
-
2019
- var add = function add(id, callback) {
2020
- if (typeof callback === "function") {
2021
- CLEANER_CALLBACKS[id] = callback;
2022
- }
2023
- };
2024
- /**
2025
- *
2026
- * @param {string} id
2027
- */
2028
-
2029
- var clear = function clear(id) {
2030
- delete CLEANER_CALLBACKS[id];
2031
- };
2032
-
2033
- var BINDED_KEYS = {
2034
- arrowUp: "ArrowUp",
2035
- arrowDown: "ArrowDown",
2036
- enter: "Enter",
2037
- tab: "Tab"
2038
- };
2039
- /** */
2040
-
2041
- var onKeyDownCallback = (function (_, dispatch, onSelect) {
2042
- return function (key) {
2043
- switch (key) {
2044
- case BINDED_KEYS.arrowUp:
2045
- dispatch(arrowUpPressed()); // dispatch(actions.showPanel());
2046
-
2047
- break;
2048
-
2049
- case BINDED_KEYS.arrowDown:
2050
- dispatch(arrowDownPressed());
2051
- dispatch(showPanel());
2052
- break;
2053
-
2054
- case BINDED_KEYS.enter:
2055
- dispatch(enterPressed(onSelect));
2056
- break;
2057
-
2058
- case BINDED_KEYS.tab:
2059
- dispatch(setFocused(false));
2060
- dispatch(hidePanel());
2061
- break;
2062
- }
2063
- };
2064
- });
2065
-
2066
- /** */
2067
-
2068
- var onMouseDownCallback = (function (_ref, dispatch) {
2069
- var visible = _ref.visible,
2070
- id = _ref.id,
2071
- disabled = _ref.disabled;
2072
- return function (e) {
2073
- e.stopPropagation();
2074
-
2075
- if (!visible && !disabled) {
2076
- applyAll(id);
2077
- dispatch(showPanel());
2078
- }
2079
- };
2080
- });
2081
-
2082
- /** */
2083
-
2084
- var stopAndPrevent = function stopAndPrevent(e) {
2085
- e.preventDefault();
2086
- e.stopPropagation();
2087
- };
2088
- /** */
2089
-
2090
-
2091
- var onKeyDownCallback_ = function onKeyDownCallback_(state, dispatch, onSelect) {
2092
- return function (e) {
2093
- switch (e.key) {
2094
- case BINDED_KEYS.enter:
2095
- case BINDED_KEYS.arrowUp:
2096
- case BINDED_KEYS.arrowDown:
2097
- stopAndPrevent(e);
2098
- onKeyDownCallback(state, dispatch, onSelect)(e.key);
2099
- break;
2100
-
2101
- case BINDED_KEYS.tab:
2102
- onKeyDownCallback(state, dispatch, onSelect)(e.key);
2103
- break;
2104
- }
2105
- };
2106
- };
2107
-
2108
- var getZIndex = function getZIndex(z) {
2109
- return z || 0;
2110
- };
2111
-
2112
- var DropdownContainer = function DropdownContainer(_ref) {
2113
- var options = _ref.options,
2114
- children = _ref.children,
2115
- onSelect = _ref.onSelect,
2116
- response = _ref.response,
2117
- className = _ref.className,
2118
- label = _ref.label,
2119
- labelPosition = _ref.labelPosition,
2120
- mandatory = _ref.mandatory,
2121
- valueFromProps = _ref.value,
2122
- zIndex = _ref.zIndex,
2123
- management = _ref.management,
2124
- state = _ref.state,
2125
- dispatch = _ref.dispatch,
2126
- refs = _ref.refs;
2127
- var visible = state.visible,
2128
- focused = state.focused,
2129
- id = state.id,
2130
- disabled = state.disabled;
2131
- add(id, function () {
2132
- dispatch(hidePanel());
2133
- dispatch(setFocused(false));
2134
- });
2135
- React.useEffect(function () {
2136
- var hook = function hook() {
2137
- dispatch(hidePanel());
2138
- dispatch(setFocused(false));
2139
- };
2140
-
2141
- window.addEventListener('mousedown', hook);
2142
- return function () {
2143
- window.removeEventListener('mousedown', hook);
2144
- clear(id);
2145
- };
2146
- }, [id, dispatch]);
2147
- React.useEffect(function () {
2148
- dispatch(setOptions(options));
2149
- }, [options, dispatch]);
2150
- React.useEffect(function () {
2151
- if (valueFromProps) {
2152
- var _options$reduce = options.reduce(function (a, o, i) {
2153
- return o.value === valueFromProps && a.index === -1 ? {
2154
- index: i,
2155
- option: o
2156
- } : a;
2157
- }, {
2158
- index: -1,
2159
- option: {}
2160
- }),
2161
- option = _options$reduce.option,
2162
- index = _options$reduce.index;
2163
-
2164
- dispatch(setSelectedOption(option));
2165
- dispatch(setActiveOption(index));
2166
- }
2167
- }, [valueFromProps, options, dispatch]);
2168
- var z = getZIndex(zIndex);
2169
- return /*#__PURE__*/React__default.createElement("div", {
2170
- className: classnames("".concat(className, " ").concat(getLabelPositionClass(labelPosition)), {
2171
- focused: focused,
2172
- disabled: disabled
2173
- }),
2174
- tabIndex: "-1",
2175
- id: id,
2176
- onMouseDown: onMouseDownCallback(state, dispatch),
2177
- onKeyDown: onKeyDownCallback_(state, dispatch, onSelect),
2178
- onFocus: function onFocus() {
2179
- return dispatch(setFocused( !disabled));
2180
- },
2181
- onBlur: function onBlur() {
2182
- dispatch(setFocused(false));
2183
- },
2184
- ref: refs
2185
- }, label ? /*#__PURE__*/React__default.createElement(Label, {
2186
- content: label,
2187
- focused: focused,
2188
- mandatory: mandatory
2189
- }) : null, /*#__PURE__*/React__default.createElement("div", {
2190
- className: "field-container"
2191
- }, /*#__PURE__*/React__default.createElement("div", {
2192
- className: "".concat(management ? 'field-with-tooltip' : 'field')
2193
- }, /*#__PURE__*/React__default.createElement("div", {
2194
- tabIndex: "-1",
2195
- style: {
2196
- zIndex: focused ? z + 1 : z
2197
- },
2198
- className: "lunatic-dropdown-container"
2199
- }, /*#__PURE__*/React__default.createElement("span", {
2200
- className: classnames("lunatic-dropdown-content", {
2201
- focused: focused,
2202
- visible: visible,
2203
- disabled: disabled
2204
- })
2205
- }, children))), management && /*#__PURE__*/React__default.createElement("div", {
2206
- className: "tooltip"
2207
- }, /*#__PURE__*/React__default.createElement(TooltipResponse, {
2208
- id: id,
2209
- response: buildMultiTooltipResponse(options)(response)
2210
- }))));
2211
- };
2212
-
2213
- DropdownContainer.propTypes = {
2214
- zIndex: PropTypes.number,
2215
- className: PropTypes.string,
2216
- id: PropTypes.string,
2217
- options: PropTypes.array.isRequired,
2218
- onSelect: PropTypes.func,
2219
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.object, PropTypes.bool])
2220
- };
2221
- DropdownContainer.defaultProps = {
2222
- options: [],
2223
- zIndex: 0,
2224
- onSelect: function onSelect() {
2225
- return null;
2226
- }
2227
- };
2228
- var DropdownContainer$1 = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
2229
- return /*#__PURE__*/React__default.createElement(DropdownContainer, _extends({}, props, {
2230
- refs: ref
2231
- }));
2232
- });
2233
-
2234
- /** */
2235
- var scrollTo = function scrollTo(id) {
2236
- var li = document.getElementById(id);
2237
-
2238
- if (li) {
2239
- var parent = li.parentNode;
2240
- var pr = parent.getBoundingClientRect();
2241
- var lr = li.getBoundingClientRect();
2242
- var top = lr.top - pr.top + parent.scrollTop;
2243
- var bottom = lr.bottom - pr.top + parent.scrollTop;
2244
-
2245
- if (bottom > parent.scrollTop + pr.height) {
2246
- parent.scrollTo(0, bottom - pr.height);
2247
- } else if (top < parent.scrollTop) {
2248
- parent.scrollTo(0, top);
2249
- }
2250
- }
2251
- };
2252
-
2253
- var preparePrefix = function preparePrefix(prefix) {
2254
- return typeof prefix === 'string' ? removeAccents(prefix.toLowerCase()).replace(/[- ']/g, '') : prefix;
2255
- };
2256
- var lettersMatching = function lettersMatching(label) {
2257
- var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
2258
- var pref = prefix.split('');
2259
- var pos = -1;
2260
- var clean = preparePrefix(label);
2261
- return clean.split('').reduce(function (a, c, idx) {
2262
- if (pos < pref.length && pref[pos + 1] === c) {
2263
- pos++;
2264
- return [].concat(_toConsumableArray(a), [c]);
2265
- }
2266
-
2267
- return a;
2268
- }, []);
2269
- };
2270
- var match = function match(label, prefix) {
2271
- var pref = prefix.split('');
2272
- var pos = -1;
2273
- var clean = preparePrefix(label);
2274
- return clean.split('').reduce(function (a, c, idx) {
2275
- if (pos < pref.length && pref[pos + 1] === c) {
2276
- pos++;
2277
- return a + 1;
2278
- }
2279
-
2280
- return a / (idx * 0.0001 + 1);
2281
- }, 0) / prefix.length;
2282
- };
2283
- /** */
2284
-
2285
- var filterOption = function filterOption(options, prefix) {
2286
- if (!prefix || prefix.length === 0) {
2287
- return options;
2288
- }
2289
-
2290
- return options.reduce(function (acc, o) {
2291
- var label = o.label,
2292
- search = o.search;
2293
- var how = match(search || label, prefix);
2294
- return how >= 0.6 ? [{
2295
- o: o,
2296
- how: how
2297
- }].concat(_toConsumableArray(acc)).sort(function (a, b) {
2298
- return a.how <= b.how;
2299
- }) : acc;
2300
- }, []).map(function (_ref) {
2301
- var o = _ref.o;
2302
- return o;
2303
- });
2304
- };
2305
-
2306
- var initial = {
2307
- prefix: undefined,
2308
- options: [],
2309
- visibleOptions: [],
2310
- visible: false,
2311
- activeIndex: undefined,
2312
- selectedOption: undefined,
2313
- focused: false,
2314
- value: ''
2315
- };
2316
- /** */
2317
-
2318
- var isPrefix = function isPrefix(prefix) {
2319
- return prefix !== undefined && prefix.length > 0;
2320
- };
2321
- /** */
2322
-
2323
-
2324
- var reduceArrowDownPressed = function reduceArrowDownPressed(state) {
2325
- var visibleOptions = state.visibleOptions,
2326
- activeIndex = state.activeIndex;
2327
- var next = visibleOptions.length ? Math.min(visibleOptions.length - 1, activeIndex === undefined ? 0 : activeIndex + 1) : undefined;
2328
-
2329
- if (next !== undefined) {
2330
- scrollTo("".concat(state.id, "-option-").concat(visibleOptions[next].value));
2331
- }
2332
-
2333
- return _objectSpread2(_objectSpread2({}, state), {}, {
2334
- activeIndex: next
2335
- });
2336
- };
2337
- /** */
2338
-
2339
-
2340
- var reduceArrowUpPressed = function reduceArrowUpPressed(state) {
2341
- var visibleOptions = state.visibleOptions,
2342
- activeIndex = state.activeIndex;
2343
- var next = visibleOptions.length ? Math.max(0, activeIndex === undefined ? 0 : activeIndex - 1) : undefined;
2344
-
2345
- if (next !== undefined) {
2346
- scrollTo("".concat(state.id, "-option-").concat(visibleOptions[next].value));
2347
- }
2348
-
2349
- return _objectSpread2(_objectSpread2({}, state), {}, {
2350
- activeIndex: next
2351
- });
2352
- };
2353
- /** */
2354
-
2355
-
2356
- var reduceEnterPressed = function reduceEnterPressed(state, callback) {
2357
- var activeIndex = state.activeIndex,
2358
- visibleOptions = state.visibleOptions,
2359
- visible = state.visible;
2360
-
2361
- if (!visible) {
2362
- return _objectSpread2(_objectSpread2({}, state), {}, {
2363
- visible: true
2364
- });
2365
- }
2366
-
2367
- if (activeIndex !== undefined) {
2368
- var option = visibleOptions[activeIndex];
2369
- callback(option);
2370
- return _objectSpread2(_objectSpread2({}, state), {}, {
2371
- selectedOption: option,
2372
- value: option.label,
2373
- prefix: preparePrefix(option.label),
2374
- visible: false
2375
- });
2376
- }
2377
-
2378
- return state;
2379
- };
2380
- /** */
2381
-
2382
-
2383
- var reducer = function reducer(state, action) {
2384
- var type = action.type,
2385
- payload = action.payload;
2386
-
2387
- switch (type) {
2388
- case SHOW_PANEL:
2389
- {
2390
- return _objectSpread2(_objectSpread2({}, state), {}, {
2391
- visible: true
2392
- });
2393
- }
2394
-
2395
- case HIDE_PANEL:
2396
- {
2397
- return _objectSpread2(_objectSpread2({}, state), {}, {
2398
- visible: false
2399
- });
2400
- }
2401
-
2402
- case SET_ACTIVE_OPTION:
2403
- {
2404
- var index = payload.index;
2405
- return _objectSpread2(_objectSpread2({}, state), {}, {
2406
- activeIndex: index
2407
- });
2408
- }
2409
-
2410
- case SET_OPTIONS:
2411
- {
2412
- var options = payload.options;
2413
- var prefix = state.prefix;
2414
- return _objectSpread2(_objectSpread2({}, state), {}, {
2415
- options: options,
2416
- visibleOptions: isPrefix(prefix) ? filterOption(options) : options
2417
- });
2418
- }
2419
-
2420
- case SET_PREFIX:
2421
- {
2422
- var _prefix = payload.prefix;
2423
- var _options = state.options;
2424
- return _objectSpread2(_objectSpread2({}, state), {}, {
2425
- prefix: _prefix,
2426
- activeIndex: undefined,
2427
- visibleOptions: isPrefix(_prefix) ? filterOption(_options, _prefix) : _options
2428
- });
2429
- }
2430
-
2431
- case SET_VALUE:
2432
- {
2433
- var value = payload.value;
2434
- return _objectSpread2(_objectSpread2({}, state), {}, {
2435
- value: value
2436
- });
2437
- }
2438
-
2439
- case SET_SELECTED_OPTION:
2440
- {
2441
- var option = payload.option;
2442
- return _objectSpread2(_objectSpread2({}, state), {}, {
2443
- value: option.label,
2444
- selectedOption: option,
2445
- prefix: preparePrefix(option.label)
2446
- });
2447
- }
2448
-
2449
- case SET_FOCUSED:
2450
- {
2451
- var focused = payload.focused;
2452
- return _objectSpread2(_objectSpread2({}, state), {}, {
2453
- focused: focused
2454
- });
2455
- }
2456
-
2457
- case RESET_SELECTION:
2458
- {
2459
- return _objectSpread2(_objectSpread2({}, state), {}, {
2460
- prefix: undefined,
2461
- value: '',
2462
- selectedOption: undefined,
2463
- activeIndex: undefined,
2464
- activeOption: undefined,
2465
- visibleOptions: state.options
2466
- });
2467
- }
2468
-
2469
- case ARROW_UP_PRESSED:
2470
- {
2471
- return reduceArrowUpPressed(state);
2472
- }
2473
-
2474
- case ARROW_DOWN_PRESSED:
2475
- {
2476
- return reduceArrowDownPressed(state);
2477
- }
2478
-
2479
- case ENTER_PRESSED:
2480
- {
2481
- var callback = payload.callback;
2482
- return reduceEnterPressed(state, callback);
2483
- }
2484
-
2485
- default:
2486
- return state;
2487
- }
2488
- };
2489
-
2490
- var Option = (function (_ref) {
2491
- var label = _ref.label,
2492
- active = _ref.active,
2493
- selected = _ref.selected;
2494
- return /*#__PURE__*/React__default.createElement("span", {
2495
- className: classnames('lunatic-dropdown-option', {
2496
- 'lunatic-dropdown-option-active': active,
2497
- 'lunatic-dropdown-option-selected': selected
2498
- })
2499
- }, label);
2500
- });
2501
-
2502
- var Dropdown = function Dropdown(_ref) {
2503
- var widthAuto = _ref.widthAuto,
2504
- initId = _ref.id,
2505
- label = _ref.label,
2506
- value = _ref.value,
2507
- options = _ref.options,
2508
- response = _ref.response,
2509
- onSelect = _ref.onSelect,
2510
- placeholder = _ref.placeholder,
2511
- disabled = _ref.disabled,
2512
- initFocused = _ref.focused,
2513
- mandatory = _ref.mandatory,
2514
- labelPosition = _ref.labelPosition,
2515
- management = _ref.management,
2516
- className = _ref.className,
2517
- zIndex = _ref.zIndex;
2518
- var containerEl = React.useRef();
2519
-
2520
- var _useReducer = React.useReducer(reducer, _objectSpread2(_objectSpread2({}, initial), {}, {
2521
- id: "dropdown-".concat(initId, "-").concat(new Date().getMilliseconds()),
2522
- disabled: disabled,
2523
- focused: initFocused
2524
- })),
2525
- _useReducer2 = _slicedToArray(_useReducer, 2),
2526
- state = _useReducer2[0],
2527
- dispatch = _useReducer2[1];
2528
-
2529
- var focused = state.focused,
2530
- visible = state.visible,
2531
- activeIndex = state.activeIndex,
2532
- id = state.id;
2533
- var onSelect_ = createOnSelect(state, dispatch, onSelect);
2534
- var selectedOption = options.find(function (o) {
2535
- return o.value === value;
2536
- });
2537
- return /*#__PURE__*/React__default.createElement(DropdownContainer$1, {
2538
- className: className || 'lunatic-dropdown',
2539
- ref: containerEl,
2540
- state: state,
2541
- dispatch: dispatch,
2542
- options: options,
2543
- response: response,
2544
- management: management,
2545
- label: label,
2546
- labelPosition: labelPosition,
2547
- mandatory: mandatory,
2548
- onSelect: onSelect_,
2549
- value: value,
2550
- zIndex: zIndex
2551
- }, /*#__PURE__*/React__default.createElement("span", {
2552
- className: classnames('lunatic-dropdown-input', {
2553
- focused: focused
2554
- })
2555
- }, /*#__PURE__*/React__default.createElement("input", {
2556
- type: "button",
2557
- disabled: disabled,
2558
- value: selectedOption ? selectedOption.label : placeholder || ''
2559
- })), getIcon(state, dispatch)(visible, containerEl), /*#__PURE__*/React__default.createElement("div", {
2560
- tabIndex: "-1",
2561
- className: classnames('lunatic-transition', {
2562
- visible: isDisplay(state),
2563
- 'width-auto': widthAuto
2564
- })
2565
- }, /*#__PURE__*/React__default.createElement(Panel, {
2566
- idDropdown: id,
2567
- options: options,
2568
- display: isDisplay(state),
2569
- activeIndex: activeIndex,
2570
- optionComponent: Option,
2571
- selectedOption: selectedOption,
2572
- onSelect: onSelect_,
2573
- handleActive: function handleActive(index) {
2574
- return dispatch(setActiveOption(index));
2575
- }
2576
- })));
2577
- };
2578
-
2579
- Dropdown.propTypes = {
2580
- widthAuto: PropTypes.bool,
2581
- disabled: PropTypes.bool,
2582
- focused: PropTypes.bool,
2583
- zIndex: PropTypes.number,
2584
- className: PropTypes.string,
2585
- id: PropTypes.string,
2586
- options: PropTypes.array.isRequired,
2587
- onSelect: PropTypes.func,
2588
- placeholder: PropTypes.string,
2589
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool])
2590
- };
2591
- Dropdown.defaultProps = {
2592
- disabled: false,
2593
- focused: false,
2594
- options: [],
2595
- zIndex: 0,
2596
- onSelect: function onSelect() {
2597
- return null;
2598
- },
2599
- placeholder: 'Search...',
2600
- widthAuto: false
2601
- };
2602
- /* **/
2603
-
2604
- var isDisplay = function isDisplay(_ref2) {
2605
- var visible = _ref2.visible,
2606
- options = _ref2.options;
2607
- return visible && options.length > 0;
2608
- };
2609
- /** */
2610
-
2611
-
2612
- var getIcon = function getIcon(_ref3, dispatch) {
2613
- var disabled = _ref3.disabled;
2614
- return function (visible, containerEl) {
2615
- if (disabled) {
2616
- return /*#__PURE__*/React__default.createElement("span", {
2617
- className: "lunatic-icone"
2618
- }, /*#__PURE__*/React__default.createElement(Icon, {
2619
- width: 10,
2620
- height: 10
2621
- }));
2622
- }
2623
-
2624
- return /*#__PURE__*/React__default.createElement("span", {
2625
- className: "lunatic-icone",
2626
- tabIndex: "-1",
2627
- onMouseDown: function onMouseDown(e) {
2628
- e.stopPropagation();
2629
- e.preventDefault();
2630
-
2631
- if (visible) {
2632
- dispatch(hidePanel());
2633
- } else {
2634
- dispatch(showPanel());
2635
- containerEl.current.focus();
2636
- }
2637
- }
2638
- }, visible ? /*#__PURE__*/React__default.createElement(Icon$1, {
2639
- width: 10,
2640
- height: 10
2641
- }) : /*#__PURE__*/React__default.createElement(Icon, {
2642
- width: 10,
2643
- height: 10
2644
- }));
2645
- };
2646
- };
2647
-
2648
- var createOnSelect = function createOnSelect(_, dispatch, onSelect) {
2649
- return function (option) {
2650
- dispatch(setSelectedOption(option));
2651
- dispatch(hidePanel());
2652
- onSelect(option);
2653
- };
2654
- };
2655
-
2656
- var childrenToOption = function childrenToOption() {
2657
- var children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2658
- return (Array.isArray(children) ? children : [children]).map(function (child) {
2659
- var value = child.props.value;
2660
- var label = child.props.children;
2661
-
2662
- if (label === undefined || value === undefined) {
2663
- throw new Error('Ooops');
2664
- }
2665
-
2666
- return {
2667
- label: label,
2668
- value: value
2669
- };
2670
- });
2671
- };
2672
-
2673
- var createDropdown = function createDropdown(Component) {
2674
- return function (_ref) {
2675
- var children = _ref.children,
2676
- options = _ref.options,
2677
- props = _objectWithoutProperties(_ref, ["children", "options"]);
2678
-
2679
- var o = options || childrenToOption(children);
2680
- return /*#__PURE__*/React__default.createElement(Component, _extends({
2681
- options: o
2682
- }, props));
2683
- };
2684
- };
2685
-
2686
- var DropdownSimple = createDropdown(Dropdown);
2687
-
2688
- var Option$1 = (function (_ref) {
2689
- var label = _ref.label,
2690
- active = _ref.active,
2691
- prefix = _ref.prefix,
2692
- selected = _ref.selected;
2693
- var initLetters = lettersMatching(label, prefix);
2694
- var what = label.split('').reduce(function (_ref2, c) {
2695
- var letters = _ref2.letters,
2696
- stack = _ref2.stack;
2697
- var m = preparePrefix(c);
2698
-
2699
- var _letters = _toArray(letters),
2700
- first = _letters[0],
2701
- rest = _letters.slice(1);
2702
-
2703
- if (m === first) {
2704
- return {
2705
- letters: rest,
2706
- stack: [].concat(_toConsumableArray(stack), [{
2707
- "char": c,
2708
- className: 'lunatic-prefix'
2709
- }])
2710
- };
2711
- }
2712
-
2713
- return {
2714
- letters: letters,
2715
- stack: [].concat(_toConsumableArray(stack), [{
2716
- "char": c,
2717
- className: 'lunatic-normal'
2718
- }])
2719
- };
2720
- }, {
2721
- letters: initLetters,
2722
- stack: []
2723
- }).stack.reduce(function (_ref3, _ref4) {
2724
- var last = _ref3.last,
2725
- stack = _ref3.stack;
2726
- var _char = _ref4["char"],
2727
- className = _ref4.className;
2728
-
2729
- if (!last) {
2730
- return {
2731
- last: className,
2732
- stack: [{
2733
- part: _char,
2734
- className: className
2735
- }]
2736
- };
2737
- }
2738
-
2739
- if (last !== className) {
2740
- return {
2741
- last: className,
2742
- stack: [{
2743
- part: _char,
2744
- className: className
2745
- }].concat(_toConsumableArray(stack))
2746
- };
2747
- }
2748
-
2749
- var _stack = _toArray(stack),
2750
- first = _stack[0],
2751
- rest = _stack.slice(1);
2752
-
2753
- return {
2754
- last: className,
2755
- stack: [_objectSpread2(_objectSpread2({}, first), {}, {
2756
- part: "".concat(first.part).concat(_char)
2757
- })].concat(_toConsumableArray(rest))
2758
- };
2759
- }, {
2760
- last: undefined,
2761
- stack: []
2762
- }).stack.reverse().map(function (_ref5, i) {
2763
- var part = _ref5.part,
2764
- className = _ref5.className;
2765
- return /*#__PURE__*/React__default.createElement("span", {
2766
- className: className,
2767
- key: i
2768
- }, part);
2769
- });
2770
- return /*#__PURE__*/React__default.createElement("span", {
2771
- className: classnames('lunatic-dropdown-option', {
2772
- 'lunatic-dropdown-option-active': active,
2773
- 'lunatic-dropdown-option-selected': selected
2774
- })
2775
- }, what);
2776
- });
2777
-
2778
- var CrossIcon = (function (_ref) {
2779
- var _ref$width = _ref.width,
2780
- width = _ref$width === void 0 ? 20 : _ref$width,
2781
- _ref$height = _ref.height,
2782
- height = _ref$height === void 0 ? 20 : _ref$height,
2783
- _ref$color = _ref.color,
2784
- color = _ref$color === void 0 ? "#aaa" : _ref$color;
2785
- return /*#__PURE__*/React__default.createElement("svg", {
2786
- xmlns: "http://www.w3.org/2000/svg",
2787
- width: width,
2788
- height: height,
2789
- x: "0",
2790
- y: "0",
2791
- enableBackground: "new 0 0 612 612",
2792
- version: "1.1",
2793
- viewBox: "0 0 612 612",
2794
- xmlSpace: "preserve"
2795
- }, /*#__PURE__*/React__default.createElement("path", {
2796
- fill: color,
2797
- d: "M444.644 306l138.644-138.644c38.284-38.284 38.284-100.36 0-138.644-38.283-38.284-100.359-38.284-138.644 0L306 167.356 167.356 28.713c-38.284-38.284-100.36-38.284-138.644 0s-38.284 100.36 0 138.644L167.356 306 28.713 444.644c-38.284 38.283-38.284 100.36 0 138.644 38.284 38.284 100.36 38.284 138.644 0L306 444.644l138.644 138.644c38.283 38.284 100.36 38.284 138.644 0 38.284-38.283 38.284-100.36 0-138.644L444.644 306z"
2798
- }));
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
2799
5
  });
2800
-
2801
- /** */
2802
-
2803
- var getIcon$1 = function getIcon(visible) {
2804
- return visible ? /*#__PURE__*/React__default.createElement(Icon$1, {
2805
- width: 10,
2806
- height: 10
2807
- }) : /*#__PURE__*/React__default.createElement(Icon, {
2808
- width: 10,
2809
- height: 10
2810
- });
6
+ var _exportNames = {
7
+ useLunatic: true
2811
8
  };
2812
-
2813
- var Icone = function Icone(_ref) {
2814
- var prefix = _ref.prefix,
2815
- visible = _ref.visible,
2816
- disabled = _ref.disabled,
2817
- onDelete = _ref.onDelete,
2818
- onSwitch = _ref.onSwitch;
2819
-
2820
- if (disabled) {
2821
- return /*#__PURE__*/React__default.createElement("span", {
2822
- className: "lunatic-icone",
2823
- tabIndex: "-1",
2824
- onMouseDown: onSwitch
2825
- }, /*#__PURE__*/React__default.createElement(Icon, {
2826
- width: 10,
2827
- height: 10
2828
- }));
9
+ Object.defineProperty(exports, "useLunatic", {
10
+ enumerable: true,
11
+ get: function get() {
12
+ return _useLunatic["default"];
2829
13
  }
2830
-
2831
- return prefix && prefix.length > 0 ? /*#__PURE__*/React__default.createElement("span", {
2832
- className: "lunatic-icone",
2833
- tabIndex: "-1",
2834
- onMouseDown: onDelete
2835
- }, /*#__PURE__*/React__default.createElement(CrossIcon, {
2836
- width: 10,
2837
- height: 10
2838
- })) : /*#__PURE__*/React__default.createElement("span", {
2839
- className: "lunatic-icone",
2840
- tabIndex: "-1",
2841
- onMouseDown: onSwitch
2842
- }, getIcon$1(visible));
2843
- };
2844
-
2845
- /* **/
2846
-
2847
- var isDisplay$1 = function isDisplay(_ref) {
2848
- var visible = _ref.visible,
2849
- visibleOptions = _ref.visibleOptions;
2850
- return visible && visibleOptions.length > 0;
2851
- };
2852
- /** */
2853
-
2854
-
2855
- var onChangeCallback = function onChangeCallback(state, dispatch) {
2856
- return function (e) {
2857
- e.stopPropagation();
2858
- e.preventDefault();
2859
- dispatch(setValue(e.target.value));
2860
- dispatch(setPrefix(preparePrefix(e.target.value)));
2861
- };
2862
- };
2863
- /** */
2864
-
2865
-
2866
- var createOnSelect$1 = function createOnSelect(_, dispatch, onSelect) {
2867
- return function (option) {
2868
- dispatch(setSelectedOption(option));
2869
- dispatch(hidePanel());
2870
- onSelect(option);
2871
- };
2872
- };
2873
- /**
2874
- *
2875
- * @param {props}
2876
- */
2877
-
2878
-
2879
- function Dropdown$1(_ref2) {
2880
- var widthAuto = _ref2.widthAuto,
2881
- _ref2$options = _ref2.options,
2882
- options = _ref2$options === void 0 ? [] : _ref2$options,
2883
- onSelect = _ref2.onSelect,
2884
- response = _ref2.response,
2885
- className = _ref2.className,
2886
- placeholder = _ref2.placeholder,
2887
- label = _ref2.label,
2888
- labelPosition = _ref2.labelPosition,
2889
- mandatory = _ref2.mandatory,
2890
- valueFromProps = _ref2.value,
2891
- zIndex = _ref2.zIndex,
2892
- management = _ref2.management,
2893
- disabled = _ref2.disabled,
2894
- initFocused = _ref2.focused;
2895
-
2896
- var _useReducer = React.useReducer(reducer, _objectSpread2(_objectSpread2({}, initial), {}, {
2897
- id: "dropdown-".concat(new Date().getMilliseconds()),
2898
- disabled: disabled,
2899
- focused: initFocused
2900
- })),
2901
- _useReducer2 = _slicedToArray(_useReducer, 2),
2902
- state = _useReducer2[0],
2903
- dispatch = _useReducer2[1];
2904
-
2905
- var prefix = state.prefix,
2906
- visible = state.visible,
2907
- activeIndex = state.activeIndex,
2908
- visibleOptions = state.visibleOptions,
2909
- value = state.value,
2910
- focused = state.focused,
2911
- id = state.id;
2912
- var inputEl = React.useRef();
2913
- var containerEl = React.useRef();
2914
- var onSelect_ = createOnSelect$1(state, dispatch, onSelect);
2915
- var selectedOption = options.find(function (o) {
2916
- return o.value === value;
2917
- });
2918
- return /*#__PURE__*/React__default.createElement(DropdownContainer$1, {
2919
- className: className || 'lunatic-dropdown',
2920
- state: state,
2921
- ref: containerEl,
2922
- dispatch: dispatch,
2923
- options: options,
2924
- label: label,
2925
- labelPosition: labelPosition,
2926
- mandatory: mandatory,
2927
- response: response,
2928
- onSelect: onSelect_,
2929
- value: valueFromProps,
2930
- zIndex: zIndex,
2931
- management: management
2932
- }, /*#__PURE__*/React__default.createElement("div", {
2933
- className: classnames('lunatic-dropdown-input', {
2934
- focused: focused,
2935
- disabled: disabled
2936
- })
2937
- }, /*#__PURE__*/React__default.createElement("input", {
2938
- type: "text",
2939
- ref: inputEl,
2940
- value: value || '',
2941
- disabled: disabled,
2942
- placeholder: placeholder,
2943
- autoComplete: "list",
2944
- autoCorrect: "off",
2945
- autoCapitalize: "off",
2946
- spellCheck: "false",
2947
- tabIndex: "-1",
2948
- onChange: onChangeCallback(state, dispatch)
2949
- })), /*#__PURE__*/React__default.createElement(Icone, {
2950
- prefix: prefix,
2951
- visible: visible,
2952
- disabled: disabled,
2953
- onDelete: function onDelete(e) {
2954
- e.stopPropagation();
2955
- inputEl.current.value = '';
2956
- dispatch(resetSelection());
2957
- onSelect_({
2958
- value: null
2959
- });
2960
- },
2961
- onSwitch: function onSwitch(e) {
2962
- e.stopPropagation();
2963
- e.preventDefault();
2964
-
2965
- if (visible) {
2966
- dispatch(hidePanel());
2967
- } else {
2968
- dispatch(showPanel());
2969
- containerEl.current.focus();
2970
- }
2971
- }
2972
- }), /*#__PURE__*/React__default.createElement("div", {
2973
- tabIndex: "-1",
2974
- className: classnames('lunatic-transition', {
2975
- visible: isDisplay$1(state),
2976
- 'width-auto': widthAuto
2977
- })
2978
- }, /*#__PURE__*/React__default.createElement(Panel, {
2979
- idDropdown: id,
2980
- options: visibleOptions,
2981
- display: isDisplay$1(state) && !disabled,
2982
- prefix: prefix,
2983
- activeIndex: activeIndex,
2984
- optionComponent: Option$1,
2985
- selectedOption: selectedOption,
2986
- onSelect: onSelect_,
2987
- handleActive: function handleActive(index) {
2988
- return dispatch(setActiveOption(index));
2989
- }
2990
- })));
2991
- }
2992
-
2993
- Dropdown$1.propTypes = {
2994
- widthAuto: PropTypes.bool,
2995
- zIndex: PropTypes.number,
2996
- disabled: PropTypes.bool,
2997
- focused: PropTypes.bool,
2998
- className: PropTypes.string,
2999
- id: PropTypes.string,
3000
- options: PropTypes.array.isRequired,
3001
- onSelect: PropTypes.func,
3002
- placeholder: PropTypes.string,
3003
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool])
3004
- };
3005
- Dropdown$1.defaultProps = {
3006
- options: [],
3007
- zIndex: 0,
3008
- onSelect: function onSelect() {
3009
- return null;
3010
- },
3011
- placeholder: 'Search...',
3012
- disabled: false,
3013
- focused: false,
3014
- widthAuto: false
3015
- };
3016
-
3017
- var childrenToOption$1 = (function () {
3018
- var children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
3019
- return (Array.isArray(children) ? children : [children]).map(function (child) {
3020
- var value = child.props.value;
3021
- var label = child.props.children;
3022
-
3023
- if (label === undefined || value === undefined) {
3024
- throw new Error("Ooops");
3025
- }
3026
-
3027
- return {
3028
- label: label,
3029
- value: value
3030
- };
3031
- });
3032
14
  });
3033
-
3034
- var createDropDown = function createDropDown(Component) {
3035
- return function (_ref) {
3036
- var children = _ref.children,
3037
- options = _ref.options,
3038
- props = _objectWithoutProperties(_ref, ["children", "options"]);
3039
-
3040
- var o = options || childrenToOption$1(children);
3041
- return /*#__PURE__*/React__default.createElement(Component, _extends({
3042
- options: o
3043
- }, props));
3044
- };
3045
- };
3046
-
3047
- var DropdownEdit = createDropDown(Dropdown$1);
3048
-
3049
- var css_248z$6 = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.lunatic-dropdown {\n display: block; }\n .lunatic-dropdown:focus {\n outline: none; }\n .lunatic-dropdown.label-left {\n display: flex;\n flex-direction: row; }\n .lunatic-dropdown.label-right {\n display: flex;\n flex-direction: row-reverse; }\n .lunatic-dropdown.label-top {\n display: flex;\n flex-direction: column; }\n .lunatic-dropdown.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n .lunatic-dropdown .lunatic-dropdown-container {\n position: relative;\n height: 2em;\n width: 100%; }\n .lunatic-dropdown .lunatic-dropdown-container:focus {\n outline: none; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-dropdown-input {\n display: block;\n background-color: snow;\n width: 100%;\n border: none;\n height: 2em;\n border-radius: 0px 0px;\n box-shadow: 0em 0em 0.1em 0.1em #e80a4d; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-dropdown-input.focused {\n box-shadow: 0 0 0 0.2em #e80a4d; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-dropdown-input.disabled {\n background-color: #ebebe4; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-dropdown-input input {\n margin: 0px 25px 0px 12px;\n width: calc(100% - 37px);\n background-color: transparent;\n height: 2em;\n border: none;\n outline: none;\n text-align: left; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-icone {\n cursor: pointer;\n position: absolute;\n right: 10px;\n top: 7px; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-icone:focus {\n outline: none; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition {\n visibility: hidden;\n overflow-y: hidden;\n opacity: 0;\n /** options style */ }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition.width-auto {\n display: inline-block; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition:focus {\n outline: none; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition.visible {\n visibility: visible;\n opacity: 1;\n transition: opacity 0.5s ease-in; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-panel {\n padding: 0;\n margin: 0;\n margin-top: 12px;\n list-style: none;\n background-color: #e07898;\n max-height: 200px;\n overflow-y: auto;\n /* width */\n /* Track */\n /* Handle */\n /* Handle on hover */ }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-panel:focus {\n outline: none; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-panel::-webkit-scrollbar {\n width: 8px; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-panel::-webkit-scrollbar-track {\n background-color: #ffe9e8;\n border-radius: 4px 4px; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-panel::-webkit-scrollbar-thumb {\n background: #e80a4d;\n border-radius: 4px 4px; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-panel::-webkit-scrollbar-thumb:hover {\n background: Indigo; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-option {\n cursor: pointer;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n color: #ebebe4;\n padding: 5px 5px;\n display: block;\n border-bottom: solid 1px #ffe9e8; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-option.lunatic-dropdown-option-active {\n color: #ebebe4;\n background-color: #e80a4d; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-option.lunatic-dropdown-option-active .lunatic-prefix {\n color: Indigo;\n font-weight: bold; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-option.lunatic-dropdown-option-selected {\n color: #ebebe4;\n background-color: Indigo; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-option.lunatic-dropdown-option-selected .lunatic-prefix {\n color: #ebebe4;\n font-weight: bold; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-option.lunatic-dropdown-option-selected.lunatic-dropdown-option-active {\n color: #ebebe4;\n background-color: #e07898; }\n .lunatic-dropdown .lunatic-dropdown-container .lunatic-dropdown-content .lunatic-transition .lunatic-dropdown-option .lunatic-prefix {\n color: Indigo;\n font-weight: bold; }\n";
3050
- styleInject(css_248z$6);
3051
-
3052
- var Dropdown$2 = function Dropdown(_ref) {
3053
- var id = _ref.id,
3054
- label = _ref.label,
3055
- preferences = _ref.preferences,
3056
- response = _ref.response,
3057
- handleChange = _ref.handleChange,
3058
- options = _ref.options,
3059
- writable = _ref.writable,
3060
- declarations = _ref.declarations,
3061
- features = _ref.features,
3062
- bindings = _ref.bindings,
3063
- management = _ref.management,
3064
- freezeOptions = _ref.freezeOptions,
3065
- rest = _objectWithoutProperties(_ref, ["id", "label", "preferences", "response", "handleChange", "options", "writable", "declarations", "features", "bindings", "management", "freezeOptions"]);
3066
-
3067
- var _useState = React.useState(options),
3068
- _useState2 = _slicedToArray(_useState, 2),
3069
- opts = _useState2[0],
3070
- setOpts = _useState2[1];
3071
-
3072
- React.useEffect(function () {
3073
- if (!freezeOptions) {
3074
- var featOptions = options.map(function (_ref2) {
3075
- var labelOption = _ref2.label,
3076
- restOpts = _objectWithoutProperties(_ref2, ["label"]);
3077
-
3078
- return _objectSpread2({
3079
- label: interpret(features)(bindings)(labelOption)
3080
- }, restOpts);
3081
- });
3082
- setOpts(featOptions);
3083
- }
3084
- }, [freezeOptions, features, bindings, options]);
3085
- var interpretedLabel = interpret(features)(bindings)(label);
3086
- var value = getResponseByPreference(preferences)(response);
3087
-
3088
- var onSelect = function onSelect(e) {
3089
- return handleChange(_defineProperty({}, getResponseName(response), e.value));
3090
- };
3091
-
3092
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Declarations, {
3093
- id: id,
3094
- type: BEFORE_QUESTION_TEXT,
3095
- declarations: declarations,
3096
- features: features,
3097
- bindings: bindings
3098
- }), /*#__PURE__*/React__default.createElement(Declarations, {
3099
- id: id,
3100
- type: AFTER_QUESTION_TEXT,
3101
- declarations: declarations,
3102
- features: features,
3103
- bindings: bindings
3104
- }), writable ? /*#__PURE__*/React__default.createElement(DropdownEdit, _extends({}, rest, {
3105
- id: id,
3106
- value: value,
3107
- response: response,
3108
- label: interpretedLabel,
3109
- options: opts,
3110
- onSelect: onSelect,
3111
- management: management
3112
- })) : /*#__PURE__*/React__default.createElement(DropdownSimple, _extends({}, rest, {
3113
- id: id,
3114
- value: value,
3115
- response: response,
3116
- label: interpretedLabel,
3117
- options: opts,
3118
- onSelect: onSelect,
3119
- management: management
3120
- })), /*#__PURE__*/React__default.createElement(Declarations, {
3121
- id: id,
3122
- type: DETACHABLE,
3123
- declarations: declarations,
3124
- features: features,
3125
- bindings: bindings
3126
- }));
3127
- };
3128
-
3129
- Dropdown$2.propTypes = {
3130
- disabled: PropTypes.bool,
3131
- writable: PropTypes.bool,
3132
- handleChange: PropTypes.func,
3133
- label: PropTypes.string,
3134
- className: PropTypes.string,
3135
- zIndex: PropTypes.number,
3136
- freezeOptions: PropTypes.bool
3137
- };
3138
- Dropdown$2.defaultProps = {
3139
- writable: false,
3140
- handleChange: function handleChange() {
3141
- return null;
3142
- },
3143
- label: undefined,
3144
- className: undefined,
3145
- zIndex: 0,
3146
- disabled: false,
3147
- freezeOptions: false
3148
- };
3149
- var component$1 = /*#__PURE__*/React__default.memo(Dropdown$2, areEqual);
3150
-
3151
- var css_248z$7 = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.input-lunatic {\n box-sizing: border-box;\n border: solid 2px #e80a4d;\n border-radius: 10px;\n padding: 5px; }\n .input-lunatic:focus {\n outline: none;\n box-shadow: 0 0 10px #e80a4d; }\n .input-lunatic:read-only {\n background-color: #ebebe4; }\n\n.warning {\n box-sizing: border-box;\n border: solid 2px #f50c0c;\n background-color: #f50c0c; }\n\n.lunatic-input-number-errors .error {\n color: #f50c0c; }\n";
3152
- styleInject(css_248z$7);
3153
-
3154
- var Input = function Input(props) {
3155
- return /*#__PURE__*/React__default.createElement(InputDeclarationsWrapper, _extends({
3156
- type: "text",
3157
- roleType: "input"
3158
- }, props));
3159
- };
3160
-
3161
- var input = /*#__PURE__*/React__default.memo(Input, areEqual);
3162
-
3163
- var InputNumber = function InputNumber(_ref) {
3164
- var id = _ref.id,
3165
- label = _ref.label,
3166
- preferences = _ref.preferences,
3167
- response = _ref.response,
3168
- min = _ref.min,
3169
- max = _ref.max,
3170
- decimals = _ref.decimals,
3171
- placeholder = _ref.placeholder,
3172
- handleChange = _ref.handleChange,
3173
- readOnly = _ref.readOnly,
3174
- disabled = _ref.disabled,
3175
- autoComplete = _ref.autoComplete,
3176
- focused = _ref.focused,
3177
- style = _ref.style,
3178
- unit = _ref.unit,
3179
- labelPosition = _ref.labelPosition,
3180
- unitPosition = _ref.unitPosition,
3181
- declarations = _ref.declarations,
3182
- features = _ref.features,
3183
- bindings = _ref.bindings,
3184
- management = _ref.management,
3185
- mandatory = _ref.mandatory,
3186
- validators = _ref.validators;
3187
- var inputRef = React.useRef();
3188
-
3189
- var _useState = React.useState(function () {
3190
- return getResponseByPreference(preferences)(response);
3191
- }),
3192
- _useState2 = _slicedToArray(_useState, 2),
3193
- value = _useState2[0],
3194
- setValue = _useState2[1];
3195
-
3196
- var _useState3 = React.useState([minMaxValidator({
3197
- min: min,
3198
- max: max
3199
- })].concat(_toConsumableArray(validators)).map(function (v) {
3200
- return v(value);
3201
- }).filter(function (m) {
3202
- return m !== undefined;
3203
- })),
3204
- _useState4 = _slicedToArray(_useState3, 2),
3205
- messagesError = _useState4[0],
3206
- setMessagesError = _useState4[1];
3207
-
3208
- React.useEffect(function () {
3209
- return setValue(getResponseByPreference(preferences)(response));
3210
- }, [response, preferences]);
3211
-
3212
- var _onChange = debounce.debounce(function (v) {
3213
- handleChange(_defineProperty({}, getResponseName(response), v));
3214
- }, 200);
3215
-
3216
- var validate = function validate(v) {
3217
- setMessagesError([minMaxValidator({
3218
- min: min,
3219
- max: max
3220
- })].concat(_toConsumableArray(validators)).map(function (f) {
3221
- return f(v);
3222
- }).filter(function (m) {
3223
- return m !== undefined;
3224
- }));
3225
- };
3226
-
3227
- React.useEffect(function () {
3228
- if (focused) inputRef.current.focus();
3229
- }, [focused]);
3230
- React.useEffect(function () {
3231
- setMessagesError([minMaxValidator({
3232
- min: min,
3233
- max: max
3234
- })].concat(_toConsumableArray(validators)).map(function (v) {
3235
- return v(value);
3236
- }).filter(function (m) {
3237
- return m !== undefined;
3238
- }));
3239
- }, [value, min, max, validators]);
3240
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Declarations, {
3241
- id: id,
3242
- type: BEFORE_QUESTION_TEXT,
3243
- declarations: declarations,
3244
- features: features,
3245
- bindings: bindings
3246
- }), /*#__PURE__*/React__default.createElement("div", {
3247
- className: getLabelPositionClass(labelPosition)
3248
- }, /*#__PURE__*/React__default.createElement("label", {
3249
- htmlFor: "input-".concat(id),
3250
- id: "input-label-".concat(id),
3251
- className: "".concat(mandatory ? 'mandatory' : '')
3252
- }, interpret(features)(bindings)(label), ' ', /*#__PURE__*/React__default.createElement("span", {
3253
- className: "unit"
3254
- }, unit && ['DEFAULT', 'BEFORE'].includes(unitPosition) ? "(".concat(unit, ")") : '')), /*#__PURE__*/React__default.createElement(Declarations, {
3255
- id: id,
3256
- type: AFTER_QUESTION_TEXT,
3257
- declarations: declarations,
3258
- features: features,
3259
- bindings: bindings
3260
- }), /*#__PURE__*/React__default.createElement("div", {
3261
- className: "field-container"
3262
- }, /*#__PURE__*/React__default.createElement("div", {
3263
- className: "".concat(management ? 'field-with-tooltip' : 'field')
3264
- }, /*#__PURE__*/React__default.createElement("input", {
3265
- type: "number",
3266
- id: "input-".concat(id),
3267
- ref: inputRef,
3268
- "aria-labelledby": "input-label-".concat(id),
3269
- value: value || '',
3270
- min: min,
3271
- max: max,
3272
- step: decimals ? "".concat(Math.pow(10, -decimals)) : '0',
3273
- placeholder: placeholder,
3274
- className: "input-lunatic ".concat(messagesError.length > 0 ? 'warning' : ''),
3275
- style: buildStyleObject(style),
3276
- readOnly: readOnly,
3277
- disabled: disabled,
3278
- autoComplete: autoComplete ? 'on' : 'off',
3279
- required: mandatory,
3280
- "aria-required": mandatory,
3281
- onChange: function onChange(e) {
3282
- var v = e.target.value;
3283
- validate(v);
3284
- setValue(v);
3285
-
3286
- _onChange(v);
3287
- }
3288
- }), unitPosition === 'AFTER' && /*#__PURE__*/React__default.createElement("span", {
3289
- className: "unit"
3290
- }, unit)), management && /*#__PURE__*/React__default.createElement("div", {
3291
- className: "tooltip"
3292
- }, /*#__PURE__*/React__default.createElement(TooltipResponse, {
3293
- id: id,
3294
- response: response
3295
- }))), /*#__PURE__*/React__default.createElement("div", {
3296
- className: "lunatic-input-number-errors"
3297
- }, messagesError.map(function (m, i) {
3298
- return /*#__PURE__*/React__default.createElement("div", {
3299
- key: i,
3300
- className: "error"
3301
- }, m);
3302
- }))), /*#__PURE__*/React__default.createElement(Declarations, {
3303
- id: id,
3304
- type: DETACHABLE,
3305
- declarations: declarations,
3306
- features: features,
3307
- bindings: bindings
3308
- }));
3309
- };
3310
-
3311
- var minMaxValidator = function minMaxValidator(_ref2) {
3312
- var min = _ref2.min,
3313
- max = _ref2.max;
3314
- return function (value) {
3315
- if (!value) {
3316
- return undefined;
3317
- }
3318
-
3319
- var valueNumber = Number(value);
3320
- if (!min && isDef(max) && valueNumber > max) return /*#__PURE__*/React__default.createElement("span", null, "La valeur doit \xEAtre inf\xE9rieure \xE0 ".concat(max));else if (isDef(min) && !max && valueNumber < min) return /*#__PURE__*/React__default.createElement("span", null, "La valeur doit \xEAtre sup\xE9rieure \xE0 ".concat(min));else if (isDef(min) && isDef(max) && (valueNumber < min || valueNumber > max)) return /*#__PURE__*/React__default.createElement("span", null, "La valeur doit \xEAtre comprise entre ".concat(min, " et ").concat(max));
3321
- return undefined;
3322
- };
3323
- };
3324
-
3325
- var isDef = function isDef(number) {
3326
- return number || number === 0;
3327
- };
3328
-
3329
- InputNumber.defaultProps = {
3330
- label: '',
3331
- preferences: ['COLLECTED'],
3332
- response: {},
3333
- min: undefined,
3334
- max: undefined,
3335
- decimals: 0,
3336
- placeholder: '',
3337
- readOnly: false,
3338
- disabled: false,
3339
- autoComplete: false,
3340
- focused: false,
3341
- declarations: [],
3342
- features: [],
3343
- bindings: {},
3344
- labelPosition: 'DEFAULT',
3345
- unitPositioni: 'DEFAULT',
3346
- mandatory: false,
3347
- management: false,
3348
- style: {},
3349
- validators: []
3350
- };
3351
- InputNumber.propTypes = {
3352
- id: PropTypes.string.isRequired,
3353
- label: PropTypes.string,
3354
- preferences: PropTypes.arrayOf(valueType),
3355
- response: response,
3356
- min: PropTypes.number,
3357
- max: PropTypes.number,
3358
- decimals: PropTypes.number,
3359
- placeholder: PropTypes.string,
3360
- handleChange: PropTypes.func.isRequired,
3361
- readOnly: PropTypes.bool,
3362
- disabled: PropTypes.bool,
3363
- autoComplete: PropTypes.bool,
3364
- focused: PropTypes.bool,
3365
- declarations: declarations,
3366
- features: PropTypes.arrayOf(PropTypes.string),
3367
- bindings: PropTypes.object,
3368
- labelPosition: PropTypes.oneOf(['DEFAULT', 'TOP', 'BOTTOM', 'LEFT', 'RIGHT']),
3369
- unitPosition: PropTypes.oneOf(['DEFAULT', 'BEFORE', 'AFTER']),
3370
- mandatory: PropTypes.bool,
3371
- management: PropTypes.bool,
3372
- style: PropTypes.object,
3373
- validators: PropTypes.arrayOf(PropTypes.func)
3374
- };
3375
- var inputNumber = /*#__PURE__*/React__default.memo(InputNumber, areEqual);
3376
-
3377
- var FilterDescription = function FilterDescription(_ref) {
3378
- var id = _ref.id,
3379
- label = _ref.label,
3380
- filterDescription = _ref.filterDescription,
3381
- features = _ref.features,
3382
- bindings = _ref.bindings,
3383
- style = _ref.style;
3384
- return filterDescription ? /*#__PURE__*/React__default.createElement("div", {
3385
- id: "filter-description-".concat(id),
3386
- "aria-label": "filter-description",
3387
- className: "filter-description-lunatic",
3388
- style: buildStyleObject(style)
3389
- }, interpret(features)(bindings)(label)) : null;
3390
- };
3391
-
3392
- FilterDescription.defaultProps = {
3393
- filterDescription: false,
3394
- features: [],
3395
- bindings: {},
3396
- style: {}
3397
- };
3398
- FilterDescription.propTypes = {
3399
- id: PropTypes.string.isRequired,
3400
- label: PropTypes.string.isRequired,
3401
- filterDescription: PropTypes.bool,
3402
- features: PropTypes.arrayOf(PropTypes.string),
3403
- bindings: PropTypes.object,
3404
- style: PropTypes.object
3405
- };
3406
-
3407
- var css_248z$8 = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.progress-lunatic {\n height: 30px;\n position: relative;\n background: #d3d3d3;\n -moz-border-radius: 20px;\n -webkit-border-radius: 20px;\n border-radius: 20px;\n padding: 5px;\n box-shadow: inset 0 -1px 1px rgba(255, 255, 255, 0.3);\n text-align: center;\n font-weight: bold; }\n\n.progress-lunatic > span {\n display: block;\n height: 100%;\n border-radius: 20px;\n background-color: #e80a4d;\n opacity: 0.6;\n box-shadow: inset 0 2px 9px rgba(255, 255, 255, 0.3), inset 0 -2px 6px rgba(0, 0, 0, 0.4);\n position: relative;\n top: -18px;\n overflow: hidden; }\n\n.progress-lunatic > span:after {\n content: '';\n position: absolute;\n top: 0;\n left: 0;\n bottom: 0;\n right: 0;\n background-image: linear-gradient(-45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%, transparent);\n z-index: 1;\n background-size: 50px 50px;\n animation: move 2s linear infinite;\n border-top-right-radius: 8px;\n border-bottom-right-radius: 8px;\n border-top-left-radius: 20px;\n border-bottom-left-radius: 20px;\n overflow: hidden; }\n";
3408
- styleInject(css_248z$8);
3409
-
3410
- var ProgressBar = function ProgressBar(_ref) {
3411
- var id = _ref.id,
3412
- value = _ref.value,
3413
- style = _ref.style;
3414
- var controledValue = value;
3415
- if (value < 0) controledValue = 0;
3416
- if (value > 100) controledValue = 100;
3417
- return /*#__PURE__*/React__default.createElement("div", {
3418
- id: "progress-".concat(id),
3419
- className: "progress-lunatic",
3420
- style: buildStyleObject(style)
3421
- }, "".concat(controledValue.toFixed(0), " %"), /*#__PURE__*/React__default.createElement("span", {
3422
- style: {
3423
- width: "".concat(controledValue, "%")
3424
- }
3425
- }));
3426
- };
3427
-
3428
- ProgressBar.propTypes = {
3429
- id: PropTypes.string.isRequired,
3430
- value: PropTypes.number.isRequired,
3431
- style: PropTypes.object
3432
- };
3433
-
3434
- var css_248z$9 = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.radio-group {\n border: 0.1em solid #e80a4d; }\n\n.radio-lunatic {\n margin: 0;\n margin-right: 1em;\n margin-left: 1em;\n margin-top: 0.5em; }\n .radio-lunatic:focus {\n outline: none;\n box-shadow: 0 0 0.3em 0.3em #e80a4d; }\n .radio-lunatic:checked + label {\n border: 0.1em solid #e80a4d;\n padding: 0.3em; }\n\n.radio-modality {\n margin-top: 1em; }\n";
3435
- styleInject(css_248z$9);
3436
-
3437
- var Radio = function Radio(props) {
3438
- return /*#__PURE__*/React__default.createElement(ListDeclarationsWrapper, _extends({
3439
- type: "radio"
3440
- }, props));
3441
- };
3442
-
3443
- var component$2 = /*#__PURE__*/React__default.memo(Radio, areEqual);
3444
-
3445
- var buildLoopComponents = function buildLoopComponents(iterations) {
3446
- return function (components) {
3447
- var toFlat = _toConsumableArray(Array(iterations).keys()).map(function (rowNumber) {
3448
- return buildFlatten(rowNumber)(components).map(function (c) {
3449
- return _objectSpread2(_objectSpread2({}, c), {}, {
3450
- rowNumber: rowNumber
3451
- });
3452
- });
3453
- });
3454
-
3455
- return toFlat.flat();
3456
- };
3457
- };
3458
-
3459
- var buildFlatten = function buildFlatten(i) {
3460
- return function (parentComponents) {
3461
- return parentComponents.map(function (component) {
3462
- var response = component.response,
3463
- responses = component.responses,
3464
- components = component.components;
3465
- if (response) return buildFlattenResponse(i)(component);else if (responses) return _objectSpread2(_objectSpread2({}, component), {}, {
3466
- responses: responses.map(function (r) {
3467
- return buildFlattenResponse(i)(r);
3468
- })
3469
- });else if (components) return _objectSpread2(_objectSpread2({}, component), {}, {
3470
- components: buildFlatten(i)(components)
3471
- });else return component;
3472
- });
3473
- };
3474
- };
3475
-
3476
- var buildFlattenResponse = function buildFlattenResponse(i) {
3477
- return function (component) {
3478
- var response = component.response,
3479
- other = _objectWithoutProperties(component, ["response"]);
3480
-
3481
- var name = response.name,
3482
- values = response.values;
3483
- var newValues = Object.entries(values).reduce(function (acc, _ref) {
3484
- var _ref2 = _slicedToArray(_ref, 2),
3485
- key = _ref2[0],
3486
- value = _ref2[1];
3487
-
3488
- return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, value ? value[i] : null));
3489
- }, {});
3490
- return _objectSpread2(_objectSpread2({}, other), {}, {
3491
- response: {
3492
- name: name,
3493
- values: newValues
3494
- }
3495
- });
3496
- };
3497
- };
3498
-
3499
- var css_248z$a = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.lunatic-loop {\n margin-top: 1em;\n margin-bottom: 1em;\n border: solid 2px #e80a4d;\n padding: 2em; }\n .lunatic-loop .loop-label {\n text-align: center;\n font-weight: bold;\n font-size: 2em; }\n .lunatic-loop .loop-component {\n margin-top: 0.4em;\n margin-bottom: 0.4em; }\n";
3500
- styleInject(css_248z$a);
3501
-
3502
- var Loop = function Loop(_ref) {
3503
- var id = _ref.id,
3504
- label = _ref.label,
3505
- iterations = _ref.iterations,
3506
- components = _ref.components,
3507
- bindings = _ref.bindings,
3508
- handleChange = _ref.handleChange,
3509
- rosterDependencies = _ref.rosterDependencies,
3510
- orchetratorProps = _objectWithoutProperties(_ref, ["id", "label", "iterations", "components", "bindings", "handleChange", "rosterDependencies"]);
3511
-
3512
- var _useState = React.useState({}),
3513
- _useState2 = _slicedToArray(_useState, 2),
3514
- todo = _useState2[0],
3515
- setTodo = _useState2[1];
3516
-
3517
- var vectorialBindings = buildVectorialBindings(bindings);
3518
- var features = orchetratorProps.features;
3519
- var iterationNb = interpret(features)(vectorialBindings)(iterations);
3520
- var involvedVariables = getInvolvedVariables(components);
3521
- /**
3522
- * Handle the increase in the number of iterations
3523
- */
3524
-
3525
- React.useEffect(function () {
3526
- involvedVariables.forEach(function (_ref2) {
3527
- var iv = _ref2.name,
3528
- depth = _ref2.depth;
3529
- if (bindings[iv] && iterationNb > bindings[iv].length) handleChange(_defineProperty({}, iv, [].concat(_toConsumableArray(bindings[iv]), _toConsumableArray(new Array(iterationNb - bindings[iv].length).fill(buildEmptyValue(depth))))));
3530
- });
3531
- }, [iterationNb, bindings, handleChange, involvedVariables]);
3532
- React.useEffect(function () {
3533
- if (Object.keys(todo).length !== 0) {
3534
- var up = todo.up,
3535
- rowNumber = todo.rowNumber;
3536
-
3537
- var _Object$entries$ = _slicedToArray(Object.entries(up)[0], 2),
3538
- key = _Object$entries$[0],
3539
- value = _Object$entries$[1];
3540
-
3541
- var previousValue = bindings[key];
3542
- var newValue = previousValue.map(function (v, i) {
3543
- return i === rowNumber ? value : v;
3544
- });
3545
- handleChange(_defineProperty({}, key, newValue));
3546
- setTodo({});
15
+ var _components = require("./components");
16
+ Object.keys(_components).forEach(function (key) {
17
+ if (key === "default" || key === "__esModule") return;
18
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
19
+ if (key in exports && exports[key] === _components[key]) return;
20
+ Object.defineProperty(exports, key, {
21
+ enumerable: true,
22
+ get: function get() {
23
+ return _components[key];
3547
24
  }
3548
- }, [bindings, todo, handleChange]);
3549
- var flattenComponents = buildLoopComponents(iterationNb)(components);
3550
- if (!displayLoop(rosterDependencies)(bindings)) return null;
3551
- var loopComponents = flattenComponents.map(function (_ref3) {
3552
- var componentType = _ref3.componentType,
3553
- idC = _ref3.id,
3554
- rowNumber = _ref3.rowNumber,
3555
- conditionFilter = _ref3.conditionFilter,
3556
- rest = _objectWithoutProperties(_ref3, ["componentType", "id", "rowNumber", "conditionFilter"]);
3557
-
3558
- var loopBindings = buildBindingsForDeeperComponents(rowNumber)(bindings);
3559
- if (!displayLoopQuestion(rosterDependencies)(loopBindings)) return null;
3560
- var Component = lunatic[componentType];
3561
- if (interpret(features)(loopBindings, true)(conditionFilter) !== 'normal') return null;
3562
- return /*#__PURE__*/React__default.createElement("div", {
3563
- key: "".concat(idC, "-loop-").concat(rowNumber),
3564
- className: "loop-component"
3565
- }, /*#__PURE__*/React__default.createElement(Component, _extends({}, orchetratorProps, rest, {
3566
- id: "".concat(idC, "-loop-").concat(rowNumber),
3567
- handleChange: function handleChange(up) {
3568
- return setTodo({
3569
- up: up,
3570
- rowNumber: rowNumber
3571
- });
3572
- },
3573
- bindings: loopBindings
3574
- })));
3575
25
  });
3576
- return /*#__PURE__*/React__default.createElement("div", {
3577
- id: "loop-".concat(id),
3578
- className: "lunatic-loop"
3579
- }, loopComponents);
3580
- };
3581
-
3582
- var component$3 = /*#__PURE__*/React__default.memo(Loop, areEqual);
3583
-
3584
- var buildRosterUIComponents = function buildRosterUIComponents(headers) {
3585
- return function (components) {
3586
- var uiComponents = components.map(function (comp) {
3587
- var response = comp.response,
3588
- other = _objectWithoutProperties(comp, ["response"]);
3589
-
3590
- var name = response.name,
3591
- values = response.values;
3592
- var size = values[COLLECTED] ? values[COLLECTED].length : 0;
3593
- return _toConsumableArray(Array(size).keys()).map(function (rowNumber) {
3594
- var newValues = Object.entries(values).reduce(function (acc, _ref) {
3595
- var _ref2 = _slicedToArray(_ref, 2),
3596
- key = _ref2[0],
3597
- value = _ref2[1];
3598
-
3599
- return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, value ? value[rowNumber] : null));
3600
- }, {});
3601
- return _objectSpread2(_objectSpread2({}, other), {}, {
3602
- response: {
3603
- name: name,
3604
- values: newValues
3605
- },
3606
- rowNumber: rowNumber
3607
- });
3608
- });
3609
- }, []);
3610
-
3611
- var transpose = function transpose(m) {
3612
- return m[0].map(function (_, i) {
3613
- return m.map(function (x) {
3614
- return x[i];
3615
- });
3616
- });
3617
- };
3618
-
3619
- var rows = transpose(uiComponents);
3620
- return [headers].concat(_toConsumableArray(rows));
3621
- };
3622
- };
3623
-
3624
- var RosterForLoop = function RosterForLoop(_ref) {
3625
- var tableId = _ref.id,
3626
- tableLabel = _ref.label,
3627
- preferences = _ref.preferences,
3628
- headers = _ref.headers,
3629
- components = _ref.components,
3630
- handleChange = _ref.handleChange,
3631
- lines = _ref.lines,
3632
- positioning = _ref.positioning,
3633
- declarations = _ref.declarations,
3634
- features = _ref.features,
3635
- bindings = _ref.bindings,
3636
- addBtnLabel = _ref.addBtnLabel,
3637
- hideBtn = _ref.hideBtn,
3638
- management = _ref.management;
3639
-
3640
- var _useState = React.useState({}),
3641
- _useState2 = _slicedToArray(_useState, 2),
3642
- todo = _useState2[0],
3643
- setTodo = _useState2[1];
3644
-
3645
- var minLines = Math.max(lines.min || 0, getRosterForLoopInitLines(components));
3646
- var maxLines = lines ? lines.max : undefined;
3647
- var width = "".concat(100 / Math.max.apply(Math, _toConsumableArray(components.map(function (row) {
3648
- return row.length;
3649
- }))), "%");
3650
- var Button$1 = Button;
3651
- var uiComponents = buildRosterUIComponents(headers)(components);
3652
- var involvedVariables = getInvolvedVariables(components);
3653
- React.useEffect(function () {
3654
- if (Object.keys(todo).length !== 0) {
3655
- var up = todo.up,
3656
- rowNumber = todo.rowNumber;
3657
-
3658
- var _Object$entries$ = _slicedToArray(Object.entries(up)[0], 2),
3659
- key = _Object$entries$[0],
3660
- value = _Object$entries$[1];
3661
-
3662
- var previousValue = bindings[key];
3663
- var newValue = previousValue.map(function (v, i) {
3664
- return i === rowNumber ? value : v;
3665
- });
3666
- handleChange(_defineProperty({}, key, newValue));
3667
- setTodo({});
3668
- }
3669
- }, [bindings, todo, handleChange]);
3670
-
3671
- var addLine = function addLine() {
3672
- var toHandle = involvedVariables.reduce(function (acc, _ref2) {
3673
- var iv = _ref2.name,
3674
- depth = _ref2.depth;
3675
- return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, iv, [].concat(_toConsumableArray(bindings[iv]), [buildEmptyValue(depth)])));
3676
- }, {});
3677
- handleChange(toHandle);
3678
- };
3679
-
3680
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Declarations, {
3681
- id: tableId,
3682
- type: BEFORE_QUESTION_TEXT,
3683
- declarations: declarations,
3684
- features: features,
3685
- bindings: bindings
3686
- }), tableLabel && /*#__PURE__*/React__default.createElement("label", {
3687
- htmlFor: "table-one-axis-".concat(tableId),
3688
- id: "table-one-axis-label-".concat(tableId)
3689
- }, interpret(features)(bindings)(tableLabel)), /*#__PURE__*/React__default.createElement(Declarations, {
3690
- id: tableId,
3691
- type: AFTER_QUESTION_TEXT,
3692
- declarations: declarations,
3693
- features: features,
3694
- bindings: bindings
3695
- }), /*#__PURE__*/React__default.createElement("table", {
3696
- id: "table-".concat(tableId),
3697
- className: "table-lunatic"
3698
- }, /*#__PURE__*/React__default.createElement("tbody", null, uiComponents.map(function (row, i) {
3699
- return /*#__PURE__*/React__default.createElement("tr", {
3700
- key: "table-".concat(tableId, "-row").concat(i)
3701
- }, row.map(function (component, j) {
3702
- var label = component.label,
3703
- headerCell = component.headerCell,
3704
- colspan = component.colspan,
3705
- rowspan = component.rowspan,
3706
- componentType = component.componentType,
3707
- id = component.id,
3708
- rowNumber = component.rowNumber,
3709
- componentProps = _objectWithoutProperties(component, ["label", "headerCell", "colspan", "rowspan", "componentType", "id", "rowNumber"]);
3710
-
3711
- var localBindings = buildBindingsForDeeperComponents(rowNumber)(bindings);
3712
-
3713
- if (componentType) {
3714
- var Component = lunatic[componentType];
3715
- return /*#__PURE__*/React__default.createElement("td", {
3716
- key: "table-".concat(tableId, "-row-").concat(i, "-cell-").concat(j),
3717
- style: {
3718
- width: width
3719
- }
3720
- }, /*#__PURE__*/React__default.createElement(Component, _extends({}, componentProps, {
3721
- id: "".concat(id, "-row-").concat(i),
3722
- label: label,
3723
- handleChange: function handleChange(up) {
3724
- setTodo({
3725
- up: up,
3726
- rowNumber: rowNumber
3727
- });
3728
- },
3729
- preferences: preferences,
3730
- positioning: positioning,
3731
- management: management,
3732
- features: features,
3733
- bindings: localBindings,
3734
- zIndex: uiComponents.length - i || 0
3735
- })));
3736
- }
3737
-
3738
- var cellOptions = {
3739
- key: "table-".concat(tableId, "-row-").concat(i, "-cell-").concat(j),
3740
- style: {
3741
- width: width
3742
- },
3743
- colSpan: colspan || 1,
3744
- rowSpan: rowspan || 1
3745
- };
3746
- var interpretedLabel = interpret(features)(bindings)(label);
3747
- return headerCell ? /*#__PURE__*/React__default.createElement("th", cellOptions, interpretedLabel) : /*#__PURE__*/React__default.createElement("td", cellOptions, interpretedLabel);
3748
- }));
3749
- }))), !hideBtn && /*#__PURE__*/React__default.createElement(Button$1, {
3750
- label: "addLine",
3751
- value: addBtnLabel,
3752
- disabled: Number.isInteger(minLines) && minLines === maxLines || lastRosterForLoopLineIsEmpty(bindings)(involvedVariables),
3753
- onClick: addLine
3754
- }), /*#__PURE__*/React__default.createElement(Declarations, {
3755
- id: tableId,
3756
- type: DETACHABLE,
3757
- declarations: declarations,
3758
- features: features,
3759
- bindings: bindings
3760
- }));
3761
- };
3762
-
3763
- RosterForLoop.defaultProps = {
3764
- label: '',
3765
- preferences: ['COLLECTED'],
3766
- components: [],
3767
- lines: {},
3768
- positioning: 'DEFAULT',
3769
- declarations: [],
3770
- features: [],
3771
- bindings: {},
3772
- addBtnLabel: 'Add a line',
3773
- management: false,
3774
- hideBtn: false,
3775
- style: {}
3776
- };
3777
- RosterForLoop.propTypes = {
3778
- id: PropTypes.string.isRequired,
3779
- label: PropTypes.string,
3780
- preferences: PropTypes.arrayOf(valueType),
3781
- components: PropTypes.array,
3782
- handleChange: PropTypes.func.isRequired,
3783
- lines: lines,
3784
- positioning: PropTypes.oneOf(['DEFAULT', 'HORIZONTAL', 'VERTICAL']),
3785
- declarations: declarations,
3786
- features: PropTypes.arrayOf(PropTypes.string),
3787
- bindings: PropTypes.object,
3788
- addBtnLabel: PropTypes.string,
3789
- hideBtn: PropTypes.bool,
3790
- management: PropTypes.bool,
3791
- style: PropTypes.object
3792
- };
3793
- var component$4 = /*#__PURE__*/React__default.memo(RosterForLoop, areEqual);
3794
-
3795
- var css_248z$b = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.sequence-lunatic {\n height: 40px;\n box-sizing: border-box;\n border-radius: 0px;\n background-color: #e80a4d;\n border: 0.1em solid #e80a4d;\n color: white;\n font-weight: bold;\n font-size: 130%;\n padding-left: 10px;\n display: flex;\n align-items: center; }\n";
3796
- styleInject(css_248z$b);
3797
-
3798
- var Sequence = function Sequence(_ref) {
3799
- var id = _ref.id,
3800
- label = _ref.label,
3801
- declarations = _ref.declarations,
3802
- features = _ref.features,
3803
- bindings = _ref.bindings,
3804
- style = _ref.style;
3805
- return /*#__PURE__*/React__default.createElement(SimpleDeclarationsWrapper, {
3806
- id: id,
3807
- declarations: declarations,
3808
- features: features,
3809
- bindings: bindings
3810
- }, /*#__PURE__*/React__default.createElement("div", {
3811
- "aria-label": "sequence-".concat(id),
3812
- className: "sequence-lunatic",
3813
- style: buildStyleObject(style)
3814
- }, interpret(features)(bindings)(label)));
3815
- };
3816
-
3817
- Sequence.defaultProps = {
3818
- declarations: [],
3819
- features: [],
3820
- bindings: {},
3821
- style: {}
3822
- };
3823
- Sequence.propTypes = {
3824
- id: PropTypes.string.isRequired,
3825
- label: PropTypes.string.isRequired,
3826
- declarations: declarations,
3827
- features: PropTypes.arrayOf(PropTypes.string),
3828
- bindings: PropTypes.object,
3829
- style: PropTypes.object
3830
- };
3831
- var component$5 = /*#__PURE__*/React__default.memo(Sequence, areEqual);
3832
-
3833
- var css_248z$c = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.subsequence-lunatic {\n height: 20px;\n box-sizing: border-box;\n border-radius: 0px;\n background-color: #e80a4d;\n border: 0.1em solid #e80a4d;\n color: white;\n font-weight: bold;\n font-size: 90%;\n padding-left: 10px;\n display: flex;\n align-items: center; }\n";
3834
- styleInject(css_248z$c);
3835
-
3836
- var Subsequence = function Subsequence(_ref) {
3837
- var id = _ref.id,
3838
- label = _ref.label,
3839
- declarations = _ref.declarations,
3840
- features = _ref.features,
3841
- bindings = _ref.bindings,
3842
- style = _ref.style;
3843
- return /*#__PURE__*/React__default.createElement(SimpleDeclarationsWrapper, {
3844
- id: id,
3845
- declarations: declarations,
3846
- features: features,
3847
- bindings: bindings
3848
- }, /*#__PURE__*/React__default.createElement("div", {
3849
- "aria-label": "subsequence-".concat(id),
3850
- className: "subsequence-lunatic",
3851
- style: buildStyleObject(style)
3852
- }, interpret(features)(bindings)(label)));
3853
- };
3854
-
3855
- Subsequence.defaultProps = {
3856
- declarations: [],
3857
- features: [],
3858
- bindings: {},
3859
- style: {}
3860
- };
3861
- Subsequence.propTypes = {
3862
- id: PropTypes.string.isRequired,
3863
- label: PropTypes.string.isRequired,
3864
- declarations: declarations,
3865
- features: PropTypes.arrayOf(PropTypes.string),
3866
- bindings: PropTypes.object,
3867
- style: PropTypes.object
3868
- };
3869
- var component$6 = /*#__PURE__*/React__default.memo(Subsequence, areEqual);
3870
-
3871
- var css_248z$d = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.textarea-lunatic {\n width: 100%;\n box-sizing: border-box;\n border: solid 2px #e80a4d;\n border-radius: 10px;\n padding: 5px; }\n .textarea-lunatic:focus {\n outline: none;\n box-shadow: 0 0 10px #e80a4d; }\n .textarea-lunatic:read-only {\n background-color: #ebebe4; }\n";
3872
- styleInject(css_248z$d);
3873
-
3874
- var Textarea = function Textarea(props) {
3875
- return /*#__PURE__*/React__default.createElement(InputDeclarationsWrapper, _extends({
3876
- type: null,
3877
- roleType: "textarea"
3878
- }, props));
3879
- };
3880
-
3881
- var component$7 = /*#__PURE__*/React__default.memo(Textarea, areEqual);
3882
-
3883
- var css_248z$e = "* {\n box-sizing: border-box; }\n\n.mandatory:after {\n content: ' *';\n color: red; }\n\n.horizontal-options {\n display: inline-block;\n margin-right: 2em; }\n\nlabel,\n.lunatic-dropdown-label {\n margin-bottom: 0.5em; }\n\n.label-top {\n display: flex;\n flex-direction: column; }\n\n.label-bottom {\n display: flex;\n flex-direction: column-reverse; }\n\n.label-right {\n justify-content: flex-end;\n display: flex;\n flex-direction: row-reverse;\n align-items: baseline; }\n .label-right :first-child {\n margin-right: 1rem; }\n\n.label-left {\n display: flex;\n flex-direction: row;\n align-items: baseline; }\n .label-left :first-child {\n margin-right: 1rem; }\n\n.field-container {\n display: flex; }\n\n.tooltip {\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center; }\n\n.field-with-tooltip {\n width: calc(100% - 25px);\n position: relative; }\n\n.field {\n width: 100%;\n position: relative; }\n\n.table-lunatic {\n table-layout: fixed;\n border-collapse: collapse;\n margin-top: 0.3em;\n margin-bottom: 0.3em; }\n .table-lunatic td,\n .table-lunatic th {\n border: 0.15em solid #e80a4d;\n padding: 0.2em; }\n .table-lunatic td fieldset,\n .table-lunatic th fieldset {\n margin: none;\n border: none; }\n .table-lunatic td fieldset .radio-modality,\n .table-lunatic th fieldset .radio-modality {\n margin-top: 0; }\n .table-lunatic td fieldset .checkbox-modality,\n .table-lunatic th fieldset .checkbox-modality {\n margin-top: 0; }\n";
3884
- styleInject(css_248z$e);
3885
-
3886
- var Table = function Table(_ref) {
3887
- var tableId = _ref.id,
3888
- tableLabel = _ref.label,
3889
- preferences = _ref.preferences,
3890
- cells = _ref.cells,
3891
- handleChange = _ref.handleChange,
3892
- initLines = _ref.lines,
3893
- positioning = _ref.positioning,
3894
- declarations = _ref.declarations,
3895
- features = _ref.features,
3896
- bindings = _ref.bindings,
3897
- addBtnLabel = _ref.addBtnLabel,
3898
- hideBtn = _ref.hideBtn,
3899
- management = _ref.management;
3900
- var minLines = initLines ? Math.max(initLines.min, getRosterInitLines(cells)) : undefined;
3901
- var maxLines = initLines ? initLines.max : undefined;
3902
-
3903
- var _useState = React.useState(minLines),
3904
- _useState2 = _slicedToArray(_useState, 2),
3905
- lines = _useState2[0],
3906
- setLines = _useState2[1];
3907
-
3908
- var width = "".concat(100 / Math.max.apply(Math, _toConsumableArray(cells.map(function (line) {
3909
- return line.length;
3910
- }))), "%");
3911
- var Button$1 = Button;
3912
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Declarations, {
3913
- id: tableId,
3914
- type: BEFORE_QUESTION_TEXT,
3915
- declarations: declarations,
3916
- features: features,
3917
- bindings: bindings
3918
- }), tableLabel && /*#__PURE__*/React__default.createElement("label", {
3919
- htmlFor: "table-one-axis-".concat(tableId),
3920
- id: "table-one-axis-label-".concat(tableId)
3921
- }, interpret(features)(bindings)(tableLabel)), /*#__PURE__*/React__default.createElement(Declarations, {
3922
- id: tableId,
3923
- type: AFTER_QUESTION_TEXT,
3924
- declarations: declarations,
3925
- features: features,
3926
- bindings: bindings
3927
- }), /*#__PURE__*/React__default.createElement("table", {
3928
- id: "table-".concat(tableId),
3929
- className: "table-lunatic"
3930
- }, /*#__PURE__*/React__default.createElement("tbody", null, (minLines || minLines === 0 ? cells.slice(0, lines + 1) : cells).map(function (line, i) {
3931
- return /*#__PURE__*/React__default.createElement("tr", {
3932
- key: "table-".concat(tableId, "-line").concat(i)
3933
- }, line.map(function (component, j) {
3934
- var label = component.label,
3935
- headerCell = component.headerCell,
3936
- colspan = component.colspan,
3937
- rowspan = component.rowspan,
3938
- componentType = component.componentType,
3939
- componentProps = _objectWithoutProperties(component, ["label", "headerCell", "colspan", "rowspan", "componentType"]);
3940
-
3941
- if (componentType) {
3942
- var Component = lunatic[componentType];
3943
- return /*#__PURE__*/React__default.createElement("td", {
3944
- key: "table-".concat(tableId, "-line").concat(i, "-cell-").concat(j),
3945
- style: {
3946
- width: width
3947
- }
3948
- }, /*#__PURE__*/React__default.createElement(Component, _extends({
3949
- label: label,
3950
- handleChange: handleChange,
3951
- preferences: preferences,
3952
- positioning: positioning,
3953
- management: management,
3954
- features: features,
3955
- bindings: bindings
3956
- }, componentProps, {
3957
- zIndex: cells.length - i || 0
3958
- })));
3959
- }
3960
-
3961
- var cellOptions = {
3962
- key: "table-".concat(tableId, "-line").concat(i, "-cell-").concat(j),
3963
- style: {
3964
- width: width
3965
- },
3966
- colSpan: colspan || 1,
3967
- rowSpan: rowspan || 1
3968
- };
3969
- var interpretedLabel = interpret(features)(bindings)(label);
3970
- return headerCell ? /*#__PURE__*/React__default.createElement("th", cellOptions, interpretedLabel) : /*#__PURE__*/React__default.createElement("td", cellOptions, interpretedLabel);
3971
- }));
3972
- }))), Number.isInteger(minLines) && lines < maxLines && !hideBtn && /*#__PURE__*/React__default.createElement(Button$1, {
3973
- label: "addLine",
3974
- value: addBtnLabel,
3975
- onClick: function onClick() {
3976
- return setLines(lines + 1);
3977
- }
3978
- }), /*#__PURE__*/React__default.createElement(Declarations, {
3979
- id: tableId,
3980
- type: DETACHABLE,
3981
- declarations: declarations,
3982
- features: features,
3983
- bindings: bindings
3984
- }));
3985
- };
3986
-
3987
- Table.defaultProps = {
3988
- label: '',
3989
- preferences: ['COLLECTED'],
3990
- cells: [],
3991
- lines: {},
3992
- positioning: 'DEFAULT',
3993
- declarations: [],
3994
- features: [],
3995
- bindings: {},
3996
- addBtnLabel: 'Add a line',
3997
- management: false,
3998
- hideBtn: false,
3999
- style: {}
4000
- };
4001
- Table.propTypes = {
4002
- id: PropTypes.string.isRequired,
4003
- label: PropTypes.string,
4004
- preferences: PropTypes.arrayOf(valueType),
4005
- cells: PropTypes.array,
4006
- handleChange: PropTypes.func.isRequired,
4007
- lines: lines,
4008
- positioning: PropTypes.oneOf(['DEFAULT', 'HORIZONTAL', 'VERTICAL']),
4009
- declarations: declarations,
4010
- features: PropTypes.arrayOf(PropTypes.string),
4011
- bindings: PropTypes.object,
4012
- addBtnLabel: PropTypes.string,
4013
- hideBtn: PropTypes.bool,
4014
- management: PropTypes.bool,
4015
- style: PropTypes.object
4016
- };
4017
- var table = /*#__PURE__*/React__default.memo(Table, areEqual);
4018
-
4019
- exports.Breadcrumb = Breadcrumb;
4020
- exports.Button = Button;
4021
- exports.CheckboxBoolean = boolean;
4022
- exports.CheckboxGroup = group;
4023
- exports.CheckboxOne = one;
4024
- exports.Datepicker = component;
4025
- exports.Declarations = Declarations;
4026
- exports.Dropdown = component$1;
4027
- exports.FilterDescription = FilterDescription;
4028
- exports.Input = input;
4029
- exports.InputNumber = inputNumber;
4030
- exports.Loop = component$3;
4031
- exports.ProgressBar = ProgressBar;
4032
- exports.Radio = component$2;
4033
- exports.RosterForLoop = component$4;
4034
- exports.Sequence = component$5;
4035
- exports.Subsequence = component$6;
4036
- exports.Table = table;
4037
- exports.Textarea = component$7;
4038
- exports.TooltipResponse = TooltipResponse;
4039
- exports.getBindings = getBindings;
4040
- exports.getCollectedState = getCollectedState;
4041
- exports.getCollectedStateByValueType = getCollectedStateByValueType;
4042
- exports.getState = getState;
4043
- exports.interpret = interpret;
4044
- exports.mergeQuestionnaireAndData = mergeQuestionnaireAndData;
4045
- exports.updateQuestionnaire = updateQuestionnaire;
4046
- exports.useLunatic = useLunatic;
4047
- //# sourceMappingURL=index.js.map
26
+ });
27
+ var _useLunatic = _interopRequireDefault(require("./use-lunatic"));
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }