@digigov/form 1.0.0-a131264d → 1.0.0-b0737a96

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 (447) hide show
  1. package/Field/FieldBase.js +14 -31
  2. package/Field/FieldBaseContainer.js +19 -41
  3. package/Field/FieldConditional.js +14 -33
  4. package/Field/index.js +18 -45
  5. package/Field/package.json +6 -0
  6. package/Field/types.js +1 -5
  7. package/Field/utils.js +30 -63
  8. package/FieldArray/FieldArray.stories.js +5 -42
  9. package/FieldArray/__stories__/Default.js +11 -32
  10. package/FieldArray/__stories__/WithExactLength.js +11 -32
  11. package/FieldArray/index.js +19 -41
  12. package/FieldArray/package.json +6 -0
  13. package/FieldObject/index.js +16 -41
  14. package/FieldObject/package.json +6 -0
  15. package/Fieldset/FieldsetWithContext.js +13 -35
  16. package/Fieldset/index.js +21 -51
  17. package/Fieldset/package.json +6 -0
  18. package/Fieldset/types.js +1 -5
  19. package/Form.stories.js +2 -9
  20. package/FormBuilder/FormBuilder.js +33 -62
  21. package/FormBuilder/FormBuilder.stories.js +4 -28
  22. package/FormBuilder/__stories__/Default.js +8 -29
  23. package/FormBuilder/index.js +2 -11
  24. package/FormBuilder/package.json +6 -0
  25. package/FormContext.js +3 -12
  26. package/MultiplicityField/MultiplicityField.stories.js +9 -98
  27. package/MultiplicityField/__stories__/Default.js +11 -32
  28. package/MultiplicityField/__stories__/PreviewDisplay.js +29 -52
  29. package/MultiplicityField/__stories__/WithExactLength.js +11 -32
  30. package/MultiplicityField/__stories__/WithMaxLength.js +11 -32
  31. package/MultiplicityField/__stories__/WithMinAndMaxLength.js +11 -32
  32. package/MultiplicityField/__stories__/WithMinLength.js +11 -32
  33. package/MultiplicityField/add-objects.js +25 -49
  34. package/MultiplicityField/index.js +26 -55
  35. package/MultiplicityField/package.json +6 -0
  36. package/Questions/Questions.js +14 -35
  37. package/Questions/Questions.stories.js +4 -28
  38. package/Questions/QuestionsContext.js +3 -12
  39. package/Questions/Step/ReviewStep.js +21 -47
  40. package/Questions/Step/Step.js +18 -42
  41. package/Questions/Step/StepArrayReview.js +23 -52
  42. package/Questions/Step/StepContext.js +3 -13
  43. package/Questions/Step/StepDescription.js +14 -42
  44. package/Questions/Step/StepForm.js +19 -45
  45. package/Questions/Step/StepQuote.js +8 -23
  46. package/Questions/Step/StepTitle.js +17 -48
  47. package/Questions/Step/getAddMoreFields.js +2 -11
  48. package/Questions/Step/index.js +13 -170
  49. package/Questions/Step/package.json +6 -0
  50. package/Questions/Step/types.js +1 -5
  51. package/Questions/__stories__/Default.js +24 -51
  52. package/Questions/getNextStep.js +1 -8
  53. package/Questions/index.js +3 -25
  54. package/Questions/index.spec.js +12 -23
  55. package/Questions/package.json +6 -0
  56. package/Questions/types.js +1 -5
  57. package/{es → cjs}/Field/FieldBase.js +31 -14
  58. package/cjs/Field/FieldBaseContainer.js +65 -0
  59. package/cjs/Field/FieldConditional.js +81 -0
  60. package/cjs/Field/index.js +103 -0
  61. package/cjs/Field/types.js +5 -0
  62. package/{es → cjs}/Field/utils.js +63 -30
  63. package/cjs/FieldArray/FieldArray.stories.js +45 -0
  64. package/cjs/FieldArray/__stories__/Default.js +111 -0
  65. package/cjs/FieldArray/__stories__/WithExactLength.js +111 -0
  66. package/cjs/FieldArray/index.js +87 -0
  67. package/cjs/FieldObject/index.js +83 -0
  68. package/cjs/Fieldset/FieldsetWithContext.js +63 -0
  69. package/cjs/Fieldset/index.js +64 -0
  70. package/cjs/Fieldset/types.js +5 -0
  71. package/cjs/Form.stories.js +10 -0
  72. package/{es → cjs}/FormBuilder/FormBuilder.js +62 -33
  73. package/cjs/FormBuilder/FormBuilder.stories.js +31 -0
  74. package/cjs/FormBuilder/__stories__/Default.js +49 -0
  75. package/cjs/FormBuilder/index.js +11 -0
  76. package/cjs/FormContext.js +14 -0
  77. package/cjs/MultiplicityField/MultiplicityField.stories.js +101 -0
  78. package/{es → cjs}/MultiplicityField/__stories__/Default.js +32 -11
  79. package/cjs/MultiplicityField/__stories__/PreviewDisplay.js +106 -0
  80. package/{es → cjs}/MultiplicityField/__stories__/WithExactLength.js +32 -11
  81. package/{es → cjs}/MultiplicityField/__stories__/WithMaxLength.js +32 -11
  82. package/{es → cjs}/MultiplicityField/__stories__/WithMinAndMaxLength.js +32 -11
  83. package/{es → cjs}/MultiplicityField/__stories__/WithMinLength.js +32 -11
  84. package/{es → cjs}/MultiplicityField/add-objects.js +49 -25
  85. package/cjs/MultiplicityField/index.js +143 -0
  86. package/cjs/Questions/Questions.js +105 -0
  87. package/cjs/Questions/Questions.stories.js +31 -0
  88. package/cjs/Questions/QuestionsContext.js +20 -0
  89. package/cjs/Questions/Step/ReviewStep.js +79 -0
  90. package/cjs/Questions/Step/Step.js +93 -0
  91. package/cjs/Questions/Step/StepArrayReview.js +79 -0
  92. package/{es → cjs}/Questions/Step/StepContext.js +13 -3
  93. package/cjs/Questions/Step/StepDescription.js +55 -0
  94. package/cjs/Questions/Step/StepForm.js +74 -0
  95. package/cjs/Questions/Step/StepQuote.js +26 -0
  96. package/cjs/Questions/Step/StepTitle.js +75 -0
  97. package/{es → cjs}/Questions/Step/getAddMoreFields.js +11 -2
  98. package/cjs/Questions/Step/index.js +170 -0
  99. package/cjs/Questions/Step/types.js +5 -0
  100. package/cjs/Questions/__stories__/Default.js +135 -0
  101. package/{es → cjs}/Questions/getNextStep.js +8 -1
  102. package/cjs/Questions/index.js +25 -0
  103. package/cjs/Questions/index.spec.js +73 -0
  104. package/cjs/Questions/types.js +5 -0
  105. package/cjs/index.js +28 -0
  106. package/cjs/inputs/AutoComplete/AutoComplete.stories.js +31 -0
  107. package/cjs/inputs/AutoComplete/__stories__/Default.js +71 -0
  108. package/cjs/inputs/AutoComplete/index.js +68 -0
  109. package/cjs/inputs/Checkboxes/Checkboxes.stories.js +59 -0
  110. package/{es → cjs}/inputs/Checkboxes/__stories__/Conditional.js +28 -8
  111. package/cjs/inputs/Checkboxes/__stories__/Default.js +62 -0
  112. package/cjs/inputs/Checkboxes/__stories__/WithDivider.js +63 -0
  113. package/cjs/inputs/Checkboxes/index.js +127 -0
  114. package/cjs/inputs/DateInput/DateInput.stories.js +31 -0
  115. package/cjs/inputs/DateInput/__stories__/Default.js +45 -0
  116. package/cjs/inputs/DateInput/index.js +181 -0
  117. package/cjs/inputs/FileInput/FileInput.stories.js +31 -0
  118. package/cjs/inputs/FileInput/__stories__/Default.js +42 -0
  119. package/cjs/inputs/FileInput/index.js +92 -0
  120. package/cjs/inputs/Input/Input.stories.js +143 -0
  121. package/cjs/inputs/Input/__stories__/AFM.js +44 -0
  122. package/cjs/inputs/Input/__stories__/Boolean.js +45 -0
  123. package/cjs/inputs/Input/__stories__/Default.js +45 -0
  124. package/cjs/inputs/Input/__stories__/IBAN.js +45 -0
  125. package/cjs/inputs/Input/__stories__/Integer.js +53 -0
  126. package/cjs/inputs/Input/__stories__/MobilePhone.js +44 -0
  127. package/cjs/inputs/Input/__stories__/PhoneNumber.js +44 -0
  128. package/cjs/inputs/Input/__stories__/PostalCode.js +47 -0
  129. package/cjs/inputs/Input/__stories__/TextWithCharacterLimit.js +51 -0
  130. package/cjs/inputs/Input/index.js +96 -0
  131. package/cjs/inputs/Label/Label.stories.js +31 -0
  132. package/cjs/inputs/Label/__stories__/Default.js +49 -0
  133. package/cjs/inputs/Label/index.js +41 -0
  134. package/cjs/inputs/OtpInput/OtpInput.stories.js +31 -0
  135. package/cjs/inputs/OtpInput/__stories__/Default.js +52 -0
  136. package/cjs/inputs/OtpInput/index.js +182 -0
  137. package/cjs/inputs/Radio/Radio.stories.js +59 -0
  138. package/{es → cjs}/inputs/Radio/__stories__/Conditional.js +28 -8
  139. package/cjs/inputs/Radio/__stories__/Default.js +67 -0
  140. package/cjs/inputs/Radio/__stories__/WithDivider.js +68 -0
  141. package/cjs/inputs/Radio/index.js +82 -0
  142. package/cjs/inputs/Select/Select.stories.js +31 -0
  143. package/cjs/inputs/Select/__stories__/Default.js +73 -0
  144. package/cjs/inputs/Select/index.js +49 -0
  145. package/cjs/inputs/index.js +71 -0
  146. package/cjs/internal.js +391 -0
  147. package/cjs/registry.js +208 -0
  148. package/cjs/types.js +5 -0
  149. package/{es → cjs}/utils.js +26 -12
  150. package/{es → cjs}/validators/index.js +54 -26
  151. package/cjs/validators/types.js +5 -0
  152. package/{es → cjs}/validators/utils/afm.js +13 -3
  153. package/{es → cjs}/validators/utils/file.js +12 -2
  154. package/{es → cjs}/validators/utils/iban.js +13 -2
  155. package/cjs/validators/utils/index.js +229 -0
  156. package/{es → cjs}/validators/utils/int.js +14 -3
  157. package/cjs/validators/utils/number.js +27 -0
  158. package/{es → cjs}/validators/utils/otp.js +14 -3
  159. package/{es → cjs}/validators/utils/phone.js +28 -6
  160. package/{es → cjs}/validators/utils/postal_code.js +14 -3
  161. package/{es → cjs}/validators/utils/text_limit.js +14 -3
  162. package/{es → cjs}/validators/utils/uuid4.js +13 -3
  163. package/cjs/validators/validators.spec.js +88 -0
  164. package/index.js +8 -28
  165. package/inputs/AutoComplete/AutoComplete.stories.js +4 -28
  166. package/inputs/AutoComplete/__stories__/Default.js +13 -35
  167. package/inputs/AutoComplete/index.js +12 -35
  168. package/inputs/AutoComplete/package.json +6 -0
  169. package/inputs/Checkboxes/Checkboxes.stories.js +6 -56
  170. package/inputs/Checkboxes/__stories__/Conditional.js +8 -28
  171. package/inputs/Checkboxes/__stories__/Default.js +8 -28
  172. package/inputs/Checkboxes/__stories__/WithDivider.js +8 -28
  173. package/inputs/Checkboxes/index.js +25 -52
  174. package/inputs/Checkboxes/package.json +6 -0
  175. package/inputs/DateInput/DateInput.stories.js +4 -28
  176. package/inputs/DateInput/__stories__/Default.js +8 -28
  177. package/inputs/DateInput/index.js +26 -52
  178. package/inputs/DateInput/package.json +6 -0
  179. package/inputs/FileInput/FileInput.stories.js +4 -28
  180. package/inputs/FileInput/__stories__/Default.js +8 -28
  181. package/inputs/FileInput/index.js +22 -52
  182. package/inputs/FileInput/package.json +6 -0
  183. package/inputs/Input/Input.stories.js +12 -140
  184. package/inputs/Input/__stories__/AFM.js +8 -28
  185. package/inputs/Input/__stories__/Boolean.js +8 -28
  186. package/inputs/Input/__stories__/Default.js +8 -28
  187. package/inputs/Input/__stories__/IBAN.js +8 -28
  188. package/inputs/Input/__stories__/Integer.js +9 -29
  189. package/inputs/Input/__stories__/MobilePhone.js +8 -28
  190. package/inputs/Input/__stories__/PhoneNumber.js +8 -28
  191. package/inputs/Input/__stories__/PostalCode.js +8 -28
  192. package/inputs/Input/__stories__/TextWithCharacterLimit.js +8 -28
  193. package/inputs/Input/index.js +19 -40
  194. package/inputs/Input/package.json +6 -0
  195. package/inputs/Label/Label.stories.js +4 -28
  196. package/inputs/Label/__stories__/Default.js +9 -29
  197. package/inputs/Label/index.js +9 -25
  198. package/inputs/Label/package.json +6 -0
  199. package/inputs/OtpInput/OtpInput.stories.js +4 -28
  200. package/inputs/OtpInput/__stories__/Default.js +9 -30
  201. package/inputs/OtpInput/index.js +28 -53
  202. package/inputs/OtpInput/package.json +6 -0
  203. package/inputs/Radio/Radio.stories.js +6 -56
  204. package/inputs/Radio/__stories__/Conditional.js +8 -28
  205. package/inputs/Radio/__stories__/Default.js +8 -28
  206. package/inputs/Radio/__stories__/WithDivider.js +8 -28
  207. package/inputs/Radio/index.js +24 -45
  208. package/inputs/Radio/package.json +6 -0
  209. package/inputs/Select/Select.stories.js +4 -28
  210. package/inputs/Select/__stories__/Default.js +8 -28
  211. package/inputs/Select/index.js +12 -29
  212. package/inputs/Select/package.json +6 -0
  213. package/inputs/index.js +8 -71
  214. package/inputs/package.json +6 -0
  215. package/internal.js +34 -391
  216. package/package.json +6 -6
  217. package/registry.d.ts +1 -1
  218. package/registry.js +61 -133
  219. package/types.js +1 -5
  220. package/utils.js +12 -26
  221. package/validators/index.js +26 -54
  222. package/validators/package.json +6 -0
  223. package/validators/types.js +1 -5
  224. package/validators/utils/afm.js +3 -13
  225. package/validators/utils/file.js +2 -12
  226. package/validators/utils/iban.js +2 -13
  227. package/validators/utils/index.js +12 -139
  228. package/validators/utils/int.js +3 -14
  229. package/validators/utils/number.js +3 -14
  230. package/validators/utils/otp.js +3 -14
  231. package/validators/utils/package.json +6 -0
  232. package/validators/utils/phone.js +6 -28
  233. package/validators/utils/postal_code.js +3 -14
  234. package/validators/utils/text_limit.js +3 -14
  235. package/validators/utils/uuid4.js +3 -13
  236. package/validators/validators.spec.js +29 -32
  237. package/Field/FieldBase.mjs +0 -84
  238. package/Field/FieldBaseContainer.mjs +0 -43
  239. package/Field/FieldConditional.mjs +0 -62
  240. package/Field/index.mjs +0 -76
  241. package/Field/types.mjs +0 -1
  242. package/Field/utils.mjs +0 -162
  243. package/FieldArray/FieldArray.stories.mjs +0 -8
  244. package/FieldArray/__stories__/Default.mjs +0 -90
  245. package/FieldArray/__stories__/WithExactLength.mjs +0 -90
  246. package/FieldArray/index.mjs +0 -65
  247. package/FieldObject/index.mjs +0 -58
  248. package/Fieldset/FieldsetWithContext.mjs +0 -41
  249. package/Fieldset/index.mjs +0 -34
  250. package/Fieldset/types.mjs +0 -1
  251. package/Form.stories.mjs +0 -3
  252. package/FormBuilder/FormBuilder.mjs +0 -160
  253. package/FormBuilder/FormBuilder.stories.mjs +0 -7
  254. package/FormBuilder/__stories__/Default.mjs +0 -28
  255. package/FormBuilder/index.mjs +0 -2
  256. package/FormContext.mjs +0 -5
  257. package/MultiplicityField/MultiplicityField.stories.mjs +0 -12
  258. package/MultiplicityField/__stories__/Default.mjs +0 -97
  259. package/MultiplicityField/__stories__/PreviewDisplay.mjs +0 -83
  260. package/MultiplicityField/__stories__/WithExactLength.mjs +0 -92
  261. package/MultiplicityField/__stories__/WithMaxLength.mjs +0 -95
  262. package/MultiplicityField/__stories__/WithMinAndMaxLength.mjs +0 -96
  263. package/MultiplicityField/__stories__/WithMinLength.mjs +0 -95
  264. package/MultiplicityField/add-objects.mjs +0 -160
  265. package/MultiplicityField/index.mjs +0 -114
  266. package/Questions/Questions.mjs +0 -84
  267. package/Questions/Questions.stories.mjs +0 -7
  268. package/Questions/QuestionsContext.mjs +0 -11
  269. package/Questions/Step/ReviewStep.mjs +0 -53
  270. package/Questions/Step/Step.mjs +0 -69
  271. package/Questions/Step/StepArrayReview.mjs +0 -50
  272. package/Questions/Step/StepContext.mjs +0 -27
  273. package/Questions/Step/StepDescription.mjs +0 -27
  274. package/Questions/Step/StepForm.mjs +0 -48
  275. package/Questions/Step/StepQuote.mjs +0 -11
  276. package/Questions/Step/StepTitle.mjs +0 -44
  277. package/Questions/Step/getAddMoreFields.mjs +0 -22
  278. package/Questions/Step/index.mjs +0 -13
  279. package/Questions/Step/types.mjs +0 -1
  280. package/Questions/__stories__/Default.mjs +0 -108
  281. package/Questions/getNextStep.mjs +0 -23
  282. package/Questions/index.mjs +0 -3
  283. package/Questions/index.spec.mjs +0 -62
  284. package/Questions/types.mjs +0 -1
  285. package/es/Field/FieldBaseContainer.js +0 -43
  286. package/es/Field/FieldConditional.js +0 -62
  287. package/es/Field/index.js +0 -76
  288. package/es/Field/types.js +0 -1
  289. package/es/FieldArray/FieldArray.stories.js +0 -8
  290. package/es/FieldArray/__stories__/Default.js +0 -90
  291. package/es/FieldArray/__stories__/WithExactLength.js +0 -90
  292. package/es/FieldArray/index.js +0 -65
  293. package/es/FieldObject/index.js +0 -58
  294. package/es/Fieldset/FieldsetWithContext.js +0 -41
  295. package/es/Fieldset/index.js +0 -34
  296. package/es/Fieldset/types.js +0 -1
  297. package/es/Form.stories.js +0 -3
  298. package/es/FormBuilder/FormBuilder.stories.js +0 -7
  299. package/es/FormBuilder/__stories__/Default.js +0 -28
  300. package/es/FormBuilder/index.js +0 -2
  301. package/es/FormContext.js +0 -5
  302. package/es/MultiplicityField/MultiplicityField.stories.js +0 -12
  303. package/es/MultiplicityField/__stories__/PreviewDisplay.js +0 -83
  304. package/es/MultiplicityField/index.js +0 -114
  305. package/es/Questions/Questions.js +0 -84
  306. package/es/Questions/Questions.stories.js +0 -7
  307. package/es/Questions/QuestionsContext.js +0 -11
  308. package/es/Questions/Step/ReviewStep.js +0 -53
  309. package/es/Questions/Step/Step.js +0 -69
  310. package/es/Questions/Step/StepArrayReview.js +0 -50
  311. package/es/Questions/Step/StepDescription.js +0 -27
  312. package/es/Questions/Step/StepForm.js +0 -48
  313. package/es/Questions/Step/StepQuote.js +0 -11
  314. package/es/Questions/Step/StepTitle.js +0 -44
  315. package/es/Questions/Step/index.js +0 -13
  316. package/es/Questions/Step/types.js +0 -1
  317. package/es/Questions/__stories__/Default.js +0 -108
  318. package/es/Questions/index.js +0 -3
  319. package/es/Questions/index.spec.js +0 -62
  320. package/es/Questions/types.js +0 -1
  321. package/es/index.js +0 -3
  322. package/es/inputs/AutoComplete/AutoComplete.stories.js +0 -7
  323. package/es/inputs/AutoComplete/__stories__/Default.js +0 -49
  324. package/es/inputs/AutoComplete/index.js +0 -45
  325. package/es/inputs/Checkboxes/Checkboxes.stories.js +0 -9
  326. package/es/inputs/Checkboxes/__stories__/Default.js +0 -42
  327. package/es/inputs/Checkboxes/__stories__/WithDivider.js +0 -43
  328. package/es/inputs/Checkboxes/index.js +0 -100
  329. package/es/inputs/DateInput/DateInput.stories.js +0 -7
  330. package/es/inputs/DateInput/__stories__/Default.js +0 -25
  331. package/es/inputs/DateInput/index.js +0 -155
  332. package/es/inputs/FileInput/FileInput.stories.js +0 -7
  333. package/es/inputs/FileInput/__stories__/Default.js +0 -22
  334. package/es/inputs/FileInput/index.js +0 -62
  335. package/es/inputs/Input/Input.stories.js +0 -15
  336. package/es/inputs/Input/__stories__/AFM.js +0 -24
  337. package/es/inputs/Input/__stories__/Boolean.js +0 -25
  338. package/es/inputs/Input/__stories__/Default.js +0 -25
  339. package/es/inputs/Input/__stories__/IBAN.js +0 -25
  340. package/es/inputs/Input/__stories__/Integer.js +0 -33
  341. package/es/inputs/Input/__stories__/MobilePhone.js +0 -24
  342. package/es/inputs/Input/__stories__/PhoneNumber.js +0 -24
  343. package/es/inputs/Input/__stories__/PostalCode.js +0 -27
  344. package/es/inputs/Input/__stories__/TextWithCharacterLimit.js +0 -31
  345. package/es/inputs/Input/index.js +0 -75
  346. package/es/inputs/Label/Label.stories.js +0 -7
  347. package/es/inputs/Label/__stories__/Default.js +0 -29
  348. package/es/inputs/Label/index.js +0 -25
  349. package/es/inputs/OtpInput/OtpInput.stories.js +0 -7
  350. package/es/inputs/OtpInput/__stories__/Default.js +0 -31
  351. package/es/inputs/OtpInput/index.js +0 -157
  352. package/es/inputs/Radio/Radio.stories.js +0 -9
  353. package/es/inputs/Radio/__stories__/Default.js +0 -47
  354. package/es/inputs/Radio/__stories__/WithDivider.js +0 -48
  355. package/es/inputs/Radio/index.js +0 -61
  356. package/es/inputs/Select/Select.stories.js +0 -7
  357. package/es/inputs/Select/__stories__/Default.js +0 -53
  358. package/es/inputs/Select/index.js +0 -32
  359. package/es/inputs/index.js +0 -8
  360. package/es/internal.js +0 -34
  361. package/es/registry.js +0 -136
  362. package/es/types.js +0 -1
  363. package/es/validators/types.js +0 -1
  364. package/es/validators/utils/index.js +0 -102
  365. package/es/validators/utils/number.js +0 -16
  366. package/es/validators/validators.spec.js +0 -85
  367. package/index.mjs +0 -8
  368. package/inputs/AutoComplete/AutoComplete.stories.mjs +0 -7
  369. package/inputs/AutoComplete/__stories__/Default.mjs +0 -49
  370. package/inputs/AutoComplete/index.mjs +0 -45
  371. package/inputs/Checkboxes/Checkboxes.stories.mjs +0 -9
  372. package/inputs/Checkboxes/__stories__/Conditional.mjs +0 -95
  373. package/inputs/Checkboxes/__stories__/Default.mjs +0 -42
  374. package/inputs/Checkboxes/__stories__/WithDivider.mjs +0 -43
  375. package/inputs/Checkboxes/index.mjs +0 -100
  376. package/inputs/DateInput/DateInput.stories.mjs +0 -7
  377. package/inputs/DateInput/__stories__/Default.mjs +0 -25
  378. package/inputs/DateInput/index.mjs +0 -155
  379. package/inputs/FileInput/FileInput.stories.mjs +0 -7
  380. package/inputs/FileInput/__stories__/Default.mjs +0 -22
  381. package/inputs/FileInput/index.mjs +0 -62
  382. package/inputs/Input/Input.stories.mjs +0 -15
  383. package/inputs/Input/__stories__/AFM.mjs +0 -24
  384. package/inputs/Input/__stories__/Boolean.mjs +0 -25
  385. package/inputs/Input/__stories__/Default.mjs +0 -25
  386. package/inputs/Input/__stories__/IBAN.mjs +0 -25
  387. package/inputs/Input/__stories__/Integer.mjs +0 -33
  388. package/inputs/Input/__stories__/MobilePhone.mjs +0 -24
  389. package/inputs/Input/__stories__/PhoneNumber.mjs +0 -24
  390. package/inputs/Input/__stories__/PostalCode.mjs +0 -27
  391. package/inputs/Input/__stories__/TextWithCharacterLimit.mjs +0 -31
  392. package/inputs/Input/index.mjs +0 -75
  393. package/inputs/Label/Label.stories.mjs +0 -7
  394. package/inputs/Label/__stories__/Default.mjs +0 -29
  395. package/inputs/Label/index.mjs +0 -25
  396. package/inputs/OtpInput/OtpInput.stories.mjs +0 -7
  397. package/inputs/OtpInput/__stories__/Default.mjs +0 -31
  398. package/inputs/OtpInput/index.mjs +0 -157
  399. package/inputs/Radio/Radio.stories.mjs +0 -9
  400. package/inputs/Radio/__stories__/Conditional.mjs +0 -95
  401. package/inputs/Radio/__stories__/Default.mjs +0 -47
  402. package/inputs/Radio/__stories__/WithDivider.mjs +0 -48
  403. package/inputs/Radio/index.mjs +0 -61
  404. package/inputs/Select/Select.stories.mjs +0 -7
  405. package/inputs/Select/__stories__/Default.mjs +0 -53
  406. package/inputs/Select/index.mjs +0 -32
  407. package/inputs/index.mjs +0 -8
  408. package/internal.mjs +0 -34
  409. package/registry.mjs +0 -136
  410. package/types.mjs +0 -1
  411. package/utils.mjs +0 -99
  412. package/validators/index.mjs +0 -186
  413. package/validators/types.mjs +0 -1
  414. package/validators/utils/afm.mjs +0 -35
  415. package/validators/utils/file.mjs +0 -52
  416. package/validators/utils/iban.mjs +0 -123
  417. package/validators/utils/index.mjs +0 -102
  418. package/validators/utils/int.mjs +0 -20
  419. package/validators/utils/number.mjs +0 -16
  420. package/validators/utils/otp.mjs +0 -26
  421. package/validators/utils/phone.mjs +0 -122
  422. package/validators/utils/postal_code.mjs +0 -29
  423. package/validators/utils/text_limit.mjs +0 -54
  424. package/validators/utils/uuid4.mjs +0 -20
  425. package/validators/validators.spec.mjs +0 -85
  426. /package/{es → cjs}/Field/index.mdx +0 -0
  427. /package/{es → cjs}/FieldArray/FieldArray.stories.playwright.json +0 -0
  428. /package/{es → cjs}/FormBuilder/FormBuilder.mdx +0 -0
  429. /package/{es → cjs}/FormBuilder/FormBuilder.stories.playwright.json +0 -0
  430. /package/{es → cjs}/MultiplicityField/MultiplicityField.mdx +0 -0
  431. /package/{es → cjs}/MultiplicityField/MultiplicityField.stories.playwright.json +0 -0
  432. /package/{es → cjs}/Questions/__snapshots__/index.spec.tsx.snap +0 -0
  433. /package/{es → cjs}/Questions/index.mdx +0 -0
  434. /package/{es → cjs}/create-simple-form.mdx +0 -0
  435. /package/{es → cjs}/index.mdx +0 -0
  436. /package/{es → cjs}/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -0
  437. /package/{es → cjs}/inputs/Checkboxes/index.mdx +0 -0
  438. /package/{es → cjs}/inputs/DateInput/DateInput.stories.playwright.json +0 -0
  439. /package/{es → cjs}/inputs/FileInput/FileInput.stories.playwright.json +0 -0
  440. /package/{es → cjs}/inputs/Input/Input.stories.playwright.json +0 -0
  441. /package/{es → cjs}/inputs/Input/index.mdx +0 -0
  442. /package/{es → cjs}/inputs/Label/Label.stories.playwright.json +0 -0
  443. /package/{es → cjs}/inputs/Label/index.mdx +0 -0
  444. /package/{es → cjs}/inputs/Radio/Radio.stories.playwright.json +0 -0
  445. /package/{es → cjs}/inputs/Radio/index.mdx +0 -0
  446. /package/{es → cjs}/inputs/Select/Select.stories.playwright.json +0 -0
  447. /package/{es → cjs}/installation.mdx +0 -0
