@digigov/form 2.0.0-2a26e869 → 2.0.0-30d44ed9

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 (372) hide show
  1. package/Field/FieldBase/index.js +7 -3
  2. package/Field/FieldBase.js.map +2 -2
  3. package/Field/FieldBaseContainer/index.js +37 -18
  4. package/Field/FieldBaseContainer.d.ts +1 -1
  5. package/Field/FieldBaseContainer.js.map +2 -2
  6. package/Field/FieldConditional/index.js +4 -0
  7. package/Field/FieldConditional.js.map +2 -2
  8. package/Field/index.js +15 -4
  9. package/Field/index.js.map +2 -2
  10. package/Field/types.d.ts +13 -3
  11. package/Field/utils/index.js +9 -1
  12. package/Field/utils/index.js.map +2 -2
  13. package/Field/utils/useField/index.js +14 -1
  14. package/Field/utils/useField.js.map +2 -2
  15. package/FieldArray/FieldArray.stories.d.ts +1 -0
  16. package/FieldArray/FormDialog/index.js +397 -0
  17. package/{inputs/Input/inputsInputScenarios → FieldArray/FormDialog}/package.json +1 -1
  18. package/FieldArray/FormDialog.d.ts +66 -0
  19. package/FieldArray/FormDialog.js.map +7 -0
  20. package/FieldArray/__stories__/Default.d.ts +1 -1
  21. package/FieldArray/__stories__/WithExactLength.d.ts +1 -1
  22. package/FieldArray/__stories__/WithModal.d.ts +2 -0
  23. package/FieldArray/index.d.ts +6 -0
  24. package/FieldArray/index.js +82 -24
  25. package/FieldArray/index.js.map +2 -2
  26. package/FieldObject/index.d.ts +5 -0
  27. package/FieldObject/index.js +30 -15
  28. package/FieldObject/index.js.map +2 -2
  29. package/FormBuilder/FormBuilder.stories.d.ts +2 -0
  30. package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +1 -1
  31. package/FormBuilder/__stories__/Default.d.ts +1 -1
  32. package/FormBuilder/__stories__/ErrorGrouping.d.ts +1 -1
  33. package/FormBuilder/index.d.ts +1 -1
  34. package/FormBuilder/index.js +11 -7
  35. package/FormBuilder/index.js.map +2 -2
  36. package/FormContext/index.js +6 -2
  37. package/FormContext.d.ts +1 -0
  38. package/FormContext.js.map +2 -2
  39. package/MultiplicityField/MultiplicityField.stories.d.ts +2 -0
  40. package/MultiplicityField/__stories__/Default.d.ts +1 -1
  41. package/MultiplicityField/__stories__/PreviewDisplay.d.ts +1 -1
  42. package/MultiplicityField/__stories__/WithExactLength.d.ts +1 -1
  43. package/MultiplicityField/__stories__/WithMaxLength.d.ts +1 -1
  44. package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +1 -1
  45. package/MultiplicityField/__stories__/WithMinLength.d.ts +1 -1
  46. package/MultiplicityField/add-objects/index.js +2 -0
  47. package/MultiplicityField/add-objects.js.map +2 -2
  48. package/MultiplicityField/index.js +4 -1
  49. package/MultiplicityField/index.js.map +2 -2
  50. package/MultiplicityField/types.d.ts +1 -0
  51. package/Questions/Questions.stories.d.ts +2 -0
  52. package/Questions/__stories__/Default.d.ts +1 -1
  53. package/cjs/Field/FieldBase/index.js +7 -3
  54. package/cjs/Field/FieldBase.js.map +2 -2
  55. package/cjs/Field/FieldBaseContainer/index.js +36 -17
  56. package/cjs/Field/FieldBaseContainer.js.map +3 -3
  57. package/cjs/Field/FieldConditional/index.js +4 -0
  58. package/cjs/Field/FieldConditional.js.map +2 -2
  59. package/cjs/Field/index.js +15 -4
  60. package/cjs/Field/index.js.map +2 -2
  61. package/cjs/Field/types.js.map +1 -1
  62. package/cjs/Field/utils/index.js +9 -1
  63. package/cjs/Field/utils/index.js.map +3 -3
  64. package/cjs/Field/utils/useField/index.js +14 -1
  65. package/cjs/Field/utils/useField.js.map +2 -2
  66. package/cjs/FieldArray/FormDialog/index.js +416 -0
  67. package/cjs/FieldArray/FormDialog.js.map +7 -0
  68. package/cjs/FieldArray/index.js +81 -23
  69. package/cjs/FieldArray/index.js.map +2 -2
  70. package/cjs/FieldObject/index.js +30 -15
  71. package/cjs/FieldObject/index.js.map +2 -2
  72. package/cjs/FormBuilder/index.js +11 -7
  73. package/cjs/FormBuilder/index.js.map +2 -2
  74. package/cjs/FormContext/index.js +7 -2
  75. package/cjs/FormContext.js.map +2 -2
  76. package/cjs/MultiplicityField/add-objects/index.js +2 -0
  77. package/cjs/MultiplicityField/add-objects.js.map +2 -2
  78. package/cjs/MultiplicityField/index.js +4 -1
  79. package/cjs/MultiplicityField/index.js.map +2 -2
  80. package/cjs/MultiplicityField/types.js.map +1 -1
  81. package/cjs/inputs/AutoCompleteInput/index.js +2 -1
  82. package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
  83. package/cjs/inputs/Checkboxes/index.js +3 -1
  84. package/cjs/inputs/Checkboxes/index.js.map +2 -2
  85. package/cjs/inputs/DateInput/index.js +44 -14
  86. package/cjs/inputs/DateInput/index.js.map +2 -2
  87. package/cjs/inputs/DateTimeInput/index.js +245 -0
  88. package/cjs/inputs/DateTimeInput/index.js.map +7 -0
  89. package/cjs/inputs/FileInput/index.js +68 -30
  90. package/cjs/inputs/FileInput/index.js.map +2 -2
  91. package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  92. package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  93. package/cjs/inputs/ImageInput/index.js +48 -11
  94. package/cjs/inputs/ImageInput/index.js.map +2 -2
  95. package/cjs/inputs/Input/index.js +8 -1
  96. package/cjs/inputs/Input/index.js.map +2 -2
  97. package/cjs/inputs/OtpInput/index.js +1 -0
  98. package/cjs/inputs/OtpInput/index.js.map +2 -2
  99. package/cjs/inputs/Radio/index.js +1 -0
  100. package/cjs/inputs/Radio/index.js.map +2 -2
  101. package/cjs/inputs/Select/index.js +9 -2
  102. package/cjs/inputs/Select/index.js.map +2 -2
  103. package/cjs/inputs/inputsScenarios/index.js +2 -2
  104. package/cjs/inputs/inputsScenarios.js.map +2 -2
  105. package/cjs/lazy/index.js +10 -1
  106. package/cjs/lazy.js.map +2 -2
  107. package/cjs/registry/index.js +12 -6
  108. package/cjs/registry.js.map +2 -2
  109. package/cjs/types.js.map +1 -1
  110. package/cjs/utils/index.js +20 -6
  111. package/cjs/utils.js.map +2 -2
  112. package/cjs/validators/index.js +21 -7
  113. package/cjs/validators/index.js.map +2 -2
  114. package/cjs/validators/utils/amka/index.js +60 -0
  115. package/cjs/validators/utils/amka.js.map +7 -0
  116. package/cjs/validators/utils/date/index.js +26 -3
  117. package/cjs/validators/utils/date.js.map +2 -2
  118. package/cjs/validators/utils/datetime/index.js +245 -0
  119. package/cjs/validators/utils/datetime.js.map +7 -0
  120. package/cjs/validators/utils/file/index.js +30 -17
  121. package/cjs/validators/utils/file.js.map +2 -2
  122. package/cjs/validators/utils/index.js +8 -2
  123. package/cjs/validators/utils/index.js.map +2 -2
  124. package/index.js +1 -1
  125. package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +2 -0
  126. package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -1
  127. package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +1 -1
  128. package/inputs/AutoCompleteInput/index.js +2 -1
  129. package/inputs/AutoCompleteInput/index.js.map +2 -2
  130. package/inputs/Checkboxes/Checkboxes.stories.d.ts +2 -0
  131. package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -1
  132. package/inputs/Checkboxes/__stories__/Default.d.ts +1 -1
  133. package/inputs/Checkboxes/__stories__/WithDivider.d.ts +1 -1
  134. package/inputs/Checkboxes/index.js +3 -1
  135. package/inputs/Checkboxes/index.js.map +2 -2
  136. package/inputs/DateInput/DateInput.stories.d.ts +6 -0
  137. package/inputs/DateInput/__stories__/Default.d.ts +1 -1
  138. package/inputs/DateInput/__stories__/WithDefaultValue.d.ts +3 -0
  139. package/inputs/DateInput/__stories__/WithInitialValue.d.ts +3 -0
  140. package/inputs/DateInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
  141. package/inputs/DateInput/__stories__/WithWrongInitialValue.d.ts +3 -0
  142. package/inputs/DateInput/index.js +45 -15
  143. package/inputs/DateInput/index.js.map +2 -2
  144. package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +14 -0
  145. package/inputs/DateTimeInput/__stories__/Default.d.ts +3 -0
  146. package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +3 -0
  147. package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +3 -0
  148. package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
  149. package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +3 -0
  150. package/inputs/DateTimeInput/index.d.ts +13 -0
  151. package/inputs/DateTimeInput/index.js +215 -0
  152. package/inputs/DateTimeInput/index.js.map +7 -0
  153. package/inputs/DateTimeInput/index.test.d.ts +1 -0
  154. package/inputs/DateTimeInput/package.json +6 -0
  155. package/inputs/FileInput/FileInput.stories.d.ts +3 -0
  156. package/inputs/FileInput/__stories__/Default.d.ts +1 -1
  157. package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
  158. package/inputs/FileInput/index.d.ts +17 -1
  159. package/inputs/FileInput/index.js +73 -32
  160. package/inputs/FileInput/index.js.map +2 -2
  161. package/inputs/ImageInput/ImageInput.stories.d.ts +4 -1
  162. package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
  163. package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
  164. package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
  165. package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
  166. package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  167. package/inputs/ImageInput/__stories__/logo.d/package.json +6 -0
  168. package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  169. package/inputs/ImageInput/index.d.ts +9 -1
  170. package/inputs/ImageInput/index.js +49 -12
  171. package/inputs/ImageInput/index.js.map +2 -2
  172. package/inputs/Input/Input.stories.d.ts +4 -0
  173. package/inputs/Input/__stories__/AFM.d.ts +1 -1
  174. package/inputs/Input/__stories__/AMKA.d.ts +3 -0
  175. package/inputs/Input/__stories__/Boolean.d.ts +1 -1
  176. package/inputs/Input/__stories__/Email.d.ts +3 -0
  177. package/inputs/Input/__stories__/IBAN.d.ts +1 -1
  178. package/inputs/Input/__stories__/Integer.d.ts +1 -1
  179. package/inputs/Input/__stories__/LandlineNumber.d.ts +1 -1
  180. package/inputs/Input/__stories__/MobilePhone.d.ts +1 -1
  181. package/inputs/Input/__stories__/PhoneNumber.d.ts +1 -1
  182. package/inputs/Input/__stories__/PostalCode.d.ts +1 -1
  183. package/inputs/Input/__stories__/String.d.ts +1 -1
  184. package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +1 -1
  185. package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
  186. package/inputs/Input/index.d.ts +2 -1
  187. package/inputs/Input/index.js +8 -1
  188. package/inputs/Input/index.js.map +2 -2
  189. package/inputs/Label/Label.stories.d.ts +2 -0
  190. package/inputs/Label/__stories__/Default.d.ts +1 -1
  191. package/inputs/OtpInput/OtpInput.stories.d.ts +2 -0
  192. package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
  193. package/inputs/OtpInput/index.js +1 -0
  194. package/inputs/OtpInput/index.js.map +2 -2
  195. package/inputs/Radio/Radio.stories.d.ts +2 -0
  196. package/inputs/Radio/__stories__/Conditional.d.ts +1 -1
  197. package/inputs/Radio/__stories__/Default.d.ts +1 -1
  198. package/inputs/Radio/__stories__/WithDivider.d.ts +1 -1
  199. package/inputs/Radio/index.js +1 -0
  200. package/inputs/Radio/index.js.map +2 -2
  201. package/inputs/Select/Select.stories.d.ts +2 -0
  202. package/inputs/Select/__stories__/Default.d.ts +1 -1
  203. package/inputs/Select/index.d.ts +2 -1
  204. package/inputs/Select/index.js +9 -2
  205. package/inputs/Select/index.js.map +2 -2
  206. package/inputs/inputsScenarios/index.js +2 -2
  207. package/inputs/inputsScenarios.d.ts +1 -1
  208. package/inputs/inputsScenarios.js.map +2 -2
  209. package/lazy/index.js +10 -1
  210. package/package.json +8 -8
  211. package/registry/index.js +12 -6
  212. package/src/Field/FieldBase.tsx +6 -2
  213. package/src/Field/FieldBaseContainer.tsx +68 -46
  214. package/src/Field/FieldConditional.tsx +4 -0
  215. package/src/Field/doc.mdx +202 -1
  216. package/src/Field/index.tsx +20 -5
  217. package/src/Field/types.tsx +15 -3
  218. package/src/Field/utils/index.ts +8 -0
  219. package/src/Field/utils/useField.ts +14 -2
  220. package/src/FieldArray/FieldArray.stories.js +1 -0
  221. package/src/FieldArray/FormDialog.tsx +565 -0
  222. package/src/FieldArray/__stories__/Default.tsx +2 -1
  223. package/src/FieldArray/__stories__/WithExactLength.tsx +2 -1
  224. package/src/FieldArray/__stories__/WithModal.tsx +160 -0
  225. package/src/FieldArray/index.test.tsx +8 -0
  226. package/src/FieldArray/index.tsx +112 -48
  227. package/src/FieldObject/index.tsx +39 -18
  228. package/src/FormBuilder/FormBuilder.stories.js +3 -0
  229. package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +1 -1
  230. package/src/FormBuilder/__stories__/Default.tsx +1 -1
  231. package/src/FormBuilder/__stories__/ErrorGrouping.tsx +1 -1
  232. package/src/FormBuilder/doc.mdx +9 -4
  233. package/src/FormBuilder/index.test.tsx +20 -17
  234. package/src/FormBuilder/index.tsx +12 -7
  235. package/src/FormBuilder/interaction.test.tsx +8 -0
  236. package/src/FormBuilder/scenarios.test.tsx +771 -6
  237. package/src/FormContext.tsx +5 -1
  238. package/src/MultiplicityField/MultiplicityField.stories.js +3 -0
  239. package/src/MultiplicityField/__stories__/Default.tsx +1 -1
  240. package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +1 -1
  241. package/src/MultiplicityField/__stories__/WithExactLength.tsx +1 -1
  242. package/src/MultiplicityField/__stories__/WithMaxLength.tsx +1 -1
  243. package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +1 -1
  244. package/src/MultiplicityField/__stories__/WithMinLength.tsx +1 -1
  245. package/src/MultiplicityField/add-objects.tsx +2 -0
  246. package/src/MultiplicityField/doc.mdx +101 -83
  247. package/src/MultiplicityField/index.test.tsx +4 -0
  248. package/src/MultiplicityField/index.tsx +3 -0
  249. package/src/MultiplicityField/types.ts +1 -0
  250. package/src/Questions/Questions.stories.js +3 -0
  251. package/src/Questions/__snapshots__/index.spec.tsx.snap +2 -1
  252. package/src/Questions/__stories__/Default.tsx +1 -1
  253. package/src/Questions/doc.mdx +21 -41
  254. package/src/Questions/index.test.tsx +4 -0
  255. package/src/doc.mdx +26 -11
  256. package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +3 -0
  257. package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +1 -1
  258. package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +1 -1
  259. package/src/inputs/AutoCompleteInput/index.test.tsx +4 -0
  260. package/src/inputs/AutoCompleteInput/index.tsx +1 -0
  261. package/src/inputs/Checkboxes/Checkboxes.stories.js +3 -0
  262. package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
  263. package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
  264. package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
  265. package/src/inputs/Checkboxes/index.test.tsx +4 -0
  266. package/src/inputs/Checkboxes/index.tsx +3 -5
  267. package/src/inputs/DateInput/DateInput.stories.js +7 -0
  268. package/src/inputs/DateInput/__stories__/Default.tsx +1 -1
  269. package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +26 -0
  270. package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +28 -0
  271. package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +26 -0
  272. package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +28 -0
  273. package/src/inputs/DateInput/index.test.tsx +20 -0
  274. package/src/inputs/DateInput/index.tsx +49 -14
  275. package/src/inputs/DateTimeInput/DateTimeInput.stories.js +14 -0
  276. package/src/inputs/DateTimeInput/__stories__/Default.tsx +25 -0
  277. package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +26 -0
  278. package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +28 -0
  279. package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +26 -0
  280. package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +28 -0
  281. package/src/inputs/DateTimeInput/doc.mdx +16 -0
  282. package/src/inputs/DateTimeInput/index.test.tsx +40 -0
  283. package/src/inputs/DateTimeInput/index.tsx +233 -0
  284. package/src/inputs/FileInput/FileInput.stories.js +4 -0
  285. package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
  286. package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
  287. package/src/inputs/FileInput/index.test.tsx +8 -0
  288. package/src/inputs/FileInput/index.tsx +104 -38
  289. package/src/inputs/ImageInput/ImageInput.stories.js +5 -1
  290. package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
  291. package/src/inputs/ImageInput/__stories__/MaxSize.tsx +3 -2
  292. package/src/inputs/ImageInput/__stories__/{WithInvalidImageSize.tsx → WithInitialValues.tsx} +12 -3
  293. package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +1 -1
  294. package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
  295. package/src/inputs/ImageInput/__stories__/logo.png +0 -0
  296. package/src/inputs/ImageInput/index.test.tsx +8 -4
  297. package/src/inputs/ImageInput/index.tsx +100 -42
  298. package/src/inputs/Input/Input.stories.js +5 -0
  299. package/src/inputs/Input/__stories__/AFM.tsx +1 -1
  300. package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
  301. package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
  302. package/src/inputs/Input/__stories__/Email.tsx +23 -0
  303. package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
  304. package/src/inputs/Input/__stories__/Integer.tsx +1 -1
  305. package/src/inputs/Input/__stories__/LandlineNumber.tsx +1 -1
  306. package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -1
  307. package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -1
  308. package/src/inputs/Input/__stories__/PostalCode.tsx +1 -1
  309. package/src/inputs/Input/__stories__/String.tsx +1 -1
  310. package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +1 -1
  311. package/src/inputs/Input/__stories__/TextWithLimit.tsx +1 -1
  312. package/src/inputs/Input/index.test.tsx +12 -0
  313. package/src/inputs/Input/index.tsx +11 -2
  314. package/src/inputs/Label/Label.stories.js +3 -0
  315. package/src/inputs/Label/__stories__/Default.tsx +1 -1
  316. package/src/inputs/Label/index.test.tsx +4 -0
  317. package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
  318. package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
  319. package/src/inputs/OtpInput/index.test.tsx +4 -0
  320. package/src/inputs/OtpInput/index.tsx +1 -0
  321. package/src/inputs/Radio/Radio.stories.js +3 -0
  322. package/src/inputs/Radio/__stories__/Conditional.tsx +1 -1
  323. package/src/inputs/Radio/__stories__/Default.tsx +1 -1
  324. package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
  325. package/src/inputs/Radio/index.test.tsx +4 -0
  326. package/src/inputs/Radio/index.tsx +1 -0
  327. package/src/inputs/Select/Select.stories.js +3 -0
  328. package/src/inputs/Select/__stories__/Default.tsx +1 -1
  329. package/src/inputs/Select/index.test.tsx +4 -0
  330. package/src/inputs/Select/index.tsx +13 -4
  331. package/src/inputs/inputsScenarios.ts +2 -2
  332. package/src/lazy.js +10 -1
  333. package/src/registry.js +12 -6
  334. package/src/types.tsx +2 -1
  335. package/src/utils.ts +27 -6
  336. package/src/validators/index.ts +30 -7
  337. package/src/validators/utils/amka.ts +39 -0
  338. package/src/validators/utils/date.ts +28 -4
  339. package/src/validators/utils/datetime.ts +222 -0
  340. package/src/validators/utils/file.ts +33 -19
  341. package/src/validators/utils/index.ts +5 -1
  342. package/types.d.ts +2 -1
  343. package/types.js.map +1 -1
  344. package/utils/index.js +20 -6
  345. package/utils.d.ts +2 -0
  346. package/utils.js.map +2 -2
  347. package/validators/index.d.ts +1 -1
  348. package/validators/index.js +26 -8
  349. package/validators/index.js.map +2 -2
  350. package/validators/utils/amka/index.js +36 -0
  351. package/validators/utils/amka/package.json +6 -0
  352. package/validators/utils/amka.d.ts +6 -0
  353. package/validators/utils/amka.js.map +7 -0
  354. package/validators/utils/date/index.js +26 -3
  355. package/validators/utils/date.d.ts +1 -1
  356. package/validators/utils/date.js.map +2 -2
  357. package/validators/utils/datetime/index.js +210 -0
  358. package/validators/utils/datetime/package.json +6 -0
  359. package/validators/utils/datetime.d.ts +9 -0
  360. package/validators/utils/datetime.js.map +7 -0
  361. package/validators/utils/file/index.js +30 -17
  362. package/validators/utils/file.js.map +2 -2
  363. package/validators/utils/index.d.ts +2 -0
  364. package/validators/utils/index.js +5 -1
  365. package/validators/utils/index.js.map +2 -2
  366. package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
  367. package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
  368. package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +0 -3
  369. package/inputs/Input/inputsInputScenarios/index.js +0 -406
  370. package/inputs/Input/inputsInputScenarios.d.ts +0 -57
  371. package/inputs/Input/inputsInputScenarios.js.map +0 -7
  372. package/src/inputs/Input/inputsInputScenarios.ts +0 -404
