@flipdish/ui-library 0.51.0 → 0.53.0

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 (343) hide show
  1. package/README.md +17 -16
  2. package/dist/components/atoms/Checkbox/index.cjs +4 -2
  3. package/dist/components/atoms/Checkbox/index.cjs.map +1 -1
  4. package/dist/components/atoms/Checkbox/index.d.ts.map +1 -1
  5. package/dist/components/atoms/Checkbox/index.js +4 -2
  6. package/dist/components/atoms/Checkbox/index.js.map +1 -1
  7. package/dist/components/atoms/Slider/index.cjs +2 -2
  8. package/dist/components/atoms/Slider/index.cjs.map +1 -1
  9. package/dist/components/atoms/Slider/index.d.ts +3 -1
  10. package/dist/components/atoms/Slider/index.d.ts.map +1 -1
  11. package/dist/components/atoms/Slider/index.js +2 -2
  12. package/dist/components/atoms/Slider/index.js.map +1 -1
  13. package/dist/components/forms/Form/hooks/useForm.cjs +26 -0
  14. package/dist/components/forms/Form/hooks/useForm.cjs.map +1 -0
  15. package/dist/components/forms/Form/hooks/useForm.d.ts +13 -0
  16. package/dist/components/forms/Form/hooks/useForm.d.ts.map +1 -0
  17. package/dist/components/forms/Form/hooks/useForm.js +24 -0
  18. package/dist/components/forms/Form/hooks/useForm.js.map +1 -0
  19. package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.cjs +93 -0
  20. package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.cjs.map +1 -0
  21. package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.d.ts +54 -0
  22. package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.d.ts.map +1 -0
  23. package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.js +91 -0
  24. package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.js.map +1 -0
  25. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.cjs +28 -0
  26. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.cjs.map +1 -0
  27. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.d.ts +10 -0
  28. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.d.ts.map +1 -0
  29. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.js +26 -0
  30. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.js.map +1 -0
  31. package/dist/components/forms/Form/index.cjs +63 -0
  32. package/dist/components/forms/Form/index.cjs.map +1 -0
  33. package/dist/components/forms/Form/index.d.ts +37 -0
  34. package/dist/components/forms/Form/index.d.ts.map +1 -0
  35. package/dist/components/forms/Form/index.js +59 -0
  36. package/dist/components/forms/Form/index.js.map +1 -0
  37. package/dist/components/forms/Form/utilities/formSubmit.utils.cjs +23 -0
  38. package/dist/components/forms/Form/utilities/formSubmit.utils.cjs.map +1 -0
  39. package/dist/components/forms/Form/utilities/formSubmit.utils.d.ts +14 -0
  40. package/dist/components/forms/Form/utilities/formSubmit.utils.d.ts.map +1 -0
  41. package/dist/components/forms/Form/utilities/formSubmit.utils.js +21 -0
  42. package/dist/components/forms/Form/utilities/formSubmit.utils.js.map +1 -0
  43. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.cjs +39 -0
  44. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.cjs.map +1 -0
  45. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.d.ts +17 -0
  46. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.d.ts.map +1 -0
  47. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.js +37 -0
  48. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.js.map +1 -0
  49. package/dist/components/forms/FormFooter/hooks/useHasFieldError.cjs +26 -0
  50. package/dist/components/forms/FormFooter/hooks/useHasFieldError.cjs.map +1 -0
  51. package/dist/components/forms/FormFooter/hooks/useHasFieldError.d.ts +9 -0
  52. package/dist/components/forms/FormFooter/hooks/useHasFieldError.d.ts.map +1 -0
  53. package/dist/components/forms/FormFooter/hooks/useHasFieldError.js +24 -0
  54. package/dist/components/forms/FormFooter/hooks/useHasFieldError.js.map +1 -0
  55. package/dist/components/forms/FormFooter/index.cjs +41 -0
  56. package/dist/components/forms/FormFooter/index.cjs.map +1 -0
  57. package/dist/components/forms/FormFooter/index.d.ts +56 -0
  58. package/dist/components/forms/FormFooter/index.d.ts.map +1 -0
  59. package/dist/components/forms/FormFooter/index.js +39 -0
  60. package/dist/components/forms/FormFooter/index.js.map +1 -0
  61. package/dist/components/forms/FormFooter/utilities/formFooter.utils.cjs +21 -0
  62. package/dist/components/forms/FormFooter/utilities/formFooter.utils.cjs.map +1 -0
  63. package/dist/components/forms/FormFooter/utilities/formFooter.utils.d.ts +12 -0
  64. package/dist/components/forms/FormFooter/utilities/formFooter.utils.d.ts.map +1 -0
  65. package/dist/components/forms/FormFooter/utilities/formFooter.utils.js +19 -0
  66. package/dist/components/forms/FormFooter/utilities/formFooter.utils.js.map +1 -0
  67. package/dist/components/forms/FormSaveErrorAlert/index.cjs +28 -0
  68. package/dist/components/forms/FormSaveErrorAlert/index.cjs.map +1 -0
  69. package/dist/components/forms/FormSaveErrorAlert/index.d.ts +18 -0
  70. package/dist/components/forms/FormSaveErrorAlert/index.d.ts.map +1 -0
  71. package/dist/components/forms/FormSaveErrorAlert/index.js +26 -0
  72. package/dist/components/forms/FormSaveErrorAlert/index.js.map +1 -0
  73. package/dist/components/forms/FormSection/FormSection.styles.cjs +15 -0
  74. package/dist/components/forms/FormSection/FormSection.styles.cjs.map +1 -0
  75. package/dist/components/forms/FormSection/FormSection.styles.d.ts +9 -0
  76. package/dist/components/forms/FormSection/FormSection.styles.d.ts.map +1 -0
  77. package/dist/components/forms/FormSection/FormSection.styles.js +13 -0
  78. package/dist/components/forms/FormSection/FormSection.styles.js.map +1 -0
  79. package/dist/components/forms/FormSection/index.cjs +43 -0
  80. package/dist/components/forms/FormSection/index.cjs.map +1 -0
  81. package/dist/components/forms/FormSection/index.d.ts +41 -0
  82. package/dist/components/forms/FormSection/index.d.ts.map +1 -0
  83. package/dist/components/forms/FormSection/index.js +41 -0
  84. package/dist/components/forms/FormSection/index.js.map +1 -0
  85. package/dist/components/forms/FormUnsavedChangesModal/index.cjs +24 -0
  86. package/dist/components/forms/FormUnsavedChangesModal/index.cjs.map +1 -0
  87. package/dist/components/forms/FormUnsavedChangesModal/index.d.ts +14 -0
  88. package/dist/components/forms/FormUnsavedChangesModal/index.d.ts.map +1 -0
  89. package/dist/components/forms/FormUnsavedChangesModal/index.js +22 -0
  90. package/dist/components/forms/FormUnsavedChangesModal/index.js.map +1 -0
  91. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.cjs +28 -0
  92. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.cjs.map +1 -0
  93. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.d.ts +12 -0
  94. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.d.ts.map +1 -0
  95. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.js +26 -0
  96. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.js.map +1 -0
  97. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.cjs +68 -0
  98. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.cjs.map +1 -0
  99. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.d.ts +26 -0
  100. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.d.ts.map +1 -0
  101. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.js +66 -0
  102. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.js.map +1 -0
  103. package/dist/components/forms/__internal__/formField/hooks/useFormField.cjs +147 -0
  104. package/dist/components/forms/__internal__/formField/hooks/useFormField.cjs.map +1 -0
  105. package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts +35 -0
  106. package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts.map +1 -0
  107. package/dist/components/forms/__internal__/formField/hooks/useFormField.js +145 -0
  108. package/dist/components/forms/__internal__/formField/hooks/useFormField.js.map +1 -0
  109. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.cjs +12 -0
  110. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.cjs.map +1 -0
  111. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.d.ts +7 -0
  112. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.d.ts.map +1 -0
  113. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.js +10 -0
  114. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.js.map +1 -0
  115. package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.cjs +47 -0
  116. package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.cjs.map +1 -0
  117. package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.d.ts +26 -0
  118. package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.d.ts.map +1 -0
  119. package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.js +43 -0
  120. package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.js.map +1 -0
  121. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.cjs +39 -0
  122. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.cjs.map +1 -0
  123. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.d.ts +21 -0
  124. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.d.ts.map +1 -0
  125. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.js +37 -0
  126. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.js.map +1 -0
  127. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.cjs +40 -0
  128. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.cjs.map +1 -0
  129. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.d.ts +18 -0
  130. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.d.ts.map +1 -0
  131. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.js +37 -0
  132. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.js.map +1 -0
  133. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.cjs +21 -0
  134. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.cjs.map +1 -0
  135. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.d.ts +11 -0
  136. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.d.ts.map +1 -0
  137. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.js +19 -0
  138. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.js.map +1 -0
  139. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.cjs +128 -0
  140. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.cjs.map +1 -0
  141. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.d.ts +72 -0
  142. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.d.ts.map +1 -0
  143. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.js +121 -0
  144. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.js.map +1 -0
  145. package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.cjs +12 -0
  146. package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.cjs.map +1 -0
  147. package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.d.ts +6 -0
  148. package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.d.ts.map +1 -0
  149. package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.js +10 -0
  150. package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.js.map +1 -0
  151. package/dist/components/forms/fields/FormCheckbox/index.cjs +34 -0
  152. package/dist/components/forms/fields/FormCheckbox/index.cjs.map +1 -0
  153. package/dist/components/forms/fields/FormCheckbox/index.d.ts +19 -0
  154. package/dist/components/forms/fields/FormCheckbox/index.d.ts.map +1 -0
  155. package/dist/components/forms/fields/FormCheckbox/index.js +32 -0
  156. package/dist/components/forms/fields/FormCheckbox/index.js.map +1 -0
  157. package/dist/components/forms/fields/FormCheckboxGroup/index.cjs +33 -0
  158. package/dist/components/forms/fields/FormCheckboxGroup/index.cjs.map +1 -0
  159. package/dist/components/forms/fields/FormCheckboxGroup/index.d.ts +19 -0
  160. package/dist/components/forms/fields/FormCheckboxGroup/index.d.ts.map +1 -0
  161. package/dist/components/forms/fields/FormCheckboxGroup/index.js +31 -0
  162. package/dist/components/forms/fields/FormCheckboxGroup/index.js.map +1 -0
  163. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.cjs +26 -0
  164. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.cjs.map +1 -0
  165. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.d.ts +11 -0
  166. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.d.ts.map +1 -0
  167. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.js +24 -0
  168. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.js.map +1 -0
  169. package/dist/components/forms/fields/FormColorPicker/index.cjs +33 -0
  170. package/dist/components/forms/fields/FormColorPicker/index.cjs.map +1 -0
  171. package/dist/components/forms/fields/FormColorPicker/index.d.ts +24 -0
  172. package/dist/components/forms/fields/FormColorPicker/index.d.ts.map +1 -0
  173. package/dist/components/forms/fields/FormColorPicker/index.js +31 -0
  174. package/dist/components/forms/fields/FormColorPicker/index.js.map +1 -0
  175. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.cjs +20 -0
  176. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.cjs.map +1 -0
  177. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.d.ts +17 -0
  178. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.d.ts.map +1 -0
  179. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.js +18 -0
  180. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.js.map +1 -0
  181. package/dist/components/forms/fields/FormDatePicker/index.cjs +35 -0
  182. package/dist/components/forms/fields/FormDatePicker/index.cjs.map +1 -0
  183. package/dist/components/forms/fields/FormDatePicker/index.d.ts +20 -0
  184. package/dist/components/forms/fields/FormDatePicker/index.d.ts.map +1 -0
  185. package/dist/components/forms/fields/FormDatePicker/index.js +33 -0
  186. package/dist/components/forms/fields/FormDatePicker/index.js.map +1 -0
  187. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.cjs +23 -0
  188. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.cjs.map +1 -0
  189. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.d.ts +9 -0
  190. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.d.ts.map +1 -0
  191. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.js +21 -0
  192. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.js.map +1 -0
  193. package/dist/components/forms/fields/FormInput/index.cjs +27 -0
  194. package/dist/components/forms/fields/FormInput/index.cjs.map +1 -0
  195. package/dist/components/forms/fields/FormInput/index.d.ts +19 -0
  196. package/dist/components/forms/fields/FormInput/index.d.ts.map +1 -0
  197. package/dist/components/forms/fields/FormInput/index.js +25 -0
  198. package/dist/components/forms/fields/FormInput/index.js.map +1 -0
  199. package/dist/components/forms/fields/FormMultiSelect/index.cjs +44 -0
  200. package/dist/components/forms/fields/FormMultiSelect/index.cjs.map +1 -0
  201. package/dist/components/forms/fields/FormMultiSelect/index.d.ts +20 -0
  202. package/dist/components/forms/fields/FormMultiSelect/index.d.ts.map +1 -0
  203. package/dist/components/forms/fields/FormMultiSelect/index.js +42 -0
  204. package/dist/components/forms/fields/FormMultiSelect/index.js.map +1 -0
  205. package/dist/components/forms/fields/FormRadioCardGroup/index.cjs +36 -0
  206. package/dist/components/forms/fields/FormRadioCardGroup/index.cjs.map +1 -0
  207. package/dist/components/forms/fields/FormRadioCardGroup/index.d.ts +32 -0
  208. package/dist/components/forms/fields/FormRadioCardGroup/index.d.ts.map +1 -0
  209. package/dist/components/forms/fields/FormRadioCardGroup/index.js +34 -0
  210. package/dist/components/forms/fields/FormRadioCardGroup/index.js.map +1 -0
  211. package/dist/components/forms/fields/FormRadioGroup/index.cjs +31 -0
  212. package/dist/components/forms/fields/FormRadioGroup/index.cjs.map +1 -0
  213. package/dist/components/forms/fields/FormRadioGroup/index.d.ts +20 -0
  214. package/dist/components/forms/fields/FormRadioGroup/index.d.ts.map +1 -0
  215. package/dist/components/forms/fields/FormRadioGroup/index.js +29 -0
  216. package/dist/components/forms/fields/FormRadioGroup/index.js.map +1 -0
  217. package/dist/components/forms/fields/FormSelect/index.cjs +30 -0
  218. package/dist/components/forms/fields/FormSelect/index.cjs.map +1 -0
  219. package/dist/components/forms/fields/FormSelect/index.d.ts +19 -0
  220. package/dist/components/forms/fields/FormSelect/index.d.ts.map +1 -0
  221. package/dist/components/forms/fields/FormSelect/index.js +28 -0
  222. package/dist/components/forms/fields/FormSelect/index.js.map +1 -0
  223. package/dist/components/forms/fields/FormSlider/index.cjs +43 -0
  224. package/dist/components/forms/fields/FormSlider/index.cjs.map +1 -0
  225. package/dist/components/forms/fields/FormSlider/index.d.ts +20 -0
  226. package/dist/components/forms/fields/FormSlider/index.d.ts.map +1 -0
  227. package/dist/components/forms/fields/FormSlider/index.js +41 -0
  228. package/dist/components/forms/fields/FormSlider/index.js.map +1 -0
  229. package/dist/components/forms/fields/FormTextArea/index.cjs +27 -0
  230. package/dist/components/forms/fields/FormTextArea/index.cjs.map +1 -0
  231. package/dist/components/forms/fields/FormTextArea/index.d.ts +19 -0
  232. package/dist/components/forms/fields/FormTextArea/index.d.ts.map +1 -0
  233. package/dist/components/forms/fields/FormTextArea/index.js +25 -0
  234. package/dist/components/forms/fields/FormTextArea/index.js.map +1 -0
  235. package/dist/components/forms/fields/FormToggle/index.cjs +32 -0
  236. package/dist/components/forms/fields/FormToggle/index.cjs.map +1 -0
  237. package/dist/components/forms/fields/FormToggle/index.d.ts +19 -0
  238. package/dist/components/forms/fields/FormToggle/index.d.ts.map +1 -0
  239. package/dist/components/forms/fields/FormToggle/index.js +30 -0
  240. package/dist/components/forms/fields/FormToggle/index.js.map +1 -0
  241. package/dist/components/forms/validation/hooks/useSchemaResolver.cjs +44 -0
  242. package/dist/components/forms/validation/hooks/useSchemaResolver.cjs.map +1 -0
  243. package/dist/components/forms/validation/hooks/useSchemaResolver.d.ts +16 -0
  244. package/dist/components/forms/validation/hooks/useSchemaResolver.d.ts.map +1 -0
  245. package/dist/components/forms/validation/hooks/useSchemaResolver.js +42 -0
  246. package/dist/components/forms/validation/hooks/useSchemaResolver.js.map +1 -0
  247. package/dist/components/forms/validation/index.cjs +413 -0
  248. package/dist/components/forms/validation/index.cjs.map +1 -0
  249. package/dist/components/forms/validation/index.d.ts +278 -0
  250. package/dist/components/forms/validation/index.d.ts.map +1 -0
  251. package/dist/components/forms/validation/index.js +394 -0
  252. package/dist/components/forms/validation/index.js.map +1 -0
  253. package/dist/components/forms/validation/utilities/validation.utils.cjs +72 -0
  254. package/dist/components/forms/validation/utilities/validation.utils.cjs.map +1 -0
  255. package/dist/components/forms/validation/utilities/validation.utils.d.ts +38 -0
  256. package/dist/components/forms/validation/utilities/validation.utils.d.ts.map +1 -0
  257. package/dist/components/forms/validation/utilities/validation.utils.js +67 -0
  258. package/dist/components/forms/validation/utilities/validation.utils.js.map +1 -0
  259. package/dist/components/forms/validation/validation.types.d.ts +8 -0
  260. package/dist/components/forms/validation/validation.types.d.ts.map +1 -0
  261. package/dist/components/organisms/ColorPicker/components/ColorPickerField.cjs +13 -3
  262. package/dist/components/organisms/ColorPicker/components/ColorPickerField.cjs.map +1 -1
  263. package/dist/components/organisms/ColorPicker/components/ColorPickerField.d.ts +1 -1
  264. package/dist/components/organisms/ColorPicker/components/ColorPickerField.d.ts.map +1 -1
  265. package/dist/components/organisms/ColorPicker/components/ColorPickerField.js +13 -3
  266. package/dist/components/organisms/ColorPicker/components/ColorPickerField.js.map +1 -1
  267. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.cjs +2 -2
  268. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.cjs.map +1 -1
  269. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.d.ts +1 -0
  270. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.d.ts.map +1 -1
  271. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.js +2 -2
  272. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.js.map +1 -1
  273. package/dist/components/organisms/ColorPicker/hooks/useCssColorField.cjs +1 -1
  274. package/dist/components/organisms/ColorPicker/hooks/useCssColorField.js +1 -1
  275. package/dist/components/organisms/ColorPicker/index.cjs +1 -1
  276. package/dist/components/organisms/ColorPicker/index.d.ts.map +1 -1
  277. package/dist/components/organisms/ColorPicker/index.js +1 -1
  278. package/dist/components/organisms/ColorPicker/providers/ColorPicker.provider.d.ts +1 -1
  279. package/dist/components/organisms/ColorPicker/providers/ColorPicker.provider.d.ts.map +1 -1
  280. package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.cjs.map +1 -0
  281. package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.d.ts.map +1 -0
  282. package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.js.map +1 -0
  283. package/dist/components/organisms/GradientPicker/components/GradientStopRow.cjs +1 -1
  284. package/dist/components/organisms/GradientPicker/components/GradientStopRow.js +1 -1
  285. package/dist/hooks/useFocusAfterRetry/index.cjs +7 -3
  286. package/dist/hooks/useFocusAfterRetry/index.cjs.map +1 -1
  287. package/dist/hooks/useFocusAfterRetry/index.d.ts +8 -2
  288. package/dist/hooks/useFocusAfterRetry/index.d.ts.map +1 -1
  289. package/dist/hooks/useFocusAfterRetry/index.js +7 -3
  290. package/dist/hooks/useFocusAfterRetry/index.js.map +1 -1
  291. package/dist/localization/en.json.cjs +117 -0
  292. package/dist/localization/en.json.cjs.map +1 -0
  293. package/dist/localization/en.json.js +98 -0
  294. package/dist/localization/en.json.js.map +1 -0
  295. package/dist/native/components/forms/Form/index.d.ts +12 -0
  296. package/dist/native/components/forms/FormFooter/index.d.ts +12 -0
  297. package/dist/native/components/forms/FormSaveErrorAlert/index.d.ts +12 -0
  298. package/dist/native/components/forms/FormSection/index.d.ts +12 -0
  299. package/dist/native/components/forms/FormUnsavedChangesModal/index.d.ts +12 -0
  300. package/dist/native/components/forms/fields/FormCheckbox/index.d.ts +12 -0
  301. package/dist/native/components/forms/fields/FormCheckboxGroup/index.d.ts +12 -0
  302. package/dist/native/components/forms/fields/FormColorPicker/index.d.ts +12 -0
  303. package/dist/native/components/forms/fields/FormDatePicker/index.d.ts +12 -0
  304. package/dist/native/components/forms/fields/FormInput/index.d.ts +12 -0
  305. package/dist/native/components/forms/fields/FormMultiSelect/index.d.ts +12 -0
  306. package/dist/native/components/forms/fields/FormRadioCardGroup/index.d.ts +12 -0
  307. package/dist/native/components/forms/fields/FormRadioGroup/index.d.ts +12 -0
  308. package/dist/native/components/forms/fields/FormSelect/index.d.ts +12 -0
  309. package/dist/native/components/forms/fields/FormSlider/index.d.ts +12 -0
  310. package/dist/native/components/forms/fields/FormTextArea/index.d.ts +12 -0
  311. package/dist/native/components/forms/fields/FormToggle/index.d.ts +12 -0
  312. package/dist/native/components/forms/validation/index.d.ts +12 -0
  313. package/dist/native/utilities/colorUtils/index.d.ts +12 -0
  314. package/dist/providers/UnsavedChangesGuardProvider/index.cjs +1 -1
  315. package/dist/providers/UnsavedChangesGuardProvider/index.js +1 -1
  316. package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.cjs.map +1 -0
  317. package/dist/providers/UnsavedChangesGuardProvider/{unsavedChangesGuard.utils.d.ts → utilities/unsavedChangesGuard.utils.d.ts} +1 -1
  318. package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.d.ts.map +1 -0
  319. package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.js.map +1 -0
  320. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.cjs +74 -0
  321. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.cjs.map +1 -0
  322. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.d.ts +51 -0
  323. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.d.ts.map +1 -0
  324. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.js +68 -0
  325. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.js.map +1 -0
  326. package/dist/utilities/colorUtils/index.cjs +24 -0
  327. package/dist/utilities/colorUtils/index.cjs.map +1 -0
  328. package/dist/utilities/colorUtils/index.d.ts +8 -0
  329. package/dist/utilities/colorUtils/index.d.ts.map +1 -0
  330. package/dist/utilities/colorUtils/index.js +22 -0
  331. package/dist/utilities/colorUtils/index.js.map +1 -0
  332. package/package.json +41 -6
  333. package/dist/components/organisms/ColorPicker/colorPicker.utils.cjs.map +0 -1
  334. package/dist/components/organisms/ColorPicker/colorPicker.utils.d.ts.map +0 -1
  335. package/dist/components/organisms/ColorPicker/colorPicker.utils.js.map +0 -1
  336. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.cjs.map +0 -1
  337. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.d.ts.map +0 -1
  338. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.js.map +0 -1
  339. /package/dist/components/organisms/ColorPicker/{colorPicker.utils.cjs → utilities/colorPicker.utils.cjs} +0 -0
  340. /package/dist/components/organisms/ColorPicker/{colorPicker.utils.d.ts → utilities/colorPicker.utils.d.ts} +0 -0
  341. /package/dist/components/organisms/ColorPicker/{colorPicker.utils.js → utilities/colorPicker.utils.js} +0 -0
  342. /package/dist/providers/UnsavedChangesGuardProvider/{unsavedChangesGuard.utils.cjs → utilities/unsavedChangesGuard.utils.cjs} +0 -0
  343. /package/dist/providers/UnsavedChangesGuardProvider/{unsavedChangesGuard.utils.js → utilities/unsavedChangesGuard.utils.js} +0 -0
