@ukhomeoffice/cop-react-form-renderer 6.7.0-alpha → 6.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (382) hide show
  1. package/dist/components/CheckYourAnswers/Answer.js +22 -16
  2. package/dist/components/CheckYourAnswers/Answer.test.js +180 -92
  3. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +143 -105
  4. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +942 -463
  5. package/dist/components/CollectionPage/CollectionPage.js +63 -73
  6. package/dist/components/CollectionPage/CollectionPage.test.js +366 -316
  7. package/dist/components/CollectionSummary/BannerStrip.js +13 -13
  8. package/dist/components/CollectionSummary/BannerStrip.test.js +76 -80
  9. package/dist/components/CollectionSummary/CollectionSummary.js +131 -102
  10. package/dist/components/CollectionSummary/CollectionSummary.scss +5 -0
  11. package/dist/components/CollectionSummary/CollectionSummary.test.js +233 -173
  12. package/dist/components/CollectionSummary/Confirmation.js +12 -14
  13. package/dist/components/CollectionSummary/Confirmation.test.js +63 -68
  14. package/dist/components/CollectionSummary/RenderListView.js +57 -48
  15. package/dist/components/CollectionSummary/RenderListView.scss +1 -1
  16. package/dist/components/CollectionSummary/RenderListView.test.js +77 -78
  17. package/dist/components/CollectionSummary/SummaryCard.js +156 -112
  18. package/dist/components/CollectionSummary/SummaryCard.scss +6 -0
  19. package/dist/components/CollectionSummary/SummaryCard.test.js +1023 -934
  20. package/dist/components/CollectionSummary/SummaryCardDetails.js +138 -94
  21. package/dist/components/CollectionSummary/SummaryCardDetails.scss +15 -4
  22. package/dist/components/CollectionSummary/SummaryCardDetails.test.js +331 -128
  23. package/dist/components/CollectionSummary/SummaryCardValidationContext.js +35 -30
  24. package/dist/components/CollectionSummary/SummaryCardValidationContext.test.js +74 -62
  25. package/dist/components/FormComponent/Collection.js +108 -74
  26. package/dist/components/FormComponent/Collection.test.js +1081 -909
  27. package/dist/components/FormComponent/Container.js +39 -40
  28. package/dist/components/FormComponent/Container.test.js +412 -312
  29. package/dist/components/FormComponent/FormComponent.js +73 -70
  30. package/dist/components/FormComponent/FormComponent.test.js +414 -353
  31. package/dist/components/FormComponent/helpers/addLabel.js +7 -4
  32. package/dist/components/FormComponent/helpers/getComponentDisabled.js +1 -1
  33. package/dist/components/FormComponent/helpers/getComponentDisabled.test.js +7 -7
  34. package/dist/components/FormComponent/helpers/getComponentError.js +5 -3
  35. package/dist/components/FormComponent/helpers/getComponentError.test.js +14 -14
  36. package/dist/components/FormComponent/helpers/getComponentFieldSet.js +4 -3
  37. package/dist/components/FormComponent/helpers/getComponentFieldSet.test.js +6 -6
  38. package/dist/components/FormComponent/helpers/index.js +4 -4
  39. package/dist/components/FormPage/FormPage.js +93 -66
  40. package/dist/components/FormPage/FormPage.test.js +163 -127
  41. package/dist/components/FormRenderer/FormRenderer.js +180 -143
  42. package/dist/components/FormRenderer/FormRenderer.test.js +1115 -730
  43. package/dist/components/FormRenderer/handlers/cyaAction.js +2 -2
  44. package/dist/components/FormRenderer/handlers/getPageId.js +3 -1
  45. package/dist/components/FormRenderer/handlers/getPageId.test.js +14 -14
  46. package/dist/components/FormRenderer/handlers/handlers.test.js +32 -32
  47. package/dist/components/FormRenderer/handlers/index.js +1 -1
  48. package/dist/components/FormRenderer/handlers/navigate.js +3 -3
  49. package/dist/components/FormRenderer/handlers/submissionError.js +1 -1
  50. package/dist/components/FormRenderer/helpers/canActionProceed.js +1 -1
  51. package/dist/components/FormRenderer/helpers/canActionProceed.test.js +15 -15
  52. package/dist/components/FormRenderer/helpers/canCYASubmit.js +3 -1
  53. package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +20 -16
  54. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +39 -22
  55. package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +74 -16
  56. package/dist/components/FormRenderer/helpers/getCYA.js +5 -3
  57. package/dist/components/FormRenderer/helpers/getCYA.test.js +11 -11
  58. package/dist/components/FormRenderer/helpers/getFormState.js +7 -5
  59. package/dist/components/FormRenderer/helpers/getFormState.test.js +10 -10
  60. package/dist/components/FormRenderer/helpers/getNextPageId.js +24 -13
  61. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +67 -67
  62. package/dist/components/FormRenderer/helpers/getPage.js +4 -2
  63. package/dist/components/FormRenderer/helpers/getPage.test.js +11 -11
  64. package/dist/components/FormRenderer/helpers/getRelevantPages.js +9 -7
  65. package/dist/components/FormRenderer/helpers/getRelevantPages.test.js +14 -14
  66. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +5 -5
  67. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +97 -103
  68. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +60 -62
  69. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +78 -71
  70. package/dist/components/FormRenderer/helpers/index.js +1 -1
  71. package/dist/components/FormRenderer/onCYAAction.js +51 -59
  72. package/dist/components/FormRenderer/onCYAAction.test.js +152 -164
  73. package/dist/components/FormRenderer/onPageAction.js +44 -44
  74. package/dist/components/FormRenderer/onPageAction.test.js +208 -223
  75. package/dist/components/FormRenderer/onTaskAction.js +13 -9
  76. package/dist/components/FormRenderer/onTaskAction.test.js +88 -93
  77. package/dist/components/PageActions/ActionButton.js +15 -12
  78. package/dist/components/PageActions/ActionButton.test.js +78 -56
  79. package/dist/components/PageActions/PageActions.js +10 -10
  80. package/dist/components/PageActions/PageActions.test.js +115 -86
  81. package/dist/components/SummaryList/GroupAction.js +17 -9
  82. package/dist/components/SummaryList/GroupAction.test.js +33 -37
  83. package/dist/components/SummaryList/RowAction.js +16 -11
  84. package/dist/components/SummaryList/RowAction.test.js +33 -37
  85. package/dist/components/SummaryList/SummaryList.js +34 -21
  86. package/dist/components/SummaryList/SummaryList.scss +15 -0
  87. package/dist/components/SummaryList/SummaryList.test.js +226 -143
  88. package/dist/components/SummaryList/SummaryListHeadingRow.js +4 -6
  89. package/dist/components/SummaryList/SummaryListHeadingRowWithAction.js +53 -0
  90. package/dist/components/SummaryList/SummaryListHeadingRowWithAction.scss +38 -0
  91. package/dist/components/SummaryList/SummaryListRow.js +4 -6
  92. package/dist/components/SummaryList/SummaryListTitleRow.js +3 -5
  93. package/dist/components/SummaryList/helpers/getGroupActionAttributes.js +5 -3
  94. package/dist/components/SummaryList/helpers/getGroupActionAttributes.test.js +22 -22
  95. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +5 -3
  96. package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +22 -22
  97. package/dist/components/SummaryList/helpers/index.js +1 -1
  98. package/dist/components/TaskList/Task.js +29 -19
  99. package/dist/components/TaskList/Task.test.js +76 -83
  100. package/dist/components/TaskList/TaskList.js +92 -49
  101. package/dist/components/TaskList/TaskList.scss +24 -0
  102. package/dist/components/TaskList/TaskList.test.js +255 -113
  103. package/dist/components/TaskList/TaskState.js +5 -7
  104. package/dist/components/TaskList/TaskState.test.js +45 -52
  105. package/dist/components/index.js +7 -7
  106. package/dist/context/HooksContext/HooksContext.js +80 -57
  107. package/dist/context/HooksContext/HooksContext.test.js +35 -26
  108. package/dist/context/HooksContext/index.js +4 -3
  109. package/dist/context/ValidationContext/ValidationContext.js +94 -43
  110. package/dist/context/ValidationContext/ValidationContext.test.js +68 -56
  111. package/dist/context/ValidationContext/index.js +4 -3
  112. package/dist/context/index.js +2 -2
  113. package/dist/hooks/index.js +10 -9
  114. package/dist/hooks/useAxios.js +40 -14
  115. package/dist/hooks/useGetRequest.js +97 -61
  116. package/dist/hooks/useHooks.js +3 -1
  117. package/dist/hooks/useRefData.js +39 -26
  118. package/dist/hooks/useValidation.js +3 -1
  119. package/dist/index.js +14 -13
  120. package/dist/json/actions.json +17 -0
  121. package/dist/json/actionsNoSave.json +17 -0
  122. package/dist/models/CollectionLabels.js +1 -1
  123. package/dist/models/ComponentTypes.js +25 -25
  124. package/dist/models/EventTypes.js +4 -4
  125. package/dist/models/FormPages.js +4 -4
  126. package/dist/models/FormTypes.js +8 -8
  127. package/dist/models/HubFormats.js +3 -3
  128. package/dist/models/PageAction.js +38 -44
  129. package/dist/models/TaskStates.js +28 -29
  130. package/dist/models/index.js +9 -9
  131. package/dist/setupTests.js +31 -30
  132. package/dist/utils/CheckYourAnswers/getCYAAction.js +5 -5
  133. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +54 -52
  134. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.js +25 -15
  135. package/dist/utils/CheckYourAnswers/getCYACollectionChangeAction.test.js +35 -33
  136. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.js +31 -17
  137. package/dist/utils/CheckYourAnswers/getCYACollectionDeleteAction.test.js +44 -42
  138. package/dist/utils/CheckYourAnswers/getCYARow.js +6 -6
  139. package/dist/utils/CheckYourAnswers/getCYARow.test.js +86 -86
  140. package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +24 -18
  141. package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +16 -15
  142. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +36 -33
  143. package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +61 -58
  144. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +113 -89
  145. package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +320 -162
  146. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +20 -25
  147. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +97 -103
  148. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +18 -13
  149. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +76 -70
  150. package/dist/utils/CheckYourAnswers/getSummaryListRowForDetails.js +42 -0
  151. package/dist/utils/CheckYourAnswers/getSummaryListRowForDetails.test.js +56 -0
  152. package/dist/utils/CheckYourAnswers/index.js +1 -1
  153. package/dist/utils/CheckYourAnswers/showComponentCYA.js +4 -4
  154. package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +25 -25
  155. package/dist/utils/CollectionPage/addCollectionPageEntry.js +2 -2
  156. package/dist/utils/CollectionPage/addCollectionPageEntry.test.js +5 -5
  157. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +2 -2
  158. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +18 -17
  159. package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +22 -12
  160. package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +38 -47
  161. package/dist/utils/CollectionPage/getCollectionPageActiveId.js +2 -2
  162. package/dist/utils/CollectionPage/getCollectionPageActiveId.test.js +10 -10
  163. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +11 -7
  164. package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +22 -22
  165. package/dist/utils/CollectionPage/getCollectionPageData.js +12 -8
  166. package/dist/utils/CollectionPage/getCollectionPageData.test.js +19 -19
  167. package/dist/utils/CollectionPage/getErrorsForCollection.js +24 -24
  168. package/dist/utils/CollectionPage/getErrorsForCollection.test.js +22 -20
  169. package/dist/utils/CollectionPage/getQuickEditPage.js +31 -35
  170. package/dist/utils/CollectionPage/getQuickEditPage.test.js +27 -15
  171. package/dist/utils/CollectionPage/index.js +1 -1
  172. package/dist/utils/CollectionPage/mergeCollectionPages.js +43 -31
  173. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +26 -26
  174. package/dist/utils/CollectionPage/removeCollectionPageEntry.js +6 -4
  175. package/dist/utils/CollectionPage/removeCollectionPageEntry.test.js +10 -10
  176. package/dist/utils/CollectionPage/setCollectionPageData.js +16 -10
  177. package/dist/utils/CollectionPage/setCollectionPageData.test.js +24 -24
  178. package/dist/utils/Component/addShowWhen.js +8 -4
  179. package/dist/utils/Component/addShowWhen.test.js +37 -37
  180. package/dist/utils/Component/applyToComponentTree.js +18 -18
  181. package/dist/utils/Component/applyToComponentTree.test.js +32 -27
  182. package/dist/utils/Component/cleanAttributes.js +13 -10
  183. package/dist/utils/Component/cleanAttributes.test.js +18 -17
  184. package/dist/utils/Component/elevateNestedComponents.js +7 -6
  185. package/dist/utils/Component/elevateNestedComponents.test.js +68 -30
  186. package/dist/utils/Component/getComponent.js +94 -88
  187. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +17 -18
  188. package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +59 -46
  189. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +48 -39
  190. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +33 -23
  191. package/dist/utils/Component/getComponentTests/getComponent.details.test.js +18 -20
  192. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +22 -17
  193. package/dist/utils/Component/getComponentTests/getComponent.file.test.js +25 -20
  194. package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +9 -10
  195. package/dist/utils/Component/getComponentTests/getComponent.html.test.js +15 -17
  196. package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +8 -9
  197. package/dist/utils/Component/getComponentTests/getComponent.list.test.js +15 -17
  198. package/dist/utils/Component/getComponentTests/getComponent.multifile.test.js +26 -22
  199. package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +175 -155
  200. package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +15 -17
  201. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +22 -17
  202. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +72 -57
  203. package/dist/utils/Component/getComponentTests/getComponent.select.test.js +22 -17
  204. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +22 -17
  205. package/dist/utils/Component/getComponentTests/getComponent.textArea.test.js +38 -31
  206. package/dist/utils/Component/getComponentTests/getComponent.time.test.js +29 -20
  207. package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +2 -2
  208. package/dist/utils/Component/getComponentTests/getComponent.warningText.test.js +8 -9
  209. package/dist/utils/Component/getDefaultValue.js +8 -6
  210. package/dist/utils/Component/getDefaultValue.test.js +12 -12
  211. package/dist/utils/Component/getDefaultValueFromConfig.js +21 -22
  212. package/dist/utils/Component/getDefaultValueFromConfig.test.js +31 -31
  213. package/dist/utils/Component/index.js +1 -1
  214. package/dist/utils/Component/isEditable.js +4 -2
  215. package/dist/utils/Component/isEditable.test.js +15 -14
  216. package/dist/utils/Component/optionIsSelected.js +6 -1
  217. package/dist/utils/Component/optionIsSelected.test.js +35 -9
  218. package/dist/utils/Component/setupContainerComponentsPath.js +29 -27
  219. package/dist/utils/Component/setupContainerComponentsPath.test.js +11 -11
  220. package/dist/utils/Component/showComponent.js +1 -1
  221. package/dist/utils/Component/showComponent.test.js +28 -28
  222. package/dist/utils/Component/wrapInFormGroup.js +2 -2
  223. package/dist/utils/Condition/index.js +1 -1
  224. package/dist/utils/Condition/meetsAllConditions.js +8 -8
  225. package/dist/utils/Condition/meetsAllConditions.test.js +20 -20
  226. package/dist/utils/Condition/meetsCondition.js +25 -16
  227. package/dist/utils/Condition/meetsCondition.test.js +402 -402
  228. package/dist/utils/Condition/meetsOneCondition.js +5 -5
  229. package/dist/utils/Condition/meetsOneCondition.test.js +16 -16
  230. package/dist/utils/Condition/setupConditions.js +18 -13
  231. package/dist/utils/Condition/setupConditions.test.js +7 -7
  232. package/dist/utils/Container/getEditableComponents.js +5 -3
  233. package/dist/utils/Container/getEditableComponents.test.js +45 -43
  234. package/dist/utils/Container/index.js +1 -1
  235. package/dist/utils/Container/setupNesting.js +20 -16
  236. package/dist/utils/Container/setupNesting.test.js +30 -27
  237. package/dist/utils/Container/showContainer.js +7 -3
  238. package/dist/utils/Container/showContainer.test.js +30 -30
  239. package/dist/utils/Data/applyFormula.js +48 -38
  240. package/dist/utils/Data/applyFormula.test.js +20 -20
  241. package/dist/utils/Data/deleteValues.js +22 -0
  242. package/dist/utils/Data/deleteValues.test.js +57 -0
  243. package/dist/utils/Data/getAutocompleteSource.js +26 -18
  244. package/dist/utils/Data/getAutocompleteSource.test.js +100 -85
  245. package/dist/utils/Data/getDataPath.js +28 -18
  246. package/dist/utils/Data/getDataPath.test.js +12 -12
  247. package/dist/utils/Data/getOptions.js +31 -24
  248. package/dist/utils/Data/getOptions.test.js +53 -35
  249. package/dist/utils/Data/getSourceData.js +19 -6
  250. package/dist/utils/Data/getSourceData.test.js +80 -84
  251. package/dist/utils/Data/index.js +3 -1
  252. package/dist/utils/Data/nestInRefdataOptions.js +16 -9
  253. package/dist/utils/Data/nestInRefdataOptions.test.js +16 -16
  254. package/dist/utils/Data/refDataToOptions.js +13 -10
  255. package/dist/utils/Data/refDataToOptions.test.js +19 -19
  256. package/dist/utils/Data/setDataItem.js +8 -7
  257. package/dist/utils/Data/setDataItem.test.js +37 -37
  258. package/dist/utils/Data/setupFormData.js +21 -13
  259. package/dist/utils/Data/setupFormData.test.js +50 -51
  260. package/dist/utils/Data/setupRefDataUrlForComponent.js +26 -20
  261. package/dist/utils/Data/setupRefDataUrlForComponent.test.js +24 -24
  262. package/dist/utils/FormPage/applyConditionalProperties.js +9 -5
  263. package/dist/utils/FormPage/applyConditionalProperties.test.js +18 -15
  264. package/dist/utils/FormPage/getConditionalText.js +3 -3
  265. package/dist/utils/FormPage/getConditionalText.test.js +29 -29
  266. package/dist/utils/FormPage/getFormPage.js +16 -15
  267. package/dist/utils/FormPage/getFormPage.test.js +46 -47
  268. package/dist/utils/FormPage/getFormPages.js +12 -7
  269. package/dist/utils/FormPage/getFormPages.test.js +23 -20
  270. package/dist/utils/FormPage/getPageActions.js +15 -9
  271. package/dist/utils/FormPage/getPageActions.test.js +32 -32
  272. package/dist/utils/FormPage/getParagraphFromText.js +7 -5
  273. package/dist/utils/FormPage/getParagraphFromText.test.js +6 -6
  274. package/dist/utils/FormPage/index.js +4 -2
  275. package/dist/utils/FormPage/showFormPage.js +7 -3
  276. package/dist/utils/FormPage/showFormPage.test.js +32 -32
  277. package/dist/utils/FormPage/showFormPageCYA.js +1 -1
  278. package/dist/utils/FormPage/showFormPageCYA.test.js +8 -8
  279. package/dist/utils/FormPage/useComponent.js +28 -21
  280. package/dist/utils/FormPage/useComponent.test.js +79 -77
  281. package/dist/utils/Format/formatData.js +1 -1
  282. package/dist/utils/Format/formatData.test.js +18 -18
  283. package/dist/utils/Format/formatDataForComponent.js +6 -5
  284. package/dist/utils/Format/formatDataForComponent.test.js +78 -50
  285. package/dist/utils/Format/formatDataForForm.js +8 -6
  286. package/dist/utils/Format/formatDataForForm.test.js +16 -13
  287. package/dist/utils/Format/formatDataForPage.js +5 -4
  288. package/dist/utils/Format/formatDataForPage.test.js +25 -20
  289. package/dist/utils/Format/index.js +1 -1
  290. package/dist/utils/Hub/getFormHub.js +1 -1
  291. package/dist/utils/Hub/getFormHub.test.js +31 -28
  292. package/dist/utils/Hub/index.js +1 -1
  293. package/dist/utils/Meta/constants.js +2 -2
  294. package/dist/utils/Meta/documents/getDocuments.js +1 -1
  295. package/dist/utils/Meta/documents/getDocuments.test.js +16 -24
  296. package/dist/utils/Meta/documents/index.js +1 -1
  297. package/dist/utils/Meta/documents/setDocumentsForField.js +16 -14
  298. package/dist/utils/Meta/documents/setDocumentsForField.test.js +34 -68
  299. package/dist/utils/Meta/index.js +1 -1
  300. package/dist/utils/Operate/checkValueIsTruthy.js +2 -2
  301. package/dist/utils/Operate/checkValueIsTruthy.test.js +16 -16
  302. package/dist/utils/Operate/deleteValueInFormData.js +26 -0
  303. package/dist/utils/Operate/deleteValueInFormData.test.js +60 -0
  304. package/dist/utils/Operate/getFirstOf.js +5 -5
  305. package/dist/utils/Operate/getFirstOf.test.js +31 -31
  306. package/dist/utils/Operate/getIndexOfMatchingValueIn.js +10 -10
  307. package/dist/utils/Operate/getIndexOfMatchingValueIn.test.js +52 -46
  308. package/dist/utils/Operate/getLength.js +50 -0
  309. package/dist/utils/Operate/getLength.test.js +89 -0
  310. package/dist/utils/Operate/index.js +1 -1
  311. package/dist/utils/Operate/persistValueInFormData.js +3 -3
  312. package/dist/utils/Operate/persistValueInFormData.test.js +20 -22
  313. package/dist/utils/Operate/runPageOperations.js +11 -7
  314. package/dist/utils/Operate/runPageOperations.test.js +36 -35
  315. package/dist/utils/Operate/setValueInFormData.js +2 -2
  316. package/dist/utils/Operate/setValueInFormData.test.js +16 -16
  317. package/dist/utils/Operate/shouldRun.js +6 -6
  318. package/dist/utils/Operate/shouldRun.test.js +27 -21
  319. package/dist/utils/Validate/additional/conditionallyRequired.js +4 -4
  320. package/dist/utils/Validate/additional/conditionallyRequired.test.js +18 -18
  321. package/dist/utils/Validate/additional/index.js +10 -7
  322. package/dist/utils/Validate/additional/index.test.js +78 -12
  323. package/dist/utils/Validate/additional/mustBeAfter.js +2 -2
  324. package/dist/utils/Validate/additional/mustBeAfter.test.js +40 -40
  325. package/dist/utils/Validate/additional/mustBeBefore.js +2 -2
  326. package/dist/utils/Validate/additional/mustBeBefore.test.js +28 -28
  327. package/dist/utils/Validate/additional/mustBeEarlierDateTime.js +11 -7
  328. package/dist/utils/Validate/additional/mustBeEarlierDateTime.test.js +41 -37
  329. package/dist/utils/Validate/additional/mustBeGreaterThan.js +2 -2
  330. package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +18 -18
  331. package/dist/utils/Validate/additional/mustBeInTheFuture.js +2 -2
  332. package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +12 -12
  333. package/dist/utils/Validate/additional/mustBeInThePast.js +3 -3
  334. package/dist/utils/Validate/additional/mustBeInThePast.test.js +12 -12
  335. package/dist/utils/Validate/additional/mustBeLessThan.js +2 -2
  336. package/dist/utils/Validate/additional/mustBeLessThan.test.js +17 -17
  337. package/dist/utils/Validate/additional/mustBeLongerThan.js +1 -1
  338. package/dist/utils/Validate/additional/mustBeLongerThan.test.js +16 -16
  339. package/dist/utils/Validate/additional/mustBeNumbersOnly.js +2 -2
  340. package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +20 -20
  341. package/dist/utils/Validate/additional/mustBeOneOf.js +21 -0
  342. package/dist/utils/Validate/additional/mustBeOneOf.test.js +36 -0
  343. package/dist/utils/Validate/additional/mustBeShorterThan.js +1 -1
  344. package/dist/utils/Validate/additional/mustBeShorterThan.test.js +16 -16
  345. package/dist/utils/Validate/additional/mustBeUniqueInCollection.js +4 -4
  346. package/dist/utils/Validate/additional/mustBeUniqueInCollection.test.js +39 -35
  347. package/dist/utils/Validate/additional/mustEnterAtLeastOne.js +2 -2
  348. package/dist/utils/Validate/additional/mustEnterAtLeastOne.test.js +16 -14
  349. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.js +1 -1
  350. package/dist/utils/Validate/additional/mustHaveLessThanDecimalPlaces.test.js +12 -12
  351. package/dist/utils/Validate/additional/mustNotContainSql.js +4 -3
  352. package/dist/utils/Validate/additional/mustNotContainSql.test.js +14 -14
  353. package/dist/utils/Validate/additional/mustSelectOnlyOne.js +2 -2
  354. package/dist/utils/Validate/additional/mustSelectOnlyOne.test.js +26 -28
  355. package/dist/utils/Validate/additional/utils.js +22 -9
  356. package/dist/utils/Validate/index.js +1 -1
  357. package/dist/utils/Validate/validateCollection.js +25 -19
  358. package/dist/utils/Validate/validateCollection.test.js +66 -74
  359. package/dist/utils/Validate/validateComponent.js +21 -18
  360. package/dist/utils/Validate/validateComponent.test.js +176 -166
  361. package/dist/utils/Validate/validateContainer.js +20 -15
  362. package/dist/utils/Validate/validateContainer.test.js +52 -58
  363. package/dist/utils/Validate/validateDate.js +21 -15
  364. package/dist/utils/Validate/validateDate.test.js +32 -31
  365. package/dist/utils/Validate/validateEmail.js +8 -6
  366. package/dist/utils/Validate/validateEmail.test.js +25 -25
  367. package/dist/utils/Validate/validateMultifile.js +7 -5
  368. package/dist/utils/Validate/validateMultifile.test.js +18 -17
  369. package/dist/utils/Validate/validatePage.js +22 -19
  370. package/dist/utils/Validate/validatePage.test.js +203 -215
  371. package/dist/utils/Validate/validateRegex.js +5 -3
  372. package/dist/utils/Validate/validateRegex.test.js +14 -14
  373. package/dist/utils/Validate/validateRequired.js +6 -4
  374. package/dist/utils/Validate/validateRequired.test.js +18 -18
  375. package/dist/utils/Validate/validateTextArea.js +6 -4
  376. package/dist/utils/Validate/validateTextArea.test.js +20 -20
  377. package/dist/utils/Validate/validateTime.js +26 -11
  378. package/dist/utils/Validate/validateTime.test.js +62 -16
  379. package/dist/utils/index.js +9 -7
  380. package/package.json +2 -2
  381. package/dist/utils/CheckYourAnswers/getComponentRowForCYA.js +0 -37
  382. package/dist/utils/CheckYourAnswers/getComponentRowForCYA.test.js +0 -41
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
@@ -10,57 +11,61 @@ var _ValidationContext = require("../../context/ValidationContext");
10
11
  var _hooks = require("../../hooks");
