@digigov/form 2.0.0-750aec28 → 2.0.0-7d765d3c

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 (548) hide show
  1. package/Field/ErrorGroup.d.ts +3 -3
  2. package/Field/ErrorGroup.js.map +1 -1
  3. package/Field/FieldBase/index.js +7 -4
  4. package/Field/FieldBase.d.ts +1 -1
  5. package/Field/FieldBase.js.map +2 -2
  6. package/Field/FieldBaseContainer/index.js +37 -18
  7. package/Field/FieldBaseContainer.d.ts +2 -2
  8. package/Field/FieldBaseContainer.js.map +2 -2
  9. package/Field/FieldConditional/index.js +4 -0
  10. package/Field/FieldConditional.d.ts +1 -1
  11. package/Field/FieldConditional.js.map +2 -2
  12. package/Field/index.d.ts +1 -1
  13. package/Field/index.js +25 -29
  14. package/Field/index.js.map +2 -2
  15. package/Field/types.d.ts +19 -11
  16. package/Field/utils/evaluateFieldWithConditions.d.ts +2 -2
  17. package/Field/utils/evaluateFieldWithConditions.js.map +2 -2
  18. package/Field/utils/resolveField/index.js +35 -0
  19. package/Field/utils/{calculateField → resolveField}/package.json +1 -1
  20. package/Field/utils/resolveField.d.ts +3 -0
  21. package/Field/utils/resolveField.js.map +7 -0
  22. package/Field/utils/useField/index.js +12 -3
  23. package/Field/utils/useField.d.ts +1 -1
  24. package/Field/utils/useField.js.map +2 -2
  25. package/FieldArray/BaseFieldArray/index.js +76 -0
  26. package/{inputs/inputsScenarios → FieldArray/BaseFieldArray}/package.json +1 -1
  27. package/FieldArray/BaseFieldArray.d.ts +5 -0
  28. package/FieldArray/BaseFieldArray.js.map +7 -0
  29. package/FieldArray/FormDialog/ArrayItemDisplay/index.js +97 -0
  30. package/FieldArray/FormDialog/ArrayItemDisplay/package.json +6 -0
  31. package/FieldArray/FormDialog/ArrayItemDisplay.d.ts +22 -0
  32. package/FieldArray/FormDialog/ArrayItemDisplay.js.map +7 -0
  33. package/FieldArray/FormDialog/ArrayItemHeader/index.js +11 -0
  34. package/FieldArray/FormDialog/ArrayItemHeader/package.json +6 -0
  35. package/FieldArray/FormDialog/ArrayItemHeader.d.ts +5 -0
  36. package/FieldArray/FormDialog/ArrayItemHeader.js.map +7 -0
  37. package/FieldArray/FormDialog/ArrayItemModal/index.js +158 -0
  38. package/{inputs/Input/inputsInputScenarios → FieldArray/FormDialog/ArrayItemModal}/package.json +1 -1
  39. package/FieldArray/FormDialog/ArrayItemModal.d.ts +26 -0
  40. package/FieldArray/FormDialog/ArrayItemModal.js.map +7 -0
  41. package/FieldArray/FormDialog/index.d.ts +19 -0
  42. package/FieldArray/FormDialog/index.js +152 -258
  43. package/FieldArray/FormDialog/index.js.map +7 -0
  44. package/FieldArray/__stories__/Default.d.ts +1 -1
  45. package/FieldArray/__stories__/WithExactLength.d.ts +1 -1
  46. package/FieldArray/__stories__/WithModal.d.ts +1 -1
  47. package/FieldArray/index.d.ts +5 -2
  48. package/FieldArray/index.js +36 -57
  49. package/FieldArray/index.js.map +2 -2
  50. package/FieldObject/index.d.ts +7 -4
  51. package/FieldObject/index.js +29 -25
  52. package/FieldObject/index.js.map +2 -2
  53. package/Fieldset/FieldsetWithContext.js.map +1 -1
  54. package/Fieldset/index.d.ts +1 -1
  55. package/Fieldset/index.js.map +1 -1
  56. package/Fieldset/types.d.ts +2 -2
  57. package/FormBuilder/FormBuilder.stories.d.ts +2 -0
  58. package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +1 -1
  59. package/FormBuilder/__stories__/Default.d.ts +1 -1
  60. package/FormBuilder/__stories__/ErrorGrouping.d.ts +1 -1
  61. package/FormBuilder/index.d.ts +2 -2
  62. package/FormBuilder/index.js +163 -134
  63. package/FormBuilder/index.js.map +2 -2
  64. package/FormContext/index.js +6 -2
  65. package/FormContext.d.ts +3 -2
  66. package/FormContext.js.map +2 -2
  67. package/MultiplicityField/MultiplicityField.stories.d.ts +2 -0
  68. package/MultiplicityField/__stories__/Default.d.ts +1 -1
  69. package/MultiplicityField/__stories__/PreviewDisplay.d.ts +1 -1
  70. package/MultiplicityField/__stories__/WithExactLength.d.ts +1 -1
  71. package/MultiplicityField/__stories__/WithMaxLength.d.ts +1 -1
  72. package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +1 -1
  73. package/MultiplicityField/__stories__/WithMinLength.d.ts +1 -1
  74. package/MultiplicityField/add-objects/index.js +12 -19
  75. package/MultiplicityField/add-objects.d.ts +1 -1
  76. package/MultiplicityField/add-objects.js.map +2 -2
  77. package/MultiplicityField/index.d.ts +2 -2
  78. package/MultiplicityField/index.js +4 -1
  79. package/MultiplicityField/index.js.map +2 -2
  80. package/MultiplicityField/types.d.ts +3 -2
  81. package/Questions/Questions.d.ts +1 -1
  82. package/Questions/Questions.js.map +1 -1
  83. package/Questions/Questions.stories.d.ts +2 -0
  84. package/Questions/QuestionsContext.d.ts +1 -1
  85. package/Questions/QuestionsContext.js.map +1 -1
  86. package/Questions/Step/Step.d.ts +1 -1
  87. package/Questions/Step/Step.js.map +1 -1
  88. package/Questions/Step/StepArrayReview.d.ts +1 -1
  89. package/Questions/Step/StepArrayReview.js.map +1 -1
  90. package/Questions/Step/StepContext.d.ts +1 -1
  91. package/Questions/Step/StepContext.js.map +1 -1
  92. package/Questions/Step/StepDescription.d.ts +1 -1
  93. package/Questions/Step/StepDescription.js.map +2 -2
  94. package/Questions/Step/StepForm.d.ts +2 -2
  95. package/Questions/Step/StepForm.js.map +1 -1
  96. package/Questions/Step/StepQuote.d.ts +1 -1
  97. package/Questions/Step/StepQuote.js.map +2 -2
  98. package/Questions/Step/StepTitle.d.ts +1 -1
  99. package/Questions/Step/StepTitle.js.map +2 -2
  100. package/Questions/Step/getAddMoreFields.d.ts +2 -2
  101. package/Questions/Step/getAddMoreFields.js.map +1 -1
  102. package/Questions/Step/types.d.ts +1 -1
  103. package/Questions/__stories__/Default.d.ts +1 -1
  104. package/Questions/getNextStep.d.ts +1 -1
  105. package/Questions/getNextStep.js.map +1 -1
  106. package/Questions/types.d.ts +1 -1
  107. package/cjs/Field/ErrorGroup.js.map +1 -1
  108. package/cjs/Field/FieldBase/index.js +7 -4
  109. package/cjs/Field/FieldBase.js.map +2 -2
  110. package/cjs/Field/FieldBaseContainer/index.js +36 -17
  111. package/cjs/Field/FieldBaseContainer.js.map +3 -3
  112. package/cjs/Field/FieldConditional/index.js +4 -0
  113. package/cjs/Field/FieldConditional.js.map +2 -2
  114. package/cjs/Field/index.js +25 -26
  115. package/cjs/Field/index.js.map +2 -2
  116. package/cjs/Field/types.js.map +1 -1
  117. package/cjs/Field/utils/evaluateFieldWithConditions.js.map +2 -2
  118. package/cjs/Field/utils/resolveField/index.js +55 -0
  119. package/cjs/Field/utils/resolveField.js.map +7 -0
  120. package/cjs/Field/utils/useField/index.js +12 -3
  121. package/cjs/Field/utils/useField.js.map +2 -2
  122. package/cjs/FieldArray/BaseFieldArray/index.js +109 -0
  123. package/cjs/FieldArray/BaseFieldArray.js.map +7 -0
  124. package/cjs/FieldArray/FormDialog/ArrayItemDisplay/index.js +130 -0
  125. package/cjs/FieldArray/FormDialog/ArrayItemDisplay.js.map +7 -0
  126. package/cjs/{locales/el → FieldArray/FormDialog/ArrayItemHeader}/index.js +16 -7
  127. package/cjs/FieldArray/FormDialog/ArrayItemHeader.js.map +7 -0
  128. package/cjs/FieldArray/FormDialog/ArrayItemModal/index.js +186 -0
  129. package/cjs/FieldArray/FormDialog/ArrayItemModal.js.map +7 -0
  130. package/cjs/FieldArray/FormDialog/index.js +148 -243
  131. package/cjs/FieldArray/FormDialog/index.js.map +7 -0
  132. package/cjs/FieldArray/index.js +35 -56
  133. package/cjs/FieldArray/index.js.map +3 -3
  134. package/cjs/FieldObject/index.js +29 -22
  135. package/cjs/FieldObject/index.js.map +2 -2
  136. package/cjs/Fieldset/FieldsetWithContext.js.map +1 -1
  137. package/cjs/Fieldset/index.js.map +1 -1
  138. package/cjs/Fieldset/types.js.map +1 -1
  139. package/cjs/FormBuilder/index.js +164 -135
  140. package/cjs/FormBuilder/index.js.map +3 -3
  141. package/cjs/FormContext/index.js +7 -2
  142. package/cjs/FormContext.js.map +2 -2
  143. package/cjs/MultiplicityField/add-objects/index.js +11 -13
  144. package/cjs/MultiplicityField/add-objects.js.map +2 -2
  145. package/cjs/MultiplicityField/index.js +4 -1
  146. package/cjs/MultiplicityField/index.js.map +2 -2
  147. package/cjs/MultiplicityField/types.js.map +1 -1
  148. package/cjs/Questions/Questions.js.map +1 -1
  149. package/cjs/Questions/QuestionsContext.js.map +1 -1
  150. package/cjs/Questions/Step/Step.js.map +1 -1
  151. package/cjs/Questions/Step/StepArrayReview.js.map +1 -1
  152. package/cjs/Questions/Step/StepContext.js.map +1 -1
  153. package/cjs/Questions/Step/StepDescription.js.map +2 -2
  154. package/cjs/Questions/Step/StepForm.js.map +1 -1
  155. package/cjs/Questions/Step/StepQuote.js.map +2 -2
  156. package/cjs/Questions/Step/StepTitle.js.map +2 -2
  157. package/cjs/Questions/Step/getAddMoreFields.js.map +1 -1
  158. package/cjs/Questions/Step/types.js.map +1 -1
  159. package/cjs/Questions/getNextStep.js.map +1 -1
  160. package/cjs/Questions/types.js.map +1 -1
  161. package/cjs/hooks/useFieldFocusManager/index.js +135 -0
  162. package/cjs/hooks/useFieldFocusManager.js.map +7 -0
  163. package/cjs/hooks/utils/index.js +98 -0
  164. package/cjs/hooks/utils.js.map +7 -0
  165. package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
  166. package/cjs/inputs/Checkboxes/index.js +67 -63
  167. package/cjs/inputs/Checkboxes/index.js.map +2 -2
  168. package/cjs/inputs/DateInput/index.js +51 -19
  169. package/cjs/inputs/DateInput/index.js.map +2 -2
  170. package/cjs/inputs/DateTimeInput/index.js +78 -39
  171. package/cjs/inputs/DateTimeInput/index.js.map +2 -2
  172. package/cjs/inputs/FileInput/index.js +52 -29
  173. package/cjs/inputs/FileInput/index.js.map +2 -2
  174. package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  175. package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  176. package/cjs/inputs/ImageInput/index.js +41 -10
  177. package/cjs/inputs/ImageInput/index.js.map +2 -2
  178. package/cjs/inputs/Input/index.js +55 -57
  179. package/cjs/inputs/Input/index.js.map +2 -2
  180. package/cjs/inputs/Label/index.js.map +1 -1
  181. package/cjs/inputs/OtpInput/index.js +36 -31
  182. package/cjs/inputs/OtpInput/index.js.map +2 -2
  183. package/cjs/inputs/Radio/index.js +5 -4
  184. package/cjs/inputs/Radio/index.js.map +3 -3
  185. package/cjs/inputs/Select/index.js +4 -3
  186. package/cjs/inputs/Select/index.js.map +2 -2
  187. package/cjs/{Field/utils → inputs/registry}/index.js +7 -5
  188. package/cjs/inputs/registry.js.map +7 -0
  189. package/cjs/lazy/index.js +9 -9
  190. package/cjs/lazy.js.map +2 -2
  191. package/cjs/registry/index.js +24 -18
  192. package/cjs/registry.js.map +2 -2
  193. package/cjs/types.js.map +1 -1
  194. package/cjs/utils/index.js +20 -6
  195. package/cjs/utils.js.map +2 -2
  196. package/cjs/validators/index.js +10 -6
  197. package/cjs/validators/index.js.map +2 -2
  198. package/cjs/validators/types.js.map +1 -1
  199. package/cjs/validators/utils/date/index.js +26 -3
  200. package/cjs/validators/utils/date.js.map +2 -2
  201. package/cjs/validators/utils/datetime/index.js +118 -24
  202. package/cjs/validators/utils/datetime.js.map +2 -2
  203. package/cjs/validators/utils/file/index.js +30 -17
  204. package/cjs/validators/utils/file.js.map +2 -2
  205. package/cjs/validators/utils/iban.js.map +1 -1
  206. package/cjs/validators/utils/image.js.map +1 -1
  207. package/cjs/validators/utils/index.js +3 -1
  208. package/cjs/validators/utils/index.js.map +2 -2
  209. package/cjs/validators/utils/int.js.map +1 -1
  210. package/cjs/validators/utils/number.js.map +1 -1
  211. package/cjs/validators/utils/otp.js.map +1 -1
  212. package/cjs/validators/utils/phone.js.map +1 -1
  213. package/cjs/validators/utils/postal_code.js.map +1 -1
  214. package/cjs/validators/utils/text_limit.js.map +1 -1
  215. package/hooks/useFieldFocusManager/index.js +116 -0
  216. package/hooks/useFieldFocusManager/package.json +6 -0
  217. package/hooks/useFieldFocusManager.d.ts +25 -0
  218. package/hooks/useFieldFocusManager.js.map +7 -0
  219. package/hooks/utils/index.js +73 -0
  220. package/{Field → hooks}/utils/package.json +1 -1
  221. package/hooks/utils.d.ts +18 -0
  222. package/hooks/utils.js.map +7 -0
  223. package/index.js +1 -1
  224. package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +2 -0
  225. package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -1
  226. package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +1 -1
  227. package/inputs/AutoCompleteInput/index.d.ts +3 -3
  228. package/inputs/AutoCompleteInput/index.js +1 -3
  229. package/inputs/AutoCompleteInput/index.js.map +2 -2
  230. package/inputs/Checkboxes/Checkboxes.stories.d.ts +2 -0
  231. package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -1
  232. package/inputs/Checkboxes/__stories__/Default.d.ts +1 -1
  233. package/inputs/Checkboxes/__stories__/WithDivider.d.ts +1 -1
  234. package/inputs/Checkboxes/index.d.ts +3 -3
  235. package/inputs/Checkboxes/index.js +67 -63
  236. package/inputs/Checkboxes/index.js.map +2 -2
  237. package/inputs/DateInput/DateInput.stories.d.ts +6 -0
  238. package/inputs/DateInput/__stories__/Default.d.ts +1 -1
  239. package/inputs/DateInput/__stories__/WithDefaultValue.d.ts +3 -0
  240. package/inputs/DateInput/__stories__/WithInitialValue.d.ts +3 -0
  241. package/inputs/DateInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
  242. package/inputs/DateInput/__stories__/WithWrongInitialValue.d.ts +3 -0
  243. package/inputs/DateInput/index.d.ts +2 -5
  244. package/inputs/DateInput/index.js +52 -20
  245. package/inputs/DateInput/index.js.map +2 -2
  246. package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +10 -3
  247. package/inputs/DateTimeInput/__stories__/Default.d.ts +1 -1
  248. package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +3 -0
  249. package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +3 -0
  250. package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
  251. package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +3 -0
  252. package/inputs/DateTimeInput/index.d.ts +2 -5
  253. package/inputs/DateTimeInput/index.js +79 -40
  254. package/inputs/DateTimeInput/index.js.map +2 -2
  255. package/inputs/FileInput/FileInput.stories.d.ts +3 -0
  256. package/inputs/FileInput/__stories__/Default.d.ts +1 -1
  257. package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
  258. package/inputs/FileInput/index.d.ts +12 -5
  259. package/inputs/FileInput/index.js +53 -30
  260. package/inputs/FileInput/index.js.map +2 -2
  261. package/inputs/ImageInput/ImageInput.stories.d.ts +4 -1
  262. package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
  263. package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
  264. package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
  265. package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
  266. package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
  267. package/inputs/ImageInput/__stories__/logo.d/package.json +6 -0
  268. package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
  269. package/inputs/ImageInput/index.d.ts +10 -2
  270. package/inputs/ImageInput/index.js +42 -11
  271. package/inputs/ImageInput/index.js.map +2 -2
  272. package/inputs/Input/Input.stories.d.ts +3 -0
  273. package/inputs/Input/__stories__/AFM.d.ts +1 -1
  274. package/inputs/Input/__stories__/Boolean.d.ts +1 -1
  275. package/inputs/Input/__stories__/Email.d.ts +3 -0
  276. package/inputs/Input/__stories__/IBAN.d.ts +1 -1
  277. package/inputs/Input/__stories__/Integer.d.ts +1 -1
  278. package/inputs/Input/__stories__/LandlineNumber.d.ts +1 -1
  279. package/inputs/Input/__stories__/MobilePhone.d.ts +1 -1
  280. package/inputs/Input/__stories__/PhoneNumber.d.ts +1 -1
  281. package/inputs/Input/__stories__/PostalCode.d.ts +1 -1
  282. package/inputs/Input/__stories__/String.d.ts +1 -1
  283. package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +1 -1
  284. package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
  285. package/inputs/Input/index.d.ts +4 -3
  286. package/inputs/Input/index.js +55 -57
  287. package/inputs/Input/index.js.map +2 -2
  288. package/inputs/Label/Label.stories.d.ts +2 -0
  289. package/inputs/Label/__stories__/Default.d.ts +1 -1
  290. package/inputs/Label/index.d.ts +1 -1
  291. package/inputs/Label/index.js.map +1 -1
  292. package/inputs/OtpInput/OtpInput.stories.d.ts +2 -0
  293. package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
  294. package/inputs/OtpInput/index.d.ts +1 -5
  295. package/inputs/OtpInput/index.js +36 -31
  296. package/inputs/OtpInput/index.js.map +2 -2
  297. package/inputs/Radio/Radio.stories.d.ts +2 -0
  298. package/inputs/Radio/__stories__/Conditional.d.ts +1 -1
  299. package/inputs/Radio/__stories__/Default.d.ts +1 -1
  300. package/inputs/Radio/__stories__/WithDivider.d.ts +1 -1
  301. package/inputs/Radio/index.d.ts +4 -4
  302. package/inputs/Radio/index.js +5 -4
  303. package/inputs/Radio/index.js.map +3 -3
  304. package/inputs/Select/Select.stories.d.ts +2 -0
  305. package/inputs/Select/__stories__/Default.d.ts +1 -1
  306. package/inputs/Select/index.d.ts +4 -3
  307. package/inputs/Select/index.js +4 -3
  308. package/inputs/Select/index.js.map +2 -2
  309. package/{Field/utils → inputs/registry}/index.js +4 -2
  310. package/{locales/el → inputs/registry}/package.json +1 -1
  311. package/{Field/utils/index.d.ts → inputs/registry.d.ts} +2 -1
  312. package/inputs/registry.js.map +7 -0
  313. package/lazy/index.js +9 -9
  314. package/package.json +8 -8
  315. package/registry/index.js +24 -18
  316. package/src/Field/ErrorGroup.tsx +3 -3
  317. package/src/Field/FieldBase.tsx +7 -4
  318. package/src/Field/FieldBaseContainer.tsx +69 -48
  319. package/src/Field/FieldConditional.tsx +5 -1
  320. package/src/Field/index.tsx +30 -38
  321. package/src/Field/types.tsx +20 -14
  322. package/src/Field/utils/evaluateFieldWithConditions.ts +5 -2
  323. package/src/Field/utils/resolveField.ts +58 -0
  324. package/src/Field/utils/useField.ts +12 -2
  325. package/src/FieldArray/BaseFieldArray.tsx +97 -0
  326. package/src/FieldArray/FormDialog/ArrayItemDisplay.tsx +165 -0
  327. package/src/FieldArray/FormDialog/ArrayItemHeader.tsx +15 -0
  328. package/src/FieldArray/FormDialog/ArrayItemModal.tsx +223 -0
  329. package/src/FieldArray/FormDialog/index.tsx +233 -0
  330. package/src/FieldArray/__stories__/Default.tsx +1 -1
  331. package/src/FieldArray/__stories__/WithExactLength.tsx +1 -1
  332. package/src/FieldArray/__stories__/WithModal.tsx +4 -3
  333. package/src/FieldArray/__tests__/multiplicity-attachment.spec.tsx +219 -0
  334. package/src/FieldArray/__tests__/multiplicity-required.spec.tsx +131 -0
  335. package/src/FieldArray/__tests__/preference-multiple-choice.spec.tsx +222 -0
  336. package/src/FieldArray/index.spec.tsx +355 -0
  337. package/src/FieldArray/index.tsx +41 -72
  338. package/src/FieldObject/index.tsx +36 -31
  339. package/src/Fieldset/FieldsetWithContext.tsx +1 -1
  340. package/src/Fieldset/index.tsx +1 -1
  341. package/src/Fieldset/types.tsx +2 -2
  342. package/src/FormBuilder/FormBuilder.stories.js +3 -0
  343. package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +1 -1
  344. package/src/FormBuilder/__stories__/Default.tsx +1 -1
  345. package/src/FormBuilder/__stories__/ErrorGrouping.tsx +1 -1
  346. package/src/FormBuilder/index.tsx +197 -146
  347. package/src/FormBuilder/scenarios.test.tsx +763 -5
  348. package/src/FormContext.tsx +7 -2
  349. package/src/MultiplicityField/MultiplicityField.stories.js +3 -0
  350. package/src/MultiplicityField/__stories__/Default.tsx +1 -1
  351. package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +1 -1
  352. package/src/MultiplicityField/__stories__/WithExactLength.tsx +1 -1
  353. package/src/MultiplicityField/__stories__/WithMaxLength.tsx +1 -1
  354. package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +1 -1
  355. package/src/MultiplicityField/__stories__/WithMinLength.tsx +1 -1
  356. package/src/MultiplicityField/add-objects.tsx +14 -21
  357. package/src/MultiplicityField/index.tsx +6 -2
  358. package/src/MultiplicityField/types.ts +6 -2
  359. package/src/Questions/Questions.stories.js +3 -0
  360. package/src/Questions/Questions.tsx +2 -2
  361. package/src/Questions/QuestionsContext.tsx +1 -1
  362. package/src/Questions/Step/Step.tsx +1 -1
  363. package/src/Questions/Step/StepArrayReview.tsx +2 -2
  364. package/src/Questions/Step/StepContext.tsx +1 -1
  365. package/src/Questions/Step/StepDescription.tsx +2 -1
  366. package/src/Questions/Step/StepForm.tsx +2 -2
  367. package/src/Questions/Step/StepQuote.tsx +2 -1
  368. package/src/Questions/Step/StepTitle.tsx +2 -1
  369. package/src/Questions/Step/getAddMoreFields.tsx +2 -2
  370. package/src/Questions/Step/types.tsx +1 -1
  371. package/src/Questions/__stories__/Default.tsx +1 -1
  372. package/src/Questions/getNextStep.tsx +1 -1
  373. package/src/Questions/types.tsx +1 -1
  374. package/src/hooks/__tests__/useFieldFocusManager.spec.tsx +1079 -0
  375. package/src/hooks/__tests__/utils.spec.ts +568 -0
  376. package/src/hooks/useFieldFocusManager.ts +162 -0
  377. package/src/hooks/utils.ts +122 -0
  378. package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +3 -0
  379. package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +1 -1
  380. package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +1 -1
  381. package/src/inputs/AutoCompleteInput/index.tsx +4 -6
  382. package/src/inputs/Checkboxes/Checkboxes.stories.js +3 -0
  383. package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
  384. package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
  385. package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
  386. package/src/inputs/Checkboxes/index.tsx +95 -91
  387. package/src/inputs/DateInput/DateInput.stories.js +7 -0
  388. package/src/inputs/DateInput/__stories__/Default.tsx +1 -1
  389. package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +26 -0
  390. package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +28 -0
  391. package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +26 -0
  392. package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +28 -0
  393. package/src/inputs/DateInput/index.test.tsx +16 -0
  394. package/src/inputs/DateInput/index.tsx +65 -20
  395. package/src/inputs/DateTimeInput/DateTimeInput.stories.js +12 -6
  396. package/src/inputs/DateTimeInput/__stories__/Default.tsx +1 -1
  397. package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +26 -0
  398. package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +28 -0
  399. package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +26 -0
  400. package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +28 -0
  401. package/src/inputs/DateTimeInput/index.test.tsx +16 -0
  402. package/src/inputs/DateTimeInput/index.tsx +92 -40
  403. package/src/inputs/FileInput/FileInput.stories.js +4 -0
  404. package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
  405. package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
  406. package/src/inputs/FileInput/index.test.tsx +4 -0
  407. package/src/inputs/FileInput/index.tsx +91 -47
  408. package/src/inputs/ImageInput/ImageInput.stories.js +5 -1
  409. package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
  410. package/src/inputs/ImageInput/__stories__/MaxSize.tsx +3 -2
  411. package/src/inputs/ImageInput/__stories__/WithInitialValues.tsx +45 -0
  412. package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +1 -1
  413. package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
  414. package/src/inputs/ImageInput/__stories__/logo.png +0 -0
  415. package/src/inputs/ImageInput/index.test.tsx +21 -17
  416. package/src/inputs/ImageInput/index.tsx +101 -49
  417. package/src/inputs/Input/Input.stories.js +4 -0
  418. package/src/inputs/Input/__stories__/AFM.tsx +1 -1
  419. package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
  420. package/src/inputs/Input/__stories__/Email.tsx +23 -0
  421. package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
  422. package/src/inputs/Input/__stories__/Integer.tsx +1 -1
  423. package/src/inputs/Input/__stories__/LandlineNumber.tsx +1 -1
  424. package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -1
  425. package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -1
  426. package/src/inputs/Input/__stories__/PostalCode.tsx +1 -1
  427. package/src/inputs/Input/__stories__/String.tsx +1 -1
  428. package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +1 -1
  429. package/src/inputs/Input/__stories__/TextWithLimit.tsx +1 -1
  430. package/src/inputs/Input/index.test.tsx +8 -0
  431. package/src/inputs/Input/index.tsx +76 -73
  432. package/src/inputs/Label/Label.stories.js +3 -0
  433. package/src/inputs/Label/__stories__/Default.tsx +1 -1
  434. package/src/inputs/Label/index.tsx +1 -1
  435. package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
  436. package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
  437. package/src/inputs/OtpInput/index.tsx +43 -34
  438. package/src/inputs/Radio/Radio.stories.js +3 -0
  439. package/src/inputs/Radio/__stories__/Conditional.tsx +1 -1
  440. package/src/inputs/Radio/__stories__/Default.tsx +1 -1
  441. package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
  442. package/src/inputs/Radio/index.tsx +29 -21
  443. package/src/inputs/Select/Select.stories.js +3 -0
  444. package/src/inputs/Select/__stories__/Default.tsx +1 -1
  445. package/src/inputs/Select/index.tsx +9 -6
  446. package/src/{Field/utils/index.ts → inputs/registry.ts} +5 -1
  447. package/src/lazy.js +9 -9
  448. package/src/registry.js +24 -18
  449. package/src/types.tsx +13 -5
  450. package/src/utils.ts +30 -8
  451. package/src/validators/index.ts +22 -15
  452. package/src/validators/types.ts +1 -1
  453. package/src/validators/utils/date.ts +30 -6
  454. package/src/validators/utils/datetime.ts +123 -31
  455. package/src/validators/utils/file.ts +35 -21
  456. package/src/validators/utils/iban.ts +2 -2
  457. package/src/validators/utils/image.ts +2 -2
  458. package/src/validators/utils/index.ts +5 -3
  459. package/src/validators/utils/int.ts +1 -1
  460. package/src/validators/utils/number.ts +1 -1
  461. package/src/validators/utils/otp.ts +2 -2
  462. package/src/validators/utils/phone.ts +2 -2
  463. package/src/validators/utils/postal_code.ts +2 -2
  464. package/src/validators/utils/text_limit.ts +2 -2
  465. package/types.d.ts +9 -4
  466. package/types.js.map +1 -1
  467. package/utils/index.js +20 -6
  468. package/utils.d.ts +3 -1
  469. package/utils.js.map +2 -2
  470. package/validators/index.d.ts +6 -6
  471. package/validators/index.js +10 -6
  472. package/validators/index.js.map +2 -2
  473. package/validators/types.d.ts +1 -1
  474. package/validators/utils/date/index.js +26 -3
  475. package/validators/utils/date.d.ts +3 -3
  476. package/validators/utils/date.js.map +2 -2
  477. package/validators/utils/datetime/index.js +118 -24
  478. package/validators/utils/datetime.d.ts +3 -3
  479. package/validators/utils/datetime.js.map +2 -2
  480. package/validators/utils/file/index.js +30 -17
  481. package/validators/utils/file.d.ts +2 -2
  482. package/validators/utils/file.js.map +2 -2
  483. package/validators/utils/iban.d.ts +2 -2
  484. package/validators/utils/iban.js.map +1 -1
  485. package/validators/utils/image.d.ts +2 -2
  486. package/validators/utils/image.js.map +1 -1
  487. package/validators/utils/index.d.ts +2 -2
  488. package/validators/utils/index.js +3 -1
  489. package/validators/utils/index.js.map +2 -2
  490. package/validators/utils/int.d.ts +1 -1
  491. package/validators/utils/int.js.map +1 -1
  492. package/validators/utils/number.d.ts +1 -1
  493. package/validators/utils/number.js.map +1 -1
  494. package/validators/utils/otp.d.ts +2 -2
  495. package/validators/utils/otp.js.map +1 -1
  496. package/validators/utils/phone.d.ts +2 -2
  497. package/validators/utils/phone.js.map +1 -1
  498. package/validators/utils/postal_code.d.ts +2 -2
  499. package/validators/utils/postal_code.js.map +1 -1
  500. package/validators/utils/text_limit.d.ts +2 -2
  501. package/validators/utils/text_limit.js.map +1 -1
  502. package/Field/utils/calculateField/index.js +0 -27
  503. package/Field/utils/calculateField.d.ts +0 -2
  504. package/Field/utils/calculateField.js.map +0 -7
  505. package/Field/utils/index.js.map +0 -7
  506. package/FieldArray/FormDialog.d.ts +0 -53
  507. package/FieldArray/FormDialog.js.map +0 -7
  508. package/FormBuilder/index.test.d.ts +0 -1
  509. package/FormBuilder/interaction.test.d.ts +0 -1
  510. package/FormBuilder/scenarios.test.d.ts +0 -88
  511. package/MultiplicityField/index.test.d.ts +0 -1
  512. package/Questions/index.spec.d.ts +0 -1
  513. package/Questions/index.test.d.ts +0 -1
  514. package/cjs/Field/utils/calculateField/index.js +0 -50
  515. package/cjs/Field/utils/calculateField.js.map +0 -7
  516. package/cjs/Field/utils/index.js.map +0 -7
  517. package/cjs/FieldArray/FormDialog.js.map +0 -7
  518. package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
  519. package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
  520. package/cjs/inputs/inputsScenarios/index.js +0 -533
  521. package/cjs/inputs/inputsScenarios.js.map +0 -7
  522. package/cjs/locales/el.js.map +0 -7
  523. package/inputs/AutoCompleteInput/index.test.d.ts +0 -1
  524. package/inputs/Checkboxes/index.test.d.ts +0 -1
  525. package/inputs/DateInput/index.test.d.ts +0 -1
  526. package/inputs/DateTimeInput/index.test.d.ts +0 -1
  527. package/inputs/FileInput/index.test.d.ts +0 -1
  528. package/inputs/ImageInput/index.test.d.ts +0 -1
  529. package/inputs/Input/index.test.d.ts +0 -1
  530. package/inputs/Input/inputsInputScenarios/index.js +0 -406
  531. package/inputs/Input/inputsInputScenarios.d.ts +0 -57
  532. package/inputs/Input/inputsInputScenarios.js.map +0 -7
  533. package/inputs/Label/index.test.d.ts +0 -1
  534. package/inputs/OtpInput/index.test.d.ts +0 -1
  535. package/inputs/Radio/index.test.d.ts +0 -1
  536. package/inputs/Select/index.test.d.ts +0 -1
  537. package/inputs/inputsScenarios/index.js +0 -499
  538. package/inputs/inputsScenarios.d.ts +0 -296
  539. package/inputs/inputsScenarios.js.map +0 -7
  540. package/locales/el/index.js +0 -6
  541. package/locales/el.d.ts +0 -2
  542. package/locales/el.js.map +0 -7
  543. package/src/Field/utils/calculateField.ts +0 -49
  544. package/src/FieldArray/FormDialog.tsx +0 -378
  545. package/src/inputs/Input/inputsInputScenarios.ts +0 -404
  546. package/src/inputs/inputsScenarios.ts +0 -496
  547. package/src/locales/el.ts +0 -3
  548. /package/{FieldArray/index.test.d.ts → hooks/__tests__/utils.spec.d.ts} +0 -0
