@formio/js 5.0.0-rc.26 → 5.0.0-rc.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (360) hide show
  1. package/dist/fonts/bootstrap-icons.woff +0 -0
  2. package/dist/fonts/bootstrap-icons.woff2 +0 -0
  3. package/dist/formio.embed.js +1 -1
  4. package/dist/formio.embed.min.js +1 -1
  5. package/dist/formio.embed.min.js.LICENSE.txt +1 -1
  6. package/dist/formio.form.js +710 -689
  7. package/dist/formio.form.min.js +1 -1
  8. package/dist/formio.form.min.js.LICENSE.txt +2 -2
  9. package/dist/formio.full.css +100 -3
  10. package/dist/formio.full.js +715 -727
  11. package/dist/formio.full.min.css +2 -2
  12. package/dist/formio.full.min.js +1 -1
  13. package/dist/formio.full.min.js.LICENSE.txt +2 -2
  14. package/dist/formio.js +659 -264
  15. package/dist/formio.min.js +1 -1
  16. package/dist/formio.min.js.LICENSE.txt +2 -2
  17. package/dist/formio.utils.js +29 -8
  18. package/dist/formio.utils.min.js +1 -1
  19. package/dist/formio.utils.min.js.LICENSE.txt +2 -2
  20. package/lib/cjs/Embed.d.ts +2 -1
  21. package/lib/cjs/Embed.js +20 -7
  22. package/lib/cjs/PDF.js +2 -2
  23. package/lib/cjs/Webform.d.ts +3 -5
  24. package/lib/cjs/Webform.js +59 -81
  25. package/lib/cjs/WebformBuilder.d.ts +1 -1
  26. package/lib/cjs/WebformBuilder.js +27 -10
  27. package/lib/cjs/Wizard.d.ts +2 -0
  28. package/lib/cjs/Wizard.js +37 -26
  29. package/lib/cjs/WizardBuilder.d.ts +1 -0
  30. package/lib/cjs/addons/PasswordStrength/PasswordStrengthAddon.d.ts +1 -2
  31. package/lib/cjs/addons/PasswordStrength/PasswordStrengthAddon.js +11 -12
  32. package/lib/cjs/addons/index.d.ts +1 -0
  33. package/lib/cjs/addons/index.js +5 -1
  34. package/lib/cjs/components/Components.d.ts +7 -0
  35. package/lib/cjs/components/Components.js +30 -0
  36. package/lib/cjs/components/_classes/component/Component.d.ts +57 -27
  37. package/lib/cjs/components/_classes/component/Component.js +193 -119
  38. package/lib/cjs/components/_classes/component/editForm/Component.edit.addons.d.ts +8 -0
  39. package/lib/cjs/components/_classes/component/editForm/Component.edit.addons.js +31 -1
  40. package/lib/cjs/components/_classes/nested/NestedComponent.d.ts +28 -11
  41. package/lib/cjs/components/_classes/nested/NestedComponent.js +88 -57
  42. package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +4 -3
  43. package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +17 -4
  44. package/lib/cjs/components/builder.js +0 -2
  45. package/lib/cjs/components/button/Button.js +2 -1
  46. package/lib/cjs/components/columns/Columns.d.ts +1 -0
  47. package/lib/cjs/components/columns/Columns.js +2 -3
  48. package/lib/cjs/components/columns/editForm/Columns.edit.display.d.ts +30 -1
  49. package/lib/cjs/components/columns/editForm/Columns.edit.display.js +23 -1
  50. package/lib/cjs/components/container/Container.d.ts +1 -0
  51. package/lib/cjs/components/container/Container.js +2 -6
  52. package/lib/cjs/components/content/Content.d.ts +1 -0
  53. package/lib/cjs/components/content/Content.js +1 -0
  54. package/lib/cjs/components/datagrid/DataGrid.d.ts +0 -8
  55. package/lib/cjs/components/datagrid/DataGrid.js +9 -26
  56. package/lib/cjs/components/datamap/DataMap.js +2 -1
  57. package/lib/cjs/components/datetime/DateTime.js +0 -2
  58. package/lib/cjs/components/day/Day.js +2 -3
  59. package/lib/cjs/components/editgrid/EditGrid.d.ts +8 -4
  60. package/lib/cjs/components/editgrid/EditGrid.js +96 -73
  61. package/lib/cjs/components/email/Email.js +0 -1
  62. package/lib/cjs/components/file/File.js +1 -1
  63. package/lib/cjs/components/file/fixtures/comp3.d.ts +29 -0
  64. package/lib/cjs/components/file/fixtures/comp3.js +31 -0
  65. package/lib/cjs/components/form/Form.d.ts +2 -6
  66. package/lib/cjs/components/form/Form.js +43 -14
  67. package/lib/cjs/components/index.d.ts +0 -2
  68. package/lib/cjs/components/index.js +0 -2
  69. package/lib/cjs/components/number/Number.d.ts +1 -2
  70. package/lib/cjs/components/number/Number.js +5 -6
  71. package/lib/cjs/components/panel/Panel.d.ts +0 -1
  72. package/lib/cjs/components/panel/Panel.js +2 -9
  73. package/lib/cjs/components/panel/editForm/Panel.edit.display.d.ts +6 -38
  74. package/lib/cjs/components/panel/editForm/Panel.edit.display.js +3 -16
  75. package/lib/cjs/components/phonenumber/PhoneNumber.js +17 -0
  76. package/lib/cjs/components/radio/Radio.js +0 -2
  77. package/lib/cjs/components/recaptcha/ReCaptcha.d.ts +1 -1
  78. package/lib/cjs/components/recaptcha/ReCaptcha.js +2 -2
  79. package/lib/cjs/components/select/Select.js +3 -2
  80. package/lib/cjs/components/selectboxes/SelectBoxes.d.ts +1 -2
  81. package/lib/cjs/components/selectboxes/SelectBoxes.js +7 -6
  82. package/lib/cjs/components/table/editForm/Table.edit.display.d.ts +31 -2
  83. package/lib/cjs/components/table/editForm/Table.edit.display.js +22 -0
  84. package/lib/cjs/components/tabs/editForm/Tabs.edit.display.d.ts +30 -2
  85. package/lib/cjs/components/tabs/editForm/Tabs.edit.display.js +22 -0
  86. package/lib/cjs/components/textfield/TextField.js +20 -6
  87. package/lib/cjs/components/time/Time.js +0 -6
  88. package/lib/cjs/components/url/Url.js +0 -1
  89. package/lib/cjs/components/well/editForm/Well.edit.display.d.ts +25 -2
  90. package/lib/cjs/components/well/editForm/Well.edit.display.js +18 -0
  91. package/lib/cjs/formio.embed.js +5 -3
  92. package/lib/cjs/formio.form.d.ts +1 -7
  93. package/lib/cjs/formio.form.js +2 -38
  94. package/lib/cjs/index.d.ts +2 -1
  95. package/lib/cjs/index.js +2 -1
  96. package/lib/cjs/providers/Providers.d.ts +0 -4
  97. package/lib/cjs/providers/storage/azure.d.ts +0 -2
  98. package/lib/cjs/providers/storage/azure.js +1 -6
  99. package/lib/cjs/providers/storage/googleDrive.d.ts +0 -1
  100. package/lib/cjs/providers/storage/googleDrive.js +0 -4
  101. package/lib/cjs/providers/storage/s3.d.ts +0 -1
  102. package/lib/cjs/providers/storage/s3.js +0 -4
  103. package/lib/cjs/translations/en.d.ts +5 -0
  104. package/lib/cjs/translations/en.js +5 -0
  105. package/lib/cjs/utils/formUtils.js +1 -0
  106. package/lib/cjs/utils/utils.d.ts +2 -1
  107. package/lib/cjs/utils/utils.js +27 -9
  108. package/lib/mjs/Embed.d.ts +2 -1
  109. package/lib/mjs/Embed.js +20 -7
  110. package/lib/mjs/PDF.js +2 -2
  111. package/lib/mjs/Webform.d.ts +3 -5
  112. package/lib/mjs/Webform.js +58 -82
  113. package/lib/mjs/WebformBuilder.d.ts +1 -1
  114. package/lib/mjs/WebformBuilder.js +28 -7
  115. package/lib/mjs/Wizard.d.ts +2 -0
  116. package/lib/mjs/Wizard.js +36 -27
  117. package/lib/mjs/WizardBuilder.d.ts +1 -0
  118. package/lib/mjs/addons/PasswordStrength/PasswordStrengthAddon.d.ts +1 -2
  119. package/lib/mjs/addons/PasswordStrength/PasswordStrengthAddon.js +11 -12
  120. package/lib/mjs/addons/index.d.ts +1 -0
  121. package/lib/mjs/addons/index.js +5 -1
  122. package/lib/mjs/components/Components.d.ts +7 -0
  123. package/lib/mjs/components/Components.js +29 -0
  124. package/lib/mjs/components/_classes/component/Component.d.ts +57 -27
  125. package/lib/mjs/components/_classes/component/Component.js +191 -118
  126. package/lib/mjs/components/_classes/component/editForm/Component.edit.addons.d.ts +8 -0
  127. package/lib/mjs/components/_classes/component/editForm/Component.edit.addons.js +31 -1
  128. package/lib/mjs/components/_classes/nested/NestedComponent.d.ts +28 -11
  129. package/lib/mjs/components/_classes/nested/NestedComponent.js +88 -57
  130. package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +4 -3
  131. package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +18 -5
  132. package/lib/mjs/components/builder.js +0 -2
  133. package/lib/mjs/components/button/Button.js +2 -1
  134. package/lib/mjs/components/columns/Columns.d.ts +1 -0
  135. package/lib/mjs/components/columns/Columns.js +2 -3
  136. package/lib/mjs/components/columns/editForm/Columns.edit.display.d.ts +30 -1
  137. package/lib/mjs/components/columns/editForm/Columns.edit.display.js +23 -1
  138. package/lib/mjs/components/container/Container.d.ts +1 -0
  139. package/lib/mjs/components/container/Container.js +2 -6
  140. package/lib/mjs/components/content/Content.d.ts +1 -0
  141. package/lib/mjs/components/content/Content.js +1 -0
  142. package/lib/mjs/components/datagrid/DataGrid.d.ts +0 -8
  143. package/lib/mjs/components/datagrid/DataGrid.js +9 -26
  144. package/lib/mjs/components/datamap/DataMap.js +2 -1
  145. package/lib/mjs/components/datetime/DateTime.js +0 -2
  146. package/lib/mjs/components/day/Day.js +2 -3
  147. package/lib/mjs/components/editgrid/EditGrid.d.ts +8 -4
  148. package/lib/mjs/components/editgrid/EditGrid.js +97 -76
  149. package/lib/mjs/components/email/Email.js +0 -1
  150. package/lib/mjs/components/file/File.js +1 -1
  151. package/lib/mjs/components/file/fixtures/comp3.d.ts +29 -0
  152. package/lib/mjs/components/file/fixtures/comp3.js +29 -0
  153. package/lib/mjs/components/form/Form.d.ts +2 -6
  154. package/lib/mjs/components/form/Form.js +45 -14
  155. package/lib/mjs/components/index.d.ts +0 -2
  156. package/lib/mjs/components/index.js +0 -2
  157. package/lib/mjs/components/number/Number.d.ts +1 -2
  158. package/lib/mjs/components/number/Number.js +4 -5
  159. package/lib/mjs/components/panel/Panel.d.ts +0 -1
  160. package/lib/mjs/components/panel/Panel.js +3 -9
  161. package/lib/mjs/components/panel/editForm/Panel.edit.display.d.ts +6 -38
  162. package/lib/mjs/components/panel/editForm/Panel.edit.display.js +3 -16
  163. package/lib/mjs/components/phonenumber/PhoneNumber.js +17 -0
  164. package/lib/mjs/components/radio/Radio.js +0 -2
  165. package/lib/mjs/components/recaptcha/ReCaptcha.d.ts +1 -1
  166. package/lib/mjs/components/recaptcha/ReCaptcha.js +2 -2
  167. package/lib/mjs/components/select/Select.js +3 -2
  168. package/lib/mjs/components/selectboxes/SelectBoxes.d.ts +1 -2
  169. package/lib/mjs/components/selectboxes/SelectBoxes.js +7 -6
  170. package/lib/mjs/components/table/editForm/Table.edit.display.d.ts +31 -2
  171. package/lib/mjs/components/table/editForm/Table.edit.display.js +22 -0
  172. package/lib/mjs/components/tabs/editForm/Tabs.edit.display.d.ts +30 -2
  173. package/lib/mjs/components/tabs/editForm/Tabs.edit.display.js +22 -0
  174. package/lib/mjs/components/textfield/TextField.js +20 -6
  175. package/lib/mjs/components/time/Time.js +0 -6
  176. package/lib/mjs/components/url/Url.js +0 -1
  177. package/lib/mjs/components/well/editForm/Well.edit.display.d.ts +25 -2
  178. package/lib/mjs/components/well/editForm/Well.edit.display.js +18 -0
  179. package/lib/mjs/formio.embed.js +5 -3
  180. package/lib/mjs/formio.form.d.ts +1 -7
  181. package/lib/mjs/formio.form.js +2 -32
  182. package/lib/mjs/index.d.ts +2 -1
  183. package/lib/mjs/index.js +1 -1
  184. package/lib/mjs/providers/Providers.d.ts +0 -4
  185. package/lib/mjs/providers/storage/azure.d.ts +0 -2
  186. package/lib/mjs/providers/storage/azure.js +1 -6
  187. package/lib/mjs/providers/storage/googleDrive.d.ts +0 -1
  188. package/lib/mjs/providers/storage/googleDrive.js +0 -4
  189. package/lib/mjs/providers/storage/s3.d.ts +0 -1
  190. package/lib/mjs/providers/storage/s3.js +0 -4
  191. package/lib/mjs/translations/en.d.ts +5 -0
  192. package/lib/mjs/translations/en.js +5 -0
  193. package/lib/mjs/utils/formUtils.js +1 -0
  194. package/lib/mjs/utils/utils.d.ts +2 -1
  195. package/lib/mjs/utils/utils.js +24 -7
  196. package/package.json +6 -6
  197. package/lib/cjs/components/tree/Node.d.ts +0 -55
  198. package/lib/cjs/components/tree/Node.js +0 -185
  199. package/lib/cjs/components/tree/Tree.d.ts +0 -48
  200. package/lib/cjs/components/tree/Tree.form.d.ts +0 -3
  201. package/lib/cjs/components/tree/Tree.form.js +0 -21
  202. package/lib/cjs/components/tree/Tree.js +0 -383
  203. package/lib/cjs/components/tree/editForm/Tree.edit.data.d.ts +0 -5
  204. package/lib/cjs/components/tree/editForm/Tree.edit.data.js +0 -9
  205. package/lib/cjs/components/tree/editForm/Tree.edit.display.d.ts +0 -9
  206. package/lib/cjs/components/tree/editForm/Tree.edit.display.js +0 -12
  207. package/lib/cjs/components/tree/fixtures/comp1.d.ts +0 -23
  208. package/lib/cjs/components/tree/fixtures/comp1.js +0 -24
  209. package/lib/cjs/components/tree/fixtures/comp2.d.ts +0 -116
  210. package/lib/cjs/components/tree/fixtures/comp2.js +0 -82
  211. package/lib/cjs/components/tree/fixtures/comp3.d.ts +0 -24
  212. package/lib/cjs/components/tree/fixtures/comp3.js +0 -25
  213. package/lib/cjs/components/tree/fixtures/comp4.d.ts +0 -42
  214. package/lib/cjs/components/tree/fixtures/comp4.js +0 -47
  215. package/lib/cjs/components/tree/fixtures/index.d.ts +0 -5
  216. package/lib/cjs/components/tree/fixtures/index.js +0 -14
  217. package/lib/cjs/validator/Rules.d.ts +0 -53
  218. package/lib/cjs/validator/Rules.js +0 -22
  219. package/lib/cjs/validator/Validator.d.ts +0 -228
  220. package/lib/cjs/validator/Validator.js +0 -1113
  221. package/lib/cjs/validator/conjunctions/index.d.ts +0 -7
  222. package/lib/cjs/validator/conjunctions/index.js +0 -18
  223. package/lib/cjs/validator/operators/index.d.ts +0 -7
  224. package/lib/cjs/validator/operators/index.js +0 -18
  225. package/lib/cjs/validator/quickRules/index.d.ts +0 -7
  226. package/lib/cjs/validator/quickRules/index.js +0 -18
  227. package/lib/cjs/validator/rules/Custom.d.ts +0 -5
  228. package/lib/cjs/validator/rules/Custom.js +0 -30
  229. package/lib/cjs/validator/rules/Date.d.ts +0 -5
  230. package/lib/cjs/validator/rules/Date.js +0 -25
  231. package/lib/cjs/validator/rules/Day.d.ts +0 -5
  232. package/lib/cjs/validator/rules/Day.js +0 -58
  233. package/lib/cjs/validator/rules/Email.d.ts +0 -5
  234. package/lib/cjs/validator/rules/Email.js +0 -24
  235. package/lib/cjs/validator/rules/JSON.d.ts +0 -5
  236. package/lib/cjs/validator/rules/JSON.js +0 -29
  237. package/lib/cjs/validator/rules/Mask.d.ts +0 -5
  238. package/lib/cjs/validator/rules/Mask.js +0 -32
  239. package/lib/cjs/validator/rules/Max.d.ts +0 -5
  240. package/lib/cjs/validator/rules/Max.js +0 -21
  241. package/lib/cjs/validator/rules/MaxDate.d.ts +0 -5
  242. package/lib/cjs/validator/rules/MaxDate.js +0 -34
  243. package/lib/cjs/validator/rules/MaxLength.d.ts +0 -5
  244. package/lib/cjs/validator/rules/MaxLength.js +0 -20
  245. package/lib/cjs/validator/rules/MaxWords.d.ts +0 -5
  246. package/lib/cjs/validator/rules/MaxWords.js +0 -20
  247. package/lib/cjs/validator/rules/MaxYear.d.ts +0 -5
  248. package/lib/cjs/validator/rules/MaxYear.js +0 -22
  249. package/lib/cjs/validator/rules/Min.d.ts +0 -5
  250. package/lib/cjs/validator/rules/Min.js +0 -21
  251. package/lib/cjs/validator/rules/MinDate.d.ts +0 -5
  252. package/lib/cjs/validator/rules/MinDate.js +0 -30
  253. package/lib/cjs/validator/rules/MinLength.d.ts +0 -5
  254. package/lib/cjs/validator/rules/MinLength.js +0 -20
  255. package/lib/cjs/validator/rules/MinWords.d.ts +0 -5
  256. package/lib/cjs/validator/rules/MinWords.js +0 -20
  257. package/lib/cjs/validator/rules/MinYear.d.ts +0 -5
  258. package/lib/cjs/validator/rules/MinYear.js +0 -22
  259. package/lib/cjs/validator/rules/Pattern.d.ts +0 -5
  260. package/lib/cjs/validator/rules/Pattern.js +0 -20
  261. package/lib/cjs/validator/rules/Required.d.ts +0 -5
  262. package/lib/cjs/validator/rules/Required.js +0 -17
  263. package/lib/cjs/validator/rules/Rule.d.ts +0 -7
  264. package/lib/cjs/validator/rules/Rule.js +0 -12
  265. package/lib/cjs/validator/rules/Select.d.ts +0 -5
  266. package/lib/cjs/validator/rules/Select.js +0 -95
  267. package/lib/cjs/validator/rules/Time.d.ts +0 -5
  268. package/lib/cjs/validator/rules/Time.js +0 -19
  269. package/lib/cjs/validator/rules/Unique.d.ts +0 -5
  270. package/lib/cjs/validator/rules/Unique.js +0 -69
  271. package/lib/cjs/validator/rules/Url.d.ts +0 -5
  272. package/lib/cjs/validator/rules/Url.js +0 -23
  273. package/lib/cjs/validator/rules/index.d.ts +0 -47
  274. package/lib/cjs/validator/rules/index.js +0 -51
  275. package/lib/cjs/validator/transformers/index.d.ts +0 -7
  276. package/lib/cjs/validator/transformers/index.js +0 -18
  277. package/lib/cjs/validator/valueSources/index.d.ts +0 -7
  278. package/lib/cjs/validator/valueSources/index.js +0 -18
  279. package/lib/mjs/components/tree/Node.d.ts +0 -55
  280. package/lib/mjs/components/tree/Node.js +0 -179
  281. package/lib/mjs/components/tree/Tree.d.ts +0 -48
  282. package/lib/mjs/components/tree/Tree.form.d.ts +0 -3
  283. package/lib/mjs/components/tree/Tree.form.js +0 -15
  284. package/lib/mjs/components/tree/Tree.js +0 -384
  285. package/lib/mjs/components/tree/editForm/Tree.edit.data.d.ts +0 -5
  286. package/lib/mjs/components/tree/editForm/Tree.edit.data.js +0 -7
  287. package/lib/mjs/components/tree/editForm/Tree.edit.display.d.ts +0 -9
  288. package/lib/mjs/components/tree/editForm/Tree.edit.display.js +0 -10
  289. package/lib/mjs/components/tree/fixtures/comp1.d.ts +0 -23
  290. package/lib/mjs/components/tree/fixtures/comp1.js +0 -22
  291. package/lib/mjs/components/tree/fixtures/comp2.d.ts +0 -116
  292. package/lib/mjs/components/tree/fixtures/comp2.js +0 -80
  293. package/lib/mjs/components/tree/fixtures/comp3.d.ts +0 -24
  294. package/lib/mjs/components/tree/fixtures/comp3.js +0 -23
  295. package/lib/mjs/components/tree/fixtures/comp4.d.ts +0 -42
  296. package/lib/mjs/components/tree/fixtures/comp4.js +0 -45
  297. package/lib/mjs/components/tree/fixtures/index.d.ts +0 -5
  298. package/lib/mjs/components/tree/fixtures/index.js +0 -5
  299. package/lib/mjs/validator/Rules.d.ts +0 -53
  300. package/lib/mjs/validator/Rules.js +0 -17
  301. package/lib/mjs/validator/Validator.d.ts +0 -228
  302. package/lib/mjs/validator/Validator.js +0 -1103
  303. package/lib/mjs/validator/conjunctions/index.d.ts +0 -7
  304. package/lib/mjs/validator/conjunctions/index.js +0 -16
  305. package/lib/mjs/validator/operators/index.d.ts +0 -7
  306. package/lib/mjs/validator/operators/index.js +0 -16
  307. package/lib/mjs/validator/quickRules/index.d.ts +0 -7
  308. package/lib/mjs/validator/quickRules/index.js +0 -16
  309. package/lib/mjs/validator/rules/Custom.d.ts +0 -5
  310. package/lib/mjs/validator/rules/Custom.js +0 -21
  311. package/lib/mjs/validator/rules/Date.d.ts +0 -5
  312. package/lib/mjs/validator/rules/Date.js +0 -16
  313. package/lib/mjs/validator/rules/Day.d.ts +0 -5
  314. package/lib/mjs/validator/rules/Day.js +0 -49
  315. package/lib/mjs/validator/rules/Email.d.ts +0 -5
  316. package/lib/mjs/validator/rules/Email.js +0 -15
  317. package/lib/mjs/validator/rules/JSON.d.ts +0 -5
  318. package/lib/mjs/validator/rules/JSON.js +0 -20
  319. package/lib/mjs/validator/rules/Mask.d.ts +0 -5
  320. package/lib/mjs/validator/rules/Mask.js +0 -23
  321. package/lib/mjs/validator/rules/Max.d.ts +0 -5
  322. package/lib/mjs/validator/rules/Max.js +0 -12
  323. package/lib/mjs/validator/rules/MaxDate.d.ts +0 -5
  324. package/lib/mjs/validator/rules/MaxDate.js +0 -25
  325. package/lib/mjs/validator/rules/MaxLength.d.ts +0 -5
  326. package/lib/mjs/validator/rules/MaxLength.js +0 -11
  327. package/lib/mjs/validator/rules/MaxWords.d.ts +0 -5
  328. package/lib/mjs/validator/rules/MaxWords.js +0 -11
  329. package/lib/mjs/validator/rules/MaxYear.d.ts +0 -5
  330. package/lib/mjs/validator/rules/MaxYear.js +0 -13
  331. package/lib/mjs/validator/rules/Min.d.ts +0 -5
  332. package/lib/mjs/validator/rules/Min.js +0 -12
  333. package/lib/mjs/validator/rules/MinDate.d.ts +0 -5
  334. package/lib/mjs/validator/rules/MinDate.js +0 -21
  335. package/lib/mjs/validator/rules/MinLength.d.ts +0 -5
  336. package/lib/mjs/validator/rules/MinLength.js +0 -11
  337. package/lib/mjs/validator/rules/MinWords.d.ts +0 -5
  338. package/lib/mjs/validator/rules/MinWords.js +0 -11
  339. package/lib/mjs/validator/rules/MinYear.d.ts +0 -5
  340. package/lib/mjs/validator/rules/MinYear.js +0 -13
  341. package/lib/mjs/validator/rules/Pattern.d.ts +0 -5
  342. package/lib/mjs/validator/rules/Pattern.js +0 -11
  343. package/lib/mjs/validator/rules/Required.d.ts +0 -5
  344. package/lib/mjs/validator/rules/Required.js +0 -8
  345. package/lib/mjs/validator/rules/Rule.d.ts +0 -7
  346. package/lib/mjs/validator/rules/Rule.js +0 -9
  347. package/lib/mjs/validator/rules/Select.d.ts +0 -5
  348. package/lib/mjs/validator/rules/Select.js +0 -86
  349. package/lib/mjs/validator/rules/Time.d.ts +0 -5
  350. package/lib/mjs/validator/rules/Time.js +0 -10
  351. package/lib/mjs/validator/rules/Unique.d.ts +0 -5
  352. package/lib/mjs/validator/rules/Unique.js +0 -60
  353. package/lib/mjs/validator/rules/Url.d.ts +0 -5
  354. package/lib/mjs/validator/rules/Url.js +0 -14
  355. package/lib/mjs/validator/rules/index.d.ts +0 -47
  356. package/lib/mjs/validator/rules/index.js +0 -46
  357. package/lib/mjs/validator/transformers/index.d.ts +0 -7
  358. package/lib/mjs/validator/transformers/index.js +0 -16
  359. package/lib/mjs/validator/valueSources/index.d.ts +0 -7
  360. package/lib/mjs/validator/valueSources/index.js +0 -16