11
12
  var _utils = _interopRequireDefault(require("../../utils"));
12
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
- /* eslint-disable react/jsx-no-constructed-context-values, no-shadow */
16
- // Global imports
17
-
14
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
15
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
17
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
18
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
19
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
20
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
21
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /* eslint-disable react/jsx-no-constructed-context-values, no-shadow */ // Global imports
18
22
  // Local imports
19
-
20
- const SummaryCardValidationContextProvider = _ref => {
21
- let {
22
- entryId,
23
- topLevelErrors,
24
- clearTopLevelErrorsForCard,
25
- children
26
- } = _ref;
27
- const {
28
- hooks
29
- } = (0, _hooks.useHooks)();
23
+ var SummaryCardValidationContextProvider = function SummaryCardValidationContextProvider(_ref) {
24
+ var entryId = _ref.entryId,
25
+ topLevelErrors = _ref.topLevelErrors,
26
+ clearTopLevelErrorsForCard = _ref.clearTopLevelErrorsForCard,
27
+ children = _ref.children;
28
+ var _useHooks = (0, _hooks.useHooks)(),
29
+ hooks = _useHooks.hooks;
30
30
 
31
31
  // Errors raised from the Collection Summary.
32
- const initialErrors = topLevelErrors.filter(e => e.entryId === entryId) || [];
32
+ var initialErrors = topLevelErrors.filter(function (e) {
33
+ return e.entryId === entryId;
34
+ }) || [];
33
35
  // Errors raised locally, via the Quick Edit page.
34
- const [errors, setErrors] = (0, _react.useState)(null);
35
- const resetQuickEditErrors = () => {
36
+ var _useState = (0, _react.useState)(null),
37
+ _useState2 = _slicedToArray(_useState, 2),
38
+ errors = _useState2[0],
39
+ setErrors = _useState2[1];
40
+ var resetQuickEditErrors = function resetQuickEditErrors() {
36
41
  // By setting errors to 'null' here we go back to using
37
42
  // whatever topLevelErrors are passed in for us.
38
43
  setErrors(null);
39
44
  };
40
- const addErrors = addedErrors => {
41
- setErrors(prev => {
42
- const newErrors = prev !== null && prev !== void 0 ? prev : [];
45
+ var addErrors = function addErrors(addedErrors) {
46
+ setErrors(function (prev) {
47
+ var newErrors = prev !== null && prev !== void 0 ? prev : [];
43
48
  return newErrors.concat(addedErrors);
44
49
  });
45
50
  };
46
51
 
47
52
  // This validate is only used by the Quick Edit page
48
53
  // on the Summary Card.
49
- const validate = {
50
- page: page => {
51
- const pageErrors = _utils.default.Validate.page(page);
52
- const allErrors = hooks.onValidate(page, pageErrors);
54
+ var validate = {
55
+ page: function page(_page) {
56
+ var pageErrors = _utils.default.Validate.page(_page);
57
+ var allErrors = hooks.onValidate(_page, pageErrors);
53
58
  setErrors(allErrors);
54
59
  return allErrors;
55
60
  }
56
61
  };
57
62
  return /*#__PURE__*/_react.default.createElement(_ValidationContext.ValidationContext.Provider, {
58
63
  value: {
59
- addErrors,
64
+ addErrors: addErrors,
60
65
  errors: errors === null ? [].concat(initialErrors) : errors,
61
- resetQuickEditErrors,
62
- clearTopLevelErrorsForCard,
63
- validate
66
+ resetQuickEditErrors: resetQuickEditErrors,
67
+ clearTopLevelErrorsForCard: clearTopLevelErrorsForCard,
68
+ validate: validate
64
69
  }
65
70
  }, children);
66
71
  };
@@ -1,30 +1,28 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  var _react = require("@testing-library/react");
4
5
  var _copReactComponents = require("@ukhomeoffice/cop-react-components");
5
6
  var _react2 = _interopRequireWildcard(require("react"));
6
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
7
8
  var _hooks = require("../../hooks");
8
- var _context = require("../../context");
9
+ var _context3 = require("../../context");
9
10
  var _SummaryCardValidationContext = _interopRequireDefault(require("./SummaryCardValidationContext"));
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
- // Global imports
14
-
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
15
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
16
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } // Global imports
15
17
  // Local imports
16
-
17
- const TestComponent = _ref => {
18
- let {
19
- customErrors
20
- } = _ref;
21
- const {
22
- addErrors,
23
- errors,
24
- resetQuickEditErrors,
25
- validate
26
- } = (0, _hooks.useValidation)();
27
- (0, _react2.useEffect)(() => {
18
+ var TestComponent = function TestComponent(_ref) {
19
+ var customErrors = _ref.customErrors;
20
+ var _useValidation = (0, _hooks.useValidation)(),
21
+ addErrors = _useValidation.addErrors,
22
+ errors = _useValidation.errors,
23
+ resetQuickEditErrors = _useValidation.resetQuickEditErrors,
24
+ validate = _useValidation.validate;
25
+ (0, _react2.useEffect)(function () {
28
26
  if (customErrors) {
29
27
  addErrors(customErrors);
30
28
  }
@@ -33,51 +31,65 @@ const TestComponent = _ref => {
33
31
  errors: errors
34
32
  }));
35
33
  };
36
- describe('context.SummaryCardValidationContext', () => {
37
- it('should appropriately set up the context', async () => {
38
- const {
39
- container
40
- } = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_context.HooksContextProvider, null, /*#__PURE__*/_react2.default.createElement(_SummaryCardValidationContext.default, {
41
- entryId: "123",
42
- topLevelErrors: []
43
- }, /*#__PURE__*/_react2.default.createElement(TestComponent, null))));
44
- expect(container.childNodes.length).toEqual(4);
45
- expect(container.textContent).toContain('addErrors is a function');
46
- expect(container.textContent).toContain('resetQuickEditErrors is a function');
47
- expect(container.textContent).toContain('validate.page is a function');
48
- expect(container.textContent).toContain('errors is an array of length 0');
49
- });
50
- it('should correctly filter out top-level errors not for this card', async () => {
51
- const TOP_LEVEL_ERRORS = [{
52
- id: 'testid',
53
- entryId: '123',
54
- error: 'error message one'
55
- }, {
56
- id: 'testid',
57
- entryId: '456',
58
- error: 'error message two'
59
- }, {
60
- id: 'testid',
61
- entryId: '123',
62
- error: 'error message three'
63
- }, {
64
- id: 'testid',
65
- error: 'error message four'
66
- }];
67
- const {
68
- container
69
- } = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_context.HooksContextProvider, null, /*#__PURE__*/_react2.default.createElement(_SummaryCardValidationContext.default, {
70
- entryId: "123",
71
- topLevelErrors: TOP_LEVEL_ERRORS
72
- }, /*#__PURE__*/_react2.default.createElement(TestComponent, null))));
73
- expect(container.childNodes.length).toEqual(5);
74
- expect(container.textContent).toContain('addErrors is a function');
75
- expect(container.textContent).toContain('resetQuickEditErrors is a function');
76
- expect(container.textContent).toContain('validate.page is a function');
77
- expect(container.textContent).toContain('errors is an array of length 2');
78
- expect(container.textContent).toContain('error message one');
79
- expect(container.textContent).toContain('error message three');
80
- });
34
+ describe('context.SummaryCardValidationContext', function () {
35
+ it('should appropriately set up the context', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
36
+ var _render, container;
37
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
38
+ while (1) switch (_context.prev = _context.next) {
39
+ case 0:
40
+ _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_context3.HooksContextProvider, null, /*#__PURE__*/_react2.default.createElement(_SummaryCardValidationContext.default, {
41
+ entryId: "123",
42
+ topLevelErrors: []
43
+ }, /*#__PURE__*/_react2.default.createElement(TestComponent, null)))), container = _render.container;
44
+ expect(container.childNodes.length).toEqual(4);
45
+ expect(container.textContent).toContain('addErrors is a function');
46
+ expect(container.textContent).toContain('resetQuickEditErrors is a function');
47
+ expect(container.textContent).toContain('validate.page is a function');
48
+ expect(container.textContent).toContain('errors is an array of length 0');
49
+ case 6:
50
+ case "end":
51
+ return _context.stop();
52
+ }
53
+ }, _callee);
54
+ })));
55
+ it('should correctly filter out top-level errors not for this card', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
56
+ var TOP_LEVEL_ERRORS, _render2, container;
57
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
58
+ while (1) switch (_context2.prev = _context2.next) {
59
+ case 0:
60
+ TOP_LEVEL_ERRORS = [{
61
+ id: 'testid',
62
+ entryId: '123',
63
+ error: 'error message one'
64
+ }, {
65
+ id: 'testid',
66
+ entryId: '456',
67
+ error: 'error message two'
68
+ }, {
69
+ id: 'testid',
70
+ entryId: '123',
71
+ error: 'error message three'
72
+ }, {
73
+ id: 'testid',
74
+ error: 'error message four'
75
+ }];
76
+ _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_context3.HooksContextProvider, null, /*#__PURE__*/_react2.default.createElement(_SummaryCardValidationContext.default, {
77
+ entryId: "123",
78
+ topLevelErrors: TOP_LEVEL_ERRORS
79
+ }, /*#__PURE__*/_react2.default.createElement(TestComponent, null)))), container = _render2.container;
80
+ expect(container.childNodes.length).toEqual(5);
81
+ expect(container.textContent).toContain('addErrors is a function');
82
+ expect(container.textContent).toContain('resetQuickEditErrors is a function');
83
+ expect(container.textContent).toContain('validate.page is a function');
84
+ expect(container.textContent).toContain('errors is an array of length 2');
85
+ expect(container.textContent).toContain('error message one');
86
+ expect(container.textContent).toContain('error message three');
87
+ case 9:
88
+ case "end":
89
+ return _context2.stop();
90
+ }
91
+ }, _callee2);
92
+ })));
81
93
  });