@@ -3,50 +3,144 @@ import customParseFormat from "dayjs/plugin/customParseFormat";
3
3
  dayjs.extend(customParseFormat);
4
4
  const VALID_DATETIME_FORMATS = ["DD/MM/YYYY HH:mm"];
5
5
  const DATETIME_CACHE = {};
6
+ const onlyNumbersRegex = /^\d+$/;
6
7
  const getDateTime = (v) => {
7
8
  return DATETIME_CACHE[v] ? DATETIME_CACHE[v] : dayjs(v, VALID_DATETIME_FORMATS, true);
8
9
  };
10
+ const getDaysInMonth = (month, year) => {
11
+ return dayjs(`${year}-${month}-01`).daysInMonth();
12
+ };
9
13
  const checkPartialDateTime = (value) => {
10
14
  const [datePart, timePart] = value.split(" ");
11
- const [day, month, year] = datePart.split("/");
12
- const [hours, minutes] = timePart ? timePart.split(":") : [null, null];
13
- if (day && !month && !year) {
15
+ const [day, month, year] = datePart?.split("/") ?? [];
16
+ const [hours, minutes] = timePart?.split(":") ?? [];
17
+ const hasDay = Boolean(day);
18
+ const hasMonth = Boolean(month);
19
+ const hasYear = Boolean(year);
20
+ const hasHours = Boolean(hours);
21
+ const hasMinutes = Boolean(minutes);
22
+ if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {
23
+ return "form.error.datetime.invalid_month_year_hours_minutes";
24
+ }
25
+ if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
26
+ return "form.error.datetime.invalid_day_year_hours_minutes";
27
+ }
28
+ if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
29
+ return "form.error.datetime.invalid_day_month_hours_minutes";
30
+ }
31
+ if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
32
+ return "form.error.datetime.invalid_year_hours_minutes";
33
+ }
34
+ if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
35
+ return "form.error.datetime.invalid_month_hours_minutes";
36
+ }
37
+ if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
38
+ return "form.error.datetime.invalid_day_hours_minutes";
39
+ }
40
+ if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
41
+ return "form.error.datetime.invalid__hours_minutes";
42
+ }
43
+ if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
44
+ return "form.error.datetime.invalid_minutes";
45
+ }
46
+ if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
47
+ return "form.error.datetime.invalid_hours";
48
+ }
49
+ if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
50
+ return "form.error.datetime.invalid_month_year_minutes";
51
+ }
52
+ if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
53
+ return "form.error.datetime.invalid_month_year_hours";
54
+ }
55
+ if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
14
56
  return "form.error.datetime.invalid_month_year";
