pixel-react 1.14.17 → 1.14.18

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 (273) hide show
  1. package/README.md +75 -75
  2. package/lib/_virtual/_commonjsHelpers.js +1 -26
  3. package/lib/_virtual/_commonjsHelpers.js.map +1 -1
  4. package/lib/_virtual/index10.js +2 -2
  5. package/lib/_virtual/index9.js +2 -2
  6. package/lib/assets/icons/spinner.svg.js +1 -1
  7. package/lib/assets/icons/spinner.svg.js.map +1 -1
  8. package/lib/components/DatePicker/DatePicker.js +1 -4
  9. package/lib/components/DatePicker/DatePicker.js.map +1 -1
  10. package/lib/index.cjs +2506 -7014
  11. package/lib/index.cjs.map +1 -1
  12. package/lib/index.d.ts +2 -1
  13. package/lib/node_modules/draft-js/lib/AtomicBlockUtils.js +1 -1
  14. package/lib/node_modules/draft-js/lib/BlockMapBuilder.js +1 -1
  15. package/lib/node_modules/draft-js/lib/BlockTree.js +1 -1
  16. package/lib/node_modules/draft-js/lib/CharacterMetadata.js +1 -1
  17. package/lib/node_modules/draft-js/lib/CompositeDraftDecorator.js +1 -1
  18. package/lib/node_modules/draft-js/lib/ContentBlock.js +1 -1
  19. package/lib/node_modules/draft-js/lib/ContentBlockNode.js +1 -1
  20. package/lib/node_modules/draft-js/lib/ContentState.js +1 -1
  21. package/lib/node_modules/draft-js/lib/ContentStateInlineStyle.js +1 -1
  22. package/lib/node_modules/draft-js/lib/DOMObserver.js +1 -1
  23. package/lib/node_modules/draft-js/lib/DefaultDraftBlockRenderMap.js +1 -1
  24. package/lib/node_modules/draft-js/lib/DraftEditorBlockNode.react.js +1 -1
  25. package/lib/node_modules/draft-js/lib/DraftEditorNode.react.js +1 -1
  26. package/lib/node_modules/draft-js/lib/DraftEntity.js +1 -1
  27. package/lib/node_modules/draft-js/lib/DraftEntityInstance.js +1 -1
  28. package/lib/node_modules/draft-js/lib/DraftModifier.js +1 -1
  29. package/lib/node_modules/draft-js/lib/DraftPasteProcessor.js +1 -1
  30. package/lib/node_modules/draft-js/lib/EditorBidiService.js +1 -1
  31. package/lib/node_modules/draft-js/lib/EditorState.js +1 -1
  32. package/lib/node_modules/draft-js/lib/SelectionState.js +1 -1
  33. package/lib/node_modules/draft-js/lib/applyEntityToContentState.js +1 -1
  34. package/lib/node_modules/draft-js/lib/convertFromHTMLToContentBlocks.js +1 -1
  35. package/lib/node_modules/draft-js/lib/convertFromRawToDraftState.js +1 -1
  36. package/lib/node_modules/draft-js/lib/createCharacterList.js +1 -1
  37. package/lib/node_modules/draft-js/lib/decodeInlineStyleRanges.js +1 -1
  38. package/lib/node_modules/draft-js/lib/insertFragmentIntoContentState.js +1 -1
  39. package/lib/node_modules/draft-js/lib/insertTextIntoContentState.js +1 -1
  40. package/lib/node_modules/draft-js/lib/modifyBlockForContentState.js +1 -1
  41. package/lib/node_modules/draft-js/lib/moveBlockInContentState.js +1 -1
  42. package/lib/node_modules/draft-js/lib/randomizeBlockMapKeys.js +1 -1
  43. package/lib/node_modules/draft-js/lib/removeRangeFromContentState.js +1 -1
  44. package/lib/node_modules/draft-js/lib/splitBlockInContentState.js +1 -1
  45. package/lib/node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js +1 -1
  46. package/lib/node_modules/{draft-js/node_modules/immutable → immutable}/dist/immutable.js +1 -1
  47. package/lib/node_modules/immutable/dist/immutable.js.map +1 -0
  48. package/lib/node_modules/js-beautify/js/src/css/index.js +1 -1
  49. package/lib/node_modules/js-beautify/js/src/css/options.js +1 -1
  50. package/lib/node_modules/js-beautify/js/src/html/beautifier.js +1 -1
  51. package/lib/node_modules/js-beautify/js/src/html/index.js +1 -1
  52. package/lib/node_modules/js-beautify/js/src/html/options.js +1 -1
  53. package/lib/node_modules/js-beautify/js/src/javascript/beautifier.js +1 -1
  54. package/lib/node_modules/js-beautify/js/src/javascript/options.js +1 -1
  55. package/lib/node_modules/libphonenumber-js/metadata.min.json.js +12 -12
  56. package/lib/node_modules/libphonenumber-js/metadata.min.json.js.map +1 -1
  57. package/lib/node_modules/prop-types/factoryWithTypeCheckers.js +1 -1
  58. package/lib/node_modules/prop-types/index.js +1 -1
  59. package/lib/node_modules/react-day-picker/dist/esm/DayPicker.js +112 -17
  60. package/lib/node_modules/react-day-picker/dist/esm/DayPicker.js.map +1 -1
  61. package/lib/node_modules/react-day-picker/dist/esm/UI.js +31 -9
  62. package/lib/node_modules/react-day-picker/dist/esm/UI.js.map +1 -1
  63. package/lib/node_modules/react-day-picker/dist/esm/classes/CalendarDay.js +9 -6
  64. package/lib/node_modules/react-day-picker/dist/esm/classes/CalendarDay.js.map +1 -1
  65. package/lib/node_modules/react-day-picker/dist/esm/classes/CalendarMonth.js +6 -1
  66. package/lib/node_modules/react-day-picker/dist/esm/classes/CalendarMonth.js.map +1 -1
  67. package/lib/node_modules/react-day-picker/dist/esm/classes/CalendarWeek.js +5 -1
  68. package/lib/node_modules/react-day-picker/dist/esm/classes/CalendarWeek.js.map +1 -1
  69. package/lib/node_modules/react-day-picker/dist/esm/classes/DateLib.js +55 -51
  70. package/lib/node_modules/react-day-picker/dist/esm/classes/DateLib.js.map +1 -1
  71. package/lib/node_modules/react-day-picker/dist/esm/components/Chevron.js +1 -1
  72. package/lib/node_modules/react-day-picker/dist/esm/components/Chevron.js.map +1 -1
  73. package/lib/node_modules/react-day-picker/dist/esm/components/Day.js +4 -4
  74. package/lib/node_modules/react-day-picker/dist/esm/components/Day.js.map +1 -1
  75. package/lib/node_modules/react-day-picker/dist/esm/components/DayButton.js +1 -1
  76. package/lib/node_modules/react-day-picker/dist/esm/components/DayButton.js.map +1 -1
  77. package/lib/node_modules/react-day-picker/dist/esm/components/Dropdown.js +1 -1
  78. package/lib/node_modules/react-day-picker/dist/esm/components/Dropdown.js.map +1 -1
  79. package/lib/node_modules/react-day-picker/dist/esm/components/DropdownNav.js +1 -1
  80. package/lib/node_modules/react-day-picker/dist/esm/components/DropdownNav.js.map +1 -1
  81. package/lib/node_modules/react-day-picker/dist/esm/components/Footer.js +1 -1
  82. package/lib/node_modules/react-day-picker/dist/esm/components/Footer.js.map +1 -1
  83. package/lib/node_modules/react-day-picker/dist/esm/components/Month.js +1 -1
  84. package/lib/node_modules/react-day-picker/dist/esm/components/Month.js.map +1 -1
  85. package/lib/node_modules/react-day-picker/dist/esm/components/MonthCaption.js +1 -1
  86. package/lib/node_modules/react-day-picker/dist/esm/components/MonthCaption.js.map +1 -1
  87. package/lib/node_modules/react-day-picker/dist/esm/components/MonthGrid.js +1 -1
  88. package/lib/node_modules/react-day-picker/dist/esm/components/MonthGrid.js.map +1 -1
  89. package/lib/node_modules/react-day-picker/dist/esm/components/Months.js +1 -1
  90. package/lib/node_modules/react-day-picker/dist/esm/components/Months.js.map +1 -1
  91. package/lib/node_modules/react-day-picker/dist/esm/components/MonthsDropdown.js +1 -1
  92. package/lib/node_modules/react-day-picker/dist/esm/components/MonthsDropdown.js.map +1 -1
  93. package/lib/node_modules/react-day-picker/dist/esm/components/Nav.js +16 -6
  94. package/lib/node_modules/react-day-picker/dist/esm/components/Nav.js.map +1 -1
  95. package/lib/node_modules/react-day-picker/dist/esm/components/NextMonthButton.js +1 -1
  96. package/lib/node_modules/react-day-picker/dist/esm/components/NextMonthButton.js.map +1 -1
  97. package/lib/node_modules/react-day-picker/dist/esm/components/Option.js +1 -1
  98. package/lib/node_modules/react-day-picker/dist/esm/components/Option.js.map +1 -1
  99. package/lib/node_modules/react-day-picker/dist/esm/components/PreviousMonthButton.js +1 -1
  100. package/lib/node_modules/react-day-picker/dist/esm/components/PreviousMonthButton.js.map +1 -1
  101. package/lib/node_modules/react-day-picker/dist/esm/components/Root.js +7 -2
  102. package/lib/node_modules/react-day-picker/dist/esm/components/Root.js.map +1 -1
  103. package/lib/node_modules/react-day-picker/dist/esm/components/Select.js +1 -1
  104. package/lib/node_modules/react-day-picker/dist/esm/components/Select.js.map +1 -1
  105. package/lib/node_modules/react-day-picker/dist/esm/components/Week.js +1 -1
  106. package/lib/node_modules/react-day-picker/dist/esm/components/Week.js.map +1 -1
  107. package/lib/node_modules/react-day-picker/dist/esm/components/WeekNumber.js +1 -1
  108. package/lib/node_modules/react-day-picker/dist/esm/components/WeekNumber.js.map +1 -1
  109. package/lib/node_modules/react-day-picker/dist/esm/components/WeekNumberHeader.js +1 -1
  110. package/lib/node_modules/react-day-picker/dist/esm/components/WeekNumberHeader.js.map +1 -1
  111. package/lib/node_modules/react-day-picker/dist/esm/components/Weekday.js +1 -1
  112. package/lib/node_modules/react-day-picker/dist/esm/components/Weekday.js.map +1 -1
  113. package/lib/node_modules/react-day-picker/dist/esm/components/Weekdays.js +1 -1
  114. package/lib/node_modules/react-day-picker/dist/esm/components/Weekdays.js.map +1 -1
  115. package/lib/node_modules/react-day-picker/dist/esm/components/Weeks.js +1 -1
  116. package/lib/node_modules/react-day-picker/dist/esm/components/Weeks.js.map +1 -1
  117. package/lib/node_modules/react-day-picker/dist/esm/components/YearsDropdown.js +1 -1
  118. package/lib/node_modules/react-day-picker/dist/esm/components/YearsDropdown.js.map +1 -1
  119. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatCaption.js +7 -2
  120. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatCaption.js.map +1 -1
  121. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatDay.js +7 -2
  122. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatDay.js.map +1 -1
  123. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatMonthDropdown.js +6 -2
  124. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatMonthDropdown.js.map +1 -1
  125. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatWeekNumber.js +11 -5
  126. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatWeekNumber.js.map +1 -1
  127. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatWeekNumberHeader.js +3 -2
  128. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatWeekNumberHeader.js.map +1 -1
  129. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatWeekdayName.js +7 -2
  130. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatWeekdayName.js.map +1 -1
  131. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatYearDropdown.js +5 -1
  132. package/lib/node_modules/react-day-picker/dist/esm/formatters/formatYearDropdown.js.map +1 -1
  133. package/lib/node_modules/react-day-picker/dist/esm/helpers/calculateFocusTarget.js +46 -19
  134. package/lib/node_modules/react-day-picker/dist/esm/helpers/calculateFocusTarget.js.map +1 -1
  135. package/lib/node_modules/react-day-picker/dist/esm/{useGetModifiers.js → helpers/createGetModifiers.js} +13 -7
  136. package/lib/node_modules/react-day-picker/dist/esm/helpers/createGetModifiers.js.map +1 -0
  137. package/lib/node_modules/react-day-picker/dist/esm/helpers/endOfBroadcastWeek.js +7 -1
  138. package/lib/node_modules/react-day-picker/dist/esm/helpers/endOfBroadcastWeek.js.map +1 -1
  139. package/lib/node_modules/react-day-picker/dist/esm/helpers/getBroadcastWeeksInMonth.js +8 -1
  140. package/lib/node_modules/react-day-picker/dist/esm/helpers/getBroadcastWeeksInMonth.js.map +1 -1
  141. package/lib/node_modules/react-day-picker/dist/esm/helpers/getClassNamesForModifiers.js +12 -0
  142. package/lib/node_modules/react-day-picker/dist/esm/helpers/getClassNamesForModifiers.js.map +1 -1
  143. package/lib/node_modules/react-day-picker/dist/esm/helpers/getComponents.js +10 -0
  144. package/lib/node_modules/react-day-picker/dist/esm/helpers/getComponents.js.map +1 -1
  145. package/lib/node_modules/react-day-picker/dist/esm/helpers/getDataAttributes.js +11 -2
  146. package/lib/node_modules/react-day-picker/dist/esm/helpers/getDataAttributes.js.map +1 -1
  147. package/lib/node_modules/react-day-picker/dist/esm/helpers/getDates.js +13 -2
  148. package/lib/node_modules/react-day-picker/dist/esm/helpers/getDates.js.map +1 -1
  149. package/lib/node_modules/react-day-picker/dist/esm/helpers/getDays.js +4 -1
  150. package/lib/node_modules/react-day-picker/dist/esm/helpers/getDays.js.map +1 -1
  151. package/lib/node_modules/react-day-picker/dist/esm/helpers/getDefaultClassNames.js +9 -2
  152. package/lib/node_modules/react-day-picker/dist/esm/helpers/getDefaultClassNames.js.map +1 -1
  153. package/lib/node_modules/react-day-picker/dist/esm/helpers/getDisplayMonths.js +10 -0
  154. package/lib/node_modules/react-day-picker/dist/esm/helpers/getDisplayMonths.js.map +1 -1
  155. package/lib/node_modules/react-day-picker/dist/esm/helpers/getFocusableDate.js +17 -2
  156. package/lib/node_modules/react-day-picker/dist/esm/helpers/getFocusableDate.js.map +1 -1
  157. package/lib/node_modules/react-day-picker/dist/esm/helpers/getFormatters.js +7 -1
  158. package/lib/node_modules/react-day-picker/dist/esm/helpers/getFormatters.js.map +1 -1
  159. package/lib/node_modules/react-day-picker/dist/esm/helpers/getInitialMonth.js +13 -3
  160. package/lib/node_modules/react-day-picker/dist/esm/helpers/getInitialMonth.js.map +1 -1
  161. package/lib/node_modules/react-day-picker/dist/esm/helpers/getMonthOptions.js +15 -1
  162. package/lib/node_modules/react-day-picker/dist/esm/helpers/getMonthOptions.js.map +1 -1
  163. package/lib/node_modules/react-day-picker/dist/esm/helpers/getMonths.js +17 -8
  164. package/lib/node_modules/react-day-picker/dist/esm/helpers/getMonths.js.map +1 -1
  165. package/lib/node_modules/react-day-picker/dist/esm/helpers/getNavMonth.js +7 -1
  166. package/lib/node_modules/react-day-picker/dist/esm/helpers/getNavMonth.js.map +1 -1
  167. package/lib/node_modules/react-day-picker/dist/esm/helpers/getNextFocus.js +20 -7
  168. package/lib/node_modules/react-day-picker/dist/esm/helpers/getNextFocus.js.map +1 -1
  169. package/lib/node_modules/react-day-picker/dist/esm/helpers/getNextMonth.js +13 -6
  170. package/lib/node_modules/react-day-picker/dist/esm/helpers/getNextMonth.js.map +1 -1
  171. package/lib/node_modules/react-day-picker/dist/esm/helpers/getPreviousMonth.js +13 -5
  172. package/lib/node_modules/react-day-picker/dist/esm/helpers/getPreviousMonth.js.map +1 -1
  173. package/lib/node_modules/react-day-picker/dist/esm/helpers/getStyleForModifiers.js +11 -0
  174. package/lib/node_modules/react-day-picker/dist/esm/helpers/getStyleForModifiers.js.map +1 -1
  175. package/lib/node_modules/react-day-picker/dist/esm/helpers/getWeekdays.js +9 -6
  176. package/lib/node_modules/react-day-picker/dist/esm/helpers/getWeekdays.js.map +1 -1
  177. package/lib/node_modules/react-day-picker/dist/esm/helpers/getWeeks.js +6 -1
  178. package/lib/node_modules/react-day-picker/dist/esm/helpers/getWeeks.js.map +1 -1
  179. package/lib/node_modules/react-day-picker/dist/esm/helpers/getYearOptions.js +13 -1
  180. package/lib/node_modules/react-day-picker/dist/esm/helpers/getYearOptions.js.map +1 -1
  181. package/lib/node_modules/react-day-picker/dist/esm/helpers/startOfBroadcastWeek.js +8 -1
  182. package/lib/node_modules/react-day-picker/dist/esm/helpers/startOfBroadcastWeek.js.map +1 -1
  183. package/lib/node_modules/react-day-picker/dist/esm/helpers/useControlledValue.js +10 -6
  184. package/lib/node_modules/react-day-picker/dist/esm/helpers/useControlledValue.js.map +1 -1
  185. package/lib/node_modules/react-day-picker/dist/esm/labels/labelDayButton.js +9 -5
  186. package/lib/node_modules/react-day-picker/dist/esm/labels/labelDayButton.js.map +1 -1
  187. package/lib/node_modules/react-day-picker/dist/esm/labels/labelGrid.js +7 -3
  188. package/lib/node_modules/react-day-picker/dist/esm/labels/labelGrid.js.map +1 -1
  189. package/lib/node_modules/react-day-picker/dist/esm/labels/labelGridcell.js +7 -3
  190. package/lib/node_modules/react-day-picker/dist/esm/labels/labelGridcell.js.map +1 -1
  191. package/lib/node_modules/react-day-picker/dist/esm/labels/labelMonthDropdown.js +3 -1
  192. package/lib/node_modules/react-day-picker/dist/esm/labels/labelMonthDropdown.js.map +1 -1
  193. package/lib/node_modules/react-day-picker/dist/esm/labels/labelNav.js +2 -1
  194. package/lib/node_modules/react-day-picker/dist/esm/labels/labelNav.js.map +1 -1
  195. package/lib/node_modules/react-day-picker/dist/esm/labels/labelNext.js +5 -3
  196. package/lib/node_modules/react-day-picker/dist/esm/labels/labelNext.js.map +1 -1
  197. package/lib/node_modules/react-day-picker/dist/esm/labels/labelPrevious.js +5 -3
  198. package/lib/node_modules/react-day-picker/dist/esm/labels/labelPrevious.js.map +1 -1
  199. package/lib/node_modules/react-day-picker/dist/esm/labels/labelWeekNumber.js +4 -1
  200. package/lib/node_modules/react-day-picker/dist/esm/labels/labelWeekNumber.js.map +1 -1
  201. package/lib/node_modules/react-day-picker/dist/esm/labels/labelWeekNumberHeader.js +3 -1
  202. package/lib/node_modules/react-day-picker/dist/esm/labels/labelWeekNumberHeader.js.map +1 -1
  203. package/lib/node_modules/react-day-picker/dist/esm/labels/labelWeekday.js +5 -1
  204. package/lib/node_modules/react-day-picker/dist/esm/labels/labelWeekday.js.map +1 -1
  205. package/lib/node_modules/react-day-picker/dist/esm/labels/labelYearDropdown.js +3 -1
  206. package/lib/node_modules/react-day-picker/dist/esm/labels/labelYearDropdown.js.map +1 -1
  207. package/lib/node_modules/react-day-picker/dist/esm/selection/useMulti.js +9 -0
  208. package/lib/node_modules/react-day-picker/dist/esm/selection/useMulti.js.map +1 -1
  209. package/lib/node_modules/react-day-picker/dist/esm/selection/useRange.js +10 -2
  210. package/lib/node_modules/react-day-picker/dist/esm/selection/useRange.js.map +1 -1
  211. package/lib/node_modules/react-day-picker/dist/esm/selection/useSingle.js +9 -0
  212. package/lib/node_modules/react-day-picker/dist/esm/selection/useSingle.js.map +1 -1
  213. package/lib/node_modules/react-day-picker/dist/esm/useAnimation.js +158 -0
  214. package/lib/node_modules/react-day-picker/dist/esm/useAnimation.js.map +1 -0
  215. package/lib/node_modules/react-day-picker/dist/esm/useCalendar.js +9 -1
  216. package/lib/node_modules/react-day-picker/dist/esm/useCalendar.js.map +1 -1
  217. package/lib/node_modules/react-day-picker/dist/esm/useDayPicker.js +4 -6
  218. package/lib/node_modules/react-day-picker/dist/esm/useDayPicker.js.map +1 -1
  219. package/lib/node_modules/react-day-picker/dist/esm/useFocus.js +14 -1
  220. package/lib/node_modules/react-day-picker/dist/esm/useFocus.js.map +1 -1
  221. package/lib/node_modules/react-day-picker/dist/esm/useSelection.js +10 -0
  222. package/lib/node_modules/react-day-picker/dist/esm/useSelection.js.map +1 -1
  223. package/lib/node_modules/react-day-picker/dist/esm/utils/addToRange.js +10 -8
  224. package/lib/node_modules/react-day-picker/dist/esm/utils/addToRange.js.map +1 -1
  225. package/lib/node_modules/react-day-picker/dist/esm/utils/dateMatchModifiers.js +5 -15
  226. package/lib/node_modules/react-day-picker/dist/esm/utils/dateMatchModifiers.js.map +1 -1
  227. package/lib/node_modules/react-day-picker/dist/esm/utils/rangeContainsDayOfWeek.js +7 -9
  228. package/lib/node_modules/react-day-picker/dist/esm/utils/rangeContainsDayOfWeek.js.map +1 -1
  229. package/lib/node_modules/react-day-picker/dist/esm/utils/rangeContainsModifiers.js +5 -14
  230. package/lib/node_modules/react-day-picker/dist/esm/utils/rangeContainsModifiers.js.map +1 -1
  231. package/lib/node_modules/react-day-picker/dist/esm/utils/rangeIncludesDate.js +7 -3
  232. package/lib/node_modules/react-day-picker/dist/esm/utils/rangeIncludesDate.js.map +1 -1
  233. package/lib/node_modules/react-day-picker/dist/esm/utils/rangeOverlaps.js +6 -2
  234. package/lib/node_modules/react-day-picker/dist/esm/utils/rangeOverlaps.js.map +1 -1
  235. package/lib/node_modules/react-day-picker/dist/esm/utils/typeguards.js +19 -6
  236. package/lib/node_modules/react-day-picker/dist/esm/utils/typeguards.js.map +1 -1
  237. package/lib/node_modules/react-draft-wysiwyg/dist/react-draft-wysiwyg.js +2 -2
  238. package/lib/node_modules/react-draft-wysiwyg/dist/react-draft-wysiwyg.js.map +1 -1
  239. package/lib/node_modules/react-hook-form/dist/index.esm.js +1203 -1151
  240. package/lib/node_modules/react-hook-form/dist/index.esm.js.map +1 -1
  241. package/lib/node_modules/{prop-types/node_modules/react-is → react-is}/cjs/react-is.development.js +1 -1
  242. package/lib/node_modules/react-is/cjs/react-is.development.js.map +1 -0
  243. package/lib/node_modules/{prop-types/node_modules/react-is → react-is}/cjs/react-is.production.min.js +1 -1
  244. package/lib/node_modules/react-is/cjs/react-is.production.min.js.map +1 -0
  245. package/lib/node_modules/{hoist-non-react-statics/node_modules/react-is → react-is}/index.js +1 -1
  246. package/lib/node_modules/react-is/index.js.map +1 -0
  247. package/lib/node_modules/webrtc-adapter/src/js/common_shim.js +1 -1
  248. package/lib/node_modules/webrtc-adapter/src/js/common_shim.js.map +1 -1
  249. package/lib/node_modules/webrtc-adapter/src/js/utils.js +6 -4
  250. package/lib/node_modules/webrtc-adapter/src/js/utils.js.map +1 -1
  251. package/lib/tsconfig.tsbuildinfo +1 -1
  252. package/package.json +106 -106
  253. package/lib/_virtual/immutable.es.js +0 -7
  254. package/lib/_virtual/immutable.es.js.map +0 -1
  255. package/lib/_virtual/index14.js +0 -4
  256. package/lib/_virtual/index14.js.map +0 -1
  257. package/lib/_virtual/react-is.development2.js +0 -4
  258. package/lib/_virtual/react-is.development2.js.map +0 -1
  259. package/lib/_virtual/react-is.production.min2.js +0 -4
  260. package/lib/_virtual/react-is.production.min2.js.map +0 -1
  261. package/lib/node_modules/draft-js/node_modules/immutable/dist/immutable.js.map +0 -1
  262. package/lib/node_modules/hoist-non-react-statics/node_modules/react-is/cjs/react-is.development.js +0 -175
  263. package/lib/node_modules/hoist-non-react-statics/node_modules/react-is/cjs/react-is.development.js.map +0 -1
  264. package/lib/node_modules/hoist-non-react-statics/node_modules/react-is/cjs/react-is.production.min.js +0 -125
  265. package/lib/node_modules/hoist-non-react-statics/node_modules/react-is/cjs/react-is.production.min.js.map +0 -1
  266. package/lib/node_modules/hoist-non-react-statics/node_modules/react-is/index.js.map +0 -1
  267. package/lib/node_modules/immutable/dist/immutable.es.js +0 -4829
  268. package/lib/node_modules/immutable/dist/immutable.es.js.map +0 -1
  269. package/lib/node_modules/prop-types/node_modules/react-is/cjs/react-is.development.js.map +0 -1
  270. package/lib/node_modules/prop-types/node_modules/react-is/cjs/react-is.production.min.js.map +0 -1
  271. package/lib/node_modules/prop-types/node_modules/react-is/index.js +0 -18
  272. package/lib/node_modules/prop-types/node_modules/react-is/index.js.map +0 -1
  273. package/lib/node_modules/react-day-picker/dist/esm/useGetModifiers.js.map +0 -1