82
94
  TestComponent.propTypes = {
83
95
  customErrors: _propTypes.default.arrayOf(_propTypes.default.shape({}))
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
@@ -11,27 +12,41 @@ var _models = require("../../models");
11
12
  var _utils = _interopRequireDefault(require("../../utils"));
12
13
  var _Container = _interopRequireDefault(require("./Container"));
13
14
  require("./Collection.scss");
15
+ var _excluded = ["firstOnlyLabel"];
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
17
- // Global imports
18
-
17
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
18
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
20
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
21
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
25
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
26
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
27
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
28
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
29
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
30
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
31
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
32
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
33
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
34
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // Global imports
19
35
  // Local imports
20
-
21
36
  // Styles
22
-
23
- const DEFAULT_CLASS = exports.DEFAULT_CLASS = 'hods-form-collection';
24
- const Collection = _ref => {
25
- let {
26
- config,
27
- value: _value,
28
- formData,
29
- onChange,
30
- onTopLevelChange,
31
- wrap
32
- } = _ref;
33
- const [value, setValue] = (0, _react.useState)(_value);
34
- const reportChange = newValue => {
37
+ var DEFAULT_CLASS = exports.DEFAULT_CLASS = 'hods-form-collection';
38
+ var Collection = function Collection(_ref) {
39
+ var config = _ref.config,
40
+ _value = _ref.value,
41
+ formData = _ref.formData,
42
+ onChange = _ref.onChange,
43
+ onTopLevelChange = _ref.onTopLevelChange,
44
+ wrap = _ref.wrap;
45
+ var _useState = (0, _react.useState)(_value),
46
+ _useState2 = _slicedToArray(_useState, 2),
47
+ value = _useState2[0],
48
+ setValue = _useState2[1];
49
+ var reportChange = function reportChange(newValue) {
35
50
  setValue(newValue);
36
51
  if (typeof onChange === 'function') {
37
52
  onChange({
@@ -42,56 +57,81 @@ const Collection = _ref => {
42
57
  });
43
58
  }
44
59
  };
45
- const onCollectionChange = _ref2 => {
46
- let {
47
- target
48
- } = _ref2;
60
+ var onCollectionChange = function onCollectionChange(_ref2) {
61
+ var target = _ref2.target;
49
62
  if (typeof onChange === 'function') {
50
63
  if (target.name === _utils.default.Meta.name) {
51
64
  onChange({
52
- target
65
+ target: target
53
66
  });
54
67
  } else {
55
- const itemIndex = value.findIndex(item => item.id === target.name);
68
+ var itemIndex = value.findIndex(function (item) {
69
+ return item.id === target.name;
70
+ });
56
71
  reportChange([].concat(value.slice(0, itemIndex), [target.value], value.slice(itemIndex + 1)));
57
72
  }
58
73
  }
59
74
  };
60
- const onAddAnother = async () => {
61
- reportChange([].concat(value, [{
62
- id: Date.now().toString()
63
- }]));
64
- };
65
- const onRemoveItem = async item => {
66
- reportChange(value.filter(i => i.id !== item.id));
67
- };
68
- const getAddLabel = labels => {
75
+ var onAddAnother = /*#__PURE__*/function () {
76
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
77
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
78
+ while (1) switch (_context.prev = _context.next) {
79
+ case 0:
80
+ reportChange([].concat(value, [{
81
+ id: Date.now().toString()
82
+ }]));
83
+ case 1:
84
+ case "end":
85
+ return _context.stop();
86
+ }
87
+ }, _callee);
88
+ }));
89
+ return function onAddAnother() {
90
+ return _ref3.apply(this, arguments);
91
+ };
92
+ }();
93
+ var onRemoveItem = /*#__PURE__*/function () {
94
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(item) {
95
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
96
+ while (1) switch (_context2.prev = _context2.next) {
97
+ case 0:
98
+ reportChange(value.filter(function (i) {
99
+ return i.id !== item.id;
100
+ }));
101
+ case 1:
102
+ case "end":
103
+ return _context2.stop();
104
+ }
105
+ }, _callee2);
106
+ }));
107
+ return function onRemoveItem(_x) {
108
+ return _ref4.apply(this, arguments);
109
+ };
110
+ }();
111
+ var getAddLabel = function getAddLabel(labels) {
69
112
  if (labels.initial && !value.length) {
70
113
  return labels.initial;
71
114
  }
72
115
  return labels.add;
73
116
  };