15
57
  }
16
- if (!day && month && !year) {
58
+ if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
59
+ return "form.error.datetime.invalid_day_year_minutes";
60
+ }
61
+ if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
62
+ return "form.error.datetime.invalid_day_year_hours";
63
+ }
64
+ if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
17
65
  return "form.error.datetime.invalid_day_year";
18
66
  }
19
- if (!day && !month && year) {
67
+ if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
68
+ return "form.error.datetime.invalid_day_month_minutes";
69
+ }
70
+ if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
71
+ return "form.error.datetime.invalid_day_month_hours";
72
+ }
73
+ if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
20
74
  return "form.error.datetime.invalid_day_month";
21
75
  }
22
- if (day && month && !year) {
76
+ if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
77
+ return "form.error.datetime.invalid_day_month_year";
78
+ }
79
+ if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
80
+ return "form.error.datetime.invalid_day_month_year_hours";
81
+ }
82
+ if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
83
+ return "form.error.datetime.invalid_year_minutes";
84
+ }
85
+ if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
86
+ return "form.error.datetime.invalid_year_hours";
87
+ }
88
+ if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
23
89
  return "form.error.datetime.invalid_year";
24
90
  }
25
- if (day && !month && year) {
91
+ if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
92
+ return "form.error.datetime.invalid_month_minutes";
93
+ }
94
+ if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
95
+ return "form.error.datetime.invalid_month_hours";
96
+ }
97
+ if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
26
98
  return "form.error.datetime.invalid_month";
27
99
  }
28
- if (!day && month && year) {
100
+ if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
101
+ return "form.error.datetime.invalid_day_minutes";
102
+ }
103
+ if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
104
+ return "form.error.datetime.invalid_day_hours";
105
+ }
106
+ if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {
29
107
  return "form.error.datetime.invalid_day";
30
108
  }