@@ -0,0 +1,394 @@
1
+ import { z } from 'zod';
2
+ import { builtInTextTemplate } from '../../../utilities/__internal__/builtInTextUtils/builtInText.utils.js';
3
+ import { noteCrossFieldRule, valuesOf } from './utilities/validation.utils.js';
4
+ export { useSchemaResolver } from './hooks/useSchemaResolver.js';
5
+
6
+ // A decimal amount of zero or more with at most two decimal places, such as 15 or 12.50.
7
+ const AMOUNT = /^\d+(\.\d{1,2})?$/;
8
+ const NUMBER = /^-?\d+(\.\d+)?$/;
9
+ const WHOLE_NUMBER = /^-?\d+$/;
10
+ const DIGITS = /^\d+$/;
11
+ const HEX_COLOUR = /^#[0-9a-f]{6}$/i;
12
+ const HEX_COLOUR_WITH_ALPHA = /^#(?:[0-9a-f]{6}|[0-9a-f]{8})$/i;
13
+ /**
14
+ * Accepts a phone number that is plausible to dial: digits with optional spaces, brackets, dashes and a leading `+`.
15
+ *
16
+ * @param phone The number as typed.
17
+ * @returns `true` when it has 7 to 15 digits and nothing else but those separators.
18
+ */
19
+ const isPlausiblePhone = (phone) => {
20
+ const digits = phone.replace(/\D/g, '');
21
+ return /^\+?[\d\s()-]+$/.test(phone) && digits.length >= 7 && digits.length <= 15;
22
+ };
23
+ /**
24
+ * Reads a rule's limit and the message for breaking it.
25
+ *
26
+ * @param rule The limit, alone or with its message.
27
+ * @param defaultId The library message shown when the rule names none.
28
+ * @returns The limit and the message to show.
29
+ */
30
+ const limitOf = (rule, defaultId) => Array.isArray(rule) ? rule : [rule, builtInTextTemplate(defaultId)];
31
+ /**
32
+ * Reads the message for an empty field.
33
+ *
34
+ * @param required The field's `required` rule.
35
+ * @param defaultId The library message shown when the rule names none.
36
+ * @returns The message to show, or `undefined` for an optional field.
37
+ */
38
+ const requiredMessage = (required, defaultId = 'This_field_is_required') => {
39
+ if (typeof required === 'string')
40
+ return required || undefined;
41
+ return required ? builtInTextTemplate(defaultId) : undefined;
42
+ };
43
+ const POSTCODE = 'Enter_a_postcode_such_as_{example}';
44
+ const ZIP_CODE = { pattern: /^\d{5}(?:-\d{4})?$/, messageId: 'Enter_a_ZIP_code_such_as_{example}' };
45
+ // The shapes the API's address forms accept, not proof a postcode exists: the address service checks that when the order is placed.
46
+ const POSTCODE_RULES = {
47
+ IE: { pattern: /^(?:[AC-FHKNPRTV-Y]\d{2}|D6W)\s?[0-9AC-FHKNPRTV-Y]{4}$/i, messageId: 'Enter_an_Eircode_such_as_D02_X285', example: 'D02 X285' },
48
+ GB: {
49
+ pattern: /^(?:[A-Z][A-HJ-Y]?\d[A-Z\d]?\s?\d[A-Z]{2}|GIR\s?0AA)$/i,
50
+ messageId: 'Enter_a_UK_postcode_such_as_SW1A_1AA',
51
+ example: 'SW1A 1AA',
52
+ },
53
+ US: { ...ZIP_CODE, example: '10001' },
54
+ CA: {
55
+ pattern: /^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
56
+ messageId: 'Enter_a_postal_code_such_as_{example}',
57
+ example: 'K1A 0B1',
58
+ },
59
+ FR: { pattern: /^(?:[Ff]-)?(?:2[AB]|\d{2})\d{3}$/, messageId: POSTCODE, example: '75001' },
60
+ DE: { pattern: /^(?:0[1-46-9]\d{3}|[1-357-9]\d{4}|4[0-24-9]\d{3}|6[013-9]\d{3})$/, messageId: POSTCODE, example: '10115' },
61
+ ES: { pattern: /^(?:0[1-9]|[1-4]\d|5[0-2])\d{3}$/, messageId: POSTCODE, example: '28013' },
62
+ IT: { pattern: /^\d{5}$/, messageId: POSTCODE, example: '00184' },
63
+ PT: { pattern: /^\d{4}(?:-\d{3})?$/, messageId: POSTCODE, example: '1000-205' },
64
+ PR: { ...ZIP_CODE, example: '00901' },
65
+ };
66
+ /**
67
+ * Adds a rule that an empty value passes: an empty value is `required`'s to report, so the field shows one message and
68
+ * an optional field may stay empty.
69
+ *
70
+ * @param schema The string schema to add the rule to.
71
+ * @param isValid Whether a value that is not empty is acceptable.
72
+ * @param message The message for one that is not.
73
+ * @param params The values the message's placeholders may use.
74
+ * @returns The schema with the rule added.
75
+ */
76
+ const unlessEmpty = (schema, isValid, message, params) => schema.refine((value) => value === '' || isValid(value), { message, params });
77
+ /**
78
+ * The rules for a text field, such as `FormInput` or `FormTextArea`. Spaces around the value are dropped before the
79
+ * rules run and from the validated value.
80
+ *
81
+ * @param options The rules to apply; a rule given without a message shows the library's default. None makes any text valid.
82
+ * @returns A zod string schema, which takes further zod rules.
83
+ */
84
+ const text = ({ required, min, max, pattern } = {}) => {
85
+ let schema = z.string().trim();
86
+ const emptyMessage = requiredMessage(required);
87
+ if (emptyMessage)
88
+ schema = schema.min(1, emptyMessage);
89
+ if (min !== undefined) {
90
+ const [limit, message] = limitOf(min, 'Enter_{min}_or_more_characters');
91
+ schema = unlessEmpty(schema, (value) => value.length >= limit, message, { min: limit });
92
+ }
93
+ if (max !== undefined)
94
+ schema = schema.max(...limitOf(max, 'Enter_{max}_characters_or_fewer'));
95
+ if (pattern) {
96
+ const [shape, message] = limitOf(pattern, 'Enter_a_valid_value');
97
+ // A pattern with the `g` or `y` flag starts each test where its last one ended, so it is put back to the start.
98
+ const matches = (value) => {
99
+ shape.lastIndex = 0;
100
+ return shape.test(value);
101
+ };
102
+ schema = unlessEmpty(schema, matches, message);
103
+ }
104
+ return schema;
105
+ };
106
+ /**
107
+ * The rules for an email address.
108
+ *
109
+ * @param messages `invalid` for a value that is not an email address, and `required` to refuse an empty one; each has a default, and without `required` the field is optional.
110
+ * @returns A zod string schema whose validated value is the trimmed address.
111
+ */
112
+ const email = ({ required, invalid = builtInTextTemplate('Enter_a_valid_email_address') } = {}) => unlessEmpty(text({ required }), (value) => z.email().safeParse(value).success, invalid);
113
+ /**
114
+ * The rules for a web address.
115
+ *
116
+ * @param messages `invalid` for a value that is not an `http` or `https` address, and `required` to refuse an empty one; each has a default, and without `required` the field is optional.
117
+ * @returns A zod string schema whose validated value is the trimmed address.
118
+ */
119
+ const url = ({ required, invalid = builtInTextTemplate('Enter_a_valid_web_address') } = {}) => unlessEmpty(text({ required }), (value) => z.httpUrl().safeParse(value).success, invalid);
120
+ /**
121
+ * The rules for a phone number: 7 to 15 digits, with optional spaces, brackets, dashes and a leading `+`. It checks the
122
+ * number is plausible to dial, not that it exists.
123
+ *
124
+ * @param messages `invalid` for a value that is not such a number, and `required` to refuse an empty one; each has a default, and without `required` the field is optional.
125
+ * @returns A zod string schema whose validated value is the trimmed number, as typed.
126
+ */
127
+ const phone = ({ required, invalid = builtInTextTemplate('Enter_a_valid_phone_number') } = {}) => unlessEmpty(text({ required }), isPlausiblePhone, invalid);
128
+ /**
129
+ * The rules for a postcode of one country, such as an Eircode in Ireland or a ZIP code in the United States. It checks
130
+ * the shape, not that the address exists. For a country the user picks in the same form, use `postcodeError` in a cross-field rule.
131
+ *
132
+ * @param options The `country` whose shape is required, `invalid` for a value that does not have it, which may show a fitting postcode as `{example}`, and `required` to refuse an empty one; each message has a default, and without `required` the field is optional.
133
+ * @returns A zod string schema whose validated value is the trimmed postcode.
134
+ */
135
+ const postcode = ({ country, required, invalid = builtInTextTemplate(POSTCODE_RULES[country].messageId) }) => unlessEmpty(text({ required }), (value) => POSTCODE_RULES[country].pattern.test(value), invalid, { example: POSTCODE_RULES[country].example });
136
+ /**
137
+ * Checks a postcode against the shape its country uses, for a `crossFieldRules` `check` where the country is another
138
+ * field of the form.
139
+ *
140
+ * @param country The address's country, which decides the shape.
141
+ * @param value The postcode as typed; surrounding spaces and letter case do not matter.
142
+ * @returns The library's default message for the country with the example it shows, or `undefined` when the postcode
143
+ * fits it or is empty, which the field's own `required` rule reports.
144
+ */
145
+ const postcodeError = (country, value) => {
146
+ const trimmed = value.trim();
147
+ if (!trimmed)
148
+ return undefined;
149
+ const { pattern, messageId, example } = POSTCODE_RULES[country];
150
+ return pattern.test(trimmed) ? undefined : { key: builtInTextTemplate(messageId), values: { example } };
151
+ };
152
+ /**
153
+ * The rules shared by every number typed into a text field: its format first, then the range it must sit in.
154
+ *
155
+ * @param format The shape a value must have to count as a number here.
156
+ * @param formatMessage The message for a value that does not have it.
157
+ * @param options Whether the field is required, and the smallest and largest number allowed.
158
+ * @returns A zod string schema; the validated value stays the text typed.
159
+ */
160
+ const numeric = (format, formatMessage, { required, min, max }) => {
161
+ let schema = text({ required, pattern: [format, formatMessage] });
162
+ // A value that is not a number is the format's to report, so the range passes it.
163
+ const inRange = (isWithin) => (value) => !format.test(value) || isWithin(Number(value));
164
+ if (min !== undefined) {
165
+ const [limit, message] = limitOf(min, 'Enter_{min}_or_more');
166
+ schema = unlessEmpty(schema, inRange((value) => value >= limit), message, { min: limit });
167
+ }
168
+ if (max !== undefined) {
169
+ const [limit, message] = limitOf(max, 'Enter_{max}_or_less');
170
+ schema = unlessEmpty(schema, inRange((value) => value <= limit), message, { max: limit });
171
+ }
172
+ return schema;
173
+ };
174
+ /**
175
+ * The rules for a money amount typed into a text field: zero or more, with at most two decimal places.
176
+ *
177
+ * @param options `invalid` for a value that is not such an amount, the optional `min` and `max` it must sit between, and
178
+ * `required` to refuse an empty value; each message has a default, and without `required` the field is optional.
179
+ * @returns A zod string schema; the validated value stays the text typed, such as `'12.50'`.
180
+ */
181
+ const amount = ({ invalid = builtInTextTemplate('Enter_a_valid_amount'), ...options } = {}) => numeric(AMOUNT, invalid, options);
182
+ /**
183
+ * The rules for a number typed into a text field, such as a quantity or a percentage.
184
+ *
185
+ * @param options `invalid` for a value that is not a number, the optional `min` and `max` it must sit between, `isWhole` to
186
+ * refuse a decimal, and `required` to refuse an empty value; each message has a default, and without `required` the field is optional.
187
+ * @returns A zod string schema; the validated value stays the text typed, so convert it with `Number` when saving.
188
+ */
189
+ const number = ({ invalid, isWhole = false, ...options } = {}) => numeric(isWhole ? WHOLE_NUMBER : NUMBER, invalid ?? builtInTextTemplate(isWhole ? 'Enter_a_whole_number' : 'Enter_a_number'), options);
190
+ /**
191
+ * The rules for a code made only of digits, such as a PIN, a verification code or an account number. Unlike `number`
192
+ * it keeps leading zeros, takes no sign or decimal point, and limits how many digits there are.
193
+ *
194
+ * @param options `invalid` for a value with anything but digits, the `length` it must have or the `min` and `max` digits it
195
+ * may have, and `required` to refuse an empty value; each message has a default, and without `required` the field is optional.
196
+ * @returns A zod string schema; the validated value is the digits as typed.
197
+ */
198
+ const digits = ({ required, invalid = builtInTextTemplate('Enter_digits_only'), length, min, max } = {}) => {
199
+ let schema = text({ required, pattern: [DIGITS, invalid] });
200
+ // A value with something other than digits is `invalid`'s to report, so the counts pass it.
201
+ const counted = (isAllowed) => (value) => !DIGITS.test(value) || isAllowed(value.length);
202
+ const rules = [
203
+ { rule: length, id: 'Enter_{length}_digits', name: 'length', isAllowed: (count, limit) => count === limit },
204
+ { rule: min, id: 'Enter_{min}_or_more_characters', name: 'min', isAllowed: (count, limit) => count >= limit },
205
+ { rule: max, id: 'Enter_{max}_characters_or_fewer', name: 'max', isAllowed: (count, limit) => count <= limit },
206
+ ];
207
+ for (const { rule, id, name, isAllowed } of rules) {
208
+ if (rule === undefined)
209
+ continue;
210
+ const [limit, message] = limitOf(rule, id);
211
+ schema = unlessEmpty(schema, counted((count) => isAllowed(count, limit)), message, { [name]: limit });
212
+ }
213
+ return schema;
214
+ };
215
+ /**
216
+ * The rule for a box the user must tick or a switch they must turn on, such as accepting terms with `FormCheckbox`.
217
+ *
218
+ * @param required The message while it is off; the library's default without it.
219
+ * @returns A zod boolean schema, which only `true` passes.
220
+ */
221
+ const checked = (required = builtInTextTemplate('Select_this_box_to_continue')) => z.boolean().refine((value) => value, required);
222
+ const requiredColour = (isColour, required, invalid) =>
223
+ // The message is given to the type check as well: `null` is not a string, and zod's own wording for that is not for users.
224
+ z
225
+ .string(required)
226
+ .min(1, required)
227
+ .refine((value) => !value || isColour(value), invalid);
228
+ const optionalColour = (isColour, invalid) => z
229
+ .string()
230
+ .nullish()
231
+ .refine((value) => !value || isColour(value), invalid);
232
+ /**
233
+ * The rules for a colour held as a hex string, as `FormColorPicker` writes it. A field with no colour is one holding
234
+ * `null`, `undefined` or `''`: the picker writes back whichever of them the form itself uses for an empty field.
235
+ *
236
+ * @param options `required` to refuse a field with no colour, the message for a value that is not a hex colour, and whether a see-through colour passes.
237
+ * @returns A zod schema of a string, which also takes `null` and `undefined` unless the colour is required.
238
+ */
239
+ const hexColour = (({ required, invalid = builtInTextTemplate('Enter_a_valid_colour'), isAlphaAllowed = false, } = {}) => {
240
+ const pattern = isAlphaAllowed ? HEX_COLOUR_WITH_ALPHA : HEX_COLOUR;
241
+ const isColour = (value) => pattern.test(value);
242
+ const emptyMessage = requiredMessage(required);
243
+ return emptyMessage ? requiredColour(isColour, emptyMessage, invalid) : optionalColour(isColour, invalid);
244
+ // The schema follows `required`, which only the two call shapes above can say.
245
+ });
246
+ /**
247
+ * Today's date in a time zone, as the ISO date string a `date` rule compares with. Use it for a limit that follows the
248
+ * calendar of the record being edited, such as a property's, and not the calendar of whoever is editing it.
249
+ *
250
+ * @param timeZone The IANA time zone, such as `Europe/Dublin`; without one, or with an empty one, the browser's. A name
251
+ * `Intl` does not know throws a `RangeError`, so validate a zone the user picks before it reaches here.
252
+ * @param now The moment to read the date at; the current time unless a test fixes it.
253
+ * @returns That date as `YYYY-MM-DD`.
254
+ */
255
+ const todayIn = (timeZone, now = new Date()) => {
256
+ // Read part by part: no locale's own date format is promised to stay `YYYY-MM-DD`.
257
+ const parts = new Intl.DateTimeFormat('en-US', {
258
+ timeZone: timeZone || undefined,
259
+ calendar: 'gregory',
260
+ numberingSystem: 'latn',
261
+ year: 'numeric',
262
+ month: '2-digit',
263
+ day: '2-digit',
264
+ }).formatToParts(now);
265
+ const part = (type) => parts.find((entry) => entry.type === type)?.value ?? '';
266
+ return `${part('year')}-${part('month')}-${part('day')}`;
267
+ };
268
+ /**
269
+ * The rules for a date held as an ISO date string (`YYYY-MM-DD`) or `null`, as `FormDatePicker` writes it.
270
+ *
271
+ * @param options `required` to refuse a field with no date, and the optional `min` and `max` it must sit between. A limit
272
+ * may be a function, read at each validation, for one that moves such as today: `min: () => todayIn()`. A default message
273
+ * shows the limit as a date, such as `13 Nov 2026`.
274
+ * @returns A zod schema of a string or `null`.
275
+ */
276
+ const date = ({ required, min, max } = {}) => {
277
+ const read = (limit) => (typeof limit === 'function' ? limit() : limit);
278
+ let schema = z.string().nullable();
279
+ const emptyMessage = requiredMessage(required);
280
+ if (emptyMessage)
281
+ schema = schema.refine((value) => Boolean(value), emptyMessage);
282
+ const earliest = min && limitOf(min, 'Choose_a_date_on_or_after_{min}');
283
+ const latest = max && limitOf(max, 'Choose_a_date_on_or_before_{max}');
284
+ return schema.superRefine((value, context) => {
285
+ if (!value)
286
+ return;
287
+ // ISO dates of the same length sort as their text. A limit is read here, so one that moves is current.
288
+ // Only the date is compared, of the value and of a limit alike: one given with a time would sort after that same date.
289
+ const from = earliest && read(earliest[0])?.slice(0, 10);
290
+ const to = latest && read(latest[0])?.slice(0, 10);
291
+ const day = value.slice(0, 10);
292
+ if (earliest && from && day < from)
293
+ context.addIssue({ code: 'custom', message: earliest[1], params: { min: from } });
294
+ if (latest && to && day > to)
295
+ context.addIssue({ code: 'custom', message: latest[1], params: { max: to } });
296
+ });
297
+ };
298
+ /**
299
+ * The rules for a field that holds one of a fixed set of ids, such as `FormSelect` or `FormRadioGroup`.
300
+ *
301
+ * @param options Every id the field may hold.
302
+ * @param required The message for a field with no choice, or a value outside `options`; the library's default without it.
303
+ * @returns A zod enum schema, so the validated value is typed as one of `options`.
304
+ */
305
+ const oneOf = (options, required = builtInTextTemplate('Choose_an_option')) => z.enum(options, required);
306
+ /**
307
+ * Adds the size rules of a list that needs at least one entry.
308
+ *
309
+ * @param list The array schema to add the rules to.
310
+ * @param options The message for an empty list, and the most entries allowed.
311
+ * @returns The schema with the rules added.
312
+ */
313
+ const sized = (list, { required = builtInTextTemplate('Choose_at_least_one_option'), max }) => {
314
+ const atLeastOneEntry = list.min(1, required);
315
+ return max === undefined ? atLeastOneEntry : atLeastOneEntry.max(...limitOf(max, 'Choose_{max}_or_fewer'));
316
+ };
317
+ /**
318
+ * The rules for a field that holds a list of any strings and needs at least one entry, such as a `FormMultiSelect`
319
+ * whose items are loaded.
320
+ *
321
+ * @param options `required` for an empty list and the optional `max` entries it may hold; each message has a default.
322
+ * @returns A zod array schema.
323
+ */
324
+ const atLeastOne = (options = {}) => sized(z.array(z.string()), options);
325
+ /**
326
+ * The rules for a field that holds a list from a fixed set of ids and needs at least one entry, such as
327
+ * `FormCheckboxGroup`.
328
+ *
329
+ * @param ids Every id the list may hold.
330
+ * @param options `required` for an empty list and the optional `max` entries it may hold; each message has a default.
331
+ * @returns A zod array schema, so the validated value is typed as a list of `ids`.
332
+ */
333
+ const atLeastOneOf = (ids, options = {}) => sized(z.array(z.enum(ids)), options);
334
+ // Marks an issue a cross-field rule raised. A later rule that reads the field it sits on still runs: that field did not fail its own rules.
335
+ const CROSS_FIELD = 'crossField';
336
+ /**
337
+ * Turns a conditional rule into the cross-field rule that runs it: the field's extra rules are checked only while the
338
+ * condition holds, and the first one broken gives the message.
339
+ *
340
+ * @param rule The rule as written in the schema.
341
+ * @returns A cross-field rule, unchanged when it already was one.
342
+ */
343
+ const asCrossFieldRule = (rule) => {
344
+ if (rule.check !== undefined)
345
+ return rule;
346
+ const { when, reportsOn, reads = [], rules } = rule;
347
+ const applies = (values) => (typeof when === 'function' ? when(values) : values[when] === true);
348
+ return {
349
+ reads: [...new Set([...(typeof when === 'function' ? [] : [when]), reportsOn, ...reads])],
350
+ reportsOn,
351
+ check: (values) => {
352
+ if (!applies(values))
353
+ return undefined;
354
+ const result = (rules instanceof z.ZodType ? rules : rules(values)).safeParse(values[reportsOn]);
355
+ if (result.success)
356
+ return undefined;
357
+ const [issue] = result.error.issues;
358
+ return { key: issue.message, values: valuesOf(issue) };
359
+ },
360
+ };
361
+ };
362
+ /**
363
+ * Adds the rules that read more than one field, such as a postcode whose shape depends on the country, or a date that
364
+ * is needed only while a toggle is on. Each rule runs as soon as the fields it reads are valid: left to itself zod
365
+ * skips it while any field in the form fails, so its error would only show on a second save. In a form validated
366
+ * through `useSchemaResolver`, a `Form*` field a rule reads re-validates the field the rule reports on as it changes.
367
+ * That holds for a schema refined further, but not for one wrapped afterwards, as `.transform()` and `.optional()` do.
368
+ *
369
+ * @param schema The object schema holding each field's own rules.
370
+ * @param rules The rules to add, in the order they should run: a `check` of your own, or `when` and the `rules` a field
371
+ * must also pass while it holds.
372
+ * @returns The same schema with the rules applied; its `shape` and value type are unchanged.
373
+ */
374
+ const crossFieldRules = (schema, ...rules) => rules.map(asCrossFieldRule).reduce((refining, { reads, reportsOn, check }) => {
375
+ const readNames = reads;
376
+ const refined = refining.superRefine((values, context) => {
377
+ const result = check(values);
378
+ if (!result)
379
+ return;
380
+ const { key, values: params } = typeof result === 'string' ? { key: result, values: undefined } : result;
381
+ context.addIssue({ code: 'custom', message: key, path: [reportsOn], params, [CROSS_FIELD]: true });
382
+ },
383
+ // Read from the issues the fields have raised, never by parsing the values again: they are already the fields'
384
+ // output, which a field that transforms its value would reject, and a field with an async rule cannot be parsed in step.
385
+ // An issue with no path is the object's own, such as a nested group that is missing: there are no fields to read.
386
+ {
387
+ when: ({ issues }) => !issues.some((issue) => !(CROSS_FIELD in issue) && (!issue.path?.length || readNames.includes(issue.path[0]))),
388
+ });
389
+ noteCrossFieldRule(refined, reads, reportsOn);
390
+ return refined;
391
+ }, schema);
392
+
393
+ export { amount, atLeastOne, atLeastOneOf, checked, crossFieldRules, date, digits, email, hexColour, number, oneOf, phone, postcode, postcodeError, text, todayIn, url };
394
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/components/forms/validation/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAqFA;AACA,MAAM,MAAM,GAAG,mBAAmB;AAClC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AAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM;QACxG,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,WAAW,GAAG,IAAI,EAAE,CAAC;IACpG,CAAC;;;;AAID,IAAA;QACE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,KACf,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,EAAE,WAAW,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAgB,CAAC,CAAC,CAAC;AAChI,KAAA,CACF;AACD,IAAA,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC;AAC7C,IAAA,OAAO,OAAO;AAChB,CAAC,EAAE,MAAM;;"}
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ var fieldDependents_utils = require('../../__internal__/formField/utilities/fieldDependents.utils.cjs');
4
+ var builtInText_utils = require('../../../../utilities/__internal__/builtInTextUtils/builtInText.utils.cjs');
5
+
6
+ // Kept by the check zod makes for a rule, never by the schema: zod copies a schema on each call, such as `.refine()`, and carries its checks over.
7
+ const rulesByCheck = new WeakMap();
8
+ /**
9
+ * Notes which fields a cross-field rule ties together, for the form's fields to re-validate one as another changes.
10
+ *
11
+ * @param refined The schema as the rule's refinement returned it, whose last check is the rule's.
12
+ * @param reads The fields the rule reads.
13
+ * @param reportsOn The field the rule's error is shown on.
14
+ */
15
+ const noteCrossFieldRule = (refined, reads, reportsOn) => {
16
+ // `_zod` is read with `?.` here and below: a schema that keeps its checks elsewhere then names nothing, where it would throw as the form mounts.
17
+ const checks = refined._zod?.def.checks ?? [];
18
+ const check = checks[checks.length - 1];
19
+ if (check)
20
+ rulesByCheck.set(check, { reads, reportsOn });
21
+ };
22
+ /**
23
+ * Collects, for each field a schema's cross-field rules read, the fields those rules report on.
24
+ *
25
+ * @param schema The form's schema. One that wraps the schema the rules were added to, as `.transform()` and
26
+ * `.optional()` give, carries none of its checks, and so names nothing.
27
+ * @returns The dependents of each field; empty for a schema with no such rule.
28
+ */
29
+ const crossFieldDependentsOf = (schema) => (schema._zod?.def.checks ?? []).reduce((dependents, check) => {
30
+ const rule = rulesByCheck.get(check);
31
+ return rule ? fieldDependents_utils.withRule(dependents, rule.reads, rule.reportsOn) : dependents;
32
+ }, new Map());
33
+ /**
34
+ * Collects the values a failed rule offers its message: the limit of a length or size rule as `min` or `max`, and
35
+ * whatever the rule passed as `params`.
36
+ *
37
+ * @param issue The zod issue for the failed rule.
38
+ * @returns The values for the message's placeholders; empty when the rule has none.
39
+ */
40
+ const valuesOf = (issue) => {
41
+ const { minimum, maximum, params } = issue;
42
+ return { ...(typeof minimum === 'number' && { min: minimum }), ...(typeof maximum === 'number' && { max: maximum }), ...params };
43
+ };
44
+ /**
45
+ * Builds the function that turns a rule's message into the text a field shows. One of the library's default messages
46
+ * is shown from the library's own text, so an app translates only the messages it wrote. A key the app has no text
47
+ * for is shown as the key, which a tester can read and report, where an empty message would hide that the field is
48
+ * invalid.
49
+ *
50
+ * @param translate The app's translation function, which may return nothing, or throw, for a key it does not know; without one the message is the text.
51
+ * @returns A function from a message and its values to the text to show.
52
+ */
53
+ const messageText = (translate) => (message, values) => {
54
+ const builtInId = builtInText_utils.builtInTextIdOf(message);
55
+ if (builtInId)
56
+ return builtInText_utils.builtInText(builtInId, values);
57
+ if (!translate)
58
+ return builtInText_utils.fillPlaceholders(message, values);
59
+ try {
60
+ const text = translate(message, values);
61
+ return typeof text === 'string' && text.trim() ? text : message;
62
+ }
63
+ catch {
64
+ return message;
65
+ }
66
+ };
67
+
68
+ exports.crossFieldDependentsOf = crossFieldDependentsOf;
69
+ exports.messageText = messageText;
70
+ exports.noteCrossFieldRule = noteCrossFieldRule;
71
+ exports.valuesOf = valuesOf;
72
+ //# sourceMappingURL=validation.utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.utils.cjs","sources":["../../../../../src/components/forms/validation/utilities/validation.utils.ts"],"sourcesContent":[null],"names":["withRule","builtInTextIdOf","builtInText","fillPlaceholders"],"mappings":";;;;;AAMA;AACA,MAAM,YAAY,GAAG,IAAI,OAAO,EAA2D;AAE3F;;;;;;AAMG;AACI,MAAM,kBAAkB,GAAG,CAAC,OAAkB,EAAE,KAAwB,EAAE,SAAiB,KAAU;;IAE1G,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AACvC,IAAA,IAAI,KAAK;QAAE,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAC1D;AAEA;;;;;;AAMG;AACI,MAAM,sBAAsB,GAAG,CAAC,MAAiB,KACtD,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE,EAAE,MAAM,CAAkB,CAAC,UAAU,EAAE,KAAK,KAAI;IAC5E,MAAM,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC;IACpC,OAAO,IAAI,GAAGA,8BAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,UAAU;AAC7E,CAAC,EAAE,IAAI,GAAG,EAAE;AAEd;;;;;;AAMG;AACI,MAAM,QAAQ,GAAG,CAAC,KAAa,KAAmB;IACvD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,KAAyE;AAC9G,IAAA,OAAO,EAAE,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE;AAClI;AAEA;;;;;;;;AAQG;AACI,MAAM,WAAW,GACtB,CAAC,SAAgC,KACjC,CAAC,OAAe,EAAE,MAAqB,KAAY;AACjD,IAAA,MAAM,SAAS,GAAGC,iCAAe,CAAC,OAAO,CAAC;AAC1C,IAAA,IAAI,SAAS;AAAE,QAAA,OAAOC,6BAAW,CAAC,SAAS,EAAE,MAAM,CAAC;AACpD,IAAA,IAAI,CAAC,SAAS;AAAE,QAAA,OAAOC,kCAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;AACxD,IAAA,IAAI;QACF,MAAM,IAAI,GAAY,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;AAChD,QAAA,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,GAAG,OAAO;IACjE;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,OAAO;IAChB;AACF;;;;;"}
@@ -0,0 +1,38 @@
1
+ import type { z } from 'zod';
2
+ import type { FieldDependents } from '../../__internal__/formField/utilities/fieldDependents.utils';
3
+ import type { MessageValues, Translate } from '../validation.types';
4
+ /**
5
+ * Notes which fields a cross-field rule ties together, for the form's fields to re-validate one as another changes.
6
+ *
7
+ * @param refined The schema as the rule's refinement returned it, whose last check is the rule's.
8
+ * @param reads The fields the rule reads.
9
+ * @param reportsOn The field the rule's error is shown on.
10
+ */
11
+ export declare const noteCrossFieldRule: (refined: z.ZodType, reads: readonly string[], reportsOn: string) => void;
12
+ /**
13
+ * Collects, for each field a schema's cross-field rules read, the fields those rules report on.
14
+ *
15
+ * @param schema The form's schema. One that wraps the schema the rules were added to, as `.transform()` and
16
+ * `.optional()` give, carries none of its checks, and so names nothing.
17
+ * @returns The dependents of each field; empty for a schema with no such rule.
18
+ */
19
+ export declare const crossFieldDependentsOf: (schema: z.ZodType) => FieldDependents;
20
+ /**
21
+ * Collects the values a failed rule offers its message: the limit of a length or size rule as `min` or `max`, and
22
+ * whatever the rule passed as `params`.
23
+ *
24
+ * @param issue The zod issue for the failed rule.
25
+ * @returns The values for the message's placeholders; empty when the rule has none.
26
+ */
27
+ export declare const valuesOf: (issue: object) => MessageValues;
28
+ /**
29
+ * Builds the function that turns a rule's message into the text a field shows. One of the library's default messages
30
+ * is shown from the library's own text, so an app translates only the messages it wrote. A key the app has no text
31
+ * for is shown as the key, which a tester can read and report, where an empty message would hide that the field is
32
+ * invalid.
33
+ *
34
+ * @param translate The app's translation function, which may return nothing, or throw, for a key it does not know; without one the message is the text.
35
+ * @returns A function from a message and its values to the text to show.
36
+ */
37
+ export declare const messageText: (translate: Translate | undefined) => (message: string, values: MessageValues) => string;
38
+ //# sourceMappingURL=validation.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.utils.d.ts","sourceRoot":"","sources":["../../../../../src/components/forms/validation/utilities/validation.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8DAA8D,CAAC;AACpG,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAKpE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,CAAC,CAAC,OAAO,EAAE,OAAO,SAAS,MAAM,EAAE,EAAE,WAAW,MAAM,KAAG,IAKpG,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,eAI5C,CAAC;AAEhB;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,KAAG,aAGxC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,GACrB,WAAW,SAAS,GAAG,SAAS,MAChC,SAAS,MAAM,EAAE,QAAQ,aAAa,KAAG,MAUzC,CAAC"}
@@ -0,0 +1,67 @@
1
+ import { withRule } from '../../__internal__/formField/utilities/fieldDependents.utils.js';
2
+ import { builtInTextIdOf, builtInText, fillPlaceholders } from '../../../../utilities/__internal__/builtInTextUtils/builtInText.utils.js';
3
+
4
+ // Kept by the check zod makes for a rule, never by the schema: zod copies a schema on each call, such as `.refine()`, and carries its checks over.
5
+ const rulesByCheck = new WeakMap();
6
+ /**
7
+ * Notes which fields a cross-field rule ties together, for the form's fields to re-validate one as another changes.
8
+ *
9
+ * @param refined The schema as the rule's refinement returned it, whose last check is the rule's.
10
+ * @param reads The fields the rule reads.
11
+ * @param reportsOn The field the rule's error is shown on.
12
+ */
13
+ const noteCrossFieldRule = (refined, reads, reportsOn) => {
14
+ // `_zod` is read with `?.` here and below: a schema that keeps its checks elsewhere then names nothing, where it would throw as the form mounts.
15
+ const checks = refined._zod?.def.checks ?? [];
16
+ const check = checks[checks.length - 1];
17
+ if (check)
18
+ rulesByCheck.set(check, { reads, reportsOn });
19
+ };
20
+ /**
21
+ * Collects, for each field a schema's cross-field rules read, the fields those rules report on.
22
+ *
23
+ * @param schema The form's schema. One that wraps the schema the rules were added to, as `.transform()` and
24
+ * `.optional()` give, carries none of its checks, and so names nothing.
25
+ * @returns The dependents of each field; empty for a schema with no such rule.
26
+ */
27
+ const crossFieldDependentsOf = (schema) => (schema._zod?.def.checks ?? []).reduce((dependents, check) => {
28
+ const rule = rulesByCheck.get(check);
29
+ return rule ? withRule(dependents, rule.reads, rule.reportsOn) : dependents;
30
+ }, new Map());
31
+ /**
32
+ * Collects the values a failed rule offers its message: the limit of a length or size rule as `min` or `max`, and
33
+ * whatever the rule passed as `params`.
34
+ *
35
+ * @param issue The zod issue for the failed rule.
36
+ * @returns The values for the message's placeholders; empty when the rule has none.
37
+ */
38
+ const valuesOf = (issue) => {
39
+ const { minimum, maximum, params } = issue;
40
+ return { ...(typeof minimum === 'number' && { min: minimum }), ...(typeof maximum === 'number' && { max: maximum }), ...params };
41
+ };
42
+ /**
43
+ * Builds the function that turns a rule's message into the text a field shows. One of the library's default messages
44
+ * is shown from the library's own text, so an app translates only the messages it wrote. A key the app has no text
45
+ * for is shown as the key, which a tester can read and report, where an empty message would hide that the field is
46
+ * invalid.
47
+ *
48
+ * @param translate The app's translation function, which may return nothing, or throw, for a key it does not know; without one the message is the text.
49
+ * @returns A function from a message and its values to the text to show.
50
+ */
51
+ const messageText = (translate) => (message, values) => {
52
+ const builtInId = builtInTextIdOf(message);
53
+ if (builtInId)
54
+ return builtInText(builtInId, values);
55
+ if (!translate)
56
+ return fillPlaceholders(message, values);
57
+ try {
58
+ const text = translate(message, values);
59
+ return typeof text === 'string' && text.trim() ? text : message;
60
+ }
61
+ catch {
62
+ return message;
63
+ }
64
+ };
65
+
66
+ export { crossFieldDependentsOf, messageText, noteCrossFieldRule, valuesOf };
67
+ //# sourceMappingURL=validation.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.utils.js","sources":["../../../../../src/components/forms/validation/utilities/validation.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAMA;AACA,MAAM,YAAY,GAAG,IAAI,OAAO,EAA2D;AAE3F;;;;;;AAMG;AACI,MAAM,kBAAkB,GAAG,CAAC,OAAkB,EAAE,KAAwB,EAAE,SAAiB,KAAU;;IAE1G,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AACvC,IAAA,IAAI,KAAK;QAAE,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAC1D;AAEA;;;;;;AAMG;AACI,MAAM,sBAAsB,GAAG,CAAC,MAAiB,KACtD,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE,EAAE,MAAM,CAAkB,CAAC,UAAU,EAAE,KAAK,KAAI;IAC5E,MAAM,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC;IACpC,OAAO,IAAI,GAAG,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,UAAU;AAC7E,CAAC,EAAE,IAAI,GAAG,EAAE;AAEd;;;;;;AAMG;AACI,MAAM,QAAQ,GAAG,CAAC,KAAa,KAAmB;IACvD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,KAAyE;AAC9G,IAAA,OAAO,EAAE,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE;AAClI;AAEA;;;;;;;;AAQG;AACI,MAAM,WAAW,GACtB,CAAC,SAAgC,KACjC,CAAC,OAAe,EAAE,MAAqB,KAAY;AACjD,IAAA,MAAM,SAAS,GAAG,eAAe,CAAC,OAAO,CAAC;AAC1C,IAAA,IAAI,SAAS;AAAE,QAAA,OAAO,WAAW,CAAC,SAAS,EAAE,MAAM,CAAC;AACpD,IAAA,IAAI,CAAC,SAAS;AAAE,QAAA,OAAO,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;AACxD,IAAA,IAAI;QACF,MAAM,IAAI,GAAY,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;AAChD,QAAA,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,GAAG,OAAO;IACjE;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,OAAO;IAChB;AACF;;"}
@@ -0,0 +1,8 @@
1
+ /** The values a message's placeholders are filled with, such as `{ min: 2 }` for "Enter at least {min} characters". */
2
+ export type MessageValues = Record<string, string | number>;
3
+ /**
4
+ * An app's translation function: given a message, which may be a translation key, and the values for its
5
+ * placeholders, it returns the text to show.
6
+ */
7
+ export type Translate = (key: string, values?: MessageValues) => string;
8
+ //# sourceMappingURL=validation.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.types.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/validation/validation.types.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,KAAK,MAAM,CAAC"}