@@ -1,1113 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ValidationChecker = exports.default = void 0;
7
- const lodash_1 = __importDefault(require("lodash"));
8
- const utils_1 = require("../utils/utils");
9
- const moment_1 = __importDefault(require("moment"));
10
- const fetch_ponyfill_1 = __importDefault(require("fetch-ponyfill"));
11
- const { fetch, Headers, Request } = (0, fetch_ponyfill_1.default)({
12
- Promise: Promise
13
- });
14
- const calendarUtils_1 = require("../utils/calendarUtils");
15
- const Rules_1 = __importDefault(require("./Rules"));
16
- class ValidationChecker {
17
- constructor(config = {}) {
18
- this.config = lodash_1.default.defaults(config, ValidationChecker.config);
19
- this.validators = {
20
- required: {
21
- key: 'validate.required',
22
- method: 'validateRequired',
23
- hasLabel: true,
24
- message(component) {
25
- return component.t(component.errorMessage('required'), {
26
- field: component.errorLabel,
27
- data: component.data
28
- });
29
- },
30
- check(component, setting, value) {
31
- if (!(0, utils_1.boolValue)(setting) || component.isValueHidden()) {
32
- return true;
33
- }
34
- const isCalendar = component.validators.some(validator => validator === 'calendar');
35
- if (!value && isCalendar && component.widget.enteredDate) {
36
- return !this.validators.calendar.check.call(this, component, setting, value);
37
- }
38
- return !component.isEmpty(value);
39
- }
40
- },
41
- onlyAvailableItems: {
42
- key: 'validate.onlyAvailableItems',
43
- method: 'validateValueAvailability',
44
- hasLabel: true,
45
- message(component) {
46
- return component.t(component.errorMessage('valueIsNotAvailable'), {
47
- field: component.errorLabel,
48
- data: component.data
49
- });
50
- },
51
- check(component, setting) {
52
- return !(0, utils_1.boolValue)(setting);
53
- }
54
- },
55
- unique: {
56
- key: 'validate.unique',
57
- hasLabel: true,
58
- message(component) {
59
- return component.t(component.errorMessage('unique'), {
60
- field: component.errorLabel,
61
- data: component.data
62
- });
63
- },
64
- check(component, setting, value) {
65
- // Skip if setting is falsy
66
- if (!(0, utils_1.boolValue)(setting)) {
67
- return true;
68
- }
69
- // Skip if value is empty object or falsy
70
- if (!value || lodash_1.default.isObjectLike(value) && lodash_1.default.isEmpty(value)) {
71
- return true;
72
- }
73
- // Skip if we don't have a database connection
74
- if (!this.config.db) {
75
- return true;
76
- }
77
- return new Promise(resolve => {
78
- var _a;
79
- const form = this.config.form;
80
- const submission = this.config.submission;
81
- const path = `data.${component.path}`;
82
- const addPathQueryParams = (pathQueryParams, query, path) => {
83
- const pathArray = path.split(/\[\d+\]?./);
84
- const needValuesInArray = pathArray.length > 1;
85
- let pathToValue = path;
86
- if (needValuesInArray) {
87
- pathToValue = pathArray.shift();
88
- const pathQueryObj = {};
89
- lodash_1.default.reduce(pathArray, (pathQueryPath, pathPart, index) => {
90
- const isLastPathPart = index === (pathArray.length - 1);
91
- const obj = lodash_1.default.get(pathQueryObj, pathQueryPath, pathQueryObj);
92
- const addedPath = `$elemMatch['${pathPart}']`;
93
- lodash_1.default.set(obj, addedPath, isLastPathPart ? pathQueryParams : {});
94
- return pathQueryPath ? `${pathQueryPath}.${addedPath}` : addedPath;
95
- }, '');
96
- query[pathToValue] = pathQueryObj;
97
- }
98
- else {
99
- query[pathToValue] = pathQueryParams;
100
- }
101
- };
102
- // Build the query
103
- const query = { form: form._id };
104
- let collationOptions = {};
105
- if (lodash_1.default.isString(value)) {
106
- if (component.component.dbIndex) {
107
- addPathQueryParams(value, query, path);
108
- }
109
- // These are kind of hacky but provides for a more efficient "unique" validation when the string is an email,
110
- // because we (by and large) only have to worry about ASCII and partial unicode; this way, we can use collation-
111
- // aware indexes with case insensitive email searches to make things like login and registration a whole lot faster
112
- else if (component.component.type === 'email' ||
113
- (component.component.type === 'textfield' && ((_a = component.component.validate) === null || _a === void 0 ? void 0 : _a.pattern) === '[A-Za-z0-9]+')) {
114
- addPathQueryParams(value, query, path);
115
- collationOptions = { collation: { locale: 'en', strength: 2 } };
116
- }
117
- else {
118
- addPathQueryParams({
119
- $regex: new RegExp(`^${(0, utils_1.escapeRegExCharacters)(value)}$`),
120
- $options: 'i'
121
- }, query, path);
122
- }
123
- }
124
- // FOR-213 - Pluck the unique location id
125
- else if (lodash_1.default.isPlainObject(value) &&
126
- value.address &&
127
- value.address['address_components'] &&
128
- value.address['place_id']) {
129
- addPathQueryParams({
130
- $regex: new RegExp(`^${(0, utils_1.escapeRegExCharacters)(value.address['place_id'])}$`),
131
- $options: 'i'
132
- }, query, `${path}.address.place_id`);
133
- }
134
- // Compare the contents of arrays vs the order.
135
- else if (lodash_1.default.isArray(value)) {
136
- addPathQueryParams({ $all: value }, query, path);
137
- }
138
- else if (lodash_1.default.isObject(value) || lodash_1.default.isNumber(value)) {
139
- addPathQueryParams({ $eq: value }, query, path);
140
- }
141
- // Only search for non-deleted items
142
- query.deleted = { $eq: null };
143
- query.state = 'submitted';
144
- const uniqueValidationCallback = (err, result) => {
145
- if (err) {
146
- return resolve(false);
147
- }
148
- else if (result) {
149
- // Only OK if it matches the current submission
150
- if (submission._id && (result._id.toString() === submission._id)) {
151
- resolve(true);
152
- }
153
- else {
154
- component.conflictId = result._id.toString();
155
- return resolve(false);
156
- }
157
- }
158
- else {
159
- return resolve(true);
160
- }
161
- };
162
- // Try to find an existing value within the form
163
- this.config.db.findOne(query, null, collationOptions, (err, result) => {
164
- if (err && collationOptions.collation) {
165
- // presume this error comes from db compatibility, try again as regex
166
- delete query[path];
167
- addPathQueryParams({
168
- $regex: new RegExp(`^${(0, utils_1.escapeRegExCharacters)(value)}$`),
169
- $options: 'i'
170
- }, query, path);
171
- this.config.db.findOne(query, uniqueValidationCallback);
172
- }
173
- else {
174
- return uniqueValidationCallback(err, result);
175
- }
176
- });
177
- }).catch(() => false);
178
- }
179
- },
180
- multiple: {
181
- key: 'validate.multiple',
182
- hasLabel: true,
183
- message(component) {
184
- const shouldBeArray = (0, utils_1.boolValue)(component.component.multiple) || Array.isArray(component.emptyValue);
185
- const isRequired = component.component.validate.required;
186
- const messageKey = shouldBeArray ? (isRequired ? 'array_nonempty' : 'array') : 'nonarray';
187
- return component.t(component.errorMessage(messageKey), {
188
- field: component.errorLabel,
189
- data: component.data
190
- });
191
- },
192
- check(component, setting, value) {
193
- // Skip multiple validation if the component tells us to
194
- if (!component.validateMultiple()) {
195
- return true;
196
- }
197
- const shouldBeArray = (0, utils_1.boolValue)(setting);
198
- const canBeArray = Array.isArray(component.emptyValue);
199
- const isArray = Array.isArray(value);
200
- const isRequired = component.component.validate.required;
201
- if (shouldBeArray) {
202
- if (isArray) {
203
- return isRequired ? !!value.length : true;
204
- }
205
- else {
206
- // Null/undefined is ok if this value isn't required; anything else should fail
207
- return lodash_1.default.isNil(value) ? !isRequired : false;
208
- }
209
- }
210
- else {
211
- return canBeArray || !isArray;
212
- }
213
- }
214
- },
215
- select: {
216
- key: 'validate.select',
217
- hasLabel: true,
218
- message(component) {
219
- return component.t(component.errorMessage('select'), {
220
- field: component.errorLabel,
221
- data: component.data
222
- });
223
- },
224
- check(component, setting, value, data, index, row, async) {
225
- // Skip if setting is falsy
226
- if (!(0, utils_1.boolValue)(setting)) {
227
- return true;
228
- }
229
- // Skip if value is empty
230
- if (!value || lodash_1.default.isEmpty(value)) {
231
- return true;
232
- }
233
- // Skip if we're not async-capable
234
- if (!async) {
235
- return true;
236
- }
237
- const schema = component.component;
238
- // Initialize the request options
239
- const requestOptions = {
240
- url: setting,
241
- method: 'GET',
242
- qs: {},
243
- json: true,
244
- headers: {}
245
- };
246
- // If the url is a boolean value
247
- if (lodash_1.default.isBoolean(requestOptions.url)) {
248
- requestOptions.url = !!requestOptions.url;
249
- if (!requestOptions.url ||
250
- schema.dataSrc !== 'url' ||
251
- !schema.data.url ||
252
- !schema.searchField) {
253
- return true;
254
- }
255
- // Get the validation url
256
- requestOptions.url = schema.data.url;
257
- // Add the search field
258
- requestOptions.qs[schema.searchField] = value;
259
- // Add the filters
260
- if (schema.filter) {
261
- requestOptions.url += (!requestOptions.url.includes('?') ? '?' : '&') + schema.filter;
262
- }
263
- // If they only wish to return certain fields.
264
- if (schema.selectFields) {
265
- requestOptions.qs.select = schema.selectFields;
266
- }
267
- }
268
- if (!requestOptions.url) {
269
- return true;
270
- }
271
- // Make sure to interpolate.
272
- requestOptions.url = (0, utils_1.interpolate)(requestOptions.url, { data: component.data });
273
- // Add query string to URL
274
- requestOptions.url += (requestOptions.url.includes('?') ? '&' : '?') + lodash_1.default.chain(requestOptions.qs)
275
- .map((val, key) => `${encodeURIComponent(key)}=${encodeURIComponent(val)}`)
276
- .join('&')
277
- .value();
278
- // Set custom headers.
279
- if (schema.data && schema.data.headers) {
280
- lodash_1.default.each(schema.data.headers, header => {
281
- if (header.key) {
282
- requestOptions.headers[header.key] = header.value;
283
- }
284
- });
285
- }
286
- // Set form.io authentication.
287
- if (schema.authenticate && this.config.token) {
288
- requestOptions.headers['x-jwt-token'] = this.config.token;
289
- }
290
- return fetch(new Request(requestOptions.url, {
291
- headers: new Headers(requestOptions.headers)
292
- }))
293
- .then(response => {
294
- if (!response.ok) {
295
- return false;
296
- }
297
- return response.json();
298
- })
299
- .then((results) => {
300
- return results && results.length;
301
- })
302
- .catch(() => false);
303
- }
304
- },
305
- min: {
306
- key: 'validate.min',
307
- hasLabel: true,
308
- message(component, setting) {
309
- return component.t(component.errorMessage('min'), {
310
- field: component.errorLabel,
311
- min: parseFloat(setting),
312
- data: component.data
313
- });
314
- },
315
- check(component, setting, value) {
316
- const min = parseFloat(setting);
317
- const parsedValue = parseFloat(value);
318
- if (Number.isNaN(min) || Number.isNaN(parsedValue)) {
319
- return true;
320
- }
321
- return parsedValue >= min;
322
- }
323
- },
324
- max: {
325
- key: 'validate.max',
326
- hasLabel: true,
327
- message(component, setting) {
328
- return component.t(component.errorMessage('max'), {
329
- field: component.errorLabel,
330
- max: parseFloat(setting),
331
- data: component.data
332
- });
333
- },
334
- check(component, setting, value) {
335
- const max = parseFloat(setting);
336
- const parsedValue = parseFloat(value);
337
- if (Number.isNaN(max) || Number.isNaN(parsedValue)) {
338
- return true;
339
- }
340
- return parsedValue <= max;
341
- }
342
- },
343
- minSelectedCount: {
344
- key: 'validate.minSelectedCount',
345
- message(component, setting) {
346
- return component.component.minSelectedCountMessage
347
- ? component.component.minSelectedCountMessage
348
- : component.t(component.errorMessage('minSelectedCount'), {
349
- minCount: parseFloat(setting),
350
- data: component.data
351
- });
352
- },
353
- check(component, setting, value) {
354
- const min = parseFloat(setting);
355
- if (!min) {
356
- return true;
357
- }
358
- const count = Object.keys(value).reduce((total, key) => {
359
- if (value[key]) {
360
- total++;
361
- }
362
- return total;
363
- }, 0);
364
- // Should not be triggered if there is no options selected at all
365
- return !count || count >= min;
366
- }
367
- },
368
- maxSelectedCount: {
369
- key: 'validate.maxSelectedCount',
370
- message(component, setting) {
371
- return component.component.maxSelectedCountMessage
372
- ? component.component.maxSelectedCountMessage
373
- : component.t(component.errorMessage('maxSelectedCount'), {
374
- minCount: parseFloat(setting),
375
- data: component.data
376
- });
377
- },
378
- check(component, setting, value) {
379
- const max = parseFloat(setting);
380
- if (!max) {
381
- return true;
382
- }
383
- const count = Object.keys(value).reduce((total, key) => {
384
- if (value[key]) {
385
- total++;
386
- }
387
- return total;
388
- }, 0);
389
- return count <= max;
390
- }
391
- },
392
- minLength: {
393
- key: 'validate.minLength',
394
- hasLabel: true,
395
- message(component, setting) {
396
- return component.t(component.errorMessage('minLength'), {
397
- field: component.errorLabel,
398
- length: setting,
399
- data: component.data
400
- });
401
- },
402
- check(component, setting, value) {
403
- const minLength = parseInt(setting, 10);
404
- if (!value || !minLength || (typeof value !== 'string') || component.isEmpty(value)) {
405
- return true;
406
- }
407
- return (value.length >= minLength);
408
- }
409
- },
410
- maxLength: {
411
- key: 'validate.maxLength',
412
- hasLabel: true,
413
- message(component, setting) {
414
- return component.t(component.errorMessage('maxLength'), {
415
- field: component.errorLabel,
416
- length: setting,
417
- data: component.data
418
- });
419
- },
420
- check(component, setting, value) {
421
- const maxLength = parseInt(setting, 10);
422
- if (!maxLength || (typeof value !== 'string')) {
423
- return true;
424
- }
425
- return (value.length <= maxLength);
426
- }
427
- },
428
- maxWords: {
429
- key: 'validate.maxWords',
430
- hasLabel: true,
431
- message(component, setting) {
432
- return component.t(component.errorMessage('maxWords'), {
433
- field: component.errorLabel,
434
- length: setting,
435
- data: component.data
436
- });
437
- },
438
- check(component, setting, value) {
439
- const maxWords = parseInt(setting, 10);
440
- if (!maxWords || (typeof value !== 'string')) {
441
- return true;
442
- }
443
- return (value.trim().split(/\s+/).length <= maxWords);
444
- }
445
- },
446
- minWords: {
447
- key: 'validate.minWords',
448
- hasLabel: true,
449
- message(component, setting) {
450
- return component.t(component.errorMessage('minWords'), {
451
- field: component.errorLabel,
452
- length: setting,
453
- data: component.data
454
- });
455
- },
456
- check(component, setting, value) {
457
- const minWords = parseInt(setting, 10);
458
- if (!minWords || !value || (typeof value !== 'string')) {
459
- return true;
460
- }
461
- return (value.trim().split(/\s+/).length >= minWords);
462
- }
463
- },
464
- email: {
465
- hasLabel: true,
466
- message(component) {
467
- return component.t(component.errorMessage('invalid_email'), {
468
- field: component.errorLabel,
469
- data: component.data
470
- });
471
- },
472
- check(component, setting, value) {
473
- /* eslint-disable max-len */
474
- // From http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
475
- const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
476
- /* eslint-enable max-len */
477
- // Allow emails to be valid if the component is pristine and no value is provided.
478
- return !value || re.test(value);
479
- }
480
- },
481
- url: {
482
- hasLabel: true,
483
- message(component) {
484
- return component.t(component.errorMessage('invalid_url'), {
485
- field: component.errorLabel,
486
- data: component.data
487
- });
488
- },
489
- check(component, setting, value) {
490
- /* eslint-disable max-len */
491
- // From https://stackoverflow.com/questions/8667070/javascript-regular-expression-to-validate-url
492
- const re = /^(?:(?:(?:https?|ftp):)?\/\/)?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
493
- // From http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
494
- const emailRe = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
495
- /* eslint-enable max-len */
496
- // Allow urls to be valid if the component is pristine and no value is provided.
497
- return !value || (re.test(value) && !emailRe.test(value));
498
- }
499
- },
500
- date: {
501
- hasLabel: true,
502
- message(component) {
503
- return component.t(component.errorMessage('invalid_date'), {
504
- field: component.errorLabel,
505
- data: component.data
506
- });
507
- },
508
- check(component, setting, value) {
509
- if (!value) {
510
- return true;
511
- }
512
- if (value === 'Invalid date' || value === 'Invalid Date') {
513
- return false;
514
- }
515
- if (typeof value === 'string') {
516
- value = new Date(value);
517
- }
518
- return value instanceof Date === true && value.toString() !== 'Invalid Date';
519
- }
520
- },
521
- day: {
522
- hasLabel: true,
523
- message(component) {
524
- return component.t(component.errorMessage('invalid_day'), {
525
- field: component.errorLabel,
526
- data: component.data
527
- });
528
- },
529
- check(component, setting, value) {
530
- if (!value) {
531
- return true;
532
- }
533
- const [DAY, MONTH, YEAR] = component.dayFirst ? [0, 1, 2] : [1, 0, 2];
534
- const values = value.split('/').map(x => parseInt(x, 10)), day = values[DAY], month = values[MONTH], year = values[YEAR], maxDay = getDaysInMonthCount(month, year);
535
- if (day < 0 || day > maxDay) {
536
- return false;
537
- }
538
- if (month < 0 || month > 12) {
539
- return false;
540
- }
541
- if (year < 0 || year > 9999) {
542
- return false;
543
- }
544
- return true;
545
- function isLeapYear(year) {
546
- // Year is leap if it is evenly divisible by 400 or evenly divisible by 4 and not evenly divisible by 100.
547
- return !(year % 400) || (!!(year % 100) && !(year % 4));
548
- }
549
- function getDaysInMonthCount(month, year) {
550
- switch (month) {
551
- case 1: // January
552
- case 3: // March
553
- case 5: // May
554
- case 7: // July
555
- case 8: // August
556
- case 10: // October
557
- case 12: // December
558
- return 31;
559
- case 4: // April
560
- case 6: // June
561
- case 9: // September
562
- case 11: // November
563
- return 30;
564
- case 2: // February
565
- return isLeapYear(year) ? 29 : 28;
566
- default:
567
- return 31;
568
- }
569
- }
570
- }
571
- },
572
- pattern: {
573
- key: 'validate.pattern',
574
- hasLabel: true,
575
- message(component, setting) {
576
- return component.t(lodash_1.default.get(component, 'component.validate.patternMessage', component.errorMessage('pattern')), {
577
- field: component.errorLabel,
578
- pattern: setting,
579
- data: component.data
580
- });
581
- },
582
- check(component, setting, value) {
583
- if (component.isEmpty(value))
584
- return true;
585
- const pattern = setting;
586
- if (!pattern) {
587
- return true;
588
- }
589
- const regex = new RegExp(`^${pattern}$`);
590
- return regex.test(value);
591
- }
592
- },
593
- json: {
594
- key: 'validate.json',
595
- check(component, setting, value, data, index, row) {
596
- if (!setting) {
597
- return true;
598
- }
599
- const valid = component.evaluate(setting, {
600
- data,
601
- row,
602
- rowIndex: index,
603
- input: value
604
- });
605
- if (valid === null) {
606
- return true;
607
- }
608
- return valid;
609
- }
610
- },
611
- mask: {
612
- key: 'inputMask',
613
- hasLabel: true,
614
- message(component) {
615
- return component.t(component.errorMessage('mask'), {
616
- field: component.errorLabel,
617
- data: component.data
618
- });
619
- },
620
- check(component, setting, value) {
621
- let inputMask;
622
- if (component.isMultipleMasksField) {
623
- const maskName = value ? value.maskName : undefined;
624
- const formioInputMask = component.getMaskByName(maskName);
625
- if (formioInputMask) {
626
- inputMask = formioInputMask;
627
- }
628
- value = value ? value.value : value;
629
- }
630
- else {
631
- inputMask = setting;
632
- }
633
- inputMask = inputMask ? (0, utils_1.getInputMask)(inputMask) : null;
634
- if (value && inputMask && !component.skipMaskValidation) {
635
- // If char which is used inside mask placeholder was used in the mask, replace it with space to prevent errors
636
- inputMask = inputMask.map((char) => char === component.placeholderChar ? ' ' : char);
637
- return (0, utils_1.matchInputMask)(value, inputMask);
638
- }
639
- return true;
640
- }
641
- },
642
- custom: {
643
- key: 'validate.custom',
644
- message(component) {
645
- return component.t(component.errorMessage('custom'), {
646
- field: component.errorLabel,
647
- data: component.data
648
- });
649
- },
650
- check(component, setting, value, data, index, row) {
651
- if (!setting) {
652
- return true;
653
- }
654
- const valid = component.evaluate(setting, {
655
- valid: true,
656
- data,
657
- rowIndex: index,
658
- row,
659
- input: value
660
- }, 'valid', true);
661
- if (valid === null) {
662
- return true;
663
- }
664
- return valid;
665
- }
666
- },
667
- maxDate: {
668
- key: 'maxDate',
669
- hasLabel: true,
670
- message(component, setting) {
671
- const date = (0, utils_1.getDateSetting)(setting);
672
- return component.t(component.errorMessage('maxDate'), {
673
- field: component.errorLabel,
674
- maxDate: (0, moment_1.default)(date).format(component.format),
675
- });
676
- },
677
- check(component, setting, value) {
678
- //if any parts of day are missing, skip maxDate validation
679
- if (component.isPartialDay && component.isPartialDay(value)) {
680
- return true;
681
- }
682
- const date = component.getValidationFormat ? (0, moment_1.default)(value, component.getValidationFormat()) : (0, moment_1.default)(value);
683
- const maxDate = (0, utils_1.getDateSetting)(setting);
684
- if (lodash_1.default.isNull(maxDate)) {
685
- return true;
686
- }
687
- else {
688
- maxDate.setHours(0, 0, 0, 0);
689
- }
690
- return date.isBefore(maxDate) || date.isSame(maxDate);
691
- }
692
- },
693
- minDate: {
694
- key: 'minDate',
695
- hasLabel: true,
696
- message(component, setting) {
697
- const date = (0, utils_1.getDateSetting)(setting);
698
- return component.t(component.errorMessage('minDate'), {
699
- field: component.errorLabel,
700
- minDate: (0, moment_1.default)(date).format(component.format),
701
- });
702
- },
703
- check(component, setting, value) {
704
- //if any parts of day are missing, skip minDate validation
705
- if (component.isPartialDay && component.isPartialDay(value)) {
706
- return true;
707
- }
708
- const date = component.getValidationFormat ? (0, moment_1.default)(value, component.getValidationFormat()) : (0, moment_1.default)(value);
709
- const minDate = (0, utils_1.getDateSetting)(setting);
710
- if (lodash_1.default.isNull(minDate)) {
711
- return true;
712
- }
713
- else {
714
- minDate.setHours(0, 0, 0, 0);
715
- }
716
- return date.isAfter(minDate) || date.isSame(minDate);
717
- }
718
- },
719
- minYear: {
720
- key: 'minYear',
721
- hasLabel: true,
722
- message(component, setting) {
723
- return component.t(component.errorMessage('minYear'), {
724
- field: component.errorLabel,
725
- minYear: setting,
726
- });
727
- },
728
- check(component, setting, value) {
729
- const minYear = setting;
730
- let year = /\d{4}$/.exec(value);
731
- year = year ? year[0] : null;
732
- if (!(+minYear) || !(+year)) {
733
- return true;
734
- }
735
- return +year >= +minYear;
736
- }
737
- },
738
- maxYear: {
739
- key: 'maxYear',
740
- hasLabel: true,
741
- message(component, setting) {
742
- return component.t(component.errorMessage('maxYear'), {
743
- field: component.errorLabel,
744
- maxYear: setting,
745
- });
746
- },
747
- check(component, setting, value) {
748
- const maxYear = setting;
749
- let year = /\d{4}$/.exec(value);
750
- year = year ? year[0] : null;
751
- if (!(+maxYear) || !(+year)) {
752
- return true;
753
- }
754
- return +year <= +maxYear;
755
- }
756
- },
757
- calendar: {
758
- key: 'validate.calendar',
759
- messageText: '',
760
- hasLabel: true,
761
- message(component) {
762
- return component.t(component.errorMessage(this.validators.calendar.messageText), {
763
- field: component.errorLabel,
764
- maxDate: (0, moment_1.default)(component.dataValue).format(component.format),
765
- });
766
- },
767
- check(component, setting, value, data, index) {
768
- this.validators.calendar.messageText = '';
769
- const widget = component.getWidget(index);
770
- if (!widget) {
771
- return true;
772
- }
773
- const { settings, enteredDate } = widget;
774
- const { minDate, maxDate, format } = settings;
775
- const momentFormat = [(0, utils_1.convertFormatToMoment)(format)];
776
- if (momentFormat[0].match(/M{3,}/g)) {
777
- momentFormat.push(momentFormat[0].replace(/M{3,}/g, 'MM'));
778
- }
779
- if (!value && enteredDate) {
780
- const { message, result } = (0, calendarUtils_1.checkInvalidDate)(enteredDate, momentFormat, minDate, maxDate);
781
- if (!result) {
782
- this.validators.calendar.messageText = message;
783
- return result;
784
- }
785
- }
786
- if (value && enteredDate) {
787
- if ((0, moment_1.default)(value).format() !== (0, moment_1.default)(enteredDate, momentFormat, true).format() && enteredDate.match(/_/gi)) {
788
- this.validators.calendar.messageText = calendarUtils_1.CALENDAR_ERROR_MESSAGES.INCOMPLETE;
789
- return false;
790
- }
791
- else {
792
- widget.enteredDate = '';
793
- return true;
794
- }
795
- }
796
- }
797
- },
798
- time: {
799
- key: 'validate.time',
800
- messageText: 'Invalid time',
801
- hasLabel: true,
802
- message(component) {
803
- return component.t(component.errorMessage(this.validators.time.messageText), {
804
- field: component.errorLabel
805
- });
806
- },
807
- check(component, setting, value) {
808
- if (component.isEmpty(value))
809
- return true;
810
- return (0, moment_1.default)(value, component.component.format).isValid();
811
- }
812
- },
813
- availableValueProperty: {
814
- key: 'validate.availableValueProperty',
815
- method: 'validateValueProperty',
816
- messageText: 'Invalid Value Property',
817
- hasLabel: true,
818
- message(component) {
819
- return component.t(component.errorMessage(this.validators.availableValueProperty.messageText), {
820
- field: component.errorLabel,
821
- });
822
- },
823
- check(component, setting, value) {
824
- if (component.component.dataSrc === 'url' && (lodash_1.default.isUndefined(value) || lodash_1.default.isObject(value))) {
825
- return false;
826
- }
827
- return true;
828
- }
829
- }
830
- };
831
- }
832
- checkValidator(component, validator, setting, value, data, index, row, async) {
833
- let resultOrPromise = null;
834
- // Allow each component to override their own validators by implementing the validator.method
835
- if (validator.method && (typeof component[validator.method] === 'function')) {
836
- resultOrPromise = component[validator.method](setting, value, data, index, row, async);
837
- }
838
- else {
839
- resultOrPromise = validator.check.call(this, component, setting, value, data, index, row, async);
840
- }
841
- const processResult = result => {
842
- if (typeof result === 'string') {
843
- return result;
844
- }
845
- if (!result && validator.message) {
846
- return validator.message.call(this, component, setting, index, row);
847
- }
848
- return '';
849
- };
850
- if (async) {
851
- return Promise.resolve(resultOrPromise).then(processResult);
852
- }
853
- else {
854
- return processResult(resultOrPromise);
855
- }
856
- }
857
- validate(component, validatorName, value, data, index, row, async, conditionallyVisible, validationObj) {
858
- // Skip validation for conditionally hidden components
859
- if (!conditionallyVisible) {
860
- return false;
861
- }
862
- const validator = this.validators[validatorName];
863
- const setting = lodash_1.default.get(validationObj || component.component, validator.key, null);
864
- const resultOrPromise = this.checkValidator(component, validator, setting, value, data, index, row, async);
865
- const processResult = result => {
866
- var _a;
867
- if (result) {
868
- const resultData = {
869
- message: (0, utils_1.unescapeHTML)(lodash_1.default.get(result, 'message', result)),
870
- level: lodash_1.default.get(result, 'level') === 'warning' ? 'warning' : 'error',
871
- path: (0, utils_1.getArrayFromComponentPath)(component.path || ''),
872
- context: {
873
- validator: validatorName,
874
- hasLabel: validator.hasLabel,
875
- setting,
876
- key: component.key,
877
- label: component.label,
878
- value,
879
- index,
880
- input: (_a = component.refs.input) === null || _a === void 0 ? void 0 : _a[index]
881
- }
882
- };
883
- if (validatorName === 'unique' && component.conflictId) {
884
- resultData.conflictId = component.conflictId;
885
- }
886
- return resultData;
887
- }
888
- else {
889
- return false;
890
- }
891
- };
892
- if (async) {
893
- return Promise.resolve(resultOrPromise).then(processResult);
894
- }
895
- else {
896
- return processResult(resultOrPromise);
897
- }
898
- }
899
- checkComponent(component, data, row, includeWarnings = false, async = false) {
900
- var _a;
901
- const isServerSidePersistent = typeof process !== 'undefined'
902
- && lodash_1.default.get(process, 'release.name') === 'node'
903
- && !lodash_1.default.defaultTo(component.component.persistent, true);
904
- // If we're server-side and it's not a persistent component, don't run validation at all
905
- if (isServerSidePersistent || component.component.validate === false) {
906
- return async ? Promise.resolve([]) : [];
907
- }
908
- data = data || component.rootValue;
909
- row = row || component.data;
910
- const values = (component.component.multiple && Array.isArray(component.validationValue))
911
- ? component.validationValue
912
- : [component.validationValue];
913
- const conditionallyVisible = component.conditionallyVisible();
914
- const addonsValidations = [];
915
- if ((_a = component === null || component === void 0 ? void 0 : component.addons) === null || _a === void 0 ? void 0 : _a.length) {
916
- values.forEach((value) => {
917
- component.addons.forEach((addon) => {
918
- if (!addon.checkValidity(value)) {
919
- addonsValidations.push(...(addon.errors || []));
920
- }
921
- });
922
- });
923
- }
924
- // If this component has the new validation system enabled, use it instead.
925
- const validations = lodash_1.default.get(component, 'component.validations');
926
- let nextGenResultsOrPromises = [];
927
- if (validations && Array.isArray(validations) && validations.length) {
928
- const validationsGroupedByMode = lodash_1.default.chain(validations)
929
- .groupBy((validation) => validation.mode)
930
- .value();
931
- if (component.calculateCondition) {
932
- includeWarnings = true;
933
- const uiGroupedValidation = lodash_1.default.chain(validationsGroupedByMode.ui)
934
- .filter('active')
935
- .groupBy((validation) => validation.group || null)
936
- .value();
937
- const commonValidations = uiGroupedValidation.null || [];
938
- delete uiGroupedValidation.null;
939
- commonValidations.forEach(({ condition, message, severity }) => {
940
- if (!component.calculateCondition(condition)) {
941
- nextGenResultsOrPromises.push({
942
- level: severity || 'error',
943
- message: component.t(message),
944
- componentInstance: component,
945
- });
946
- }
947
- });
948
- lodash_1.default.forEach(uiGroupedValidation, (validationGroup) => {
949
- lodash_1.default.forEach(validationGroup, ({ condition, message, severity }) => {
950
- if (!component.calculateCondition(condition)) {
951
- nextGenResultsOrPromises.push({
952
- level: severity || 'error',
953
- message: component.t(message),
954
- componentInstance: component,
955
- });
956
- return false;
957
- }
958
- });
959
- });
960
- }
961
- else {
962
- nextGenResultsOrPromises = this.checkValidations(component, validations, data, row, values, async);
963
- }
964
- if (component.validators.includes('custom') && validationsGroupedByMode.js) {
965
- lodash_1.default.each(validationsGroupedByMode.js, (validation) => {
966
- nextGenResultsOrPromises.push(lodash_1.default.map(values, (value, index) => this.validate(component, 'custom', value, data, index, row, async, conditionallyVisible, validation)));
967
- });
968
- }
969
- if (component.validators.includes('json') && validationsGroupedByMode.json) {
970
- lodash_1.default.each(validationsGroupedByMode.json, (validation) => {
971
- nextGenResultsOrPromises.push(lodash_1.default.map(values, (value, index) => this.validate(component, 'json', value, data, index, row, async, conditionallyVisible, validation)));
972
- });
973
- }
974
- }
975
- const validateCustom = lodash_1.default.get(component, 'component.validate.custom');
976
- const customErrorMessage = lodash_1.default.get(component, 'component.validate.customMessage');
977
- // Run primary validators
978
- const resultsOrPromises = (0, lodash_1.default)(component.validators).chain()
979
- .map(validatorName => {
980
- if (!this.validators.hasOwnProperty(validatorName)) {
981
- return {
982
- message: `Validator for "${validatorName}" is not defined`,
983
- level: 'warning',
984
- context: {
985
- validator: validatorName,
986
- key: component.key,
987
- label: component.label
988
- }
989
- };
990
- }
991
- // Handle the case when there is no values defined and it is required.
992
- if (validatorName === 'required' && !values.length) {
993
- return [this.validate(component, validatorName, null, data, 0, row, async, conditionallyVisible)];
994
- }
995
- return lodash_1.default.map(values, (value, index) => this.validate(component, validatorName, value, data, index, row, async, conditionallyVisible));
996
- })
997
- .flatten()
998
- .value();
999
- // Run the "unique" pseudo-validator
1000
- component.component.validate = component.component.validate || {};
1001
- component.component.validate.unique = component.component.unique;
1002
- resultsOrPromises.push(this.validate(component, 'unique', component.validationValue, data, 0, data, async, conditionallyVisible));
1003
- // Run the "multiple" pseudo-validator
1004
- component.component.validate.multiple = component.component.multiple;
1005
- resultsOrPromises.push(this.validate(component, 'multiple', component.validationValue, data, 0, data, async, conditionallyVisible));
1006
- resultsOrPromises.push(...addonsValidations);
1007
- resultsOrPromises.push(...nextGenResultsOrPromises);
1008
- // Define how results should be formatted
1009
- const formatResults = results => {
1010
- // Condense to a single flat array
1011
- results = (0, lodash_1.default)(results).chain().flatten().compact().value();
1012
- if (customErrorMessage || validateCustom) {
1013
- lodash_1.default.each(results, result => {
1014
- result.message = component.t(customErrorMessage || result.message, {
1015
- field: component.errorLabel,
1016
- data,
1017
- row,
1018
- error: result
1019
- });
1020
- result.context.hasLabel = false;
1021
- });
1022
- }
1023
- return includeWarnings ? results : lodash_1.default.reject(results, result => result.level === 'warning');
1024
- };
1025
- // Wait for results if using async mode, otherwise process and return immediately
1026
- if (async) {
1027
- return Promise.all(resultsOrPromises).then(formatResults);
1028
- }
1029
- else {
1030
- return formatResults(resultsOrPromises);
1031
- }
1032
- }
1033
- /**
1034
- * Use the new validations engine to evaluate any errors.
1035
- *
1036
- * @param component
1037
- * @param validations
1038
- * @param data
1039
- * @param row
1040
- * @param values
1041
- * @returns {any[]}
1042
- */
1043
- checkValidations(component, validations, data, row, values, async) {
1044
- // Get results.
1045
- const results = validations.map((validation) => {
1046
- return this.checkRule(component, validation, data, row, values, async);
1047
- });
1048
- // Flatten array and filter out empty results.
1049
- const messages = results.reduce((prev, result) => {
1050
- if (result) {
1051
- return [...prev, ...result];
1052
- }
1053
- return prev;
1054
- }, []).filter((result) => result);
1055
- // Keep only the last error for each rule.
1056
- const rules = messages.reduce((prev, message) => {
1057
- prev[message.context.validator] = message;
1058
- return prev;
1059
- }, {});
1060
- return Object.values(rules);
1061
- }
1062
- checkRule(component, validation, data, row, values, async) {
1063
- const Rule = Rules_1.default.getRule(validation.rule);
1064
- const results = [];
1065
- if (Rule) {
1066
- const rule = new Rule(component, validation.settings, this.config);
1067
- values.map((value, index) => {
1068
- const result = rule.check(value, data, row, async);
1069
- if (result !== true) {
1070
- results.push({
1071
- level: validation.level || 'error',
1072
- message: component.t(validation.message || rule.defaultMessage, {
1073
- settings: validation.settings,
1074
- field: component.errorLabel,
1075
- data,
1076
- row,
1077
- error: result,
1078
- }),
1079
- context: {
1080
- key: component.key,
1081
- index,
1082
- label: component.label,
1083
- validator: validation.rule,
1084
- },
1085
- });
1086
- }
1087
- });
1088
- }
1089
- // If there are no results, return false so it is removed by filter.
1090
- return results.length === 0 ? false : results;
1091
- }
1092
- get check() {
1093
- return this.checkComponent;
1094
- }
1095
- get() {
1096
- lodash_1.default.get.call(this, arguments);
1097
- }
1098
- each() {
1099
- lodash_1.default.each.call(this, arguments);
1100
- }
1101
- has() {
1102
- lodash_1.default.has.call(this, arguments);
1103
- }
1104
- }
1105
- exports.ValidationChecker = ValidationChecker;
1106
- ValidationChecker.config = {
1107
- db: null,
1108
- token: null,
1109
- form: null,
1110
- submission: null
1111
- };
1112
- const instance = new ValidationChecker();
1113
- exports.default = instance;