@@ -1,3 +1,4 @@
1
+ import * as React from 'react';
1
2
  import React__default from 'react';
2
3
 
3
4
  var isCheckBoxInput = (element) => element.type === 'checkbox';
@@ -106,7 +107,6 @@ var set = (object, path, value) => {
106
107
  object[key] = newValue;
107
108
  object = object[key];
108
109
  }
109
- return object;
110
110
  };
111
111
 
112
112
  const EVENTS = {
@@ -217,42 +217,7 @@ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true)
217
217
  return result;
218
218
  };
219
219
 
220
- var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
221
-
222
- var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
223
- updateFormState(formStateData);
224
- const { name, ...formState } = formStateData;
225
- return (isEmptyObject(formState) ||
226
- Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
227
- Object.keys(formState).find((key) => _proxyFormState[key] ===
228
- (!isRoot || VALIDATION_MODE.all)));
229
- };
230
-
231
- var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
232
-
233
- var shouldSubscribeByName = (name, signalName, exact) => !name ||
234
- !signalName ||
235
- name === signalName ||
236
- convertToArrayPayload(name).some((currentName) => currentName &&
237
- (exact
238
- ? currentName === signalName
239
- : currentName.startsWith(signalName) ||
240
- signalName.startsWith(currentName)));
241
-
242
- function useSubscribe(props) {
243
- const _props = React__default.useRef(props);
244
- _props.current = props;
245
- React__default.useEffect(() => {
246
- const subscription = !props.disabled &&
247
- _props.current.subject &&
248
- _props.current.subject.subscribe({
249
- next: _props.current.next,
250
- });
251
- return () => {
252
- subscription && subscription.unsubscribe();
253
- };
254
- }, [props.disabled]);
255
- }
220
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
256
221
 
