@flipdish/ui-library 0.51.0 → 0.52.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 (298) 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/useSubmitInTurn/useSubmitInTurn.cjs +28 -0
  20. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.cjs.map +1 -0
  21. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.d.ts +10 -0
  22. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.d.ts.map +1 -0
  23. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.js +26 -0
  24. package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.js.map +1 -0
  25. package/dist/components/forms/Form/index.cjs +43 -0
  26. package/dist/components/forms/Form/index.cjs.map +1 -0
  27. package/dist/components/forms/Form/index.d.ts +30 -0
  28. package/dist/components/forms/Form/index.d.ts.map +1 -0
  29. package/dist/components/forms/Form/index.js +40 -0
  30. package/dist/components/forms/Form/index.js.map +1 -0
  31. package/dist/components/forms/Form/utilities/formSubmit.utils.cjs +23 -0
  32. package/dist/components/forms/Form/utilities/formSubmit.utils.cjs.map +1 -0
  33. package/dist/components/forms/Form/utilities/formSubmit.utils.d.ts +14 -0
  34. package/dist/components/forms/Form/utilities/formSubmit.utils.d.ts.map +1 -0
  35. package/dist/components/forms/Form/utilities/formSubmit.utils.js +21 -0
  36. package/dist/components/forms/Form/utilities/formSubmit.utils.js.map +1 -0
  37. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.cjs +39 -0
  38. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.cjs.map +1 -0
  39. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.d.ts +17 -0
  40. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.d.ts.map +1 -0
  41. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.js +37 -0
  42. package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.js.map +1 -0
  43. package/dist/components/forms/FormFooter/hooks/useHasFieldError.cjs +26 -0
  44. package/dist/components/forms/FormFooter/hooks/useHasFieldError.cjs.map +1 -0
  45. package/dist/components/forms/FormFooter/hooks/useHasFieldError.d.ts +9 -0
  46. package/dist/components/forms/FormFooter/hooks/useHasFieldError.d.ts.map +1 -0
  47. package/dist/components/forms/FormFooter/hooks/useHasFieldError.js +24 -0
  48. package/dist/components/forms/FormFooter/hooks/useHasFieldError.js.map +1 -0
  49. package/dist/components/forms/FormFooter/index.cjs +41 -0
  50. package/dist/components/forms/FormFooter/index.cjs.map +1 -0
  51. package/dist/components/forms/FormFooter/index.d.ts +52 -0
  52. package/dist/components/forms/FormFooter/index.d.ts.map +1 -0
  53. package/dist/components/forms/FormFooter/index.js +39 -0
  54. package/dist/components/forms/FormFooter/index.js.map +1 -0
  55. package/dist/components/forms/FormFooter/utilities/formFooter.utils.cjs +21 -0
  56. package/dist/components/forms/FormFooter/utilities/formFooter.utils.cjs.map +1 -0
  57. package/dist/components/forms/FormFooter/utilities/formFooter.utils.d.ts +12 -0
  58. package/dist/components/forms/FormFooter/utilities/formFooter.utils.d.ts.map +1 -0
  59. package/dist/components/forms/FormFooter/utilities/formFooter.utils.js +19 -0
  60. package/dist/components/forms/FormFooter/utilities/formFooter.utils.js.map +1 -0
  61. package/dist/components/forms/FormSection/FormSection.styles.cjs +15 -0
  62. package/dist/components/forms/FormSection/FormSection.styles.cjs.map +1 -0
  63. package/dist/components/forms/FormSection/FormSection.styles.d.ts +9 -0
  64. package/dist/components/forms/FormSection/FormSection.styles.d.ts.map +1 -0
  65. package/dist/components/forms/FormSection/FormSection.styles.js +13 -0
  66. package/dist/components/forms/FormSection/FormSection.styles.js.map +1 -0
  67. package/dist/components/forms/FormSection/index.cjs +43 -0
  68. package/dist/components/forms/FormSection/index.cjs.map +1 -0
  69. package/dist/components/forms/FormSection/index.d.ts +41 -0
  70. package/dist/components/forms/FormSection/index.d.ts.map +1 -0
  71. package/dist/components/forms/FormSection/index.js +41 -0
  72. package/dist/components/forms/FormSection/index.js.map +1 -0
  73. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.cjs +28 -0
  74. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.cjs.map +1 -0
  75. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.d.ts +12 -0
  76. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.d.ts.map +1 -0
  77. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.js +26 -0
  78. package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.js.map +1 -0
  79. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.cjs +68 -0
  80. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.cjs.map +1 -0
  81. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.d.ts +26 -0
  82. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.d.ts.map +1 -0
  83. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.js +66 -0
  84. package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.js.map +1 -0
  85. package/dist/components/forms/__internal__/formField/hooks/useFormField.cjs +142 -0
  86. package/dist/components/forms/__internal__/formField/hooks/useFormField.cjs.map +1 -0
  87. package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts +35 -0
  88. package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts.map +1 -0
  89. package/dist/components/forms/__internal__/formField/hooks/useFormField.js +140 -0
  90. package/dist/components/forms/__internal__/formField/hooks/useFormField.js.map +1 -0
  91. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.cjs +12 -0
  92. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.cjs.map +1 -0
  93. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.d.ts +7 -0
  94. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.d.ts.map +1 -0
  95. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.js +10 -0
  96. package/dist/components/forms/__internal__/formField/providers/FieldElements.context.js.map +1 -0
  97. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.cjs +39 -0
  98. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.cjs.map +1 -0
  99. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.d.ts +21 -0
  100. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.d.ts.map +1 -0
  101. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.js +37 -0
  102. package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.js.map +1 -0
  103. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.cjs +40 -0
  104. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.cjs.map +1 -0
  105. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.d.ts +18 -0
  106. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.d.ts.map +1 -0
  107. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.js +37 -0
  108. package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.js.map +1 -0
  109. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.cjs +21 -0
  110. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.cjs.map +1 -0
  111. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.d.ts +11 -0
  112. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.d.ts.map +1 -0
  113. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.js +19 -0
  114. package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.js.map +1 -0
  115. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.cjs +128 -0
  116. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.cjs.map +1 -0
  117. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.d.ts +72 -0
  118. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.d.ts.map +1 -0
  119. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.js +121 -0
  120. package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.js.map +1 -0
  121. package/dist/components/forms/fields/FormCheckbox/index.cjs +34 -0
  122. package/dist/components/forms/fields/FormCheckbox/index.cjs.map +1 -0
  123. package/dist/components/forms/fields/FormCheckbox/index.d.ts +16 -0
  124. package/dist/components/forms/fields/FormCheckbox/index.d.ts.map +1 -0
  125. package/dist/components/forms/fields/FormCheckbox/index.js +32 -0
  126. package/dist/components/forms/fields/FormCheckbox/index.js.map +1 -0
  127. package/dist/components/forms/fields/FormCheckboxGroup/index.cjs +33 -0
  128. package/dist/components/forms/fields/FormCheckboxGroup/index.cjs.map +1 -0
  129. package/dist/components/forms/fields/FormCheckboxGroup/index.d.ts +16 -0
  130. package/dist/components/forms/fields/FormCheckboxGroup/index.d.ts.map +1 -0
  131. package/dist/components/forms/fields/FormCheckboxGroup/index.js +31 -0
  132. package/dist/components/forms/fields/FormCheckboxGroup/index.js.map +1 -0
  133. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.cjs +26 -0
  134. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.cjs.map +1 -0
  135. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.d.ts +11 -0
  136. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.d.ts.map +1 -0
  137. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.js +24 -0
  138. package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.js.map +1 -0
  139. package/dist/components/forms/fields/FormColorPicker/index.cjs +33 -0
  140. package/dist/components/forms/fields/FormColorPicker/index.cjs.map +1 -0
  141. package/dist/components/forms/fields/FormColorPicker/index.d.ts +21 -0
  142. package/dist/components/forms/fields/FormColorPicker/index.d.ts.map +1 -0
  143. package/dist/components/forms/fields/FormColorPicker/index.js +31 -0
  144. package/dist/components/forms/fields/FormColorPicker/index.js.map +1 -0
  145. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.cjs +20 -0
  146. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.cjs.map +1 -0
  147. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.d.ts +17 -0
  148. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.d.ts.map +1 -0
  149. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.js +18 -0
  150. package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.js.map +1 -0
  151. package/dist/components/forms/fields/FormDatePicker/index.cjs +35 -0
  152. package/dist/components/forms/fields/FormDatePicker/index.cjs.map +1 -0
  153. package/dist/components/forms/fields/FormDatePicker/index.d.ts +17 -0
  154. package/dist/components/forms/fields/FormDatePicker/index.d.ts.map +1 -0
  155. package/dist/components/forms/fields/FormDatePicker/index.js +33 -0
  156. package/dist/components/forms/fields/FormDatePicker/index.js.map +1 -0
  157. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.cjs +23 -0
  158. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.cjs.map +1 -0
  159. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.d.ts +9 -0
  160. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.d.ts.map +1 -0
  161. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.js +21 -0
  162. package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.js.map +1 -0
  163. package/dist/components/forms/fields/FormInput/index.cjs +27 -0
  164. package/dist/components/forms/fields/FormInput/index.cjs.map +1 -0
  165. package/dist/components/forms/fields/FormInput/index.d.ts +16 -0
  166. package/dist/components/forms/fields/FormInput/index.d.ts.map +1 -0
  167. package/dist/components/forms/fields/FormInput/index.js +25 -0
  168. package/dist/components/forms/fields/FormInput/index.js.map +1 -0
  169. package/dist/components/forms/fields/FormMultiSelect/index.cjs +44 -0
  170. package/dist/components/forms/fields/FormMultiSelect/index.cjs.map +1 -0
  171. package/dist/components/forms/fields/FormMultiSelect/index.d.ts +17 -0
  172. package/dist/components/forms/fields/FormMultiSelect/index.d.ts.map +1 -0
  173. package/dist/components/forms/fields/FormMultiSelect/index.js +42 -0
  174. package/dist/components/forms/fields/FormMultiSelect/index.js.map +1 -0
  175. package/dist/components/forms/fields/FormRadioCardGroup/index.cjs +36 -0
  176. package/dist/components/forms/fields/FormRadioCardGroup/index.cjs.map +1 -0
  177. package/dist/components/forms/fields/FormRadioCardGroup/index.d.ts +29 -0
  178. package/dist/components/forms/fields/FormRadioCardGroup/index.d.ts.map +1 -0
  179. package/dist/components/forms/fields/FormRadioCardGroup/index.js +34 -0
  180. package/dist/components/forms/fields/FormRadioCardGroup/index.js.map +1 -0
  181. package/dist/components/forms/fields/FormRadioGroup/index.cjs +31 -0
  182. package/dist/components/forms/fields/FormRadioGroup/index.cjs.map +1 -0
  183. package/dist/components/forms/fields/FormRadioGroup/index.d.ts +17 -0
  184. package/dist/components/forms/fields/FormRadioGroup/index.d.ts.map +1 -0
  185. package/dist/components/forms/fields/FormRadioGroup/index.js +29 -0
  186. package/dist/components/forms/fields/FormRadioGroup/index.js.map +1 -0
  187. package/dist/components/forms/fields/FormSelect/index.cjs +30 -0
  188. package/dist/components/forms/fields/FormSelect/index.cjs.map +1 -0
  189. package/dist/components/forms/fields/FormSelect/index.d.ts +16 -0
  190. package/dist/components/forms/fields/FormSelect/index.d.ts.map +1 -0
  191. package/dist/components/forms/fields/FormSelect/index.js +28 -0
  192. package/dist/components/forms/fields/FormSelect/index.js.map +1 -0
  193. package/dist/components/forms/fields/FormSlider/index.cjs +43 -0
  194. package/dist/components/forms/fields/FormSlider/index.cjs.map +1 -0
  195. package/dist/components/forms/fields/FormSlider/index.d.ts +17 -0
  196. package/dist/components/forms/fields/FormSlider/index.d.ts.map +1 -0
  197. package/dist/components/forms/fields/FormSlider/index.js +41 -0
  198. package/dist/components/forms/fields/FormSlider/index.js.map +1 -0
  199. package/dist/components/forms/fields/FormTextArea/index.cjs +27 -0
  200. package/dist/components/forms/fields/FormTextArea/index.cjs.map +1 -0
  201. package/dist/components/forms/fields/FormTextArea/index.d.ts +16 -0
  202. package/dist/components/forms/fields/FormTextArea/index.d.ts.map +1 -0
  203. package/dist/components/forms/fields/FormTextArea/index.js +25 -0
  204. package/dist/components/forms/fields/FormTextArea/index.js.map +1 -0
  205. package/dist/components/forms/fields/FormToggle/index.cjs +32 -0
  206. package/dist/components/forms/fields/FormToggle/index.cjs.map +1 -0
  207. package/dist/components/forms/fields/FormToggle/index.d.ts +16 -0
  208. package/dist/components/forms/fields/FormToggle/index.d.ts.map +1 -0
  209. package/dist/components/forms/fields/FormToggle/index.js +30 -0
  210. package/dist/components/forms/fields/FormToggle/index.js.map +1 -0
  211. package/dist/components/forms/validation/hooks/useSchemaResolver.cjs +39 -0
  212. package/dist/components/forms/validation/hooks/useSchemaResolver.cjs.map +1 -0
  213. package/dist/components/forms/validation/hooks/useSchemaResolver.d.ts +15 -0
  214. package/dist/components/forms/validation/hooks/useSchemaResolver.d.ts.map +1 -0
  215. package/dist/components/forms/validation/hooks/useSchemaResolver.js +37 -0
  216. package/dist/components/forms/validation/hooks/useSchemaResolver.js.map +1 -0
  217. package/dist/components/forms/validation/index.cjs +309 -0
  218. package/dist/components/forms/validation/index.cjs.map +1 -0
  219. package/dist/components/forms/validation/index.d.ts +214 -0
  220. package/dist/components/forms/validation/index.d.ts.map +1 -0
  221. package/dist/components/forms/validation/index.js +293 -0
  222. package/dist/components/forms/validation/index.js.map +1 -0
  223. package/dist/components/forms/validation/utilities/validation.utils.cjs +42 -0
  224. package/dist/components/forms/validation/utilities/validation.utils.cjs.map +1 -0
  225. package/dist/components/forms/validation/utilities/validation.utils.d.ts +20 -0
  226. package/dist/components/forms/validation/utilities/validation.utils.d.ts.map +1 -0
  227. package/dist/components/forms/validation/utilities/validation.utils.js +39 -0
  228. package/dist/components/forms/validation/utilities/validation.utils.js.map +1 -0
  229. package/dist/components/forms/validation/validation.types.d.ts +8 -0
  230. package/dist/components/forms/validation/validation.types.d.ts.map +1 -0
  231. package/dist/components/organisms/ColorPicker/components/ColorPickerField.cjs +13 -3
  232. package/dist/components/organisms/ColorPicker/components/ColorPickerField.cjs.map +1 -1
  233. package/dist/components/organisms/ColorPicker/components/ColorPickerField.d.ts +1 -1
  234. package/dist/components/organisms/ColorPicker/components/ColorPickerField.d.ts.map +1 -1
  235. package/dist/components/organisms/ColorPicker/components/ColorPickerField.js +13 -3
  236. package/dist/components/organisms/ColorPicker/components/ColorPickerField.js.map +1 -1
  237. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.cjs +2 -2
  238. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.cjs.map +1 -1
  239. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.d.ts +1 -0
  240. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.d.ts.map +1 -1
  241. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.js +2 -2
  242. package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.js.map +1 -1
  243. package/dist/components/organisms/ColorPicker/hooks/useCssColorField.cjs +1 -1
  244. package/dist/components/organisms/ColorPicker/hooks/useCssColorField.js +1 -1
  245. package/dist/components/organisms/ColorPicker/index.cjs +1 -1
  246. package/dist/components/organisms/ColorPicker/index.d.ts.map +1 -1
  247. package/dist/components/organisms/ColorPicker/index.js +1 -1
  248. package/dist/components/organisms/ColorPicker/providers/ColorPicker.provider.d.ts +1 -1
  249. package/dist/components/organisms/ColorPicker/providers/ColorPicker.provider.d.ts.map +1 -1
  250. package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.cjs.map +1 -0
  251. package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.d.ts.map +1 -0
  252. package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.js.map +1 -0
  253. package/dist/components/organisms/GradientPicker/components/GradientStopRow.cjs +1 -1
  254. package/dist/components/organisms/GradientPicker/components/GradientStopRow.js +1 -1
  255. package/dist/localization/en.json.cjs +98 -0
  256. package/dist/localization/en.json.cjs.map +1 -0
  257. package/dist/localization/en.json.js +81 -0
  258. package/dist/localization/en.json.js.map +1 -0
  259. package/dist/native/components/forms/Form/index.d.ts +12 -0
  260. package/dist/native/components/forms/FormFooter/index.d.ts +12 -0
  261. package/dist/native/components/forms/FormSection/index.d.ts +12 -0
  262. package/dist/native/components/forms/fields/FormCheckbox/index.d.ts +12 -0
  263. package/dist/native/components/forms/fields/FormCheckboxGroup/index.d.ts +12 -0
  264. package/dist/native/components/forms/fields/FormColorPicker/index.d.ts +12 -0
  265. package/dist/native/components/forms/fields/FormDatePicker/index.d.ts +12 -0
  266. package/dist/native/components/forms/fields/FormInput/index.d.ts +12 -0
  267. package/dist/native/components/forms/fields/FormMultiSelect/index.d.ts +12 -0
  268. package/dist/native/components/forms/fields/FormRadioCardGroup/index.d.ts +12 -0
  269. package/dist/native/components/forms/fields/FormRadioGroup/index.d.ts +12 -0
  270. package/dist/native/components/forms/fields/FormSelect/index.d.ts +12 -0
  271. package/dist/native/components/forms/fields/FormSlider/index.d.ts +12 -0
  272. package/dist/native/components/forms/fields/FormTextArea/index.d.ts +12 -0
  273. package/dist/native/components/forms/fields/FormToggle/index.d.ts +12 -0
  274. package/dist/native/components/forms/validation/index.d.ts +12 -0
  275. package/dist/providers/UnsavedChangesGuardProvider/index.cjs +1 -1
  276. package/dist/providers/UnsavedChangesGuardProvider/index.js +1 -1
  277. package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.cjs.map +1 -0
  278. package/dist/providers/UnsavedChangesGuardProvider/{unsavedChangesGuard.utils.d.ts → utilities/unsavedChangesGuard.utils.d.ts} +1 -1
  279. package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.d.ts.map +1 -0
  280. package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.js.map +1 -0
  281. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.cjs +74 -0
  282. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.cjs.map +1 -0
  283. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.d.ts +51 -0
  284. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.d.ts.map +1 -0
  285. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.js +68 -0
  286. package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.js.map +1 -0
  287. package/package.json +41 -6
  288. package/dist/components/organisms/ColorPicker/colorPicker.utils.cjs.map +0 -1
  289. package/dist/components/organisms/ColorPicker/colorPicker.utils.d.ts.map +0 -1
  290. package/dist/components/organisms/ColorPicker/colorPicker.utils.js.map +0 -1
  291. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.cjs.map +0 -1
  292. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.d.ts.map +0 -1
  293. package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.js.map +0 -1
  294. /package/dist/components/organisms/ColorPicker/{colorPicker.utils.cjs → utilities/colorPicker.utils.cjs} +0 -0
  295. /package/dist/components/organisms/ColorPicker/{colorPicker.utils.d.ts → utilities/colorPicker.utils.d.ts} +0 -0
  296. /package/dist/components/organisms/ColorPicker/{colorPicker.utils.js → utilities/colorPicker.utils.js} +0 -0
  297. /package/dist/providers/UnsavedChangesGuardProvider/{unsavedChangesGuard.utils.cjs → utilities/unsavedChangesGuard.utils.cjs} +0 -0
  298. /package/dist/providers/UnsavedChangesGuardProvider/{unsavedChangesGuard.utils.js → utilities/unsavedChangesGuard.utils.js} +0 -0