@@ -0,0 +1,39 @@
1
+ function digitSum(number) {
2
+ const sum = number > 9 ? 1 : 0;
3
+ return sum + (number % 10);
4
+ }
5
+
6
+ export function validateAMKA(amka: string): boolean {
7
+ // Validate that the last digit is the correct check digit (created using the
8
+ // Luhn algorithm https://en.wikipedia.org/wiki/Luhn_algorithm).
9
+ amka = String(amka);
10
+ const checkDigitIndex = amka.length - 1;
11
+ let sum = 0;
12
+ amka
13
+ .substring(0, checkDigitIndex)
14
+ .split('')
15
+ .reverse()
16
+ .forEach(function (value, index) {
17
+ const weight = ((index + 1) % 2) + 1;
18
+ sum += digitSum(parseInt(value, 10) * weight);
19
+ });
20
+ const sumMod10 = sum % 10;
21
+ if (sumMod10 === 0) {
22
+ return amka.substring(checkDigitIndex) === '0';
23
+ } else {
24
+ return amka.substring(checkDigitIndex) === 10 - sumMod10 + '';
25
+ }
26
+ }
27
+
28
+ export const AMKA_VALIDATOR = {
29
+ name: 'amka-validator',
30
+ message: 'form.error.amka',
31
+ test: (value): boolean => {
32
+ if (!value) return true;
33
+ const AMKA_REGEX = /^[0-9]{11}$/;
34
+ if (!AMKA_REGEX.test(value) || value === '00000000000') {
35
+ return false;
36
+ }
37
+ return validateAMKA(value);
38
+ },
39
+ };
@@ -7,14 +7,18 @@ dayjs.extend(customParseFormat);
7
7
 
8
8
  const VALID_DATE_FORMATS = ['DD/MM/YYYY'];
9
9
  const DATE_CACHE = {};
10
+ const onlyNumbersRegex = /^\d+$/;
10
11
 
11
12
  const getDate = (v: string) => {
12
13
  return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
13
14
  };
14
15
 
16
+ const getDaysInMonth = (month: number, year: number): number => {
17
+ return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
18
+ };
19
+
15
20
  // Function to check partial date completion
16
21
  const checkPartialDate = (value: string) => {
17
- console.log("value.split('/')", value.split('/'));
18
22
  const [day, month, year] = value.split('/');
19
23
  if (day && !month && !year) {
20
24
  return 'form.error.date.invalid_month_year';
@@ -33,9 +37,29 @@ const checkPartialDate = (value: string) => {
33
37
  }
34
38
  if (!day && month && year) {
35
39
  return 'form.error.date.invalid_day';
36
- } else {
37
- return 'form.error.date.invalid';
38
40
  }
41
+ if (day && month) {
42
+ const dayNum = parseInt(day);
43
+ const monthNum = parseInt(month);
44
+ const validYear = onlyNumbersRegex.test(year) ? year : undefined;
45
+ if (!validYear || year.length < 4) {
46
+ return 'form.error.date.invalid';
47
+ }
48
+ const yearNum = parseInt(validYear);
49
+ const maxDay = getDaysInMonth(monthNum, yearNum);
50
+ if (dayNum < 1 || dayNum > maxDay) {
51
+ return {
52
+ key: 'form.error.date.invalid_day_range',
53
+ context: {
54
+ maxDay: maxDay,
55
+ },
56
+ };
57
+ }
58
+ if (monthNum < 1 || monthNum > 12) {
59
+ return 'form.error.datetime.invalid_month_range';
60
+ }
61
+ }
62
+ return 'form.error.date.invalid';
39
63
  };
40
64
 
41
65
  export const LATER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
@@ -96,7 +120,7 @@ export const EARLIER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
96
120
 
97
121
  export const DATE_VALIDATOR = {
98
122
  name: 'date-validator',
99
- message: (v): string => {
123
+ message: (v): string | object => {
100
124
  return checkPartialDate(v.value);
101
125
  },
102
126
  test: function (value: string) {
@@ -0,0 +1,222 @@
1
+ import dayjs from 'dayjs';
2
+ import customParseFormat from 'dayjs/plugin/customParseFormat';
3
+ import { FieldSpec } from '@digigov/form/types';
4
+ import { ValidatorSchema } from '@digigov/form/validators/types';
5
+
6
+ dayjs.extend(customParseFormat);
7
+
8
+ const VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];
9
+ const DATETIME_CACHE = {};
10
+ const onlyNumbersRegex = /^\d+$/;
11
+
12
+ const getDateTime = (v: string) => {
13
+ return DATETIME_CACHE[v]
14
+ ? DATETIME_CACHE[v]
15
+ : dayjs(v, VALID_DATETIME_FORMATS, true);
16
+ };
17
+
18
+ const getDaysInMonth = (month: number, year: number): number => {
19
+ return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
20
+ };
21
+
22
+ const checkPartialDateTime = (value: string) => {
23
+ const [datePart, timePart] = value.split(' ');
24
+ const [day, month, year] = datePart?.split('/') ?? [];
25
+ const [hours, minutes] = timePart?.split(':') ?? [];
26
+
27
+ const hasDay = Boolean(day);
28
+ const hasMonth = Boolean(month);
29
+ const hasYear = Boolean(year);
30
+ const hasHours = Boolean(hours);
31
+ const hasMinutes = Boolean(minutes);
32
+
33
+ if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {
34
+ return 'form.error.datetime.invalid_month_year_hours_minutes';
35
+ }
36
+ if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
37
+ return 'form.error.datetime.invalid_day_year_hours_minutes';
38
+ }
39
+ if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
40
+ return 'form.error.datetime.invalid_day_month_hours_minutes';
41
+ }
42
+ if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
43
+ return 'form.error.datetime.invalid_year_hours_minutes';
44
+ }
45
+ if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
46
+ return 'form.error.datetime.invalid_month_hours_minutes';
47
+ }
48
+ if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
49
+ return 'form.error.datetime.invalid_day_hours_minutes';
50
+ }
51
+ if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
52
+ return 'form.error.datetime.invalid__hours_minutes';
53
+ }
54
+ if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
55
+ return 'form.error.datetime.invalid_minutes';
56
+ }
57
+ if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
58
+ return 'form.error.datetime.invalid_hours';
59
+ }
60
+ if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
61
+ return 'form.error.datetime.invalid_month_year_minutes';
62
+ }
63
+ if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
64
+ return 'form.error.datetime.invalid_month_year_hours';
65
+ }
66
+ if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
67
+ return 'form.error.datetime.invalid_month_year';
68
+ }
69
+ if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
70
+ return 'form.error.datetime.invalid_day_year_minutes';
71
+ }
72
+ if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
73
+ return 'form.error.datetime.invalid_day_year_hours';
74
+ }
75
+ if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
76
+ return 'form.error.datetime.invalid_day_year';
77
+ }
78
+ if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
79
+ return 'form.error.datetime.invalid_day_month_minutes';
80
+ }
81
+ if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
82
+ return 'form.error.datetime.invalid_day_month_hours';
83
+ }
84
+ if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
85
+ return 'form.error.datetime.invalid_day_month';
86
+ }
87
+ if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
88
+ return 'form.error.datetime.invalid_day_month_year';
89
+ }
90
+ if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
91
+ return 'form.error.datetime.invalid_day_month_year_hours';
92
+ }
93
+ if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
94
+ return 'form.error.datetime.invalid_year_minutes';
95
+ }
96
+ if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
97
+ return 'form.error.datetime.invalid_year_hours';
98
+ }
99
+ if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
100
+ return 'form.error.datetime.invalid_year';
101
+ }
102
+ if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
103
+ return 'form.error.datetime.invalid_month_minutes';
104
+ }
105
+ if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
106
+ return 'form.error.datetime.invalid_month_hours';
107
+ }
108
+ if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
109
+ return 'form.error.datetime.invalid_month';
110
+ }
111
+ if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
112
+ return 'form.error.datetime.invalid_day_minutes';
113
+ }
114
+ if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
115
+ return 'form.error.datetime.invalid_day_hours';
116
+ }
117
+ if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {
118
+ return 'form.error.datetime.invalid_day';
119
+ }
120
+ if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
121
+ return 'form.error.datetime.invalid_day_month_year_minutes';
122
+ }
123
+ if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
124
+ return 'form.error.datetime.invalid_hours_minutes';
125
+ }
126
+ if (day && month) {
127
+ const dayNum = parseInt(day);
128
+ const monthNum = parseInt(month);
129
+ const validYear = onlyNumbersRegex.test(year) ? year : undefined;
130
+ if (!validYear || year.length < 4) {
131
+ return 'form.error.datetime.invalid';
132
+ }
133
+ const yearNum = parseInt(validYear);
134
+ const maxDay = getDaysInMonth(monthNum, yearNum);
135
+ if (dayNum < 1 || dayNum > maxDay) {
136
+ return {
137
+ key: 'form.error.datetime.invalid_day_range',
138
+ context: {
139
+ maxDay: maxDay,
140
+ },
141
+ };
142
+ }
143
+ if (monthNum < 1 || monthNum > 12) {
144
+ return 'form.error.datetime.invalid_month_range';
145
+ }
146
+ }
147
+ if (hours && minutes) {
148
+ const hoursNum = parseInt(hours);
149
+ const minutesNum = parseInt(minutes);
150
+ if (hoursNum < 0 || hoursNum > 23) {
151
+ return 'form.error.datetime.invalid_hours_range';
152
+ }
153
+ if (minutesNum < 0 || minutesNum > 59) {
154
+ return 'form.error.datetime.invalid_minutes_range';
155
+ }
156
+ }
157
+ return 'form.error.datetime.invalid';
158
+ };
159
+
160
+ export const LATER_THAN_DATETIME_VALIDATOR = (
161
+ field: FieldSpec
162
+ ): ValidatorSchema => {
163
+ let minDateTime;
164
+ const params = field.extra || {};
165
+ if (params.min === 'now') {
166
+ minDateTime = dayjs();
167
+ } else {
168
+ minDateTime = getDateTime(params.min);
169
+ }
170
+ return {
171
+ name: 'later-than-datetime',
172
+ message: {
173
+ key: 'form.error.datetime.later_than',
174
+ context: {
175
+ minDateTime: minDateTime.format('DD/MM/YYYY HH:mm'),
176
+ },
177
+ },
178
+ test: function (value: string) {
179
+ if (!value) return true;
180
+ const datetime = getDateTime(value);
181
+ return datetime.isValid() && datetime.isAfter(minDateTime);
182
+ },
183
+ };
184
+ };
185
+
186
+ export const EARLIER_THAN_DATETIME_VALIDATOR = (
187
+ field: FieldSpec
188
+ ): ValidatorSchema => {
189
+ let maxDateTime;
190
+ const params = field.extra || {};
191
+ if (params.max === 'now') {
192
+ maxDateTime = dayjs();
193
+ } else {
194
+ maxDateTime = getDateTime(params.max);
195
+ }
196
+ return {
197
+ name: 'earlier-than-datetime',
198
+ message: {
199
+ key: 'form.error.datetime.earlier_than',
200
+ context: {
201
+ maxDateTime: maxDateTime.format('DD/MM/YYYY HH:mm'),
202
+ },
203
+ },
204
+ test: function (value: string) {
205
+ if (!value) return true;
206
+ const datetime = getDateTime(value);
207
+ return datetime.isValid() && datetime.isBefore(maxDateTime);
208
+ },
209
+ };
210
+ };
211
+
212
+ export const DATETIME_VALIDATOR = {
213
+ name: 'datetime-validator',
214
+ message: (v): string | object => {
215
+ return checkPartialDateTime(v.value);
216
+ },
217
+ test: function (value: string) {
218
+ if (!value) return true;
219
+ const datetime = getDateTime(value);
220
+ return datetime.isValid();
221
+ },
222
+ };
@@ -3,25 +3,39 @@ import { ValidatorSchema } from '@digigov/form/validators/types';
3
3
 
