@digigov/form 2.0.0-298cfc51 → 2.0.0-32ae417f

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 (682) hide show
  1. package/Field/ErrorGroup/index.js +48 -0
  2. package/{Form.stories → Field/ErrorGroup}/package.json +1 -1
  3. package/Field/ErrorGroup.d.ts +15 -0
  4. package/Field/ErrorGroup.js.map +7 -0
  5. package/Field/FieldBase/index.js +37 -25
  6. package/Field/FieldBase.js.map +2 -2
  7. package/Field/FieldBaseContainer/index.js +37 -17
  8. package/Field/FieldBaseContainer.d.ts +1 -1
  9. package/Field/FieldBaseContainer.js.map +2 -2
  10. package/Field/FieldConditional/index.js +4 -0
  11. package/Field/FieldConditional.js.map +2 -2
  12. package/Field/index.js +15 -4
  13. package/Field/index.js.map +2 -2
  14. package/Field/types.d.ts +20 -10
  15. package/Field/utils/index.js +9 -1
  16. package/Field/utils/index.js.map +2 -2
  17. package/Field/utils/useField/index.js +14 -1
  18. package/Field/utils/useField.js.map +2 -2
  19. package/FieldArray/FieldArray.stories.d.ts +1 -0
  20. package/FieldArray/FormDialog/index.js +397 -0
  21. package/{Questions/Questions.stories → FieldArray/FormDialog}/package.json +1 -1
  22. package/FieldArray/FormDialog.d.ts +66 -0
  23. package/FieldArray/FormDialog.js.map +7 -0
  24. package/FieldArray/__stories__/Default.d.ts +1 -1
  25. package/FieldArray/__stories__/WithExactLength.d.ts +1 -1
  26. package/FieldArray/__stories__/WithModal.d.ts +2 -0
  27. package/FieldArray/index.d.ts +6 -0
  28. package/FieldArray/index.js +84 -26
  29. package/FieldArray/index.js.map +2 -2
  30. package/FieldObject/index.d.ts +5 -0
  31. package/FieldObject/index.js +30 -15
  32. package/FieldObject/index.js.map +2 -2
  33. package/FormBuilder/FormBuilder.stories.d.ts +4 -0
  34. package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +3 -0
  35. package/FormBuilder/__stories__/Default.d.ts +1 -1
  36. package/FormBuilder/__stories__/ErrorGrouping.d.ts +3 -0
  37. package/FormBuilder/index.d.ts +1 -1
  38. package/FormBuilder/index.js +92 -9
  39. package/FormBuilder/index.js.map +2 -2
  40. package/FormBuilder/interaction.test.d.ts +1 -0
  41. package/FormContext/index.js +6 -2
  42. package/FormContext.d.ts +1 -0
  43. package/FormContext.js.map +2 -2
  44. package/MultiplicityField/MultiplicityField.stories.d.ts +2 -0
  45. package/MultiplicityField/__stories__/Default.d.ts +1 -1
  46. package/MultiplicityField/__stories__/PreviewDisplay.d.ts +1 -1
  47. package/MultiplicityField/__stories__/WithExactLength.d.ts +1 -1
  48. package/MultiplicityField/__stories__/WithMaxLength.d.ts +1 -1
  49. package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +1 -1
  50. package/MultiplicityField/__stories__/WithMinLength.d.ts +1 -1
  51. package/MultiplicityField/add-objects/index.js +6 -2
  52. package/MultiplicityField/add-objects.js.map +2 -2
  53. package/MultiplicityField/index.js +5 -1
  54. package/MultiplicityField/index.js.map +2 -2
  55. package/MultiplicityField/types.d.ts +2 -2
  56. package/Questions/Questions/index.js +5 -4
  57. package/Questions/Questions.js.map +2 -2
  58. package/Questions/Questions.stories.d.ts +2 -0
  59. package/Questions/Step/StepArrayReview.js.map +2 -2
  60. package/Questions/__stories__/Default.d.ts +1 -1
  61. package/cjs/Field/ErrorGroup/index.js +82 -0
  62. package/cjs/Field/ErrorGroup.js.map +7 -0
  63. package/cjs/Field/FieldBase/index.js +36 -24
  64. package/cjs/Field/FieldBase.js.map +2 -2
  65. package/cjs/Field/FieldBaseContainer/index.js +36 -16
  66. package/cjs/Field/FieldBaseContainer.js.map +3 -3
  67. package/cjs/Field/FieldConditional/index.js +4 -0
  68. package/cjs/Field/FieldConditional.js.map +2 -2
  69. package/cjs/Field/index.js +15 -4
  70. package/cjs/Field/index.js.map +2 -2
  71. package/cjs/Field/types.js.map +1 -1
  72. package/cjs/Field/utils/index.js +9 -1
  73. package/cjs/Field/utils/index.js.map +3 -3
  74. package/cjs/Field/utils/useField/index.js +14 -1
  75. package/cjs/Field/utils/useField.js.map +2 -2
  76. package/cjs/FieldArray/FormDialog/index.js +416 -0
  77. package/cjs/FieldArray/FormDialog.js.map +7 -0
  78. package/cjs/FieldArray/index.js +82 -24
  79. package/cjs/FieldArray/index.js.map +3 -3
  80. package/cjs/FieldObject/index.js +30 -15
  81. package/cjs/FieldObject/index.js.map +2 -2
  82. package/cjs/FormBuilder/index.js +92 -9
  83. package/cjs/FormBuilder/index.js.map +2 -2
  84. package/cjs/FormContext/index.js +9 -4
  85. package/cjs/FormContext.js.map +3 -3
  86. package/cjs/MultiplicityField/add-objects/index.js +6 -2
  87. package/cjs/MultiplicityField/add-objects.js.map +2 -2
  88. package/cjs/MultiplicityField/index.js +5 -1
  89. package/cjs/MultiplicityField/index.js.map +2 -2
  90. package/cjs/MultiplicityField/types.js.map +1 -1
  91. package/cjs/Questions/Questions/index.js +5 -4
  92. package/cjs/Questions/Questions.js.map +2 -2
  93. package/cjs/Questions/Step/StepArrayReview.js.map +2 -2
  94. package/cjs/inputs/AutoCompleteInput/index.js +4 -3
  95. package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
  96. package/cjs/inputs/Checkboxes/index.js +3 -1
  97. package/cjs/inputs/Checkboxes/index.js.map +2 -2
  98. package/cjs/inputs/DateInput/index.js +48 -18
  99. package/cjs/inputs/DateInput/index.js.map +2 -2
  100. package/cjs/inputs/DateTimeInput/index.js +245 -0
  101. package/cjs/inputs/DateTimeInput/index.js.map +7 -0
  102. package/cjs/inputs/FileInput/index.js +68 -30
  103. package/cjs/inputs/FileInput/index.js.map +2 -2
  104. package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  105. package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  106. package/cjs/inputs/ImageInput/index.js +48 -11
  107. package/cjs/inputs/ImageInput/index.js.map +2 -2
  108. package/cjs/inputs/Input/index.js +10 -2
  109. package/cjs/inputs/Input/index.js.map +2 -2
  110. package/cjs/inputs/Label/index.js.map +2 -2
  111. package/cjs/inputs/OtpInput/index.js +1 -0
  112. package/cjs/inputs/OtpInput/index.js.map +2 -2
  113. package/cjs/inputs/Radio/index.js +1 -0
  114. package/cjs/inputs/Radio/index.js.map +2 -2
  115. package/cjs/inputs/Select/index.js +9 -2
  116. package/cjs/inputs/Select/index.js.map +2 -2
  117. package/cjs/inputs/inputsScenarios/index.js +6 -12
  118. package/cjs/inputs/inputsScenarios.js.map +2 -2
  119. package/cjs/{lazy/index.js → lazy.js} +48 -37
  120. package/cjs/lazy.js.map +3 -3
  121. package/cjs/locales/el.js.map +1 -1
  122. package/cjs/{registry/index.js → registry.js} +68 -60
  123. package/cjs/registry.js.map +3 -3
  124. package/cjs/types.js.map +1 -1
  125. package/cjs/utils/index.js +22 -7
  126. package/cjs/utils.js.map +2 -2
  127. package/cjs/validators/index.js +39 -19
  128. package/cjs/validators/index.js.map +2 -2
  129. package/cjs/validators/utils/amka/index.js +60 -0
  130. package/cjs/validators/utils/amka.js.map +7 -0
  131. package/cjs/validators/utils/date/index.js +27 -4
  132. package/cjs/validators/utils/date.js.map +2 -2
  133. package/cjs/validators/utils/datetime/index.js +245 -0
  134. package/cjs/validators/utils/datetime.js.map +7 -0
  135. package/cjs/validators/utils/file/index.js +30 -17
  136. package/cjs/validators/utils/file.js.map +2 -2
  137. package/cjs/validators/utils/index.js +8 -2
  138. package/cjs/validators/utils/index.js.map +2 -2
  139. package/cjs/validators/utils/int/index.js +1 -1
  140. package/cjs/validators/utils/int.js.map +2 -2
  141. package/cjs/validators/utils/number/index.js +1 -1
  142. package/cjs/validators/utils/number.js.map +2 -2
  143. package/cjs/validators/utils/phone.js.map +2 -2
  144. package/cjs/validators/utils/postal_code.js.map +1 -1
  145. package/cjs/validators/utils/uuid4.js.map +2 -2
  146. package/index.js +1 -1
  147. package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +2 -0
  148. package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -1
  149. package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +1 -1
  150. package/inputs/AutoCompleteInput/index.d.ts +1 -1
  151. package/inputs/AutoCompleteInput/index.js +4 -3
  152. package/inputs/AutoCompleteInput/index.js.map +2 -2
  153. package/inputs/Checkboxes/Checkboxes.stories.d.ts +2 -0
  154. package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -1
  155. package/inputs/Checkboxes/__stories__/Default.d.ts +1 -1
  156. package/inputs/Checkboxes/__stories__/WithDivider.d.ts +1 -1
  157. package/inputs/Checkboxes/index.d.ts +1 -1
  158. package/inputs/Checkboxes/index.js +3 -1
  159. package/inputs/Checkboxes/index.js.map +2 -2
  160. package/inputs/DateInput/DateInput.stories.d.ts +6 -0
  161. package/inputs/DateInput/__stories__/Default.d.ts +1 -1
  162. package/inputs/DateInput/__stories__/WithDefaultValue.d.ts +3 -0
  163. package/inputs/DateInput/__stories__/WithInitialValue.d.ts +3 -0
  164. package/inputs/DateInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
  165. package/inputs/DateInput/__stories__/WithWrongInitialValue.d.ts +3 -0
  166. package/inputs/DateInput/index.d.ts +1 -2
  167. package/inputs/DateInput/index.js +49 -19
  168. package/inputs/DateInput/index.js.map +2 -2
  169. package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +14 -0
  170. package/inputs/DateTimeInput/__stories__/Default.d.ts +3 -0
  171. package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +3 -0
  172. package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +3 -0
  173. package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
  174. package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +3 -0
  175. package/inputs/DateTimeInput/index.d.ts +13 -0
  176. package/inputs/DateTimeInput/index.js +215 -0
  177. package/inputs/DateTimeInput/index.js.map +7 -0
  178. package/inputs/DateTimeInput/index.test.d.ts +1 -0
  179. package/inputs/{Input/Input.stories → DateTimeInput}/package.json +1 -1
  180. package/inputs/FileInput/FileInput.stories.d.ts +3 -0
  181. package/inputs/FileInput/__stories__/Default.d.ts +1 -1
  182. package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
  183. package/inputs/FileInput/index.d.ts +17 -1
  184. package/inputs/FileInput/index.js +73 -32
  185. package/inputs/FileInput/index.js.map +2 -2
  186. package/inputs/ImageInput/ImageInput.stories.d.ts +4 -1
  187. package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
  188. package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
  189. package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
  190. package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
  191. package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  192. package/inputs/{DateInput/__stories__/Default → ImageInput/__stories__/logo.d}/package.json +1 -1
  193. package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  194. package/inputs/ImageInput/index.d.ts +9 -1
  195. package/inputs/ImageInput/index.js +49 -12
  196. package/inputs/ImageInput/index.js.map +2 -2
  197. package/inputs/Input/Input.stories.d.ts +5 -0
  198. package/inputs/Input/__stories__/AFM.d.ts +1 -1
  199. package/inputs/Input/__stories__/AMKA.d.ts +3 -0
  200. package/inputs/Input/__stories__/Boolean.d.ts +1 -1
  201. package/inputs/Input/__stories__/Email.d.ts +3 -0
  202. package/inputs/Input/__stories__/IBAN.d.ts +1 -1
  203. package/inputs/Input/__stories__/Integer.d.ts +1 -1
  204. package/inputs/Input/__stories__/LandlineNumber.d.ts +1 -1
  205. package/inputs/Input/__stories__/MobilePhone.d.ts +1 -1
  206. package/inputs/Input/__stories__/PhoneNumber.d.ts +1 -1
  207. package/inputs/Input/__stories__/PostalCode.d.ts +1 -1
  208. package/inputs/Input/__stories__/String.d.ts +1 -1
  209. package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +3 -0
  210. package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
  211. package/inputs/Input/index.d.ts +2 -1
  212. package/inputs/Input/index.js +10 -2
  213. package/inputs/Input/index.js.map +2 -2
  214. package/inputs/Label/Label.stories.d.ts +2 -0
  215. package/inputs/Label/__stories__/Default.d.ts +1 -1
  216. package/inputs/Label/index.d.ts +0 -2
  217. package/inputs/Label/index.js.map +2 -2
  218. package/inputs/OtpInput/OtpInput.stories.d.ts +2 -0
  219. package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
  220. package/inputs/OtpInput/index.js +1 -0
  221. package/inputs/OtpInput/index.js.map +2 -2
  222. package/inputs/Radio/Radio.stories.d.ts +2 -0
  223. package/inputs/Radio/__stories__/Conditional.d.ts +1 -1
  224. package/inputs/Radio/__stories__/Default.d.ts +1 -1
  225. package/inputs/Radio/__stories__/WithDivider.d.ts +1 -1
  226. package/inputs/Radio/index.d.ts +1 -1
  227. package/inputs/Radio/index.js +1 -0
  228. package/inputs/Radio/index.js.map +2 -2
  229. package/inputs/Select/Select.stories.d.ts +2 -0
  230. package/inputs/Select/__stories__/Default.d.ts +1 -1
  231. package/inputs/Select/index.d.ts +3 -2
  232. package/inputs/Select/index.js +13 -3
  233. package/inputs/Select/index.js.map +2 -2
  234. package/inputs/inputsScenarios/index.js +6 -12
  235. package/inputs/inputsScenarios.d.ts +1 -1
  236. package/inputs/inputsScenarios.js.map +2 -2
  237. package/lazy/index.js +77 -70
  238. package/locales/el.js.map +1 -1
  239. package/package.json +8 -8
  240. package/registry/index.js +114 -107
  241. package/src/Field/ErrorGroup.tsx +84 -0
  242. package/src/Field/FieldBase.tsx +39 -24
  243. package/src/Field/FieldBaseContainer.tsx +69 -46
  244. package/src/Field/FieldConditional.tsx +6 -2
  245. package/src/Field/doc.mdx +202 -1
  246. package/src/Field/index.tsx +20 -5
  247. package/src/Field/types.tsx +41 -29
  248. package/src/Field/utils/index.ts +8 -0
  249. package/src/Field/utils/useField.ts +14 -2
  250. package/src/FieldArray/FieldArray.stories.js +1 -0
  251. package/src/FieldArray/FormDialog.tsx +565 -0
  252. package/src/FieldArray/__stories__/Default.tsx +2 -1
  253. package/src/FieldArray/__stories__/WithExactLength.tsx +2 -1
  254. package/src/FieldArray/__stories__/WithModal.tsx +160 -0
  255. package/src/FieldArray/index.test.tsx +8 -0
  256. package/src/FieldArray/index.tsx +114 -50
  257. package/src/FieldObject/index.tsx +39 -18
  258. package/src/FormBuilder/FormBuilder.stories.js +5 -0
  259. package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +63 -0
  260. package/src/FormBuilder/__stories__/Default.tsx +1 -1
  261. package/src/FormBuilder/__stories__/ErrorGrouping.tsx +43 -0
  262. package/src/FormBuilder/doc.mdx +9 -4
  263. package/src/FormBuilder/index.test.tsx +12 -0
  264. package/src/FormBuilder/index.tsx +102 -12
  265. package/src/FormBuilder/interaction.test.tsx +40 -0
  266. package/src/FormBuilder/scenarios.test.tsx +1002 -130
  267. package/src/FormContext.tsx +5 -2
  268. package/src/MultiplicityField/MultiplicityField.stories.js +3 -0
  269. package/src/MultiplicityField/__stories__/Default.tsx +1 -1
  270. package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +1 -1
  271. package/src/MultiplicityField/__stories__/WithExactLength.tsx +1 -1
  272. package/src/MultiplicityField/__stories__/WithMaxLength.tsx +1 -1
  273. package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +1 -1
  274. package/src/MultiplicityField/__stories__/WithMinLength.tsx +1 -1
  275. package/src/MultiplicityField/add-objects.tsx +6 -3
  276. package/src/MultiplicityField/doc.mdx +101 -83
  277. package/src/MultiplicityField/index.test.tsx +4 -0
  278. package/src/MultiplicityField/index.tsx +4 -0
  279. package/src/MultiplicityField/types.ts +2 -2
  280. package/src/Questions/Questions.stories.js +3 -0
  281. package/src/Questions/Questions.tsx +4 -4
  282. package/src/Questions/Step/StepArrayReview.tsx +1 -1
  283. package/src/Questions/__snapshots__/index.spec.tsx.snap +3 -1
  284. package/src/Questions/__stories__/Default.tsx +1 -1
  285. package/src/Questions/doc.mdx +21 -41
  286. package/src/Questions/index.spec.tsx +14 -2
  287. package/src/Questions/index.test.tsx +4 -0
  288. package/src/doc.mdx +26 -11
  289. package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +3 -0
  290. package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +3 -11
  291. package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +2 -8
  292. package/src/inputs/AutoCompleteInput/index.test.tsx +4 -0
  293. package/src/inputs/AutoCompleteInput/index.tsx +4 -5
  294. package/src/inputs/Checkboxes/Checkboxes.stories.js +3 -0
  295. package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
  296. package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
  297. package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
  298. package/src/inputs/Checkboxes/index.test.tsx +4 -0
  299. package/src/inputs/Checkboxes/index.tsx +4 -6
  300. package/src/inputs/DateInput/DateInput.stories.js +7 -0
  301. package/src/inputs/DateInput/__stories__/Default.tsx +8 -13
  302. package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +26 -0
  303. package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +28 -0
  304. package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +26 -0
  305. package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +28 -0
  306. package/src/inputs/DateInput/index.test.tsx +20 -0
  307. package/src/inputs/DateInput/index.tsx +53 -18
  308. package/src/inputs/DateTimeInput/DateTimeInput.stories.js +14 -0
  309. package/src/inputs/DateTimeInput/__stories__/Default.tsx +25 -0
  310. package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +26 -0
  311. package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +28 -0
  312. package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +26 -0
  313. package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +28 -0
  314. package/src/inputs/DateTimeInput/doc.mdx +16 -0
  315. package/src/inputs/DateTimeInput/index.test.tsx +40 -0
  316. package/src/inputs/DateTimeInput/index.tsx +233 -0
  317. package/src/inputs/FileInput/FileInput.stories.js +4 -0
  318. package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
  319. package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
  320. package/src/inputs/FileInput/index.test.tsx +8 -0
  321. package/src/inputs/FileInput/index.tsx +104 -38
  322. package/src/inputs/ImageInput/ImageInput.stories.js +5 -2
  323. package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
  324. package/src/inputs/ImageInput/__stories__/MaxSize.tsx +5 -4
  325. package/src/inputs/ImageInput/__stories__/{WithInvalidImageSize.tsx → WithInitialValues.tsx} +12 -3
  326. package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +1 -1
  327. package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
  328. package/src/inputs/ImageInput/__stories__/logo.png +0 -0
  329. package/src/inputs/ImageInput/index.test.tsx +8 -4
  330. package/src/inputs/ImageInput/index.tsx +97 -42
  331. package/src/inputs/Input/Input.stories.js +6 -0
  332. package/src/inputs/Input/__stories__/AFM.tsx +1 -1
  333. package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
  334. package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
  335. package/src/inputs/Input/__stories__/Email.tsx +23 -0
  336. package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
  337. package/src/inputs/Input/__stories__/Integer.tsx +1 -1
  338. package/src/inputs/Input/__stories__/LandlineNumber.tsx +2 -2
  339. package/src/inputs/Input/__stories__/MobilePhone.tsx +2 -2
  340. package/src/inputs/Input/__stories__/PhoneNumber.tsx +2 -2
  341. package/src/inputs/Input/__stories__/PostalCode.tsx +2 -2
  342. package/src/inputs/Input/__stories__/String.tsx +1 -1
  343. package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +26 -0
  344. package/src/inputs/Input/__stories__/TextWithLimit.tsx +2 -1
  345. package/src/inputs/Input/index.test.tsx +16 -0
  346. package/src/inputs/Input/index.tsx +13 -3
  347. package/src/inputs/Label/Label.stories.js +3 -0
  348. package/src/inputs/Label/__stories__/Default.tsx +1 -1
  349. package/src/inputs/Label/index.test.tsx +4 -0
  350. package/src/inputs/Label/index.tsx +0 -3
  351. package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
  352. package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
  353. package/src/inputs/OtpInput/index.test.tsx +4 -0
  354. package/src/inputs/OtpInput/index.tsx +3 -1
  355. package/src/inputs/Radio/Radio.stories.js +3 -0
  356. package/src/inputs/Radio/__stories__/Conditional.tsx +1 -1
  357. package/src/inputs/Radio/__stories__/Default.tsx +1 -1
  358. package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
  359. package/src/inputs/Radio/index.test.tsx +4 -0
  360. package/src/inputs/Radio/index.tsx +2 -1
  361. package/src/inputs/Select/Select.stories.js +3 -0
  362. package/src/inputs/Select/__stories__/Default.tsx +1 -1
  363. package/src/inputs/Select/index.test.tsx +4 -0
  364. package/src/inputs/Select/index.tsx +18 -6
  365. package/src/inputs/inputsScenarios.ts +36 -42
  366. package/src/lazy.js +77 -67
  367. package/src/locales/el.ts +1 -1
  368. package/src/registry.js +106 -100
  369. package/src/types.tsx +4 -3
  370. package/src/utils.ts +29 -8
  371. package/src/validators/index.ts +70 -20
  372. package/src/validators/utils/amka.ts +39 -0
  373. package/src/validators/utils/date.ts +29 -5
  374. package/src/validators/utils/datetime.ts +228 -0
  375. package/src/validators/utils/file.ts +33 -17
  376. package/src/validators/utils/index.ts +5 -1
  377. package/src/validators/utils/int.ts +1 -1
  378. package/src/validators/utils/number.ts +1 -1
  379. package/src/validators/utils/phone.ts +1 -1
  380. package/src/validators/utils/postal_code.ts +1 -1
  381. package/src/validators/utils/uuid4.ts +2 -1
  382. package/src/validators/validators.spec.ts +3 -3
  383. package/types.d.ts +4 -3
  384. package/types.js.map +1 -1
  385. package/utils/index.js +22 -7
  386. package/utils.d.ts +2 -0
  387. package/utils.js.map +2 -2
  388. package/validators/index.d.ts +1 -1
  389. package/validators/index.js +44 -20
  390. package/validators/index.js.map +2 -2
  391. package/validators/utils/amka/index.js +36 -0
  392. package/{FieldArray/FieldArray.stories → validators/utils/amka}/package.json +1 -1
  393. package/validators/utils/amka.d.ts +6 -0
  394. package/validators/utils/amka.js.map +7 -0
  395. package/validators/utils/date/index.js +27 -4
  396. package/validators/utils/date.d.ts +1 -1
  397. package/validators/utils/date.js.map +2 -2
  398. package/validators/utils/datetime/index.js +210 -0
  399. package/validators/utils/datetime/package.json +6 -0
  400. package/validators/utils/datetime.d.ts +9 -0
  401. package/validators/utils/datetime.js.map +7 -0
  402. package/validators/utils/file/index.js +30 -17
  403. package/validators/utils/file.js.map +2 -2
  404. package/validators/utils/index.d.ts +2 -0
  405. package/validators/utils/index.js +5 -1
  406. package/validators/utils/index.js.map +2 -2
  407. package/validators/utils/int/index.js +1 -1
  408. package/validators/utils/int.js.map +2 -2
  409. package/validators/utils/number/index.js +1 -1
  410. package/validators/utils/number.js.map +2 -2
  411. package/validators/utils/phone.d.ts +1 -1
  412. package/validators/utils/phone.js.map +2 -2
  413. package/validators/utils/postal_code.d.ts +1 -1
  414. package/validators/utils/postal_code.js.map +1 -1
  415. package/validators/utils/uuid4.js.map +2 -2
  416. package/FieldArray/FieldArray.stories/index.js +0 -14
  417. package/FieldArray/FieldArray.stories.js.map +0 -7
  418. package/FieldArray/__stories__/Default/index.js +0 -95
  419. package/FieldArray/__stories__/Default/package.json +0 -6
  420. package/FieldArray/__stories__/Default.js.map +0 -7
  421. package/FieldArray/__stories__/WithExactLength/index.js +0 -95
  422. package/FieldArray/__stories__/WithExactLength/package.json +0 -6
  423. package/FieldArray/__stories__/WithExactLength.js.map +0 -7
  424. package/Form.stories/index.js +0 -7
  425. package/Form.stories.js.map +0 -7
  426. package/FormBuilder/FormBuilder.stories/index.js +0 -12
  427. package/FormBuilder/FormBuilder.stories/package.json +0 -6
  428. package/FormBuilder/FormBuilder.stories.js.map +0 -7
  429. package/FormBuilder/__stories__/Default/index.js +0 -32
  430. package/FormBuilder/__stories__/Default/package.json +0 -6
  431. package/FormBuilder/__stories__/Default.js.map +0 -7
  432. package/MultiplicityField/MultiplicityField.stories/index.js +0 -22
  433. package/MultiplicityField/MultiplicityField.stories/package.json +0 -6
  434. package/MultiplicityField/MultiplicityField.stories.js.map +0 -7
  435. package/MultiplicityField/__stories__/Default/index.js +0 -100
  436. package/MultiplicityField/__stories__/Default/package.json +0 -6
  437. package/MultiplicityField/__stories__/Default.js.map +0 -7
  438. package/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -70
  439. package/MultiplicityField/__stories__/PreviewDisplay/package.json +0 -6
  440. package/MultiplicityField/__stories__/PreviewDisplay.js.map +0 -7
  441. package/MultiplicityField/__stories__/WithExactLength/index.js +0 -97
  442. package/MultiplicityField/__stories__/WithExactLength/package.json +0 -6
  443. package/MultiplicityField/__stories__/WithExactLength.js.map +0 -7
  444. package/MultiplicityField/__stories__/WithMaxLength/index.js +0 -100
  445. package/MultiplicityField/__stories__/WithMaxLength/package.json +0 -6
  446. package/MultiplicityField/__stories__/WithMaxLength.js.map +0 -7
  447. package/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -101
  448. package/MultiplicityField/__stories__/WithMinAndMaxLength/package.json +0 -6
  449. package/MultiplicityField/__stories__/WithMinAndMaxLength.js.map +0 -7
  450. package/MultiplicityField/__stories__/WithMinLength/index.js +0 -100
  451. package/MultiplicityField/__stories__/WithMinLength/package.json +0 -6
  452. package/MultiplicityField/__stories__/WithMinLength.js.map +0 -7
  453. package/Questions/Questions.stories/index.js +0 -12
  454. package/Questions/Questions.stories.js.map +0 -7
  455. package/Questions/__stories__/Default/index.js +0 -108
  456. package/Questions/__stories__/Default/package.json +0 -6
  457. package/Questions/__stories__/Default.js.map +0 -7
  458. package/cjs/FieldArray/FieldArray.stories/index.js +0 -48
  459. package/cjs/FieldArray/FieldArray.stories.js.map +0 -7
  460. package/cjs/FieldArray/__stories__/Default/index.js +0 -128
  461. package/cjs/FieldArray/__stories__/Default.js.map +0 -7
  462. package/cjs/FieldArray/__stories__/WithExactLength/index.js +0 -128
  463. package/cjs/FieldArray/__stories__/WithExactLength.js.map +0 -7
  464. package/cjs/Form.stories/index.js +0 -26
  465. package/cjs/Form.stories.js.map +0 -7
  466. package/cjs/FormBuilder/FormBuilder.stories/index.js +0 -45
  467. package/cjs/FormBuilder/FormBuilder.stories.js.map +0 -7
  468. package/cjs/FormBuilder/__stories__/Default/index.js +0 -65
  469. package/cjs/FormBuilder/__stories__/Default.js.map +0 -7
  470. package/cjs/MultiplicityField/MultiplicityField.stories/index.js +0 -60
  471. package/cjs/MultiplicityField/MultiplicityField.stories.js.map +0 -7
  472. package/cjs/MultiplicityField/__stories__/Default/index.js +0 -133
  473. package/cjs/MultiplicityField/__stories__/Default.js.map +0 -7
  474. package/cjs/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -86
  475. package/cjs/MultiplicityField/__stories__/PreviewDisplay.js.map +0 -7
  476. package/cjs/MultiplicityField/__stories__/WithExactLength/index.js +0 -130
  477. package/cjs/MultiplicityField/__stories__/WithExactLength.js.map +0 -7
  478. package/cjs/MultiplicityField/__stories__/WithMaxLength/index.js +0 -133
  479. package/cjs/MultiplicityField/__stories__/WithMaxLength.js.map +0 -7
  480. package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -134
  481. package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength.js.map +0 -7
  482. package/cjs/MultiplicityField/__stories__/WithMinLength/index.js +0 -133
  483. package/cjs/MultiplicityField/__stories__/WithMinLength.js.map +0 -7
  484. package/cjs/Questions/Questions.stories/index.js +0 -45
  485. package/cjs/Questions/Questions.stories.js.map +0 -7
  486. package/cjs/Questions/__stories__/Default/index.js +0 -136
  487. package/cjs/Questions/__stories__/Default.js.map +0 -7
  488. package/cjs/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -48
  489. package/cjs/inputs/AutoCompleteInput/AutoComplete.stories.js.map +0 -7
  490. package/cjs/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -83
  491. package/cjs/inputs/AutoCompleteInput/__stories__/Default.js.map +0 -7
  492. package/cjs/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -83
  493. package/cjs/inputs/AutoCompleteInput/__stories__/Multiple.js.map +0 -7
  494. package/cjs/inputs/Checkboxes/Checkboxes.stories/index.js +0 -51
  495. package/cjs/inputs/Checkboxes/Checkboxes.stories.js.map +0 -7
  496. package/cjs/inputs/Checkboxes/__stories__/Conditional/index.js +0 -133
  497. package/cjs/inputs/Checkboxes/__stories__/Conditional.js.map +0 -7
  498. package/cjs/inputs/Checkboxes/__stories__/Default/index.js +0 -77
  499. package/cjs/inputs/Checkboxes/__stories__/Default.js.map +0 -7
  500. package/cjs/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -78
  501. package/cjs/inputs/Checkboxes/__stories__/WithDivider.js.map +0 -7
  502. package/cjs/inputs/DateInput/DateInput.stories/index.js +0 -45
  503. package/cjs/inputs/DateInput/DateInput.stories.js.map +0 -7
  504. package/cjs/inputs/DateInput/__stories__/Default/index.js +0 -61
  505. package/cjs/inputs/DateInput/__stories__/Default.js.map +0 -7
  506. package/cjs/inputs/FileInput/FileInput.stories/index.js +0 -45
  507. package/cjs/inputs/FileInput/FileInput.stories.js.map +0 -7
  508. package/cjs/inputs/FileInput/__stories__/Default/index.js +0 -61
  509. package/cjs/inputs/FileInput/__stories__/Default.js.map +0 -7
  510. package/cjs/inputs/ImageInput/ImageInput.stories/index.js +0 -51
  511. package/cjs/inputs/ImageInput/ImageInput.stories.js.map +0 -7
  512. package/cjs/inputs/ImageInput/__stories__/Default/index.js +0 -63
  513. package/cjs/inputs/ImageInput/__stories__/Default.js.map +0 -7
  514. package/cjs/inputs/ImageInput/__stories__/MaxSize/index.js +0 -69
  515. package/cjs/inputs/ImageInput/__stories__/MaxSize.js.map +0 -7
  516. package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -72
  517. package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +0 -7
  518. package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -68
  519. package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize.js.map +0 -7
  520. package/cjs/inputs/Input/Input.stories/index.js +0 -72
  521. package/cjs/inputs/Input/Input.stories.js.map +0 -7
  522. package/cjs/inputs/Input/__stories__/AFM/index.js +0 -63
  523. package/cjs/inputs/Input/__stories__/AFM.js.map +0 -7
  524. package/cjs/inputs/Input/__stories__/Boolean/index.js +0 -64
  525. package/cjs/inputs/Input/__stories__/Boolean.js.map +0 -7
  526. package/cjs/inputs/Input/__stories__/IBAN/index.js +0 -64
  527. package/cjs/inputs/Input/__stories__/IBAN.js.map +0 -7
  528. package/cjs/inputs/Input/__stories__/Integer/index.js +0 -78
  529. package/cjs/inputs/Input/__stories__/Integer.js.map +0 -7
  530. package/cjs/inputs/Input/__stories__/LandlineNumber/index.js +0 -68
  531. package/cjs/inputs/Input/__stories__/LandlineNumber.js.map +0 -7
  532. package/cjs/inputs/Input/__stories__/MobilePhone/index.js +0 -68
  533. package/cjs/inputs/Input/__stories__/MobilePhone.js.map +0 -7
  534. package/cjs/inputs/Input/__stories__/PhoneNumber/index.js +0 -67
  535. package/cjs/inputs/Input/__stories__/PhoneNumber.js.map +0 -7
  536. package/cjs/inputs/Input/__stories__/PostalCode/index.js +0 -65
  537. package/cjs/inputs/Input/__stories__/PostalCode.js.map +0 -7
  538. package/cjs/inputs/Input/__stories__/String/index.js +0 -64
  539. package/cjs/inputs/Input/__stories__/String.js.map +0 -7
  540. package/cjs/inputs/Input/__stories__/TextWithLimit/index.js +0 -64
  541. package/cjs/inputs/Input/__stories__/TextWithLimit.js.map +0 -7
  542. package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
  543. package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
  544. package/cjs/inputs/Label/Label.stories/index.js +0 -45
  545. package/cjs/inputs/Label/Label.stories.js.map +0 -7
  546. package/cjs/inputs/Label/__stories__/Default/index.js +0 -72
  547. package/cjs/inputs/Label/__stories__/Default.js.map +0 -7
  548. package/cjs/inputs/OtpInput/OtpInput.stories/index.js +0 -45
  549. package/cjs/inputs/OtpInput/OtpInput.stories.js.map +0 -7
  550. package/cjs/inputs/OtpInput/__stories__/Default/index.js +0 -64
  551. package/cjs/inputs/OtpInput/__stories__/Default.js.map +0 -7
  552. package/cjs/inputs/Radio/Radio.stories/index.js +0 -51
  553. package/cjs/inputs/Radio/Radio.stories.js.map +0 -7
  554. package/cjs/inputs/Radio/__stories__/Conditional/index.js +0 -133
  555. package/cjs/inputs/Radio/__stories__/Conditional.js.map +0 -7
  556. package/cjs/inputs/Radio/__stories__/Default/index.js +0 -81
  557. package/cjs/inputs/Radio/__stories__/Default.js.map +0 -7
  558. package/cjs/inputs/Radio/__stories__/WithDivider/index.js +0 -82
  559. package/cjs/inputs/Radio/__stories__/WithDivider.js.map +0 -7
  560. package/cjs/inputs/Select/Select.stories/index.js +0 -45
  561. package/cjs/inputs/Select/Select.stories.js.map +0 -7
  562. package/cjs/inputs/Select/__stories__/Default/index.js +0 -86
  563. package/cjs/inputs/Select/__stories__/Default.js.map +0 -7
  564. package/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -14
  565. package/inputs/AutoCompleteInput/AutoComplete.stories/package.json +0 -6
  566. package/inputs/AutoCompleteInput/AutoComplete.stories.js.map +0 -7
  567. package/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -50
  568. package/inputs/AutoCompleteInput/__stories__/Default/package.json +0 -6
  569. package/inputs/AutoCompleteInput/__stories__/Default.js.map +0 -7
  570. package/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -50
  571. package/inputs/AutoCompleteInput/__stories__/Multiple/package.json +0 -6
  572. package/inputs/AutoCompleteInput/__stories__/Multiple.js.map +0 -7
  573. package/inputs/Checkboxes/Checkboxes.stories/index.js +0 -16
  574. package/inputs/Checkboxes/Checkboxes.stories/package.json +0 -6
  575. package/inputs/Checkboxes/Checkboxes.stories.js.map +0 -7
  576. package/inputs/Checkboxes/__stories__/Conditional/index.js +0 -100
  577. package/inputs/Checkboxes/__stories__/Conditional/package.json +0 -6
  578. package/inputs/Checkboxes/__stories__/Conditional.js.map +0 -7
  579. package/inputs/Checkboxes/__stories__/Default/index.js +0 -44
  580. package/inputs/Checkboxes/__stories__/Default/package.json +0 -6
  581. package/inputs/Checkboxes/__stories__/Default.js.map +0 -7
  582. package/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -45
  583. package/inputs/Checkboxes/__stories__/WithDivider/package.json +0 -6
  584. package/inputs/Checkboxes/__stories__/WithDivider.js.map +0 -7
  585. package/inputs/DateInput/DateInput.stories/index.js +0 -12
  586. package/inputs/DateInput/DateInput.stories/package.json +0 -6
  587. package/inputs/DateInput/DateInput.stories.js.map +0 -7
  588. package/inputs/DateInput/__stories__/Default/index.js +0 -28
  589. package/inputs/DateInput/__stories__/Default.js.map +0 -7
  590. package/inputs/FileInput/FileInput.stories/index.js +0 -12
  591. package/inputs/FileInput/FileInput.stories/package.json +0 -6
  592. package/inputs/FileInput/FileInput.stories.js.map +0 -7
  593. package/inputs/FileInput/__stories__/Default/index.js +0 -28
  594. package/inputs/FileInput/__stories__/Default/package.json +0 -6
  595. package/inputs/FileInput/__stories__/Default.js.map +0 -7
  596. package/inputs/ImageInput/ImageInput.stories/index.js +0 -16
  597. package/inputs/ImageInput/ImageInput.stories/package.json +0 -6
  598. package/inputs/ImageInput/ImageInput.stories.js.map +0 -7
  599. package/inputs/ImageInput/__stories__/Default/index.js +0 -30
  600. package/inputs/ImageInput/__stories__/Default/package.json +0 -6
  601. package/inputs/ImageInput/__stories__/Default.js.map +0 -7
  602. package/inputs/ImageInput/__stories__/MaxSize/index.js +0 -36
  603. package/inputs/ImageInput/__stories__/MaxSize/package.json +0 -6
  604. package/inputs/ImageInput/__stories__/MaxSize.js.map +0 -7
  605. package/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -39
  606. package/inputs/ImageInput/__stories__/WithInvalidImageDimension/package.json +0 -6
  607. package/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +0 -7
  608. package/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -35
  609. package/inputs/ImageInput/__stories__/WithInvalidImageSize/package.json +0 -6
  610. package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +0 -3
  611. package/inputs/ImageInput/__stories__/WithInvalidImageSize.js.map +0 -7
  612. package/inputs/Input/Input.stories/index.js +0 -30
  613. package/inputs/Input/Input.stories.js.map +0 -7
  614. package/inputs/Input/__stories__/AFM/index.js +0 -30
  615. package/inputs/Input/__stories__/AFM/package.json +0 -6
  616. package/inputs/Input/__stories__/AFM.js.map +0 -7
  617. package/inputs/Input/__stories__/Boolean/index.js +0 -31
  618. package/inputs/Input/__stories__/Boolean/package.json +0 -6
  619. package/inputs/Input/__stories__/Boolean.js.map +0 -7
  620. package/inputs/Input/__stories__/IBAN/index.js +0 -31
  621. package/inputs/Input/__stories__/IBAN/package.json +0 -6
  622. package/inputs/Input/__stories__/IBAN.js.map +0 -7
  623. package/inputs/Input/__stories__/Integer/index.js +0 -45
  624. package/inputs/Input/__stories__/Integer/package.json +0 -6
  625. package/inputs/Input/__stories__/Integer.js.map +0 -7
  626. package/inputs/Input/__stories__/LandlineNumber/index.js +0 -35
  627. package/inputs/Input/__stories__/LandlineNumber/package.json +0 -6
  628. package/inputs/Input/__stories__/LandlineNumber.js.map +0 -7
  629. package/inputs/Input/__stories__/MobilePhone/index.js +0 -35
  630. package/inputs/Input/__stories__/MobilePhone/package.json +0 -6
  631. package/inputs/Input/__stories__/MobilePhone.js.map +0 -7
  632. package/inputs/Input/__stories__/PhoneNumber/index.js +0 -34
  633. package/inputs/Input/__stories__/PhoneNumber/package.json +0 -6
  634. package/inputs/Input/__stories__/PhoneNumber.js.map +0 -7
  635. package/inputs/Input/__stories__/PostalCode/index.js +0 -32
  636. package/inputs/Input/__stories__/PostalCode/package.json +0 -6
  637. package/inputs/Input/__stories__/PostalCode.js.map +0 -7
  638. package/inputs/Input/__stories__/String/index.js +0 -31
  639. package/inputs/Input/__stories__/String/package.json +0 -6
  640. package/inputs/Input/__stories__/String.js.map +0 -7
  641. package/inputs/Input/__stories__/TextWithLimit/index.js +0 -31
  642. package/inputs/Input/__stories__/TextWithLimit/package.json +0 -6
  643. package/inputs/Input/__stories__/TextWithLimit.js.map +0 -7
  644. package/inputs/Input/inputsInputScenarios/index.js +0 -406
  645. package/inputs/Input/inputsInputScenarios/package.json +0 -6
  646. package/inputs/Input/inputsInputScenarios.d.ts +0 -57
  647. package/inputs/Input/inputsInputScenarios.js.map +0 -7
  648. package/inputs/Label/Label.stories/index.js +0 -12
  649. package/inputs/Label/Label.stories/package.json +0 -6
  650. package/inputs/Label/Label.stories.js.map +0 -7
  651. package/inputs/Label/__stories__/Default/index.js +0 -39
  652. package/inputs/Label/__stories__/Default/package.json +0 -6
  653. package/inputs/Label/__stories__/Default.js.map +0 -7
  654. package/inputs/OtpInput/OtpInput.stories/index.js +0 -12
  655. package/inputs/OtpInput/OtpInput.stories/package.json +0 -6
  656. package/inputs/OtpInput/OtpInput.stories.js.map +0 -7
  657. package/inputs/OtpInput/__stories__/Default/index.js +0 -31
  658. package/inputs/OtpInput/__stories__/Default/package.json +0 -6
  659. package/inputs/OtpInput/__stories__/Default.js.map +0 -7
  660. package/inputs/Radio/Radio.stories/index.js +0 -16
  661. package/inputs/Radio/Radio.stories/package.json +0 -6
  662. package/inputs/Radio/Radio.stories.js.map +0 -7
  663. package/inputs/Radio/__stories__/Conditional/index.js +0 -100
  664. package/inputs/Radio/__stories__/Conditional/package.json +0 -6
  665. package/inputs/Radio/__stories__/Conditional.js.map +0 -7
  666. package/inputs/Radio/__stories__/Default/index.js +0 -48
  667. package/inputs/Radio/__stories__/Default/package.json +0 -6
  668. package/inputs/Radio/__stories__/Default.js.map +0 -7
  669. package/inputs/Radio/__stories__/WithDivider/index.js +0 -49
  670. package/inputs/Radio/__stories__/WithDivider/package.json +0 -6
  671. package/inputs/Radio/__stories__/WithDivider.js.map +0 -7
  672. package/inputs/Select/Select.stories/index.js +0 -12
  673. package/inputs/Select/Select.stories/package.json +0 -6
  674. package/inputs/Select/Select.stories.js.map +0 -7
  675. package/inputs/Select/__stories__/Default/index.js +0 -53
  676. package/inputs/Select/__stories__/Default/package.json +0 -6
  677. package/inputs/Select/__stories__/Default.js.map +0 -7
  678. package/lazy.d.ts +0 -80
  679. package/lazy.js.map +0 -7
  680. package/registry.d.ts +0 -71
  681. package/registry.js.map +0 -7
  682. package/src/inputs/Input/inputsInputScenarios.ts +0 -405