74
- (0, _react.useEffect)(() => {
117
+ (0, _react.useEffect)(function () {
75
118
  if (config.focusOnAdd && Array.isArray(value) && value.length) {
76
119
  if (value.length > config.minimumEntries || !config.minimumEntries) {
77
120
  var _value2, _document$getElementB, _focusable$;
78
- const containerId = (_value2 = value[value.length - 1]) === null || _value2 === void 0 ? void 0 : _value2.id;
79
- const container = (_document$getElementB = document.getElementById(containerId)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.childNodes[0];
80
- const focusable = container === null || container === void 0 ? void 0 : container.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
121
+ var containerId = (_value2 = value[value.length - 1]) === null || _value2 === void 0 ? void 0 : _value2.id;
122
+ var container = (_document$getElementB = document.getElementById(containerId)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.childNodes[0];
123
+ var focusable = container === null || container === void 0 ? void 0 : container.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
81
124
  (_focusable$ = focusable[0]) === null || _focusable$ === void 0 || _focusable$.focus();
82
125
  }
83
126
  }
84
127
  }, [value.length, config.focusOnAdd, config.minimumEntries]);
85
- (0, _react.useEffect)(() => {
128
+ (0, _react.useEffect)(function () {
86
129
  if (config.minimumEntries && !value.length) {
87
130
  onAddAnother();
88
131
  }
89
132
  }, [config.minimumEntries, value.length]);
90
- const labels = {
91
- ..._models.CollectionLabels,
92
- ...config.labels
93
- };
94
- const classes = _utils.default.classBuilder(DEFAULT_CLASS, [], config.className);
133
+ var labels = _objectSpread(_objectSpread({}, _models.CollectionLabels), config.labels);
134
+ var classes = _utils.default.classBuilder(DEFAULT_CLASS, [], config.className);
95
135
  return /*#__PURE__*/_react.default.createElement("div", {
96
136
  className: classes(),
97
137
  id: config.id
@@ -99,20 +139,18 @@ const Collection = _ref => {
99
139
  id: config.id,
100
140
  required: config.required,
101
141
  className: classes('title')
102
- }, config.label), value && value.map((item, index) => {
142
+ }, config.label), value && value.map(function (item, index) {
103
143
  var _config$removeLocatio;
104
- const fullPath = "".concat(config.full_path || config.fieldId, "[").concat(index, "]");
105
- const labelCount = (config.countOffset || 0) + index + 1;
106
- const itemTitle = _utils.default.interpolateString(labels.item, {
107
- ...item,
144
+ var fullPath = "".concat(config.full_path || config.fieldId, "[").concat(index, "]");
145
+ var labelCount = (config.countOffset || 0) + index + 1;
146
+ var itemTitle = _utils.default.interpolateString(labels.item, _objectSpread(_objectSpread({}, item), {}, {
108
147
  index: labelCount
109
- });
110
- const removeLabel = _utils.default.interpolateString(labels.remove, {
111
- ...item,
148
+ }));
149
+ var removeLabel = _utils.default.interpolateString(labels.remove, _objectSpread(_objectSpread({}, item), {}, {
112
150
  index: labelCount
113
- });
114
- const removeStyle = config.disableAddAndRemove || index === 0 && config.minimumEntries ? '' : (_config$removeLocatio = config.removeLocation) !== null && _config$removeLocatio !== void 0 ? _config$removeLocatio : 'start';
115
- const addStyle = index !== 0 && config.subsequentItemStyle ? config.subsequentItemStyle : {};
151
+ }));
152
+ var removeStyle = config.disableAddAndRemove || index === 0 && config.minimumEntries ? '' : (_config$removeLocatio = config.removeLocation) !== null && _config$removeLocatio !== void 0 ? _config$removeLocatio : 'start';
153
+ var addStyle = index !== 0 && config.subsequentItemStyle ? config.subsequentItemStyle : {};
116
154
  return /*#__PURE__*/_react.default.createElement("div", {
117
155
  className: "".concat(classes('item')),
118
156
  key: item.id,
@@ -122,7 +160,9 @@ const Collection = _ref => {
122
160
  required: true,
123
161
  className: classes('item-title')
124
162
  }, itemTitle, removeStyle === 'start' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
125
- onClick: () => onRemoveItem(item),
163
+ onClick: function onClick() {
164
+ return onRemoveItem(item);
165
+ },
126
166
  classModifiers: "secondary"
127
167
  }, removeLabel)), /*#__PURE__*/_react.default.createElement(_Container.default, {
128
168
  container: {
@@ -131,34 +171,26 @@ const Collection = _ref => {
131
171
  type: 'container',
132
172
  required: config.required,
133
173
  full_path: fullPath,
134
- components: config.item.map(component => {
135
- const {
136
- firstOnlyLabel,
137
- ...cleanedComponent
138
- } = component;
139
- let {
140
- hint
141
- } = component;
174
+ components: config.item.map(function (component) {
175
+ var firstOnlyLabel = component.firstOnlyLabel,
176
+ cleanedComponent = _objectWithoutProperties(component, _excluded);
177
+ var hint = component.hint;
142
178
  if (config.restrictHint && index > 0) {
143
179
  hint = undefined;
144
180
  }
145
- let {
146
- label
147
- } = component;
181
+ var label = component.label;
148
182
  if (index === 0) {
149
183
  var _component$firstOnlyL;
150
184
  label = (_component$firstOnlyL = component.firstOnlyLabel) !== null && _component$firstOnlyL !== void 0 ? _component$firstOnlyL : component.label;
151
185
  }
152
- return {
153
- ...cleanedComponent,
154
- hint,
186
+ return _objectSpread(_objectSpread({}, cleanedComponent), {}, {
187
+ hint: hint,
155
188
  readonly: !!(config !== null && config !== void 0 && config.readonly || component.readonly),
156
- label: _utils.default.interpolateString(label, {
157
- ...item,
189
+ label: _utils.default.interpolateString(label, _objectSpread(_objectSpread({}, item), {}, {
158
190
  index: labelCount
159
- }),
191
+ })),
160
192
  full_path: "".concat(fullPath, ".").concat(component.fieldId)
161
- };
193
+ });
162
194
  })
163
195
  },
164
196
  value: item,
@@ -169,7 +201,9 @@ const Collection = _ref => {
169
201
  }), removeStyle === 'end' && /*#__PURE__*/_react.default.createElement(_copReactComponents.ButtonGroup, {
170
202
  className: "govuk-!-margin-top-2"
171
203
  }, /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
172
- onClick: () => onRemoveItem(item),
204
+ onClick: function onClick() {
205
+ return onRemoveItem(item);
206
+ },
173
207
  classModifiers: "secondary"
174
208
  }, removeLabel)));
175
209
  }), !config.disableAddAndRemove && /*#__PURE__*/_react.default.createElement(_copReactComponents.ButtonGroup, null, /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {