@digigov/form 2.0.0-4be8f7cc → 2.0.0-555d1027

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 (843) hide show
  1. package/Field/ErrorGroup/index.js +48 -0
  2. package/{Questions/index.spec → 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 +116 -77
  6. package/Field/FieldBase.js.map +7 -0
  7. package/Field/FieldBaseContainer/index.js +47 -37
  8. package/Field/FieldBaseContainer.js.map +7 -0
  9. package/Field/FieldConditional/index.js +83 -53
  10. package/Field/FieldConditional.js.map +7 -0
  11. package/Field/index.js +113 -63
  12. package/Field/index.js.map +7 -0
  13. package/Field/types/index.js +1 -1
  14. package/Field/types.d.ts +52 -5
  15. package/Field/types.js.map +7 -0
  16. package/Field/utils/calculateField/index.js +27 -0
  17. package/{FieldArray/FieldArray.stories → Field/utils/calculateField}/package.json +1 -1
  18. package/Field/utils/calculateField.d.ts +2 -0
  19. package/Field/utils/calculateField.js.map +7 -0
  20. package/Field/utils/evaluateFieldWithConditions/index.js +26 -0
  21. package/{inputs/DateInput/__stories__/Default → Field/utils/evaluateFieldWithConditions}/package.json +1 -1
  22. package/Field/utils/evaluateFieldWithConditions.d.ts +2 -0
  23. package/Field/utils/evaluateFieldWithConditions.js.map +7 -0
  24. package/Field/utils/index.d.ts +4 -0
  25. package/Field/utils/index.js +49 -116
  26. package/Field/utils/index.js.map +7 -0
  27. package/Field/utils/useField/index.js +64 -0
  28. package/{FormBuilder/FormBuilder → Field/utils/useField}/package.json +1 -1
  29. package/Field/utils/useField.d.ts +2 -0
  30. package/Field/utils/useField.js.map +7 -0
  31. package/FieldArray/FieldArray.stories.d.ts +3 -2
  32. package/FieldArray/FormDialog/index.js +399 -0
  33. package/{validators/validators.spec → FieldArray/FormDialog}/package.json +1 -1
  34. package/FieldArray/FormDialog.d.ts +67 -0
  35. package/FieldArray/FormDialog.js.map +7 -0
  36. package/FieldArray/__stories__/Default.d.ts +2 -2
  37. package/FieldArray/__stories__/WithExactLength.d.ts +2 -2
  38. package/FieldArray/__stories__/WithModal.d.ts +2 -0
  39. package/FieldArray/index.d.ts +7 -0
  40. package/FieldArray/index.js +113 -59
  41. package/FieldArray/index.js.map +7 -0
  42. package/FieldArray/index.test.d.ts +1 -0
  43. package/FieldObject/index.d.ts +8 -0
  44. package/FieldObject/index.js +85 -52
  45. package/FieldObject/index.js.map +7 -0
  46. package/Fieldset/FieldsetWithContext/index.js +27 -31
  47. package/Fieldset/FieldsetWithContext.js.map +7 -0
  48. package/Fieldset/index.d.ts +1 -1
  49. package/Fieldset/index.js +27 -29
  50. package/Fieldset/index.js.map +7 -0
  51. package/Fieldset/types/index.js +1 -1
  52. package/Fieldset/types.d.ts +3 -2
  53. package/Fieldset/types.js.map +7 -0
  54. package/FormBuilder/FormBuilder.stories.d.ts +5 -1
  55. package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +3 -0
  56. package/FormBuilder/__stories__/Default.d.ts +2 -2
  57. package/FormBuilder/__stories__/ErrorGrouping.d.ts +3 -0
  58. package/FormBuilder/index.d.ts +8 -1
  59. package/FormBuilder/index.js +241 -2
  60. package/FormBuilder/index.js.map +7 -0
  61. package/FormBuilder/index.test.d.ts +1 -0
  62. package/FormBuilder/interaction.test.d.ts +1 -0
  63. package/FormBuilder/scenarios.test.d.ts +88 -0
  64. package/FormContext/index.js +11 -3
  65. package/FormContext.d.ts +1 -0
  66. package/FormContext.js.map +7 -0
  67. package/MultiplicityField/MultiplicityField.stories.d.ts +8 -6
  68. package/MultiplicityField/__stories__/Default.d.ts +2 -2
  69. package/MultiplicityField/__stories__/PreviewDisplay.d.ts +2 -2
  70. package/MultiplicityField/__stories__/WithExactLength.d.ts +2 -2
  71. package/MultiplicityField/__stories__/WithMaxLength.d.ts +2 -2
  72. package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +2 -2
  73. package/MultiplicityField/__stories__/WithMinLength.d.ts +2 -2
  74. package/MultiplicityField/add-objects/index.js +139 -132
  75. package/MultiplicityField/add-objects.d.ts +2 -1
  76. package/MultiplicityField/add-objects.js.map +7 -0
  77. package/MultiplicityField/index.d.ts +2 -19
  78. package/MultiplicityField/index.js +117 -106
  79. package/MultiplicityField/index.js.map +7 -0
  80. package/MultiplicityField/index.test.d.ts +1 -0
  81. package/MultiplicityField/types/index.js +1 -0
  82. package/MultiplicityField/types/package.json +6 -0
  83. package/MultiplicityField/types.d.ts +19 -0
  84. package/MultiplicityField/types.js.map +7 -0
  85. package/Questions/Questions/index.js +48 -56
  86. package/Questions/Questions.js.map +7 -0
  87. package/Questions/Questions.stories.d.ts +3 -1
  88. package/Questions/QuestionsContext/index.js +9 -9
  89. package/Questions/QuestionsContext.d.ts +0 -1
  90. package/Questions/QuestionsContext.js.map +7 -0
  91. package/Questions/Step/ReviewStep/index.js +35 -47
  92. package/Questions/Step/ReviewStep.js.map +7 -0
  93. package/Questions/Step/Step/index.js +39 -47
  94. package/Questions/Step/Step.js.map +7 -0
  95. package/Questions/Step/StepArrayReview/index.js +41 -45
  96. package/Questions/Step/StepArrayReview.js.map +7 -0
  97. package/Questions/Step/StepContext/index.js +15 -19
  98. package/Questions/Step/StepContext.d.ts +0 -1
  99. package/Questions/Step/StepContext.js.map +7 -0
  100. package/Questions/Step/StepDescription/index.js +22 -22
  101. package/Questions/Step/StepDescription.js.map +7 -0
  102. package/Questions/Step/StepForm/index.js +33 -43
  103. package/Questions/Step/StepForm.js.map +7 -0
  104. package/Questions/Step/StepQuote/index.js +10 -9
  105. package/Questions/Step/StepQuote.js.map +7 -0
  106. package/Questions/Step/StepTitle/index.js +41 -38
  107. package/Questions/Step/StepTitle.d.ts +2 -1
  108. package/Questions/Step/StepTitle.js.map +7 -0
  109. package/Questions/Step/getAddMoreFields/index.js +28 -20
  110. package/Questions/Step/getAddMoreFields.js.map +7 -0
  111. package/Questions/Step/index.d.ts +0 -1
  112. package/Questions/Step/index.js +16 -13
  113. package/Questions/Step/index.js.map +7 -0
  114. package/Questions/Step/types/index.js +1 -1
  115. package/Questions/Step/types.d.ts +1 -0
  116. package/Questions/Step/types.js.map +7 -0
  117. package/Questions/__stories__/Default.d.ts +2 -2
  118. package/Questions/getNextStep/index.js +12 -10
  119. package/Questions/getNextStep.js.map +7 -0
  120. package/Questions/index.js +7 -3
  121. package/Questions/index.js.map +7 -0
  122. package/Questions/index.test.d.ts +1 -0
  123. package/Questions/types/index.js +1 -1
  124. package/Questions/types.d.ts +1 -0
  125. package/Questions/types.js.map +7 -0
  126. package/cjs/Field/ErrorGroup/index.js +82 -0
  127. package/cjs/Field/ErrorGroup.js.map +7 -0
  128. package/cjs/Field/FieldBase/index.js +148 -83
  129. package/cjs/Field/FieldBase.js.map +7 -0
  130. package/cjs/Field/FieldBaseContainer/index.js +79 -43
  131. package/cjs/Field/FieldBaseContainer.js.map +7 -0
  132. package/cjs/Field/FieldConditional/index.js +115 -59
  133. package/cjs/Field/FieldConditional.js.map +7 -0
  134. package/cjs/Field/index.js +142 -72
  135. package/cjs/Field/index.js.map +7 -0
  136. package/cjs/Field/types/index.js +16 -5
  137. package/cjs/Field/types.js.map +7 -0
  138. package/cjs/Field/utils/calculateField/index.js +50 -0
  139. package/cjs/Field/utils/calculateField.js.map +7 -0
  140. package/cjs/Field/utils/evaluateFieldWithConditions/index.js +49 -0
  141. package/cjs/Field/utils/evaluateFieldWithConditions.js.map +7 -0
  142. package/cjs/Field/utils/index.js +92 -133
  143. package/cjs/Field/utils/index.js.map +7 -0
  144. package/cjs/Field/utils/useField/index.js +87 -0
  145. package/cjs/Field/utils/useField.js.map +7 -0
  146. package/cjs/FieldArray/FormDialog/index.js +418 -0
  147. package/cjs/FieldArray/FormDialog.js.map +7 -0
  148. package/cjs/FieldArray/index.js +145 -65
  149. package/cjs/FieldArray/index.js.map +7 -0
  150. package/cjs/FieldObject/index.js +114 -61
  151. package/cjs/FieldObject/index.js.map +7 -0
  152. package/cjs/Fieldset/FieldsetWithContext/index.js +54 -40
  153. package/cjs/Fieldset/FieldsetWithContext.js.map +7 -0
  154. package/cjs/Fieldset/index.js +61 -39
  155. package/cjs/Fieldset/index.js.map +7 -0
  156. package/cjs/Fieldset/types/index.js +16 -5
  157. package/cjs/Fieldset/types.js.map +7 -0
  158. package/cjs/FormBuilder/index.js +277 -8
  159. package/cjs/FormBuilder/index.js.map +7 -0
  160. package/cjs/FormContext/index.js +34 -8
  161. package/cjs/FormContext.js.map +7 -0
  162. package/cjs/MultiplicityField/add-objects/index.js +166 -138
  163. package/cjs/MultiplicityField/add-objects.js.map +7 -0
  164. package/cjs/MultiplicityField/index.js +145 -115
  165. package/cjs/MultiplicityField/index.js.map +7 -0
  166. package/cjs/MultiplicityField/types/index.js +16 -0
  167. package/cjs/MultiplicityField/types.js.map +7 -0
  168. package/cjs/Questions/Questions/index.js +80 -65
  169. package/cjs/Questions/Questions.js.map +7 -0
  170. package/cjs/Questions/QuestionsContext/index.js +31 -14
  171. package/cjs/Questions/QuestionsContext.js.map +7 -0
  172. package/cjs/Questions/Step/ReviewStep/index.js +61 -56
  173. package/cjs/Questions/Step/ReviewStep.js.map +7 -0
  174. package/cjs/Questions/Step/Step/index.js +71 -56
  175. package/cjs/Questions/Step/Step.js.map +7 -0
  176. package/cjs/Questions/Step/StepArrayReview/index.js +65 -54
  177. package/cjs/Questions/Step/StepArrayReview.js.map +7 -0
  178. package/cjs/Questions/Step/StepContext/index.js +37 -24
  179. package/cjs/Questions/Step/StepContext.js.map +7 -0
  180. package/cjs/Questions/Step/StepDescription/index.js +55 -31
  181. package/cjs/Questions/Step/StepDescription.js.map +7 -0
  182. package/cjs/Questions/Step/StepForm/index.js +65 -52
  183. package/cjs/Questions/Step/StepForm.js.map +7 -0
  184. package/cjs/Questions/Step/StepQuote/index.js +42 -15
  185. package/cjs/Questions/Step/StepQuote.js.map +7 -0
  186. package/cjs/Questions/Step/StepTitle/index.js +72 -47
  187. package/cjs/Questions/Step/StepTitle.js.map +7 -0
  188. package/cjs/Questions/Step/getAddMoreFields/index.js +50 -25
  189. package/cjs/Questions/Step/getAddMoreFields.js.map +7 -0
  190. package/cjs/Questions/Step/index.js +59 -143
  191. package/cjs/Questions/Step/index.js.map +7 -0
  192. package/cjs/Questions/Step/types/index.js +16 -5
  193. package/cjs/Questions/Step/types.js.map +7 -0
  194. package/cjs/Questions/getNextStep/index.js +33 -14
  195. package/cjs/Questions/getNextStep.js.map +7 -0
  196. package/cjs/Questions/index.js +29 -19
  197. package/cjs/Questions/index.js.map +7 -0
  198. package/cjs/Questions/types/index.js +16 -5
  199. package/cjs/Questions/types.js.map +7 -0
  200. package/cjs/index.js +47 -20
  201. package/cjs/index.js.map +7 -0
  202. package/cjs/inputs/AutoCompleteInput/index.js +92 -49
  203. package/cjs/inputs/AutoCompleteInput/index.js.map +7 -0
  204. package/cjs/inputs/Checkboxes/index.js +102 -96
  205. package/cjs/inputs/Checkboxes/index.js.map +7 -0
  206. package/cjs/inputs/DateInput/index.js +157 -115
  207. package/cjs/inputs/DateInput/index.js.map +7 -0
  208. package/cjs/inputs/DateTimeInput/index.js +245 -0
  209. package/cjs/inputs/DateTimeInput/index.js.map +7 -0
  210. package/cjs/inputs/FileInput/index.js +115 -65
  211. package/cjs/inputs/FileInput/index.js.map +7 -0
  212. package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  213. package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  214. package/cjs/inputs/ImageInput/index.js +127 -83
  215. package/cjs/inputs/ImageInput/index.js.map +7 -0
  216. package/cjs/inputs/Input/index.js +106 -71
  217. package/cjs/inputs/Input/index.js.map +7 -0
  218. package/cjs/inputs/Label/index.js +45 -24
  219. package/cjs/inputs/Label/index.js.map +7 -0
  220. package/cjs/inputs/OtpInput/index.js +143 -113
  221. package/cjs/inputs/OtpInput/index.js.map +7 -0
  222. package/cjs/inputs/Radio/index.js +131 -61
  223. package/cjs/inputs/Radio/index.js.map +7 -0
  224. package/cjs/inputs/Select/index.js +61 -36
  225. package/cjs/inputs/Select/index.js.map +7 -0
  226. package/cjs/inputs/index.js +62 -69
  227. package/cjs/inputs/index.js.map +7 -0
  228. package/cjs/inputs/inputsScenarios/index.js +533 -0
  229. package/cjs/inputs/inputsScenarios.js.map +7 -0
  230. package/cjs/internal/index.js +36 -346
  231. package/cjs/internal.js.map +7 -0
  232. package/cjs/lazy/index.js +110 -516
  233. package/cjs/lazy.js.map +7 -0
  234. package/cjs/locales/el/index.js +35 -0
  235. package/cjs/locales/el.js.map +7 -0
  236. package/cjs/registry/index.js +190 -142
  237. package/cjs/registry.js.map +7 -0
  238. package/cjs/types/index.js +22 -5
  239. package/cjs/types.js.map +7 -0
  240. package/cjs/utils/index.js +93 -83
  241. package/cjs/utils.js.map +7 -0
  242. package/cjs/validators/index.js +139 -167
  243. package/cjs/validators/index.js.map +7 -0
  244. package/cjs/validators/types/index.js +16 -5
  245. package/cjs/validators/types.js.map +7 -0
  246. package/cjs/validators/utils/afm/index.js +38 -21
  247. package/cjs/validators/utils/afm.js.map +7 -0
  248. package/cjs/validators/utils/amka/index.js +60 -0
  249. package/cjs/validators/utils/amka.js.map +7 -0
  250. package/cjs/validators/utils/date/index.js +156 -0
  251. package/cjs/validators/utils/date.js.map +7 -0
  252. package/cjs/validators/utils/datetime/index.js +240 -0
  253. package/cjs/validators/utils/datetime.js.map +7 -0
  254. package/cjs/validators/utils/file/index.js +48 -30
  255. package/cjs/validators/utils/file.js.map +7 -0
  256. package/cjs/validators/utils/iban/index.js +36 -17
  257. package/cjs/validators/utils/iban.js.map +7 -0
  258. package/cjs/validators/utils/image/index.js +88 -112
  259. package/cjs/validators/utils/image.js.map +7 -0
  260. package/cjs/validators/utils/index.js +103 -159
  261. package/cjs/validators/utils/index.js.map +7 -0
  262. package/cjs/validators/utils/int/index.js +35 -13
  263. package/cjs/validators/utils/int.js.map +7 -0
  264. package/cjs/validators/utils/number/index.js +34 -12
  265. package/cjs/validators/utils/number.js.map +7 -0
  266. package/cjs/validators/utils/otp/index.js +35 -13
  267. package/cjs/validators/utils/otp.js.map +7 -0
  268. package/cjs/validators/utils/phone/index.js +113 -58
  269. package/cjs/validators/utils/phone.js.map +7 -0
  270. package/cjs/validators/utils/postal_code/index.js +36 -16
  271. package/cjs/validators/utils/postal_code.js.map +7 -0
  272. package/cjs/validators/utils/text_limit/index.js +40 -25
  273. package/cjs/validators/utils/text_limit.js.map +7 -0
  274. package/cjs/validators/utils/uuid4/index.js +34 -13
  275. package/cjs/validators/utils/uuid4.js.map +7 -0
  276. package/index.d.ts +4 -1
  277. package/index.js +13 -4
  278. package/index.js.map +7 -0
  279. package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +4 -2
  280. package/inputs/AutoCompleteInput/__stories__/Default.d.ts +2 -2
  281. package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +2 -2
  282. package/inputs/AutoCompleteInput/index.d.ts +2 -2
  283. package/inputs/AutoCompleteInput/index.js +62 -40
  284. package/inputs/AutoCompleteInput/index.js.map +7 -0
  285. package/inputs/AutoCompleteInput/index.test.d.ts +1 -0
  286. package/inputs/Checkboxes/Checkboxes.stories.d.ts +5 -3
  287. package/inputs/Checkboxes/__stories__/Conditional.d.ts +2 -2
  288. package/inputs/Checkboxes/__stories__/Default.d.ts +2 -2
  289. package/inputs/Checkboxes/__stories__/WithDivider.d.ts +2 -2
  290. package/inputs/Checkboxes/index.d.ts +2 -1
  291. package/inputs/Checkboxes/index.js +74 -87
  292. package/inputs/Checkboxes/index.js.map +7 -0
  293. package/inputs/Checkboxes/index.test.d.ts +1 -0
  294. package/inputs/DateInput/DateInput.stories.d.ts +7 -1
  295. package/inputs/DateInput/__stories__/Default.d.ts +2 -2
  296. package/inputs/DateInput/__stories__/WithDefaultValue.d.ts +3 -0
  297. package/inputs/DateInput/__stories__/WithInitialValue.d.ts +3 -0
  298. package/inputs/DateInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
  299. package/inputs/DateInput/__stories__/WithWrongInitialValue.d.ts +3 -0
  300. package/inputs/DateInput/index.d.ts +3 -4
  301. package/inputs/DateInput/index.js +127 -105
  302. package/inputs/DateInput/index.js.map +7 -0
  303. package/inputs/DateInput/index.test.d.ts +1 -0
  304. package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +14 -0
  305. package/inputs/DateTimeInput/__stories__/Default.d.ts +3 -0
  306. package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +3 -0
  307. package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +3 -0
  308. package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
  309. package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +3 -0
  310. package/inputs/DateTimeInput/index.d.ts +13 -0
  311. package/inputs/DateTimeInput/index.js +215 -0
  312. package/inputs/DateTimeInput/index.js.map +7 -0
  313. package/inputs/DateTimeInput/index.test.d.ts +1 -0
  314. package/inputs/DateTimeInput/package.json +6 -0
  315. package/inputs/FileInput/FileInput.stories.d.ts +4 -1
  316. package/inputs/FileInput/__stories__/Default.d.ts +2 -2
  317. package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
  318. package/inputs/FileInput/index.d.ts +17 -1
  319. package/inputs/FileInput/index.js +86 -56
  320. package/inputs/FileInput/index.js.map +7 -0
  321. package/inputs/FileInput/index.test.d.ts +1 -0
  322. package/inputs/ImageInput/ImageInput.stories.d.ts +6 -3
  323. package/inputs/ImageInput/__stories__/Default.d.ts +2 -2
  324. package/inputs/ImageInput/__stories__/MaxSize.d.ts +3 -0
  325. package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
  326. package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +2 -2
  327. package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  328. package/inputs/{FileInput/__stories__/Default → ImageInput/__stories__/logo.d}/package.json +1 -1
  329. package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  330. package/inputs/ImageInput/index.d.ts +9 -1
  331. package/inputs/ImageInput/index.js +95 -75
  332. package/inputs/ImageInput/index.js.map +7 -0
  333. package/inputs/ImageInput/index.test.d.ts +1 -0
  334. package/inputs/Input/Input.stories.d.ts +15 -10
  335. package/inputs/Input/__stories__/AFM.d.ts +2 -2
  336. package/inputs/Input/__stories__/AMKA.d.ts +3 -0
  337. package/inputs/Input/__stories__/Boolean.d.ts +2 -2
  338. package/inputs/Input/__stories__/Email.d.ts +3 -0
  339. package/inputs/Input/__stories__/IBAN.d.ts +2 -2
  340. package/inputs/Input/__stories__/Integer.d.ts +2 -2
  341. package/inputs/Input/__stories__/LandlineNumber.d.ts +2 -2
  342. package/inputs/Input/__stories__/MobilePhone.d.ts +2 -2
  343. package/inputs/Input/__stories__/PhoneNumber.d.ts +2 -2
  344. package/inputs/Input/__stories__/PostalCode.d.ts +2 -2
  345. package/inputs/Input/__stories__/String.d.ts +3 -0
  346. package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +3 -0
  347. package/inputs/Input/__stories__/TextWithLimit.d.ts +3 -0
  348. package/inputs/Input/index.d.ts +2 -1
  349. package/inputs/Input/index.js +75 -66
  350. package/inputs/Input/index.js.map +7 -0
  351. package/inputs/Input/index.test.d.ts +1 -0
  352. package/inputs/Label/Label.stories.d.ts +3 -1
  353. package/inputs/Label/__stories__/Default.d.ts +2 -2
  354. package/inputs/Label/index.d.ts +1 -3
  355. package/inputs/Label/index.js +12 -17
  356. package/inputs/Label/index.js.map +7 -0
  357. package/inputs/Label/index.test.d.ts +1 -0
  358. package/inputs/OtpInput/OtpInput.stories.d.ts +3 -1
  359. package/inputs/OtpInput/__stories__/Default.d.ts +2 -2
  360. package/inputs/OtpInput/index.d.ts +1 -1
  361. package/inputs/OtpInput/index.js +111 -104
  362. package/inputs/OtpInput/index.js.map +7 -0
  363. package/inputs/OtpInput/index.test.d.ts +1 -0
  364. package/inputs/Radio/Radio.stories.d.ts +5 -3
  365. package/inputs/Radio/__stories__/Conditional.d.ts +2 -2
  366. package/inputs/Radio/__stories__/Default.d.ts +2 -2
  367. package/inputs/Radio/__stories__/WithDivider.d.ts +2 -2
  368. package/inputs/Radio/index.d.ts +6 -1
  369. package/inputs/Radio/index.js +102 -55
  370. package/inputs/Radio/index.js.map +7 -0
  371. package/inputs/Radio/index.test.d.ts +1 -0
  372. package/inputs/Select/Select.stories.d.ts +3 -1
  373. package/inputs/Select/__stories__/Default.d.ts +2 -2
  374. package/inputs/Select/index.d.ts +3 -2
  375. package/inputs/Select/index.js +33 -31
  376. package/inputs/Select/index.js.map +7 -0
  377. package/inputs/Select/index.test.d.ts +1 -0
  378. package/inputs/index.js +21 -9
  379. package/inputs/index.js.map +7 -0
  380. package/inputs/inputsScenarios/index.js +499 -0
  381. package/inputs/inputsScenarios/package.json +6 -0
  382. package/inputs/inputsScenarios.d.ts +296 -0
  383. package/inputs/inputsScenarios.js.map +7 -0
  384. package/internal/index.js +10 -34
  385. package/internal.d.ts +2 -31
  386. package/internal.js.map +7 -0
  387. package/lazy/index.js +76 -393
  388. package/locales/el/index.js +6 -0
  389. package/{Form.stories → locales/el}/package.json +1 -1
  390. package/locales/el.d.ts +2 -0
  391. package/locales/el.js.map +7 -0
  392. package/package.json +8 -9
  393. package/registry/index.js +125 -98
  394. package/src/Field/ErrorGroup.tsx +84 -0
  395. package/src/Field/FieldBase.tsx +40 -23
  396. package/src/Field/FieldBaseContainer.tsx +22 -8
  397. package/src/Field/FieldConditional.tsx +9 -1
  398. package/src/Field/doc.mdx +207 -0
  399. package/src/Field/index.tsx +40 -6
  400. package/src/Field/types.tsx +82 -5
  401. package/src/Field/utils/calculateField.ts +49 -0
  402. package/src/Field/utils/evaluateFieldWithConditions.ts +30 -0
  403. package/src/Field/utils/index.ts +84 -0
  404. package/src/Field/utils/useField.ts +66 -0
  405. package/src/FieldArray/FieldArray.stories.js +3 -2
  406. package/src/FieldArray/FormDialog.tsx +568 -0
  407. package/src/FieldArray/__stories__/Default.tsx +2 -1
  408. package/src/FieldArray/__stories__/WithExactLength.tsx +2 -1
  409. package/src/FieldArray/__stories__/WithModal.tsx +160 -0
  410. package/src/FieldArray/index.test.tsx +32 -0
  411. package/src/FieldArray/index.tsx +99 -50
  412. package/src/FieldObject/index.tsx +56 -22
  413. package/src/Fieldset/index.tsx +5 -5
  414. package/src/Fieldset/types.tsx +5 -3
  415. package/src/FormBuilder/FormBuilder.stories.js +6 -1
  416. package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +63 -0
  417. package/src/FormBuilder/__stories__/Default.tsx +1 -1
  418. package/src/FormBuilder/__stories__/ErrorGrouping.tsx +43 -0
  419. package/{FormBuilder/FormBuilder.mdx → src/FormBuilder/doc.mdx} +27 -35
  420. package/src/FormBuilder/index.test.tsx +32 -0
  421. package/src/FormBuilder/index.tsx +268 -1
  422. package/src/FormBuilder/interaction.test.tsx +40 -0
  423. package/src/FormBuilder/scenarios.test.tsx +1978 -0
  424. package/src/FormContext.tsx +5 -2
  425. package/src/MultiplicityField/MultiplicityField.stories.js +9 -6
  426. package/src/MultiplicityField/__stories__/Default.tsx +1 -1
  427. package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +3 -3
  428. package/src/MultiplicityField/__stories__/WithExactLength.tsx +2 -2
  429. package/src/MultiplicityField/__stories__/WithMaxLength.tsx +2 -2
  430. package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +2 -2
  431. package/src/MultiplicityField/__stories__/WithMinLength.tsx +2 -2
  432. package/src/MultiplicityField/add-objects.tsx +33 -15
  433. package/{MultiplicityField/MultiplicityField.mdx → src/MultiplicityField/doc.mdx} +112 -98
  434. package/src/MultiplicityField/index.test.tsx +44 -0
  435. package/src/MultiplicityField/index.tsx +24 -34
  436. package/src/MultiplicityField/types.ts +22 -0
  437. package/src/Questions/Questions.stories.js +4 -1
  438. package/src/Questions/Questions.tsx +4 -4
  439. package/src/Questions/Step/StepArrayReview.tsx +1 -1
  440. package/src/Questions/Step/StepTitle.tsx +5 -3
  441. package/src/Questions/Step/index.ts +0 -1
  442. package/src/Questions/Step/types.tsx +1 -0
  443. package/src/Questions/__snapshots__/index.spec.tsx.snap +74 -587
  444. package/src/Questions/__stories__/Default.tsx +1 -1
  445. package/src/Questions/{index.mdx → doc.mdx} +34 -57
  446. package/src/Questions/index.spec.tsx +17 -5
  447. package/src/Questions/index.test.tsx +24 -0
  448. package/src/Questions/types.tsx +1 -0
  449. package/src/create-simple-form.mdx +2 -6
  450. package/{index.mdx → src/doc.mdx} +29 -18
  451. package/src/index.ts +4 -1
  452. package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +5 -2
  453. package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +3 -11
  454. package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +3 -10
  455. package/{inputs/AutoCompleteInput/index.mdx → src/inputs/AutoCompleteInput/doc.mdx} +2 -13
  456. package/src/inputs/AutoCompleteInput/index.test.tsx +28 -0
  457. package/src/inputs/AutoCompleteInput/index.tsx +47 -31
  458. package/src/inputs/Checkboxes/Checkboxes.stories.js +6 -3
  459. package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
  460. package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
  461. package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
  462. package/src/inputs/Checkboxes/{index.mdx → doc.mdx} +5 -15
  463. package/src/inputs/Checkboxes/index.test.tsx +32 -0
  464. package/src/inputs/Checkboxes/index.tsx +34 -31
  465. package/src/inputs/DateInput/DateInput.stories.js +8 -1
  466. package/src/inputs/DateInput/__stories__/Default.tsx +17 -16
  467. package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +26 -0
  468. package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +28 -0
  469. package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +26 -0
  470. package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +28 -0
  471. package/src/inputs/DateInput/{index.mdx → doc.mdx} +1 -8
  472. package/src/inputs/DateInput/index.test.tsx +40 -0
  473. package/src/inputs/DateInput/index.tsx +60 -23
  474. package/src/inputs/DateTimeInput/DateTimeInput.stories.js +14 -0
  475. package/src/inputs/DateTimeInput/__stories__/Default.tsx +25 -0
  476. package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +26 -0
  477. package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +28 -0
  478. package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +26 -0
  479. package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +28 -0
  480. package/src/inputs/DateTimeInput/doc.mdx +16 -0
  481. package/src/inputs/DateTimeInput/index.test.tsx +40 -0
  482. package/src/inputs/DateTimeInput/index.tsx +233 -0
  483. package/src/inputs/FileInput/FileInput.stories.js +5 -1
  484. package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
  485. package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
  486. package/src/inputs/FileInput/{index.mdx → doc.mdx} +1 -5
  487. package/src/inputs/FileInput/index.test.tsx +28 -0
  488. package/src/inputs/FileInput/index.tsx +106 -41
  489. package/src/inputs/ImageInput/ImageInput.stories.js +7 -3
  490. package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
  491. package/src/inputs/ImageInput/__stories__/{WithInvalidImageSize.tsx → MaxSize.tsx} +5 -3
  492. package/src/inputs/ImageInput/__stories__/WithInitialValues.tsx +45 -0
  493. package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +3 -1
  494. package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
  495. package/src/inputs/ImageInput/__stories__/logo.png +0 -0
  496. package/src/inputs/ImageInput/doc.mdx +23 -0
  497. package/src/inputs/ImageInput/index.test.tsx +36 -0
  498. package/src/inputs/ImageInput/index.tsx +103 -50
  499. package/src/inputs/Input/Input.stories.js +16 -10
  500. package/src/inputs/Input/__stories__/AFM.tsx +1 -1
  501. package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
  502. package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
  503. package/src/inputs/Input/__stories__/Email.tsx +23 -0
  504. package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
  505. package/src/inputs/Input/__stories__/Integer.tsx +1 -1
  506. package/src/inputs/Input/__stories__/LandlineNumber.tsx +3 -2
  507. package/src/inputs/Input/__stories__/MobilePhone.tsx +2 -1
  508. package/src/inputs/Input/__stories__/PhoneNumber.tsx +2 -1
  509. package/src/inputs/Input/__stories__/PostalCode.tsx +2 -1
  510. package/src/inputs/Input/__stories__/{Default.tsx → String.tsx} +2 -2
  511. package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +26 -0
  512. package/src/inputs/Input/__stories__/{TextWithCharacterLimit.tsx → TextWithLimit.tsx} +3 -2
  513. package/src/inputs/Input/doc.mdx +56 -0
  514. package/src/inputs/Input/index.test.tsx +72 -0
  515. package/src/inputs/Input/index.tsx +44 -31
  516. package/src/inputs/Label/Label.stories.js +4 -1
  517. package/src/inputs/Label/__stories__/Default.tsx +4 -2
  518. package/src/inputs/Label/doc.mdx +14 -0
  519. package/src/inputs/Label/index.test.tsx +24 -0
  520. package/src/inputs/Label/index.tsx +3 -10
  521. package/src/inputs/OtpInput/OtpInput.stories.js +4 -1
  522. package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
  523. package/{inputs/OtpInput/index.mdx → src/inputs/OtpInput/doc.mdx} +1 -8
  524. package/src/inputs/OtpInput/index.test.tsx +24 -0
  525. package/src/inputs/OtpInput/index.tsx +3 -1
  526. package/src/inputs/Radio/Radio.stories.js +6 -3
  527. package/src/inputs/Radio/__stories__/Conditional.tsx +3 -2
  528. package/src/inputs/Radio/__stories__/Default.tsx +1 -1
  529. package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
  530. package/{cjs/inputs/Radio/index.mdx → src/inputs/Radio/doc.mdx} +5 -15
  531. package/src/inputs/Radio/index.test.tsx +32 -0
  532. package/src/inputs/Radio/index.tsx +79 -9
  533. package/src/inputs/Select/Select.stories.js +4 -1
  534. package/src/inputs/Select/__stories__/Default.tsx +1 -1
  535. package/{inputs/Select/index.mdx → src/inputs/Select/doc.mdx} +1 -5
  536. package/src/inputs/Select/index.test.tsx +24 -0
  537. package/src/inputs/Select/index.tsx +18 -7
  538. package/src/inputs/inputsScenarios.ts +496 -0
  539. package/src/installation.mdx +2 -5
  540. package/src/internal.ts +2 -31
  541. package/src/lazy.js +77 -59
  542. package/src/locales/el.ts +3 -0
  543. package/src/registry.js +108 -88
  544. package/src/types.tsx +13 -65
  545. package/src/utils.ts +55 -33
  546. package/src/validators/index.ts +107 -90
  547. package/src/validators/utils/amka.ts +39 -0
  548. package/src/validators/utils/date.ts +126 -0
  549. package/src/validators/utils/datetime.ts +217 -0
  550. package/src/validators/utils/file.ts +33 -17
  551. package/src/validators/utils/index.ts +6 -1
  552. package/src/validators/utils/int.ts +1 -1
  553. package/src/validators/utils/number.ts +1 -1
  554. package/src/validators/utils/phone.ts +63 -72
  555. package/src/validators/utils/postal_code.ts +1 -1
  556. package/src/validators/utils/uuid4.ts +2 -1
  557. package/src/validators/validators.spec.ts +6 -40
  558. package/types/index.js +2 -1
  559. package/types.d.ts +8 -36
  560. package/types.js.map +7 -0
  561. package/utils/index.js +71 -77
  562. package/utils.d.ts +2 -0
  563. package/utils.js.map +7 -0
  564. package/validators/index.d.ts +1 -1
  565. package/validators/index.js +121 -153
  566. package/validators/index.js.map +7 -0
  567. package/validators/types/index.js +1 -1
  568. package/validators/types.js.map +7 -0
  569. package/validators/utils/afm/index.js +16 -16
  570. package/validators/utils/afm.js.map +7 -0
  571. package/validators/utils/amka/index.js +36 -0
  572. package/validators/utils/amka/package.json +6 -0
  573. package/validators/utils/amka.d.ts +6 -0
  574. package/validators/utils/amka.js.map +7 -0
  575. package/validators/utils/date/index.js +121 -0
  576. package/validators/utils/date/package.json +6 -0
  577. package/validators/utils/date.d.ts +9 -0
  578. package/validators/utils/date.js.map +7 -0
  579. package/validators/utils/datetime/index.js +205 -0
  580. package/{Questions/Questions.stories → validators/utils/datetime}/package.json +1 -1
  581. package/validators/utils/datetime.d.ts +9 -0
  582. package/validators/utils/datetime.js.map +7 -0
  583. package/validators/utils/file/index.js +26 -25
  584. package/validators/utils/file.js.map +7 -0
  585. package/validators/utils/iban/index.js +14 -12
  586. package/validators/utils/iban.js.map +7 -0
  587. package/validators/utils/image/index.js +66 -106
  588. package/validators/utils/image.js.map +7 -0
  589. package/validators/utils/index.d.ts +3 -0
  590. package/validators/utils/index.js +59 -48
  591. package/validators/utils/index.js.map +7 -0
  592. package/validators/utils/int/index.js +13 -8
  593. package/validators/utils/int.js.map +7 -0
  594. package/validators/utils/number/index.js +12 -7
  595. package/validators/utils/number.js.map +7 -0
  596. package/validators/utils/otp/index.js +13 -8
  597. package/validators/utils/otp.js.map +7 -0
  598. package/validators/utils/phone/index.js +89 -51
  599. package/validators/utils/phone.d.ts +1 -1
  600. package/validators/utils/phone.js.map +7 -0
  601. package/validators/utils/postal_code/index.js +14 -11
  602. package/validators/utils/postal_code.d.ts +1 -1
  603. package/validators/utils/postal_code.js.map +7 -0
  604. package/validators/utils/text_limit/index.js +18 -20
  605. package/validators/utils/text_limit.js.map +7 -0
  606. package/validators/utils/uuid4/index.js +12 -8
  607. package/validators/utils/uuid4.js.map +7 -0
  608. package/Field/index.mdx +0 -6
  609. package/Field/utils.d.ts +0 -5
  610. package/FieldArray/FieldArray.stories/index.js +0 -8
  611. package/FieldArray/FieldArray.stories.playwright.json +0 -353
  612. package/FieldArray/__stories__/Default/index.js +0 -88
  613. package/FieldArray/__stories__/Default/package.json +0 -6
  614. package/FieldArray/__stories__/WithExactLength/index.js +0 -88
  615. package/FieldArray/__stories__/WithExactLength/package.json +0 -6
  616. package/Form.stories/index.js +0 -3
  617. package/FormBuilder/FormBuilder/index.js +0 -152
  618. package/FormBuilder/FormBuilder.d.ts +0 -5
  619. package/FormBuilder/FormBuilder.stories/index.js +0 -7
  620. package/FormBuilder/FormBuilder.stories/package.json +0 -6
  621. package/FormBuilder/FormBuilder.stories.playwright.json +0 -52
  622. package/FormBuilder/__stories__/Default/index.js +0 -26
  623. package/FormBuilder/__stories__/Default/package.json +0 -6
  624. package/MultiplicityField/MultiplicityField.stories/index.js +0 -12
  625. package/MultiplicityField/MultiplicityField.stories/package.json +0 -6
  626. package/MultiplicityField/MultiplicityField.stories.playwright.json +0 -1370
  627. package/MultiplicityField/__stories__/Default/index.js +0 -95
  628. package/MultiplicityField/__stories__/Default/package.json +0 -6
  629. package/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -72
  630. package/MultiplicityField/__stories__/PreviewDisplay/package.json +0 -6
  631. package/MultiplicityField/__stories__/WithExactLength/index.js +0 -90
  632. package/MultiplicityField/__stories__/WithExactLength/package.json +0 -6
  633. package/MultiplicityField/__stories__/WithMaxLength/index.js +0 -93
  634. package/MultiplicityField/__stories__/WithMaxLength/package.json +0 -6
  635. package/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -94
  636. package/MultiplicityField/__stories__/WithMinAndMaxLength/package.json +0 -6
  637. package/MultiplicityField/__stories__/WithMinLength/index.js +0 -93
  638. package/MultiplicityField/__stories__/WithMinLength/package.json +0 -6
  639. package/Questions/Questions.stories/index.js +0 -7
  640. package/Questions/__snapshots__/index.spec.tsx.snap +0 -596
  641. package/Questions/__stories__/Default/index.js +0 -102
  642. package/Questions/__stories__/Default/package.json +0 -6
  643. package/Questions/index.mdx +0 -415
  644. package/Questions/index.spec/index.js +0 -59
  645. package/cjs/Field/index.mdx +0 -6
  646. package/cjs/FieldArray/FieldArray.stories/index.js +0 -38
  647. package/cjs/FieldArray/FieldArray.stories.playwright.json +0 -353
  648. package/cjs/FieldArray/__stories__/Default/index.js +0 -98
  649. package/cjs/FieldArray/__stories__/WithExactLength/index.js +0 -98
  650. package/cjs/Form.stories/index.js +0 -9
  651. package/cjs/FormBuilder/FormBuilder/index.js +0 -162
  652. package/cjs/FormBuilder/FormBuilder.mdx +0 -256
  653. package/cjs/FormBuilder/FormBuilder.stories/index.js +0 -26
  654. package/cjs/FormBuilder/FormBuilder.stories.playwright.json +0 -52
  655. package/cjs/FormBuilder/__stories__/Default/index.js +0 -36
  656. package/cjs/MultiplicityField/MultiplicityField.mdx +0 -590
  657. package/cjs/MultiplicityField/MultiplicityField.stories/index.js +0 -86
  658. package/cjs/MultiplicityField/MultiplicityField.stories.playwright.json +0 -1370
  659. package/cjs/MultiplicityField/__stories__/Default/index.js +0 -105
  660. package/cjs/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -82
  661. package/cjs/MultiplicityField/__stories__/WithExactLength/index.js +0 -100
  662. package/cjs/MultiplicityField/__stories__/WithMaxLength/index.js +0 -103
  663. package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -104
  664. package/cjs/MultiplicityField/__stories__/WithMinLength/index.js +0 -103
  665. package/cjs/Questions/Questions.stories/index.js +0 -26
  666. package/cjs/Questions/__snapshots__/index.spec.tsx.snap +0 -596
  667. package/cjs/Questions/__stories__/Default/index.js +0 -113
  668. package/cjs/Questions/index.mdx +0 -415
  669. package/cjs/Questions/index.spec/index.js +0 -63
  670. package/cjs/create-simple-form.mdx +0 -539
  671. package/cjs/index.mdx +0 -51
  672. package/cjs/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -38
  673. package/cjs/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -51
  674. package/cjs/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -52
  675. package/cjs/inputs/AutoCompleteInput/index.mdx +0 -29
  676. package/cjs/inputs/Checkboxes/Checkboxes.stories/index.js +0 -50
  677. package/cjs/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -85
  678. package/cjs/inputs/Checkboxes/__stories__/Conditional/index.js +0 -103
  679. package/cjs/inputs/Checkboxes/__stories__/Default/index.js +0 -50
  680. package/cjs/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -51
  681. package/cjs/inputs/Checkboxes/index.mdx +0 -33
  682. package/cjs/inputs/DateInput/DateInput.stories/index.js +0 -26
  683. package/cjs/inputs/DateInput/DateInput.stories.playwright.json +0 -72
  684. package/cjs/inputs/DateInput/__stories__/Default/index.js +0 -33
  685. package/cjs/inputs/DateInput/index.mdx +0 -23
  686. package/cjs/inputs/FileInput/FileInput.stories/index.js +0 -26
  687. package/cjs/inputs/FileInput/FileInput.stories.playwright.json +0 -75
  688. package/cjs/inputs/FileInput/__stories__/Default/index.js +0 -30
  689. package/cjs/inputs/FileInput/index.mdx +0 -19
  690. package/cjs/inputs/ImageInput/ImageInput.stories/index.js +0 -50
  691. package/cjs/inputs/ImageInput/ImageInput.stories.playwright.json +0 -77
  692. package/cjs/inputs/ImageInput/__stories__/Default/index.js +0 -38
  693. package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -46
  694. package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -43
  695. package/cjs/inputs/ImageInput/index.mdx +0 -19
  696. package/cjs/inputs/Input/Input.stories/index.js +0 -134
  697. package/cjs/inputs/Input/Input.stories.playwright.json +0 -376
  698. package/cjs/inputs/Input/__stories__/AFM/index.js +0 -32
  699. package/cjs/inputs/Input/__stories__/Boolean/index.js +0 -33
  700. package/cjs/inputs/Input/__stories__/Default/index.js +0 -33
  701. package/cjs/inputs/Input/__stories__/IBAN/index.js +0 -33
  702. package/cjs/inputs/Input/__stories__/Integer/index.js +0 -41
  703. package/cjs/inputs/Input/__stories__/LandlineNumber/index.js +0 -36
  704. package/cjs/inputs/Input/__stories__/MobilePhone/index.js +0 -36
  705. package/cjs/inputs/Input/__stories__/PhoneNumber/index.js +0 -35
  706. package/cjs/inputs/Input/__stories__/PostalCode/index.js +0 -35
  707. package/cjs/inputs/Input/__stories__/TextWithCharacterLimit/index.js +0 -39
  708. package/cjs/inputs/Input/index.mdx +0 -95
  709. package/cjs/inputs/Label/Label.stories/index.js +0 -26
  710. package/cjs/inputs/Label/Label.stories.playwright.json +0 -40
  711. package/cjs/inputs/Label/__stories__/Default/index.js +0 -37
  712. package/cjs/inputs/Label/index.mdx +0 -0
  713. package/cjs/inputs/OtpInput/OtpInput.stories/index.js +0 -26
  714. package/cjs/inputs/OtpInput/__stories__/Default/index.js +0 -39
  715. package/cjs/inputs/OtpInput/index.mdx +0 -23
  716. package/cjs/inputs/Radio/Radio.stories/index.js +0 -50
  717. package/cjs/inputs/Radio/Radio.stories.playwright.json +0 -73
  718. package/cjs/inputs/Radio/__stories__/Conditional/index.js +0 -103
  719. package/cjs/inputs/Radio/__stories__/Default/index.js +0 -55
  720. package/cjs/inputs/Radio/__stories__/WithDivider/index.js +0 -56
  721. package/cjs/inputs/Select/Select.stories/index.js +0 -26
  722. package/cjs/inputs/Select/Select.stories.playwright.json +0 -22
  723. package/cjs/inputs/Select/__stories__/Default/index.js +0 -61
  724. package/cjs/inputs/Select/index.mdx +0 -17
  725. package/cjs/installation.mdx +0 -68
  726. package/cjs/validators/validators.spec/index.js +0 -87
  727. package/create-simple-form.mdx +0 -539
  728. package/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -8
  729. package/inputs/AutoCompleteInput/AutoComplete.stories/package.json +0 -6
  730. package/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -44
  731. package/inputs/AutoCompleteInput/__stories__/Default/package.json +0 -6
  732. package/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -45
  733. package/inputs/AutoCompleteInput/__stories__/Multiple/package.json +0 -6
  734. package/inputs/Checkboxes/Checkboxes.stories/index.js +0 -9
  735. package/inputs/Checkboxes/Checkboxes.stories/package.json +0 -6
  736. package/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -85
  737. package/inputs/Checkboxes/__stories__/Conditional/index.js +0 -93
  738. package/inputs/Checkboxes/__stories__/Conditional/package.json +0 -6
  739. package/inputs/Checkboxes/__stories__/Default/index.js +0 -40
  740. package/inputs/Checkboxes/__stories__/Default/package.json +0 -6
  741. package/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -41
  742. package/inputs/Checkboxes/__stories__/WithDivider/package.json +0 -6
  743. package/inputs/Checkboxes/index.mdx +0 -33
  744. package/inputs/DateInput/DateInput.stories/index.js +0 -7
  745. package/inputs/DateInput/DateInput.stories/package.json +0 -6
  746. package/inputs/DateInput/DateInput.stories.playwright.json +0 -72
  747. package/inputs/DateInput/__stories__/Default/index.js +0 -23
  748. package/inputs/DateInput/index.mdx +0 -23
  749. package/inputs/FileInput/FileInput.stories/index.js +0 -7
  750. package/inputs/FileInput/FileInput.stories/package.json +0 -6
  751. package/inputs/FileInput/FileInput.stories.playwright.json +0 -75
  752. package/inputs/FileInput/__stories__/Default/index.js +0 -20
  753. package/inputs/FileInput/index.mdx +0 -19
  754. package/inputs/ImageInput/ImageInput.stories/index.js +0 -9
  755. package/inputs/ImageInput/ImageInput.stories/package.json +0 -6
  756. package/inputs/ImageInput/ImageInput.stories.playwright.json +0 -77
  757. package/inputs/ImageInput/__stories__/Default/index.js +0 -28
  758. package/inputs/ImageInput/__stories__/Default/package.json +0 -6
  759. package/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -36
  760. package/inputs/ImageInput/__stories__/WithInvalidImageDimension/package.json +0 -6
  761. package/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -33
  762. package/inputs/ImageInput/__stories__/WithInvalidImageSize/package.json +0 -6
  763. package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +0 -3
  764. package/inputs/ImageInput/index.mdx +0 -19
  765. package/inputs/Input/Input.stories/index.js +0 -16
  766. package/inputs/Input/Input.stories/package.json +0 -6
  767. package/inputs/Input/Input.stories.playwright.json +0 -376
  768. package/inputs/Input/__stories__/AFM/index.js +0 -22
  769. package/inputs/Input/__stories__/AFM/package.json +0 -6
  770. package/inputs/Input/__stories__/Boolean/index.js +0 -23
  771. package/inputs/Input/__stories__/Boolean/package.json +0 -6
  772. package/inputs/Input/__stories__/Default/index.js +0 -23
  773. package/inputs/Input/__stories__/Default/package.json +0 -6
  774. package/inputs/Input/__stories__/Default.d.ts +0 -3
  775. package/inputs/Input/__stories__/IBAN/index.js +0 -23
  776. package/inputs/Input/__stories__/IBAN/package.json +0 -6
  777. package/inputs/Input/__stories__/Integer/index.js +0 -31
  778. package/inputs/Input/__stories__/Integer/package.json +0 -6
  779. package/inputs/Input/__stories__/LandlineNumber/index.js +0 -26
  780. package/inputs/Input/__stories__/LandlineNumber/package.json +0 -6
  781. package/inputs/Input/__stories__/MobilePhone/index.js +0 -26
  782. package/inputs/Input/__stories__/MobilePhone/package.json +0 -6
  783. package/inputs/Input/__stories__/PhoneNumber/index.js +0 -25
  784. package/inputs/Input/__stories__/PhoneNumber/package.json +0 -6
  785. package/inputs/Input/__stories__/PostalCode/index.js +0 -25
  786. package/inputs/Input/__stories__/PostalCode/package.json +0 -6
  787. package/inputs/Input/__stories__/TextWithCharacterLimit/index.js +0 -29
  788. package/inputs/Input/__stories__/TextWithCharacterLimit/package.json +0 -6
  789. package/inputs/Input/__stories__/TextWithCharacterLimit.d.ts +0 -3
  790. package/inputs/Input/index.mdx +0 -95
  791. package/inputs/Label/Label.stories/index.js +0 -7
  792. package/inputs/Label/Label.stories/package.json +0 -6
  793. package/inputs/Label/Label.stories.playwright.json +0 -40
  794. package/inputs/Label/__stories__/Default/index.js +0 -27
  795. package/inputs/Label/__stories__/Default/package.json +0 -6
  796. package/inputs/Label/index.mdx +0 -0
  797. package/inputs/OtpInput/OtpInput.stories/index.js +0 -7
  798. package/inputs/OtpInput/OtpInput.stories/package.json +0 -6
  799. package/inputs/OtpInput/__stories__/Default/index.js +0 -29
  800. package/inputs/OtpInput/__stories__/Default/package.json +0 -6
  801. package/inputs/Radio/Radio.stories/index.js +0 -9
  802. package/inputs/Radio/Radio.stories/package.json +0 -6
  803. package/inputs/Radio/Radio.stories.playwright.json +0 -73
  804. package/inputs/Radio/__stories__/Conditional/index.js +0 -93
  805. package/inputs/Radio/__stories__/Conditional/package.json +0 -6
  806. package/inputs/Radio/__stories__/Default/index.js +0 -45
  807. package/inputs/Radio/__stories__/Default/package.json +0 -6
  808. package/inputs/Radio/__stories__/WithDivider/index.js +0 -46
  809. package/inputs/Radio/__stories__/WithDivider/package.json +0 -6
  810. package/inputs/Radio/index.mdx +0 -33
  811. package/inputs/Select/Select.stories/index.js +0 -7
  812. package/inputs/Select/Select.stories/package.json +0 -6
  813. package/inputs/Select/Select.stories.playwright.json +0 -22
  814. package/inputs/Select/__stories__/Default/index.js +0 -51
  815. package/inputs/Select/__stories__/Default/package.json +0 -6
  816. package/installation.mdx +0 -68
  817. package/lazy.d.ts +0 -69
  818. package/registry.d.ts +0 -64
  819. package/src/Field/index.mdx +0 -6
  820. package/src/Field/utils.ts +0 -191
  821. package/src/FieldArray/FieldArray.stories.playwright.json +0 -353
  822. package/src/FormBuilder/FormBuilder.mdx +0 -256
  823. package/src/FormBuilder/FormBuilder.stories.playwright.json +0 -52
  824. package/src/FormBuilder/FormBuilder.tsx +0 -166
  825. package/src/MultiplicityField/MultiplicityField.mdx +0 -590
  826. package/src/MultiplicityField/MultiplicityField.stories.playwright.json +0 -1370
  827. package/src/index.mdx +0 -51
  828. package/src/inputs/AutoCompleteInput/index.mdx +0 -29
  829. package/src/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -85
  830. package/src/inputs/DateInput/DateInput.stories.playwright.json +0 -72
  831. package/src/inputs/FileInput/FileInput.stories.playwright.json +0 -75
  832. package/src/inputs/ImageInput/ImageInput.stories.playwright.json +0 -77
  833. package/src/inputs/ImageInput/index.mdx +0 -19
  834. package/src/inputs/Input/Input.stories.playwright.json +0 -376
  835. package/src/inputs/Input/index.mdx +0 -95
  836. package/src/inputs/Label/Label.stories.playwright.json +0 -40
  837. package/src/inputs/Label/index.mdx +0 -0
  838. package/src/inputs/OtpInput/index.mdx +0 -23
  839. package/src/inputs/Radio/Radio.stories.playwright.json +0 -73
  840. package/src/inputs/Radio/index.mdx +0 -33
  841. package/src/inputs/Select/Select.stories.playwright.json +0 -22
  842. package/src/inputs/Select/index.mdx +0 -17
  843. package/validators/validators.spec/index.js +0 -85
package/types.d.ts CHANGED
@@ -1,40 +1,9 @@
1
- /// <reference types="react" />
2
- import { UseFormReturn, UseFormProps } from 'react-hook-form';
3
- import { FieldComponentRegistry } from '@digigov/form/Field/types';
1
+ import { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';
2
+ import { FieldComponentRegistry, FieldLabelProps, FieldSpec, FormData } from '@digigov/form/Field/types';
4
3
  import { ValidatorSchema } from '@digigov/form/validators/types';
5
- import { GridProps } from '@digigov/ui/layouts/Grid';
6
- export type FieldError = {
4
+ export * from '@digigov/form/Field/types';
5
+ export interface FieldError {
7
6
  message: string;
8
- };
9
- export type FieldLabelProps = {
10
- primary?: string;
11
- secondary?: string;
12
- };
13
- export interface FieldCondition {
14
- is: string | string[] | number | number[] | boolean | boolean[];
15
- then?: Partial<FieldSpec>;
16
- else?: Partial<FieldSpec>;
17
- }
18
- export interface FieldSpec {
19
- key: string;
20
- type?: 'int' | 'string' | 'text' | 'boolean' | 'email' | 'uuid4' | 'choice:multiple' | 'choice:single' | 'mobile_phone' | 'date' | 'otp' | 'afm' | 'iban' | 'file' | 'image' | 'postal_code' | 'phone_number' | 'array' | 'object';
21
- component?: any;
22
- maxLength?: number;
23
- condition?: Record<string, FieldCondition>;
24
- controlled?: boolean;
25
- label?: FieldLabelProps;
26
- extra?: {
27
- [key: string]: any;
28
- };
29
- editable?: boolean;
30
- required?: boolean;
31
- enabled?: boolean;
32
- layout?: Record<string, GridProps['xs'] | GridProps['sm'] | GridProps['md'] | GridProps['lg'] | GridProps['xl']>;
33
- validators?: ValidatorSchema[];
34
- wrapper?: 'label' | 'fieldset';
35
- maxWidth?: string;
36
- maxHeight?: string;
37
- width?: string;
38
7
  }
39
8
  export interface FieldsetSpec {
40
9
  key: string;
@@ -42,7 +11,6 @@ export interface FieldsetSpec {
42
11
  label?: FieldLabelProps;
43
12
  body?: React.ReactNode;
44
13
  }
45
- export type FormData = UseFormProps['defaultValues'];
46
14
  export interface FormContextProps {
47
15
  fieldsetsMap?: Record<string, FieldsetSpec>;
48
16
  fieldsMap: Record<string, FieldSpec>;
@@ -57,9 +25,11 @@ export interface FormContextProps {
57
25
  unregister: UseFormReturn['unregister'];
58
26
  formState: UseFormReturn['formState'];
59
27
  reset: UseFormReturn['reset'];
28
+ resetField: UseFormReturn['resetField'];
60
29
  registerField: (field: FieldSpec) => void;
61
30
  errors: UseFormReturn['formState']['errors'];
62
31
  componentRegistry?: FieldComponentRegistry;
32
+ submit: () => Promise<void>;
63
33
  }
64
34
  export interface FormBuilderProps {
65
35
  fields?: FieldSpec[];
@@ -75,6 +45,8 @@ export interface FormBuilderProps {
75
45
  validatorRegistry?: Record<string, ValidatorSchema[]>;
76
46
  componentRegistry?: FieldComponentRegistry;
77
47
  grid?: boolean;
48
+ controlledFieldsOnly?: boolean;
49
+ errors?: ErrorOption;
78
50
  }
79
51
  export interface FormBaseProps extends Omit<FormBuilderProps, 'fields' | 'fieldsets' | 'auto'> {
80
52
  fieldsetsMap?: Record<string, FieldsetSpec>;
package/types.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/types.tsx"],
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
+ "mappings": "AAQA,cAAc;",
6
+ "names": []
7
+ }
package/utils/index.js CHANGED
@@ -1,80 +1,74 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- import _extends from "@babel/runtime/helpers/extends";
3
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
4
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
5
- import { validateFieldsNatively } from '@hookform/resolvers';
6
- import { appendErrors } from 'react-hook-form';
7
- /**
8
- * Why `path!` ? because it could be `undefined` in some case
9
- * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string
10
- */
11
- var parseErrorSchema = function parseErrorSchema(error, validateAllFieldCriteria) {
12
- return (error.inner || []).reduce(function (previous, error) {
13
- var _error$path;
14
- error.path = (_error$path = error.path) === null || _error$path === void 0 ? void 0 : _error$path.replace(/\[([0-9]+)\]/g, '.$1');
15
- if (!previous[error.path]) {
16
- previous[error.path] = {
17
- message: error.message,
18
- type: error.type
19
- };
20
- }
21
- if (validateAllFieldCriteria) {
22
- var types = previous[error.path].types;
23
- var messages = types && types[error.type];
24
- previous[error.path] = appendErrors(error.path, validateAllFieldCriteria, previous, error.type, messages ? [].concat(messages, error.message) : error.message);
1
+ import { validateFieldsNatively } from "@hookform/resolvers";
2
+ import { appendErrors } from "react-hook-form";
3
+ const parseErrorSchema = (error, validateAllFieldCriteria) => {
4
+ return (error.inner || []).reduce(
5
+ (previous, error2) => {
6
+ error2.path = error2.path?.replace(/\[([0-9]+)\]/g, ".$1");
7
+ if (!previous[error2.path]) {
8
+ previous[error2.path] = { message: error2.message, type: error2.type };
9
+ }
10
+ if (validateAllFieldCriteria) {
11
+ const types = previous[error2.path].types;
12
+ const messages = types && types[error2.type];
13
+ previous[error2.path] = appendErrors(
14
+ error2.path,
15
+ validateAllFieldCriteria,
16
+ previous,
17
+ error2.type,
18
+ messages ? [].concat(messages, error2.message) : error2.message
19
+ );
20
+ }
21
+ return previous;
22
+ },
23
+ {}
24
+ );
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];
25
36
  }
26
- return previous;
37
+ return acc;
27
38
  }, {});
28
- };
29
- export var yupResolver = function yupResolver(schema) {
30
- var schemaOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
31
- var resolverOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
32
- return /*#__PURE__*/function () {
33
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(values, context, options) {
34
- var result, parsed;
35
- return _regeneratorRuntime().wrap(function _callee$(_context) {
36
- while (1) switch (_context.prev = _context.next) {
37
- case 0:
38
- _context.prev = 0;
39
- if (schemaOptions.context && process.env.NODE_ENV === 'development') {
40
- // eslint-disable-next-line no-console
41
- console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead");
42
- }
43
- _context.next = 4;
44
- return schema[resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'](values, _extends({
45
- abortEarly: false
46
- }, schemaOptions, {
47
- context: context
48
- }));
49
- case 4:
50
- result = _context.sent;
51
- options.shouldUseNativeValidation && validateFieldsNatively({}, options);
52
- return _context.abrupt("return", {
53
- values: resolverOptions.rawValues ? values : result,
54
- errors: {}
55
- });
56
- case 9:
57
- _context.prev = 9;
58
- _context.t0 = _context["catch"](0);
59
- if (_context.t0.inner) {
60
- _context.next = 13;
61
- break;
62
- }
63
- throw _context.t0;
64
- case 13:
65
- parsed = parseErrorSchema(_context.t0, !options.shouldUseNativeValidation && options.criteriaMode === 'all');
66
- return _context.abrupt("return", {
67
- values: {},
68
- errors: parsed
69
- });
70
- case 15:
71
- case "end":
72
- return _context.stop();
73
- }
74
- }, _callee, null, [[0, 9]]);
75
- }));
76
- return function (_x, _x2, _x3) {
77
- return _ref.apply(this, arguments);
39
+ }
40
+ const yupResolver = (schema, schemaOptions = {}, resolverOptions = {}) => async (values, context, options) => {
41
+ try {
42
+ if (schemaOptions.context && process.env.NODE_ENV === "development") {
43
+ console.warn(
44
+ "You should not used the yup options context. Please, use the 'useForm' context object instead"
45
+ );
46
+ }
47
+ const result = await schema[resolverOptions.mode === "sync" ? "validateSync" : "validate"](
48
+ flattenObject(values),
49
+ Object.assign({ abortEarly: false }, schemaOptions, { context })
50
+ );
51
+ if (options.shouldUseNativeValidation)
52
+ validateFieldsNatively({}, options);
53
+ return {
54
+ values: resolverOptions.rawValues ? values : result,
55
+ errors: {}
78
56
  };
79
- }();
80
- };
57
+ } catch (e) {
58
+ if (!e.inner) {
59
+ throw e;
60
+ }
61
+ return {
62
+ values: {},
63
+ errors: parseErrorSchema(
64
+ e,
65
+ !options.shouldUseNativeValidation && options.criteriaMode === "all"
66
+ ),
67
+ options
68
+ };
69
+ }
70
+ };
71
+ export {
72
+ yupResolver
73
+ };
74
+ //# sourceMappingURL=utils.js.map
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 ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 // 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
+ "names": ["error"]
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;
@@ -1,182 +1,150 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- import { useMemo } from 'react';
3
- import dayjs from 'dayjs';
4
- import customParseFormat from 'dayjs/plugin/customParseFormat';
5
- import * as yup from 'yup';
6
- import { getYupObjectShape, AFM_VALIDATOR, FILE_MAX_SIZE_VALIDATOR, IBAN_VALIDATOR, OTP_VALIDATOR, MOBILE_PHONE_VALIDATOR, PHONE_NUMBER_VALIDATOR, TEXT_LIMIT_VALIDATOR, POSTALCODE_VALIDATOR, UUID4_VALIDATOR, IMAGE_DIMENSION_VALIDATOR } from '@digigov/form/validators/utils';
7
- import { INT_VALIDATOR } from '@digigov/form/validators/utils/int';
8
- import { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';
9
- dayjs.extend(customParseFormat);
10
- var VALID_DATE_FORMATS = ['DD/MM/YYYY'];
11
- var DATE_CACHE = {};
12
- var getDate = function getDate(v) {
13
- return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
14
- };
15
- export var getYUPTypeMap = function getYUPTypeMap() {
16
- var yupTypeMap = {
17
- file: function file(field) {
18
- return yup.mixed().transform(function (value) {
19
- if (!value.length) {
1
+ import { useMemo } from "react";
2
+ import * as yup from "yup";
3
+ import {
4
+ getYupObjectShape,
5
+ AFM_VALIDATOR,
6
+ AMKA_VALIDATOR,
7
+ FILE_MAX_SIZE_VALIDATOR,
8
+ IBAN_VALIDATOR,
9
+ OTP_VALIDATOR,
10
+ MOBILE_PHONE_VALIDATOR,
11
+ PHONE_NUMBER_VALIDATOR,
12
+ TEXT_LIMIT_VALIDATOR,
13
+ POSTALCODE_VALIDATOR,
14
+ UUID4_VALIDATOR,
15
+ IMAGE_DIMENSION_VALIDATOR,
16
+ DATE_VALIDATOR,
17
+ LATER_THAN_VALIDATOR,
18
+ EARLIER_THAN_VALIDATOR,
19
+ DATETIME_VALIDATOR,
20
+ LATER_THAN_DATETIME_VALIDATOR,
21
+ EARLIER_THAN_DATETIME_VALIDATOR
22
+ } from "@digigov/form/validators/utils";
23
+ import { INT_VALIDATOR } from "@digigov/form/validators/utils/int";
24
+ import { NUMBER_VALIDATOR } from "@digigov/form/validators/utils/number";
25
+ const getYUPTypeMap = (validatorRegistry) => {
26
+ const yupTypeMap = {
27
+ file: (field) => {
28
+ return yup.mixed().transform((value) => {
29
+ if (!value || value.length === 0) {
20
30
  return null;
21
31
  }
22
32
  return value;
23
33
  }).nullable().test(FILE_MAX_SIZE_VALIDATOR(field));
24
34
  },
25
- string: yup.string,
26
- "boolean": yup["boolean"],
27
- object: function object(field) {
35
+ string: (field) => {
36
+ if (field.trim) {
37
+ return yup.string().trim();
38
+ } else {
39
+ return yup.string();
40
+ }
41
+ },
42
+ boolean: () => {
43
+ return yup.boolean().nullable().transform((value) => {
44
+ if (value === "" || typeof value === "string") return null;
45
+ if (typeof value === "boolean") return value;
46
+ if (value === 0 || value === 1) return Boolean(value);
47
+ return value;
48
+ });
49
+ },
50
+ object: (field) => {
28
51
  return getYupObjectShape(field.extra.fields, yupTypeMap);
29
52
  },
30
- array: function array(field) {
31
- if (_typeof(field.extra.of) === 'object') {
32
- // else if the field is an object then it is a scalar type
33
- // eg. number, string etc.
34
- var arrayValidator = yup.array().of(yupTypeMap[field.extra.of.type](field.extra.of)).required(field.required);
35
- if (field.extra.length) arrayValidator = arrayValidator.length(field.extra.length, {
36
- key: 'form.error.array.length',
37
- context: {
38
- length: field.extra.length
39
- }
40
- });
41
- if (field.extra.min) arrayValidator = arrayValidator.min(field.extra.min, {
42
- key: 'form.error.array.min',
43
- context: {
44
- min: field.extra.min
45
- }
46
- });
47
- if (field.extra.max) arrayValidator = arrayValidator.max(field.extra.max, {
48
- key: 'form.error.array.max',
49
- context: {
50
- max: field.extra.max
51
- }
52
- });
53
+ array: (field) => {
54
+ if (typeof field.extra.of === "object") {
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));
59
+ if (field.extra.length)
60
+ arrayValidator = arrayValidator.length(field.extra.length, {
61
+ key: "form.error.array.length",
62
+ context: {
63
+ length: field.extra.length
64
+ }
65
+ });
66
+ if (field.extra.min)
67
+ arrayValidator = arrayValidator.min(field.extra.min, {
68
+ key: "form.error.array.min",
69
+ context: {
70
+ min: field.extra.min
71
+ }
72
+ });
73
+ if (field.extra.max)
74
+ arrayValidator = arrayValidator.max(field.extra.max, {
75
+ key: "form.error.array.max",
76
+ context: {
77
+ max: field.extra.max
78
+ }
79
+ });
53
80
  return arrayValidator;
54
- } else if (typeof field.extra.of === 'string') {
81
+ } else if (typeof field.extra.of === "string") {
55
82
  return yup.array().of(yupTypeMap[field.extra.of]());
56
83
  } else {
57
- // in any other case it will be string
58
84
  return yup.array().of(yup.string());
59
85
  }
60
86
  },
61
- "int": function int() {
62
- return yup.mixed().transform(function (_, val) {
63
- return val !== '' ? Number(val) : null;
64
- }).test(NUMBER_VALIDATOR()).test(INT_VALIDATOR());
65
- },
66
- email: function email() {
67
- return yup.string().email('form.error.email');
68
- },
69
- afm: function afm() {
70
- return yup.string().test(AFM_VALIDATOR);
71
- },
72
- uuid4: function uuid4() {
73
- return yup.string().test(UUID4_VALIDATOR);
74
- },
75
- iban: function iban(field) {
76
- return yup.string().test(IBAN_VALIDATOR(field));
77
- },
78
- otp: function otp(field) {
79
- return yup.string().test(OTP_VALIDATOR(field));
80
- },
81
- text: function text(field) {
82
- var _field$extra, _field$extra$limit, _field$extra2, _field$extra2$limit;
83
- if (field !== null && field !== void 0 && (_field$extra = field.extra) !== null && _field$extra !== void 0 && (_field$extra$limit = _field$extra.limit) !== null && _field$extra$limit !== void 0 && _field$extra$limit.max || !!(field !== null && field !== void 0 && (_field$extra2 = field.extra) !== null && _field$extra2 !== void 0 && (_field$extra2$limit = _field$extra2.limit) !== null && _field$extra2$limit !== void 0 && _field$extra2$limit.min)) {
84
- return yup.string().test(TEXT_LIMIT_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)),
95
+ text: (field) => {
96
+ if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {
97
+ return field.trim ? yup.string().trim().test(TEXT_LIMIT_VALIDATOR(field)) : yup.string().test(TEXT_LIMIT_VALIDATOR(field));
85
98
  } else {
86
- return yup.string();
99
+ return field.trim ? yup.string().trim() : yup.string();
87
100
  }
88
101
  },
89
- image: function image(field) {
90
- return yup.mixed().transform(function (value) {
102
+ image: (field) => {
103
+ return yup.mixed().transform((value) => {
91
104
  if (!value.length || value.length === 0) {
92
105
  return null;
93
106
  }
94
107
  return value;
95
108
  }).nullable().test(FILE_MAX_SIZE_VALIDATOR(field)).test(IMAGE_DIMENSION_VALIDATOR(field));
96
109
  },
97
- postal_code: function postal_code(field) {
98
- return yup.string().test(POSTALCODE_VALIDATOR(field));
99
- },
100
- mobile_phone: function mobile_phone() {
101
- return yup.string().test(MOBILE_PHONE_VALIDATOR);
102
- },
103
- phone_number: function phone_number(field) {
104
- return yup.string().test(PHONE_NUMBER_VALIDATOR(field));
105
- },
106
- 'choice:multiple': function choiceMultiple() {
107
- return yup.array().of(yup.string()).nullable();
108
- },
109
- 'choice:single': function choiceSingle() {
110
- return yup.string().nullable();
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)),
113
+ "choice:multiple": () => yup.array().of(yup.string()).nullable(),
114
+ "choice:single": () => yup.string().nullable(),
115
+ date: (field) => {
116
+ let schema = yup.string().nullable();
117
+ if (field?.extra?.min) {
118
+ schema = schema.test(LATER_THAN_VALIDATOR(field));
119
+ }
120
+ if (field?.extra?.max) {
121
+ schema = schema.test(EARLIER_THAN_VALIDATOR(field));
122
+ } else {
123
+ schema = schema.test(DATE_VALIDATOR);
124
+ }
125
+ return schema;
111
126
  },
112
- date: function date(field) {
113
- var simpleDate = yup.string().nullable(true).test('date', 'form.error.date.invalid', function (value) {
114
- if (!value) return true;
115
- var date = getDate(value);
116
- return date.isValid();
117
- });
118
- var params = field.extra || {};
119
- if (params.max) {
120
- var maxDate;
121
- if (params.max === 'now') {
122
- var today = new Date();
123
- maxDate = new Date(today);
124
- } else {
125
- maxDate = getDate(params.max).toDate();
126
- }
127
- var maxNextDate = new Date(maxDate);
128
- maxNextDate.setDate(maxDate.getDate() + 1);
129
- simpleDate = simpleDate.test({
130
- name: 'earlier-than',
131
- message: {
132
- key: 'form.error.date.earlier_than',
133
- context: {
134
- maxDate: maxNextDate.toLocaleDateString()
135
- }
136
- },
137
- test: function test(value) {
138
- if (!value) return true;
139
- var date = getDate(value);
140
- var isValid = +date.toDate() < +maxDate;
141
- return isValid;
142
- }
143
- });
127
+ datetime: (field) => {
128
+ if (field?.extra?.min) {
129
+ return yup.string().test(LATER_THAN_DATETIME_VALIDATOR(field));
144
130
  }
145
- if (params.min) {
146
- var minDate;
147
- if (params.min === 'now') {
148
- var _today = new Date();
149
- minDate = new Date(_today);
150
- } else {
151
- minDate = getDate(params.min).toDate();
152
- }
153
- var minPreviousDate = new Date(minDate);
154
- minPreviousDate.setDate(minDate.getDate() - 1);
155
- simpleDate = simpleDate.test({
156
- name: 'later-than',
157
- message: {
158
- key: 'form.error.date.later_than',
159
- context: {
160
- minDate: minPreviousDate.toLocaleDateString()
161
- }
162
- },
163
- test: function test(value) {
164
- if (!value) return true;
165
- var date = getDate(value);
166
- var isValid = +date.toDate() > +minDate;
167
- return isValid;
168
- }
169
- });
131
+ if (field?.extra?.max) {
132
+ return yup.string().test(EARLIER_THAN_DATETIME_VALIDATOR(field));
170
133
  }
171
- return simpleDate;
172
- }
134
+ return yup.string().test(DATETIME_VALIDATOR);
135
+ },
136
+ ...validatorRegistry
173
137
  };
174
138
  return yupTypeMap;
175
139
  };
176
- // Create a yup validation schema from given fields input
177
- export function useValidationSchema(fields, validatorRegistry) {
178
- return useMemo(function () {
179
- var yupTypeMap = getYUPTypeMap();
140
+ function useValidationSchema(fields, validatorRegistry) {
141
+ return useMemo(() => {
142
+ const yupTypeMap = getYUPTypeMap(validatorRegistry);
180
143
  return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
181
- }, []);
182
- }
144
+ }, [fields, validatorRegistry]);
145
+ }
146
+ export {
147
+ getYUPTypeMap,
148
+ useValidationSchema
149
+ };
150
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/validators/index.ts"],
4
+ "sourcesContent": ["import { MutableRefObject, useMemo } from 'react';\nimport * as yup from 'yup';\nimport { AnyObjectSchema, StringSchema } from 'yup';\nimport { RequiredArraySchema } from 'yup/lib/array';\nimport Lazy from 'yup/lib/Lazy';\nimport { MixedSchema } from 'yup/lib/mixed';\nimport { TypeOfShape, AssertsShape } from 'yup/lib/object';\nimport { AnyObject } from 'yup/lib/types';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\nimport {\n getYupObjectShape,\n AFM_VALIDATOR,\n AMKA_VALIDATOR,\n FILE_MAX_SIZE_VALIDATOR,\n IBAN_VALIDATOR,\n OTP_VALIDATOR,\n MOBILE_PHONE_VALIDATOR,\n PHONE_NUMBER_VALIDATOR,\n TEXT_LIMIT_VALIDATOR,\n POSTALCODE_VALIDATOR,\n UUID4_VALIDATOR,\n IMAGE_DIMENSION_VALIDATOR,\n DATE_VALIDATOR,\n LATER_THAN_VALIDATOR,\n EARLIER_THAN_VALIDATOR,\n DATETIME_VALIDATOR,\n LATER_THAN_DATETIME_VALIDATOR,\n EARLIER_THAN_DATETIME_VALIDATOR,\n} from '@digigov/form/validators/utils';\nimport { INT_VALIDATOR } from '@digigov/form/validators/utils/int';\nimport { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';\n\nexport const getYUPTypeMap = (\n validatorRegistry?: Record<string, any>\n): Record<string, any> => {\n const yupTypeMap = {\n file: (field): MixedSchema => {\n return yup\n .mixed()\n .transform((value) => {\n if (!value || value.length === 0) {\n return null;\n }\n return value;\n })\n .nullable()\n .test(FILE_MAX_SIZE_VALIDATOR(field));\n },\n string: (field): yup.StringSchema => {\n if (field.trim) {\n return yup.string().trim();\n } else {\n return yup.string();\n }\n },\n boolean: (): yup.BooleanSchema<\n boolean | null | undefined,\n AnyObject,\n boolean | null | undefined\n > => {\n return yup\n .boolean()\n .nullable()\n .transform((value) => {\n if (value === '' || typeof value === 'string') return null;\n if (typeof value === 'boolean') return value;\n if (value === 0 || value === 1) return Boolean(value);\n return value;\n });\n },\n object: (\n field\n ):\n | yup.ObjectSchema<any, AnyObject, TypeOfShape<any>, AssertsShape<any>>\n | Lazy<any, unknown> => {\n return getYupObjectShape(field.extra.fields, yupTypeMap);\n },\n array: (\n field\n ):\n | yup.ArraySchema<any, AnyObject, any[] | undefined>\n | RequiredArraySchema<any, AnyObject, any[] | undefined> => {\n if (typeof field.extra.of === 'object') {\n // else if the field is an object then it is a scalar type\n // eg. number, string etc.\n if (field.required) {\n field.extra.min = 1;\n }\n let arrayValidator = yup\n .array()\n .nullable()\n .of(yupTypeMap[field.extra.of.type](field.extra.of));\n if (field.extra.length)\n arrayValidator = arrayValidator.length(field.extra.length, {\n key: 'form.error.array.length',\n context: {\n length: field.extra.length,\n },\n });\n if (field.extra.min)\n arrayValidator = arrayValidator.min(field.extra.min, {\n key: 'form.error.array.min',\n context: {\n min: field.extra.min,\n },\n });\n if (field.extra.max)\n arrayValidator = arrayValidator.max(field.extra.max, {\n key: 'form.error.array.max',\n context: {\n max: field.extra.max,\n },\n });\n return arrayValidator;\n } else if (typeof field.extra.of === 'string') {\n return yup.array().of(yupTypeMap[field.extra.of]());\n } else {\n // in any other case it will be string\n return yup.array().of(yup.string());\n }\n },\n number: (): MixedSchema =>\n yup\n .mixed()\n .transform((_, val) => (val !== '' ? Number(val) : undefined))\n .test(NUMBER_VALIDATOR()),\n int: (): MixedSchema =>\n yup\n .mixed()\n .transform((_, val) => (val !== '' ? Number(val) : undefined))\n .test(NUMBER_VALIDATOR())\n .test(INT_VALIDATOR()),\n email: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().email('form.error.email')\n : yup.string().email('form.error.email'),\n afm: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(AFM_VALIDATOR)\n : yup.string().test(AFM_VALIDATOR),\n amka: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(AMKA_VALIDATOR)\n : yup.string().test(AMKA_VALIDATOR),\n uuid4: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(UUID4_VALIDATOR)\n : yup.string().test(UUID4_VALIDATOR),\n iban: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(IBAN_VALIDATOR(field))\n : yup.string().trim().test(IBAN_VALIDATOR(field)),\n otp: (field): yup.StringSchema =>\n yup.string().trim().test(OTP_VALIDATOR(field)),\n text: (field): yup.StringSchema => {\n if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {\n return field.trim\n ? yup.string().trim().test(TEXT_LIMIT_VALIDATOR(field))\n : yup.string().test(TEXT_LIMIT_VALIDATOR(field));\n } else {\n return field.trim ? yup.string().trim() : yup.string();\n }\n },\n image: (field): MixedSchema => {\n return yup\n .mixed()\n .transform((value) => {\n if (!value.length || value.length === 0) {\n return null;\n }\n return value;\n })\n .nullable()\n .test(FILE_MAX_SIZE_VALIDATOR(field))\n .test(IMAGE_DIMENSION_VALIDATOR(field));\n },\n postal_code: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(POSTALCODE_VALIDATOR(field))\n : yup.string().test(POSTALCODE_VALIDATOR(field)),\n mobile_phone: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(MOBILE_PHONE_VALIDATOR)\n : yup.string().test(MOBILE_PHONE_VALIDATOR),\n phone_number: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field))\n : yup.string().test(PHONE_NUMBER_VALIDATOR(field)),\n 'choice:multiple': (): yup.ArraySchema<\n yup.StringSchema<string | undefined, AnyObject, string | undefined>,\n AnyObject,\n (string | undefined)[] | null | undefined,\n (string | undefined)[] | null | undefined\n > => yup.array().of(yup.string()).nullable(),\n 'choice:single': (): StringSchema<\n string | null | undefined,\n AnyObject,\n string | null | undefined\n > => yup.string().nullable(),\n date: (\n field\n ): yup.StringSchema<\n string | null | undefined,\n AnyObject,\n string | null | undefined\n > => {\n let schema = yup.string().nullable();\n if (field?.extra?.min) {\n schema = schema.test(LATER_THAN_VALIDATOR(field));\n }\n if (field?.extra?.max) {\n schema = schema.test(EARLIER_THAN_VALIDATOR(field));\n } else {\n schema = schema.test(DATE_VALIDATOR);\n }\n return schema;\n },\n datetime: (field): yup.StringSchema => {\n if (field?.extra?.min) {\n return yup.string().test(LATER_THAN_DATETIME_VALIDATOR(field));\n }\n if (field?.extra?.max) {\n return yup.string().test(EARLIER_THAN_DATETIME_VALIDATOR(field));\n }\n return yup.string().test(DATETIME_VALIDATOR);\n },\n ...validatorRegistry,\n };\n return yupTypeMap;\n};\n\nexport interface MutableRefObjectProps {}\n// Create a yup validation schema from given fields input\nexport function useValidationSchema(\n fields: FieldSpec[] | MutableRefObject<MutableRefObjectProps>,\n validatorRegistry?: Record<string, ValidatorSchema[]>\n): Lazy<any, unknown> | AnyObjectSchema | void {\n return useMemo(() => {\n const yupTypeMap = getYUPTypeMap(validatorRegistry);\n return getYupObjectShape(fields, yupTypeMap, validatorRegistry);\n }, [fields, validatorRegistry]);\n}\n"],
5
+ "mappings": "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",
6
+ "names": []
7
+ }