@@ -0,0 +1,228 @@
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 (
100
+ hasDay &&
101
+ hasMonth &&
102
+ (!hasYear || year.length < 4) &&
103
+ hasHours &&
104
+ hasMinutes
105
+ ) {
106
+ return 'form.error.datetime.invalid_year';
107
+ }
108
+ if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
109
+ return 'form.error.datetime.invalid_month_minutes';
110
+ }
111
+ if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
112
+ return 'form.error.datetime.invalid_month_hours';
113
+ }
114
+ if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
115
+ return 'form.error.datetime.invalid_month';
116
+ }
117
+ if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
118
+ return 'form.error.datetime.invalid_day_minutes';
119
+ }
120
+ if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
121
+ return 'form.error.datetime.invalid_day_hours';
122
+ }
123
+ if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {
124
+ return 'form.error.datetime.invalid_day';
125
+ }
126
+ if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
127
+ return 'form.error.datetime.invalid_day_month_year_minutes';
128
+ }
129
+ if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
130
+ return 'form.error.datetime.invalid_hours_minutes';
131
+ }
132
+ if (day && month) {
133
+ const dayNum = parseInt(day);
134
+ const monthNum = parseInt(month);
135
+ const validYear = onlyNumbersRegex.test(year) ? year : undefined;
136
+ if (!validYear) {
137
+ return 'form.error.datetime.invalid';
138
+ }
139
+ const yearNum = parseInt(validYear);
140
+ const maxDay = getDaysInMonth(monthNum, yearNum);
141
+ if (dayNum < 1 || dayNum > maxDay) {
142
+ return {
143
+ key: 'form.error.datetime.invalid_day_range',
144
+ context: {
145
+ maxDay: maxDay,
146
+ },
147
+ };
148
+ }
149
+ if (monthNum < 1 || monthNum > 12) {
150
+ return 'form.error.datetime.invalid_month_range';
151
+ }
152
+ }
153
+ if (hours && minutes) {
154
+ const hoursNum = parseInt(hours);
155
+ const minutesNum = parseInt(minutes);
156
+ if (hoursNum < 0 || hoursNum > 23) {
157
+ return 'form.error.datetime.invalid_hours_range';
158
+ }
159
+ if (minutesNum < 0 || minutesNum > 59) {
160
+ return 'form.error.datetime.invalid_minutes_range';
161
+ }
162
+ }
163
+ return 'form.error.datetime.invalid';
164
+ };
165
+
166
+ export const LATER_THAN_DATETIME_VALIDATOR = (
167
+ field: FieldSpec
168
+ ): ValidatorSchema => {
169
+ let minDateTime;
170
+ const params = field.extra || {};
171
+ if (params.min === 'now') {
172
+ minDateTime = dayjs();
173
+ } else {
174
+ minDateTime = getDateTime(params.min);
175
+ }
176
+ return {
177
+ name: 'later-than-datetime',
178
+ message: {
179
+ key: 'form.error.datetime.later_than',
180
+ context: {
181
+ minDateTime: minDateTime.format('DD/MM/YYYY HH:mm'),
182
+ },
183
+ },
184
+ test: function (value: string) {
185
+ if (!value) return true;
186
+ const datetime = getDateTime(value);
187
+ return datetime.isValid() && datetime.isAfter(minDateTime);
188
+ },
189
+ };
190
+ };
191
+
192
+ export const EARLIER_THAN_DATETIME_VALIDATOR = (
193
+ field: FieldSpec
194
+ ): ValidatorSchema => {
195
+ let maxDateTime;
196
+ const params = field.extra || {};
197
+ if (params.max === 'now') {
198
+ maxDateTime = dayjs();
199
+ } else {
200
+ maxDateTime = getDateTime(params.max);
201
+ }
202
+ return {
203
+ name: 'earlier-than-datetime',
204
+ message: {
205
+ key: 'form.error.datetime.earlier_than',
206
+ context: {
207
+ maxDateTime: maxDateTime.format('DD/MM/YYYY HH:mm'),
208
+ },
209
+ },
210
+ test: function (value: string) {
211
+ if (!value) return true;
212
+ const datetime = getDateTime(value);
213
+ return datetime.isValid() && datetime.isBefore(maxDateTime);
214
+ },
215
+ };
216
+ };
217
+
218
+ export const DATETIME_VALIDATOR = {
219
+ name: 'datetime-validator',
220
+ message: (v): string | object => {
221
+ return checkPartialDateTime(v.value);
222
+ },
223
+ test: function (value: string) {
224
+ if (!value) return true;
225
+ const datetime = getDateTime(value);
226
+ return datetime.isValid();
227
+ },
228
+ };
@@ -3,23 +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: field.type === 'file' ? 'form.error.file_size' : 'form.error.image_size',
10
- context: {
11
- maxSizeToMb: (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
+ },
12
28
  },