4
4
  const DEFAULT_FILE_MAX_SIZE = 10000000;
5
5
 
6
- export const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => ({
7
- name: 'file-max-size-validator',
8
- message: {
9
- key:
10
- field.type === 'file' ? 'form.error.file_size' : 'form.error.image_size',
11
- context: {
12
- maxSizeToMb:
13
- (field?.extra?.limit.maxSize || DEFAULT_FILE_MAX_SIZE) / 1000000,
6
+ export const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
7
+ const maxSizeInBytes = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
8
+ let maxSizeTransformed = maxSizeInBytes / (1024 * 1024); // In MB
9
+ let maxSizeText = 'MB';
10
+ if (Math.round(maxSizeTransformed) === 0) {
11
+ maxSizeTransformed = Math.round(maxSizeInBytes / 1024);
12
+ maxSizeText = 'KB';
13
+ }
14
+ if (Math.round(maxSizeTransformed) === 0) {
15
+ maxSizeTransformed = maxSizeInBytes;
16
+ maxSizeText = 'Bytes';
17
+ }
18
+ return {
19
+ name: 'file-max-size-validator',
20
+ message: {
21
+ key:
22
+ field.type === 'file'
23
+ ? 'form.error.file_size'
24
+ : 'form.error.image_size',
25
+ context: {
26
+ maxSize: `${maxSizeTransformed} ${maxSizeText}`,
27
+ },
14
28
  },
15
- },
16
- test: (value: File[]): boolean => {
17
- if (value) {
18
- for (const file of value) {
19
- const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
20
- if (file.size > maxSize) {
21
- return false;
29
+ test: (value: File[]): boolean => {
30
+ if (value) {
31
+ for (const file of Array.from(value)) {
32
+ const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
33
+ if (file.size > maxSize) {
34
+ return false;
35
+ }
22
36
  }
23
37
  }
24
- }
25
- return true;
26
- },
27
- });
38
+ return true;
39
+ },
40
+ };
41
+ };
@@ -3,6 +3,7 @@ import { FieldSpec } from '@digigov/form/types';
3
3
  import { ValidatorSchema } from '@digigov/form/validators/types';
4
4
 
5
5
  export * from '@digigov/form/validators/utils/afm';
6
+ export * from '@digigov/form/validators/utils/amka';
6
7
  export * from '@digigov/form/validators/utils/file';
7
8
  export * from '@digigov/form/validators/utils/iban';
8
9
  export * from '@digigov/form/validators/utils/otp';
@@ -12,6 +13,7 @@ export * from '@digigov/form/validators/utils/postal_code';
12
13
  export * from '@digigov/form/validators/utils/uuid4';
13
14
  export * from '@digigov/form/validators/utils/text_limit';
14
15
  export * from '@digigov/form/validators/utils/date';
16
+ export * from '@digigov/form/validators/utils/datetime';
15
17
 
16
18
  export function getYupField(field: FieldSpec, yupTypeMap: Record<string, any>) {
17
19
  const yupField = yupTypeMap[field?.type || 'string'] || yupTypeMap['string'];
@@ -97,7 +99,9 @@ export function getYupObjectShape(
97
99
 
98
100
  return yup.lazy(function () {
99
101
  const fieldSchemas = computeShape(
100
- Object.values(fields.current),
102
+ Object.values(fields.current).filter(
103
+ (f: FieldSpec) => !f.key.includes('.')
104
+ ) as FieldSpec[],
101
105
  yupTypeMap,
102
106
  validatorRegistry
103
107
  );
package/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UseFormReturn, UseFormProps } from 'react-hook-form';
1
+ import { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';
2
2
  import { FieldComponentRegistry, FieldLabelProps, FieldSpec, FormData } from '@digigov/form/Field/types';
3
3
  import { ValidatorSchema } from '@digigov/form/validators/types';
4
4
  export * from '@digigov/form/Field/types';
@@ -46,6 +46,7 @@ export interface FormBuilderProps {
46
46
  componentRegistry?: FieldComponentRegistry;
47
47
  grid?: boolean;
48
48
  controlledFieldsOnly?: boolean;
49
+ errors?: ErrorOption;
49
50
  }
50
51
  export interface FormBaseProps extends Omit<FormBuilderProps, 'fields' | 'fieldsets' | 'auto'> {
51
52
  fieldsetsMap?: Record<string, FieldsetSpec>;
package/types.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/types.tsx"],
4
- "sourcesContent": ["import { UseFormReturn, UseFormProps } from 'react-hook-form';\nimport {\n FieldComponentRegistry,\n FieldLabelProps,\n FieldSpec,\n FormData,\n} from '@digigov/form/Field/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\nexport * from '@digigov/form/Field/types';\nexport interface FieldError {\n message: string;\n}\n\nexport interface FieldsetSpec {\n key: string;\n fields: string[];\n label?: FieldLabelProps;\n body?: React.ReactNode;\n}\n\nexport interface FormContextProps {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n control: UseFormReturn['control'];\n register: UseFormReturn['register'];\n trigger: UseFormReturn['trigger'];\n clearErrors: UseFormReturn['clearErrors'];\n watch: UseFormReturn['watch'];\n getFieldState: UseFormReturn['getFieldState'];\n setValue: UseFormReturn['setValue'];\n getValues: UseFormReturn['getValues'];\n unregister: UseFormReturn['unregister'];\n formState: UseFormReturn['formState'];\n reset: UseFormReturn['reset'];\n resetField: UseFormReturn['resetField'];\n registerField: (field: FieldSpec) => void;\n errors: UseFormReturn['formState']['errors'];\n componentRegistry?: FieldComponentRegistry;\n submit: () => Promise<void>;\n}\n\nexport interface FormBuilderProps {\n fields?: FieldSpec[];\n fieldsets?: FieldsetSpec[];\n initial?: FormData;\n onSubmit?: (data: FormData) => void | null | FieldError[];\n mode?: UseFormProps['mode'];\n reValidateMode?: UseFormProps['reValidateMode'];\n criteriaMode?: UseFormProps['criteriaMode'];\n children?: React.ReactNode;\n shouldFocusError?: boolean;\n auto?: boolean;\n validatorRegistry?: Record<string, ValidatorSchema[]>;\n componentRegistry?: FieldComponentRegistry;\n grid?: boolean;\n controlledFieldsOnly?: boolean;\n}\n\nexport interface FormBaseProps\n extends Omit<FormBuilderProps, 'fields' | 'fieldsets' | 'auto'> {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n registerField: (field: FieldSpec) => void;\n resolver: any;\n}\n"],
4
+ "sourcesContent": ["import { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';\nimport {\n FieldComponentRegistry,\n FieldLabelProps,\n FieldSpec,\n FormData,\n} from '@digigov/form/Field/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\nexport * from '@digigov/form/Field/types';\nexport interface FieldError {\n message: string;\n}\n\nexport interface FieldsetSpec {\n key: string;\n fields: string[];\n label?: FieldLabelProps;\n body?: React.ReactNode;\n}\n\nexport interface FormContextProps {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n control: UseFormReturn['control'];\n register: UseFormReturn['register'];\n trigger: UseFormReturn['trigger'];\n clearErrors: UseFormReturn['clearErrors'];\n watch: UseFormReturn['watch'];\n getFieldState: UseFormReturn['getFieldState'];\n setValue: UseFormReturn['setValue'];\n getValues: UseFormReturn['getValues'];\n unregister: UseFormReturn['unregister'];\n formState: UseFormReturn['formState'];\n reset: UseFormReturn['reset'];\n resetField: UseFormReturn['resetField'];\n registerField: (field: FieldSpec) => void;\n errors: UseFormReturn['formState']['errors'];\n componentRegistry?: FieldComponentRegistry;\n submit: () => Promise<void>;\n}\n\nexport interface FormBuilderProps {\n fields?: FieldSpec[];\n fieldsets?: FieldsetSpec[];\n initial?: FormData;\n onSubmit?: (data: FormData) => void | null | FieldError[];\n mode?: UseFormProps['mode'];\n reValidateMode?: UseFormProps['reValidateMode'];\n criteriaMode?: UseFormProps['criteriaMode'];\n children?: React.ReactNode;\n shouldFocusError?: boolean;\n auto?: boolean;\n validatorRegistry?: Record<string, ValidatorSchema[]>;\n componentRegistry?: FieldComponentRegistry;\n grid?: boolean;\n controlledFieldsOnly?: boolean;\n errors?: ErrorOption;\n}\n\nexport interface FormBaseProps\n extends Omit<FormBuilderProps, 'fields' | 'fieldsets' | 'auto'> {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n registerField: (field: FieldSpec) => void;\n resolver: any;\n}\n"],
5
5
  "mappings": "AAQA,cAAc;",
6
6
  "names": []
7
7
  }
package/utils/index.js CHANGED
@@ -23,6 +23,20 @@ const parseErrorSchema = (error, validateAllFieldCriteria) => {
23
23
  {}
24
24
  );
25
25
  };
26
+ function isPlainObject(obj) {
27
+ return typeof obj === "object" && obj !== null && Object.prototype.toString.call(obj) === "[object Object]";
28
+ }
29
+ function flattenObject(obj, prefix = "") {
30
+ return Object.keys(obj).reduce((acc, key) => {
31
+ const prefixedKey = prefix ? `${prefix}.${key}` : key;
32
+ if (isPlainObject(obj[key])) {
33
+ Object.assign(acc, flattenObject(obj[key], prefixedKey));
34
+ } else {
35
+ acc[prefixedKey] = obj[key];
36
+ }
37
+ return acc;
38
+ }, {});
39
+ }
26
40
  const yupResolver = (schema, schemaOptions = {}, resolverOptions = {}) => async (values, context, options) => {
27
41
  try {
28
42
  if (schemaOptions.context && process.env.NODE_ENV === "development") {
@@ -31,7 +45,7 @@ const yupResolver = (schema, schemaOptions = {}, resolverOptions = {}) => async
31
45
  );
32
46
  }
33
47
  const result = await schema[resolverOptions.mode === "sync" ? "validateSync" : "validate"](
34
- values,
48
+ flattenObject(values),
35
49
  Object.assign({ abortEarly: false }, schemaOptions, { context })
36
50
  );
37
51
  if (options.shouldUseNativeValidation)
@@ -44,13 +58,13 @@ const yupResolver = (schema, schemaOptions = {}, resolverOptions = {}) => async
44
58
  if (!e.inner) {
45
59
  throw e;
46
60
  }
47
- const parsed = parseErrorSchema(
48
- e,
49
- !options.shouldUseNativeValidation && options.criteriaMode === "all"
50
- );
51
61
  return {
52
62
  values: {},
53
- errors: parsed
63
+ errors: parseErrorSchema(
64
+ e,
65
+ !options.shouldUseNativeValidation && options.criteriaMode === "all"
66
+ ),
67
+ options
54
68
  };
55
69
  }
56
70
  };
package/utils.d.ts CHANGED
@@ -2,7 +2,9 @@ import { FieldError } from 'react-hook-form';
2
2
  export declare const yupResolver: (schema: any, schemaOptions?: any, resolverOptions?: any) => (values: any, context: any, options: any) => Promise<{
3
3
  values: any;
4
4
  errors: {};
5
+ options?: undefined;
5
6
  } | {
6
7
  values: {};
7
8
  errors: Record<string, FieldError>;
9
+ options: any;
8
10
  }>;
package/utils.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/utils.ts"],
4
- "sourcesContent": ["import { validateFieldsNatively } from '@hookform/resolvers';\nimport { appendErrors, FieldError } from 'react-hook-form';\nimport * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nconst parseErrorSchema = (\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean\n) => {\n return (error.inner || []).reduce<Record<string, FieldError>>(\n (previous, error) => {\n error.path = error.path?.replace(/\\[([0-9]+)\\]/g, '.$1');\n if (!previous[error.path!]) {\n previous[error.path!] = { message: error.message, type: error.type! };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[error.path!].types;\n const messages = types && types[error.type!];\n\n previous[error.path!] = appendErrors(\n error.path!,\n validateAllFieldCriteria,\n previous,\n error.type!,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message\n ) as FieldError;\n }\n\n return previous;\n },\n {}\n );\n};\n\nexport const yupResolver =\n (schema: any, schemaOptions: any = {}, resolverOptions: any = {}) =>\n async (values, context, options) => {\n try {\n if (schemaOptions.context && process.env.NODE_ENV === 'development') {\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\"\n );\n }\n\n const result = await schema[\n resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'\n ](\n values,\n Object.assign({ abortEarly: false }, schemaOptions, { context })\n );\n\n if (options.shouldUseNativeValidation)\n validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.rawValues ? values : result,\n errors: {},\n };\n } catch (e) {\n if (!e.inner) {\n throw e;\n }\n\n const parsed = parseErrorSchema(\n e,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all'\n );\n return {\n values: {},\n errors: parsed,\n };\n }\n };\n"],
5
- "mappings": "AAAA,SAAS,8BAA8B;AACvC,SAAS,oBAAgC;AAOzC,MAAM,mBAAmB,CACvB,OACA,6BACG;AACH,UAAQ,MAAM,SAAS,CAAC,GAAG;AAAA,IACzB,CAAC,UAAUA,WAAU;AACnB,MAAAA,OAAM,OAAOA,OAAM,MAAM,QAAQ,iBAAiB,KAAK;AACvD,UAAI,CAAC,SAASA,OAAM,IAAK,GAAG;AAC1B,iBAASA,OAAM,IAAK,IAAI,EAAE,SAASA,OAAM,SAAS,MAAMA,OAAM,KAAM;AAAA,MACtE;AAEA,UAAI,0BAA0B;AAC5B,cAAM,QAAQ,SAASA,OAAM,IAAK,EAAE;AACpC,cAAM,WAAW,SAAS,MAAMA,OAAM,IAAK;AAE3C,iBAASA,OAAM,IAAK,IAAI;AAAA,UACtBA,OAAM;AAAA,UACN;AAAA,UACA;AAAA,UACAA,OAAM;AAAA,UACN,WACK,CAAC,EAAe,OAAO,UAAsBA,OAAM,OAAO,IAC3DA,OAAM;AAAA,QACZ;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;AAEO,MAAM,cACX,CAAC,QAAa,gBAAqB,CAAC,GAAG,kBAAuB,CAAC,MAC/D,OAAO,QAAQ,SAAS,YAAY;AAClC,MAAI;AACF,QAAI,cAAc,WAAW,QAAQ,IAAI,aAAa,eAAe;AACnE,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,OACnB,gBAAgB,SAAS,SAAS,iBAAiB,UACrD;AAAA,MACE;AAAA,MACA,OAAO,OAAO,EAAE,YAAY,MAAM,GAAG,eAAe,EAAE,QAAQ,CAAC;AAAA,IACjE;AAEA,QAAI,QAAQ;AACV,6BAAuB,CAAC,GAAG,OAAO;AAEpC,WAAO;AAAA,MACL,QAAQ,gBAAgB,YAAY,SAAS;AAAA,MAC7C,QAAQ,CAAC;AAAA,IACX;AAAA,EACF,SAAS,GAAG;AACV,QAAI,CAAC,EAAE,OAAO;AACZ,YAAM;AAAA,IACR;AAEA,UAAM,SAAS;AAAA,MACb;AAAA,MACA,CAAC,QAAQ,6BAA6B,QAAQ,iBAAiB;AAAA,IACjE;AACA,WAAO;AAAA,MACL,QAAQ,CAAC;AAAA,MACT,QAAQ;AAAA,IACV;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { validateFieldsNatively } from '@hookform/resolvers';\nimport { appendErrors, FieldError } from 'react-hook-form';\nimport * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nconst parseErrorSchema = (\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean\n) => {\n return (error.inner || []).reduce<Record<string, FieldError>>(\n (previous, error) => {\n error.path = error.path?.replace(/\\[([0-9]+)\\]/g, '.$1');\n // error.path = error.path?.replace(/\\[\"(.*?)\"\\]/g, '$1');\n if (!previous[error.path!]) {\n previous[error.path!] = { message: error.message, type: error.type! };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[error.path!].types;\n const messages = types && types[error.type!];\n\n previous[error.path!] = appendErrors(\n error.path!,\n validateAllFieldCriteria,\n previous,\n error.type!,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message\n ) as FieldError;\n }\n\n return previous;\n },\n {}\n );\n};\nfunction isPlainObject(obj) {\n return (\n typeof obj === 'object' &&\n obj !== null &&\n Object.prototype.toString.call(obj) === '[object Object]'\n );\n}\nfunction flattenObject(obj, prefix = '') {\n return Object.keys(obj).reduce((acc, key) => {\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n\n if (isPlainObject(obj[key])) {\n Object.assign(acc, flattenObject(obj[key], prefixedKey));\n } else {\n acc[prefixedKey] = obj[key];\n }\n\n return acc;\n }, {});\n}\n\nexport const yupResolver =\n (schema: any, schemaOptions: any = {}, resolverOptions: any = {}) =>\n async (values, context, options) => {\n try {\n if (schemaOptions.context && process.env.NODE_ENV === 'development') {\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\"\n );\n }\n\n const result = await schema[\n resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'\n ](\n flattenObject(values),\n Object.assign({ abortEarly: false }, schemaOptions, { context })\n );\n\n if (options.shouldUseNativeValidation)\n validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.rawValues ? values : result,\n errors: {},\n };\n } catch (e) {\n if (!e.inner) {\n throw e;\n }\n\n return {\n values: {},\n errors: parseErrorSchema(\n e,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all'\n ),\n options,\n };\n }\n };\n"],
5
+ "mappings": "AAAA,SAAS,8BAA8B;AACvC,SAAS,oBAAgC;AAOzC,MAAM,mBAAmB,CACvB,OACA,6BACG;AACH,UAAQ,MAAM,SAAS,CAAC,GAAG;AAAA,IACzB,CAAC,UAAUA,WAAU;AACnB,MAAAA,OAAM,OAAOA,OAAM,MAAM,QAAQ,iBAAiB,KAAK;AAEvD,UAAI,CAAC,SAASA,OAAM,IAAK,GAAG;AAC1B,iBAASA,OAAM,IAAK,IAAI,EAAE,SAASA,OAAM,SAAS,MAAMA,OAAM,KAAM;AAAA,MACtE;AAEA,UAAI,0BAA0B;AAC5B,cAAM,QAAQ,SAASA,OAAM,IAAK,EAAE;AACpC,cAAM,WAAW,SAAS,MAAMA,OAAM,IAAK;AAE3C,iBAASA,OAAM,IAAK,IAAI;AAAA,UACtBA,OAAM;AAAA,UACN;AAAA,UACA;AAAA,UACAA,OAAM;AAAA,UACN,WACK,CAAC,EAAe,OAAO,UAAsBA,OAAM,OAAO,IAC3DA,OAAM;AAAA,QACZ;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;AACA,SAAS,cAAc,KAAK;AAC1B,SACE,OAAO,QAAQ,YACf,QAAQ,QACR,OAAO,UAAU,SAAS,KAAK,GAAG,MAAM;AAE5C;AACA,SAAS,cAAc,KAAK,SAAS,IAAI;AACvC,SAAO,OAAO,KAAK,GAAG,EAAE,OAAO,CAAC,KAAK,QAAQ;AAC3C,UAAM,cAAc,SAAS,GAAG,MAAM,IAAI,GAAG,KAAK;AAElD,QAAI,cAAc,IAAI,GAAG,CAAC,GAAG;AAC3B,aAAO,OAAO,KAAK,cAAc,IAAI,GAAG,GAAG,WAAW,CAAC;AAAA,IACzD,OAAO;AACL,UAAI,WAAW,IAAI,IAAI,GAAG;AAAA,IAC5B;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAEO,MAAM,cACX,CAAC,QAAa,gBAAqB,CAAC,GAAG,kBAAuB,CAAC,MAC/D,OAAO,QAAQ,SAAS,YAAY;AAClC,MAAI;AACF,QAAI,cAAc,WAAW,QAAQ,IAAI,aAAa,eAAe;AACnE,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,OACnB,gBAAgB,SAAS,SAAS,iBAAiB,UACrD;AAAA,MACE,cAAc,MAAM;AAAA,MACpB,OAAO,OAAO,EAAE,YAAY,MAAM,GAAG,eAAe,EAAE,QAAQ,CAAC;AAAA,IACjE;AAEA,QAAI,QAAQ;AACV,6BAAuB,CAAC,GAAG,OAAO;AAEpC,WAAO;AAAA,MACL,QAAQ,gBAAgB,YAAY,SAAS;AAAA,MAC7C,QAAQ,CAAC;AAAA,IACX;AAAA,EACF,SAAS,GAAG;AACV,QAAI,CAAC,EAAE,OAAO;AACZ,YAAM;AAAA,IACR;AAEA,WAAO;AAAA,MACL,QAAQ,CAAC;AAAA,MACT,QAAQ;AAAA,QACN;AAAA,QACA,CAAC,QAAQ,6BAA6B,QAAQ,iBAAiB;AAAA,MACjE;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": ["error"]
7
7
  }
@@ -3,7 +3,7 @@ import { AnyObjectSchema } from 'yup';
3
3
  import Lazy from 'yup/lib/Lazy';
4
4
  import { FieldSpec } from '@digigov/form/types';
5
5
  import { ValidatorSchema } from '@digigov/form/validators/types';
6
- export declare const getYUPTypeMap: () => Record<string, any>;
6
+ export declare const getYUPTypeMap: (validatorRegistry?: Record<string, any>) => Record<string, any>;
7
7
  export interface MutableRefObjectProps {
8
8
  }
9
9
  export declare function useValidationSchema(fields: FieldSpec[] | MutableRefObject<MutableRefObjectProps>, validatorRegistry?: Record<string, ValidatorSchema[]>): Lazy<any, unknown> | AnyObjectSchema | void;
@@ -3,6 +3,7 @@ import * as yup from "yup";
3
3
  import {
4
4
  getYupObjectShape,
5
5
  AFM_VALIDATOR,
6
+ AMKA_VALIDATOR,
6
7
  FILE_MAX_SIZE_VALIDATOR,
7
8
  IBAN_VALIDATOR,
8
9
  OTP_VALIDATOR,
@@ -14,15 +15,18 @@ import {
14
15
  IMAGE_DIMENSION_VALIDATOR,
15
16
  DATE_VALIDATOR,
16
17
  LATER_THAN_VALIDATOR,
17
- EARLIER_THAN_VALIDATOR
18
+ EARLIER_THAN_VALIDATOR,
19
+ DATETIME_VALIDATOR,
20
+ LATER_THAN_DATETIME_VALIDATOR,
21
+ EARLIER_THAN_DATETIME_VALIDATOR
18
22
  } from "@digigov/form/validators/utils";
19
23
  import { INT_VALIDATOR } from "@digigov/form/validators/utils/int";
20
24
  import { NUMBER_VALIDATOR } from "@digigov/form/validators/utils/number";
21
- const getYUPTypeMap = () => {
25
+ const getYUPTypeMap = (validatorRegistry) => {
22
26
  const yupTypeMap = {
23
27
  file: (field) => {
24
28
  return yup.mixed().transform((value) => {
25
- if (!value.length) {
29
+ if (!value || value.length === 0) {
26
30
  return null;
27
31
  }
28
32
  return value;
@@ -30,7 +34,7 @@ const getYUPTypeMap = () => {
30
34
  },
31
35
  string: (field) => {
32
36
  if (field.trim) {
33
- return yup.string().trim().required(field.required);
37
+ return yup.string().trim();
34
38
  } else {
35
39
  return yup.string();
36
40
  }
@@ -48,7 +52,10 @@ const getYUPTypeMap = () => {
48
52
  },
49
53
  array: (field) => {
50
54
  if (typeof field.extra.of === "object") {
51
- let arrayValidator = yup.array().of(yupTypeMap[field.extra.of.type](field.extra.of)).required(field.required);
55
+ if (field.required) {
56
+ field.extra.min = 1;
57
+ }
58
+ let arrayValidator = yup.array().nullable().of(yupTypeMap[field.extra.of.type](field.extra.of));
52
59
  if (field.extra.length)
53
60
  arrayValidator = arrayValidator.length(field.extra.length, {
54
61
  key: "form.error.array.length",
@@ -81,6 +88,7 @@ const getYUPTypeMap = () => {
81
88
  int: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) : void 0).test(NUMBER_VALIDATOR()).test(INT_VALIDATOR()),
82
89
  email: (field) => field.trim ? yup.string().trim().email("form.error.email") : yup.string().email("form.error.email"),
83
90
  afm: (field) => field.trim ? yup.string().trim().test(AFM_VALIDATOR) : yup.string().test(AFM_VALIDATOR),
91
+ amka: (field) => field.trim ? yup.string().trim().test(AMKA_VALIDATOR) : yup.string().test(AMKA_VALIDATOR),
84
92
  uuid4: (field) => field.trim ? yup.string().trim().test(UUID4_VALIDATOR) : yup.string().test(UUID4_VALIDATOR),
85
93
  iban: (field) => field.trim ? yup.string().trim().test(IBAN_VALIDATOR(field)) : yup.string().trim().test(IBAN_VALIDATOR(field)),
86
94
  otp: (field) => yup.string().trim().test(OTP_VALIDATOR(field)),
@@ -115,15 +123,25 @@ const getYUPTypeMap = () => {
115
123
  schema = schema.test(DATE_VALIDATOR);
116
124
  }
117
125
  return schema;
118
- }
126
+ },
127
+ datetime: (field) => {
128
+ if (field?.extra?.min) {
129
+ return yup.string().test(LATER_THAN_DATETIME_VALIDATOR(field));
130
+ }
131
+ if (field?.extra?.max) {
132
+ return yup.string().test(EARLIER_THAN_DATETIME_VALIDATOR(field));
133
+ }
134
+ return yup.string().test(DATETIME_VALIDATOR);
135
+ },
136
+ ...validatorRegistry
119
137
  };
120
138
  return yupTypeMap;
121
139
  };
122
140
  function useValidationSchema(fields, validatorRegistry) {
123
141
  return useMemo(() => {
124
- const yupTypeMap = getYUPTypeMap();
142
+ const yupTypeMap = getYUPTypeMap(validatorRegistry);
125
143
  return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
126
- }, []);
144
+ }, [fields, validatorRegistry]);
127
145
  }
128
146
  export {
129
147
  getYUPTypeMap,