31
- if (day && month && year) {
32
- if (hours && !minutes) {
33
- return "form.error.datetime.invalid_minutes";
109
+ if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
110
+ return "form.error.datetime.invalid_day_month_year_minutes";
111
+ }
112
+ if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
113
+ return "form.error.datetime.invalid_hours_minutes";
114
+ }
115
+ if (day && month) {
116
+ const dayNum = parseInt(day);
117
+ const monthNum = parseInt(month);
118
+ const validYear = onlyNumbersRegex.test(year) ? year : void 0;
119
+ if (!validYear || year.length < 4) {
120
+ return "form.error.datetime.invalid";
34
121
  }
35
- if (!hours && minutes) {
36
- return "form.error.datetime.invalid_hours";
122
+ const yearNum = parseInt(validYear);
123
+ const maxDay = getDaysInMonth(monthNum, yearNum);
124
+ if (dayNum < 1 || dayNum > maxDay) {
125
+ return {
126
+ key: "form.error.datetime.invalid_day_range",
127
+ context: {
128
+ maxDay
129
+ }
130
+ };
37
131
  }
38
- if (!hours && !minutes) {
39
- return "form.error.datetime.invalid";
132
+ if (monthNum < 1 || monthNum > 12) {
133
+ return "form.error.datetime.invalid_month_range";
40
134
  }
41
- if (hours && minutes) {
42
- const hoursNum = parseInt(hours);
43
- const minutesNum = parseInt(minutes);
44
- if (hoursNum < 0 || hoursNum > 23) {
45
- return "form.error.datetime.invalid_hours_range";
46
- }
47
- if (minutesNum < 0 || minutesNum > 59) {
48
- return "form.error.datetime.invalid_minutes_range";
49
- }
135
+ }
136
+ if (hours && minutes) {
137
+ const hoursNum = parseInt(hours);
138
+ const minutesNum = parseInt(minutes);
139
+ if (hoursNum < 0 || hoursNum > 23) {
140
+ return "form.error.datetime.invalid_hours_range";
141
+ }
142
+ if (minutesNum < 0 || minutesNum > 59) {
143
+ return "form.error.datetime.invalid_minutes_range";
50
144
  }
51
145
  }
52
146
  return "form.error.datetime.invalid";
@@ -1,9 +1,9 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
  export declare const LATER_THAN_DATETIME_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
4
4
  export declare const EARLIER_THAN_DATETIME_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
5
5
  export declare const DATETIME_VALIDATOR: {
6
6
  name: string;
7
- message: (v: any) => string;
7
+ message: (v: any) => string | object;
8
8
  test: (value: string) => any;
9
9
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/validators/utils/datetime.ts"],
4
- "sourcesContent": ["import dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\ndayjs.extend(customParseFormat);\n\nconst VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];\nconst DATETIME_CACHE = {};\n\nconst getDateTime = (v: string) => {\n return DATETIME_CACHE[v]\n ? DATETIME_CACHE[v]\n : dayjs(v, VALID_DATETIME_FORMATS, true);\n};\n\n// Function to check partial datetime completion\nconst checkPartialDateTime = (value: string) => {\n const [datePart, timePart] = value.split(' ');\n const [day, month, year] = datePart.split('/');\n const [hours, minutes] = timePart ? timePart.split(':') : [null, null];\n\n // Check date part first\n if (day && !month && !year) {\n return 'form.error.datetime.invalid_month_year';\n }\n if (!day && month && !year) {\n return 'form.error.datetime.invalid_day_year';\n }\n if (!day && !month && year) {\n return 'form.error.datetime.invalid_day_month';\n }\n if (day && month && !year) {\n return 'form.error.datetime.invalid_year';\n }\n if (day && !month && year) {\n return 'form.error.datetime.invalid_month';\n }\n if (!day && month && year) {\n return 'form.error.datetime.invalid_day';\n }\n // If date is complete, check time part\n if (day && month && year) {\n if (hours && !minutes) {\n return 'form.error.datetime.invalid_minutes';\n }\n if (!hours && minutes) {\n return 'form.error.datetime.invalid_hours';\n }\n if (!hours && !minutes) {\n return 'form.error.datetime.invalid';\n }\n if (hours && minutes) {\n const hoursNum = parseInt(hours);\n const minutesNum = parseInt(minutes);\n if (hoursNum < 0 || hoursNum > 23) {\n return 'form.error.datetime.invalid_hours_range';\n }\n if (minutesNum < 0 || minutesNum > 59) {\n return 'form.error.datetime.invalid_minutes_range';\n }\n }\n }\n\n return 'form.error.datetime.invalid';\n};\n\nexport const LATER_THAN_DATETIME_VALIDATOR = (\n field: FieldSpec\n): ValidatorSchema => {\n let minDateTime;\n const params = field.extra || {};\n if (params.min === 'now') {\n minDateTime = dayjs();\n } else {\n minDateTime = getDateTime(params.min);\n }\n return {\n name: 'later-than-datetime',\n message: {\n key: 'form.error.datetime.later_than',\n context: {\n minDateTime: minDateTime.format('DD/MM/YYYY HH:mm'),\n },\n },\n test: function (value: string) {\n if (!value) return true;\n const datetime = getDateTime(value);\n return datetime.isValid() && datetime.isAfter(minDateTime);\n },\n };\n};\n\nexport const EARLIER_THAN_DATETIME_VALIDATOR = (\n field: FieldSpec\n): ValidatorSchema => {\n let maxDateTime;\n const params = field.extra || {};\n if (params.max === 'now') {\n maxDateTime = dayjs();\n } else {\n maxDateTime = getDateTime(params.max);\n }\n return {\n name: 'earlier-than-datetime',\n message: {\n key: 'form.error.datetime.earlier_than',\n context: {\n maxDateTime: maxDateTime.format('DD/MM/YYYY HH:mm'),\n },\n },\n test: function (value: string) {\n if (!value) return true;\n const datetime = getDateTime(value);\n return datetime.isValid() && datetime.isBefore(maxDateTime);\n },\n };\n};\n\nexport const DATETIME_VALIDATOR = {\n name: 'datetime-validator',\n message: (v): string => {\n return checkPartialDateTime(v.value);\n },\n test: function (value: string) {\n if (!value) return true;\n const datetime = getDateTime(value);\n return datetime.isValid();\n },\n};\n"],
5
- "mappings": "AAAA,OAAO,WAAW;AAClB,OAAO,uBAAuB;A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AAQ;AAAA,EAC1B;AACF;",
4
+ "sourcesContent": ["import dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport type { FieldSpec } from '@digigov/form/types';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\n\ndayjs.extend(customParseFormat);\n\nconst VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];\nconst DATETIME_CACHE = {};\nconst onlyNumbersRegex = /^\\d+$/;\n\nconst getDateTime = (v: string) => {\n return DATETIME_CACHE[v]\n ? DATETIME_CACHE[v]\n : dayjs(v, VALID_DATETIME_FORMATS, true);\n};\n\nconst getDaysInMonth = (month: number, year: number): number => {\n return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024\n};\n\nconst checkPartialDateTime = (value: string) => {\n const [datePart, timePart] = value.split(' ');\n const [day, month, year] = datePart?.split('/') ?? [];\n const [hours, minutes] = timePart?.split(':') ?? [];\n\n const hasDay = Boolean(day);\n const hasMonth = Boolean(month);\n const hasYear = Boolean(year);\n const hasHours = Boolean(hours);\n const hasMinutes = Boolean(minutes);\n\n if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_month_year_hours_minutes';\n }\n if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_year_hours_minutes';\n }\n if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_month_hours_minutes';\n }\n if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_year_hours_minutes';\n }\n if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_month_hours_minutes';\n }\n if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_hours_minutes';\n }\n if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid__hours_minutes';\n }\n if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_minutes';\n }\n if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_hours';\n }\n if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_month_year_minutes';\n }\n if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_month_year_hours';\n }\n if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_month_year';\n }\n if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_year_minutes';\n }\n if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_year_hours';\n }\n if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_year';\n }\n if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_month_minutes';\n }\n if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_month_hours';\n }\n if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_month';\n }\n if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_month_year';\n }\n if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_month_year_hours';\n }\n if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_year_minutes';\n }\n if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_year_hours';\n }\n if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_year';\n }\n if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_month_minutes';\n }\n if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_month_hours';\n }\n if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_month';\n }\n if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_minutes';\n }\n if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_hours';\n }\n if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day';\n }\n if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_month_year_minutes';\n }\n if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_hours_minutes';\n }\n if (day && month) {\n const dayNum = parseInt(day);\n const monthNum = parseInt(month);\n const validYear = onlyNumbersRegex.test(year) ? year : undefined;\n if (!validYear || year.length < 4) {\n return 'form.error.datetime.invalid';\n }\n const yearNum = parseInt(validYear);\n const maxDay = getDaysInMonth(monthNum, yearNum);\n if (dayNum < 1 || dayNum > maxDay) {\n return {\n key: 'form.error.datetime.invalid_day_range',\n context: {\n maxDay: maxDay,\n },\n };\n }\n if (monthNum < 1 || monthNum > 12) {\n return 'form.error.datetime.invalid_month_range';\n }\n }\n if (hours && minutes) {\n const hoursNum = parseInt(hours);\n const minutesNum = parseInt(minutes);\n if (hoursNum < 0 || hoursNum > 23) {\n return 'form.error.datetime.invalid_hours_range';\n }\n if (minutesNum < 0 || minutesNum > 59) {\n return 'form.error.datetime.invalid_minutes_range';\n }\n }\n return 'form.error.datetime.invalid';\n};\n\nexport const LATER_THAN_DATETIME_VALIDATOR = (\n field: FieldSpec\n): ValidatorSchema => {\n let minDateTime;\n const params = field.extra || {};\n if (params.min === 'now') {\n minDateTime = dayjs();\n } else {\n minDateTime = getDateTime(params.min);\n }\n return {\n name: 'later-than-datetime',\n message: {\n key: 'form.error.datetime.later_than',\n context: {\n minDateTime: minDateTime.format('DD/MM/YYYY HH:mm'),\n },\n },\n test: function (value: string) {\n if (!value) return true;\n const datetime = getDateTime(value);\n return datetime.isValid() && datetime.isAfter(minDateTime);\n },\n };\n};\n\nexport const EARLIER_THAN_DATETIME_VALIDATOR = (\n field: FieldSpec\n): ValidatorSchema => {\n let maxDateTime;\n const params = field.extra || {};\n if (params.max === 'now') {\n maxDateTime = dayjs();\n } else {\n maxDateTime = getDateTime(params.max);\n }\n return {\n name: 'earlier-than-datetime',\n message: {\n key: 'form.error.datetime.earlier_than',\n context: {\n maxDateTime: maxDateTime.format('DD/MM/YYYY HH:mm'),\n },\n },\n test: function (value: string) {\n if (!value) return true;\n const datetime = getDateTime(value);\n return datetime.isValid() && datetime.isBefore(maxDateTime);\n },\n };\n};\n\nexport const DATETIME_VALIDATOR = {\n name: 'datetime-validator',\n message: (v): string | object => {\n return checkPartialDateTime(v.value);\n },\n test: function (value: string) {\n if (!value) return true;\n const datetime = getDateTime(value);\n return datetime.isValid();\n },\n};\n"],
5
+ "mappings": "AAAA,OAAO,WAAW;AAClB,OAAO,uBAAuB;AAI9B,MAAM,OAAO,iBAAiB;AAE9B,MAAM,yBAAyB,CAAC,kBAAkB;AAClD,MAAM,iBAAiB,CAAC;AACxB,MAAM,mBAAmB;AAEzB,MAAM,cAAc,CAAC,MAAc;AACjC,SAAO,eAAe,CAAC,IACnB,eAAe,CAAC,IAChB,MAAM,GAAG,wBAAwB,IAAI;AAC3C;AAEA,MAAM,iBAAiB,CAAC,OAAe,SAAyB;AAC9D,SAAO,MAAM,GAAG,IAAI,IAAI,KAAK,KAAK,EAAE,YAAY;AAClD;AAEA,MAAM,uBAAuB,CAAC,UAAkB;AAC9C,QAAM,CAAC,UAAU,QAAQ,IAAI,MAAM,MAAM,GAAG;AAC5C,QAAM,CAAC,KAAK,OAAO,IAAI,IAAI,UAAU,MAAM,GAAG,KAAK,CAAC;AACpD,QA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AAAA,MACpD;AAAA,IACF;AAAA,IACA,MAAM,SAAU,OAAe;AAC7B,UAAI,CAAC,MAAO,QAAO;AACnB,YAAM,WAAW,YAAY,KAAK;AAClC,aAAO,SAAS,QAAQ,KAAK,SAAS,QAAQ,WAAW;AAAA,IAC3D;AAAA,EACF;AACF;AAEO,MAAM,kCAAkC,CAC7C,UACoB;AACpB,MAAI;AACJ,QAAM,SAAS,MAAM,SAAS,CAAC;AAC/B,MAAI,OAAO,QAAQ,OAAO;AACxB,kBAAc,MAAM;AAAA,EACtB,OAAO;AACL,kBAAc,YAAY,OAAO,GAAG;AAAA,EACtC;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,KAAK;AAAA,MACL,SAAS;AAAA,QACP,aAAa,YAAY,OAAO,kBAAkB;AAAA,MACpD;AAAA,IACF;AAAA,IACA,MAAM,SAAU,OAAe;AAC7B,UAAI,CAAC,MAAO,QAAO;AACnB,YAAM,WAAW,YAAY,KAAK;AAClC,aAAO,SAAS,QAAQ,KAAK,SAAS,SAAS,WAAW;AAAA,IAC5D;AAAA,EACF;AACF;AAEO,MAAM,qBAAqB;AAAA,EAChC,MAAM;AAAA,EACN,SAAS,CAAC,MAAuB;AAC/B,WAAO,qBAAqB,EAAE,KAAK;AAAA,EACrC;AAAA,EACA,MAAM,SAAU,OAAe;AAC7B,QAAI,CAAC,MAAO,QAAO;AACnB,UAAM,WAAW,YAAY,KAAK;AAClC,WAAO,SAAS,QAAQ;AAAA,EAC1B;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,24 +1,37 @@
1
1
  const DEFAULT_FILE_MAX_SIZE = 1e7;
2
- const FILE_MAX_SIZE_VALIDATOR = (field) => ({
3
- name: "file-max-size-validator",
4
- message: {
5
- key: field.type === "file" ? "form.error.file_size" : "form.error.image_size",
6
- context: {
7
- maxSizeToMb: (field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE) / 1e6
8
- }
9
- },
10
- test: (value) => {
11
- if (value) {
12
- for (const file of value) {
13
- const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
14
- if (file.size > maxSize) {
15
- return false;
2
+ const FILE_MAX_SIZE_VALIDATOR = (field) => {
3
+ const maxSizeInBytes = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
4
+ let maxSizeTransformed = maxSizeInBytes / (1024 * 1024);
5
+ let maxSizeText = "MB";
6
+ if (Math.round(maxSizeTransformed) === 0) {
7
+ maxSizeTransformed = Math.round(maxSizeInBytes / 1024);
8
+ maxSizeText = "KB";
9
+ }
10
+ if (Math.round(maxSizeTransformed) === 0) {
11
+ maxSizeTransformed = maxSizeInBytes;
12
+ maxSizeText = "Bytes";
13
+ }
14
+ return {
15
+ name: "file-max-size-validator",
16
+ message: {
17
+ key: field.type === "file" ? "form.error.file_size" : "form.error.image_size",
18
+ context: {
19
+ maxSize: `${maxSizeTransformed} ${maxSizeText}`
20
+ }
21
+ },
22
+ test: (value) => {
23
+ if (value) {
24
+ for (const file of Array.from(value)) {
25
+ const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
26
+ if (file.size > maxSize) {
27
+ return false;
28
+ }
16
29
  }
17
30
  }
31
+ return true;
18
32
  }
19
- return true;
20
- }
21
- });
33
+ };
34
+ };
22
35
  export {
23
36
  FILE_MAX_SIZE_VALIDATOR
24
37
  };
@@ -1,3 +1,3 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
  export declare const FILE_MAX_SIZE_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/validators/utils/file.ts"],
4
- "sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nconst DEFAULT_FILE_MAX_SIZE = 10000000;\n\nexport const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => ({\n name: 'file-max-size-validator',\n message: {\n key:\n field.type === 'file' ? 'form.error.file_size' : 'form.error.image_size',\n context: {\n maxSizeToMb:\n (field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE) / 1000000,\n },\n },\n test: (value: File[]): boolean => {\n if (value) {\n for (const file of value) {\n const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;\n if (file.size > maxSize) {\n return false;\n }\n }\n }\n return true;\n },\n});\n"],
5
- "mappings": "AAGA,MAAM,wBAAwB;AAEvB,MAAM,0BAA0B,CAAC,WAAuC;AAAA,EAC7E,MAAM;AAAA,EACN,SAAS;AAAA,IACP,KACE,MAAM,SAAS,SAAS,yBAAyB;AAAA,IACnD,SAAS;AAAA,MACP,cACG,OAAO,OAAO,OAAO,WAAW,yBAAyB;AAAA,IAC9D;AAAA,EACF;AAAA,EACA,MAAM,CAAC,UAA2B;AAChC,QAAI,OAAO;AACT,iBAAW,QAAQ,OAAO;AACxB,cAAM,UAAU,OAAO,OAAO,OAAO,WAAW;AAChD,YAAI,KAAK,OAAO,SAAS;AACvB,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import type { FieldSpec } from '@digigov/form/types';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\n\nconst DEFAULT_FILE_MAX_SIZE = 10000000;\n\nexport const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n const maxSizeInBytes = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;\n let maxSizeTransformed = maxSizeInBytes / (1024 * 1024); // In MB\n let maxSizeText = 'MB';\n if (Math.round(maxSizeTransformed) === 0) {\n maxSizeTransformed = Math.round(maxSizeInBytes / 1024);\n maxSizeText = 'KB';\n }\n if (Math.round(maxSizeTransformed) === 0) {\n maxSizeTransformed = maxSizeInBytes;\n maxSizeText = 'Bytes';\n }\n return {\n name: 'file-max-size-validator',\n message: {\n key:\n field.type === 'file'\n ? 'form.error.file_size'\n : 'form.error.image_size',\n context: {\n maxSize: `${maxSizeTransformed} ${maxSizeText}`,\n },\n },\n test: (value: File[]): boolean => {\n if (value) {\n for (const file of Array.from(value)) {\n const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;\n if (file.size > maxSize) {\n return false;\n }\n }\n }\n return true;\n },\n };\n};\n"],
5
+ "mappings": "AAGA,MAAM,wBAAwB;AAEvB,MAAM,0BAA0B,CAAC,UAAsC;AAC5E,QAAM,iBAAiB,OAAO,OAAO,OAAO,WAAW;AACvD,MAAI,qBAAqB,kBAAkB,OAAO;AAClD,MAAI,cAAc;AAClB,MAAI,KAAK,MAAM,kBAAkB,MAAM,GAAG;AACxC,yBAAqB,KAAK,MAAM,iBAAiB,IAAI;AACrD,kBAAc;AAAA,EAChB;AACA,MAAI,KAAK,MAAM,kBAAkB,MAAM,GAAG;AACxC,yBAAqB;AACrB,kBAAc;AAAA,EAChB;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,KACE,MAAM,SAAS,SACX,yBACA;AAAA,MACN,SAAS;AAAA,QACP,SAAS,GAAG,kBAAkB,IAAI,WAAW;AAAA,MAC/C;AAAA,IACF;AAAA,IACA,MAAM,CAAC,UAA2B;AAChC,UAAI,OAAO;AACT,mBAAW,QAAQ,MAAM,KAAK,KAAK,GAAG;AACpC,gBAAM,UAAU,OAAO,OAAO,OAAO,WAAW;AAChD,cAAI,KAAK,OAAO,SAAS;AACvB,mBAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
  export declare function validateIban(value: string, countryCode: string): boolean;
4
4
  export declare const IBAN_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/validators/utils/iban.ts"],
4
- "sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\nexport function validateIban(value: string, countryCode: string): boolean {\n value = value.replace(/\\s/g, '').replace(/-/g, '');\n if (value.match(/^[0-9]*$/i)) {\n // this is for greek iban without the country code\n if (value.length !== 25) {\n return false;\n }\n } else {\n value = value.toUpperCase();\n if (countryCode) {\n if (!value.startsWith(countryCode.toUpperCase())) {\n return false;\n }\n if (value.length === ibanCountryCodesLengths[countryCode.toUpperCase()]) {\n return true;\n }\n }\n if (value.length !== 27) {\n // this is for greek iban\n return false;\n }\n }\n return true;\n}\n\nexport const IBAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n const countryCode = field?.extra?.country;\n return {\n name: 'iban-validator',\n message: 'form.error.iban',\n test: (value: string): boolean => {\n if (!value) {\n return true;\n }\n return validateIban(value, countryCode);\n },\n };\n};\n\nconst ibanCountryCodesLengths = {\n AD: 24,\n AT: 20,\n AZ: 28,\n BH: 22,\n BY: 28,\n BE: 16,\n BA: 20,\n BR: 29,\n BG: 22,\n CR: 22,\n HR: 21,\n CY: 28,\n CZ: 24,\n DK: 18,\n DO: 28,\n EG: 29,\n SV: 28,\n EE: 20,\n FO: 18,\n FI: 18,\n FR: 27,\n GE: 22,\n DE: 22,\n GI: 23,\n GR: 27,\n GL: 18,\n GT: 28,\n VA: 22,\n HU: 28,\n IS: 26,\n IQ: 23,\n IE: 22,\n IL: 23,\n IT: 27,\n JO: 30,\n KZ: 20,\n XK: 20,\n KW: 30,\n LV: 21,\n LB: 28,\n LI: 21,\n LT: 20,\n LU: 20,\n MT: 31,\n MR: 27,\n MU: 30,\n MD: 24,\n MC: 27,\n ME: 22,\n NL: 18,\n MK: 19,\n NO: 15,\n PK: 24,\n PS: 29,\n PL: 28,\n PT: 25,\n QA: 29,\n RO: 24,\n LC: 32,\n SM: 27,\n ST: 25,\n SA: 24,\n RS: 22,\n SC: 31,\n SK: 24,\n SI: 19,\n ES: 24,\n SE: 24,\n CH: 21,\n TL: 23,\n TN: 24,\n TR: 26,\n UA: 29,\n AE: 23,\n GB: 22,\n VG: 24,\n};\n"],
4
+ "sourcesContent": ["import type { FieldSpec } from '@digigov/form/types';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\nexport function validateIban(value: string, countryCode: string): boolean {\n value = value.replace(/\\s/g, '').replace(/-/g, '');\n if (value.match(/^[0-9]*$/i)) {\n // this is for greek iban without the country code\n if (value.length !== 25) {\n return false;\n }\n } else {\n value = value.toUpperCase();\n if (countryCode) {\n if (!value.startsWith(countryCode.toUpperCase())) {\n return false;\n }\n if (value.length === ibanCountryCodesLengths[countryCode.toUpperCase()]) {\n return true;\n }\n }\n if (value.length !== 27) {\n // this is for greek iban\n return false;\n }\n }\n return true;\n}\n\nexport const IBAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n const countryCode = field?.extra?.country;\n return {\n name: 'iban-validator',\n message: 'form.error.iban',\n test: (value: string): boolean => {\n if (!value) {\n return true;\n }\n return validateIban(value, countryCode);\n },\n };\n};\n\nconst ibanCountryCodesLengths = {\n AD: 24,\n AT: 20,\n AZ: 28,\n BH: 22,\n BY: 28,\n BE: 16,\n BA: 20,\n BR: 29,\n BG: 22,\n CR: 22,\n HR: 21,\n CY: 28,\n CZ: 24,\n DK: 18,\n DO: 28,\n EG: 29,\n SV: 28,\n EE: 20,\n FO: 18,\n FI: 18,\n FR: 27,\n GE: 22,\n DE: 22,\n GI: 23,\n GR: 27,\n GL: 18,\n GT: 28,\n VA: 22,\n HU: 28,\n IS: 26,\n IQ: 23,\n IE: 22,\n IL: 23,\n IT: 27,\n JO: 30,\n KZ: 20,\n XK: 20,\n KW: 30,\n LV: 21,\n LB: 28,\n LI: 21,\n LT: 20,\n LU: 20,\n MT: 31,\n MR: 27,\n MU: 30,\n MD: 24,\n MC: 27,\n ME: 22,\n NL: 18,\n MK: 19,\n NO: 15,\n PK: 24,\n PS: 29,\n PL: 28,\n PT: 25,\n QA: 29,\n RO: 24,\n LC: 32,\n SM: 27,\n ST: 25,\n SA: 24,\n RS: 22,\n SC: 31,\n SK: 24,\n SI: 19,\n ES: 24,\n SE: 24,\n CH: 21,\n TL: 23,\n TN: 24,\n TR: 26,\n UA: 29,\n AE: 23,\n GB: 22,\n VG: 24,\n};\n"],
5
5
  "mappings": "AAEO,SAAS,aAAa,OAAe,aAA8B;AACxE,UAAQ,MAAM,QAAQ,OAAO,EAAE,EAAE,QAAQ,MAAM,EAAE;AACjD,MAAI,MAAM,MAAM,WAAW,GAAG;AAE5B,QAAI,MAAM,WAAW,IAAI;AACvB,aAAO;AAAA,IACT;AAAA,EACF,OAAO;AACL,YAAQ,MAAM,YAAY;AAC1B,QAAI,aAAa;AACf,UAAI,CAAC,MAAM,WAAW,YAAY,YAAY,CAAC,GAAG;AAChD,eAAO;AAAA,MACT;AACA,UAAI,MAAM,WAAW,wBAAwB,YAAY,YAAY,CAAC,GAAG;AACvE,eAAO;AAAA,MACT;AAAA,IACF;AACA,QAAI,MAAM,WAAW,IAAI;AAEvB,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,iBAAiB,CAAC,UAAsC;AACnE,QAAM,cAAc,OAAO,OAAO;AAClC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM,CAAC,UAA2B;AAChC,UAAI,CAAC,OAAO;AACV,eAAO;AAAA,MACT;AACA,aAAO,aAAa,OAAO,WAAW;AAAA,IACxC;AAAA,EACF;AACF;AAEA,MAAM,0BAA0B;AAAA,EAC9B,IAAI;AAAA,EACJ,IAAI;AAA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J,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,3 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
  export declare const IMAGE_DIMENSION_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/validators/utils/image.ts"],
4
- "sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nconst DEFAULT_IMAGE_MAX_HEIGHT_SIZE = 2000;\nconst DEFAULT_IMAGE_MAX_WIDTH_SIZE = 2000;\nconst DEFAULT_IMAGE_MIN_HEIGHT_SIZE = 100;\nconst DEFAULT_IMAGE_MIN_WIDTH_SIZE = 100;\n\nfunction getImageDimensions(\n file: File\n): Promise<{ width: number; height: number }> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = (event) => {\n const img = new Image();\n img.onload = () => {\n resolve({ width: img.width, height: img.height });\n };\n img.onerror = reject;\n const result = event?.target?.result;\n if (result && typeof result === 'string') {\n img.src = result;\n } else {\n reject(new Error('Invalid file format'));\n }\n };\n reader.onerror = reject;\n reader.readAsDataURL(file);\n });\n}\n\nexport const IMAGE_DIMENSION_VALIDATOR = (\n field: FieldSpec\n): ValidatorSchema => ({\n name: 'image-dimension-validator',\n message: (value: any) => {\n const minHeight =\n field?.extra?.limit?.minHeight || DEFAULT_IMAGE_MIN_HEIGHT_SIZE;\n const minWidth =\n field?.extra?.limit?.minWidth || DEFAULT_IMAGE_MIN_WIDTH_SIZE;\n const maxHeight =\n field?.extra?.limit?.maxHeight || DEFAULT_IMAGE_MAX_HEIGHT_SIZE;\n const maxWidth =\n field?.extra?.limit?.maxWidth || DEFAULT_IMAGE_MAX_WIDTH_SIZE;\n if (!value || value.length === 0) {\n return {\n name: 'image-validator',\n message: 'form.error.required',\n };\n } else {\n return {\n key: 'form.error.image.image_dimension_size',\n context: {\n maxHeight: maxHeight,\n maxWidth: maxWidth,\n minHeight: minHeight,\n minWidth: minWidth,\n },\n };\n }\n },\n test: async (value: File[]): Promise<boolean> => {\n if (!value || value.length === 0) {\n return true;\n }\n const file = value[0];\n const { width, height } = await getImageDimensions(file);\n const maxHeight =\n field?.extra?.limit?.maxHeight || DEFAULT_IMAGE_MAX_HEIGHT_SIZE;\n const maxWidth =\n field?.extra?.limit?.maxWidth || DEFAULT_IMAGE_MAX_WIDTH_SIZE;\n const minHeight =\n field?.extra?.limit?.minHeight || DEFAULT_IMAGE_MIN_HEIGHT_SIZE;\n const minWidth =\n field?.extra?.limit?.minWidth || DEFAULT_IMAGE_MIN_WIDTH_SIZE;\n if (!file) {\n return true;\n }\n try {\n if (height > maxHeight || width > maxWidth) {\n return false;\n }\n if (height < minHeight || width < minWidth) {\n return false;\n }\n return true;\n } catch (error) {\n console.error('Error getting image dimensions:', error);\n return false; // Return false in case of an error.\n }\n },\n});\n"],
4
+ "sourcesContent": ["import type { FieldSpec } from '@digigov/form/types';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\n\nconst DEFAULT_IMAGE_MAX_HEIGHT_SIZE = 2000;\nconst DEFAULT_IMAGE_MAX_WIDTH_SIZE = 2000;\nconst DEFAULT_IMAGE_MIN_HEIGHT_SIZE = 100;\nconst DEFAULT_IMAGE_MIN_WIDTH_SIZE = 100;\n\nfunction getImageDimensions(\n file: File\n): Promise<{ width: number; height: number }> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = (event) => {\n const img = new Image();\n img.onload = () => {\n resolve({ width: img.width, height: img.height });\n };\n img.onerror = reject;\n const result = event?.target?.result;\n if (result && typeof result === 'string') {\n img.src = result;\n } else {\n reject(new Error('Invalid file format'));\n }\n };\n reader.onerror = reject;\n reader.readAsDataURL(file);\n });\n}\n\nexport const IMAGE_DIMENSION_VALIDATOR = (\n field: FieldSpec\n): ValidatorSchema => ({\n name: 'image-dimension-validator',\n message: (value: any) => {\n const minHeight =\n field?.extra?.limit?.minHeight || DEFAULT_IMAGE_MIN_HEIGHT_SIZE;\n const minWidth =\n field?.extra?.limit?.minWidth || DEFAULT_IMAGE_MIN_WIDTH_SIZE;\n const maxHeight =\n field?.extra?.limit?.maxHeight || DEFAULT_IMAGE_MAX_HEIGHT_SIZE;\n const maxWidth =\n field?.extra?.limit?.maxWidth || DEFAULT_IMAGE_MAX_WIDTH_SIZE;\n if (!value || value.length === 0) {\n return {\n name: 'image-validator',\n message: 'form.error.required',\n };\n } else {\n return {\n key: 'form.error.image.image_dimension_size',\n context: {\n maxHeight: maxHeight,\n maxWidth: maxWidth,\n minHeight: minHeight,\n minWidth: minWidth,\n },\n };\n }\n },\n test: async (value: File[]): Promise<boolean> => {\n if (!value || value.length === 0) {\n return true;\n }\n const file = value[0];\n const { width, height } = await getImageDimensions(file);\n const maxHeight =\n field?.extra?.limit?.maxHeight || DEFAULT_IMAGE_MAX_HEIGHT_SIZE;\n const maxWidth =\n field?.extra?.limit?.maxWidth || DEFAULT_IMAGE_MAX_WIDTH_SIZE;\n const minHeight =\n field?.extra?.limit?.minHeight || DEFAULT_IMAGE_MIN_HEIGHT_SIZE;\n const minWidth =\n field?.extra?.limit?.minWidth || DEFAULT_IMAGE_MIN_WIDTH_SIZE;\n if (!file) {\n return true;\n }\n try {\n if (height > maxHeight || width > maxWidth) {\n return false;\n }\n if (height < minHeight || width < minWidth) {\n return false;\n }\n return true;\n } catch (error) {\n console.error('Error getting image dimensions:', error);\n return false; // Return false in case of an error.\n }\n },\n});\n"],
5
5
  "mappings": "AAGA,MAAM,gCAAgC;AACtC,MAAM,+BAA+B;AACrC,MAAM,gCAAgC;AACtC,MAAM,+BAA+B;AAErC,SAAS,m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AO,OAAO,OAAO,YAAY;AACnC,UAAM,YACJ,OAAO,OAAO,OAAO,aAAa;AACpC,UAAM,WACJ,OAAO,OAAO,OAAO,YAAY;AACnC,QAAI,CAAC,MAAM;AACT,aAAO;AAAA,IACT;AACA,QAAI;AACF,UAAI,SAAS,aAAa,QAAQ,UAAU;AAC1C,eAAO;AAAA,MACT;AACA,UAAI,SAAS,aAAa,QAAQ,UAAU;AAC1C,eAAO;AAAA,MACT;AACA,aAAO;AAAA,IACT,SAAS,OAAO;AACd,cAAQ,MAAM,mCAAmC,KAAK;AACtD,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import * as yup from 'yup';
2
- import { FieldSpec } from '@digigov/form/types';
3
- import { ValidatorSchema } from '@digigov/form/validators/types';
2
+ import type { FieldSpec } from '@digigov/form/types';
3
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
4
4
  export * from '@digigov/form/validators/utils/afm';
5
5
  export * from '@digigov/form/validators/utils/amka';
6
6
  export * from '@digigov/form/validators/utils/file';
@@ -83,7 +83,9 @@ function getYupObjectShape(fields, yupTypeMap, validatorRegistry) {
83
83
  }
84
84
  return yup.lazy(function() {
85
85
  const fieldSchemas = computeShape(
86
- Object.values(fields.current),
86
+ Object.values(fields.current).filter(
87
+ (f) => !f.key.includes(".")
88
+ ),
87
89
  yupTypeMap,
88
90
  validatorRegistry
89
91
  );
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/validators/utils/index.ts"],
4
- "sourcesContent": ["import * as yup from 'yup';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport * from '@digigov/form/validators/utils/afm';\nexport * from '@digigov/form/validators/utils/amka';\nexport * from '@digigov/form/validators/utils/file';\nexport * from '@digigov/form/validators/utils/iban';\nexport * from '@digigov/form/validators/utils/otp';\nexport * from '@digigov/form/validators/utils/image';\nexport * from '@digigov/form/validators/utils/phone';\nexport * from '@digigov/form/validators/utils/postal_code';\nexport * from '@digigov/form/validators/utils/uuid4';\nexport * from '@digigov/form/validators/utils/text_limit';\nexport * from '@digigov/form/validators/utils/date';\nexport * from '@digigov/form/validators/utils/datetime';\n\nexport function getYupField(field: FieldSpec, yupTypeMap: Record<string, any>) {\n const yupField = yupTypeMap[field?.type || 'string'] || yupTypeMap['string'];\n return yupField(field);\n}\nexport function computeShape(\n fields: FieldSpec[],\n yupTypeMap: Record<string, ValidatorSchema>,\n validatorRegistry: Record<string, ValidatorSchema[]> | undefined\n) {\n const fieldSchemas = {};\n const objectFields: Record<string, FieldSpec[]> = {};\n fields.forEach((field) => {\n let yupField = getYupField(field, yupTypeMap);\n if (field.condition) {\n for (const key in field.condition) {\n let then: any, otherwise: any;\n if (field.condition[key].then) {\n if (field.condition[key].then?.required === false) {\n then = yupField.nullable();\n } else if (field.condition[key].then?.required === true) {\n then = yupField.nullable().required('form.error.required');\n }\n }\n if (field.condition[key].else) {\n if (field.condition[key].else?.required === false) {\n otherwise = yupField.nullable();\n } else if (field.condition[key].else?.required === true) {\n otherwise = yupField.nullable().required('form.error.required');\n }\n }\n if (then || otherwise) {\n yupField = yupField.when(key, {\n is: (val) => {\n //@ts-ignore\n const is = field.condition[key].is;\n if (is === val || (Array.isArray(val) && val.includes(is))) {\n return true;\n } else {\n return false;\n }\n },\n then,\n otherwise,\n });\n }\n }\n } else if (field.required) {\n yupField = yupField.nullable().required('form.error.required');\n }\n if (validatorRegistry && field.type && validatorRegistry[field.type]) {\n validatorRegistry[field.type].forEach((validator: any) => {\n yupField = yupField.test(validator);\n });\n }\n if (field.validators) {\n field.validators.forEach((validator) => {\n yupField = yupField.test(validator);\n });\n }\n fieldSchemas[field.key] = yupField;\n });\n for (const objectKey in objectFields) {\n fieldSchemas[objectKey] = getYupObjectShape(\n objectFields[objectKey],\n yupTypeMap,\n validatorRegistry\n );\n }\n return fieldSchemas;\n}\n\nexport function getYupObjectShape(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fields: FieldSpec[] | any,\n yupTypeMap: Record<string, any>,\n validatorRegistry?: Record<string, ValidatorSchema[]>\n) {\n if (!fields.current) {\n const fieldSchemas = computeShape(fields, yupTypeMap, validatorRegistry);\n return yup.object().shape(fieldSchemas);\n }\n\n return yup.lazy(function () {\n const fieldSchemas = computeShape(\n Object.values(fields.current),\n yupTypeMap,\n validatorRegistry\n );\n return yup.object().shape(fieldSchemas);\n });\n}\n"],
5
- "mappings": "AAAA,YAAY,SAAS;AAIrB,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEP,SAAS,YAAY,OAAkB,YAAiC;AAC7E,QAAM,WAAW,WAAW,OAAO,QAAQ,QAAQ,KAAK,WAAW,QAAQ;AAC3E,SAAO,SAAS,KAAK;AACvB;AACO,SAAS,aACd,QACA,YACA,mBACA;AACA,QAAM,eAAe,CAAC;AACtB,QAAM,eAA4C,CAAC;AACnD,SAAO,QAAQ,CAAC,UAAU;AACxB,QAAI,WAAW,YAAY,OAAO,UAAU;AAC5C,QAAI,MAAM,WAAW;AACnB,iBAAW,OAAO,MAAM,WAAW;AACjC,YAAI,MAAW;AACf,YAAI,MAAM,UAAU,GAAG,EAAE,MAAM;AAC7B,cAAI,MAAM,UAAU,GAAG,EAAE,MAAM,aAAa,OAAO;AACjD,mBAAO,SAAS,SAAS;AAAA,UAC3B,WAAW,MAAM,UAAU,GAAG,EAAE,MAAM,aAAa,MAAM;AACvD,mBAAO,SAAS,SAAS,EAAE,SAAS,qBAAqB;AAAA,UAC3D;AAAA,QACF;AACA,YAAI,MAAM,UAAU,GAAG,EAAE,MAAM;AAC7B,cAAI,MAAM,UAAU,GAAG,EAAE,MAAM,aAAa,OAAO;AACjD,wBAAY,SAAS,SAAS;AAAA,UAChC,WAAW,MAAM,UAAU,GA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,OAAO;AAAA,MAC5B;AAAA,MACA;AAAA,IACF;AACA,WAAO,IAAI,OAAO,EAAE,MAAM,YAAY;AAAA,EACxC,CAAC;AACH;",
4
+ "sourcesContent": ["import * as yup from 'yup';\nimport type { FieldSpec } from '@digigov/form/types';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport * from '@digigov/form/validators/utils/afm';\nexport * from '@digigov/form/validators/utils/amka';\nexport * from '@digigov/form/validators/utils/file';\nexport * from '@digigov/form/validators/utils/iban';\nexport * from '@digigov/form/validators/utils/otp';\nexport * from '@digigov/form/validators/utils/image';\nexport * from '@digigov/form/validators/utils/phone';\nexport * from '@digigov/form/validators/utils/postal_code';\nexport * from '@digigov/form/validators/utils/uuid4';\nexport * from '@digigov/form/validators/utils/text_limit';\nexport * from '@digigov/form/validators/utils/date';\nexport * from '@digigov/form/validators/utils/datetime';\n\nexport function getYupField(field: FieldSpec, yupTypeMap: Record<string, any>) {\n const yupField = yupTypeMap[field?.type || 'string'] || yupTypeMap['string'];\n return yupField(field);\n}\nexport function computeShape(\n fields: FieldSpec[],\n yupTypeMap: Record<string, ValidatorSchema>,\n validatorRegistry: Record<string, ValidatorSchema[]> | undefined\n) {\n const fieldSchemas = {};\n const objectFields: Record<string, FieldSpec[]> = {};\n fields.forEach((field) => {\n let yupField = getYupField(field, yupTypeMap);\n if (field.condition) {\n for (const key in field.condition) {\n let then: any, otherwise: any;\n if (field.condition[key].then) {\n if (field.condition[key].then?.required === false) {\n then = yupField.nullable();\n } else if (field.condition[key].then?.required === true) {\n then = yupField.nullable().required('form.error.required');\n }\n }\n if (field.condition[key].else) {\n if (field.condition[key].else?.required === false) {\n otherwise = yupField.nullable();\n } else if (field.condition[key].else?.required === true) {\n otherwise = yupField.nullable().required('form.error.required');\n }\n }\n if (then || otherwise) {\n yupField = yupField.when(key, {\n is: (val) => {\n //@ts-ignore\n const is = field.condition[key].is;\n if (is === val || (Array.isArray(val) && val.includes(is))) {\n return true;\n } else {\n return false;\n }\n },\n then,\n otherwise,\n });\n }\n }\n } else if (field.required) {\n yupField = yupField.nullable().required('form.error.required');\n }\n if (validatorRegistry && field.type && validatorRegistry[field.type]) {\n validatorRegistry[field.type].forEach((validator: any) => {\n yupField = yupField.test(validator);\n });\n }\n if (field.validators) {\n field.validators.forEach((validator) => {\n yupField = yupField.test(validator);\n });\n }\n fieldSchemas[field.key] = yupField;\n });\n for (const objectKey in objectFields) {\n fieldSchemas[objectKey] = getYupObjectShape(\n objectFields[objectKey],\n yupTypeMap,\n validatorRegistry\n );\n }\n return fieldSchemas;\n}\n\nexport function getYupObjectShape(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fields: FieldSpec[] | any,\n yupTypeMap: Record<string, any>,\n validatorRegistry?: Record<string, ValidatorSchema[]>\n) {\n if (!fields.current) {\n const fieldSchemas = computeShape(fields, yupTypeMap, validatorRegistry);\n return yup.object().shape(fieldSchemas);\n }\n\n return yup.lazy(function () {\n const fieldSchemas = computeShape(\n Object.values(fields.current).filter(\n (f: FieldSpec) => !f.key.includes('.')\n ) as FieldSpec[],\n yupTypeMap,\n validatorRegistry\n );\n return yup.object().shape(fieldSchemas);\n });\n}\n"],
5
+ "mappings": "AAAA,YAAY,SAAS;AAIrB,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEP,SAAS,YAAY,OAAkB,YAAiC;AAC7E,QAAM,WAAW,WAAW,OAAO,QAAQ,QAAQ,KAAK,WAAW,QAAQ;AAC3E,SAAO,SAAS,KAAK;AACvB;AACO,SAAS,aACd,QACA,YACA,mBACA;AACA,QAAM,eAAe,CAAC;AACtB,QAAM,eAA4C,CAAC;AACnD,SAAO,QAAQ,CAAC,UAAU;AACxB,QAAI,WAAW,YAAY,OAAO,UAAU;AAC5C,QAAI,MAAM,WAAW;AACnB,iBAAW,OAAO,MAAM,WAAW;AACjC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,iBAAa,MAAM,GAAG,IAAI;AAAA,EAC5B,CAAC;AACD,aAAW,aAAa,cAAc;AACpC,iBAAa,SAAS,IAAI;AAAA,MACxB,aAAa,SAAS;AAAA,MACtB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,kBAEd,QACA,YACA,mBACA;AACA,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,eAAe,aAAa,QAAQ,YAAY,iBAAiB;AACvE,WAAO,IAAI,OAAO,EAAE,MAAM,YAAY;AAAA,EACxC;AAEA,SAAO,IAAI,KAAK,WAAY;AAC1B,UAAM,eAAe;AAAA,MACnB,OAAO,OAAO,OAAO,OAAO,EAAE;AAAA,QAC5B,CAAC,MAAiB,CAAC,EAAE,IAAI,SAAS,GAAG;AAAA,MACvC;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,WAAO,IAAI,OAAO,EAAE,MAAM,YAAY;AAAA,EACxC,CAAC;AACH;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,3 @@
1
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
2
2
  export declare function validateIntNumber(number: number): boolean;
3
3
  export declare const INT_VALIDATOR: () => ValidatorSchema;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/validators/utils/int.ts"],
4
- "sourcesContent": ["import { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport function validateIntNumber(number: number): boolean {\n if (number === undefined) {\n return false;\n } else {\n return Number.isInteger(number) && Number(number) > 0;\n }\n}\n\nexport const INT_VALIDATOR = (): ValidatorSchema => {\n return {\n name: 'int-validator',\n message: 'form.error.positive_integer_number',\n test: (value: number): boolean => {\n if (value === undefined) {\n return true;\n }\n return validateIntNumber(value);\n },\n };\n};\n"],
4
+ "sourcesContent": ["import type { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport function validateIntNumber(number: number): boolean {\n if (number === undefined) {\n return false;\n } else {\n return Number.isInteger(number) && Number(number) > 0;\n }\n}\n\nexport const INT_VALIDATOR = (): ValidatorSchema => {\n return {\n name: 'int-validator',\n message: 'form.error.positive_integer_number',\n test: (value: number): boolean => {\n if (value === undefined) {\n return true;\n }\n return validateIntNumber(value);\n },\n };\n};\n"],
5
5
  "mappings": "AAEO,SAAS,kBAAkB,QAAyB;AACzD,MAAI,WAAW,QAAW;AACxB,WAAO;AAAA,EACT,OAAO;AACL,WAAO,OAAO,UAAU,MAAM,KAAK,OAAO,MAAM,IAAI;AAAA,EACtD;AACF;AAEO,MAAM,gBAAgB,MAAuB;AAClD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM,CAAC,UAA2B;AAChC,UAAI,UAAU,QAAW;AACvB,eAAO;AAAA,MACT;AACA,aAAO,kBAAkB,KAAK;AAAA,IAChC;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,3 @@
1
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
2
2
  export declare function validateNumber(number: number): boolean;
3
3
  export declare const NUMBER_VALIDATOR: () => ValidatorSchema;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/validators/utils/number.ts"],
4
- "sourcesContent": ["import { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport function validateNumber(number: number): boolean {\n return !Number.isNaN(number);\n}\n\nexport const NUMBER_VALIDATOR = (): ValidatorSchema => {\n return {\n name: 'number-validator',\n message: 'form.error.number',\n test: (value: number): boolean => {\n if (value === undefined) {\n return true;\n }\n return validateNumber(value);\n },\n };\n};\n"],
4
+ "sourcesContent": ["import type { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport function validateNumber(number: number): boolean {\n return !Number.isNaN(number);\n}\n\nexport const NUMBER_VALIDATOR = (): ValidatorSchema => {\n return {\n name: 'number-validator',\n message: 'form.error.number',\n test: (value: number): boolean => {\n if (value === undefined) {\n return true;\n }\n return validateNumber(value);\n },\n };\n};\n"],
5
5
  "mappings": "AAEO,SAAS,eAAe,QAAyB;AACtD,SAAO,CAAC,OAAO,MAAM,MAAM;AAC7B;AAEO,MAAM,mBAAmB,MAAuB;AACrD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM,CAAC,UAA2B;AAChC,UAAI,UAAU,QAAW;AACvB,eAAO;AAAA,MACT;AACA,aAAO,eAAe,KAAK;AAAA,IAC7B;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
  export declare function validateOtp(value: string, maxLength: number): boolean;
4
4
  export declare const OTP_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/validators/utils/otp.ts"],
4
- "sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\nexport function validateOtp(value: string, maxLength: number): boolean {\n if (value.length === maxLength) {\n return true;\n } else {\n return false;\n }\n}\n\nexport const OTP_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n const maxLength = field?.maxLength;\n return {\n name: 'otp-validator',\n message: {\n key: 'form.error.otp.less_than',\n context: {\n maxLength: field?.maxLength,\n },\n },\n test: (value: string): boolean => {\n if (!value) {\n return true;\n }\n return validateOtp(value, maxLength as number);\n },\n };\n};\n"],
4
+ "sourcesContent": ["import type { FieldSpec } from '@digigov/form/types';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\nexport function validateOtp(value: string, maxLength: number): boolean {\n if (value.length === maxLength) {\n return true;\n } else {\n return false;\n }\n}\n\nexport const OTP_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n const maxLength = field?.maxLength;\n return {\n name: 'otp-validator',\n message: {\n key: 'form.error.otp.less_than',\n context: {\n maxLength: field?.maxLength,\n },\n },\n test: (value: string): boolean => {\n if (!value) {\n return true;\n }\n return validateOtp(value, maxLength as number);\n },\n };\n};\n"],
5
5
  "mappings": "AAEO,SAAS,YAAY,OAAe,WAA4B;AACrE,MAAI,MAAM,WAAW,WAAW;AAC9B,WAAO;AAAA,EACT,OAAO;AACL,WAAO;AAAA,EACT;AACF;AAEO,MAAM,gBAAgB,CAAC,UAAsC;AAClE,QAAM,YAAY,OAAO;AACzB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,KAAK;AAAA,MACL,SAAS;AAAA,QACP,WAAW,OAAO;AAAA,MACpB;AAAA,IACF;AAAA,IACA,MAAM,CAAC,UAA2B;AAChC,UAAI,CAAC,OAAO;AACV,eAAO;AAAA,MACT;AACA,aAAO,YAAY,OAAO,SAAmB;AAAA,IAC/C;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,5 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
  export type PhoneNumberType = 'landline' | 'mobile' | null;
4
4
  export declare function discoverPhoneType(phoneNumber: string, config: any): string;
5
5
  export declare function validatePhoneNumber(phoneNumber: string, countries?: string[], typeOfPhoneNumber?: PhoneNumberType): boolean;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/validators/utils/phone.ts"],
4
- "sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport type PhoneNumberType = 'landline' | 'mobile' | null;\n// add more countries from here libphonenumber-js/metadata.full.json\nconst countryPhoneData = {\n GR: [\n '30',\n '00',\n '5005000\\\\d{3}|8\\\\d{9,11}|(?:[269]\\\\d|70)\\\\d{8}',\n [10, 11, 12],\n [\n ['(\\\\d{2})(\\\\d{4})(\\\\d{4})', '$1 $2 $3', ['21|7']],\n [\n '(\\\\d{4})(\\\\d{6})',\n '$1 $2',\n ['2(?:2|3[2-57-9]|4[2-469]|5[2-59]|6[2-9]|7[2-69]|8[2-49])|5'],\n ],\n ['(\\\\d{3})(\\\\d{3})(\\\\d{4})', '$1 $2 $3', ['[2689]']],\n ['(\\\\d{3})(\\\\d{3,4})(\\\\d{5})', '$1 $2 $3', ['8']],\n ],\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n [\n [\n '2(?:1\\\\d\\\\d|2(?:2[1-46-9]|[36][1-8]|4[1-7]|5[1-4]|7[1-5]|[89][1-9])|3(?:1\\\\d|2[1-57]|[35][1-3]|4[13]|7[1-7]|8[124-6]|9[1-79])|4(?:1\\\\d|2[1-8]|3[1-4]|4[13-5]|6[1-578]|9[1-5])|5(?:1\\\\d|[29][1-4]|3[1-5]|4[124]|5[1-6])|6(?:1\\\\d|[269][1-6]|3[1245]|4[1-7]|5[13-9]|7[14]|8[1-5])|7(?:1\\\\d|2[1-5]|3[1-6]|4[1-7]|5[1-57]|6[135]|9[125-7])|8(?:1\\\\d|2[1-5]|[34][1-4]|9[1-57]))\\\\d{6}',\n [10],\n ],\n ['68[57-9]\\\\d{7}|(?:69|94)\\\\d{8}', [10]],\n ['800\\\\d{7,9}'],\n ['90[19]\\\\d{7}', [10]],\n ['70\\\\d{8}', [10]],\n 0,\n ['5005000\\\\d{3}', [10]],\n 0,\n 0,\n ['8(?:0[16]|12|[27]5|50)\\\\d{7}', [10]],\n ],\n ],\n};\n\nfunction expandPhoneNumberStructure(compressed) {\n const countries = Object.keys(compressed);\n const expanded: any = {};\n for (const country of countries) {\n expanded[country] = {\n fixedLine: {\n possibleLengths: {\n _national: compressed[country][3].map(String),\n },\n nationalNumberPattern: compressed[country][11][0][0],\n },\n mobile: {\n nationalNumberPattern: compressed[country][11][1][0],\n },\n tollFree: {\n nationalNumberPattern: compressed[country][11][2][0],\n },\n premiumRate: {\n nationalNumberPattern: compressed[country][11][3][0],\n },\n sharedCost: {\n nationalNumberPattern: compressed[country][11][9][0],\n },\n personalNumber: {\n nationalNumberPattern: compressed[country][11][4][0],\n },\n uan: {\n nationalNumberPattern: compressed[country][11][6][0],\n },\n id: country,\n countryCode: compressed[country][0],\n internationalPrefix: compressed[country][1],\n };\n }\n return expanded;\n}\nconst PHONENUMBER_SPEC = expandPhoneNumberStructure(countryPhoneData);\nexport function discoverPhoneType(phoneNumber: string, config: any): string {\n const cleanNumber = phoneNumber\n .replace(/\\D/g, '')\n .replace(/\\s/g, '')\n .replace(/^\\+/, '')\n .replace(new RegExp('^' + config.internationalPrefix, ''), '')\n .replace(new RegExp('^' + config.countryCode, ''), '');\n const categories = {\n landline: config.fixedLine,\n mobile: config.mobile,\n 'toll-free': config.tollFree,\n 'premium-rate': config.premiumRate,\n };\n\n for (const [categoryName, categoryDetails] of Object.entries(categories)) {\n const pattern = new RegExp(\n '^(' + categoryDetails.nationalNumberPattern.replace(/\\s/g, '') + ')$',\n ''\n );\n if (cleanNumber.match(pattern)) {\n return categoryName; // Returns the category name if the number matches the pattern\n }\n }\n\n // If no category matches, return 'Unknown'\n return 'unknown';\n}\nfunction getNumberType(phoneNumber: string, country: string) {\n const spec = PHONENUMBER_SPEC[country.toUpperCase()];\n if (!spec) {\n throw new Error(`Country ${country} is not supported`);\n }\n const type = discoverPhoneType(phoneNumber, spec);\n return type;\n}\n\nfunction isPhoneNumberValid(\n phoneNumber: string,\n countries: string[],\n types = ['mobile', 'landline']\n) {\n return countries.some((country) => {\n const numberType = getNumberType(phoneNumber, country);\n if (numberType && types.includes(numberType)) {\n return true;\n }\n return false;\n });\n}\nfunction isNumberOfType(phoneNumber: string, country: string, type: string) {\n const numberType = getNumberType(phoneNumber, country);\n if (numberType === type) {\n return true;\n }\n return false;\n}\nexport function validatePhoneNumber(\n phoneNumber: string,\n countries: string[] = ['gr'],\n typeOfPhoneNumber?: PhoneNumberType\n): boolean {\n if (!countries || countries.length === 0) {\n return true;\n }\n return isPhoneNumberValid(\n phoneNumber,\n countries,\n typeOfPhoneNumber ? [typeOfPhoneNumber] : undefined\n );\n}\n\nfunction validateMobile(value): boolean {\n return isNumberOfType(value, 'gr', 'mobile');\n}\n\nexport const MOBILE_PHONE_VALIDATOR = {\n name: 'mobile-phone-validator',\n message: 'form.error.mobile_phone',\n test: (value): boolean => {\n if (value) {\n return validateMobile(value);\n }\n return true;\n },\n};\n\nexport const PHONE_NUMBER_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n const countryCodes = field?.extra?.countries;\n const typeOfPhone: PhoneNumberType | null = field?.extra?.phoneType;\n return {\n name: 'phone-number-validator',\n message: (): string => {\n if (typeOfPhone === 'mobile') {\n return 'form.error.mobile_phone';\n }\n if (typeOfPhone === 'landline') {\n return 'form.error.landline';\n } else {\n return 'form.error.phone_number';\n }\n },\n test: (value: string): boolean => {\n if (!value) {\n return true;\n }\n return validatePhoneNumber(value, countryCodes, typeOfPhone);\n },\n };\n};\n"],
4
+ "sourcesContent": ["import type { FieldSpec } from '@digigov/form/types';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport type PhoneNumberType = 'landline' | 'mobile' | null;\n// add more countries from here libphonenumber-js/metadata.full.json\nconst countryPhoneData = {\n GR: [\n '30',\n '00',\n '5005000\\\\d{3}|8\\\\d{9,11}|(?:[269]\\\\d|70)\\\\d{8}',\n [10, 11, 12],\n [\n ['(\\\\d{2})(\\\\d{4})(\\\\d{4})', '$1 $2 $3', ['21|7']],\n [\n '(\\\\d{4})(\\\\d{6})',\n '$1 $2',\n ['2(?:2|3[2-57-9]|4[2-469]|5[2-59]|6[2-9]|7[2-69]|8[2-49])|5'],\n ],\n ['(\\\\d{3})(\\\\d{3})(\\\\d{4})', '$1 $2 $3', ['[2689]']],\n ['(\\\\d{3})(\\\\d{3,4})(\\\\d{5})', '$1 $2 $3', ['8']],\n ],\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n [\n [\n '2(?:1\\\\d\\\\d|2(?:2[1-46-9]|[36][1-8]|4[1-7]|5[1-4]|7[1-5]|[89][1-9])|3(?:1\\\\d|2[1-57]|[35][1-3]|4[13]|7[1-7]|8[124-6]|9[1-79])|4(?:1\\\\d|2[1-8]|3[1-4]|4[13-5]|6[1-578]|9[1-5])|5(?:1\\\\d|[29][1-4]|3[1-5]|4[124]|5[1-6])|6(?:1\\\\d|[269][1-6]|3[1245]|4[1-7]|5[13-9]|7[14]|8[1-5])|7(?:1\\\\d|2[1-5]|3[1-6]|4[1-7]|5[1-57]|6[135]|9[125-7])|8(?:1\\\\d|2[1-5]|[34][1-4]|9[1-57]))\\\\d{6}',\n [10],\n ],\n ['68[57-9]\\\\d{7}|(?:69|94)\\\\d{8}', [10]],\n ['800\\\\d{7,9}'],\n ['90[19]\\\\d{7}', [10]],\n ['70\\\\d{8}', [10]],\n 0,\n ['5005000\\\\d{3}', [10]],\n 0,\n 0,\n ['8(?:0[16]|12|[27]5|50)\\\\d{7}', [10]],\n ],\n ],\n};\n\nfunction expandPhoneNumberStructure(compressed) {\n const countries = Object.keys(compressed);\n const expanded: any = {};\n for (const country of countries) {\n expanded[country] = {\n fixedLine: {\n possibleLengths: {\n _national: compressed[country][3].map(String),\n },\n nationalNumberPattern: compressed[country][11][0][0],\n },\n mobile: {\n nationalNumberPattern: compressed[country][11][1][0],\n },\n tollFree: {\n nationalNumberPattern: compressed[country][11][2][0],\n },\n premiumRate: {\n nationalNumberPattern: compressed[country][11][3][0],\n },\n sharedCost: {\n nationalNumberPattern: compressed[country][11][9][0],\n },\n personalNumber: {\n nationalNumberPattern: compressed[country][11][4][0],\n },\n uan: {\n nationalNumberPattern: compressed[country][11][6][0],\n },\n id: country,\n countryCode: compressed[country][0],\n internationalPrefix: compressed[country][1],\n };\n }\n return expanded;\n}\nconst PHONENUMBER_SPEC = expandPhoneNumberStructure(countryPhoneData);\nexport function discoverPhoneType(phoneNumber: string, config: any): string {\n const cleanNumber = phoneNumber\n .replace(/\\D/g, '')\n .replace(/\\s/g, '')\n .replace(/^\\+/, '')\n .replace(new RegExp('^' + config.internationalPrefix, ''), '')\n .replace(new RegExp('^' + config.countryCode, ''), '');\n const categories = {\n landline: config.fixedLine,\n mobile: config.mobile,\n 'toll-free': config.tollFree,\n 'premium-rate': config.premiumRate,\n };\n\n for (const [categoryName, categoryDetails] of Object.entries(categories)) {\n const pattern = new RegExp(\n '^(' + categoryDetails.nationalNumberPattern.replace(/\\s/g, '') + ')$',\n ''\n );\n if (cleanNumber.match(pattern)) {\n return categoryName; // Returns the category name if the number matches the pattern\n }\n }\n\n // If no category matches, return 'Unknown'\n return 'unknown';\n}\nfunction getNumberType(phoneNumber: string, country: string) {\n const spec = PHONENUMBER_SPEC[country.toUpperCase()];\n if (!spec) {\n throw new Error(`Country ${country} is not supported`);\n }\n const type = discoverPhoneType(phoneNumber, spec);\n return type;\n}\n\nfunction isPhoneNumberValid(\n phoneNumber: string,\n countries: string[],\n types = ['mobile', 'landline']\n) {\n return countries.some((country) => {\n const numberType = getNumberType(phoneNumber, country);\n if (numberType && types.includes(numberType)) {\n return true;\n }\n return false;\n });\n}\nfunction isNumberOfType(phoneNumber: string, country: string, type: string) {\n const numberType = getNumberType(phoneNumber, country);\n if (numberType === type) {\n return true;\n }\n return false;\n}\nexport function validatePhoneNumber(\n phoneNumber: string,\n countries: string[] = ['gr'],\n typeOfPhoneNumber?: PhoneNumberType\n): boolean {\n if (!countries || countries.length === 0) {\n return true;\n }\n return isPhoneNumberValid(\n phoneNumber,\n countries,\n typeOfPhoneNumber ? [typeOfPhoneNumber] : undefined\n );\n}\n\nfunction validateMobile(value): boolean {\n return isNumberOfType(value, 'gr', 'mobile');\n}\n\nexport const MOBILE_PHONE_VALIDATOR = {\n name: 'mobile-phone-validator',\n message: 'form.error.mobile_phone',\n test: (value): boolean => {\n if (value) {\n return validateMobile(value);\n }\n return true;\n },\n};\n\nexport const PHONE_NUMBER_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n const countryCodes = field?.extra?.countries;\n const typeOfPhone: PhoneNumberType | null = field?.extra?.phoneType;\n return {\n name: 'phone-number-validator',\n message: (): string => {\n if (typeOfPhone === 'mobile') {\n return 'form.error.mobile_phone';\n }\n if (typeOfPhone === 'landline') {\n return 'form.error.landline';\n } else {\n return 'form.error.phone_number';\n }\n },\n test: (value: string): boolean => {\n if (!value) {\n return true;\n }\n return validatePhoneNumber(value, countryCodes, typeOfPhone);\n },\n };\n};\n"],
5
5
  "mappings": "AAKA,MAAM,mBAAmB;AAAA,EACvB,IAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,CAAC,IAAI,IAAI,EAAE;AAAA,IACX;AAAA,MACE,CAAC,4BAA4B,YAAY,CAAC,MAAM,CAAC;AAAA,MACjD;AAAA,QACE;AAAA,QACA;AAAA,QACA,CAAC,4DAA4D;AAAA,MAC/D;AAAA,MACA,CAAC,4BAA4B,YAAY,CAAC,QAAQ,CAAC;AAAA,MACnD,CAAC,8BAA8B,YAAY,CAAC,GAAG,CAAC;AAAA,IAClD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE;AAAA,QACE;AAAA,QACA,CAAC,EAAE;AAAA,MACL;AAAA,MACA,CAAC,kCAAkC,CAAC,EAAE,CAAC;AAAA,MACvC,CAAC,aAAa;AAAA,MACd,CAAC,gBAAgB,CAAC,EAAE,CAAC;AAAA,MACrB,CAAC,YAAY,CAAC,EAAE,CAAC;AAAA,MACjB;AAAA,MACA,CAAC,iBAAiB,CAAC,EAAE,CAAC;AAAA,MACtB;AAAA,MACA;AAAA,MACA,CAAC,gCAAgC,CAAC,EAAE,CAAC;AAAA,IACvC;AAAA,EACF;AACF;AAEA,SAAS,2BAA2B,YAAY;AAC9C,QAAM,YAAY,OAAO,KAAK,UAAU;AACx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e,OAAgB;AACtC,SAAO,eAAe,OAAO,MAAM,QAAQ;AAC7C;AAEO,MAAM,yBAAyB;AAAA,EACpC,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM,CAAC,UAAmB;AACxB,QAAI,OAAO;AACT,aAAO,eAAe,KAAK;AAAA,IAC7B;AACA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,yBAAyB,CAAC,UAAsC;AAC3E,QAAM,eAAe,OAAO,OAAO;AACnC,QAAM,cAAsC,OAAO,OAAO;AAC1D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS,MAAc;AACrB,UAAI,gBAAgB,UAAU;AAC5B,eAAO;AAAA,MACT;AACA,UAAI,gBAAgB,YAAY;AAC9B,eAAO;AAAA,MACT,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,MAAM,CAAC,UAA2B;AAChC,UAAI,CAAC,OAAO;AACV,eAAO;AAAA,MACT;AACA,aAAO,oBAAoB,OAAO,cAAc,WAAW;AAAA,IAC7D;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
  export declare function validatePostalCode(number: string, countries: string[]): boolean;
4
4
  export declare const POSTALCODE_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/validators/utils/postal_code.ts"],
4
- "sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nconst CODE_REGEX = /^[12345678][0-9]{4}$/;\nexport function validatePostalCode(\n number: string,\n countries: string[]\n): boolean {\n if (!countries) {\n return false;\n } else {\n if (countries.length === 1 && countries[0].toUpperCase() === 'GR') {\n // Greek postal code must be 5 digits long and shouldn't start with 0 or 9.\n return CODE_REGEX.test(number);\n } else {\n return true;\n }\n }\n}\n\nexport const POSTALCODE_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n const countryCode = field?.extra?.countries;\n return {\n name: 'postal-code-validator',\n message: 'form.error.postalCode',\n test: (value: string): boolean => {\n if (!value) {\n return true;\n }\n return validatePostalCode(value, countryCode);\n },\n };\n};\n"],
4
+ "sourcesContent": ["import type { FieldSpec } from '@digigov/form/types';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\n\nconst CODE_REGEX = /^[12345678][0-9]{4}$/;\nexport function validatePostalCode(\n number: string,\n countries: string[]\n): boolean {\n if (!countries) {\n return false;\n } else {\n if (countries.length === 1 && countries[0].toUpperCase() === 'GR') {\n // Greek postal code must be 5 digits long and shouldn't start with 0 or 9.\n return CODE_REGEX.test(number);\n } else {\n return true;\n }\n }\n}\n\nexport const POSTALCODE_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n const countryCode = field?.extra?.countries;\n return {\n name: 'postal-code-validator',\n message: 'form.error.postalCode',\n test: (value: string): boolean => {\n if (!value) {\n return true;\n }\n return validatePostalCode(value, countryCode);\n },\n };\n};\n"],
5
5
  "mappings": "AAGA,MAAM,aAAa;AACZ,SAAS,mBACd,QACA,WACS;AACT,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT,OAAO;AACL,QAAI,UAAU,WAAW,KAAK,UAAU,CAAC,EAAE,YAAY,MAAM,MAAM;AAEjE,aAAO,WAAW,KAAK,MAAM;AAAA,IAC/B,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,MAAM,uBAAuB,CAAC,UAAsC;AACzE,QAAM,cAAc,OAAO,OAAO;AAClC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM,CAAC,UAA2B;AAChC,UAAI,CAAC,OAAO;AACV,eAAO;AAAA,MACT;AACA,aAAO,mBAAmB,OAAO,WAAW;AAAA,IAC9C;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- import { FieldSpec } from '@digigov/form/types';
2
- import { ValidatorSchema } from '@digigov/form/validators/types';
1
+ import type { FieldSpec } from '@digigov/form/types';
2
+ import type { ValidatorSchema } from '@digigov/form/validators/types';
3
3
  export declare function validateText(value: string, min: number, max: number): boolean;
4
4
  export declare const TEXT_LIMIT_VALIDATOR: (field: FieldSpec) => ValidatorSchema;