13
- },
14
- test: (value: File[]): boolean => {
15
- if (value) {
16
- for (const file of value) {
17
- const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE
18
- if (file.size > maxSize) {
19
- 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
+ }
20
36
  }
21
37
  }
22
- }
23
- return true;
24
- },
25
- });
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
  );
@@ -13,7 +13,7 @@ export const INT_VALIDATOR = (): ValidatorSchema => {
13
13
  name: 'int-validator',
14
14
  message: 'form.error.positive_integer_number',
15
15
  test: (value: number): boolean => {
16
- if (value === null) {
16
+ if (value === undefined) {
17
17
  return true;
18
18
  }
19
19
  return validateIntNumber(value);
@@ -9,7 +9,7 @@ export const NUMBER_VALIDATOR = (): ValidatorSchema => {
9
9
  name: 'number-validator',
10
10
  message: 'form.error.number',
11
11
  test: (value: number): boolean => {
12
- if (value === null) {
12
+ if (value === undefined) {
13
13
  return true;
14
14
  }
15
15
  return validateNumber(value);
@@ -138,7 +138,7 @@ function isNumberOfType(phoneNumber: string, country: string, type: string) {
138
138
  }
139
139
  export function validatePhoneNumber(
140
140
  phoneNumber: string,
141
- countries: Array<string> = ['gr'],
141
+ countries: string[] = ['gr'],
142
142
  typeOfPhoneNumber?: PhoneNumberType
143
143
  ): boolean {
144
144
  if (!countries || countries.length === 0) {
@@ -4,7 +4,7 @@ import { ValidatorSchema } from '@digigov/form/validators/types';
4
4
  const CODE_REGEX = /^[12345678][0-9]{4}$/;
5
5
  export function validatePostalCode(
6
6
  number: string,
7
- countries: Array<string>
7
+ countries: string[]
8
8
  ): boolean {
9
9
  if (!countries) {
10
10
  return false;
@@ -1,4 +1,5 @@
1
- const UUID4_PATTERN = /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
1
+ const UUID4_PATTERN =
2
+ /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
2
3
 
3
4
  export function validateUUID4(uuid4: string): boolean {
4
5
  if (uuid4.length !== 36) {
@@ -75,14 +75,14 @@ it('throws if given country is not supported', () => {
75
75
  );
76
76
  });
77
77
 
78
- it('validates phone number type mobile with gr country code', () => {
78
+ it('validates phone number type mobile with gr country code', () => {
79
79
  expect(validatePhoneNumber('6934100982', ['GR'], 'mobile')).toBe(true);
80
80
  });
81
81
 
82
- it('validates phone number with no type and gr country code', () => {
82
+ it('validates phone number with no type and gr country code', () => {
83
83
  expect(validatePhoneNumber('6934100982', ['gr'], null)).toBe(true);
84
84
  });
85
85
 
86
- it('validates phone number with no type and gr country code', () => {
86
+ it('validates invalid phone number with no type and gr country code', () => {
87
87
  expect(validatePhoneNumber('41446681800', ['gr'], null)).toBe(false);
88
88
  });
package/types.d.ts CHANGED
@@ -1,10 +1,10 @@
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';
5
- export type FieldError = {
5
+ export interface FieldError {
6
6
  message: string;
7
- };
7
+ }
8
8
  export interface FieldsetSpec {
9
9
  key: string;
10
10
  fields: string[];
@@ -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 type 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,10 +45,11 @@ 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
- options.shouldUseNativeValidation && validateFieldsNatively({}, options);
51
+ if (options.shouldUseNativeValidation)
52
+ validateFieldsNatively({}, options);
38
53
  return {
39
54
  values: resolverOptions.rawValues ? values : result,
40
55
  errors: {}
@@ -43,13 +58,13 @@ const yupResolver = (schema, schemaOptions = {}, resolverOptions = {}) => async
43
58
  if (!e.inner) {
44
59
  throw e;
45
60
  }
46
- const parsed = parseErrorSchema(
47
- e,
48
- !options.shouldUseNativeValidation && options.criteriaMode === "all"
49
- );
50
61
  return {
51
62
  values: {},
52
- errors: parsed
63
+ errors: parseErrorSchema(
64
+ e,
65
+ !options.shouldUseNativeValidation && options.criteriaMode === "all"
66
+ ),
67
+ options
53
68
  };
54
69
  }
55
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 // eslint-disable-next-line no-console\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 options.shouldUseNativeValidation && 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;AAEnE,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,YAAQ,6BAA6B,uBAAuB,CAAC,GAAG,OAAO;AAEvE,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,21 +15,30 @@ 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;
29
33
  }).nullable().test(FILE_MAX_SIZE_VALIDATOR(field));
30
34
  },
31
- string: yup.string,
35
+ string: (field) => {
36
+ if (field.trim) {
37
+ return yup.string().trim();
38
+ } else {
39
+ return yup.string();
40
+ }
41
+ },
32
42
  boolean: () => {
33
43
  return yup.boolean().nullable().transform((value) => {
34
44
  if (value === "" || typeof value === "string") return null;
@@ -42,7 +52,10 @@ const getYUPTypeMap = () => {
42
52
  },
43
53
  array: (field) => {
44
54
  if (typeof field.extra.of === "object") {
45
- 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));
46
59
  if (field.extra.length)
47
60
  arrayValidator = arrayValidator.length(field.extra.length, {
48
61
  key: "form.error.array.length",
@@ -71,18 +84,19 @@ const getYUPTypeMap = () => {
71
84
  return yup.array().of(yup.string());
72
85
  }
73
86
  },
74
- number: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) : null).test(NUMBER_VALIDATOR()),
75
- int: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) : null).test(NUMBER_VALIDATOR()).test(INT_VALIDATOR()),
76
- email: () => yup.string().email("form.error.email"),
77
- afm: () => yup.string().test(AFM_VALIDATOR),
78
- uuid4: () => yup.string().test(UUID4_VALIDATOR),
79
- iban: (field) => yup.string().test(IBAN_VALIDATOR(field)),
80
- otp: (field) => yup.string().test(OTP_VALIDATOR(field)),
87
+ number: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) : void 0).test(NUMBER_VALIDATOR()),
88
+ int: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) : void 0).test(NUMBER_VALIDATOR()).test(INT_VALIDATOR()),
89
+ email: (field) => field.trim ? yup.string().trim().email("form.error.email") : yup.string().email("form.error.email"),
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),
92
+ uuid4: (field) => field.trim ? yup.string().trim().test(UUID4_VALIDATOR) : yup.string().test(UUID4_VALIDATOR),
93
+ iban: (field) => field.trim ? yup.string().trim().test(IBAN_VALIDATOR(field)) : yup.string().trim().test(IBAN_VALIDATOR(field)),
94
+ otp: (field) => yup.string().trim().test(OTP_VALIDATOR(field)),
81
95
  text: (field) => {
82
96
  if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {
83
- return yup.string().test(TEXT_LIMIT_VALIDATOR(field));
97
+ return field.trim ? yup.string().trim().test(TEXT_LIMIT_VALIDATOR(field)) : yup.string().test(TEXT_LIMIT_VALIDATOR(field));
84
98
  } else {
85
- return yup.string();
99
+ return field.trim ? yup.string().trim() : yup.string();
86
100
  }
87
101
  },
88
102
  image: (field) => {
@@ -93,9 +107,9 @@ const getYUPTypeMap = () => {
93
107
  return value;
94
108
  }).nullable().test(FILE_MAX_SIZE_VALIDATOR(field)).test(IMAGE_DIMENSION_VALIDATOR(field));
95
109
  },
96
- postal_code: (field) => yup.string().test(POSTALCODE_VALIDATOR(field)),
97
- mobile_phone: () => yup.string().test(MOBILE_PHONE_VALIDATOR),
98
- phone_number: (field) => yup.string().test(PHONE_NUMBER_VALIDATOR(field)),
110
+ postal_code: (field) => field.trim ? yup.string().trim().test(POSTALCODE_VALIDATOR(field)) : yup.string().test(POSTALCODE_VALIDATOR(field)),
111
+ mobile_phone: (field) => field.trim ? yup.string().trim().test(MOBILE_PHONE_VALIDATOR) : yup.string().test(MOBILE_PHONE_VALIDATOR),
112
+ phone_number: (field) => field.trim ? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field)) : yup.string().test(PHONE_NUMBER_VALIDATOR(field)),
99
113
  "choice:multiple": () => yup.array().of(yup.string()).nullable(),
100
114
  "choice:single": () => yup.string().nullable(),
101
115
  date: (field) => {
@@ -109,15 +123,25 @@ const getYUPTypeMap = () => {
109
123
  schema = schema.test(DATE_VALIDATOR);
110
124
  }
111
125
  return schema;
112
- }
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
113
137
  };
114
138
  return yupTypeMap;
115
139
  };
116
140
  function useValidationSchema(fields, validatorRegistry) {
117
141
  return useMemo(() => {
118
- const yupTypeMap = getYUPTypeMap();
142
+ const yupTypeMap = getYUPTypeMap(validatorRegistry);
119
143
  return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
120
- }, []);
144
+ }, [fields, validatorRegistry]);
121
145
  }
122
146
  export {
123
147
  getYUPTypeMap,