@@ -0,0 +1,140 @@
1
+ import { useContext, useCallback, useRef, useEffect } from 'react';
2
+ import { useFormContext, useController } from 'react-hook-form';
3
+ import { FieldElementsContext } from '../providers/FieldElements.context.js';
4
+ import { isSameValue, isFilledIn } from '../utilities/fieldValue.utils.js';
5
+ import { validationQueueOf, runInTurn, isAwaitingAnswer, holdTurnsUntil, withdrawAsks } from '../utilities/validationQueue.utils.js';
6
+ import { useFocusThroughSubmit } from './useFocusThroughSubmit.js';
7
+
8
+ const toList = (value) => {
9
+ if (value === undefined)
10
+ return [];
11
+ return Array.isArray(value) ? value : [value];
12
+ };
13
+ /**
14
+ * Binds one control to a react-hook-form field, for the `components/forms` wrappers. In a form that validates and
15
+ * re-validates on blur (`mode` and `reValidateMode` both `'onBlur'`) it re-validates a field on every change while that field is invalid, so an error raised by a blur,
16
+ * a submit, `trigger()` or the server clears as soon as the user fixes it, and a valid field stays quiet until blur.
17
+ * It also reports the form's lock: disabled for good, or locked while it submits.
18
+ *
19
+ * @param name The field's path in the form values.
20
+ * @param revalidates Other fields whose rule reads this one. Typing here re-validates those already invalid; finishing the edit also re-validates those the user has filled in or visited.
21
+ * @returns The field's `value`, `onChange`, `onCommit`, `onDraft`, `onBlur`, `ref` and `name`, with `isInvalid`, its `errorMessage`, and the form's lock as `isDisabled` and `isLocked`.
22
+ */
23
+ const useFormField = (name, revalidates) => {
24
+ const form = useFormContext();
25
+ if (!form)
26
+ throw new Error('A components/forms field needs a react-hook-form FormProvider above it.');
27
+ const { control, trigger, getFieldState, getValues } = form;
28
+ const { field, fieldState, formState } = useController({ name, control });
29
+ const { ref: focusRef, isLocked } = useFocusThroughSubmit(field.ref, formState.isSubmitting);
30
+ const fieldElements = useContext(FieldElementsContext);
31
+ // `Form` reads where each field sits, so a failed submit focuses the first invalid one in page order.
32
+ const ref = useCallback((instance) => {
33
+ focusRef(instance);
34
+ const element = instance instanceof Element ? instance : instance?.element;
35
+ if (element)
36
+ fieldElements?.set(name, element);
37
+ else
38
+ fieldElements?.delete(name);
39
+ }, [focusRef, fieldElements, name]);
40
+ const { onChange: setValue } = field;
41
+ const isInvalid = fieldState.invalid;
42
+ const { error } = fieldState;
43
+ const errorMessage = error?.message;
44
+ // `trigger` is only on the form, not on `control`, which is why the wrappers need a FormProvider.
45
+ const validate = useCallback((names) => trigger(names), [trigger]);
46
+ const validation = validationQueueOf(control);
47
+ // Typing only ever clears an error or changes its message, so it asks only while the field is invalid.
48
+ const isInvalidNow = useCallback((field) => getFieldState(field).invalid, [getFieldState]);
49
+ const revalidate = useCallback(() => runInTurn(validation, [name], isInvalidNow, validate), [validation, name, isInvalidNow, validate]);
50
+ // Whether a finished edit still stands when a check it asked for comes up: the field holds that value, and counts as
51
+ // visited or changed. A reset leaves it neither, even one to the value just chosen, and validating then would put an error on a form just discarded.
52
+ const standingEdit = useCallback(() => {
53
+ const edited = getValues(name);
54
+ return () => {
55
+ const editor = getFieldState(name);
56
+ // By what it holds: leaving the field copies a list or a group, so the same choice comes back as a new object.
57
+ return isSameValue(getValues(name), edited) && (editor.isTouched || editor.isDirty);
58
+ };
59
+ }, [name, getFieldState, getValues]);
60
+ // The end of an edit: react-hook-form marks the field visited and validates it, by itself and outside the queue.
61
+ const { onBlur: validateOnBlur } = field;
62
+ const finishEdit = useCallback(() => {
63
+ const isAwaited = isAwaitingAnswer(validation, name);
64
+ // Typed as returning nothing, but react-hook-form (7.92) returns the validation it started; without it no turn is held back.
65
+ const answer = validateOnBlur();
66
+ holdTurnsUntil(validation, name, answer);
67
+ // An answer on its way is for an older value and may land after this one: asked again in turn, so it is not the last word.
68
+ if (isAwaited)
69
+ void runInTurn(validation, [name], standingEdit(), validate);
70
+ }, [validation, name, validateOnBlur, standingEdit, validate]);
71
+ // A cross-field rule puts its error on another field, which the form never re-checks when this one changes. Typing
72
+ // only clears such an error; a finished edit may also raise one, on a dependent the user has filled in or visited.
73
+ const revalidateDependents = useCallback((isEditFinished) => {
74
+ // The edit that asks. If it is gone when the turn comes, only an error already on screen is worth re-checking.
75
+ const isEditStanding = standingEdit();
76
+ const isWanted = (dependent) => {
77
+ const { invalid, isTouched } = getFieldState(dependent);
78
+ if (invalid)
79
+ return true;
80
+ return isEditFinished && isEditStanding() && (isTouched || isFilledIn(getValues(dependent)));
81
+ };
82
+ const dependents = toList(revalidates);
83
+ if (dependents.length > 0)
84
+ void runInTurn(validation, dependents, isWanted, validate);
85
+ }, [revalidates, standingEdit, getFieldState, getValues, validation, validate]);
86
+ // Typed into since the dependents were last checked in full, which leaving the field then does.
87
+ const hasTyped = useRef(false);
88
+ const onChange = useCallback((next) => {
89
+ setValue(next);
90
+ const isAwaited = isAwaitingAnswer(validation, name);
91
+ // Leaving the field checks it again, so nothing withdrawn here is lost.
92
+ withdrawAsks(validation, name);
93
+ // Read from the form, not from the last render: an error that landed between two keystrokes is not on screen yet.
94
+ // Also while an answer is on its way: the error may have cleared since, and that answer is for an older value.
95
+ if (getFieldState(name).invalid || isAwaited)
96
+ void revalidate();
97
+ hasTyped.current = true;
98
+ revalidateDependents(false);
99
+ }, [setValue, getFieldState, validation, name, revalidate, revalidateDependents]);
100
+ // The value the current error was raised against. Leaving the field without changing it cannot make it valid, and
101
+ // re-validating would wipe an error only the server can judge, such as a name that is already taken.
102
+ const erroredValue = useRef(undefined);
103
+ const { value } = field;
104
+ // biome-ignore lint/correctness/useExhaustiveDependencies: recorded when the error appears or changes, not on every keystroke
105
+ useEffect(() => {
106
+ erroredValue.current = error ? value : undefined;
107
+ }, [error]);
108
+ const onBlur = useCallback(() => {
109
+ const hadTyped = hasTyped.current;
110
+ hasTyped.current = false;
111
+ // First, so the field counts as visited before its dependents are asked about, which they are only while it does.
112
+ if (!(error && isSameValue(value, erroredValue.current)))
113
+ finishEdit();
114
+ // Leaving a field the user only passed through must not raise an error on another one.
115
+ if (hadTyped)
116
+ revalidateDependents(true);
117
+ }, [error, value, finishEdit, revalidateDependents]);
118
+ // A choice has no typing phase to wait out, so it counts as changed and left in one step.
119
+ const onCommit = useCallback((next) => {
120
+ setValue(next);
121
+ finishEdit();
122
+ revalidateDependents(true);
123
+ }, [setValue, finishEdit, revalidateDependents]);
124
+ return {
125
+ name: field.name,
126
+ value: value,
127
+ ref,
128
+ onBlur,
129
+ onDraft: setValue,
130
+ onChange,
131
+ onCommit,
132
+ isInvalid,
133
+ errorMessage,
134
+ isDisabled: field.disabled ?? false,
135
+ isLocked,
136
+ };
137
+ };
138
+
139
+ export { useFormField };
140
+ //# sourceMappingURL=useFormField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormField.js","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFormField.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AA8BA,MAAM,MAAM,GAAG,CAAQ,KAAkC,KAAa;IACpE,IAAI,KAAK,KAAK,SAAS;AAAE,QAAA,OAAO,EAAE;AAClC,IAAA,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC;AAC/C,CAAC;AAED;;;;;;;;;AASG;MACU,YAAY,GAAG,CAC1B,IAAwB,EACxB,WAAuD,KAClC;AACrB,IAAA,MAAM,I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alid field in page order, and `FormFooter` to
7
+ * count only the errors a user can see. `null` outside `Form`.
8
+ */
9
+ const FieldElementsContext = React.createContext(null);
10
+
11
+ exports.FieldElementsContext = FieldElementsContext;
12
+ //# sourceMappingURL=FieldElements.context.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldElements.context.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/providers/FieldElements.context.ts"],"sourcesContent":[null],"names":["createContext"],"mappings":";;;;AAGA;;;AAGG;MACU,oBAAoB,GAAGA,mBAAa,CAAuB,IAAI;;"}
@@ -0,0 +1,7 @@
1
+ import type { FieldElements } from '../utilities/fieldElements.utils';
2
+ /**
3
+ * The fields `Form` has on the page: it reads them to find the first invalid field in page order, and `FormFooter` to
4
+ * count only the errors a user can see. `null` outside `Form`.
5
+ */
6
+ export declare const FieldElementsContext: import("react").Context<FieldElements | null>;
7
+ //# sourceMappingURL=FieldElements.context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldElements.context.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/providers/FieldElements.context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,oBAAoB,+CAA4C,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { createContext } from 'react';
2
+
3
+ /**
4
+ * The fields `Form` has on the page: it reads them to find the first invalid field in page order, and `FormFooter` to
5
+ * count only the errors a user can see. `null` outside `Form`.
6
+ */
7
+ const FieldElementsContext = createContext(null);
8
+
9
+ export { FieldElementsContext };
10
+ //# sourceMappingURL=FieldElements.context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldElements.context.js","sources":["../../../../../../src/components/forms/__internal__/formField/providers/FieldElements.context.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;AAGG;MACU,oBAAoB,GAAG,aAAa,CAAuB,IAAI;;"}
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Creates the record of a form's mounted fields. A field leaving the page changes nothing in the form's state, so a
5
+ * component that depends on which fields are shown, such as the footer's Save button, subscribes here to render again.
6
+ *
7
+ * @returns The record, empty until a field mounts.
8
+ */
9
+ const createFieldElements = () => {
10
+ const elements = new Map();
11
+ const listeners = new Set();
12
+ let version = 0;
13
+ const changed = () => {
14
+ version += 1;
15
+ for (const listener of [...listeners])
16
+ listener();
17
+ };
18
+ return {
19
+ elements,
20
+ set: (name, element) => {
21
+ if (elements.get(name) === element)
22
+ return;
23
+ elements.set(name, element);
24
+ changed();
25
+ },
26
+ delete: (name) => {
27
+ if (elements.delete(name))
28
+ changed();
29
+ },
30
+ subscribe: (onChange) => {
31
+ listeners.add(onChange);
32
+ return () => listeners.delete(onChange);
33
+ },
34
+ getVersion: () => version,
35
+ };
36
+ };
37
+
38
+ exports.createFieldElements = createFieldElements;
39
+ //# sourceMappingURL=fieldElements.utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fieldElements.utils.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/utilities/fieldElements.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAcA;;;;;AAKG;AACI,MAAM,mBAAmB,GAAG,MAAoB;AACrD,IAAA,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAmB;AAC3C,IAAA,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc;IACvC,IAAI,OAAO,GAAG,CAAC;IAEf,MAAM,OAAO,GAAG,MAAK;QACnB,OAAO,IAAI,CAAC;AACZ,QAAA,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,SAAS,CAAC;AAAE,YAAA,QAAQ,EAAE;AACnD,IAAA,CAAC;IAED,OAAO;QACL,QAAQ;AACR,QAAA,GAAG,EAAE,CAAC,IAAI,EAAE,OAAO,KAAI;AACrB,YAAA,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,OAAO;gBAAE;AACpC,YAAA,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC;AAC3B,YAAA,OAAO,EAAE;QACX,CAAC;AACD,QAAA,MAAM,EAAE,CAAC,IAAI,KAAI;AACf,YAAA,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;AAAE,gBAAA,OAAO,EAAE;QACtC,CAAC;AACD,QAAA,SAAS,EAAE,CAAC,QAAQ,KAAI;AACtB,YAAA,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC;YACvB,OAAO,MAAM,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC;QACzC,CAAC;AACD,QAAA,UAAU,EAAE,MAAM,OAAO;KAC1B;AACH;;"}
@@ -0,0 +1,21 @@
1
+ /** The fields a `Form` has on the page, which tells whatever reads it when one joins or leaves. */
2
+ export interface FieldElements {
3
+ /** Each mounted field's element by field name. */
4
+ elements: Map<string, Element>;
5
+ /** Records a field's element as it mounts. */
6
+ set: (name: string, element: Element) => void;
7
+ /** Forgets a field as it leaves the page. */
8
+ delete: (name: string) => void;
9
+ /** Calls `onChange` after a field joins or leaves, in the shape `useSyncExternalStore` takes; returns the function that stops it. */
10
+ subscribe: (onChange: () => void) => () => void;
11
+ /** A number that changes whenever a field joins or leaves. */
12
+ getVersion: () => number;
13
+ }
14
+ /**
15
+ * Creates the record of a form's mounted fields. A field leaving the page changes nothing in the form's state, so a
16
+ * component that depends on which fields are shown, such as the footer's Save button, subscribes here to render again.
17
+ *
18
+ * @returns The record, empty until a field mounts.
19
+ */
20
+ export declare const createFieldElements: () => FieldElements;
21
+ //# sourceMappingURL=fieldElements.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fieldElements.utils.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/utilities/fieldElements.utils.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,8CAA8C;IAC9C,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9C,6CAA6C;IAC7C,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,qIAAqI;IACrI,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;IAChD,8DAA8D;IAC9D,UAAU,EAAE,MAAM,MAAM,CAAC;CAC1B;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,QAAO,aA0BtC,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Creates the record of a form's mounted fields. A field leaving the page changes nothing in the form's state, so a
3
+ * component that depends on which fields are shown, such as the footer's Save button, subscribes here to render again.
4
+ *
5
+ * @returns The record, empty until a field mounts.
6
+ */
7
+ const createFieldElements = () => {
8
+ const elements = new Map();
9
+ const listeners = new Set();
10
+ let version = 0;
11
+ const changed = () => {
12
+ version += 1;
13
+ for (const listener of [...listeners])
14
+ listener();
15
+ };
16
+ return {
17
+ elements,
18
+ set: (name, element) => {
19
+ if (elements.get(name) === element)
20
+ return;
21
+ elements.set(name, element);
22
+ changed();
23
+ },
24
+ delete: (name) => {
25
+ if (elements.delete(name))
26
+ changed();
27
+ },
28
+ subscribe: (onChange) => {
29
+ listeners.add(onChange);
30
+ return () => listeners.delete(onChange);
31
+ },
32
+ getVersion: () => version,
33
+ };
34
+ };
35
+
36
+ export { createFieldElements };
37
+ //# sourceMappingURL=fieldElements.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fieldElements.utils.js","sources":["../../../../../../src/components/forms/__internal__/formField/utilities/fieldElements.utils.ts"],"sourcesContent":[null],"names":[],"mappings":"AAcA;;;;;AAKG;AACI,MAAM,mBAAmB,GAAG,MAAoB;AACrD,IAAA,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAmB;AAC3C,IAAA,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc;IACvC,IAAI,OAAO,GAAG,CAAC;IAEf,MAAM,OAAO,GAAG,MAAK;QACnB,OAAO,IAAI,CAAC;AACZ,QAAA,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,SAAS,CAAC;AAAE,YAAA,QAAQ,EAAE;AACnD,IAAA,CAAC;IAED,OAAO;QACL,QAAQ;AACR,QAAA,GAAG,EAAE,CAAC,IAAI,EAAE,OAAO,KAAI;AACrB,YAAA,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,OAAO;gBAAE;AACpC,YAAA,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC;AAC3B,YAAA,OAAO,EAAE;QACX,CAAC;AACD,QAAA,MAAM,EAAE,CAAC,IAAI,KAAI;AACf,YAAA,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;AAAE,gBAAA,OAAO,EAAE;QACtC,CAAC;AACD,QAAA,SAAS,EAAE,CAAC,QAAQ,KAAI;AACtB,YAAA,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC;YACvB,OAAO,MAAM,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC;QACzC,CAAC;AACD,QAAA,UAAU,EAAE,MAAM,OAAO;KAC1B;AACH;;"}
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ // Only a list or a plain group is looked into; any other object, such as a date, is a value in itself.
4
+ const isGroup = (value) => typeof value === 'object' && value !== null && (Array.isArray(value) || Object.getPrototypeOf(value) === Object.prototype);
5
+ /**
6
+ * Tells whether the user has given a field a value. An unticked box, an empty list and a group holding only such
7
+ * values all count as empty.
8
+ *
9
+ * @param value The field's value as the form holds it.
10
+ * @returns `true` when the value, or something inside it, is filled in.
11
+ */
12
+ const isFilledIn = (value) => {
13
+ if (value === undefined || value === null || value === '' || value === false)
14
+ return false;
15
+ return isGroup(value) ? Object.values(value).some(isFilledIn) : true;
16
+ };
17
+ /**
18
+ * Compares two values of a field by what they hold, not by which object holds it: react-hook-form copies a list or a
19
+ * group when the field is left, so the same choice comes back as a new object.
20
+ *
21
+ * @param first One value of the field.
22
+ * @param second The value to compare it with.
23
+ * @returns `true` when both hold the same thing, entry for entry.
24
+ */
25
+ const isSameValue = (first, second) => {
26
+ if (Object.is(first, second))
27
+ return true;
28
+ if (first instanceof Date && second instanceof Date)
29
+ return first.getTime() === second.getTime();
30
+ if (!isGroup(first) || !isGroup(second) || Array.isArray(first) !== Array.isArray(second))
31
+ return false;
32
+ const keys = Object.keys(first);
33
+ const other = second;
34
+ return (keys.length === Object.keys(second).length &&
35
+ keys.every((key) => key in other && isSameValue(first[key], other[key])));
36
+ };
37
+
38
+ exports.isFilledIn = isFilledIn;
39
+ exports.isSameValue = isSameValue;
40
+ //# sourceMappingURL=fieldValue.utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fieldValue.utils.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/utilities/fieldValue.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;AACA,MAAM,OAAO,GAAG,CAAC,KAAc,KAC7B,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,SAAS,CAAC;AAE5H;;;;;;AAMG;AACI,MAAM,UAAU,GAAG,CAAC,KAAc,KAAa;AACpD,IAAA,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,KAAK;AAAE,QAAA,OAAO,KAAK;IAC1F,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI;AACtE;AAEA;;;;;;;AAOG;MACU,WAAW,GAAG,CAAC,KAAc,EAAE,MAAe,KAAa;AACtE,IAAA,IAAI,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;AAAE,QAAA,OAAO,IAAI;AACzC,IAAA,IAAI,KAAK,YAAY,IAAI,IAAI,MAAM,YAAY,IAAI;QAAE,OAAO,KAAK,CAAC,OAAO,EAAE,KAAK,MAAM,CAAC,OAAO,EAAE;IAChG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;AAAE,QAAA,OAAO,KAAK;IACvG,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;IAC/B,MAAM,KAAK,GAAG,MAAiC;AAC/C,IAAA,QACE,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM;QAC1C,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI,KAAK,IAAI,WAAW,CAAE,KAAiC,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAEzG;;;"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Tells whether the user has given a field a value. An unticked box, an empty list and a group holding only such
3
+ * values all count as empty.
4
+ *
5
+ * @param value The field's value as the form holds it.
6
+ * @returns `true` when the value, or something inside it, is filled in.
7
+ */
8
+ export declare const isFilledIn: (value: unknown) => boolean;
9
+ /**
10
+ * Compares two values of a field by what they hold, not by which object holds it: react-hook-form copies a list or a
11
+ * group when the field is left, so the same choice comes back as a new object.
12
+ *
13
+ * @param first One value of the field.
14
+ * @param second The value to compare it with.
15
+ * @returns `true` when both hold the same thing, entry for entry.
16
+ */
17
+ export declare const isSameValue: (first: unknown, second: unknown) => boolean;
18
+ //# sourceMappingURL=fieldValue.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fieldValue.utils.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/utilities/fieldValue.utils.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,OAG3C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,EAAE,QAAQ,OAAO,KAAG,OAU7D,CAAC"}
@@ -0,0 +1,37 @@
1
+ // Only a list or a plain group is looked into; any other object, such as a date, is a value in itself.
2
+ const isGroup = (value) => typeof value === 'object' && value !== null && (Array.isArray(value) || Object.getPrototypeOf(value) === Object.prototype);
3
+ /**
4
+ * Tells whether the user has given a field a value. An unticked box, an empty list and a group holding only such
5
+ * values all count as empty.
6
+ *
7
+ * @param value The field's value as the form holds it.
8
+ * @returns `true` when the value, or something inside it, is filled in.
9
+ */
10
+ const isFilledIn = (value) => {
11
+ if (value === undefined || value === null || value === '' || value === false)
12
+ return false;
13
+ return isGroup(value) ? Object.values(value).some(isFilledIn) : true;
14
+ };
15
+ /**
16
+ * Compares two values of a field by what they hold, not by which object holds it: react-hook-form copies a list or a
17
+ * group when the field is left, so the same choice comes back as a new object.
18
+ *
19
+ * @param first One value of the field.
20
+ * @param second The value to compare it with.
21
+ * @returns `true` when both hold the same thing, entry for entry.
22
+ */
23
+ const isSameValue = (first, second) => {
24
+ if (Object.is(first, second))
25
+ return true;
26
+ if (first instanceof Date && second instanceof Date)
27
+ return first.getTime() === second.getTime();
28
+ if (!isGroup(first) || !isGroup(second) || Array.isArray(first) !== Array.isArray(second))
29
+ return false;
30
+ const keys = Object.keys(first);
31
+ const other = second;
32
+ return (keys.length === Object.keys(second).length &&
33
+ keys.every((key) => key in other && isSameValue(first[key], other[key])));
34
+ };
35
+
36
+ export { isFilledIn, isSameValue };
37
+ //# sourceMappingURL=fieldValue.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fieldValue.ut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AI,CAAC,MAAM,CAAC,CAAC,MAAM;QAC1C,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI,KAAK,IAAI,WAAW,CAAE,KAAiC,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAEzG;;"}
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ var reactHookForm = require('react-hook-form');
4
+
5
+ /**
6
+ * Finds the field to focus after a failed submit: the first invalid one as the page shows them. react-hook-form's own
7
+ * choice is the first in the order the fields mounted, which is not the page's once a field appears later than its neighbours.
8
+ *
9
+ * @param errors The form's errors after validation.
10
+ * @param fieldElements Each mounted field's element by field name.
11
+ * @returns The name to pass to `setFocus`, or `undefined` when no field on the page is invalid.
12
+ */
13
+ const firstInvalidFieldOnPage = (errors, fieldElements) => {
14
+ // A field that unmounted without clearing its entry is skipped: it is no longer on the page.
15
+ const invalid = [...fieldElements].filter(([name, element]) => element.isConnected && reactHookForm.get(errors, name));
16
+ const [first] = invalid.sort(([, a], [, b]) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1));
17
+ return first?.[0];
18
+ };
19
+
20
+ exports.firstInvalidFieldOnPage = firstInvalidFieldOnPage;
21
+ //# sourceMappingURL=formFocus.utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formFocus.utils.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/utilities/formFocus.utils.ts"],"sourcesContent":[null],"names":["get"],"mappings":";;;;AAEA;;;;;;;AAOG;MACU,uBAAuB,GAAG,CAAC,MAAmB,EAAE,aAAmC,KAAwB;;AAEtH,IAAA,MAAM,OAAO,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,WAAW,IAAIA,iBAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACxG,IAAA,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,2BAA2B,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC1H,IAAA,OAAO,KAAK,GAAG,CAAC,CAAC;AACnB;;"}
@@ -0,0 +1,11 @@
1
+ import { type FieldErrors } from 'react-hook-form';
2
+ /**
3
+ * Finds the field to focus after a failed submit: the first invalid one as the page shows them. react-hook-form's own
4
+ * choice is the first in the order the fields mounted, which is not the page's once a field appears later than its neighbours.
5
+ *
6
+ * @param errors The form's errors after validation.
7
+ * @param fieldElements Each mounted field's element by field name.
8
+ * @returns The name to pass to `setFocus`, or `undefined` when no field on the page is invalid.
9
+ */
10
+ export declare const firstInvalidFieldOnPage: (errors: FieldErrors, fieldElements: Map<string, Element>) => string | undefined;
11
+ //# sourceMappingURL=formFocus.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formFocus.utils.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/utilities/formFocus.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAO,MAAM,iBAAiB,CAAC;AAExD;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAAI,QAAQ,WAAW,EAAE,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAAM,GAAG,SAK3G,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { get } from 'react-hook-form';
2
+
3
+ /**
4
+ * Finds the field to focus after a failed submit: the first invalid one as the page shows them. react-hook-form's own
5
+ * choice is the first in the order the fields mounted, which is not the page's once a field appears later than its neighbours.
6
+ *
7
+ * @param errors The form's errors after validation.
8
+ * @param fieldElements Each mounted field's element by field name.
9
+ * @returns The name to pass to `setFocus`, or `undefined` when no field on the page is invalid.
10
+ */
11
+ const firstInvalidFieldOnPage = (errors, fieldElements) => {
12
+ // A field that unmounted without clearing its entry is skipped: it is no longer on the page.
13
+ const invalid = [...fieldElements].filter(([name, element]) => element.isConnected && get(errors, name));
14
+ const [first] = invalid.sort(([, a], [, b]) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1));
15
+ return first?.[0];
16
+ };
17
+
18
+ export { firstInvalidFieldOnPage };
19
+ //# sourceMappingURL=formFocus.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formFocus.utils.js","sources":["../../../../../../src/components/forms/__internal__/formField/utilities/formFocus.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;;;AAOG;MACU,uBAAuB,GAAG,CAAC,MAAmB,EAAE,aAAmC,KAAwB;;AAEtH,IAAA,MAAM,OAAO,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACxG,IAAA,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,2BAA2B,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC1H,IAAA,OAAO,KAAK,GAAG,CAAC,CAAC;AACnB;;"}
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+
3
+ // Kept by the form's `control`: a field's own validation and one asked for by a field that re-validates it would
4
+ // otherwise run side by side, and the answer for the older value could land last.
5
+ const queues = new WeakMap();
6
+ /**
7
+ * Gives a form its validation queue, one for the whole form however many fields ask.
8
+ *
9
+ * @param control The form's `control`, which the queue is kept by and dropped with.
10
+ * @returns The form's queue, created on the first ask.
11
+ */
12
+ const validationQueueOf = (control) => {
13
+ const queue = queues.get(control) ?? {
14
+ running: null,
15
+ waiting: new Map(),
16
+ isBusy: false,
17
+ leaving: new Map(),
18
+ };
19
+ queues.set(control, queue);
20
+ return queue;
21
+ };
22
+ /**
23
+ * Tells whether a validation of the field is running or waiting, so an answer is still to land for a value that may be old.
24
+ *
25
+ * @param queue The form's queue.
26
+ * @param name The field asked about.
27
+ * @returns `true` while the queue has yet to answer for the field.
28
+ */
29
+ const isAwaitingAnswer = (queue, name) => Boolean(queue.running?.includes(name) || queue.waiting.has(name));
30
+ // One validation at a time: with an async schema, an older answer landing last would leave a stale error on a newer value.
31
+ const workThrough = async (queue) => {
32
+ if (queue.isBusy)
33
+ return;
34
+ queue.isBusy = true;
35
+ try {
36
+ // A field is held back while an answer from outside the queue is out for it: that answer is for an older value, and
37
+ // landing last it would be the last word. Only that field waits, so an answer that never comes holds up no other.
38
+ const takeReady = () => [...queue.waiting].filter(([name]) => !queue.leaving.has(name));
39
+ for (let ready = takeReady(); ready.length > 0; ready = takeReady()) {
40
+ for (const [name] of ready)
41
+ queue.waiting.delete(name);
42
+ const due = ready.filter(([, isWanted]) => isWanted()).map(([name]) => name);
43
+ if (due.length > 0) {
44
+ queue.running = due;
45
+ // A resolver that throws, such as an async check whose request failed, leaves the errors as they were, and the
46
+ // batch waiting behind it still runs: one failed validation must not stop the field re-validating.
47
+ queue.answering = queue.validate?.(due).catch(() => { });
48
+ await queue.answering;
49
+ queue.running = null;
50
+ queue.answering = null;
51
+ }
52
+ }
53
+ }
54
+ finally {
55
+ queue.running = null;
56
+ queue.answering = null;
57
+ queue.isBusy = false;
58
+ }
59
+ };
60
+ /**
61
+ * Asks for fields to be validated, one validation at a time across the form. Fields asked for while one runs wait and
62
+ * go together in the next. Each is validated only if still wanted when its turn comes: the answer before it, or a
63
+ * reset, may have settled it, and validating then would put an error on a field the user is typing in or has discarded.
64
+ *
65
+ * @param queue The form's queue.
66
+ * @param names The fields to validate.
67
+ * @param isStillWanted Read for each field when its turn comes; a field asked for twice is validated if either ask still wants it.
68
+ * @param validate Validates the fields of a turn, as the form's `trigger` does. One that rejects leaves the errors as they were.
69
+ * @returns A promise that settles once the queue has nothing left it can run.
70
+ */
71
+ const runInTurn = (queue, names, isStillWanted, validate) => {
72
+ for (const name of names) {
73
+ const earlier = queue.waiting.get(name);
74
+ const wanted = () => isStillWanted(name);
75
+ queue.waiting.set(name, earlier ? () => earlier() || wanted() : wanted);
76
+ }
77
+ queue.validate = validate;
78
+ return workThrough(queue);
79
+ };
80
+ /**
81
+ * Records a validation of a field that runs outside the queue, as react-hook-form's own does when the field is left.
82
+ * A check waiting for that field is held back until it has answered, then taken up; no other field waits for it.
83
+ *
84
+ * @param queue The form's queue.
85
+ * @param name The field being validated outside the queue.
86
+ * @param answer That validation's promise. Anything else, or one that rejects, holds nothing back for longer than a moment.
87
+ */
88
+ const holdTurnsUntil = (queue, name, answer) => {
89
+ const release = () => {
90
+ if (queue.leaving.get(name) === answered)
91
+ queue.leaving.delete(name);
92
+ void workThrough(queue);
93
+ };
94
+ const answered = Promise.allSettled([queue.leaving.get(name), answer]).then(release);
95
+ queue.leaving.set(name, answered);
96
+ };
97
+ /**
98
+ * Withdraws what is waiting on a field whose value the user has just changed by typing. A check another field asked
99
+ * of it that has not begun could only raise an error mid-word, and react-hook-form drops an outside answer for the old
100
+ * value, so nothing is left to hold a check back for. A check already running is not stopped.
101
+ *
102
+ * @param queue The form's queue.
103
+ * @param name The field typed into.
104
+ */
105
+ const withdrawAsks = (queue, name) => {
106
+ queue.waiting.delete(name);
107
+ queue.leaving.delete(name);
108
+ };
109
+ /**
110
+ * Waits until no validation of the form is out: none running or waiting in the queue, and none that began outside it
111
+ * when a field was left. A submit waits for this, so no older answer lands after the submit's own validation.
112
+ *
113
+ * @param queue The form's queue.
114
+ * @returns A promise that settles once every such validation has answered; at once when none is out.
115
+ */
116
+ const whenAnswered = async (queue) => {
117
+ // Each answer may let a check that was held back begin, so it looks again until nothing is out.
118
+ while (queue.answering || queue.leaving.size > 0)
119
+ await Promise.allSettled([queue.answering, ...queue.leaving.values()]);
120
+ };
121
+
122
+ exports.holdTurnsUntil = holdTurnsUntil;
123
+ exports.isAwaitingAnswer = isAwaitingAnswer;
124
+ exports.runInTurn = runInTurn;
125
+ exports.validationQueueOf = validationQueueOf;
126
+ exports.whenAnswered = whenAnswered;
127
+ exports.withdrawAsks = withdrawAsks;
128
+ //# sourceMappingURL=validationQueue.utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validationQueue.utils.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/utilities/validationQueue.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAmBA;AACA;AACA,MAAM,MAAM,GAAG,IAAI,OAAO,EAA2B;AAErD;;;;;AAKG;AACI,MAAM,iBAAiB,GAAG,CAAC,OAAe,KAAqB;IACpE,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI;AACnC,QAAA,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,IAAI,GAAG,EAAyB;AACzC,QAAA,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,IAAI,GAAG,EAA4B;KAC7C;AACD,IAAA,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC;AAC1B,IAAA,OAAO,KAAK;AACd;AAEA;;;;;;AAMG;AACI,MAAM,gBAAgB,GAAG,CAAC,KAAsB,EAAE,IAAY,KAAc,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;AAEnJ;AACA,MAAM,WAAW,GAAG,OAAO,KAAsB,KAAI;IACnD,IAAI,KAAK,CAAC,MAAM;QAAE;AAClB,IAAA,KAAK,CAAC,MAAM,GAAG,IAAI;AACnB,IAAA,IAAI;;;AAGF,QAAA,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,C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