@@ -1,186 +0,0 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- import { useMemo } from 'react';
3
- import dayjs from 'dayjs';
4
- import customParseFormat from 'dayjs/plugin/customParseFormat';
5
- import * as yup from 'yup';
6
- import { getYupObjectShape, AFM_VALIDATOR, FILE_MAX_SIZE_VALIDATOR, IBAN_VALIDATOR, OTP_VALIDATOR, MOBILE_PHONE_VALIDATOR, PHONE_NUMBER_VALIDATOR, TEXT_LIMIT_VALIDATOR, POSTALCODE_VALIDATOR, UUID4_VALIDATOR } from "./utils";
7
- import { INT_VALIDATOR } from "./utils/int";
8
- import { NUMBER_VALIDATOR } from "./utils/number";
9
- dayjs.extend(customParseFormat);
10
- var VALID_DATE_FORMATS = ['DD/MM/YYYY'];
11
- var DATE_CACHE = {};
12
-
13
- var getDate = function getDate(v) {
14
- return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
15
- };
16
-
17
- export var getYUPTypeMap = function getYUPTypeMap() {
18
- var yupTypeMap = {
19
- file: function file(field) {
20
- return yup.mixed().transform(function (value) {
21
- if (!value.length) {
22
- return null;
23
- }
24
-
25
- return value;
26
- }).nullable().test(FILE_MAX_SIZE_VALIDATOR(field));
27
- },
28
- string: yup.string,
29
- "boolean": yup["boolean"],
30
- object: function object(field) {
31
- return getYupObjectShape(field.extra.fields, yupTypeMap);
32
- },
33
- array: function array(field) {
34
- if (_typeof(field.extra.of) === 'object') {
35
- // else if the field is an object then it is a scalar type
36
- // eg. number, string etc.
37
- var arrayValidator = yup.array().of(yupTypeMap[field.extra.of.type](field.extra.of)).required(field.required);
38
- if (field.extra.length) arrayValidator = arrayValidator.length(field.extra.length, {
39
- key: 'form.error.array.length',
40
- context: {
41
- length: field.extra.length
42
- }
43
- });
44
- if (field.extra.min) arrayValidator = arrayValidator.min(field.extra.min, {
45
- key: 'form.error.array.min',
46
- context: {
47
- min: field.extra.min
48
- }
49
- });
50
- if (field.extra.max) arrayValidator = arrayValidator.max(field.extra.max, {
51
- key: 'form.error.array.max',
52
- context: {
53
- max: field.extra.max
54
- }
55
- });
56
- return arrayValidator;
57
- } else if (typeof field.extra.of === 'string') {
58
- return yup.array().of(yupTypeMap[field.extra.of]());
59
- } else {
60
- // in any other case it will be string
61
- return yup.array().of(yup.string());
62
- }
63
- },
64
- "int": function int() {
65
- return yup.mixed().transform(function (_, val) {
66
- return val !== '' ? Number(val) : null;
67
- }).test(NUMBER_VALIDATOR()).test(INT_VALIDATOR());
68
- },
69
- email: function email() {
70
- return yup.string().email('form.error.email');
71
- },
72
- afm: function afm() {
73
- return yup.string().test(AFM_VALIDATOR);
74
- },
75
- uuid4: function uuid4() {
76
- return yup.string().test(UUID4_VALIDATOR);
77
- },
78
- iban: function iban(field) {
79
- return yup.string().test(IBAN_VALIDATOR(field));
80
- },
81
- otp: function otp(field) {
82
- return yup.string().test(OTP_VALIDATOR(field));
83
- },
84
- text: function text(field) {
85
- var _field$extra, _field$extra$limit, _field$extra2, _field$extra2$limit;
86
-
87
- if (field !== null && field !== void 0 && (_field$extra = field.extra) !== null && _field$extra !== void 0 && (_field$extra$limit = _field$extra.limit) !== null && _field$extra$limit !== void 0 && _field$extra$limit.max || !!(field !== null && field !== void 0 && (_field$extra2 = field.extra) !== null && _field$extra2 !== void 0 && (_field$extra2$limit = _field$extra2.limit) !== null && _field$extra2$limit !== void 0 && _field$extra2$limit.min)) {
88
- return yup.string().test(TEXT_LIMIT_VALIDATOR(field));
89
- } else {
90
- return yup.string();
91
- }
92
- },
93
- postal_code: function postal_code(field) {
94
- return yup.string().test(POSTALCODE_VALIDATOR(field));
95
- },
96
- mobile_phone: function mobile_phone() {
97
- return yup.string().test(MOBILE_PHONE_VALIDATOR);
98
- },
99
- phone_number: function phone_number(field) {
100
- return yup.string().test(PHONE_NUMBER_VALIDATOR(field));
101
- },
102
- 'choice:multiple': function choiceMultiple() {
103
- return yup.array().of(yup.string()).nullable();
104
- },
105
- 'choice:single': function choiceSingle() {
106
- return yup.string().nullable();
107
- },
108
- date: function date(field) {
109
- var simpleDate = yup.string().nullable(true).test('date', 'form.error.date.invalid', function (value) {
110
- if (!value) return true;
111
- var date = getDate(value);
112
- return date.isValid();
113
- });
114
- var params = field.extra || {};
115
-
116
- if (params.max) {
117
- var maxDate;
118
-
119
- if (params.max === 'now') {
120
- var today = new Date();
121
- maxDate = new Date(today);
122
- } else {
123
- maxDate = getDate(params.max).toDate();
124
- }
125
-
126
- var maxNextDate = new Date(maxDate);
127
- maxNextDate.setDate(maxDate.getDate() + 1);
128
- simpleDate = simpleDate.test({
129
- name: 'earlier-than',
130
- message: {
131
- key: 'form.error.date.earlier_than',
132
- context: {
133
- maxDate: maxNextDate.toLocaleDateString()
134
- }
135
- },
136
- test: function test(value) {
137
- if (!value) return true;
138
- var date = getDate(value);
139
- var isValid = +date.toDate() < +maxDate;
140
- return isValid;
141
- }
142
- });
143
- }
144
-
145
- if (params.min) {
146
- var minDate;
147
-
148
- if (params.min === 'now') {
149
- var _today = new Date();
150
-
151
- minDate = new Date(_today);
152
- } else {
153
- minDate = getDate(params.min).toDate();
154
- }
155
-
156
- var minPreviousDate = new Date(minDate);
157
- minPreviousDate.setDate(minDate.getDate() - 1);
158
- simpleDate = simpleDate.test({
159
- name: 'later-than',
160
- message: {
161
- key: 'form.error.date.later_than',
162
- context: {
163
- minDate: minPreviousDate.toLocaleDateString()
164
- }
165
- },
166
- test: function test(value) {
167
- if (!value) return true;
168
- var date = getDate(value);
169
- var isValid = +date.toDate() > +minDate;
170
- return isValid;
171
- }
172
- });
173
- }
174
-
175
- return simpleDate;
176
- }
177
- };
178
- return yupTypeMap;
179
- };
180
- // Create a yup validation schema from given fields input
181
- export function useValidationSchema(fields, validatorRegistry) {
182
- return useMemo(function () {
183
- var yupTypeMap = getYUPTypeMap();
184
- return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
185
- }, []);
186
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,35 +0,0 @@
1
- export function validateAFM(afm) {
2
- if (afm.length !== 9) {
3
- // "afm should be 9 digits"
4
- return false;
5
- }
6
-
7
- if (!/^\d+$/.test(afm)) {
8
- // "This is not a number"
9
- return false;
10
- }
11
-
12
- if (afm === '0'.repeat(9)) {
13
- // "This is zero number (000000000)"
14
- return false;
15
- }
16
-
17
- var sum = afm.substring(0, 8).split('').reduce(function (s, v, i) {
18
- return s + (parseInt(v) << 8 - i);
19
- }, 0);
20
- var calc = sum % 11;
21
- var d9 = parseInt(afm[8]);
22
- var valid = calc % 10 === d9;
23
- return valid;
24
- }
25
- export var AFM_VALIDATOR = {
26
- name: 'afm-validator',
27
- message: 'form.error.afm',
28
- test: function test(value) {
29
- if (value) {
30
- return validateAFM(value);
31
- }
32
-
33
- return true;
34
- }
35
- };
@@ -1,52 +0,0 @@
1
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
2
-
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
-
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6
-
7
- var DEFAULT_FILE_MAX_SIZE = 10000000;
8
- export var FILE_MAX_SIZE_VALIDATOR = function FILE_MAX_SIZE_VALIDATOR(field) {
9
- return {
10
- name: 'file-max-size-validator',
11
- message: 'form.error.file_size',
12
- test: function test(value) {
13
- if (field.extra && field.extra.maxSize && value) {
14
- var _iterator = _createForOfIteratorHelper(value),
15
- _step;
16
-
17
- try {
18
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
19
- var file = _step.value;
20
-
21
- if (file.size >= field.extra.maxSize) {
22
- return false;
23
- }
24
- }
25
- } catch (err) {
26
- _iterator.e(err);
27
- } finally {
28
- _iterator.f();
29
- }
30
- } else if (value) {
31
- var _iterator2 = _createForOfIteratorHelper(value),
32
- _step2;
33
-
34
- try {
35
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
36
- var _file = _step2.value;
37
-
38
- if (_file.size >= DEFAULT_FILE_MAX_SIZE) {
39
- return false;
40
- }
41
- }
42
- } catch (err) {
43
- _iterator2.e(err);
44
- } finally {
45
- _iterator2.f();
46
- }
47
- }
48
-
49
- return true;
50
- }
51
- };
52
- };
@@ -1,123 +0,0 @@
1
- export function validateIban(value, countryCode) {
2
- value = value.replace(/\s/g, '').replace(/-/g, '');
3
-
4
- if (value.match(/^[0-9]*$/i)) {
5
- // this is for greek iban without the country code
6
- if (value.length !== 25) {
7
- return false;
8
- }
9
- } else {
10
- value = value.toUpperCase();
11
-
12
- if (countryCode) {
13
- if (!value.startsWith(countryCode.toUpperCase())) {
14
- return false;
15
- }
16
-
17
- if (value.length === ibanCountryCodesLengths[countryCode.toUpperCase()]) {
18
- return true;
19
- }
20
- }
21
-
22
- if (value.length !== 27) {
23
- // this is for greek iban
24
- return false;
25
- }
26
- }
27
-
28
- return true;
29
- }
30
- export var IBAN_VALIDATOR = function IBAN_VALIDATOR(field) {
31
- var _field$extra;
32
-
33
- var countryCode = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.country;
34
- return {
35
- name: 'iban-validator',
36
- message: 'form.error.iban',
37
- test: function test(value) {
38
- if (!value) {
39
- return true;
40
- }
41
-
42
- return validateIban(value, countryCode);
43
- }
44
- };
45
- };
46
- var ibanCountryCodesLengths = {
47
- AD: 24,
48
- AT: 20,
49
- AZ: 28,
50
- BH: 22,
51
- BY: 28,
52
- BE: 16,
53
- BA: 20,
54
- BR: 29,
55
- BG: 22,
56
- CR: 22,
57
- HR: 21,
58
- CY: 28,
59
- CZ: 24,
60
- DK: 18,
61
- DO: 28,
62
- EG: 29,
63
- SV: 28,
64
- EE: 20,
65
- FO: 18,
66
- FI: 18,
67
- FR: 27,
68
- GE: 22,
69
- DE: 22,
70
- GI: 23,
71
- GR: 27,
72
- GL: 18,
73
- GT: 28,
74
- VA: 22,
75
- HU: 28,
76
- IS: 26,
77
- IQ: 23,
78
- IE: 22,
79
- IL: 23,
80
- IT: 27,
81
- JO: 30,
82
- KZ: 20,
83
- XK: 20,
84
- KW: 30,
85
- LV: 21,
86
- LB: 28,
87
- LI: 21,
88
- LT: 20,
89
- LU: 20,
90
- MT: 31,
91
- MR: 27,
92
- MU: 30,
93
- MD: 24,
94
- MC: 27,
95
- ME: 22,
96
- NL: 18,
97
- MK: 19,
98
- NO: 15,
99
- PK: 24,
100
- PS: 29,
101
- PL: 28,
102
- PT: 25,
103
- QA: 29,
104
- RO: 24,
105
- LC: 32,
106
- SM: 27,
107
- ST: 25,
108
- SA: 24,
109
- RS: 22,
110
- SC: 31,
111
- SK: 24,
112
- SI: 19,
113
- ES: 24,
114
- SE: 24,
115
- CH: 21,
116
- TL: 23,
117
- TN: 24,
118
- TR: 26,
119
- UA: 29,
120
- AE: 23,
121
- GB: 22,
122
- VG: 24
123
- };
@@ -1,102 +0,0 @@
1
- import * as yup from 'yup';
2
- export * from "./afm";
3
- export * from "./file";
4
- export * from "./iban";
5
- export * from "./otp";
6
- export * from "./phone";
7
- export * from "./postal_code";
8
- export * from "./uuid4";
9
- export * from "./text_limit";
10
- export function getYupField(field, yupTypeMap) {
11
- var yupField = yupTypeMap[(field === null || field === void 0 ? void 0 : field.type) || 'string'] || yupTypeMap['string'];
12
- return yupField(field);
13
- }
14
- export function computeShape(fields, yupTypeMap, validatorRegistry) {
15
- var fieldSchemas = {};
16
- var objectFields = {};
17
- fields.forEach(function (field) {
18
- var yupField = getYupField(field, yupTypeMap);
19
-
20
- if (field.condition) {
21
- var _loop = function _loop(key) {
22
- var then = void 0,
23
- otherwise = void 0;
24
-
25
- if (field.condition[key].then) {
26
- var _field$condition$key$, _field$condition$key$2;
27
-
28
- if (((_field$condition$key$ = field.condition[key].then) === null || _field$condition$key$ === void 0 ? void 0 : _field$condition$key$.required) === false) {
29
- then = yupField.nullable();
30
- } else if (((_field$condition$key$2 = field.condition[key].then) === null || _field$condition$key$2 === void 0 ? void 0 : _field$condition$key$2.required) === true) {
31
- then = yupField.nullable().required('form.error.required');
32
- }
33
- }
34
-
35
- if (field.condition[key]["else"]) {
36
- var _field$condition$key$3, _field$condition$key$4;
37
-
38
- if (((_field$condition$key$3 = field.condition[key]["else"]) === null || _field$condition$key$3 === void 0 ? void 0 : _field$condition$key$3.required) === false) {
39
- otherwise = yupField.nullable();
40
- } else if (((_field$condition$key$4 = field.condition[key]["else"]) === null || _field$condition$key$4 === void 0 ? void 0 : _field$condition$key$4.required) === true) {
41
- otherwise = yupField.nullable().required('form.error.required');
42
- }
43
- }
44
-
45
- if (then || otherwise) {
46
- yupField = yupField.when(key, {
47
- is: function is(val) {
48
- //@ts-ignore
49
- var is = field.condition[key].is;
50
-
51
- if (is === val || Array.isArray(val) && val.includes(is)) {
52
- return true;
53
- } else {
54
- return false;
55
- }
56
- },
57
- then: then,
58
- otherwise: otherwise
59
- });
60
- }
61
- };
62
-
63
- for (var key in field.condition) {
64
- _loop(key);
65
- }
66
- } else if (field.required) {
67
- yupField = yupField.nullable().required('form.error.required');
68
- }
69
-
70
- if (validatorRegistry && field.type && validatorRegistry[field.type]) {
71
- validatorRegistry[field.type].forEach(function (validator) {
72
- yupField = yupField.test(validator);
73
- });
74
- }
75
-
76
- if (field.validators) {
77
- field.validators.forEach(function (validator) {
78
- yupField = yupField.test(validator);
79
- });
80
- }
81
-
82
- fieldSchemas[field.key] = yupField;
83
- });
84
-
85
- for (var objectKey in objectFields) {
86
- fieldSchemas[objectKey] = getYupObjectShape(objectFields[objectKey], yupTypeMap, validatorRegistry);
87
- }
88
-
89
- return fieldSchemas;
90
- }
91
- export function getYupObjectShape( // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
- fields, yupTypeMap, validatorRegistry) {
93
- if (!fields.current) {
94
- var fieldSchemas = computeShape(fields, yupTypeMap, validatorRegistry);
95
- return yup.object().shape(fieldSchemas);
96
- }
97
-
98
- return yup.lazy(function () {
99
- var fieldSchemas = computeShape(Object.values(fields.current), yupTypeMap, validatorRegistry);
100
- return yup.object().shape(fieldSchemas);
101
- });
102
- }
@@ -1,20 +0,0 @@
1
- export function validateIntNumber(number) {
2
- if (number === undefined) {
3
- return false;
4
- } else {
5
- return Number.isInteger(number) && Number(number) > 0;
6
- }
7
- }
8
- export var INT_VALIDATOR = function INT_VALIDATOR() {
9
- return {
10
- name: 'int-validator',
11
- message: 'form.error.positive_integer_number',
12
- test: function test(value) {
13
- if (value === null) {
14
- return true;
15
- }
16
-
17
- return validateIntNumber(value);
18
- }
19
- };
20
- };
@@ -1,16 +0,0 @@
1
- export function validateNumber(number) {
2
- return !Number.isNaN(number);
3
- }
4
- export var NUMBER_VALIDATOR = function NUMBER_VALIDATOR() {
5
- return {
6
- name: 'number-validator',
7
- message: 'form.error.number',
8
- test: function test(value) {
9
- if (value === null) {
10
- return true;
11
- }
12
-
13
- return validateNumber(value);
14
- }
15
- };
16
- };
@@ -1,26 +0,0 @@
1
- export function validateOtp(value, maxLength) {
2
- if (value.length === maxLength) {
3
- return true;
4
- } else {
5
- return false;
6
- }
7
- }
8
- export var OTP_VALIDATOR = function OTP_VALIDATOR(field) {
9
- var maxLength = field === null || field === void 0 ? void 0 : field.maxLength;
10
- return {
11
- name: 'otp-validator',
12
- message: {
13
- key: 'form.error.otp.less_than',
14
- context: {
15
- maxLength: field === null || field === void 0 ? void 0 : field.maxLength
16
- }
17
- },
18
- test: function test(value) {
19
- if (!value) {
20
- return true;
21
- }
22
-
23
- return validateOtp(value, maxLength);
24
- }
25
- };
26
- };
@@ -1,122 +0,0 @@
1
- import * as gPhoneNumber from 'google-libphonenumber';
2
- export function validatePhoneNumber(phoneNumber) {
3
- var countries = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['gr'];
4
- var typeOfPhoneNumber = arguments.length > 2 ? arguments[2] : undefined;
5
- var phoneUtil = gPhoneNumber.PhoneNumberUtil.getInstance();
6
-
7
- if (!countries || countries.length === 0) {
8
- return true;
9
- }
10
-
11
- return countries.some(function (country) {
12
- try {
13
- var phone = phoneUtil.parse(phoneNumber, country.toUpperCase());
14
-
15
- if (phoneUtil.isValidNumber(phone)) {
16
- if (typeOfPhoneNumber) {
17
- if (matchTypeOfPhoneNumber(phone, typeOfPhoneNumber, phoneUtil)) {
18
- return true;
19
- } else {
20
- return false;
21
- }
22
- } else {
23
- return true;
24
- }
25
- }
26
-
27
- return false;
28
- } catch (error) {
29
- console.error(error);
30
- return false;
31
- }
32
- });
33
- }
34
- var phoneNumberTypes = {
35
- 0: 'landline',
36
- 1: 'mobile',
37
- 2: 'landline_or_mobile'
38
- };
39
- export function matchTypeOfPhoneNumber(phone, type, phoneUtil) {
40
- try {
41
- var phoneNumberType = phoneUtil.getNumberType(phone);
42
- var numberType = phoneNumberTypes[phoneNumberType];
43
-
44
- if (numberType === 'landline_or_mobile' || numberType === type) {
45
- return true;
46
- } else {
47
- return false;
48
- }
49
- } catch (error) {
50
- console.error(error);
51
- return false;
52
- }
53
- }
54
-
55
- function validateMobile(value) {
56
- var phoneUtil = gPhoneNumber.PhoneNumberUtil.getInstance();
57
- var origValue = value; // probably catch all the cases with a regex instead of gphonenumber
58
-
59
- if (!value.match(/^((\+|00){0,1}\d{1,3}[- ]?)?\d{10}$/)) {
60
- return false;
61
- }
62
-
63
- try {
64
- var phone;
65
-
66
- try {
67
- phone = phoneUtil.parse(value);
68
- } catch (err) {
69
- try {
70
- value = '+' + value;
71
- phone = phoneUtil.parse(value);
72
- } catch (err) {
73
- value = '+30' + origValue;
74
- phone = phoneUtil.parse(value);
75
- }
76
- }
77
-
78
- return phoneUtil.isValidNumber(phone);
79
- } catch (err) {
80
- console.error(err);
81
- return false;
82
- }
83
- }
84
-
85
- export var MOBILE_PHONE_VALIDATOR = {
86
- name: 'mobile-phone-validator',
87
- message: 'form.error.mobile_phone',
88
- test: function test(value) {
89
- if (value) {
90
- return validateMobile(value);
91
- }
92
-
93
- return true;
94
- }
95
- };
96
- export var PHONE_NUMBER_VALIDATOR = function PHONE_NUMBER_VALIDATOR(field) {
97
- var _field$extra, _field$extra2;
98
-
99
- var countryCode = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.countries;
100
- var typeOfPhone = field === null || field === void 0 ? void 0 : (_field$extra2 = field.extra) === null || _field$extra2 === void 0 ? void 0 : _field$extra2.phoneType;
101
- return {
102
- name: 'phone-number-validator',
103
- message: function message() {
104
- if (typeOfPhone === 'mobile') {
105
- return 'form.error.mobile_phone';
106
- }
107
-
108
- if (typeOfPhone === 'landline') {
109
- return 'form.error.landline';
110
- } else {
111
- return 'form.error.phone_number';
112
- }
113
- },
114
- test: function test(value) {
115
- if (!value) {
116
- return true;
117
- }
118
-
119
- return validatePhoneNumber(value, countryCode, typeOfPhone);
120
- }
121
- };
122
- };