257
222
  /**
258
223
  * This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
@@ -288,7 +253,6 @@ function useFormState(props) {
288
253
  const methods = useFormContext();
289
254
  const { control = methods.control, disabled, name, exact } = props || {};
290
255
  const [formState, updateFormState] = React__default.useState(control._formState);
291
- const _mounted = React__default.useRef(true);
292
256
  const _localProxyFormState = React__default.useRef({
293
257
  isDirty: false,
294
258
  isLoading: false,
@@ -299,25 +263,20 @@ function useFormState(props) {
299
263
  isValid: false,
300
264
  errors: false,
301
265
  });
302
- const _name = React__default.useRef(name);
303
- _name.current = name;
304
- useSubscribe({
305
- disabled,
306
- next: (value) => _mounted.current &&
307
- shouldSubscribeByName(_name.current, value.name, exact) &&
308
- shouldRenderFormState(value, _localProxyFormState.current, control._updateFormState) &&
309
- updateFormState({
310
- ...control._formState,
311
- ...value,
312
- }),
313
- subject: control._subjects.state,
314
- });
266
+ useIsomorphicLayoutEffect(() => control._subscribe({
267
+ name: name,
268
+ formState: _localProxyFormState.current,
269
+ exact,
270
+ callback: (formState) => {
271
+ !disabled &&
272
+ updateFormState({
273
+ ...control._formState,
274
+ ...formState,
275
+ });
276
+ },
277
+ }), [name, disabled, exact]);
315
278
  React__default.useEffect(() => {
316
- _mounted.current = true;
317
- _localProxyFormState.current.isValid && control._updateValid(true);
318
- return () => {
319
- _mounted.current = false;
320
- };
279
+ _localProxyFormState.current.isValid && control._setValid(true);
321
280
  }, [control]);
322
281
  return React__default.useMemo(() => getProxyFormState(formState, control, _localProxyFormState.current, false), [formState, control]);
323
282
  }
@@ -355,18 +314,17 @@ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) =>
355
314
  function useWatch(props) {
356
315
  const methods = useFormContext();
357
316
  const { control = methods.control, name, defaultValue, disabled, exact, } = props || {};
358
- const _name = React__default.useRef(name);
359
- _name.current = name;
360
- useSubscribe({
361
- disabled,
362
- subject: control._subjects.values,
363
- next: (formState) => {
364
- if (shouldSubscribeByName(_name.current, formState.name, exact)) {
365
- updateValue(cloneObject(generateWatchOutput(_name.current, control._names, formState.values || control._formValues, false, defaultValue)));
366
- }
317
+ const _defaultValue = React__default.useRef(defaultValue);
318
+ const [value, updateValue] = React__default.useState(control._getWatch(name, _defaultValue.current));
319
+ useIsomorphicLayoutEffect(() => control._subscribe({
320
+ name: name,
321
+ formState: {
322
+ values: true,
367
323
  },
368
- });
369
- const [value, updateValue] = React__default.useState(control._getWatch(name, defaultValue));
324
+ exact,
325
+ callback: (formState) => !disabled &&
326
+ updateValue(generateWatchOutput(name, control._names, formState.values || control._formValues, false, _defaultValue.current)),
327
+ }), [name, control, disabled, exact]);
370
328
  React__default.useEffect(() => control._removeUnmounted());
371
329
  return value;
372
330
  }
@@ -410,6 +368,7 @@ function useController(props) {
410
368
  name,
411
369
  exact: true,
412
370
  });
371
+ const _props = React__default.useRef(props);
413
372
  const _registerProps = React__default.useRef(control.register(name, {
414
373
  ...props.rules,
415
374
  value,
@@ -437,47 +396,49 @@ function useController(props) {
437
396
  get: () => get(formState.errors, name),
438
397
  },
439
398
  }), [formState, name]);
399
+ const onChange = React__default.useCallback((event) => _registerProps.current.onChange({
400
+ target: {
401
+ value: getEventValue(event),
402
+ name: name,
403
+ },
404
+ type: EVENTS.CHANGE,
405
+ }), [name]);
406
+ const onBlur = React__default.useCallback(() => _registerProps.current.onBlur({
407
+ target: {
408
+ value: get(control._formValues, name),
409
+ name: name,
410
+ },
411
+ type: EVENTS.BLUR,
412
+ }), [name, control._formValues]);
413
+ const ref = React__default.useCallback((elm) => {
414
+ const field = get(control._fields, name);
415
+ if (field && elm) {
416
+ field._f.ref = {
417
+ focus: () => elm.focus(),
418
+ select: () => elm.select(),
419
+ setCustomValidity: (message) => elm.setCustomValidity(message),
420
+ reportValidity: () => elm.reportValidity(),
421
+ };
422
+ }
423
+ }, [control._fields, name]);
440
424
  const field = React__default.useMemo(() => ({
441
425
  name,
442
426
  value,
443
427
  ...(isBoolean(disabled) || formState.disabled
444
428
  ? { disabled: formState.disabled || disabled }
445
429
  : {}),
446
- onChange: (event) => _registerProps.current.onChange({
447
- target: {
448
- value: getEventValue(event),
449
- name: name,
450
- },
451
- type: EVENTS.CHANGE,
452
- }),
453
- onBlur: () => _registerProps.current.onBlur({
454
- target: {
455
- value: get(control._formValues, name),
456
- name: name,
457
- },
458
- type: EVENTS.BLUR,
459
- }),
460
- ref: (elm) => {
461
- const field = get(control._fields, name);
462
- if (field && elm) {
463
- field._f.ref = {
464
- focus: () => elm.focus(),
465
- select: () => elm.select(),
466
- setCustomValidity: (message) => elm.setCustomValidity(message),
467
- reportValidity: () => elm.reportValidity(),
468
- };
469
- }
470
- },
471
- }), [
472
- name,
473
- control._formValues,
474
- disabled,
475
- formState.disabled,
476
- value,
477
- control._fields,
478
- ]);
430
+ onChange,
431
+ onBlur,
432
+ ref,
433
+ }), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
479
434
  React__default.useEffect(() => {
480
435
  const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
436
+ control.register(name, {
437
+ ..._props.current.rules,
438
+ ...(isBoolean(_props.current.disabled)
439
+ ? { disabled: _props.current.disabled }
440
+ : {}),
441
+ });
481
442
  const updateMounted = (name, value) => {
482
443
  const field = get(control._fields, name);
483
444
  if (field && field._f) {
@@ -502,9 +463,8 @@ function useController(props) {
502
463
  };
503
464
  }, [name, control, isArrayField, shouldUnregister]);
504
465
  React__default.useEffect(() => {
505
- control._updateDisabledField({
466
+ control._setDisabledField({
506
467
  disabled,
507
- fields: control._fields,
508
468
  name,
509
469
  });
510
470
  }, [disabled, name, control]);
@@ -684,67 +644,70 @@ var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => va
684
644
  }
685
645
  : {};
686
646
 
687
- var generateId = () => {
688
- const d = typeof performance === 'undefined' ? Date.now() : performance.now() * 1000;
689
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
690
- const r = (Math.random() * 16 + d) % 16 | 0;
691
- return (c == 'x' ? r : (r & 0x3) | 0x8).toString(16);
692
- });
693
- };
694
-
695
- var getFocusFieldName = (name, index, options = {}) => options.shouldFocus || isUndefined(options.shouldFocus)
696
- ? options.focusName ||
697
- `${name}.${isUndefined(options.focusIndex) ? index : options.focusIndex}.`
698
- : '';
647
+ var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
699
648
 
700
- var getValidationModes = (mode) => ({
701
- isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
702
- isOnBlur: mode === VALIDATION_MODE.onBlur,
703
- isOnChange: mode === VALIDATION_MODE.onChange,
704
- isOnAll: mode === VALIDATION_MODE.all,
705
- isOnTouch: mode === VALIDATION_MODE.onTouched,
706
- });
649
+ var createSubject = () => {
650
+ let _observers = [];
651
+ const next = (value) => {
652
+ for (const observer of _observers) {
653
+ observer.next && observer.next(value);
654
+ }
655
+ };
656
+ const subscribe = (observer) => {
657
+ _observers.push(observer);
658
+ return {
659
+ unsubscribe: () => {
660
+ _observers = _observers.filter((o) => o !== observer);
661
+ },
662
+ };
663
+ };
664
+ const unsubscribe = () => {
665
+ _observers = [];
666
+ };
667
+ return {
668
+ get observers() {
669
+ return _observers;
670
+ },
671
+ next,
672
+ subscribe,
673
+ unsubscribe,
674
+ };
675
+ };
707
676
 
708
- var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
709
- (_names.watchAll ||
710
- _names.watch.has(name) ||
711
- [..._names.watch].some((watchName) => name.startsWith(watchName) &&
712
- /^\.\w+/.test(name.slice(watchName.length))));
677
+ var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
713
678
 
714
- const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
715
- for (const key of fieldsNames || Object.keys(fields)) {
716
- const field = get(fields, key);
717
- if (field) {
718
- const { _f, ...currentField } = field;
719
- if (_f) {
720
- if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
721
- return true;
722
- }
723
- else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
724
- return true;
725
- }
726
- else {
727
- if (iterateFieldsByAction(currentField, action)) {
728
- break;
729
- }
730
- }
731
- }
732
- else if (isObject(currentField)) {
733
- if (iterateFieldsByAction(currentField, action)) {
734
- break;
735
- }
679
+ function deepEqual(object1, object2) {
680
+ if (isPrimitive(object1) || isPrimitive(object2)) {
681
+ return object1 === object2;
682
+ }
683
+ if (isDateObject(object1) && isDateObject(object2)) {
684
+ return object1.getTime() === object2.getTime();
685
+ }
686
+ const keys1 = Object.keys(object1);
687
+ const keys2 = Object.keys(object2);
688
+ if (keys1.length !== keys2.length) {
689
+ return false;
690
+ }
691
+ for (const key of keys1) {
692
+ const val1 = object1[key];
693
+ if (!keys2.includes(key)) {
694
+ return false;
695
+ }
696
+ if (key !== 'ref') {
697
+ const val2 = object2[key];
698
+ if ((isDateObject(val1) && isDateObject(val2)) ||
699
+ (isObject(val1) && isObject(val2)) ||
700
+ (Array.isArray(val1) && Array.isArray(val2))
701
+ ? !deepEqual(val1, val2)
702
+ : val1 !== val2) {
703
+ return false;
736
704
  }
737
705
  }
738
706
  }
739
- return;
740
- };
707
+ return true;
708
+ }
741
709
 
742
- var updateFieldArrayRootError = (errors, error, name) => {
743
- const fieldArrayErrors = convertToArrayPayload(get(errors, name));
744
- set(fieldArrayErrors, 'root', error[name]);
745
- set(errors, name, fieldArrayErrors);
746
- return errors;
747
- };
710
+ var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
748
711
 
749
712
  var isFileInput = (element) => element.type === 'file';
750
713
 
@@ -759,806 +722,526 @@ var isHTMLElement = (value) => {
759
722
  (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement));
760
723
  };
761
724
 
762
- var isMessage = (value) => isString(value);
725
+ var isMultipleSelect = (element) => element.type === `select-multiple`;
763
726
 
764
727
  var isRadioInput = (element) => element.type === 'radio';
765
728
 
766
- var isRegex = (value) => value instanceof RegExp;
729
+ var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
767
730
 
768
- const defaultResult = {
769
- value: false,
770
- isValid: false,
771
- };
772
- const validResult = { value: true, isValid: true };
773
- var getCheckboxValue = (options) => {
774
- if (Array.isArray(options)) {
775
- if (options.length > 1) {
776
- const values = options
777
- .filter((option) => option && option.checked && !option.disabled)
778
- .map((option) => option.value);
779
- return { value: values, isValid: !!values.length };
780
- }
781
- return options[0].checked && !options[0].disabled
782
- ? // @ts-expect-error expected to work in the browser
783
- options[0].attributes && !isUndefined(options[0].attributes.value)
784
- ? isUndefined(options[0].value) || options[0].value === ''
785
- ? validResult
786
- : { value: options[0].value, isValid: true }
787
- : validResult
788
- : defaultResult;
789
- }
790
- return defaultResult;
791
- };
731
+ var live = (ref) => isHTMLElement(ref) && ref.isConnected;
792
732
 
793
- const defaultReturn = {
794
- isValid: false,
795
- value: null,
796
- };
797
- var getRadioValue = (options) => Array.isArray(options)
798
- ? options.reduce((previous, option) => option && option.checked && !option.disabled
799
- ? {
800
- isValid: true,
801
- value: option.value,
733
+ function baseGet(object, updatePath) {
734
+ const length = updatePath.slice(0, -1).length;
735
+ let index = 0;
736
+ while (index < length) {
737
+ object = isUndefined(object) ? index++ : object[updatePath[index++]];
738
+ }
739
+ return object;
740
+ }
741
+ function isEmptyArray(obj) {
742
+ for (const key in obj) {
743
+ if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
744
+ return false;
802
745
  }
803
- : previous, defaultReturn)
804
- : defaultReturn;
805
-
806
- function getValidateError(result, ref, type = 'validate') {
807
- if (isMessage(result) ||
808
- (Array.isArray(result) && result.every(isMessage)) ||
809
- (isBoolean(result) && !result)) {
810
- return {
811
- type,
812
- message: isMessage(result) ? result : '',
813
- ref,
814
- };
815
746
  }
747
+ return true;
816
748
  }
817
-
818
- var getValueAndMessage = (validationData) => isObject(validationData) && !isRegex(validationData)
819
- ? validationData
820
- : {
821
- value: validationData,
822
- message: '',
823
- };
824
-
825
- var validateField = async (field, disabledFieldNames, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
826
- const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, } = field._f;
827
- const inputValue = get(formValues, name);
828
- if (!mount || disabledFieldNames.has(name)) {
829
- return {};
749
+ function unset(object, path) {
750
+ const paths = Array.isArray(path)
751
+ ? path
752
+ : isKey(path)
753
+ ? [path]
754
+ : stringToPath(path);
755
+ const childObject = paths.length === 1 ? object : baseGet(object, paths);
756
+ const index = paths.length - 1;
757
+ const key = paths[index];
758
+ if (childObject) {
759
+ delete childObject[key];
830
760
  }
831
- const inputRef = refs ? refs[0] : ref;
832
- const setCustomValidity = (message) => {
833
- if (shouldUseNativeValidation && inputRef.reportValidity) {
834
- inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
835
- inputRef.reportValidity();
836
- }
837
- };
838
- const error = {};
839
- const isRadio = isRadioInput(ref);
840
- const isCheckBox = isCheckBoxInput(ref);
841
- const isRadioOrCheckbox = isRadio || isCheckBox;
842
- const isEmpty = ((valueAsNumber || isFileInput(ref)) &&
843
- isUndefined(ref.value) &&
844
- isUndefined(inputValue)) ||
845
- (isHTMLElement(ref) && ref.value === '') ||
846
- inputValue === '' ||
847
- (Array.isArray(inputValue) && !inputValue.length);
848
- const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
849
- const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
850
- const message = exceedMax ? maxLengthMessage : minLengthMessage;
851
- error[name] = {
852
- type: exceedMax ? maxType : minType,
853
- message,
854
- ref,
855
- ...appendErrorsCurry(exceedMax ? maxType : minType, message),
856
- };
857
- };
858
- if (isFieldArray
859
- ? !Array.isArray(inputValue) || !inputValue.length
860
- : required &&
861
- ((!isRadioOrCheckbox && (isEmpty || isNullOrUndefined(inputValue))) ||
862
- (isBoolean(inputValue) && !inputValue) ||
863
- (isCheckBox && !getCheckboxValue(refs).isValid) ||
864
- (isRadio && !getRadioValue(refs).isValid))) {
865
- const { value, message } = isMessage(required)
866
- ? { value: !!required, message: required }
867
- : getValueAndMessage(required);
868
- if (value) {
869
- error[name] = {
870
- type: INPUT_VALIDATION_RULES.required,
871
- message,
872
- ref: inputRef,
873
- ...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message),
874
- };
875
- if (!validateAllFieldCriteria) {
876
- setCustomValidity(message);
877
- return error;
878
- }
879
- }
761
+ if (index !== 0 &&
762
+ ((isObject(childObject) && isEmptyObject(childObject)) ||
763
+ (Array.isArray(childObject) && isEmptyArray(childObject)))) {
764
+ unset(object, paths.slice(0, -1));
880
765
  }
881
- if (!isEmpty && (!isNullOrUndefined(min) || !isNullOrUndefined(max))) {
882
- let exceedMax;
883
- let exceedMin;
884
- const maxOutput = getValueAndMessage(max);
885
- const minOutput = getValueAndMessage(min);
886
- if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
887
- const valueNumber = ref.valueAsNumber ||
888
- (inputValue ? +inputValue : inputValue);
889
- if (!isNullOrUndefined(maxOutput.value)) {
890
- exceedMax = valueNumber > maxOutput.value;
891
- }
892
- if (!isNullOrUndefined(minOutput.value)) {
893
- exceedMin = valueNumber < minOutput.value;
894
- }
895
- }
896
- else {
897
- const valueDate = ref.valueAsDate || new Date(inputValue);
898
- const convertTimeToDate = (time) => new Date(new Date().toDateString() + ' ' + time);
899
- const isTime = ref.type == 'time';
900
- const isWeek = ref.type == 'week';
901
- if (isString(maxOutput.value) && inputValue) {
902
- exceedMax = isTime
903
- ? convertTimeToDate(inputValue) > convertTimeToDate(maxOutput.value)
904
- : isWeek
905
- ? inputValue > maxOutput.value
906
- : valueDate > new Date(maxOutput.value);
907
- }
908
- if (isString(minOutput.value) && inputValue) {
909
- exceedMin = isTime
910
- ? convertTimeToDate(inputValue) < convertTimeToDate(minOutput.value)
911
- : isWeek
912
- ? inputValue < minOutput.value
913
- : valueDate < new Date(minOutput.value);
914
- }
915
- }
916
- if (exceedMax || exceedMin) {
917
- getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
918
- if (!validateAllFieldCriteria) {
919
- setCustomValidity(error[name].message);
920
- return error;
921
- }
766
+ return object;
767
+ }
768
+
769
+ var objectHasFunction = (data) => {
770
+ for (const key in data) {
771
+ if (isFunction(data[key])) {
772
+ return true;
922
773
  }
923
774
  }
924
- if ((maxLength || minLength) &&
925
- !isEmpty &&
926
- (isString(inputValue) || (isFieldArray && Array.isArray(inputValue)))) {
927
- const maxLengthOutput = getValueAndMessage(maxLength);
928
- const minLengthOutput = getValueAndMessage(minLength);
929
- const exceedMax = !isNullOrUndefined(maxLengthOutput.value) &&
930
- inputValue.length > +maxLengthOutput.value;
931
- const exceedMin = !isNullOrUndefined(minLengthOutput.value) &&
932
- inputValue.length < +minLengthOutput.value;
933
- if (exceedMax || exceedMin) {
934
- getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
935
- if (!validateAllFieldCriteria) {
936
- setCustomValidity(error[name].message);
937
- return error;
775
+ return false;
776
+ };
777
+
778
+ function markFieldsDirty(data, fields = {}) {
779
+ const isParentNodeArray = Array.isArray(data);
780
+ if (isObject(data) || isParentNodeArray) {
781
+ for (const key in data) {
782
+ if (Array.isArray(data[key]) ||
783
+ (isObject(data[key]) && !objectHasFunction(data[key]))) {
784
+ fields[key] = Array.isArray(data[key]) ? [] : {};
785
+ markFieldsDirty(data[key], fields[key]);
938
786
  }
939
- }
940
- }
941
- if (pattern && !isEmpty && isString(inputValue)) {
942
- const { value: patternValue, message } = getValueAndMessage(pattern);
943
- if (isRegex(patternValue) && !inputValue.match(patternValue)) {
944
- error[name] = {
945
- type: INPUT_VALIDATION_RULES.pattern,
946
- message,
947
- ref,
948
- ...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message),
949
- };
950
- if (!validateAllFieldCriteria) {
951
- setCustomValidity(message);
952
- return error;
787
+ else if (!isNullOrUndefined(data[key])) {
788
+ fields[key] = true;
953
789
  }
954
790
  }
955
791
  }
956
- if (validate) {
957
- if (isFunction(validate)) {
958
- const result = await validate(inputValue, formValues);
959
- const validateError = getValidateError(result, inputRef);
960
- if (validateError) {
961
- error[name] = {
962
- ...validateError,
963
- ...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message),
964
- };
965
- if (!validateAllFieldCriteria) {
966
- setCustomValidity(validateError.message);
967
- return error;
968
- }
969
- }
970
- }
971
- else if (isObject(validate)) {
972
- let validationResult = {};
973
- for (const key in validate) {
974
- if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
975
- break;
792
+ return fields;
793
+ }
794
+ function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues) {
795
+ const isParentNodeArray = Array.isArray(data);
796
+ if (isObject(data) || isParentNodeArray) {
797
+ for (const key in data) {
798
+ if (Array.isArray(data[key]) ||
799
+ (isObject(data[key]) && !objectHasFunction(data[key]))) {
800
+ if (isUndefined(formValues) ||
801
+ isPrimitive(dirtyFieldsFromValues[key])) {
802
+ dirtyFieldsFromValues[key] = Array.isArray(data[key])
803
+ ? markFieldsDirty(data[key], [])
804
+ : { ...markFieldsDirty(data[key]) };
976
805
  }
977
- const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
978
- if (validateError) {
979
- validationResult = {
980
- ...validateError,
981
- ...appendErrorsCurry(key, validateError.message),
982
- };
983
- setCustomValidity(validateError.message);
984
- if (validateAllFieldCriteria) {
985
- error[name] = validationResult;
986
- }
806
+ else {
807
+ getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
987
808
  }
988
809
  }
989
- if (!isEmptyObject(validationResult)) {
990
- error[name] = {
991
- ref: inputRef,
992
- ...validationResult,
993
- };
994
- if (!validateAllFieldCriteria) {
995
- return error;
996
- }
810
+ else {
811
+ dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
997
812
  }
998
813
  }
999
814
  }
1000
- setCustomValidity(true);
1001
- return error;
1002
- };
1003
-
1004
- var appendAt = (data, value) => [
1005
- ...data,
1006
- ...convertToArrayPayload(value),
1007
- ];
1008
-
1009
- var fillEmptyArray = (value) => Array.isArray(value) ? value.map(() => undefined) : undefined;
1010
-
1011
- function insert(data, index, value) {
1012
- return [
1013
- ...data.slice(0, index),
1014
- ...convertToArrayPayload(value),
1015
- ...data.slice(index),
1016
- ];
815
+ return dirtyFieldsFromValues;
1017
816
  }
817
+ var getDirtyFields = (defaultValues, formValues) => getDirtyFieldsFromDefaultValues(defaultValues, formValues, markFieldsDirty(formValues));
1018
818
 
1019
- var moveArrayAt = (data, from, to) => {
1020
- if (!Array.isArray(data)) {
1021
- return [];
1022
- }
1023
- if (isUndefined(data[to])) {
1024
- data[to] = undefined;
819
+ const defaultResult = {
820
+ value: false,
821
+ isValid: false,
822
+ };
823
+ const validResult = { value: true, isValid: true };
824
+ var getCheckboxValue = (options) => {
825
+ if (Array.isArray(options)) {
826
+ if (options.length > 1) {
827
+ const values = options
828
+ .filter((option) => option && option.checked && !option.disabled)
829
+ .map((option) => option.value);
830
+ return { value: values, isValid: !!values.length };
831
+ }
832
+ return options[0].checked && !options[0].disabled
833
+ ? // @ts-expect-error expected to work in the browser
834
+ options[0].attributes && !isUndefined(options[0].attributes.value)
835
+ ? isUndefined(options[0].value) || options[0].value === ''
836
+ ? validResult
837
+ : { value: options[0].value, isValid: true }
838
+ : validResult
839
+ : defaultResult;
1025
840
  }
1026
- data.splice(to, 0, data.splice(from, 1)[0]);
1027
- return data;
841
+ return defaultResult;
1028
842
  };
1029
843
 
1030
- var prependAt = (data, value) => [
1031
- ...convertToArrayPayload(value),
1032
- ...convertToArrayPayload(data),
1033
- ];
1034
-
1035
- function removeAtIndexes(data, indexes) {
1036
- let i = 0;
1037
- const temp = [...data];
1038
- for (const index of indexes) {
1039
- temp.splice(index - i, 1);
1040
- i++;
1041
- }
1042
- return compact(temp).length ? temp : [];
1043
- }
1044
- var removeArrayAt = (data, index) => isUndefined(index)
1045
- ? []
1046
- : removeAtIndexes(data, convertToArrayPayload(index).sort((a, b) => a - b));
844
+ var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value)
845
+ ? value
846
+ : valueAsNumber
847
+ ? value === ''
848
+ ? NaN
849
+ : value
850
+ ? +value
851
+ : value
852
+ : valueAsDate && isString(value)
853
+ ? new Date(value)
854
+ : setValueAs
855
+ ? setValueAs(value)
856
+ : value;
1047
857
 
1048
- var swapArrayAt = (data, indexA, indexB) => {
1049
- [data[indexA], data[indexB]] = [data[indexB], data[indexA]];
858
+ const defaultReturn = {
859
+ isValid: false,
860
+ value: null,
1050
861
  };
862
+ var getRadioValue = (options) => Array.isArray(options)
863
+ ? options.reduce((previous, option) => option && option.checked && !option.disabled
864
+ ? {
865
+ isValid: true,
866
+ value: option.value,
867
+ }
868
+ : previous, defaultReturn)
869
+ : defaultReturn;
1051
870
 
1052
- function baseGet(object, updatePath) {
1053
- const length = updatePath.slice(0, -1).length;
1054
- let index = 0;
1055
- while (index < length) {
1056
- object = isUndefined(object) ? index++ : object[updatePath[index++]];
871
+ function getFieldValue(_f) {
872
+ const ref = _f.ref;
873
+ if (isFileInput(ref)) {
874
+ return ref.files;
1057
875
  }
1058
- return object;
1059
- }
1060
- function isEmptyArray(obj) {
1061
- for (const key in obj) {
1062
- if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
1063
- return false;
1064
- }
876
+ if (isRadioInput(ref)) {
877
+ return getRadioValue(_f.refs).value;
1065
878
  }
1066
- return true;
1067
- }
1068
- function unset(object, path) {
1069
- const paths = Array.isArray(path)
1070
- ? path
1071
- : isKey(path)
1072
- ? [path]
1073
- : stringToPath(path);
1074
- const childObject = paths.length === 1 ? object : baseGet(object, paths);
1075
- const index = paths.length - 1;
1076
- const key = paths[index];
1077
- if (childObject) {
1078
- delete childObject[key];
879
+ if (isMultipleSelect(ref)) {
880
+ return [...ref.selectedOptions].map(({ value }) => value);
1079
881
  }
1080
- if (index !== 0 &&
1081
- ((isObject(childObject) && isEmptyObject(childObject)) ||
1082
- (Array.isArray(childObject) && isEmptyArray(childObject)))) {
1083
- unset(object, paths.slice(0, -1));
882
+ if (isCheckBoxInput(ref)) {
883
+ return getCheckboxValue(_f.refs).value;
1084
884
  }
1085
- return object;
885
+ return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
1086
886
  }
1087
887
 
1088
- var updateAt = (fieldValues, index, value) => {
1089
- fieldValues[index] = value;
1090
- return fieldValues;
888
+ var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
889
+ const fields = {};
890
+ for (const name of fieldsNames) {
891
+ const field = get(_fields, name);
892
+ field && set(fields, name, field._f);
893
+ }
894
+ return {
895
+ criteriaMode,
896
+ names: [...fieldsNames],
897
+ fields,
898
+ shouldUseNativeValidation,
899
+ };
1091
900
  };
1092
901
 
1093
- /**
1094
- * A custom hook that exposes convenient methods to perform operations with a list of dynamic inputs that need to be appended, updated, removed etc. • [Demo](https://codesandbox.io/s/react-hook-form-usefieldarray-ssugn) • [Video](https://youtu.be/4MrbfGSFY2A)
1095
- *
1096
- * @remarks
1097
- * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/react-hook-form-usefieldarray-ssugn)
1098
- *
1099
- * @param props - useFieldArray props
1100
- *
1101
- * @returns methods - functions to manipulate with the Field Arrays (dynamic inputs) {@link UseFieldArrayReturn}
1102
- *
1103
- * @example
1104
- * ```tsx
1105
- * function App() {
1106
- * const { register, control, handleSubmit, reset, trigger, setError } = useForm({
1107
- * defaultValues: {
1108
- * test: []
1109
- * }
1110
- * });
1111
- * const { fields, append } = useFieldArray({
1112
- * control,
1113
- * name: "test"
1114
- * });
1115
- *
1116
- * return (
1117
- * <form onSubmit={handleSubmit(data => console.log(data))}>
1118
- * {fields.map((item, index) => (
1119
- * <input key={item.id} {...register(`test.${index}.firstName`)} />
1120
- * ))}
1121
- * <button type="button" onClick={() => append({ firstName: "bill" })}>
1122
- * append
1123
- * </button>
1124
- * <input type="submit" />
1125
- * </form>
1126
- * );
1127
- * }
1128
- * ```
1129
- */
1130
- function useFieldArray(props) {
1131
- const methods = useFormContext();
1132
- const { control = methods.control, name, keyName = 'id', shouldUnregister, rules, } = props;
1133
- const [fields, setFields] = React__default.useState(control._getFieldArray(name));
1134
- const ids = React__default.useRef(control._getFieldArray(name).map(generateId));
1135
- const _fieldIds = React__default.useRef(fields);
1136
- const _name = React__default.useRef(name);
1137
- const _actioned = React__default.useRef(false);
1138
- _name.current = name;
1139
- _fieldIds.current = fields;
1140
- control._names.array.add(name);
1141
- rules &&
1142
- control.register(name, rules);
1143
- useSubscribe({
1144
- next: ({ values, name: fieldArrayName, }) => {
1145
- if (fieldArrayName === _name.current || !fieldArrayName) {
1146
- const fieldValues = get(values, _name.current);
1147
- if (Array.isArray(fieldValues)) {
1148
- setFields(fieldValues);
1149
- ids.current = fieldValues.map(generateId);
902
+ var isRegex = (value) => value instanceof RegExp;
903
+
904
+ var getRuleValue = (rule) => isUndefined(rule)
905
+ ? rule
906
+ : isRegex(rule)
907
+ ? rule.source
908
+ : isObject(rule)
909
+ ? isRegex(rule.value)
910
+ ? rule.value.source
911
+ : rule.value
912
+ : rule;
913
+
914
+ var getValidationModes = (mode) => ({
915
+ isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
916
+ isOnBlur: mode === VALIDATION_MODE.onBlur,
917
+ isOnChange: mode === VALIDATION_MODE.onChange,
918
+ isOnAll: mode === VALIDATION_MODE.all,
919
+ isOnTouch: mode === VALIDATION_MODE.onTouched,
920
+ });
921
+
922
+ const ASYNC_FUNCTION = 'AsyncFunction';
923
+ var hasPromiseValidation = (fieldReference) => !!fieldReference &&
924
+ !!fieldReference.validate &&
925
+ !!((isFunction(fieldReference.validate) &&
926
+ fieldReference.validate.constructor.name === ASYNC_FUNCTION) ||
927
+ (isObject(fieldReference.validate) &&
928
+ Object.values(fieldReference.validate).find((validateFunction) => validateFunction.constructor.name === ASYNC_FUNCTION)));
929
+
930
+ var hasValidation = (options) => options.mount &&
931
+ (options.required ||
932
+ options.min ||
933
+ options.max ||
934
+ options.maxLength ||
935
+ options.minLength ||
936
+ options.pattern ||
937
+ options.validate);
938
+
939
+ var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
940
+ (_names.watchAll ||
941
+ _names.watch.has(name) ||
942
+ [..._names.watch].some((watchName) => name.startsWith(watchName) &&
943
+ /^\.\w+/.test(name.slice(watchName.length))));
944
+
945
+ const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
946
+ for (const key of fieldsNames || Object.keys(fields)) {
947
+ const field = get(fields, key);
948
+ if (field) {
949
+ const { _f, ...currentField } = field;
950
+ if (_f) {
951
+ if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
952
+ return true;
953
+ }
954
+ else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
955
+ return true;
956
+ }
957
+ else {
958
+ if (iterateFieldsByAction(currentField, action)) {
959
+ break;
960
+ }
1150
961
  }
1151
962
  }
1152
- },
1153
- subject: control._subjects.array,
1154
- });
1155
- const updateValues = React__default.useCallback((updatedFieldArrayValues) => {
1156
- _actioned.current = true;
1157
- control._updateFieldArray(name, updatedFieldArrayValues);
1158
- }, [control, name]);
1159
- const append = (value, options) => {
1160
- const appendValue = convertToArrayPayload(cloneObject(value));
1161
- const updatedFieldArrayValues = appendAt(control._getFieldArray(name), appendValue);
1162
- control._names.focus = getFocusFieldName(name, updatedFieldArrayValues.length - 1, options);
1163
- ids.current = appendAt(ids.current, appendValue.map(generateId));
1164
- updateValues(updatedFieldArrayValues);
1165
- setFields(updatedFieldArrayValues);
1166
- control._updateFieldArray(name, updatedFieldArrayValues, appendAt, {
1167
- argA: fillEmptyArray(value),
1168
- });
1169
- };
1170
- const prepend = (value, options) => {
1171
- const prependValue = convertToArrayPayload(cloneObject(value));
1172
- const updatedFieldArrayValues = prependAt(control._getFieldArray(name), prependValue);
1173
- control._names.focus = getFocusFieldName(name, 0, options);
1174
- ids.current = prependAt(ids.current, prependValue.map(generateId));
1175
- updateValues(updatedFieldArrayValues);
1176
- setFields(updatedFieldArrayValues);
1177
- control._updateFieldArray(name, updatedFieldArrayValues, prependAt, {
1178
- argA: fillEmptyArray(value),
1179
- });
1180
- };
1181
- const remove = (index) => {
1182
- const updatedFieldArrayValues = removeArrayAt(control._getFieldArray(name), index);
1183
- ids.current = removeArrayAt(ids.current, index);
1184
- updateValues(updatedFieldArrayValues);
1185
- setFields(updatedFieldArrayValues);
1186
- !Array.isArray(get(control._fields, name)) &&
1187
- set(control._fields, name, undefined);
1188
- control._updateFieldArray(name, updatedFieldArrayValues, removeArrayAt, {
1189
- argA: index,
1190
- });
1191
- };
1192
- const insert$1 = (index, value, options) => {
1193
- const insertValue = convertToArrayPayload(cloneObject(value));
1194
- const updatedFieldArrayValues = insert(control._getFieldArray(name), index, insertValue);
1195
- control._names.focus = getFocusFieldName(name, index, options);
1196
- ids.current = insert(ids.current, index, insertValue.map(generateId));
1197
- updateValues(updatedFieldArrayValues);
1198
- setFields(updatedFieldArrayValues);
1199
- control._updateFieldArray(name, updatedFieldArrayValues, insert, {
1200
- argA: index,
1201
- argB: fillEmptyArray(value),
1202
- });
1203
- };
1204
- const swap = (indexA, indexB) => {
1205
- const updatedFieldArrayValues = control._getFieldArray(name);
1206
- swapArrayAt(updatedFieldArrayValues, indexA, indexB);
1207
- swapArrayAt(ids.current, indexA, indexB);
1208
- updateValues(updatedFieldArrayValues);
1209
- setFields(updatedFieldArrayValues);
1210
- control._updateFieldArray(name, updatedFieldArrayValues, swapArrayAt, {
1211
- argA: indexA,
1212
- argB: indexB,
1213
- }, false);
1214
- };
1215
- const move = (from, to) => {
1216
- const updatedFieldArrayValues = control._getFieldArray(name);
1217
- moveArrayAt(updatedFieldArrayValues, from, to);
1218
- moveArrayAt(ids.current, from, to);
1219
- updateValues(updatedFieldArrayValues);
1220
- setFields(updatedFieldArrayValues);
1221
- control._updateFieldArray(name, updatedFieldArrayValues, moveArrayAt, {
1222
- argA: from,
1223
- argB: to,
1224
- }, false);
1225
- };
1226
- const update = (index, value) => {
1227
- const updateValue = cloneObject(value);
1228
- const updatedFieldArrayValues = updateAt(control._getFieldArray(name), index, updateValue);
1229
- ids.current = [...updatedFieldArrayValues].map((item, i) => !item || i === index ? generateId() : ids.current[i]);
1230
- updateValues(updatedFieldArrayValues);
1231
- setFields([...updatedFieldArrayValues]);
1232
- control._updateFieldArray(name, updatedFieldArrayValues, updateAt, {
1233
- argA: index,
1234
- argB: updateValue,
1235
- }, true, false);
1236
- };
1237
- const replace = (value) => {
1238
- const updatedFieldArrayValues = convertToArrayPayload(cloneObject(value));
1239
- ids.current = updatedFieldArrayValues.map(generateId);
1240
- updateValues([...updatedFieldArrayValues]);
1241
- setFields([...updatedFieldArrayValues]);
1242
- control._updateFieldArray(name, [...updatedFieldArrayValues], (data) => data, {}, true, false);
1243
- };
1244
- React__default.useEffect(() => {
1245
- control._state.action = false;
1246
- isWatched(name, control._names) &&
1247
- control._subjects.state.next({
1248
- ...control._formState,
1249
- });
1250
- if (_actioned.current &&
1251
- (!getValidationModes(control._options.mode).isOnSubmit ||
1252
- control._formState.isSubmitted)) {
1253
- if (control._options.resolver) {
1254
- control._executeSchema([name]).then((result) => {
1255
- const error = get(result.errors, name);
1256
- const existingError = get(control._formState.errors, name);
1257
- if (existingError
1258
- ? (!error && existingError.type) ||
1259
- (error &&
1260
- (existingError.type !== error.type ||
1261
- existingError.message !== error.message))
1262
- : error && error.type) {
1263
- error
1264
- ? set(control._formState.errors, name, error)
1265
- : unset(control._formState.errors, name);
1266
- control._subjects.state.next({
1267
- errors: control._formState.errors,
1268
- });
1269
- }
1270
- });
1271
- }
1272
- else {
1273
- const field = get(control._fields, name);
1274
- if (field &&
1275
- field._f &&
1276
- !(getValidationModes(control._options.reValidateMode).isOnSubmit &&
1277
- getValidationModes(control._options.mode).isOnSubmit)) {
1278
- validateField(field, control._names.disabled, control._formValues, control._options.criteriaMode === VALIDATION_MODE.all, control._options.shouldUseNativeValidation, true).then((error) => !isEmptyObject(error) &&
1279
- control._subjects.state.next({
1280
- errors: updateFieldArrayRootError(control._formState.errors, error, name),
1281
- }));
1282
- }
1283
- }
1284
- }
1285
- control._subjects.values.next({
1286
- name,
1287
- values: { ...control._formValues },
1288
- });
1289
- control._names.focus &&
1290
- iterateFieldsByAction(control._fields, (ref, key) => {
1291
- if (control._names.focus &&
1292
- key.startsWith(control._names.focus) &&
1293
- ref.focus) {
1294
- ref.focus();
1295
- return 1;
1296
- }
1297
- return;
1298
- });
1299
- control._names.focus = '';
1300
- control._updateValid();
1301
- _actioned.current = false;
1302
- }, [fields, name, control]);
1303
- React__default.useEffect(() => {
1304
- !get(control._formValues, name) && control._updateFieldArray(name);
1305
- return () => {
1306
- (control._options.shouldUnregister || shouldUnregister) &&
1307
- control.unregister(name);
1308
- };
1309
- }, [name, control, keyName, shouldUnregister]);
1310
- return {
1311
- swap: React__default.useCallback(swap, [updateValues, name, control]),
1312
- move: React__default.useCallback(move, [updateValues, name, control]),
1313
- prepend: React__default.useCallback(prepend, [updateValues, name, control]),
1314
- append: React__default.useCallback(append, [updateValues, name, control]),
1315
- remove: React__default.useCallback(remove, [updateValues, name, control]),
1316
- insert: React__default.useCallback(insert$1, [updateValues, name, control]),
1317
- update: React__default.useCallback(update, [updateValues, name, control]),
1318
- replace: React__default.useCallback(replace, [updateValues, name, control]),
1319
- fields: React__default.useMemo(() => fields.map((field, index) => ({
1320
- ...field,
1321
- [keyName]: ids.current[index] || generateId(),
1322
- })), [fields, keyName]),
963
+ else if (isObject(currentField)) {
964
+ if (iterateFieldsByAction(currentField, action)) {
965
+ break;
966
+ }
967
+ }
968
+ }
969
+ }
970
+ return;
971
+ };
972
+
973
+ function schemaErrorLookup(errors, _fields, name) {
974
+ const error = get(errors, name);
975
+ if (error || isKey(name)) {
976
+ return {
977
+ error,
978
+ name,
979
+ };
980
+ }
981
+ const names = name.split('.');
982
+ while (names.length) {
983
+ const fieldName = names.join('.');
984
+ const field = get(_fields, fieldName);
985
+ const foundError = get(errors, fieldName);
986
+ if (field && !Array.isArray(field) && name !== fieldName) {
987
+ return { name };
988
+ }
989
+ if (foundError && foundError.type) {
990
+ return {
991
+ name: fieldName,
992
+ error: foundError,
993
+ };
994
+ }
995
+ names.pop();
996
+ }
997
+ return {
998
+ name,
1323
999
  };
1324
1000
  }
1325
1001
 
1326
- var createSubject = () => {
1327
- let _observers = [];
1328
- const next = (value) => {
1329
- for (const observer of _observers) {
1330
- observer.next && observer.next(value);
1331
- }
1332
- };
1333
- const subscribe = (observer) => {
1334
- _observers.push(observer);
1335
- return {
1336
- unsubscribe: () => {
1337
- _observers = _observers.filter((o) => o !== observer);
1338
- },
1339
- };
1340
- };
1341
- const unsubscribe = () => {
1342
- _observers = [];
1343
- };
1344
- return {
1345
- get observers() {
1346
- return _observers;
1347
- },
1348
- next,
1349
- subscribe,
1350
- unsubscribe,
1351
- };
1002
+ var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
1003
+ updateFormState(formStateData);
1004
+ const { name, ...formState } = formStateData;
1005
+ return (isEmptyObject(formState) ||
1006
+ Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
1007
+ Object.keys(formState).find((key) => _proxyFormState[key] ===
1008
+ (!isRoot || VALIDATION_MODE.all)));
1352
1009
  };
1353
1010
 
1354
- var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
1011
+ var shouldSubscribeByName = (name, signalName, exact) => !name ||
1012
+ !signalName ||
1013
+ name === signalName ||
1014
+ convertToArrayPayload(name).some((currentName) => currentName &&
1015
+ (exact
1016
+ ? currentName === signalName
1017
+ : currentName.startsWith(signalName) ||
1018
+ signalName.startsWith(currentName)));
1355
1019
 
1356
- function deepEqual(object1, object2) {
1357
- if (isPrimitive(object1) || isPrimitive(object2)) {
1358
- return object1 === object2;
1020
+ var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
1021
+ if (mode.isOnAll) {
1022
+ return false;
1359
1023
  }
1360
- if (isDateObject(object1) && isDateObject(object2)) {
1361
- return object1.getTime() === object2.getTime();
1024
+ else if (!isSubmitted && mode.isOnTouch) {
1025
+ return !(isTouched || isBlurEvent);
1362
1026
  }
1363
- const keys1 = Object.keys(object1);
1364
- const keys2 = Object.keys(object2);
1365
- if (keys1.length !== keys2.length) {
1366
- return false;
1027
+ else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
1028
+ return !isBlurEvent;
1367
1029
  }
1368
- for (const key of keys1) {
1369
- const val1 = object1[key];
1370
- if (!keys2.includes(key)) {
1371
- return false;
1372
- }
1373
- if (key !== 'ref') {
1374
- const val2 = object2[key];
1375
- if ((isDateObject(val1) && isDateObject(val2)) ||
1376
- (isObject(val1) && isObject(val2)) ||
1377
- (Array.isArray(val1) && Array.isArray(val2))
1378
- ? !deepEqual(val1, val2)
1379
- : val1 !== val2) {
1380
- return false;
1381
- }
1382
- }
1030
+ else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
1031
+ return isBlurEvent;
1383
1032
  }
1384
1033
  return true;
1385
- }
1386
-
1387
- var isMultipleSelect = (element) => element.type === `select-multiple`;
1388
-
1389
- var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
1034
+ };
1390
1035
 
1391
- var live = (ref) => isHTMLElement(ref) && ref.isConnected;
1036
+ var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
1392
1037
 
1393
- var objectHasFunction = (data) => {
1394
- for (const key in data) {
1395
- if (isFunction(data[key])) {
1396
- return true;
1397
- }
1398
- }
1399
- return false;
1038
+ var updateFieldArrayRootError = (errors, error, name) => {
1039
+ const fieldArrayErrors = convertToArrayPayload(get(errors, name));
1040
+ set(fieldArrayErrors, 'root', error[name]);
1041
+ set(errors, name, fieldArrayErrors);
1042
+ return errors;
1400
1043
  };
1401
1044
 
1402
- function markFieldsDirty(data, fields = {}) {
1403
- const isParentNodeArray = Array.isArray(data);
1404
- if (isObject(data) || isParentNodeArray) {
1405
- for (const key in data) {
1406
- if (Array.isArray(data[key]) ||
1407
- (isObject(data[key]) && !objectHasFunction(data[key]))) {
1408
- fields[key] = Array.isArray(data[key]) ? [] : {};
1409
- markFieldsDirty(data[key], fields[key]);
1410
- }
1411
- else if (!isNullOrUndefined(data[key])) {
1412
- fields[key] = true;
1413
- }
1414
- }
1045
+ var isMessage = (value) => isString(value);
1046
+
1047
+ function getValidateError(result, ref, type = 'validate') {
1048
+ if (isMessage(result) ||
1049
+ (Array.isArray(result) && result.every(isMessage)) ||
1050
+ (isBoolean(result) && !result)) {
1051
+ return {
1052
+ type,
1053
+ message: isMessage(result) ? result : '',
1054
+ ref,
1055
+ };
1415
1056
  }
1416
- return fields;
1417
- }
1418
- function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues) {
1419
- const isParentNodeArray = Array.isArray(data);
1420
- if (isObject(data) || isParentNodeArray) {
1421
- for (const key in data) {
1422
- if (Array.isArray(data[key]) ||
1423
- (isObject(data[key]) && !objectHasFunction(data[key]))) {
1424
- if (isUndefined(formValues) ||
1425
- isPrimitive(dirtyFieldsFromValues[key])) {
1426
- dirtyFieldsFromValues[key] = Array.isArray(data[key])
1427
- ? markFieldsDirty(data[key], [])
1428
- : { ...markFieldsDirty(data[key]) };
1429
- }
1430
- else {
1431
- getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
1432
- }
1433
- }
1434
- else {
1435
- dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
1436
- }
1437
- }
1438
- }
1439
- return dirtyFieldsFromValues;
1440
- }
1441
- var getDirtyFields = (defaultValues, formValues) => getDirtyFieldsFromDefaultValues(defaultValues, formValues, markFieldsDirty(formValues));
1442
-
1443
- var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value)
1444
- ? value
1445
- : valueAsNumber
1446
- ? value === ''
1447
- ? NaN
1448
- : value
1449
- ? +value
1450
- : value
1451
- : valueAsDate && isString(value)
1452
- ? new Date(value)
1453
- : setValueAs
1454
- ? setValueAs(value)
1455
- : value;
1456
-
1457
- function getFieldValue(_f) {
1458
- const ref = _f.ref;
1459
- if (isFileInput(ref)) {
1460
- return ref.files;
1461
- }
1462
- if (isRadioInput(ref)) {
1463
- return getRadioValue(_f.refs).value;
1464
- }
1465
- if (isMultipleSelect(ref)) {
1466
- return [...ref.selectedOptions].map(({ value }) => value);
1467
- }
1468
- if (isCheckBoxInput(ref)) {
1469
- return getCheckboxValue(_f.refs).value;
1470
- }
1471
- return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
1472
1057
  }
1473
1058
 
1474
- var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
1475
- const fields = {};
1476
- for (const name of fieldsNames) {
1477
- const field = get(_fields, name);
1478
- field && set(fields, name, field._f);
1479
- }
1480
- return {
1481
- criteriaMode,
1482
- names: [...fieldsNames],
1483
- fields,
1484
- shouldUseNativeValidation,
1059
+ var getValueAndMessage = (validationData) => isObject(validationData) && !isRegex(validationData)
1060
+ ? validationData
1061
+ : {
1062
+ value: validationData,
1063
+ message: '',
1485
1064
  };
1486
- };
1487
-
1488
- var getRuleValue = (rule) => isUndefined(rule)
1489
- ? rule
1490
- : isRegex(rule)
1491
- ? rule.source
1492
- : isObject(rule)
1493
- ? isRegex(rule.value)
1494
- ? rule.value.source
1495
- : rule.value
1496
- : rule;
1497
-
1498
- const ASYNC_FUNCTION = 'AsyncFunction';
1499
- var hasPromiseValidation = (fieldReference) => !!fieldReference &&
1500
- !!fieldReference.validate &&
1501
- !!((isFunction(fieldReference.validate) &&
1502
- fieldReference.validate.constructor.name === ASYNC_FUNCTION) ||
1503
- (isObject(fieldReference.validate) &&
1504
- Object.values(fieldReference.validate).find((validateFunction) => validateFunction.constructor.name === ASYNC_FUNCTION)));
1505
-
1506
- var hasValidation = (options) => options.mount &&
1507
- (options.required ||
1508
- options.min ||
1509
- options.max ||
1510
- options.maxLength ||
1511
- options.minLength ||
1512
- options.pattern ||
1513
- options.validate);
1514
1065
 
1515
- function schemaErrorLookup(errors, _fields, name) {
1516
- const error = get(errors, name);
1517
- if (error || isKey(name)) {
1518
- return {
1519
- error,
1520
- name,
1521
- };
1066
+ var validateField = async (field, disabledFieldNames, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
1067
+ const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, } = field._f;
1068
+ const inputValue = get(formValues, name);
1069
+ if (!mount || disabledFieldNames.has(name)) {
1070
+ return {};
1522
1071
  }
1523
- const names = name.split('.');
1524
- while (names.length) {
1525
- const fieldName = names.join('.');
1526
- const field = get(_fields, fieldName);
1527
- const foundError = get(errors, fieldName);
1528
- if (field && !Array.isArray(field) && name !== fieldName) {
1529
- return { name };
1072
+ const inputRef = refs ? refs[0] : ref;
1073
+ const setCustomValidity = (message) => {
1074
+ if (shouldUseNativeValidation && inputRef.reportValidity) {
1075
+ inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
1076
+ inputRef.reportValidity();
1530
1077
  }
1531
- if (foundError && foundError.type) {
1532
- return {
1533
- name: fieldName,
1534
- error: foundError,
1078
+ };
1079
+ const error = {};
1080
+ const isRadio = isRadioInput(ref);
1081
+ const isCheckBox = isCheckBoxInput(ref);
1082
+ const isRadioOrCheckbox = isRadio || isCheckBox;
1083
+ const isEmpty = ((valueAsNumber || isFileInput(ref)) &&
1084
+ isUndefined(ref.value) &&
1085
+ isUndefined(inputValue)) ||
1086
+ (isHTMLElement(ref) && ref.value === '') ||
1087
+ inputValue === '' ||
1088
+ (Array.isArray(inputValue) && !inputValue.length);
1089
+ const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
1090
+ const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
1091
+ const message = exceedMax ? maxLengthMessage : minLengthMessage;
1092
+ error[name] = {
1093
+ type: exceedMax ? maxType : minType,
1094
+ message,
1095
+ ref,
1096
+ ...appendErrorsCurry(exceedMax ? maxType : minType, message),
1097
+ };
1098
+ };
1099
+ if (isFieldArray
1100
+ ? !Array.isArray(inputValue) || !inputValue.length
1101
+ : required &&
1102
+ ((!isRadioOrCheckbox && (isEmpty || isNullOrUndefined(inputValue))) ||
1103
+ (isBoolean(inputValue) && !inputValue) ||
1104
+ (isCheckBox && !getCheckboxValue(refs).isValid) ||
1105
+ (isRadio && !getRadioValue(refs).isValid))) {
1106
+ const { value, message } = isMessage(required)
1107
+ ? { value: !!required, message: required }
1108
+ : getValueAndMessage(required);
1109
+ if (value) {
1110
+ error[name] = {
1111
+ type: INPUT_VALIDATION_RULES.required,
1112
+ message,
1113
+ ref: inputRef,
1114
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message),
1535
1115
  };
1116
+ if (!validateAllFieldCriteria) {
1117
+ setCustomValidity(message);
1118
+ return error;
1119
+ }
1536
1120
  }
1537
- names.pop();
1538
- }
1539
- return {
1540
- name,
1541
- };
1542
- }
1543
-
1544
- var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
1545
- if (mode.isOnAll) {
1546
- return false;
1547
1121
  }
1548
- else if (!isSubmitted && mode.isOnTouch) {
1549
- return !(isTouched || isBlurEvent);
1122
+ if (!isEmpty && (!isNullOrUndefined(min) || !isNullOrUndefined(max))) {
1123
+ let exceedMax;
1124
+ let exceedMin;
1125
+ const maxOutput = getValueAndMessage(max);
1126
+ const minOutput = getValueAndMessage(min);
1127
+ if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
1128
+ const valueNumber = ref.valueAsNumber ||
1129
+ (inputValue ? +inputValue : inputValue);
1130
+ if (!isNullOrUndefined(maxOutput.value)) {
1131
+ exceedMax = valueNumber > maxOutput.value;
1132
+ }
1133
+ if (!isNullOrUndefined(minOutput.value)) {
1134
+ exceedMin = valueNumber < minOutput.value;
1135
+ }
1136
+ }
1137
+ else {
1138
+ const valueDate = ref.valueAsDate || new Date(inputValue);
1139
+ const convertTimeToDate = (time) => new Date(new Date().toDateString() + ' ' + time);
1140
+ const isTime = ref.type == 'time';
1141
+ const isWeek = ref.type == 'week';
1142
+ if (isString(maxOutput.value) && inputValue) {
1143
+ exceedMax = isTime
1144
+ ? convertTimeToDate(inputValue) > convertTimeToDate(maxOutput.value)
1145
+ : isWeek
1146
+ ? inputValue > maxOutput.value
1147
+ : valueDate > new Date(maxOutput.value);
1148
+ }
1149
+ if (isString(minOutput.value) && inputValue) {
1150
+ exceedMin = isTime
1151
+ ? convertTimeToDate(inputValue) < convertTimeToDate(minOutput.value)
1152
+ : isWeek
1153
+ ? inputValue < minOutput.value
1154
+ : valueDate < new Date(minOutput.value);
1155
+ }
1156
+ }
1157
+ if (exceedMax || exceedMin) {
1158
+ getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
1159
+ if (!validateAllFieldCriteria) {
1160
+ setCustomValidity(error[name].message);
1161
+ return error;
1162
+ }
1163
+ }
1550
1164
  }
1551
- else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
1552
- return !isBlurEvent;
1165
+ if ((maxLength || minLength) &&
1166
+ !isEmpty &&
1167
+ (isString(inputValue) || (isFieldArray && Array.isArray(inputValue)))) {
1168
+ const maxLengthOutput = getValueAndMessage(maxLength);
1169
+ const minLengthOutput = getValueAndMessage(minLength);
1170
+ const exceedMax = !isNullOrUndefined(maxLengthOutput.value) &&
1171
+ inputValue.length > +maxLengthOutput.value;
1172
+ const exceedMin = !isNullOrUndefined(minLengthOutput.value) &&
1173
+ inputValue.length < +minLengthOutput.value;
1174
+ if (exceedMax || exceedMin) {
1175
+ getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
1176
+ if (!validateAllFieldCriteria) {
1177
+ setCustomValidity(error[name].message);
1178
+ return error;
1179
+ }
1180
+ }
1553
1181
  }
1554
- else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
1555
- return isBlurEvent;
1182
+ if (pattern && !isEmpty && isString(inputValue)) {
1183
+ const { value: patternValue, message } = getValueAndMessage(pattern);
1184
+ if (isRegex(patternValue) && !inputValue.match(patternValue)) {
1185
+ error[name] = {
1186
+ type: INPUT_VALIDATION_RULES.pattern,
1187
+ message,
1188
+ ref,
1189
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message),
1190
+ };
1191
+ if (!validateAllFieldCriteria) {
1192
+ setCustomValidity(message);
1193
+ return error;
1194
+ }
1195
+ }
1556
1196
  }
1557
- return true;
1197
+ if (validate) {
1198
+ if (isFunction(validate)) {
1199
+ const result = await validate(inputValue, formValues);
1200
+ const validateError = getValidateError(result, inputRef);
1201
+ if (validateError) {
1202
+ error[name] = {
1203
+ ...validateError,
1204
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message),
1205
+ };
1206
+ if (!validateAllFieldCriteria) {
1207
+ setCustomValidity(validateError.message);
1208
+ return error;
1209
+ }
1210
+ }
1211
+ }
1212
+ else if (isObject(validate)) {
1213
+ let validationResult = {};
1214
+ for (const key in validate) {
1215
+ if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
1216
+ break;
1217
+ }
1218
+ const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
1219
+ if (validateError) {
1220
+ validationResult = {
1221
+ ...validateError,
1222
+ ...appendErrorsCurry(key, validateError.message),
1223
+ };
1224
+ setCustomValidity(validateError.message);
1225
+ if (validateAllFieldCriteria) {
1226
+ error[name] = validationResult;
1227
+ }
1228
+ }
1229
+ }
1230
+ if (!isEmptyObject(validationResult)) {
1231
+ error[name] = {
1232
+ ref: inputRef,
1233
+ ...validationResult,
1234
+ };
1235
+ if (!validateAllFieldCriteria) {
1236
+ return error;
1237
+ }
1238
+ }
1239
+ }
1240
+ }
1241
+ setCustomValidity(true);
1242
+ return error;
1558
1243
  };
1559
1244
 
1560
- var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
1561
-
1562
1245
  const defaultOptions = {
1563
1246
  mode: VALIDATION_MODE.onSubmit,
1564
1247
  reValidateMode: VALIDATION_MODE.onChange,
@@ -1572,6 +1255,7 @@ function createFormControl(props = {}) {
1572
1255
  let _formState = {
1573
1256
  submitCount: 0,
1574
1257
  isDirty: false,
1258
+ isReady: false,
1575
1259
  isLoading: isFunction(_options.defaultValues),
1576
1260
  isValidating: false,
1577
1261
  isSubmitted: false,
@@ -1584,7 +1268,7 @@ function createFormControl(props = {}) {
1584
1268
  errors: _options.errors || {},
1585
1269
  disabled: _options.disabled || false,
1586
1270
  };
1587
- let _fields = {};
1271
+ const _fields = {};
1588
1272
  let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
1589
1273
  ? cloneObject(_options.defaultValues || _options.values) || {}
1590
1274
  : {};
@@ -1614,22 +1298,25 @@ function createFormControl(props = {}) {
1614
1298
  isValid: false,
1615
1299
  errors: false,
1616
1300
  };
1301
+ let _proxySubscribeFormState = {
1302
+ ..._proxyFormState,
1303
+ };
1617
1304
  const _subjects = {
1618
- values: createSubject(),
1619
1305
  array: createSubject(),
1620
1306
  state: createSubject(),
1621
1307
  };
1622
- const validationModeBeforeSubmit = getValidationModes(_options.mode);
1623
- const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
1624
1308
  const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
1625
1309
  const debounce = (callback) => (wait) => {
1626
1310
  clearTimeout(timer);
1627
1311
  timer = setTimeout(callback, wait);
1628
1312
  };
1629
- const _updateValid = async (shouldUpdateValid) => {
1630
- if (!_options.disabled && (_proxyFormState.isValid || shouldUpdateValid)) {
1313
+ const _setValid = async (shouldUpdateValid) => {
1314
+ if (!_options.disabled &&
1315
+ (_proxyFormState.isValid ||
1316
+ _proxySubscribeFormState.isValid ||
1317
+ shouldUpdateValid)) {
1631
1318
  const isValid = _options.resolver
1632
- ? isEmptyObject((await _executeSchema()).errors)
1319
+ ? isEmptyObject((await _runSchema()).errors)
1633
1320
  : await executeBuiltInValidation(_fields, true);
1634
1321
  if (isValid !== _formState.isValid) {
1635
1322
  _subjects.state.next({
@@ -1640,7 +1327,10 @@ function createFormControl(props = {}) {
1640
1327
  };
1641
1328
  const _updateIsValidating = (names, isValidating) => {
1642
1329
  if (!_options.disabled &&
1643
- (_proxyFormState.isValidating || _proxyFormState.validatingFields)) {
1330
+ (_proxyFormState.isValidating ||
1331
+ _proxyFormState.validatingFields ||
1332
+ _proxySubscribeFormState.isValidating ||
1333
+ _proxySubscribeFormState.validatingFields)) {
1644
1334
  (names || Array.from(_names.mount)).forEach((name) => {
1645
1335
  if (name) {
1646
1336
  isValidating
@@ -1654,7 +1344,7 @@ function createFormControl(props = {}) {
1654
1344
  });
1655
1345
  }
1656
1346
  };
1657
- const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
1347
+ const _setFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
1658
1348
  if (args && method && !_options.disabled) {
1659
1349
  _state.action = true;
1660
1350
  if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
@@ -1667,13 +1357,14 @@ function createFormControl(props = {}) {
1667
1357
  shouldSetValues && set(_formState.errors, name, errors);
1668
1358
  unsetEmptyArray(_formState.errors, name);
1669
1359
  }
1670
- if (_proxyFormState.touchedFields &&
1360
+ if ((_proxyFormState.touchedFields ||
1361
+ _proxySubscribeFormState.touchedFields) &&
1671
1362
  shouldUpdateFieldsAndState &&
1672
1363
  Array.isArray(get(_formState.touchedFields, name))) {
1673
1364
  const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
1674
1365
  shouldSetValues && set(_formState.touchedFields, name, touchedFields);
1675
1366
  }
1676
- if (_proxyFormState.dirtyFields) {
1367
+ if (_proxyFormState.dirtyFields || _proxySubscribeFormState.dirtyFields) {
1677
1368
  _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
1678
1369
  }
1679
1370
  _subjects.state.next({
@@ -1710,7 +1401,7 @@ function createFormControl(props = {}) {
1710
1401
  shouldSkipSetValueAs
1711
1402
  ? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f))
1712
1403
  : setFieldValue(name, defaultValue);
1713
- _state.mount && _updateValid();
1404
+ _state.mount && _setValid();
1714
1405
  }
1715
1406
  };
1716
1407
  const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
@@ -1720,24 +1411,22 @@ function createFormControl(props = {}) {
1720
1411
  name,
1721
1412
  };
1722
1413
  if (!_options.disabled) {
1723
- const disabledField = !!(get(_fields, name) &&
1724
- get(_fields, name)._f &&
1725
- get(_fields, name)._f.disabled);
1726
1414
  if (!isBlurEvent || shouldDirty) {
1727
- if (_proxyFormState.isDirty) {
1415
+ if (_proxyFormState.isDirty || _proxySubscribeFormState.isDirty) {
1728
1416
  isPreviousDirty = _formState.isDirty;
1729
1417
  _formState.isDirty = output.isDirty = _getDirty();
1730
1418
  shouldUpdateField = isPreviousDirty !== output.isDirty;
1731
1419
  }
1732
- const isCurrentFieldPristine = disabledField || deepEqual(get(_defaultValues, name), fieldValue);
1733
- isPreviousDirty = !!(!disabledField && get(_formState.dirtyFields, name));
1734
- isCurrentFieldPristine || disabledField
1420
+ const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
1421
+ isPreviousDirty = !!get(_formState.dirtyFields, name);
1422
+ isCurrentFieldPristine
1735
1423
  ? unset(_formState.dirtyFields, name)
1736
1424
  : set(_formState.dirtyFields, name, true);
1737
1425
  output.dirtyFields = _formState.dirtyFields;
1738
1426
  shouldUpdateField =
1739
1427
  shouldUpdateField ||
1740
- (_proxyFormState.dirtyFields &&
1428
+ ((_proxyFormState.dirtyFields ||
1429
+ _proxySubscribeFormState.dirtyFields) &&
1741
1430
  isPreviousDirty !== !isCurrentFieldPristine);
1742
1431
  }
1743
1432
  if (isBlurEvent) {
@@ -1747,7 +1436,8 @@ function createFormControl(props = {}) {
1747
1436
  output.touchedFields = _formState.touchedFields;
1748
1437
  shouldUpdateField =
1749
1438
  shouldUpdateField ||
1750
- (_proxyFormState.touchedFields &&
1439
+ ((_proxyFormState.touchedFields ||
1440
+ _proxySubscribeFormState.touchedFields) &&
1751
1441
  isPreviousFieldTouched !== isBlurEvent);
1752
1442
  }
1753
1443
  }
@@ -1757,7 +1447,7 @@ function createFormControl(props = {}) {
1757
1447
  };
1758
1448
  const shouldRenderByError = (name, isValid, error, fieldState) => {
1759
1449
  const previousFieldError = get(_formState.errors, name);
1760
- const shouldUpdateValid = _proxyFormState.isValid &&
1450
+ const shouldUpdateValid = (_proxyFormState.isValid || _proxySubscribeFormState.isValid) &&
1761
1451
  isBoolean(isValid) &&
1762
1452
  _formState.isValid !== isValid;
1763
1453
  if (_options.delayError && error) {
@@ -1787,14 +1477,14 @@ function createFormControl(props = {}) {
1787
1477
  _subjects.state.next(updatedFormState);
1788
1478
  }
1789
1479
  };
1790
- const _executeSchema = async (name) => {
1480
+ const _runSchema = async (name) => {
1791
1481
  _updateIsValidating(name, true);
1792
1482
  const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1793
1483
  _updateIsValidating(name);
1794
1484
  return result;
1795
1485
  };
1796
1486
  const executeSchemaAndUpdateState = async (names) => {
1797
- const { errors } = await _executeSchema(names);
1487
+ const { errors } = await _runSchema(names);
1798
1488
  if (names) {
1799
1489
  for (const name of names) {
1800
1490
  const error = get(errors, name);
@@ -1885,13 +1575,17 @@ function createFormControl(props = {}) {
1885
1575
  }
1886
1576
  else if (fieldReference.refs) {
1887
1577
  if (isCheckBoxInput(fieldReference.ref)) {
1888
- fieldReference.refs.length > 1
1889
- ? fieldReference.refs.forEach((checkboxRef) => (!checkboxRef.defaultChecked || !checkboxRef.disabled) &&
1890
- (checkboxRef.checked = Array.isArray(fieldValue)
1891
- ? !!fieldValue.find((data) => data === checkboxRef.value)
1892
- : fieldValue === checkboxRef.value))
1893
- : fieldReference.refs[0] &&
1894
- (fieldReference.refs[0].checked = !!fieldValue);
1578
+ fieldReference.refs.forEach((checkboxRef) => {
1579
+ if (!checkboxRef.defaultChecked || !checkboxRef.disabled) {
1580
+ if (Array.isArray(fieldValue)) {
1581
+ checkboxRef.checked = !!fieldValue.find((data) => data === checkboxRef.value);
1582
+ }
1583
+ else {
1584
+ checkboxRef.checked =
1585
+ fieldValue === checkboxRef.value || !!fieldValue;
1586
+ }
1587
+ }
1588
+ });
1895
1589
  }
1896
1590
  else {
1897
1591
  fieldReference.refs.forEach((radioRef) => (radioRef.checked = radioRef.value === fieldValue));
@@ -1903,9 +1597,9 @@ function createFormControl(props = {}) {
1903
1597
  else {
1904
1598
  fieldReference.ref.value = fieldValue;
1905
1599
  if (!fieldReference.ref.type) {
1906
- _subjects.values.next({
1600
+ _subjects.state.next({
1907
1601
  name,
1908
- values: { ..._formValues },
1602
+ values: cloneObject(_formValues),
1909
1603
  });
1910
1604
  }
1911
1605
  }
@@ -1917,6 +1611,9 @@ function createFormControl(props = {}) {
1917
1611
  };
1918
1612
  const setValues = (name, value, options) => {
1919
1613
  for (const fieldKey in value) {
1614
+ if (!value.hasOwnProperty(fieldKey)) {
1615
+ return;
1616
+ }
1920
1617
  const fieldValue = value[fieldKey];
1921
1618
  const fieldName = `${name}.${fieldKey}`;
1922
1619
  const field = get(_fields, fieldName);
@@ -1936,9 +1633,12 @@ function createFormControl(props = {}) {
1936
1633
  if (isFieldArray) {
1937
1634
  _subjects.array.next({
1938
1635
  name,
1939
- values: { ..._formValues },
1636
+ values: cloneObject(_formValues),
1940
1637
  });
1941
- if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields) &&
1638
+ if ((_proxyFormState.isDirty ||
1639
+ _proxyFormState.dirtyFields ||
1640
+ _proxySubscribeFormState.isDirty ||
1641
+ _proxySubscribeFormState.dirtyFields) &&
1942
1642
  options.shouldDirty) {
1943
1643
  _subjects.state.next({
1944
1644
  name,
@@ -1953,9 +1653,9 @@ function createFormControl(props = {}) {
1953
1653
  : setFieldValue(name, cloneValue, options);
1954
1654
  }
1955
1655
  isWatched(name, _names) && _subjects.state.next({ ..._formState });
1956
- _subjects.values.next({
1656
+ _subjects.state.next({
1957
1657
  name: _state.mount ? name : undefined,
1958
- values: { ..._formValues },
1658
+ values: cloneObject(_formValues),
1959
1659
  });
1960
1660
  };
1961
1661
  const onChange = async (event) => {
@@ -1964,17 +1664,20 @@ function createFormControl(props = {}) {
1964
1664
  let name = target.name;
1965
1665
  let isFieldValueUpdated = true;
1966
1666
  const field = get(_fields, name);
1967
- const getCurrentFieldValue = () => target.type ? getFieldValue(field._f) : getEventValue(event);
1968
1667
  const _updateIsFieldValueUpdated = (fieldValue) => {
1969
1668
  isFieldValueUpdated =
1970
1669
  Number.isNaN(fieldValue) ||
1971
1670
  (isDateObject(fieldValue) && isNaN(fieldValue.getTime())) ||
1972
1671
  deepEqual(fieldValue, get(_formValues, name, fieldValue));
1973
1672
  };
1673
+ const validationModeBeforeSubmit = getValidationModes(_options.mode);
1674
+ const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
1974
1675
  if (field) {
1975
1676
  let error;
1976
1677
  let isValid;
1977
- const fieldValue = getCurrentFieldValue();
1678
+ const fieldValue = target.type
1679
+ ? getFieldValue(field._f)
1680
+ : getEventValue(event);
1978
1681
  const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
1979
1682
  const shouldSkipValidation = (!hasValidation(field._f) &&
1980
1683
  !_options.resolver &&
@@ -1990,21 +1693,23 @@ function createFormControl(props = {}) {
1990
1693
  else if (field._f.onChange) {
1991
1694
  field._f.onChange(event);
1992
1695
  }
1993
- const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, false);
1696
+ const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent);
1994
1697
  const shouldRender = !isEmptyObject(fieldState) || watched;
1995
1698
  !isBlurEvent &&
1996
- _subjects.values.next({
1699
+ _subjects.state.next({
1997
1700
  name,
1998
1701
  type: event.type,
1999
- values: { ..._formValues },
1702
+ values: cloneObject(_formValues),
2000
1703
  });
2001
1704
  if (shouldSkipValidation) {
2002
- if (_proxyFormState.isValid) {
2003
- if (_options.mode === 'onBlur' && isBlurEvent) {
2004
- _updateValid();
1705
+ if (_proxyFormState.isValid || _proxySubscribeFormState.isValid) {
1706
+ if (_options.mode === 'onBlur') {
1707
+ if (isBlurEvent) {
1708
+ _setValid();
1709
+ }
2005
1710
  }
2006
1711
  else if (!isBlurEvent) {
2007
- _updateValid();
1712
+ _setValid();
2008
1713
  }
2009
1714
  }
2010
1715
  return (shouldRender &&
@@ -2012,7 +1717,7 @@ function createFormControl(props = {}) {
2012
1717
  }
2013
1718
  !isBlurEvent && watched && _subjects.state.next({ ..._formState });
2014
1719
  if (_options.resolver) {
2015
- const { errors } = await _executeSchema([name]);
1720
+ const { errors } = await _runSchema([name]);
2016
1721
  _updateIsFieldValueUpdated(fieldValue);
2017
1722
  if (isFieldValueUpdated) {
2018
1723
  const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
@@ -2031,7 +1736,8 @@ function createFormControl(props = {}) {
2031
1736
  if (error) {
2032
1737
  isValid = false;
2033
1738
  }
2034
- else if (_proxyFormState.isValid) {
1739
+ else if (_proxyFormState.isValid ||
1740
+ _proxySubscribeFormState.isValid) {
2035
1741
  isValid = await executeBuiltInValidation(_fields, true);
2036
1742
  }
2037
1743
  }
@@ -2066,14 +1772,15 @@ function createFormControl(props = {}) {
2066
1772
  const field = get(_fields, fieldName);
2067
1773
  return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
2068
1774
  }))).every(Boolean);
2069
- !(!validationResult && !_formState.isValid) && _updateValid();
1775
+ !(!validationResult && !_formState.isValid) && _setValid();
2070
1776
  }
2071
1777
  else {
2072
1778
  validationResult = isValid = await executeBuiltInValidation(_fields);
2073
1779
  }
2074
1780
  _subjects.state.next({
2075
1781
  ...(!isString(name) ||
2076
- (_proxyFormState.isValid && isValid !== _formState.isValid)
1782
+ ((_proxyFormState.isValid || _proxySubscribeFormState.isValid) &&
1783
+ isValid !== _formState.isValid)
2077
1784
  ? {}
2078
1785
  : { name }),
2079
1786
  ...(_options.resolver || !name ? { isValid } : {}),
@@ -2126,10 +1833,33 @@ function createFormControl(props = {}) {
2126
1833
  options && options.shouldFocus && ref && ref.focus && ref.focus();
2127
1834
  };
2128
1835
  const watch = (name, defaultValue) => isFunction(name)
2129
- ? _subjects.values.subscribe({
1836
+ ? _subjects.state.subscribe({
2130
1837
  next: (payload) => name(_getWatch(undefined, defaultValue), payload),
2131
1838
  })
2132
1839
  : _getWatch(name, defaultValue, true);
1840
+ const _subscribe = (props) => _subjects.state.subscribe({
1841
+ next: (formState) => {
1842
+ if (shouldSubscribeByName(props.name, formState.name, props.exact) &&
1843
+ shouldRenderFormState(formState, props.formState || _proxyFormState, _setFormState, props.reRenderRoot)) {
1844
+ props.callback({
1845
+ values: { ..._formValues },
1846
+ ..._formState,
1847
+ ...formState,
1848
+ });
1849
+ }
1850
+ },
1851
+ }).unsubscribe;
1852
+ const subscribe = (props) => {
1853
+ _state.mount = true;
1854
+ _proxySubscribeFormState = {
1855
+ ..._proxySubscribeFormState,
1856
+ ...props.formState,
1857
+ };
1858
+ return _subscribe({
1859
+ ...props,
1860
+ formState: _proxySubscribeFormState,
1861
+ });
1862
+ };
2133
1863
  const unregister = (name, options = {}) => {
2134
1864
  for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
2135
1865
  _names.mount.delete(fieldName);
@@ -2147,21 +1877,20 @@ function createFormControl(props = {}) {
2147
1877
  !options.keepDefaultValue &&
2148
1878
  unset(_defaultValues, fieldName);
2149
1879
  }
2150
- _subjects.values.next({
2151
- values: { ..._formValues },
1880
+ _subjects.state.next({
1881
+ values: cloneObject(_formValues),
2152
1882
  });
2153
1883
  _subjects.state.next({
2154
1884
  ..._formState,
2155
1885
  ...(!options.keepDirty ? {} : { isDirty: _getDirty() }),
2156
1886
  });
2157
- !options.keepIsValid && _updateValid();
1887
+ !options.keepIsValid && _setValid();
2158
1888
  };
2159
- const _updateDisabledField = ({ disabled, name, field, fields, }) => {
1889
+ const _setDisabledField = ({ disabled, name, }) => {
2160
1890
  if ((isBoolean(disabled) && _state.mount) ||
2161
1891
  !!disabled ||
2162
1892
  _names.disabled.has(name)) {
2163
1893
  disabled ? _names.disabled.add(name) : _names.disabled.delete(name);
2164
- updateTouchAndDirty(name, getFieldValue(field ? field._f : get(fields, name)._f), false, false, true);
2165
1894
  }
2166
1895
  };
2167
1896
  const register = (name, options = {}) => {
@@ -2178,8 +1907,7 @@ function createFormControl(props = {}) {
2178
1907
  });
2179
1908
  _names.mount.add(name);
2180
1909
  if (field) {
2181
- _updateDisabledField({
2182
- field,
1910
+ _setDisabledField({
2183
1911
  disabled: isBoolean(options.disabled)
2184
1912
  ? options.disabled
2185
1913
  : _options.disabled,
@@ -2273,25 +2001,26 @@ function createFormControl(props = {}) {
2273
2001
  let onValidError = undefined;
2274
2002
  if (e) {
2275
2003
  e.preventDefault && e.preventDefault();
2276
- e.persist && e.persist();
2004
+ e.persist &&
2005
+ e.persist();
2277
2006
  }
2278
2007
  let fieldValues = cloneObject(_formValues);
2279
- if (_names.disabled.size) {
2280
- for (const name of _names.disabled) {
2281
- set(fieldValues, name, undefined);
2282
- }
2283
- }
2284
2008
  _subjects.state.next({
2285
2009
  isSubmitting: true,
2286
2010
  });
2287
2011
  if (_options.resolver) {
2288
- const { errors, values } = await _executeSchema();
2012
+ const { errors, values } = await _runSchema();
2289
2013
  _formState.errors = errors;
2290
2014
  fieldValues = values;
2291
2015
  }
2292
2016
  else {
2293
2017
  await executeBuiltInValidation(_fields);
2294
2018
  }
2019
+ if (_names.disabled.size) {
2020
+ for (const name of _names.disabled) {
2021
+ set(fieldValues, name, undefined);
2022
+ }
2023
+ }
2295
2024
  unset(_formState.errors, 'root');
2296
2025
  if (isEmptyObject(_formState.errors)) {
2297
2026
  _subjects.state.next({
@@ -2342,7 +2071,7 @@ function createFormControl(props = {}) {
2342
2071
  }
2343
2072
  if (!options.keepError) {
2344
2073
  unset(_formState.errors, name);
2345
- _proxyFormState.isValid && _updateValid();
2074
+ _proxyFormState.isValid && _setValid();
2346
2075
  }
2347
2076
  _subjects.state.next({ ..._formState });
2348
2077
  }
@@ -2368,188 +2097,494 @@ function createFormControl(props = {}) {
2368
2097
  }
2369
2098
  }
2370
2099
  else {
2371
- if (isWeb && isUndefined(formValues)) {
2372
- for (const name of _names.mount) {
2373
- const field = get(_fields, name);
2374
- if (field && field._f) {
2375
- const fieldReference = Array.isArray(field._f.refs)
2376
- ? field._f.refs[0]
2377
- : field._f.ref;
2378
- if (isHTMLElement(fieldReference)) {
2379
- const form = fieldReference.closest('form');
2380
- if (form) {
2381
- form.reset();
2382
- break;
2383
- }
2384
- }
2385
- }
2386
- }
2100
+ if (isWeb && isUndefined(formValues)) {
2101
+ for (const name of _names.mount) {
2102
+ const field = get(_fields, name);
2103
+ if (field && field._f) {
2104
+ const fieldReference = Array.isArray(field._f.refs)
2105
+ ? field._f.refs[0]
2106
+ : field._f.ref;
2107
+ if (isHTMLElement(fieldReference)) {
2108
+ const form = fieldReference.closest('form');
2109
+ if (form) {
2110
+ form.reset();
2111
+ break;
2112
+ }
2113
+ }
2114
+ }
2115
+ }
2116
+ }
2117
+ for (const fieldName of _names.mount) {
2118
+ setValue(fieldName, get(values, fieldName));
2119
+ }
2120
+ }
2121
+ _formValues = cloneObject(values);
2122
+ _subjects.array.next({
2123
+ values: { ...values },
2124
+ });
2125
+ _subjects.state.next({
2126
+ values: { ...values },
2127
+ });
2128
+ }
2129
+ _names = {
2130
+ mount: keepStateOptions.keepDirtyValues ? _names.mount : new Set(),
2131
+ unMount: new Set(),
2132
+ array: new Set(),
2133
+ disabled: new Set(),
2134
+ watch: new Set(),
2135
+ watchAll: false,
2136
+ focus: '',
2137
+ };
2138
+ _state.mount =
2139
+ !_proxyFormState.isValid ||
2140
+ !!keepStateOptions.keepIsValid ||
2141
+ !!keepStateOptions.keepDirtyValues;
2142
+ _state.watch = !!_options.shouldUnregister;
2143
+ _subjects.state.next({
2144
+ submitCount: keepStateOptions.keepSubmitCount
2145
+ ? _formState.submitCount
2146
+ : 0,
2147
+ isDirty: isEmptyResetValues
2148
+ ? false
2149
+ : keepStateOptions.keepDirty
2150
+ ? _formState.isDirty
2151
+ : !!(keepStateOptions.keepDefaultValues &&
2152
+ !deepEqual(formValues, _defaultValues)),
2153
+ isSubmitted: keepStateOptions.keepIsSubmitted
2154
+ ? _formState.isSubmitted
2155
+ : false,
2156
+ dirtyFields: isEmptyResetValues
2157
+ ? {}
2158
+ : keepStateOptions.keepDirtyValues
2159
+ ? keepStateOptions.keepDefaultValues && _formValues
2160
+ ? getDirtyFields(_defaultValues, _formValues)
2161
+ : _formState.dirtyFields
2162
+ : keepStateOptions.keepDefaultValues && formValues
2163
+ ? getDirtyFields(_defaultValues, formValues)
2164
+ : keepStateOptions.keepDirty
2165
+ ? _formState.dirtyFields
2166
+ : {},
2167
+ touchedFields: keepStateOptions.keepTouched
2168
+ ? _formState.touchedFields
2169
+ : {},
2170
+ errors: keepStateOptions.keepErrors ? _formState.errors : {},
2171
+ isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful
2172
+ ? _formState.isSubmitSuccessful
2173
+ : false,
2174
+ isSubmitting: false,
2175
+ });
2176
+ };
2177
+ const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
2178
+ ? formValues(_formValues)
2179
+ : formValues, keepStateOptions);
2180
+ const setFocus = (name, options = {}) => {
2181
+ const field = get(_fields, name);
2182
+ const fieldReference = field && field._f;
2183
+ if (fieldReference) {
2184
+ const fieldRef = fieldReference.refs
2185
+ ? fieldReference.refs[0]
2186
+ : fieldReference.ref;
2187
+ if (fieldRef.focus) {
2188
+ fieldRef.focus();
2189
+ options.shouldSelect &&
2190
+ isFunction(fieldRef.select) &&
2191
+ fieldRef.select();
2192
+ }
2193
+ }
2194
+ };
2195
+ const _setFormState = (updatedFormState) => {
2196
+ _formState = {
2197
+ ..._formState,
2198
+ ...updatedFormState,
2199
+ };
2200
+ };
2201
+ const _resetDefaultValues = () => isFunction(_options.defaultValues) &&
2202
+ _options.defaultValues().then((values) => {
2203
+ reset(values, _options.resetOptions);
2204
+ _subjects.state.next({
2205
+ isLoading: false,
2206
+ });
2207
+ });
2208
+ const methods = {
2209
+ control: {
2210
+ register,
2211
+ unregister,
2212
+ getFieldState,
2213
+ handleSubmit,
2214
+ setError,
2215
+ _subscribe,
2216
+ _runSchema,
2217
+ _getWatch,
2218
+ _getDirty,
2219
+ _setValid,
2220
+ _setFieldArray,
2221
+ _setDisabledField,
2222
+ _setErrors,
2223
+ _getFieldArray,
2224
+ _reset,
2225
+ _resetDefaultValues,
2226
+ _removeUnmounted,
2227
+ _disableForm,
2228
+ _subjects,
2229
+ _proxyFormState,
2230
+ get _fields() {
2231
+ return _fields;
2232
+ },
2233
+ get _formValues() {
2234
+ return _formValues;
2235
+ },
2236
+ get _state() {
2237
+ return _state;
2238
+ },
2239
+ set _state(value) {
2240
+ _state = value;
2241
+ },
2242
+ get _defaultValues() {
2243
+ return _defaultValues;
2244
+ },
2245
+ get _names() {
2246
+ return _names;
2247
+ },
2248
+ set _names(value) {
2249
+ _names = value;
2250
+ },
2251
+ get _formState() {
2252
+ return _formState;
2253
+ },
2254
+ get _options() {
2255
+ return _options;
2256
+ },
2257
+ set _options(value) {
2258
+ _options = {
2259
+ ..._options,
2260
+ ...value,
2261
+ };
2262
+ },
2263
+ },
2264
+ subscribe,
2265
+ trigger,
2266
+ register,
2267
+ handleSubmit,
2268
+ watch,
2269
+ setValue,
2270
+ getValues,
2271
+ reset,
2272
+ resetField,
2273
+ clearErrors,
2274
+ unregister,
2275
+ setError,
2276
+ setFocus,
2277
+ getFieldState,
2278
+ };
2279
+ return {
2280
+ ...methods,
2281
+ formControl: methods,
2282
+ };
2283
+ }
2284
+
2285
+ var generateId = () => {
2286
+ const d = typeof performance === 'undefined' ? Date.now() : performance.now() * 1000;
2287
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
2288
+ const r = (Math.random() * 16 + d) % 16 | 0;
2289
+ return (c == 'x' ? r : (r & 0x3) | 0x8).toString(16);
2290
+ });
2291
+ };
2292
+
2293
+ var getFocusFieldName = (name, index, options = {}) => options.shouldFocus || isUndefined(options.shouldFocus)
2294
+ ? options.focusName ||
2295
+ `${name}.${isUndefined(options.focusIndex) ? index : options.focusIndex}.`
2296
+ : '';
2297
+
2298
+ var appendAt = (data, value) => [
2299
+ ...data,
2300
+ ...convertToArrayPayload(value),
2301
+ ];
2302
+
2303
+ var fillEmptyArray = (value) => Array.isArray(value) ? value.map(() => undefined) : undefined;
2304
+
2305
+ function insert(data, index, value) {
2306
+ return [
2307
+ ...data.slice(0, index),
2308
+ ...convertToArrayPayload(value),
2309
+ ...data.slice(index),
2310
+ ];
2311
+ }
2312
+
2313
+ var moveArrayAt = (data, from, to) => {
2314
+ if (!Array.isArray(data)) {
2315
+ return [];
2316
+ }
2317
+ if (isUndefined(data[to])) {
2318
+ data[to] = undefined;
2319
+ }
2320
+ data.splice(to, 0, data.splice(from, 1)[0]);
2321
+ return data;
2322
+ };
2323
+
2324
+ var prependAt = (data, value) => [
2325
+ ...convertToArrayPayload(value),
2326
+ ...convertToArrayPayload(data),
2327
+ ];
2328
+
2329
+ function removeAtIndexes(data, indexes) {
2330
+ let i = 0;
2331
+ const temp = [...data];
2332
+ for (const index of indexes) {
2333
+ temp.splice(index - i, 1);
2334
+ i++;
2335
+ }
2336
+ return compact(temp).length ? temp : [];
2337
+ }
2338
+ var removeArrayAt = (data, index) => isUndefined(index)
2339
+ ? []
2340
+ : removeAtIndexes(data, convertToArrayPayload(index).sort((a, b) => a - b));
2341
+
2342
+ var swapArrayAt = (data, indexA, indexB) => {
2343
+ [data[indexA], data[indexB]] = [data[indexB], data[indexA]];
2344
+ };
2345
+
2346
+ var updateAt = (fieldValues, index, value) => {
2347
+ fieldValues[index] = value;
2348
+ return fieldValues;
2349
+ };
2350
+
2351
+ /**
2352
+ * A custom hook that exposes convenient methods to perform operations with a list of dynamic inputs that need to be appended, updated, removed etc. • [Demo](https://codesandbox.io/s/react-hook-form-usefieldarray-ssugn) • [Video](https://youtu.be/4MrbfGSFY2A)
2353
+ *
2354
+ * @remarks
2355
+ * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/react-hook-form-usefieldarray-ssugn)
2356
+ *
2357
+ * @param props - useFieldArray props
2358
+ *
2359
+ * @returns methods - functions to manipulate with the Field Arrays (dynamic inputs) {@link UseFieldArrayReturn}
2360
+ *
2361
+ * @example
2362
+ * ```tsx
2363
+ * function App() {
2364
+ * const { register, control, handleSubmit, reset, trigger, setError } = useForm({
2365
+ * defaultValues: {
2366
+ * test: []
2367
+ * }
2368
+ * });
2369
+ * const { fields, append } = useFieldArray({
2370
+ * control,
2371
+ * name: "test"
2372
+ * });
2373
+ *
2374
+ * return (
2375
+ * <form onSubmit={handleSubmit(data => console.log(data))}>
2376
+ * {fields.map((item, index) => (
2377
+ * <input key={item.id} {...register(`test.${index}.firstName`)} />
2378
+ * ))}
2379
+ * <button type="button" onClick={() => append({ firstName: "bill" })}>
2380
+ * append
2381
+ * </button>
2382
+ * <input type="submit" />
2383
+ * </form>
2384
+ * );
2385
+ * }
2386
+ * ```
2387
+ */
2388
+ function useFieldArray(props) {
2389
+ const methods = useFormContext();
2390
+ const { control = methods.control, name, keyName = 'id', shouldUnregister, rules, } = props;
2391
+ const [fields, setFields] = React__default.useState(control._getFieldArray(name));
2392
+ const ids = React__default.useRef(control._getFieldArray(name).map(generateId));
2393
+ const _fieldIds = React__default.useRef(fields);
2394
+ const _name = React__default.useRef(name);
2395
+ const _actioned = React__default.useRef(false);
2396
+ _name.current = name;
2397
+ _fieldIds.current = fields;
2398
+ control._names.array.add(name);
2399
+ rules &&
2400
+ control.register(name, rules);
2401
+ React__default.useEffect(() => control._subjects.array.subscribe({
2402
+ next: ({ values, name: fieldArrayName, }) => {
2403
+ if (fieldArrayName === _name.current || !fieldArrayName) {
2404
+ const fieldValues = get(values, _name.current);
2405
+ if (Array.isArray(fieldValues)) {
2406
+ setFields(fieldValues);
2407
+ ids.current = fieldValues.map(generateId);
2408
+ }
2409
+ }
2410
+ },
2411
+ }).unsubscribe, [control]);
2412
+ const updateValues = React__default.useCallback((updatedFieldArrayValues) => {
2413
+ _actioned.current = true;
2414
+ control._setFieldArray(name, updatedFieldArrayValues);
2415
+ }, [control, name]);
2416
+ const append = (value, options) => {
2417
+ const appendValue = convertToArrayPayload(cloneObject(value));
2418
+ const updatedFieldArrayValues = appendAt(control._getFieldArray(name), appendValue);
2419
+ control._names.focus = getFocusFieldName(name, updatedFieldArrayValues.length - 1, options);
2420
+ ids.current = appendAt(ids.current, appendValue.map(generateId));
2421
+ updateValues(updatedFieldArrayValues);
2422
+ setFields(updatedFieldArrayValues);
2423
+ control._setFieldArray(name, updatedFieldArrayValues, appendAt, {
2424
+ argA: fillEmptyArray(value),
2425
+ });
2426
+ };
2427
+ const prepend = (value, options) => {
2428
+ const prependValue = convertToArrayPayload(cloneObject(value));
2429
+ const updatedFieldArrayValues = prependAt(control._getFieldArray(name), prependValue);
2430
+ control._names.focus = getFocusFieldName(name, 0, options);
2431
+ ids.current = prependAt(ids.current, prependValue.map(generateId));
2432
+ updateValues(updatedFieldArrayValues);
2433
+ setFields(updatedFieldArrayValues);
2434
+ control._setFieldArray(name, updatedFieldArrayValues, prependAt, {
2435
+ argA: fillEmptyArray(value),
2436
+ });
2437
+ };
2438
+ const remove = (index) => {
2439
+ const updatedFieldArrayValues = removeArrayAt(control._getFieldArray(name), index);
2440
+ ids.current = removeArrayAt(ids.current, index);
2441
+ updateValues(updatedFieldArrayValues);
2442
+ setFields(updatedFieldArrayValues);
2443
+ !Array.isArray(get(control._fields, name)) &&
2444
+ set(control._fields, name, undefined);
2445
+ control._setFieldArray(name, updatedFieldArrayValues, removeArrayAt, {
2446
+ argA: index,
2447
+ });
2448
+ };
2449
+ const insert$1 = (index, value, options) => {
2450
+ const insertValue = convertToArrayPayload(cloneObject(value));
2451
+ const updatedFieldArrayValues = insert(control._getFieldArray(name), index, insertValue);
2452
+ control._names.focus = getFocusFieldName(name, index, options);
2453
+ ids.current = insert(ids.current, index, insertValue.map(generateId));
2454
+ updateValues(updatedFieldArrayValues);
2455
+ setFields(updatedFieldArrayValues);
2456
+ control._setFieldArray(name, updatedFieldArrayValues, insert, {
2457
+ argA: index,
2458
+ argB: fillEmptyArray(value),
2459
+ });
2460
+ };
2461
+ const swap = (indexA, indexB) => {
2462
+ const updatedFieldArrayValues = control._getFieldArray(name);
2463
+ swapArrayAt(updatedFieldArrayValues, indexA, indexB);
2464
+ swapArrayAt(ids.current, indexA, indexB);
2465
+ updateValues(updatedFieldArrayValues);
2466
+ setFields(updatedFieldArrayValues);
2467
+ control._setFieldArray(name, updatedFieldArrayValues, swapArrayAt, {
2468
+ argA: indexA,
2469
+ argB: indexB,
2470
+ }, false);
2471
+ };
2472
+ const move = (from, to) => {
2473
+ const updatedFieldArrayValues = control._getFieldArray(name);
2474
+ moveArrayAt(updatedFieldArrayValues, from, to);
2475
+ moveArrayAt(ids.current, from, to);
2476
+ updateValues(updatedFieldArrayValues);
2477
+ setFields(updatedFieldArrayValues);
2478
+ control._setFieldArray(name, updatedFieldArrayValues, moveArrayAt, {
2479
+ argA: from,
2480
+ argB: to,
2481
+ }, false);
2482
+ };
2483
+ const update = (index, value) => {
2484
+ const updateValue = cloneObject(value);
2485
+ const updatedFieldArrayValues = updateAt(control._getFieldArray(name), index, updateValue);
2486
+ ids.current = [...updatedFieldArrayValues].map((item, i) => !item || i === index ? generateId() : ids.current[i]);
2487
+ updateValues(updatedFieldArrayValues);
2488
+ setFields([...updatedFieldArrayValues]);
2489
+ control._setFieldArray(name, updatedFieldArrayValues, updateAt, {
2490
+ argA: index,
2491
+ argB: updateValue,
2492
+ }, true, false);
2493
+ };
2494
+ const replace = (value) => {
2495
+ const updatedFieldArrayValues = convertToArrayPayload(cloneObject(value));
2496
+ ids.current = updatedFieldArrayValues.map(generateId);
2497
+ updateValues([...updatedFieldArrayValues]);
2498
+ setFields([...updatedFieldArrayValues]);
2499
+ control._setFieldArray(name, [...updatedFieldArrayValues], (data) => data, {}, true, false);
2500
+ };
2501
+ React__default.useEffect(() => {
2502
+ control._state.action = false;
2503
+ isWatched(name, control._names) &&
2504
+ control._subjects.state.next({
2505
+ ...control._formState,
2506
+ });
2507
+ if (_actioned.current &&
2508
+ (!getValidationModes(control._options.mode).isOnSubmit ||
2509
+ control._formState.isSubmitted) &&
2510
+ !getValidationModes(control._options.reValidateMode).isOnSubmit) {
2511
+ if (control._options.resolver) {
2512
+ control._runSchema([name]).then((result) => {
2513
+ const error = get(result.errors, name);
2514
+ const existingError = get(control._formState.errors, name);
2515
+ if (existingError
2516
+ ? (!error && existingError.type) ||
2517
+ (error &&
2518
+ (existingError.type !== error.type ||
2519
+ existingError.message !== error.message))
2520
+ : error && error.type) {
2521
+ error
2522
+ ? set(control._formState.errors, name, error)
2523
+ : unset(control._formState.errors, name);
2524
+ control._subjects.state.next({
2525
+ errors: control._formState.errors,
2526
+ });
2527
+ }
2528
+ });
2529
+ }
2530
+ else {
2531
+ const field = get(control._fields, name);
2532
+ if (field &&
2533
+ field._f &&
2534
+ !(getValidationModes(control._options.reValidateMode).isOnSubmit &&
2535
+ getValidationModes(control._options.mode).isOnSubmit)) {
2536
+ validateField(field, control._names.disabled, control._formValues, control._options.criteriaMode === VALIDATION_MODE.all, control._options.shouldUseNativeValidation, true).then((error) => !isEmptyObject(error) &&
2537
+ control._subjects.state.next({
2538
+ errors: updateFieldArrayRootError(control._formState.errors, error, name),
2539
+ }));
2387
2540
  }
2388
- _fields = {};
2389
2541
  }
2390
- _formValues = _options.shouldUnregister
2391
- ? keepStateOptions.keepDefaultValues
2392
- ? cloneObject(_defaultValues)
2393
- : {}
2394
- : cloneObject(values);
2395
- _subjects.array.next({
2396
- values: { ...values },
2397
- });
2398
- _subjects.values.next({
2399
- values: { ...values },
2400
- });
2401
2542
  }
2402
- _names = {
2403
- mount: keepStateOptions.keepDirtyValues ? _names.mount : new Set(),
2404
- unMount: new Set(),
2405
- array: new Set(),
2406
- disabled: new Set(),
2407
- watch: new Set(),
2408
- watchAll: false,
2409
- focus: '',
2410
- };
2411
- _state.mount =
2412
- !_proxyFormState.isValid ||
2413
- !!keepStateOptions.keepIsValid ||
2414
- !!keepStateOptions.keepDirtyValues;
2415
- _state.watch = !!_options.shouldUnregister;
2416
- _subjects.state.next({
2417
- submitCount: keepStateOptions.keepSubmitCount
2418
- ? _formState.submitCount
2419
- : 0,
2420
- isDirty: isEmptyResetValues
2421
- ? false
2422
- : keepStateOptions.keepDirty
2423
- ? _formState.isDirty
2424
- : !!(keepStateOptions.keepDefaultValues &&
2425
- !deepEqual(formValues, _defaultValues)),
2426
- isSubmitted: keepStateOptions.keepIsSubmitted
2427
- ? _formState.isSubmitted
2428
- : false,
2429
- dirtyFields: isEmptyResetValues
2430
- ? {}
2431
- : keepStateOptions.keepDirtyValues
2432
- ? keepStateOptions.keepDefaultValues && _formValues
2433
- ? getDirtyFields(_defaultValues, _formValues)
2434
- : _formState.dirtyFields
2435
- : keepStateOptions.keepDefaultValues && formValues
2436
- ? getDirtyFields(_defaultValues, formValues)
2437
- : keepStateOptions.keepDirty
2438
- ? _formState.dirtyFields
2439
- : {},
2440
- touchedFields: keepStateOptions.keepTouched
2441
- ? _formState.touchedFields
2442
- : {},
2443
- errors: keepStateOptions.keepErrors ? _formState.errors : {},
2444
- isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful
2445
- ? _formState.isSubmitSuccessful
2446
- : false,
2447
- isSubmitting: false,
2543
+ control._subjects.state.next({
2544
+ name,
2545
+ values: cloneObject(control._formValues),
2448
2546
  });
2449
- };
2450
- const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
2451
- ? formValues(_formValues)
2452
- : formValues, keepStateOptions);
2453
- const setFocus = (name, options = {}) => {
2454
- const field = get(_fields, name);
2455
- const fieldReference = field && field._f;
2456
- if (fieldReference) {
2457
- const fieldRef = fieldReference.refs
2458
- ? fieldReference.refs[0]
2459
- : fieldReference.ref;
2460
- if (fieldRef.focus) {
2461
- fieldRef.focus();
2462
- options.shouldSelect &&
2463
- isFunction(fieldRef.select) &&
2464
- fieldRef.select();
2465
- }
2466
- }
2467
- };
2468
- const _updateFormState = (updatedFormState) => {
2469
- _formState = {
2470
- ..._formState,
2471
- ...updatedFormState,
2472
- };
2473
- };
2474
- const _resetDefaultValues = () => isFunction(_options.defaultValues) &&
2475
- _options.defaultValues().then((values) => {
2476
- reset(values, _options.resetOptions);
2477
- _subjects.state.next({
2478
- isLoading: false,
2547
+ control._names.focus &&
2548
+ iterateFieldsByAction(control._fields, (ref, key) => {
2549
+ if (control._names.focus &&
2550
+ key.startsWith(control._names.focus) &&
2551
+ ref.focus) {
2552
+ ref.focus();
2553
+ return 1;
2554
+ }
2555
+ return;
2479
2556
  });
2480
- });
2557
+ control._names.focus = '';
2558
+ control._setValid();
2559
+ _actioned.current = false;
2560
+ }, [fields, name, control]);
2561
+ React__default.useEffect(() => {
2562
+ !get(control._formValues, name) && control._setFieldArray(name);
2563
+ return () => {
2564
+ const updateMounted = (name, value) => {
2565
+ const field = get(control._fields, name);
2566
+ if (field && field._f) {
2567
+ field._f.mount = value;
2568
+ }
2569
+ };
2570
+ control._options.shouldUnregister || shouldUnregister
2571
+ ? control.unregister(name)
2572
+ : updateMounted(name, false);
2573
+ };
2574
+ }, [name, control, keyName, shouldUnregister]);
2481
2575
  return {
2482
- control: {
2483
- register,
2484
- unregister,
2485
- getFieldState,
2486
- handleSubmit,
2487
- setError,
2488
- _executeSchema,
2489
- _getWatch,
2490
- _getDirty,
2491
- _updateValid,
2492
- _removeUnmounted,
2493
- _updateFieldArray,
2494
- _updateDisabledField,
2495
- _getFieldArray,
2496
- _reset,
2497
- _resetDefaultValues,
2498
- _updateFormState,
2499
- _disableForm,
2500
- _subjects,
2501
- _proxyFormState,
2502
- _setErrors,
2503
- get _fields() {
2504
- return _fields;
2505
- },
2506
- get _formValues() {
2507
- return _formValues;
2508
- },
2509
- get _state() {
2510
- return _state;
2511
- },
2512
- set _state(value) {
2513
- _state = value;
2514
- },
2515
- get _defaultValues() {
2516
- return _defaultValues;
2517
- },
2518
- get _names() {
2519
- return _names;
2520
- },
2521
- set _names(value) {
2522
- _names = value;
2523
- },
2524
- get _formState() {
2525
- return _formState;
2526
- },
2527
- set _formState(value) {
2528
- _formState = value;
2529
- },
2530
- get _options() {
2531
- return _options;
2532
- },
2533
- set _options(value) {
2534
- _options = {
2535
- ..._options,
2536
- ...value,
2537
- };
2538
- },
2539
- },
2540
- trigger,
2541
- register,
2542
- handleSubmit,
2543
- watch,
2544
- setValue,
2545
- getValues,
2546
- reset,
2547
- resetField,
2548
- clearErrors,
2549
- unregister,
2550
- setError,
2551
- setFocus,
2552
- getFieldState,
2576
+ swap: React__default.useCallback(swap, [updateValues, name, control]),
2577
+ move: React__default.useCallback(move, [updateValues, name, control]),
2578
+ prepend: React__default.useCallback(prepend, [updateValues, name, control]),
2579
+ append: React__default.useCallback(append, [updateValues, name, control]),
2580
+ remove: React__default.useCallback(remove, [updateValues, name, control]),
2581
+ insert: React__default.useCallback(insert$1, [updateValues, name, control]),
2582
+ update: React__default.useCallback(update, [updateValues, name, control]),
2583
+ replace: React__default.useCallback(replace, [updateValues, name, control]),
2584
+ fields: React__default.useMemo(() => fields.map((field, index) => ({
2585
+ ...field,
2586
+ [keyName]: ids.current[index] || generateId(),
2587
+ })), [fields, keyName]),
2553
2588
  };
2554
2589
  }
2555
2590
 
@@ -2599,27 +2634,55 @@ function useForm(props = {}) {
2599
2634
  validatingFields: {},
2600
2635
  errors: props.errors || {},
2601
2636
  disabled: props.disabled || false,
2637
+ isReady: false,
2602
2638
  defaultValues: isFunction(props.defaultValues)
2603
2639
  ? undefined
2604
2640
  : props.defaultValues,
2605
2641
  });
2606
2642
  if (!_formControl.current) {
2607
2643
  _formControl.current = {
2608
- ...createFormControl(props),
2644
+ ...(props.formControl ? props.formControl : createFormControl(props)),
2609
2645
  formState,
2610
2646
  };
2647
+ if (props.formControl &&
2648
+ props.defaultValues &&
2649
+ !isFunction(props.defaultValues)) {
2650
+ props.formControl.reset(props.defaultValues, props.resetOptions);
2651
+ }
2611
2652
  }
2612
2653
  const control = _formControl.current.control;
2613
2654
  control._options = props;
2614
- useSubscribe({
2615
- subject: control._subjects.state,
2616
- next: (value) => {
2617
- if (shouldRenderFormState(value, control._proxyFormState, control._updateFormState, true)) {
2618
- updateFormState({ ...control._formState });
2619
- }
2620
- },
2621
- });
2655
+ useIsomorphicLayoutEffect(() => {
2656
+ const sub = control._subscribe({
2657
+ formState: control._proxyFormState,
2658
+ callback: () => updateFormState({ ...control._formState }),
2659
+ reRenderRoot: true,
2660
+ });
2661
+ updateFormState((data) => ({
2662
+ ...data,
2663
+ isReady: true,
2664
+ }));
2665
+ control._formState.isReady = true;
2666
+ return sub;
2667
+ }, [control]);
2622
2668
  React__default.useEffect(() => control._disableForm(props.disabled), [control, props.disabled]);
2669
+ React__default.useEffect(() => {
2670
+ if (props.mode) {
2671
+ control._options.mode = props.mode;
2672
+ }
2673
+ if (props.reValidateMode) {
2674
+ control._options.reValidateMode = props.reValidateMode;
2675
+ }
2676
+ if (props.errors && !isEmptyObject(props.errors)) {
2677
+ control._setErrors(props.errors);
2678
+ }
2679
+ }, [control, props.errors, props.mode, props.reValidateMode]);
2680
+ React__default.useEffect(() => {
2681
+ props.shouldUnregister &&
2682
+ control._subjects.state.next({
2683
+ values: control._getWatch(),
2684
+ });
2685
+ }, [control, props.shouldUnregister]);
2623
2686
  React__default.useEffect(() => {
2624
2687
  if (control._proxyFormState.isDirty) {
2625
2688
  const isDirty = control._getDirty();
@@ -2639,15 +2702,10 @@ function useForm(props = {}) {
2639
2702
  else {
2640
2703
  control._resetDefaultValues();
2641
2704
  }
2642
- }, [props.values, control]);
2643
- React__default.useEffect(() => {
2644
- if (props.errors) {
2645
- control._setErrors(props.errors);
2646
- }
2647
- }, [props.errors, control]);
2705
+ }, [control, props.values]);
2648
2706
  React__default.useEffect(() => {
2649
2707
  if (!control._state.mount) {
2650
- control._updateValid();
2708
+ control._setValid();
2651
2709
  control._state.mount = true;
2652
2710
  }
2653
2711
  if (control._state.watch) {
@@ -2656,15 +2714,9 @@ function useForm(props = {}) {
2656
2714
  }
2657
2715
  control._removeUnmounted();
2658
2716
  });
2659
- React__default.useEffect(() => {
2660
- props.shouldUnregister &&
2661
- control._subjects.values.next({
2662
- values: control._getWatch(),
2663
- });
2664
- }, [props.shouldUnregister, control]);
2665
2717
  _formControl.current.formState = getProxyFormState(formState, control);
2666
2718
  return _formControl.current;
2667
2719
  }
2668
2720
 
2669
- export { Controller, Form, FormProvider, appendErrors, get, set, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
2721
+ export { Controller, Form, FormProvider, appendErrors, createFormControl, get, set, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
2670
2722
  //# sourceMappingURL=index.esm.js.map