@grafana/plugin-ui 0.16.1 → 0.17.1

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 (518) hide show
  1. package/dist/cjs/index.cjs +21907 -20495
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.d.cts +882 -554
  4. package/dist/cjs/test-utils.cjs +3979 -91
  5. package/dist/cjs/test-utils.cjs.map +1 -1
  6. package/dist/cjs/test-utils.d.cts +1 -1
  7. package/dist/esm/_virtual/chance2.js +2 -2
  8. package/dist/esm/async-query-data/DatasourceWithAsyncBackend.js +7 -7
  9. package/dist/esm/async-query-data/DatasourceWithAsyncBackend.js.map +1 -1
  10. package/dist/esm/async-query-data/RunQueryButtons.js +4 -4
  11. package/dist/esm/async-query-data/RunQueryButtons.js.map +1 -1
  12. package/dist/esm/async-query-data/requestLooper.js +6 -6
  13. package/dist/esm/async-query-data/requestLooper.js.map +1 -1
  14. package/dist/esm/components/ConfigEditor/AdvancedSettings/AdvancedHttpSettings.js.map +1 -1
  15. package/dist/esm/components/ConfigEditor/Auth/Auth.js.map +1 -1
  16. package/dist/esm/components/ConfigEditor/Auth/auth-method/AuthMethodSettings.js +7 -7
  17. package/dist/esm/components/ConfigEditor/Auth/auth-method/AuthMethodSettings.js.map +1 -1
  18. package/dist/esm/components/ConfigEditor/Auth/auth-method/BasicAuth.js.map +1 -1
  19. package/dist/esm/components/ConfigEditor/Auth/custom-headers/CustomHeader.js.map +1 -1
  20. package/dist/esm/components/ConfigEditor/Auth/custom-headers/CustomHeaders.js +1 -1
  21. package/dist/esm/components/ConfigEditor/Auth/custom-headers/CustomHeaders.js.map +1 -1
  22. package/dist/esm/components/ConfigEditor/Auth/styles.js.map +1 -1
  23. package/dist/esm/components/ConfigEditor/Auth/tls/SelfSignedCertificate.js +1 -1
  24. package/dist/esm/components/ConfigEditor/Auth/tls/SelfSignedCertificate.js.map +1 -1
  25. package/dist/esm/components/ConfigEditor/Auth/tls/SkipTLSVerification.js.map +1 -1
  26. package/dist/esm/components/ConfigEditor/Auth/tls/TLSClientAuth.js +3 -3
  27. package/dist/esm/components/ConfigEditor/Auth/tls/TLSClientAuth.js.map +1 -1
  28. package/dist/esm/components/ConfigEditor/Auth/tls/TLSSettings.js.map +1 -1
  29. package/dist/esm/components/ConfigEditor/Auth/tls/TLSSettingsSection.js.map +1 -1
  30. package/dist/esm/components/ConfigEditor/Auth/types.js.map +1 -1
  31. package/dist/esm/components/ConfigEditor/Auth/utils.js +3 -3
  32. package/dist/esm/components/ConfigEditor/Auth/utils.js.map +1 -1
  33. package/dist/esm/components/ConfigEditor/ConfigSection/ConfigDescriptionLink.js +2 -2
  34. package/dist/esm/components/ConfigEditor/ConfigSection/ConfigDescriptionLink.js.map +1 -1
  35. package/dist/esm/components/ConfigEditor/ConfigSection/ConfigSection.js.map +1 -1
  36. package/dist/esm/components/ConfigEditor/ConfigSection/ConfigSubSection.js.map +1 -1
  37. package/dist/esm/components/ConfigEditor/ConfigSection/GenericConfigSection.js.map +1 -1
  38. package/dist/esm/components/ConfigEditor/Connection/ConnectionSettings.js +1 -1
  39. package/dist/esm/components/ConfigEditor/Connection/ConnectionSettings.js.map +1 -1
  40. package/dist/esm/components/ConfigEditor/DataSourceDescription.js.map +1 -1
  41. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/DatasourceConfigWizard.js +23 -0
  42. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/DatasourceConfigWizard.js.map +1 -0
  43. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/DatasourceErrorBoundary.js +27 -0
  44. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/DatasourceErrorBoundary.js.map +1 -0
  45. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/SchemaField.js +61 -0
  46. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/SchemaField.js.map +1 -0
  47. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/WizardLayout.js +89 -0
  48. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/WizardLayout.js.map +1 -0
  49. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/cel.js +75 -0
  50. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/cel.js.map +1 -0
  51. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/config.js +262 -0
  52. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/config.js.map +1 -0
  53. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/datasource.js +354 -0
  54. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/datasource.js.map +1 -0
  55. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/hooks/formInterpreter.js +93 -0
  56. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/hooks/formInterpreter.js.map +1 -0
  57. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/hooks/useDatasourceConfigForm.js +254 -0
  58. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/hooks/useDatasourceConfigForm.js.map +1 -0
  59. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/hooks/useHealthChecks.js +106 -0
  60. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/hooks/useHealthChecks.js.map +1 -0
  61. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/AuthorizationHeaderField.js +52 -0
  62. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/AuthorizationHeaderField.js.map +1 -0
  63. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/ComplexFieldNote.js +32 -0
  64. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/ComplexFieldNote.js.map +1 -0
  65. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/FieldInput.js +110 -0
  66. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/FieldInput.js.map +1 -0
  67. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/FileUploadField.js +112 -0
  68. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/FileUploadField.js.map +1 -0
  69. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/IndexedPairEditor.js +140 -0
  70. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/IndexedPairEditor.js.map +1 -0
  71. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/ObjectArrayEditor.js +201 -0
  72. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/ObjectArrayEditor.js.map +1 -0
  73. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/PrimitiveInputs.js +103 -0
  74. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/PrimitiveInputs.js.map +1 -0
  75. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/SecureFieldInput.js +72 -0
  76. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/SecureFieldInput.js.map +1 -0
  77. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/StringArrayInput.js +94 -0
  78. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/StringArrayInput.js.map +1 -0
  79. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/fieldUtils.js +138 -0
  80. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/inputs/fieldUtils.js.map +1 -0
  81. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/layoutParts.js +82 -0
  82. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/layoutParts.js.map +1 -0
  83. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/resolvePluginName.js +30 -0
  84. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/resolvePluginName.js.map +1 -0
  85. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/styles.js +128 -0
  86. package/dist/esm/components/ConfigEditor/DatasourceConfigWizard/styles.js.map +1 -0
  87. package/dist/esm/components/ConfigEditor/SecureSocksProxyToggle.js.map +1 -1
  88. package/dist/esm/components/CustomHeadersSettings/CustomHeadersSettings.js +11 -11
  89. package/dist/esm/components/CustomHeadersSettings/CustomHeadersSettings.js.map +1 -1
  90. package/dist/esm/components/DataLinks/DataLink.js +5 -4
  91. package/dist/esm/components/DataLinks/DataLink.js.map +1 -1
  92. package/dist/esm/components/DataLinks/DataLinks.js +3 -3
  93. package/dist/esm/components/DataLinks/DataLinks.js.map +1 -1
  94. package/dist/esm/components/DataSourcePicker/DataSourcePicker.js +10 -10
  95. package/dist/esm/components/DataSourcePicker/DataSourcePicker.js.map +1 -1
  96. package/dist/esm/components/DatePicker/DatePicker.js.map +1 -1
  97. package/dist/esm/components/DatePicker/styles.js +2 -2
  98. package/dist/esm/components/DatePicker/styles.js.map +1 -1
  99. package/dist/esm/components/DatePickerWithInput/DatePickerWithInput.js.map +1 -1
  100. package/dist/esm/components/DatePickerWithInput/styles.js +2 -2
  101. package/dist/esm/components/DatePickerWithInput/styles.js.map +1 -1
  102. package/dist/esm/components/DebounceInput/DebounceInput.js.map +1 -1
  103. package/dist/esm/components/Plugins/PluginSignatureBadge.js.map +1 -1
  104. package/dist/esm/components/QueryEditor/AccessoryButton.js.map +1 -1
  105. package/dist/esm/components/QueryEditor/CatalogSelector.js +1 -1
  106. package/dist/esm/components/QueryEditor/CatalogSelector.js.map +1 -1
  107. package/dist/esm/components/QueryEditor/ConfirmModal.js +2 -1
  108. package/dist/esm/components/QueryEditor/ConfirmModal.js.map +1 -1
  109. package/dist/esm/components/QueryEditor/DatasetSelector.js +1 -1
  110. package/dist/esm/components/QueryEditor/DatasetSelector.js.map +1 -1
  111. package/dist/esm/components/QueryEditor/EditorField.js +5 -5
  112. package/dist/esm/components/QueryEditor/EditorField.js.map +1 -1
  113. package/dist/esm/components/QueryEditor/EditorFieldGroup.js.map +1 -1
  114. package/dist/esm/components/QueryEditor/EditorHeader.js +2 -2
  115. package/dist/esm/components/QueryEditor/EditorHeader.js.map +1 -1
  116. package/dist/esm/components/QueryEditor/EditorList.js.map +1 -1
  117. package/dist/esm/components/QueryEditor/EditorRow.js +4 -4
  118. package/dist/esm/components/QueryEditor/EditorRow.js.map +1 -1
  119. package/dist/esm/components/QueryEditor/EditorRows.js +2 -2
  120. package/dist/esm/components/QueryEditor/EditorRows.js.map +1 -1
  121. package/dist/esm/components/QueryEditor/EditorStack.js +1 -1
  122. package/dist/esm/components/QueryEditor/EditorStack.js.map +1 -1
  123. package/dist/esm/components/QueryEditor/EditorSwitch.js +2 -2
  124. package/dist/esm/components/QueryEditor/EditorSwitch.js.map +1 -1
  125. package/dist/esm/components/QueryEditor/FlexItem.js.map +1 -1
  126. package/dist/esm/components/QueryEditor/InlineSelect.js.map +1 -1
  127. package/dist/esm/components/QueryEditor/InputGroup.js +2 -2
  128. package/dist/esm/components/QueryEditor/InputGroup.js.map +1 -1
  129. package/dist/esm/components/QueryEditor/QueryEditor.js +7 -7
  130. package/dist/esm/components/QueryEditor/QueryEditor.js.map +1 -1
  131. package/dist/esm/components/QueryEditor/QueryEditorRow.js.map +1 -0
  132. package/dist/esm/components/QueryEditor/QueryHeader.js +18 -18
  133. package/dist/esm/components/QueryEditor/QueryHeader.js.map +1 -1
  134. package/dist/esm/components/QueryEditor/RunQueryButton.js +1 -1
  135. package/dist/esm/components/QueryEditor/RunQueryButton.js.map +1 -1
  136. package/dist/esm/components/QueryEditor/Space.js +2 -2
  137. package/dist/esm/components/QueryEditor/Space.js.map +1 -1
  138. package/dist/esm/components/QueryEditor/TableSelector.js.map +1 -1
  139. package/dist/esm/components/QueryEditor/defaults.js +7 -7
  140. package/dist/esm/components/QueryEditor/defaults.js.map +1 -1
  141. package/dist/esm/components/QueryEditor/expressions.js.map +1 -1
  142. package/dist/esm/components/QueryEditor/query-editor-raw/QueryEditorRaw.js.map +1 -1
  143. package/dist/esm/components/QueryEditor/query-editor-raw/QueryToolbox.js +4 -4
  144. package/dist/esm/components/QueryEditor/query-editor-raw/QueryToolbox.js.map +1 -1
  145. package/dist/esm/components/QueryEditor/query-editor-raw/QueryValidator.js +4 -4
  146. package/dist/esm/components/QueryEditor/query-editor-raw/QueryValidator.js.map +1 -1
  147. package/dist/esm/components/QueryEditor/query-editor-raw/RawEditor.js +3 -3
  148. package/dist/esm/components/QueryEditor/query-editor-raw/RawEditor.js.map +1 -1
  149. package/dist/esm/components/QueryEditor/types.js.map +1 -1
  150. package/dist/esm/components/QueryEditor/utils/formatSQL.js.map +1 -1
  151. package/dist/esm/components/QueryEditor/utils/sql.utils.js +8 -8
  152. package/dist/esm/components/QueryEditor/utils/sql.utils.js.map +1 -1
  153. package/dist/esm/components/QueryEditor/utils/useSqlChange.js.map +1 -1
  154. package/dist/esm/components/QueryEditor/visual-query-builder/AwesomeQueryBuilder.js +28 -27
  155. package/dist/esm/components/QueryEditor/visual-query-builder/AwesomeQueryBuilder.js.map +1 -1
  156. package/dist/esm/components/QueryEditor/visual-query-builder/EditorField.js +3 -3
  157. package/dist/esm/components/QueryEditor/visual-query-builder/EditorField.js.map +1 -1
  158. package/dist/esm/components/QueryEditor/visual-query-builder/EditorRow.js +2 -2
  159. package/dist/esm/components/QueryEditor/visual-query-builder/EditorRow.js.map +1 -1
  160. package/dist/esm/components/QueryEditor/visual-query-builder/EditorRows.js.map +1 -1
  161. package/dist/esm/components/QueryEditor/visual-query-builder/GroupByRow.js +2 -2
  162. package/dist/esm/components/QueryEditor/visual-query-builder/GroupByRow.js.map +1 -1
  163. package/dist/esm/components/QueryEditor/visual-query-builder/OrderByRow.js +4 -4
  164. package/dist/esm/components/QueryEditor/visual-query-builder/OrderByRow.js.map +1 -1
  165. package/dist/esm/components/QueryEditor/visual-query-builder/Preview.js +2 -2
  166. package/dist/esm/components/QueryEditor/visual-query-builder/Preview.js.map +1 -1
  167. package/dist/esm/components/QueryEditor/visual-query-builder/SQLGroupByRow.js.map +1 -1
  168. package/dist/esm/components/QueryEditor/visual-query-builder/SQLOrderByRow.js +2 -2
  169. package/dist/esm/components/QueryEditor/visual-query-builder/SQLOrderByRow.js.map +1 -1
  170. package/dist/esm/components/QueryEditor/visual-query-builder/SQLSelectRow.js.map +1 -1
  171. package/dist/esm/components/QueryEditor/visual-query-builder/SQLWhereRow.js.map +1 -1
  172. package/dist/esm/components/QueryEditor/visual-query-builder/SelectRow.js +9 -9
  173. package/dist/esm/components/QueryEditor/visual-query-builder/SelectRow.js.map +1 -1
  174. package/dist/esm/components/QueryEditor/visual-query-builder/VisualEditor.js.map +1 -1
  175. package/dist/esm/components/QueryEditor/visual-query-builder/WhereRow.js.map +1 -1
  176. package/dist/esm/components/SQLEditor/components/SQLEditor.js +13 -13
  177. package/dist/esm/components/SQLEditor/components/SQLEditor.js.map +1 -1
  178. package/dist/esm/components/SQLEditor/hooks/useLatestCallback.js +1 -1
  179. package/dist/esm/components/SQLEditor/hooks/useLatestCallback.js.map +1 -1
  180. package/dist/esm/components/SQLEditor/mocks/Monaco.js.map +1 -1
  181. package/dist/esm/components/SQLEditor/mocks/TextModel.js.map +1 -1
  182. package/dist/esm/components/SQLEditor/mocks/queries/multiLineFullQuery.js.map +1 -1
  183. package/dist/esm/components/SQLEditor/mocks/queries/multiLineFullQueryWithAggregation.js.map +1 -1
  184. package/dist/esm/components/SQLEditor/mocks/queries/multiLineMultipleColumns.js.map +1 -1
  185. package/dist/esm/components/SQLEditor/mocks/queries/singleLineEmptyQuery.js.map +1 -1
  186. package/dist/esm/components/SQLEditor/mocks/queries/singleLineFullQuery.js.map +1 -1
  187. package/dist/esm/components/SQLEditor/mocks/queries/singleLineFullQueryWithAggregation.js.map +1 -1
  188. package/dist/esm/components/SQLEditor/mocks/queries/singleLineMultipleColumns.js.map +1 -1
  189. package/dist/esm/components/SQLEditor/mocks/queries/singleLineTwoQueries.js.map +1 -1
  190. package/dist/esm/components/SQLEditor/mocks/queries/singleLineTwoQueriesWithAggregation.js.map +1 -1
  191. package/dist/esm/components/SQLEditor/standardSql/definition.js.map +1 -1
  192. package/dist/esm/components/SQLEditor/standardSql/getStandardSuggestions.js +2 -2
  193. package/dist/esm/components/SQLEditor/standardSql/getStandardSuggestions.js.map +1 -1
  194. package/dist/esm/components/SQLEditor/standardSql/getStatementPosition.js +3 -3
  195. package/dist/esm/components/SQLEditor/standardSql/getStatementPosition.js.map +1 -1
  196. package/dist/esm/components/SQLEditor/standardSql/language.js.map +1 -1
  197. package/dist/esm/components/SQLEditor/standardSql/macros.js.map +1 -1
  198. package/dist/esm/components/SQLEditor/standardSql/standardSQLCompletionItemProvider.js +2 -2
  199. package/dist/esm/components/SQLEditor/standardSql/standardSQLCompletionItemProvider.js.map +1 -1
  200. package/dist/esm/components/SQLEditor/standardSql/standardSuggestionsRegistry.js +1 -1
  201. package/dist/esm/components/SQLEditor/standardSql/standardSuggestionsRegistry.js.map +1 -1
  202. package/dist/esm/components/SQLEditor/standardSql/statementPositionResolversRegistry.js +25 -25
  203. package/dist/esm/components/SQLEditor/standardSql/statementPositionResolversRegistry.js.map +1 -1
  204. package/dist/esm/components/SQLEditor/standardSql/suggestionsKindRegistry.js +1 -1
  205. package/dist/esm/components/SQLEditor/standardSql/suggestionsKindRegistry.js.map +1 -1
  206. package/dist/esm/components/SQLEditor/test-utils/index.js.map +1 -1
  207. package/dist/esm/components/SQLEditor/test-utils/statementPosition.js.map +1 -1
  208. package/dist/esm/components/SQLEditor/types.js.map +1 -1
  209. package/dist/esm/components/SQLEditor/utils/LinkedToken.js +15 -12
  210. package/dist/esm/components/SQLEditor/utils/LinkedToken.js.map +1 -1
  211. package/dist/esm/components/SQLEditor/utils/commands.js.map +1 -1
  212. package/dist/esm/components/SQLEditor/utils/debugger.js +1 -1
  213. package/dist/esm/components/SQLEditor/utils/debugger.js.map +1 -1
  214. package/dist/esm/components/SQLEditor/utils/getSuggestionKind.js.map +1 -1
  215. package/dist/esm/components/SQLEditor/utils/linkedTokenBuilder.js +1 -1
  216. package/dist/esm/components/SQLEditor/utils/linkedTokenBuilder.js.map +1 -1
  217. package/dist/esm/components/SQLEditor/utils/toCompletionItem.js +1 -1
  218. package/dist/esm/components/SQLEditor/utils/toCompletionItem.js.map +1 -1
  219. package/dist/esm/components/SQLEditor/utils/tokenType.js.map +1 -1
  220. package/dist/esm/components/SQLEditor/utils/tokenUtils.js +9 -9
  221. package/dist/esm/components/SQLEditor/utils/tokenUtils.js.map +1 -1
  222. package/dist/esm/components/Segment/Segment.js.map +1 -1
  223. package/dist/esm/components/VisualQueryBuilder/QueryModellerBase.js +8 -8
  224. package/dist/esm/components/VisualQueryBuilder/QueryModellerBase.js.map +1 -1
  225. package/dist/esm/components/VisualQueryBuilder/components/LabelFilterItem.js +11 -11
  226. package/dist/esm/components/VisualQueryBuilder/components/LabelFilterItem.js.map +1 -1
  227. package/dist/esm/components/VisualQueryBuilder/components/LabelFilters.js +1 -1
  228. package/dist/esm/components/VisualQueryBuilder/components/LabelFilters.js.map +1 -1
  229. package/dist/esm/components/VisualQueryBuilder/components/OperationEditor.js +4 -4
  230. package/dist/esm/components/VisualQueryBuilder/components/OperationEditor.js.map +1 -1
  231. package/dist/esm/components/VisualQueryBuilder/components/OperationEditorBody.js +3 -2
  232. package/dist/esm/components/VisualQueryBuilder/components/OperationEditorBody.js.map +1 -1
  233. package/dist/esm/components/VisualQueryBuilder/components/OperationExplainedBox.js +3 -3
  234. package/dist/esm/components/VisualQueryBuilder/components/OperationExplainedBox.js.map +1 -1
  235. package/dist/esm/components/VisualQueryBuilder/components/OperationHeader.js +8 -5
  236. package/dist/esm/components/VisualQueryBuilder/components/OperationHeader.js.map +1 -1
  237. package/dist/esm/components/VisualQueryBuilder/components/OperationInfoButton.js +5 -3
  238. package/dist/esm/components/VisualQueryBuilder/components/OperationInfoButton.js.map +1 -1
  239. package/dist/esm/components/VisualQueryBuilder/components/OperationList.js +3 -3
  240. package/dist/esm/components/VisualQueryBuilder/components/OperationList.js.map +1 -1
  241. package/dist/esm/components/VisualQueryBuilder/components/OperationListExplained.js +2 -2
  242. package/dist/esm/components/VisualQueryBuilder/components/OperationListExplained.js.map +1 -1
  243. package/dist/esm/components/VisualQueryBuilder/components/OperationParamEditor.js +6 -5
  244. package/dist/esm/components/VisualQueryBuilder/components/OperationParamEditor.js.map +1 -1
  245. package/dist/esm/components/VisualQueryBuilder/components/OperationsEditorRow.js +2 -2
  246. package/dist/esm/components/VisualQueryBuilder/components/OperationsEditorRow.js.map +1 -1
  247. package/dist/esm/components/VisualQueryBuilder/components/QueryBuilderHints.js +8 -8
  248. package/dist/esm/components/VisualQueryBuilder/components/QueryBuilderHints.js.map +1 -1
  249. package/dist/esm/components/VisualQueryBuilder/components/QueryEditorModeToggle.js.map +1 -1
  250. package/dist/esm/components/VisualQueryBuilder/components/QueryHeaderSwitch.js +2 -2
  251. package/dist/esm/components/VisualQueryBuilder/components/QueryHeaderSwitch.js.map +1 -1
  252. package/dist/esm/components/VisualQueryBuilder/components/QueryOptionGroup.js.map +1 -1
  253. package/dist/esm/components/VisualQueryBuilder/components/RawQuery.js +2 -2
  254. package/dist/esm/components/VisualQueryBuilder/components/RawQuery.js.map +1 -1
  255. package/dist/esm/components/VisualQueryBuilder/types.js.map +1 -1
  256. package/dist/esm/datasource/SqlDatasource.js +17 -16
  257. package/dist/esm/datasource/SqlDatasource.js.map +1 -1
  258. package/dist/esm/datasource/constants.js.map +1 -1
  259. package/dist/esm/hooks/useDebounce.js.map +1 -1
  260. package/dist/esm/index.d.ts +882 -554
  261. package/dist/esm/index.js +11 -3
  262. package/dist/esm/index.js.map +1 -1
  263. package/dist/esm/node_modules/chance/chance.js +3973 -88
  264. package/dist/esm/node_modules/chance/chance.js.map +1 -1
  265. package/dist/esm/node_modules/immutable/dist/immutable.es.js +6186 -0
  266. package/dist/esm/node_modules/immutable/dist/immutable.es.js.map +1 -0
  267. package/dist/esm/node_modules/js-yaml/dist/js-yaml.js +3059 -0
  268. package/dist/esm/node_modules/js-yaml/dist/js-yaml.js.map +1 -0
  269. package/dist/esm/node_modules/react-hook-form/dist/index.esm.js +2798 -0
  270. package/dist/esm/node_modules/react-hook-form/dist/index.esm.js.map +1 -0
  271. package/dist/esm/node_modules/rxjs/dist/esm5/internal/Observable.js +2 -2
  272. package/dist/esm/node_modules/rxjs/dist/esm5/internal/Observable.js.map +1 -1
  273. package/dist/esm/node_modules/rxjs/dist/esm5/internal/Subscriber.js +3 -3
  274. package/dist/esm/node_modules/rxjs/dist/esm5/internal/Subscriber.js.map +1 -1
  275. package/dist/esm/node_modules/rxjs/dist/esm5/internal/Subscription.js +1 -1
  276. package/dist/esm/node_modules/rxjs/dist/esm5/internal/Subscription.js.map +1 -1
  277. package/dist/esm/node_modules/rxjs/dist/esm5/internal/config.js +1 -6
  278. package/dist/esm/node_modules/rxjs/dist/esm5/internal/config.js.map +1 -1
  279. package/dist/esm/node_modules/rxjs/dist/esm5/internal/lastValueFrom.js.map +1 -1
  280. package/dist/esm/node_modules/rxjs/dist/esm5/internal/observable/empty.js.map +1 -1
  281. package/dist/esm/node_modules/rxjs/dist/esm5/internal/observable/innerFrom.js +3 -3
  282. package/dist/esm/node_modules/rxjs/dist/esm5/internal/observable/innerFrom.js.map +1 -1
  283. package/dist/esm/node_modules/rxjs/dist/esm5/internal/observable/merge.js +2 -2
  284. package/dist/esm/node_modules/rxjs/dist/esm5/internal/observable/merge.js.map +1 -1
  285. package/dist/esm/node_modules/rxjs/dist/esm5/internal/observable/of.js.map +1 -1
  286. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/OperatorSubscriber.js +1 -1
  287. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/OperatorSubscriber.js.map +1 -1
  288. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/catchError.js.map +1 -1
  289. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/map.js +2 -2
  290. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/map.js.map +1 -1
  291. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/mergeAll.js +1 -1
  292. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/mergeAll.js.map +1 -1
  293. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/mergeInternals.js.map +1 -1
  294. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/mergeMap.js +1 -1
  295. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/mergeMap.js.map +1 -1
  296. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/observeOn.js +1 -1
  297. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/observeOn.js.map +1 -1
  298. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/subscribeOn.js +1 -1
  299. package/dist/esm/node_modules/rxjs/dist/esm5/internal/operators/subscribeOn.js.map +1 -1
  300. package/dist/esm/node_modules/rxjs/dist/esm5/internal/scheduled/scheduleArray.js.map +1 -1
  301. package/dist/esm/node_modules/rxjs/dist/esm5/internal/scheduled/scheduleAsyncIterable.js.map +1 -1
  302. package/dist/esm/node_modules/rxjs/dist/esm5/internal/scheduled/scheduleIterable.js +1 -1
  303. package/dist/esm/node_modules/rxjs/dist/esm5/internal/scheduled/scheduleIterable.js.map +1 -1
  304. package/dist/esm/node_modules/rxjs/dist/esm5/internal/scheduled/scheduled.js.map +1 -1
  305. package/dist/esm/node_modules/rxjs/dist/esm5/internal/scheduler/timeoutProvider.js +1 -1
  306. package/dist/esm/node_modules/rxjs/dist/esm5/internal/scheduler/timeoutProvider.js.map +1 -1
  307. package/dist/esm/node_modules/rxjs/dist/esm5/internal/symbol/iterator.js.map +1 -1
  308. package/dist/esm/node_modules/rxjs/dist/esm5/internal/symbol/observable.js.map +1 -1
  309. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/EmptyError.js +7 -5
  310. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/EmptyError.js.map +1 -1
  311. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/UnsubscriptionError.js.map +1 -1
  312. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/arrRemove.js.map +1 -1
  313. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js.map +1 -1
  314. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/errorContext.js.map +1 -1
  315. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/executeSchedule.js +2 -2
  316. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/executeSchedule.js.map +1 -1
  317. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/isArrayLike.js.map +1 -1
  318. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/isAsyncIterable.js +1 -1
  319. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/isAsyncIterable.js.map +1 -1
  320. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/isFunction.js +2 -2
  321. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/isFunction.js.map +1 -1
  322. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/isIterable.js +1 -1
  323. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/isIterable.js.map +1 -1
  324. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/isPromise.js +1 -1
  325. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/isPromise.js.map +1 -1
  326. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/isReadableStreamLike.js +2 -2
  327. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/isReadableStreamLike.js.map +1 -1
  328. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/lift.js +1 -1
  329. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/lift.js.map +1 -1
  330. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/noop.js.map +1 -1
  331. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/pipe.js.map +1 -1
  332. package/dist/esm/node_modules/rxjs/dist/esm5/internal/util/reportUnhandledError.js.map +1 -1
  333. package/dist/esm/node_modules/semver/classes/comparator.js.map +1 -1
  334. package/dist/esm/node_modules/semver/classes/range.js +24 -4
  335. package/dist/esm/node_modules/semver/classes/range.js.map +1 -1
  336. package/dist/esm/node_modules/semver/classes/semver.js +27 -10
  337. package/dist/esm/node_modules/semver/classes/semver.js.map +1 -1
  338. package/dist/esm/node_modules/semver/functions/clean.js.map +1 -1
  339. package/dist/esm/node_modules/semver/functions/cmp.js.map +1 -1
  340. package/dist/esm/node_modules/semver/functions/coerce.js.map +1 -1
  341. package/dist/esm/node_modules/semver/functions/compare-build.js.map +1 -1
  342. package/dist/esm/node_modules/semver/functions/diff.js +1 -1
  343. package/dist/esm/node_modules/semver/functions/diff.js.map +1 -1
  344. package/dist/esm/node_modules/semver/functions/inc.js.map +1 -1
  345. package/dist/esm/node_modules/semver/functions/parse.js.map +1 -1
  346. package/dist/esm/node_modules/semver/functions/prerelease.js.map +1 -1
  347. package/dist/esm/node_modules/semver/functions/satisfies.js.map +1 -1
  348. package/dist/esm/node_modules/semver/functions/truncate.js +62 -0
  349. package/dist/esm/node_modules/semver/functions/truncate.js.map +1 -0
  350. package/dist/esm/node_modules/semver/functions/valid.js +5 -5
  351. package/dist/esm/node_modules/semver/functions/valid.js.map +1 -1
  352. package/dist/esm/node_modules/semver/index.js +3 -0
  353. package/dist/esm/node_modules/semver/index.js.map +1 -1
  354. package/dist/esm/node_modules/semver/internal/debug.js.map +1 -1
  355. package/dist/esm/node_modules/semver/internal/identifiers.js.map +1 -1
  356. package/dist/esm/node_modules/semver/internal/lrucache.js.map +1 -1
  357. package/dist/esm/node_modules/semver/internal/parse-options.js.map +1 -1
  358. package/dist/esm/node_modules/semver/internal/re.js +13 -13
  359. package/dist/esm/node_modules/semver/internal/re.js.map +1 -1
  360. package/dist/esm/node_modules/semver/ranges/intersects.js.map +1 -1
  361. package/dist/esm/node_modules/semver/ranges/max-satisfying.js.map +1 -1
  362. package/dist/esm/node_modules/semver/ranges/min-satisfying.js.map +1 -1
  363. package/dist/esm/node_modules/semver/ranges/min-version.js.map +1 -1
  364. package/dist/esm/node_modules/semver/ranges/outside.js.map +1 -1
  365. package/dist/esm/node_modules/semver/ranges/simplify.js.map +1 -1
  366. package/dist/esm/node_modules/semver/ranges/subset.js +3 -3
  367. package/dist/esm/node_modules/semver/ranges/subset.js.map +1 -1
  368. package/dist/esm/node_modules/semver/ranges/valid.js.map +1 -1
  369. package/dist/esm/node_modules/tslib/tslib.es6.js +2 -2
  370. package/dist/esm/node_modules/tslib/tslib.es6.js.map +1 -1
  371. package/dist/esm/schema/utils/dsconfig.js +97 -0
  372. package/dist/esm/schema/utils/dsconfig.js.map +1 -0
  373. package/dist/esm/schema/utils/llm.js +54 -0
  374. package/dist/esm/schema/utils/llm.js.map +1 -0
  375. package/dist/esm/schema/utils/provisioning.js +389 -0
  376. package/dist/esm/schema/utils/provisioning.js.map +1 -0
  377. package/dist/esm/schema/utils/registry.js +31 -0
  378. package/dist/esm/schema/utils/registry.js.map +1 -0
  379. package/dist/esm/test/mocks/DataQuery.js.map +1 -1
  380. package/dist/esm/test/mocks/Datasource.js +1 -1
  381. package/dist/esm/test/mocks/Datasource.js.map +1 -1
  382. package/dist/esm/test/mocks/Plugin.js +5 -2
  383. package/dist/esm/test/mocks/Plugin.js.map +1 -1
  384. package/dist/esm/test/mocks/QueryEditorProps.js.map +1 -1
  385. package/dist/esm/test/mocks/utils.js +2 -2
  386. package/dist/esm/test/mocks/utils.js.map +1 -1
  387. package/dist/esm/test-utils.d.ts +1 -1
  388. package/package.json +67 -66
  389. package/dist/esm/components/QueryEditorRow/QueryEditorRow.js.map +0 -1
  390. package/dist/esm/schema/registry/alertmanager.schema.json.js +0 -77
  391. package/dist/esm/schema/registry/alertmanager.schema.json.js.map +0 -1
  392. package/dist/esm/schema/registry/cloudwatch.schema.json.js +0 -384
  393. package/dist/esm/schema/registry/cloudwatch.schema.json.js.map +0 -1
  394. package/dist/esm/schema/registry/elasticsearch.schema.json.js +0 -287
  395. package/dist/esm/schema/registry/elasticsearch.schema.json.js.map +0 -1
  396. package/dist/esm/schema/registry/grafana-amazonprometheus-datasource.schema.json.js +0 -166
  397. package/dist/esm/schema/registry/grafana-amazonprometheus-datasource.schema.json.js.map +0 -1
  398. package/dist/esm/schema/registry/grafana-appdynamics-datasource.schema.json.js +0 -145
  399. package/dist/esm/schema/registry/grafana-appdynamics-datasource.schema.json.js.map +0 -1
  400. package/dist/esm/schema/registry/grafana-astradb-datasource.schema.json.js +0 -123
  401. package/dist/esm/schema/registry/grafana-astradb-datasource.schema.json.js.map +0 -1
  402. package/dist/esm/schema/registry/grafana-athena-datasource.schema.json.js +0 -158
  403. package/dist/esm/schema/registry/grafana-athena-datasource.schema.json.js.map +0 -1
  404. package/dist/esm/schema/registry/grafana-azure-data-explorer-datasource.schema.json.js +0 -204
  405. package/dist/esm/schema/registry/grafana-azure-data-explorer-datasource.schema.json.js.map +0 -1
  406. package/dist/esm/schema/registry/grafana-azure-monitor-datasource.schema.json.js +0 -294
  407. package/dist/esm/schema/registry/grafana-azure-monitor-datasource.schema.json.js.map +0 -1
  408. package/dist/esm/schema/registry/grafana-azuredevops-datasource.schema.json.js +0 -101
  409. package/dist/esm/schema/registry/grafana-azuredevops-datasource.schema.json.js.map +0 -1
  410. package/dist/esm/schema/registry/grafana-azureprometheus-datasource.schema.json.js +0 -125
  411. package/dist/esm/schema/registry/grafana-azureprometheus-datasource.schema.json.js.map +0 -1
  412. package/dist/esm/schema/registry/grafana-bigquery-datasource.schema.json.js +0 -508
  413. package/dist/esm/schema/registry/grafana-bigquery-datasource.schema.json.js.map +0 -1
  414. package/dist/esm/schema/registry/grafana-clickhouse-datasource.schema.json.js +0 -1400
  415. package/dist/esm/schema/registry/grafana-clickhouse-datasource.schema.json.js.map +0 -1
  416. package/dist/esm/schema/registry/grafana-cockroachdb-datasource.schema.json.js +0 -302
  417. package/dist/esm/schema/registry/grafana-cockroachdb-datasource.schema.json.js.map +0 -1
  418. package/dist/esm/schema/registry/grafana-databricks-datasource.schema.json.js +0 -291
  419. package/dist/esm/schema/registry/grafana-databricks-datasource.schema.json.js.map +0 -1
  420. package/dist/esm/schema/registry/grafana-datadog-datasource.schema.json.js +0 -155
  421. package/dist/esm/schema/registry/grafana-datadog-datasource.schema.json.js.map +0 -1
  422. package/dist/esm/schema/registry/grafana-dynatrace-datasource.schema.json.js +0 -179
  423. package/dist/esm/schema/registry/grafana-dynatrace-datasource.schema.json.js.map +0 -1
  424. package/dist/esm/schema/registry/grafana-falconlogscale-datasource.schema.json.js +0 -134
  425. package/dist/esm/schema/registry/grafana-falconlogscale-datasource.schema.json.js.map +0 -1
  426. package/dist/esm/schema/registry/grafana-github-datasource.schema.json.js +0 -156
  427. package/dist/esm/schema/registry/grafana-github-datasource.schema.json.js.map +0 -1
  428. package/dist/esm/schema/registry/grafana-gitlab-datasource.schema.json.js +0 -84
  429. package/dist/esm/schema/registry/grafana-gitlab-datasource.schema.json.js.map +0 -1
  430. package/dist/esm/schema/registry/grafana-googlesheets-datasource.schema.json.js +0 -231
  431. package/dist/esm/schema/registry/grafana-googlesheets-datasource.schema.json.js.map +0 -1
  432. package/dist/esm/schema/registry/grafana-honeycomb-datasource.schema.json.js +0 -87
  433. package/dist/esm/schema/registry/grafana-honeycomb-datasource.schema.json.js.map +0 -1
  434. package/dist/esm/schema/registry/grafana-iot-sitewise-datasource.schema.json.js +0 -159
  435. package/dist/esm/schema/registry/grafana-iot-sitewise-datasource.schema.json.js.map +0 -1
  436. package/dist/esm/schema/registry/grafana-jira-datasource.schema.json.js +0 -188
  437. package/dist/esm/schema/registry/grafana-jira-datasource.schema.json.js.map +0 -1
  438. package/dist/esm/schema/registry/grafana-looker-datasource.schema.json.js +0 -82
  439. package/dist/esm/schema/registry/grafana-looker-datasource.schema.json.js.map +0 -1
  440. package/dist/esm/schema/registry/grafana-mongodb-datasource.schema.json.js +0 -278
  441. package/dist/esm/schema/registry/grafana-mongodb-datasource.schema.json.js.map +0 -1
  442. package/dist/esm/schema/registry/grafana-mqtt-datasource.schema.json.js +0 -168
  443. package/dist/esm/schema/registry/grafana-mqtt-datasource.schema.json.js.map +0 -1
  444. package/dist/esm/schema/registry/grafana-newrelic-datasource.schema.json.js +0 -129
  445. package/dist/esm/schema/registry/grafana-newrelic-datasource.schema.json.js.map +0 -1
  446. package/dist/esm/schema/registry/grafana-odbc-datasource.schema.json.js +0 -56
  447. package/dist/esm/schema/registry/grafana-odbc-datasource.schema.json.js.map +0 -1
  448. package/dist/esm/schema/registry/grafana-opensearch-datasource.schema.json.js +0 -212
  449. package/dist/esm/schema/registry/grafana-opensearch-datasource.schema.json.js.map +0 -1
  450. package/dist/esm/schema/registry/grafana-oracle-datasource.schema.json.js +0 -186
  451. package/dist/esm/schema/registry/grafana-oracle-datasource.schema.json.js.map +0 -1
  452. package/dist/esm/schema/registry/grafana-pagerduty-datasource.schema.json.js +0 -85
  453. package/dist/esm/schema/registry/grafana-pagerduty-datasource.schema.json.js.map +0 -1
  454. package/dist/esm/schema/registry/grafana-postgresql-datasource.schema.json.js +0 -411
  455. package/dist/esm/schema/registry/grafana-postgresql-datasource.schema.json.js.map +0 -1
  456. package/dist/esm/schema/registry/grafana-pyroscope-datasource.schema.json.js +0 -41
  457. package/dist/esm/schema/registry/grafana-pyroscope-datasource.schema.json.js.map +0 -1
  458. package/dist/esm/schema/registry/grafana-redshift-datasource.schema.json.js +0 -201
  459. package/dist/esm/schema/registry/grafana-redshift-datasource.schema.json.js.map +0 -1
  460. package/dist/esm/schema/registry/grafana-salesforce-datasource.schema.json.js +0 -201
  461. package/dist/esm/schema/registry/grafana-salesforce-datasource.schema.json.js.map +0 -1
  462. package/dist/esm/schema/registry/grafana-saphana-datasource.schema.json.js +0 -208
  463. package/dist/esm/schema/registry/grafana-saphana-datasource.schema.json.js.map +0 -1
  464. package/dist/esm/schema/registry/grafana-sentry-datasource.schema.json.js +0 -94
  465. package/dist/esm/schema/registry/grafana-sentry-datasource.schema.json.js.map +0 -1
  466. package/dist/esm/schema/registry/grafana-servicenow-datasource.schema.json.js +0 -179
  467. package/dist/esm/schema/registry/grafana-servicenow-datasource.schema.json.js.map +0 -1
  468. package/dist/esm/schema/registry/grafana-snowflake-datasource.schema.json.js +0 -304
  469. package/dist/esm/schema/registry/grafana-snowflake-datasource.schema.json.js.map +0 -1
  470. package/dist/esm/schema/registry/grafana-splunk-datasource.schema.json.js +0 -319
  471. package/dist/esm/schema/registry/grafana-splunk-datasource.schema.json.js.map +0 -1
  472. package/dist/esm/schema/registry/grafana-splunkobservability-datasource.schema.json.js +0 -90
  473. package/dist/esm/schema/registry/grafana-splunkobservability-datasource.schema.json.js.map +0 -1
  474. package/dist/esm/schema/registry/grafana-strava-datasource.schema.json.js +0 -74
  475. package/dist/esm/schema/registry/grafana-strava-datasource.schema.json.js.map +0 -1
  476. package/dist/esm/schema/registry/grafana-sumologic-datasource.schema.json.js +0 -102
  477. package/dist/esm/schema/registry/grafana-sumologic-datasource.schema.json.js.map +0 -1
  478. package/dist/esm/schema/registry/grafana-surrealdb-datasource.schema.json.js +0 -92
  479. package/dist/esm/schema/registry/grafana-surrealdb-datasource.schema.json.js.map +0 -1
  480. package/dist/esm/schema/registry/grafana-timestream-datasource.schema.json.js +0 -145
  481. package/dist/esm/schema/registry/grafana-timestream-datasource.schema.json.js.map +0 -1
  482. package/dist/esm/schema/registry/grafana-wavefront-datasource.schema.json.js +0 -80
  483. package/dist/esm/schema/registry/grafana-wavefront-datasource.schema.json.js.map +0 -1
  484. package/dist/esm/schema/registry/grafana-x-ray-datasource.schema.json.js +0 -112
  485. package/dist/esm/schema/registry/grafana-x-ray-datasource.schema.json.js.map +0 -1
  486. package/dist/esm/schema/registry/grafana-yugabyte-datasource.schema.json.js +0 -114
  487. package/dist/esm/schema/registry/grafana-yugabyte-datasource.schema.json.js.map +0 -1
  488. package/dist/esm/schema/registry/graphite.schema.json.js +0 -104
  489. package/dist/esm/schema/registry/graphite.schema.json.js.map +0 -1
  490. package/dist/esm/schema/registry/index.js +0 -27
  491. package/dist/esm/schema/registry/index.js.map +0 -1
  492. package/dist/esm/schema/registry/influxdb.schema.json.js +0 -717
  493. package/dist/esm/schema/registry/influxdb.schema.json.js.map +0 -1
  494. package/dist/esm/schema/registry/jaeger.schema.json.js +0 -59
  495. package/dist/esm/schema/registry/jaeger.schema.json.js.map +0 -1
  496. package/dist/esm/schema/registry/loki.schema.json.js +0 -545
  497. package/dist/esm/schema/registry/loki.schema.json.js.map +0 -1
  498. package/dist/esm/schema/registry/marcusolsson-csv-datasource.schema.json.js +0 -45
  499. package/dist/esm/schema/registry/marcusolsson-csv-datasource.schema.json.js.map +0 -1
  500. package/dist/esm/schema/registry/marcusolsson-json-datasource.schema.json.js +0 -36
  501. package/dist/esm/schema/registry/marcusolsson-json-datasource.schema.json.js.map +0 -1
  502. package/dist/esm/schema/registry/mssql.schema.json.js +0 -292
  503. package/dist/esm/schema/registry/mssql.schema.json.js.map +0 -1
  504. package/dist/esm/schema/registry/mysql.schema.json.js +0 -304
  505. package/dist/esm/schema/registry/mysql.schema.json.js.map +0 -1
  506. package/dist/esm/schema/registry/opentsdb.schema.json.js +0 -113
  507. package/dist/esm/schema/registry/opentsdb.schema.json.js.map +0 -1
  508. package/dist/esm/schema/registry/prometheus.schema.json.js +0 -783
  509. package/dist/esm/schema/registry/prometheus.schema.json.js.map +0 -1
  510. package/dist/esm/schema/registry/stackdriver.schema.json.js +0 -224
  511. package/dist/esm/schema/registry/stackdriver.schema.json.js.map +0 -1
  512. package/dist/esm/schema/registry/staticRegistry.js +0 -135
  513. package/dist/esm/schema/registry/staticRegistry.js.map +0 -1
  514. package/dist/esm/schema/registry/tempo.schema.json.js +0 -664
  515. package/dist/esm/schema/registry/tempo.schema.json.js.map +0 -1
  516. package/dist/esm/schema/registry/zipkin.schema.json.js +0 -40
  517. package/dist/esm/schema/registry/zipkin.schema.json.js.map +0 -1
  518. /package/dist/esm/components/{QueryEditorRow → QueryEditor}/QueryEditorRow.js +0 -0
@@ -0,0 +1,2798 @@
1
+ import React from 'react';
2
+
3
+ var isCheckBoxInput = (element) => element.type === 'checkbox';
4
+
5
+ var isDateObject = (value) => value instanceof Date;
6
+
7
+ var isNullOrUndefined = (value) => value == null;
8
+
9
+ const isObjectType = (value) => typeof value === 'object';
10
+ var isObject = (value) => !isNullOrUndefined(value) &&
11
+ !Array.isArray(value) &&
12
+ isObjectType(value) &&
13
+ !isDateObject(value);
14
+
15
+ var getEventValue = (event) => isObject(event) && event.target
16
+ ? isCheckBoxInput(event.target)
17
+ ? event.target.checked
18
+ : event.target.value
19
+ : event;
20
+
21
+ var isNameInFieldArray = (names, name) => name
22
+ .split('.')
23
+ .some((part, index, arr) => !isNaN(Number(part)) && names.has(arr.slice(0, index).join('.')));
24
+
25
+ var isPlainObject = (tempObject) => {
26
+ const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
27
+ return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
28
+ };
29
+
30
+ var isWeb = typeof window !== 'undefined' &&
31
+ typeof window.HTMLElement !== 'undefined' &&
32
+ typeof document !== 'undefined';
33
+
34
+ function cloneObject(data) {
35
+ if (data instanceof Date) {
36
+ return new Date(data);
37
+ }
38
+ const isFileListInstance = typeof FileList !== 'undefined' && data instanceof FileList;
39
+ if (isWeb && (data instanceof Blob || isFileListInstance)) {
40
+ return data;
41
+ }
42
+ const isArray = Array.isArray(data);
43
+ if (!isArray && !(isObject(data) && isPlainObject(data))) {
44
+ return data;
45
+ }
46
+ const copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
47
+ for (const key in data) {
48
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
49
+ copy[key] = cloneObject(data[key]);
50
+ }
51
+ }
52
+ return copy;
53
+ }
54
+
55
+ const EVENTS = {
56
+ BLUR: 'blur',
57
+ FOCUS_OUT: 'focusout',
58
+ CHANGE: 'change',
59
+ SUBMIT: 'submit',
60
+ TRIGGER: 'trigger',
61
+ VALID: 'valid',
62
+ };
63
+ const VALIDATION_MODE = {
64
+ onBlur: 'onBlur',
65
+ onChange: 'onChange',
66
+ onSubmit: 'onSubmit',
67
+ onTouched: 'onTouched',
68
+ all: 'all',
69
+ };
70
+ const INPUT_VALIDATION_RULES = {
71
+ max: 'max',
72
+ min: 'min',
73
+ maxLength: 'maxLength',
74
+ minLength: 'minLength',
75
+ pattern: 'pattern',
76
+ required: 'required',
77
+ validate: 'validate',
78
+ };
79
+ const ROOT_ERROR_TYPE = 'root';
80
+ const PROTOTYPE_KEYWORDS = ['__proto__', 'constructor', 'prototype'];
81
+
82
+ const IS_KEY_RE = /^\w*$/;
83
+ var isKey = (value) => IS_KEY_RE.test(value);
84
+
85
+ var isUndefined = (val) => val === undefined;
86
+
87
+ const FIELD_PATH_RE = /[.[\]'"]/;
88
+ var stringToPath = (input) => input.split(FIELD_PATH_RE).filter(Boolean);
89
+
90
+ var get = (object, path, defaultValue) => {
91
+ if (!path || !isObject(object)) {
92
+ return defaultValue;
93
+ }
94
+ const paths = isKey(path) ? [path] : stringToPath(path);
95
+ if (paths.some((key) => PROTOTYPE_KEYWORDS.includes(key))) {
96
+ return defaultValue;
97
+ }
98
+ const result = paths.reduce((result, key) => {
99
+ return isNullOrUndefined(result) ? undefined : result[key];
100
+ }, object);
101
+ return isUndefined(result) || result === object
102
+ ? isUndefined(object[path])
103
+ ? defaultValue
104
+ : object[path]
105
+ : result;
106
+ };
107
+
108
+ var isBoolean = (value) => typeof value === 'boolean';
109
+
110
+ var isFunction = (value) => typeof value === 'function';
111
+
112
+ var set$1 = (object, path, value) => {
113
+ let index = -1;
114
+ const tempPath = isKey(path) ? [path] : stringToPath(path);
115
+ const length = tempPath.length;
116
+ const lastIndex = length - 1;
117
+ while (++index < length) {
118
+ const key = tempPath[index];
119
+ let newValue = value;
120
+ if (index !== lastIndex) {
121
+ const objValue = object[key];
122
+ newValue =
123
+ isObject(objValue) || Array.isArray(objValue)
124
+ ? objValue
125
+ : !isNaN(+tempPath[index + 1])
126
+ ? []
127
+ : {};
128
+ }
129
+ if (PROTOTYPE_KEYWORDS.includes(key)) {
130
+ return;
131
+ }
132
+ object[key] = newValue;
133
+ object = object[key];
134
+ }
135
+ };
136
+
137
+ /**
138
+ * Separate context for `control` to prevent unnecessary rerenders.
139
+ * Internal hooks that only need control use this instead of full form context.
140
+ */
141
+ const HookFormControlContext = React.createContext(null);
142
+ HookFormControlContext.displayName = 'HookFormControlContext';
143
+ /**
144
+ * @internal Internal hook to access only control from context.
145
+ */
146
+ const useFormControlContext = () => React.useContext(HookFormControlContext);
147
+
148
+ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
149
+ const result = {};
150
+ for (const key in formState) {
151
+ Object.defineProperty(result, key, {
152
+ get: () => {
153
+ const _key = key;
154
+ if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
155
+ control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
156
+ }
157
+ localProxyFormState && (localProxyFormState[_key] = true);
158
+ return formState[_key];
159
+ },
160
+ });
161
+ }
162
+ return result;
163
+ };
164
+
165
+ const useIsomorphicLayoutEffect = isWeb
166
+ ? React.useLayoutEffect
167
+ : React.useEffect;
168
+
169
+ /**
170
+ * 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.
171
+ *
172
+ * @remarks
173
+ * [API](https://react-hook-form.com/docs/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
174
+ *
175
+ * @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
176
+ *
177
+ * @example
178
+ * ```tsx
179
+ * function App() {
180
+ * const { register, handleSubmit, control } = useForm({
181
+ * defaultValues: {
182
+ * firstName: "firstName"
183
+ * }});
184
+ * const { dirtyFields } = useFormState({
185
+ * control
186
+ * });
187
+ * const onSubmit = (data) => console.log(data);
188
+ *
189
+ * return (
190
+ * <form onSubmit={handleSubmit(onSubmit)}>
191
+ * <input {...register("firstName")} placeholder="First Name" />
192
+ * {dirtyFields.firstName && <p>Field is dirty.</p>}
193
+ * <input type="submit" />
194
+ * </form>
195
+ * );
196
+ * }
197
+ * ```
198
+ */
199
+ function useFormState(props) {
200
+ const formControl = useFormControlContext();
201
+ const { control = formControl, disabled, name, exact } = props || {};
202
+ const [formState, updateFormState] = React.useState(() => ({
203
+ ...control._formState,
204
+ defaultValues: control._defaultValues,
205
+ }));
206
+ const _localProxyFormState = React.useRef({
207
+ isDirty: false,
208
+ isLoading: false,
209
+ dirtyFields: false,
210
+ touchedFields: false,
211
+ validatingFields: false,
212
+ isValidating: false,
213
+ isValid: false,
214
+ errors: false,
215
+ });
216
+ useIsomorphicLayoutEffect(() => control._subscribe({
217
+ name,
218
+ formState: _localProxyFormState.current,
219
+ exact,
220
+ callback: (formState) => {
221
+ !disabled &&
222
+ updateFormState({
223
+ ...control._formState,
224
+ ...formState,
225
+ defaultValues: control._defaultValues,
226
+ });
227
+ },
228
+ }), [name, disabled, exact]);
229
+ React.useEffect(() => {
230
+ _localProxyFormState.current.isValid && control._setValid(true);
231
+ }, [control]);
232
+ return React.useMemo(() => getProxyFormState(formState, control, _localProxyFormState.current, false), [formState, control]);
233
+ }
234
+
235
+ var isString = (value) => typeof value === 'string';
236
+
237
+ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
238
+ if (isString(names)) {
239
+ isGlobal && _names.watch.add(names);
240
+ return get(formValues, names, defaultValue);
241
+ }
242
+ if (Array.isArray(names)) {
243
+ return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName),
244
+ get(formValues, fieldName)));
245
+ }
246
+ isGlobal && (_names.watchAll = true);
247
+ return formValues;
248
+ };
249
+
250
+ var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
251
+
252
+ const isEmptyObjectWithCustomPrototype = (object, keys) => keys.length === 0 && !Array.isArray(object) && !isPlainObject(object);
253
+ function deepEqual(object1, object2, visited = new WeakMap()) {
254
+ if (object1 === object2) {
255
+ return true;
256
+ }
257
+ if (isPrimitive(object1) || isPrimitive(object2)) {
258
+ return Object.is(object1, object2);
259
+ }
260
+ if (isDateObject(object1) && isDateObject(object2)) {
261
+ return Object.is(object1.getTime(), object2.getTime());
262
+ }
263
+ const keys1 = Object.keys(object1);
264
+ const keys2 = Object.keys(object2);
265
+ if (keys1.length !== keys2.length) {
266
+ return false;
267
+ }
268
+ if (isEmptyObjectWithCustomPrototype(object1, keys1) ||
269
+ isEmptyObjectWithCustomPrototype(object2, keys2)) {
270
+ return Object.is(object1, object2);
271
+ }
272
+ if (!keys1.length && Array.isArray(object1) !== Array.isArray(object2)) {
273
+ return false;
274
+ }
275
+ const visitedPairs = visited.get(object1);
276
+ if (visitedPairs && visitedPairs.has(object2)) {
277
+ return true;
278
+ }
279
+ if (visitedPairs) {
280
+ visitedPairs.add(object2);
281
+ }
282
+ else {
283
+ const ws = new WeakSet();
284
+ ws.add(object2);
285
+ visited.set(object1, ws);
286
+ }
287
+ for (const key of keys1) {
288
+ const val1 = object1[key];
289
+ if (!(key in object2)) {
290
+ return false;
291
+ }
292
+ if (key !== 'ref') {
293
+ const val2 = object2[key];
294
+ if ((isDateObject(val1) && isDateObject(val2)) ||
295
+ ((isObject(val1) || Array.isArray(val1)) &&
296
+ (isObject(val2) || Array.isArray(val2)))
297
+ ? !deepEqual(val1, val2, visited)
298
+ : !Object.is(val1, val2)) {
299
+ return false;
300
+ }
301
+ }
302
+ }
303
+ return true;
304
+ }
305
+
306
+ /**
307
+ * Custom hook to subscribe to field change and isolate re-rendering at the component level.
308
+ *
309
+ * @remarks
310
+ *
311
+ * [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
312
+ *
313
+ * @example
314
+ * ```tsx
315
+ * const { control } = useForm();
316
+ * const values = useWatch({
317
+ * name: "fieldName"
318
+ * control,
319
+ * })
320
+ * ```
321
+ */
322
+ function useWatch(props) {
323
+ const formControl = useFormControlContext();
324
+ const { control = formControl, name, defaultValue, disabled, exact, compute, } = props || {};
325
+ const _defaultValue = React.useRef(defaultValue);
326
+ const _compute = React.useRef(compute);
327
+ const _computeFormValues = React.useRef(undefined);
328
+ const _prevControl = React.useRef(control);
329
+ const _prevName = React.useRef(name);
330
+ _compute.current = compute;
331
+ const [value, updateValue] = React.useState(() => {
332
+ const defaultValue = control._getWatch(name, _defaultValue.current);
333
+ return _compute.current ? _compute.current(defaultValue) : defaultValue;
334
+ });
335
+ const getCurrentOutput = React.useCallback((values) => {
336
+ const formValues = generateWatchOutput(name, control._names, values || control._formValues, false, _defaultValue.current);
337
+ return _compute.current ? _compute.current(formValues) : formValues;
338
+ }, [control._formValues, control._names, name]);
339
+ const refreshValue = React.useCallback((values) => {
340
+ if (!disabled) {
341
+ const formValues = generateWatchOutput(name, control._names, values || control._formValues, false, _defaultValue.current);
342
+ if (_compute.current) {
343
+ const computedFormValues = _compute.current(formValues);
344
+ if (!deepEqual(computedFormValues, _computeFormValues.current)) {
345
+ updateValue(computedFormValues);
346
+ _computeFormValues.current = computedFormValues;
347
+ }
348
+ }
349
+ else {
350
+ updateValue(formValues);
351
+ }
352
+ }
353
+ }, [control._formValues, control._names, disabled, name]);
354
+ useIsomorphicLayoutEffect(() => {
355
+ if (_prevControl.current !== control ||
356
+ !deepEqual(_prevName.current, name)) {
357
+ _prevControl.current = control;
358
+ _prevName.current = name;
359
+ refreshValue();
360
+ }
361
+ return control._subscribe({
362
+ name,
363
+ formState: {
364
+ values: true,
365
+ },
366
+ exact,
367
+ callback: (formState) => {
368
+ refreshValue(formState.values);
369
+ },
370
+ });
371
+ }, [control, exact, name, refreshValue]);
372
+ React.useEffect(() => control._removeUnmounted());
373
+ // If name or control changed for this render, synchronously reflect the
374
+ // latest value so callers (like useController) see the correct value
375
+ // immediately on the same render.
376
+ // Optimize: Check control reference first before expensive deepEqual
377
+ const controlChanged = _prevControl.current !== control;
378
+ const prevName = _prevName.current;
379
+ // Cache the computed output to avoid duplicate calls within the same render
380
+ // We include shouldReturnImmediate in deps to ensure proper recomputation
381
+ const computedOutput = React.useMemo(() => {
382
+ if (disabled) {
383
+ return null;
384
+ }
385
+ const nameChanged = !controlChanged && !deepEqual(prevName, name);
386
+ const shouldReturnImmediate = controlChanged || nameChanged;
387
+ return shouldReturnImmediate ? getCurrentOutput() : null;
388
+ }, [disabled, controlChanged, name, prevName, getCurrentOutput]);
389
+ return computedOutput !== null ? computedOutput : value;
390
+ }
391
+
392
+ /**
393
+ * Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
394
+ *
395
+ * @remarks
396
+ * [API](https://react-hook-form.com/docs/usecontroller) • [Demo](https://codesandbox.io/s/usecontroller-0o8px)
397
+ *
398
+ * @param props - the path name to the form field value, and validation rules.
399
+ *
400
+ * @returns field properties, field and form state. {@link UseControllerReturn}
401
+ *
402
+ * @example
403
+ * ```tsx
404
+ * function Input(props) {
405
+ * const { field, fieldState, formState } = useController(props);
406
+ * return (
407
+ * <div>
408
+ * <input {...field} placeholder={props.name} />
409
+ * <p>{fieldState.isTouched && "Touched"}</p>
410
+ * <p>{formState.isSubmitted ? "submitted" : ""}</p>
411
+ * </div>
412
+ * );
413
+ * }
414
+ * ```
415
+ */
416
+ function useController(props) {
417
+ const formControl = useFormControlContext();
418
+ const { name, disabled, control = formControl, shouldUnregister, defaultValue, exact = true, } = props;
419
+ const isArrayField = isNameInFieldArray(control._names.array, name);
420
+ const defaultValueMemo = React.useMemo(() => get(control._formValues, name, get(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
421
+ const value = useWatch({
422
+ control,
423
+ name,
424
+ defaultValue: defaultValueMemo,
425
+ exact,
426
+ });
427
+ const formState = useFormState({
428
+ control,
429
+ name,
430
+ exact,
431
+ });
432
+ const _props = React.useRef(props);
433
+ const _proxyRef = React.useRef(null);
434
+ const _registerProps = React.useRef(control.register(name, {
435
+ ...props.rules,
436
+ value,
437
+ ...(isBoolean(props.disabled) ? { disabled: props.disabled } : {}),
438
+ }));
439
+ _props.current = props;
440
+ const fieldState = React.useMemo(() => Object.defineProperties({}, {
441
+ invalid: {
442
+ enumerable: true,
443
+ get: () => !!get(formState.errors, name),
444
+ },
445
+ isDirty: {
446
+ enumerable: true,
447
+ get: () => !!get(formState.dirtyFields, name),
448
+ },
449
+ isTouched: {
450
+ enumerable: true,
451
+ get: () => !!get(formState.touchedFields, name),
452
+ },
453
+ isValidating: {
454
+ enumerable: true,
455
+ get: () => !!get(formState.validatingFields, name),
456
+ },
457
+ error: {
458
+ enumerable: true,
459
+ get: () => get(formState.errors, name),
460
+ },
461
+ }), [formState, name]);
462
+ const onChange = React.useCallback((event) => {
463
+ const value = getEventValue(event);
464
+ if (!get(control._fields, name)) {
465
+ _registerProps.current = control.register(name, {
466
+ ..._props.current.rules,
467
+ value,
468
+ });
469
+ }
470
+ return _registerProps.current.onChange({
471
+ target: {
472
+ value: getEventValue(event),
473
+ name: name,
474
+ },
475
+ type: EVENTS.CHANGE,
476
+ });
477
+ }, [name, control]);
478
+ const onBlur = React.useCallback(() => _registerProps.current.onBlur({
479
+ target: {
480
+ value: get(control._formValues, name),
481
+ name: name,
482
+ },
483
+ type: EVENTS.BLUR,
484
+ }), [name, control._formValues]);
485
+ const ref = React.useCallback((elm) => {
486
+ if (elm) {
487
+ _proxyRef.current = {
488
+ focus: () => isFunction(elm.focus) && elm.focus(),
489
+ select: () => isFunction(elm.select) && elm.select(),
490
+ setCustomValidity: (message) => isFunction(elm.setCustomValidity) && elm.setCustomValidity(message),
491
+ reportValidity: () => isFunction(elm.reportValidity) && elm.reportValidity(),
492
+ };
493
+ }
494
+ const field = get(control._fields, name);
495
+ if (field && field._f && elm) {
496
+ field._f.ref = _proxyRef.current;
497
+ }
498
+ }, [control._fields, name]);
499
+ const field = React.useMemo(() => ({
500
+ name,
501
+ value,
502
+ ...(isBoolean(disabled) || formState.disabled
503
+ ? { disabled: formState.disabled || disabled }
504
+ : {}),
505
+ onChange,
506
+ onBlur,
507
+ ref,
508
+ }), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
509
+ React.useEffect(() => {
510
+ const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
511
+ control.register(name, {
512
+ ..._props.current.rules,
513
+ ...(isBoolean(_props.current.disabled)
514
+ ? { disabled: _props.current.disabled }
515
+ : {}),
516
+ });
517
+ const updateMounted = (name, value) => {
518
+ const field = get(control._fields, name);
519
+ if (field && field._f) {
520
+ field._f.mount = value;
521
+ }
522
+ };
523
+ updateMounted(name, true);
524
+ if (_shouldUnregisterField) {
525
+ const value = cloneObject(get(shouldUnregister
526
+ ? control._defaultValues
527
+ : control._options.values || control._defaultValues, name, get(control._options.defaultValues, name, _props.current.defaultValue)));
528
+ set$1(control._defaultValues, name, value);
529
+ if (isUndefined(get(control._formValues, name))) {
530
+ set$1(control._formValues, name, value);
531
+ }
532
+ }
533
+ !isArrayField && control.register(name);
534
+ if (_proxyRef.current) {
535
+ const field = get(control._fields, name);
536
+ if (field && field._f) {
537
+ field._f.ref = _proxyRef.current;
538
+ }
539
+ }
540
+ return () => {
541
+ (isArrayField
542
+ ? _shouldUnregisterField && !control._state.action
543
+ : _shouldUnregisterField)
544
+ ? control.unregister(name)
545
+ : updateMounted(name, false);
546
+ };
547
+ }, [name, control, isArrayField, shouldUnregister]);
548
+ React.useEffect(() => {
549
+ control._setDisabledField({
550
+ disabled,
551
+ name,
552
+ });
553
+ }, [disabled, name, control]);
554
+ return React.useMemo(() => ({
555
+ field,
556
+ formState,
557
+ fieldState,
558
+ }), [field, formState, fieldState]);
559
+ }
560
+
561
+ /**
562
+ * Component based on `useController` hook to work with controlled component.
563
+ *
564
+ * @remarks
565
+ * [API](https://react-hook-form.com/docs/usecontroller/controller) • [Demo](https://codesandbox.io/s/react-hook-form-v6-controller-ts-jwyzw) • [Video](https://www.youtube.com/watch?v=N2UNk_UCVyA)
566
+ *
567
+ * @param props - the path name to the form field value, and validation rules.
568
+ *
569
+ * @returns provide field handler functions, field and form state.
570
+ *
571
+ * @example
572
+ * ```tsx
573
+ * function App() {
574
+ * const { control } = useForm<FormValues>({
575
+ * defaultValues: {
576
+ * test: ""
577
+ * }
578
+ * });
579
+ *
580
+ * return (
581
+ * <form>
582
+ * <Controller
583
+ * control={control}
584
+ * name="test"
585
+ * render={({ field: { onChange, onBlur, value, ref }, formState, fieldState }) => (
586
+ * <>
587
+ * <input
588
+ * onChange={onChange} // send value to hook form
589
+ * onBlur={onBlur} // notify when input is touched
590
+ * value={value} // return updated value
591
+ * ref={ref} // set ref for focus management
592
+ * />
593
+ * <p>{formState.isSubmitted ? "submitted" : ""}</p>
594
+ * <p>{fieldState.isTouched ? "touched" : ""}</p>
595
+ * </>
596
+ * )}
597
+ * />
598
+ * </form>
599
+ * );
600
+ * }
601
+ * ```
602
+ */
603
+ const Controller = (props) => props.render(useController(props));
604
+
605
+ const flatten = (obj) => {
606
+ const output = {};
607
+ for (const key of Object.keys(obj)) {
608
+ if (isObjectType(obj[key]) &&
609
+ obj[key] !== null &&
610
+ !isDateObject(obj[key])) {
611
+ const nested = flatten(obj[key]);
612
+ for (const nestedKey of Object.keys(nested)) {
613
+ output[`${key}.${nestedKey}`] = nested[nestedKey];
614
+ }
615
+ }
616
+ else {
617
+ output[key] = obj[key];
618
+ }
619
+ }
620
+ return output;
621
+ };
622
+
623
+ const HookFormContext = React.createContext(null);
624
+ HookFormContext.displayName = 'HookFormContext';
625
+
626
+ var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
627
+ ? {
628
+ ...errors[name],
629
+ types: {
630
+ ...(errors[name] && errors[name].types ? errors[name].types : {}),
631
+ [type]: message || true,
632
+ },
633
+ }
634
+ : {};
635
+
636
+ var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
637
+
638
+ var convertToArrayPayload = (value) => (Array.isArray(value) ? value : [value]);
639
+
640
+ var createSubject = () => {
641
+ let _observers = [];
642
+ const next = (value) => {
643
+ for (const observer of _observers) {
644
+ observer.next && observer.next(value);
645
+ }
646
+ };
647
+ const subscribe = (observer) => {
648
+ _observers.push(observer);
649
+ return {
650
+ unsubscribe: () => {
651
+ _observers = _observers.filter((o) => o !== observer);
652
+ },
653
+ };
654
+ };
655
+ const unsubscribe = () => {
656
+ _observers = [];
657
+ };
658
+ return {
659
+ get observers() {
660
+ return _observers;
661
+ },
662
+ next,
663
+ subscribe,
664
+ unsubscribe,
665
+ };
666
+ };
667
+
668
+ function extractFormValues(fieldsState, formValues) {
669
+ const values = {};
670
+ for (const key in fieldsState) {
671
+ if (fieldsState.hasOwnProperty(key)) {
672
+ const fieldState = fieldsState[key];
673
+ const fieldValue = formValues[key];
674
+ if (fieldState && isObject(fieldState) && fieldValue) {
675
+ const nestedFieldsState = extractFormValues(fieldState, fieldValue);
676
+ if (isObject(nestedFieldsState)) {
677
+ values[key] = nestedFieldsState;
678
+ }
679
+ }
680
+ else if (fieldsState[key]) {
681
+ values[key] = fieldValue;
682
+ }
683
+ }
684
+ }
685
+ return values;
686
+ }
687
+
688
+ var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
689
+
690
+ var isFileInput = (element) => element.type === 'file';
691
+
692
+ var isHTMLElement = (value) => {
693
+ if (!isWeb) {
694
+ return false;
695
+ }
696
+ const owner = value ? value.ownerDocument : 0;
697
+ return (value instanceof
698
+ (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement));
699
+ };
700
+
701
+ var isMultipleSelect = (element) => element.type === `select-multiple`;
702
+
703
+ var isRadioInput = (element) => element.type === 'radio';
704
+
705
+ var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
706
+
707
+ var live = (ref) => isHTMLElement(ref) && ref.isConnected;
708
+
709
+ function baseGet(object, updatePath) {
710
+ const length = updatePath.slice(0, -1).length;
711
+ let index = 0;
712
+ while (index < length) {
713
+ if (isNullOrUndefined(object)) {
714
+ object = undefined;
715
+ break;
716
+ }
717
+ object = object[updatePath[index]];
718
+ index++;
719
+ }
720
+ return object;
721
+ }
722
+ function isEmptyArray(obj) {
723
+ for (const key in obj) {
724
+ if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
725
+ return false;
726
+ }
727
+ }
728
+ return true;
729
+ }
730
+ function unset(object, path) {
731
+ if (isString(path) && Object.prototype.hasOwnProperty.call(object, path)) {
732
+ delete object[path];
733
+ return object;
734
+ }
735
+ const paths = Array.isArray(path)
736
+ ? path
737
+ : isKey(path)
738
+ ? [path]
739
+ : stringToPath(path);
740
+ if (paths.some((segment) => PROTOTYPE_KEYWORDS.includes(String(segment)))) {
741
+ return object;
742
+ }
743
+ const childObject = paths.length === 1 ? object : baseGet(object, paths);
744
+ const index = paths.length - 1;
745
+ const key = paths[index];
746
+ if (childObject) {
747
+ delete childObject[key];
748
+ }
749
+ if (index !== 0 &&
750
+ ((isObject(childObject) && isEmptyObject(childObject)) ||
751
+ (Array.isArray(childObject) && isEmptyArray(childObject)))) {
752
+ unset(object, paths.slice(0, -1));
753
+ }
754
+ return object;
755
+ }
756
+
757
+ var objectHasFunction = (data) => {
758
+ for (const key in data) {
759
+ if (isFunction(data[key])) {
760
+ return true;
761
+ }
762
+ }
763
+ return false;
764
+ };
765
+
766
+ function isTraversable(value) {
767
+ return Array.isArray(value) || (isObject(value) && !objectHasFunction(value));
768
+ }
769
+ function markFieldsDirty(data, fields = {}) {
770
+ for (const key in data) {
771
+ const value = data[key];
772
+ if (isTraversable(value)) {
773
+ fields[key] = Array.isArray(value) ? [] : {};
774
+ markFieldsDirty(value, fields[key]);
775
+ }
776
+ else if (!isUndefined(value)) {
777
+ fields[key] = true;
778
+ }
779
+ }
780
+ return fields;
781
+ }
782
+ function pruneDirtyFields(value) {
783
+ if (value === false) {
784
+ return undefined;
785
+ }
786
+ if (value === true) {
787
+ return true;
788
+ }
789
+ if (Array.isArray(value)) {
790
+ const result = value.map((value) => pruneDirtyFields(value));
791
+ return (result.some((value) => value !== undefined) ? result : undefined);
792
+ }
793
+ if (isObject(value)) {
794
+ const result = {};
795
+ for (const key in value) {
796
+ const pruned = pruneDirtyFields(value[key]);
797
+ if (!isUndefined(pruned)) {
798
+ result[key] = pruned;
799
+ }
800
+ }
801
+ return (Object.keys(result).length ? result : undefined);
802
+ }
803
+ return undefined;
804
+ }
805
+ function getDirtyFields(data, formValues, dirtyFieldsFromValues) {
806
+ if (!dirtyFieldsFromValues) {
807
+ dirtyFieldsFromValues = markFieldsDirty(formValues);
808
+ }
809
+ for (const key in data) {
810
+ const value = data[key];
811
+ if (isTraversable(value)) {
812
+ if (isUndefined(formValues) || isPrimitive(dirtyFieldsFromValues[key])) {
813
+ dirtyFieldsFromValues[key] = markFieldsDirty(value, Array.isArray(value) ? [] : {});
814
+ }
815
+ else {
816
+ getDirtyFields(value, isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
817
+ }
818
+ }
819
+ else {
820
+ const formValue = formValues[key];
821
+ dirtyFieldsFromValues[key] = !deepEqual(value, formValue);
822
+ }
823
+ }
824
+ return pruneDirtyFields(dirtyFieldsFromValues) || {};
825
+ }
826
+
827
+ const defaultResult = {
828
+ value: false,
829
+ isValid: false,
830
+ };
831
+ const validResult = { value: true, isValid: true };
832
+ var getCheckboxValue = (options) => {
833
+ if (Array.isArray(options)) {
834
+ if (options.length > 1) {
835
+ const values = options
836
+ .filter((option) => option && option.checked && !option.disabled)
837
+ .map((option) => option.value);
838
+ return { value: values, isValid: !!values.length };
839
+ }
840
+ return options[0].checked && !options[0].disabled
841
+ ? // @ts-expect-error expected to work in the browser
842
+ options[0].attributes && !isUndefined(options[0].attributes.value)
843
+ ? isUndefined(options[0].value) || options[0].value === ''
844
+ ? validResult
845
+ : { value: options[0].value, isValid: true }
846
+ : validResult
847
+ : defaultResult;
848
+ }
849
+ return defaultResult;
850
+ };
851
+
852
+ var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value)
853
+ ? value
854
+ : valueAsNumber
855
+ ? value === ''
856
+ ? NaN
857
+ : value
858
+ ? +value
859
+ : value
860
+ : valueAsDate && isString(value)
861
+ ? new Date(value)
862
+ : setValueAs
863
+ ? setValueAs(value)
864
+ : value;
865
+
866
+ const defaultReturn = {
867
+ isValid: false,
868
+ value: null,
869
+ };
870
+ var getRadioValue = (options) => Array.isArray(options)
871
+ ? options.reduce((previous, option) => option && option.checked && !option.disabled
872
+ ? {
873
+ isValid: true,
874
+ value: option.value,
875
+ }
876
+ : previous, defaultReturn)
877
+ : defaultReturn;
878
+
879
+ function getFieldValue(_f) {
880
+ const ref = _f.ref;
881
+ if (isFileInput(ref)) {
882
+ return ref.files;
883
+ }
884
+ if (isRadioInput(ref)) {
885
+ return getRadioValue(_f.refs).value;
886
+ }
887
+ if (isMultipleSelect(ref)) {
888
+ return [...ref.selectedOptions].map(({ value }) => value);
889
+ }
890
+ if (isCheckBoxInput(ref)) {
891
+ return getCheckboxValue(_f.refs).value;
892
+ }
893
+ return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
894
+ }
895
+
896
+ var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
897
+ const fields = {};
898
+ for (const name of fieldsNames) {
899
+ const field = get(_fields, name);
900
+ field && set$1(fields, name, field._f);
901
+ }
902
+ return {
903
+ criteriaMode,
904
+ names: [...fieldsNames],
905
+ fields,
906
+ shouldUseNativeValidation,
907
+ };
908
+ };
909
+
910
+ var isRegex = (value) => value instanceof RegExp;
911
+
912
+ var getRuleValue = (rule) => isUndefined(rule)
913
+ ? rule
914
+ : isRegex(rule)
915
+ ? rule.source
916
+ : isObject(rule)
917
+ ? isRegex(rule.value)
918
+ ? rule.value.source
919
+ : rule.value
920
+ : rule;
921
+
922
+ var getValidationModes = (mode) => ({
923
+ isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
924
+ isOnBlur: mode === VALIDATION_MODE.onBlur,
925
+ isOnChange: mode === VALIDATION_MODE.onChange,
926
+ isOnAll: mode === VALIDATION_MODE.all,
927
+ isOnTouch: mode === VALIDATION_MODE.onTouched,
928
+ });
929
+
930
+ const ASYNC_FUNCTION = 'AsyncFunction';
931
+ var hasPromiseValidation = (fieldReference) => {
932
+ if (!fieldReference || !fieldReference.validate)
933
+ return false;
934
+ if (isFunction(fieldReference.validate)) {
935
+ return fieldReference.validate.constructor.name === ASYNC_FUNCTION;
936
+ }
937
+ if (isObject(fieldReference.validate)) {
938
+ for (const key in fieldReference.validate) {
939
+ if (fieldReference.validate[key].constructor
940
+ .name === ASYNC_FUNCTION) {
941
+ return true;
942
+ }
943
+ }
944
+ }
945
+ return false;
946
+ };
947
+
948
+ var hasValidation = (options) => options.mount &&
949
+ (options.required ||
950
+ options.min ||
951
+ options.max ||
952
+ options.maxLength ||
953
+ options.minLength ||
954
+ options.pattern ||
955
+ options.validate);
956
+
957
+ var isWatched = (name, _names, isBlurEvent) => {
958
+ if (isBlurEvent)
959
+ return false;
960
+ if (_names.watchAll || _names.watch.has(name))
961
+ return true;
962
+ for (const watchName of _names.watch) {
963
+ if (name.startsWith(watchName) && name.charAt(watchName.length) === '.')
964
+ return true;
965
+ }
966
+ return false;
967
+ };
968
+
969
+ const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
970
+ for (const key of fieldsNames || Object.keys(fields)) {
971
+ const field = get(fields, key);
972
+ if (field) {
973
+ const { _f, ...currentField } = field;
974
+ if (_f) {
975
+ if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
976
+ return true;
977
+ }
978
+ else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
979
+ return true;
980
+ }
981
+ else {
982
+ if (iterateFieldsByAction(currentField, action)) {
983
+ break;
984
+ }
985
+ }
986
+ }
987
+ else if (isObject(currentField)) {
988
+ if (iterateFieldsByAction(currentField, action)) {
989
+ break;
990
+ }
991
+ }
992
+ }
993
+ }
994
+ return;
995
+ };
996
+
997
+ function schemaErrorLookup(errors, _fields, name) {
998
+ const error = get(errors, name);
999
+ if (error || isKey(name)) {
1000
+ return {
1001
+ error,
1002
+ name,
1003
+ };
1004
+ }
1005
+ const names = name.split('.');
1006
+ while (names.length) {
1007
+ const fieldName = names.join('.');
1008
+ const field = get(_fields, fieldName);
1009
+ const foundError = get(errors, fieldName);
1010
+ if (field && !Array.isArray(field) && name !== fieldName) {
1011
+ return { name };
1012
+ }
1013
+ if (foundError && foundError.type) {
1014
+ return {
1015
+ name: fieldName,
1016
+ error: foundError,
1017
+ };
1018
+ }
1019
+ if (foundError && foundError.root && foundError.root.type) {
1020
+ return {
1021
+ name: `${fieldName}.root`,
1022
+ error: foundError.root,
1023
+ };
1024
+ }
1025
+ names.pop();
1026
+ }
1027
+ return {
1028
+ name,
1029
+ };
1030
+ }
1031
+
1032
+ var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
1033
+ updateFormState(formStateData);
1034
+ const { name, ...formState } = formStateData;
1035
+ const keys = Object.keys(formState);
1036
+ return (!keys.length ||
1037
+ (isRoot && keys.length >= Object.keys(_proxyFormState).length) ||
1038
+ keys.find((key) => _proxyFormState[key] ===
1039
+ (!isRoot || VALIDATION_MODE.all)));
1040
+ };
1041
+
1042
+ var shouldSubscribeByName = (name, signalName, exact) => !name ||
1043
+ !signalName ||
1044
+ name === signalName ||
1045
+ convertToArrayPayload(name).some((currentName) => currentName &&
1046
+ (exact
1047
+ ? currentName === signalName || currentName.startsWith(signalName + '.')
1048
+ : currentName.startsWith(signalName) ||
1049
+ signalName.startsWith(currentName)));
1050
+
1051
+ var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
1052
+ if (mode.isOnAll) {
1053
+ return false;
1054
+ }
1055
+ else if (!isSubmitted && mode.isOnTouch) {
1056
+ return !(isTouched || isBlurEvent);
1057
+ }
1058
+ else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
1059
+ return !isBlurEvent;
1060
+ }
1061
+ else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
1062
+ return isBlurEvent;
1063
+ }
1064
+ return true;
1065
+ };
1066
+
1067
+ var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
1068
+
1069
+ var updateFieldArrayRootError = (errors, error, name) => {
1070
+ const existingErrors = get(errors, name);
1071
+ const fieldArrayErrors = Array.isArray(existingErrors) ? existingErrors : [];
1072
+ set$1(fieldArrayErrors, ROOT_ERROR_TYPE, error[name]);
1073
+ set$1(errors, name, fieldArrayErrors);
1074
+ return errors;
1075
+ };
1076
+
1077
+ function getValidateError(result, ref, type = 'validate') {
1078
+ if (isString(result) ||
1079
+ (Array.isArray(result) && result.every(isString)) ||
1080
+ (isBoolean(result) && !result)) {
1081
+ return {
1082
+ type,
1083
+ message: isString(result) ? result : '',
1084
+ ref,
1085
+ };
1086
+ }
1087
+ }
1088
+
1089
+ var getValueAndMessage = (validationData) => isObject(validationData) && !isRegex(validationData)
1090
+ ? validationData
1091
+ : {
1092
+ value: validationData,
1093
+ message: '',
1094
+ };
1095
+
1096
+ var validateField = async (field, disabledFieldNames, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
1097
+ const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, } = field._f;
1098
+ const inputValue = get(formValues, name);
1099
+ if (!mount || disabledFieldNames.has(name)) {
1100
+ return {};
1101
+ }
1102
+ const inputRef = refs ? refs[0] : ref;
1103
+ const setCustomValidity = (message) => {
1104
+ if (shouldUseNativeValidation && inputRef.reportValidity) {
1105
+ const validityMessage = isBoolean(message) ? '' : message || '';
1106
+ if (refs) {
1107
+ refs.forEach((ref) => ref.setCustomValidity(validityMessage));
1108
+ }
1109
+ else {
1110
+ inputRef.setCustomValidity(validityMessage);
1111
+ }
1112
+ inputRef.reportValidity();
1113
+ }
1114
+ };
1115
+ const error = {};
1116
+ const isRadio = isRadioInput(ref);
1117
+ const isCheckBox = isCheckBoxInput(ref);
1118
+ const isRadioOrCheckbox = isRadio || isCheckBox;
1119
+ const isEmpty = ((valueAsNumber || isFileInput(ref)) &&
1120
+ isUndefined(ref.value) &&
1121
+ isUndefined(inputValue)) ||
1122
+ (isHTMLElement(ref) && ref.value === '') ||
1123
+ inputValue === '' ||
1124
+ (Array.isArray(inputValue) && !inputValue.length);
1125
+ const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
1126
+ const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
1127
+ const message = exceedMax ? maxLengthMessage : minLengthMessage;
1128
+ error[name] = {
1129
+ type: exceedMax ? maxType : minType,
1130
+ message,
1131
+ ref,
1132
+ ...appendErrorsCurry(exceedMax ? maxType : minType, message),
1133
+ };
1134
+ };
1135
+ if (isFieldArray
1136
+ ? !Array.isArray(inputValue) || !inputValue.length
1137
+ : required &&
1138
+ ((!isRadioOrCheckbox && (isEmpty || isNullOrUndefined(inputValue))) ||
1139
+ (isBoolean(inputValue) && !inputValue) ||
1140
+ (isCheckBox && !getCheckboxValue(refs).isValid) ||
1141
+ (isRadio && !getRadioValue(refs).isValid))) {
1142
+ const { value, message } = isString(required)
1143
+ ? { value: !!required, message: required }
1144
+ : getValueAndMessage(required);
1145
+ if (value) {
1146
+ error[name] = {
1147
+ type: INPUT_VALIDATION_RULES.required,
1148
+ message,
1149
+ ref: inputRef,
1150
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message),
1151
+ };
1152
+ if (!validateAllFieldCriteria) {
1153
+ setCustomValidity(message);
1154
+ return error;
1155
+ }
1156
+ }
1157
+ }
1158
+ if (!isEmpty && (!isNullOrUndefined(min) || !isNullOrUndefined(max))) {
1159
+ let exceedMax;
1160
+ let exceedMin;
1161
+ const maxOutput = getValueAndMessage(max);
1162
+ const minOutput = getValueAndMessage(min);
1163
+ if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
1164
+ const valueNumber = ref.valueAsNumber ||
1165
+ (inputValue ? +inputValue : inputValue);
1166
+ if (!isNullOrUndefined(maxOutput.value)) {
1167
+ exceedMax = valueNumber > maxOutput.value;
1168
+ }
1169
+ if (!isNullOrUndefined(minOutput.value)) {
1170
+ exceedMin = valueNumber < minOutput.value;
1171
+ }
1172
+ }
1173
+ else {
1174
+ const valueDate = ref.valueAsDate || new Date(inputValue);
1175
+ const convertTimeToDate = (time) => new Date(new Date().toDateString() + ' ' + time);
1176
+ const isTime = ref.type == 'time';
1177
+ const isWeek = ref.type == 'week';
1178
+ if (isString(maxOutput.value) && inputValue) {
1179
+ exceedMax = isTime
1180
+ ? convertTimeToDate(inputValue) > convertTimeToDate(maxOutput.value)
1181
+ : isWeek
1182
+ ? inputValue > maxOutput.value
1183
+ : valueDate > new Date(maxOutput.value);
1184
+ }
1185
+ if (isString(minOutput.value) && inputValue) {
1186
+ exceedMin = isTime
1187
+ ? convertTimeToDate(inputValue) < convertTimeToDate(minOutput.value)
1188
+ : isWeek
1189
+ ? inputValue < minOutput.value
1190
+ : valueDate < new Date(minOutput.value);
1191
+ }
1192
+ }
1193
+ if (exceedMax || exceedMin) {
1194
+ getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
1195
+ if (!validateAllFieldCriteria) {
1196
+ setCustomValidity(error[name].message);
1197
+ return error;
1198
+ }
1199
+ }
1200
+ }
1201
+ if ((maxLength || minLength) &&
1202
+ !isEmpty &&
1203
+ (isString(inputValue) || (isFieldArray && Array.isArray(inputValue)))) {
1204
+ const maxLengthOutput = getValueAndMessage(maxLength);
1205
+ const minLengthOutput = getValueAndMessage(minLength);
1206
+ const exceedMax = !isNullOrUndefined(maxLengthOutput.value) &&
1207
+ inputValue.length > +maxLengthOutput.value;
1208
+ const exceedMin = !isNullOrUndefined(minLengthOutput.value) &&
1209
+ inputValue.length < +minLengthOutput.value;
1210
+ if (exceedMax || exceedMin) {
1211
+ getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
1212
+ if (!validateAllFieldCriteria) {
1213
+ setCustomValidity(error[name].message);
1214
+ return error;
1215
+ }
1216
+ }
1217
+ }
1218
+ if (pattern && !isEmpty && isString(inputValue)) {
1219
+ const { value: patternValue, message } = getValueAndMessage(pattern);
1220
+ if (isRegex(patternValue) && !inputValue.match(patternValue)) {
1221
+ error[name] = {
1222
+ type: INPUT_VALIDATION_RULES.pattern,
1223
+ message,
1224
+ ref,
1225
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message),
1226
+ };
1227
+ if (!validateAllFieldCriteria) {
1228
+ setCustomValidity(message);
1229
+ return error;
1230
+ }
1231
+ }
1232
+ }
1233
+ if (validate) {
1234
+ if (isFunction(validate)) {
1235
+ const result = await validate(inputValue, formValues);
1236
+ const validateError = getValidateError(result, inputRef);
1237
+ if (validateError) {
1238
+ error[name] = {
1239
+ ...validateError,
1240
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message),
1241
+ };
1242
+ if (!validateAllFieldCriteria) {
1243
+ setCustomValidity(validateError.message);
1244
+ return error;
1245
+ }
1246
+ }
1247
+ }
1248
+ else if (isObject(validate)) {
1249
+ let validationResult = {};
1250
+ for (const key in validate) {
1251
+ if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
1252
+ break;
1253
+ }
1254
+ const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
1255
+ if (validateError) {
1256
+ validationResult = {
1257
+ ...validateError,
1258
+ ...appendErrorsCurry(key, validateError.message),
1259
+ };
1260
+ setCustomValidity(validateError.message);
1261
+ if (validateAllFieldCriteria) {
1262
+ error[name] = validationResult;
1263
+ }
1264
+ }
1265
+ }
1266
+ if (!isEmptyObject(validationResult)) {
1267
+ error[name] = {
1268
+ ref: inputRef,
1269
+ ...validationResult,
1270
+ };
1271
+ if (!validateAllFieldCriteria) {
1272
+ return error;
1273
+ }
1274
+ }
1275
+ }
1276
+ }
1277
+ setCustomValidity(true);
1278
+ return error;
1279
+ };
1280
+
1281
+ const defaultOptions = {
1282
+ mode: VALIDATION_MODE.onSubmit,
1283
+ reValidateMode: VALIDATION_MODE.onChange,
1284
+ shouldFocusError: true,
1285
+ };
1286
+ const FORM_ERROR_TYPE = 'form';
1287
+ const DEFAULT_FORM_STATE = {
1288
+ submitCount: 0,
1289
+ isDirty: false,
1290
+ isReady: false,
1291
+ isValidating: false,
1292
+ isSubmitted: false,
1293
+ isSubmitting: false,
1294
+ isSubmitSuccessful: false,
1295
+ isValid: false,
1296
+ touchedFields: {},
1297
+ dirtyFields: {},
1298
+ validatingFields: {},
1299
+ };
1300
+ function createFormControl(props = {}) {
1301
+ let _options = {
1302
+ ...defaultOptions,
1303
+ ...props,
1304
+ };
1305
+ let _formState = {
1306
+ ...cloneObject(DEFAULT_FORM_STATE),
1307
+ isLoading: isFunction(_options.defaultValues),
1308
+ errors: _options.errors || {},
1309
+ disabled: _options.disabled || false,
1310
+ };
1311
+ let _fields = {};
1312
+ let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
1313
+ ? cloneObject(_options.defaultValues || _options.values) || {}
1314
+ : {};
1315
+ let _formValues = _options.shouldUnregister
1316
+ ? {}
1317
+ : cloneObject(_defaultValues);
1318
+ let _state = {
1319
+ action: false,
1320
+ mount: false,
1321
+ watch: false,
1322
+ keepIsValid: false,
1323
+ };
1324
+ let _names = {
1325
+ mount: new Set(),
1326
+ disabled: new Set(),
1327
+ unMount: new Set(),
1328
+ array: new Set(),
1329
+ watch: new Set(),
1330
+ registerName: new Set(),
1331
+ };
1332
+ let delayErrorCallback;
1333
+ let timer = 0;
1334
+ let _valuesSubscriberCount = 0;
1335
+ let _validationModeBeforeSubmit = getValidationModes(_options.mode);
1336
+ let _validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
1337
+ const defaultProxyFormState = {
1338
+ isDirty: false,
1339
+ dirtyFields: false,
1340
+ validatingFields: false,
1341
+ touchedFields: false,
1342
+ isValidating: false,
1343
+ isValid: false,
1344
+ errors: false,
1345
+ };
1346
+ const _proxyFormState = {
1347
+ ...defaultProxyFormState,
1348
+ };
1349
+ let _proxySubscribeFormState = {
1350
+ ..._proxyFormState,
1351
+ };
1352
+ const _subjects = {
1353
+ array: createSubject(),
1354
+ state: createSubject(),
1355
+ };
1356
+ const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
1357
+ const debounce = (callback) => (wait) => {
1358
+ clearTimeout(timer);
1359
+ timer = setTimeout(callback, wait);
1360
+ };
1361
+ const _setValid = async (shouldUpdateValid) => {
1362
+ if (_state.keepIsValid) {
1363
+ return;
1364
+ }
1365
+ if (!_options.disabled &&
1366
+ (_proxyFormState.isValid ||
1367
+ _proxySubscribeFormState.isValid ||
1368
+ shouldUpdateValid)) {
1369
+ let isValid;
1370
+ if (_options.resolver) {
1371
+ isValid = isEmptyObject((await _runSchema()).errors);
1372
+ _updateIsValidating();
1373
+ }
1374
+ else {
1375
+ isValid = await executeBuiltInValidation({
1376
+ fields: _fields,
1377
+ onlyCheckValid: true,
1378
+ eventType: EVENTS.VALID,
1379
+ });
1380
+ }
1381
+ if (isValid !== _formState.isValid) {
1382
+ _subjects.state.next({
1383
+ isValid,
1384
+ });
1385
+ }
1386
+ }
1387
+ };
1388
+ const _updateIsValidating = (names, isValidating) => {
1389
+ if (!_options.disabled &&
1390
+ (_proxyFormState.isValidating ||
1391
+ _proxyFormState.validatingFields ||
1392
+ _proxySubscribeFormState.isValidating ||
1393
+ _proxySubscribeFormState.validatingFields)) {
1394
+ (names || Array.from(_names.mount)).forEach((name) => {
1395
+ if (name) {
1396
+ isValidating
1397
+ ? set$1(_formState.validatingFields, name, isValidating)
1398
+ : unset(_formState.validatingFields, name);
1399
+ }
1400
+ });
1401
+ _subjects.state.next({
1402
+ validatingFields: _formState.validatingFields,
1403
+ isValidating: !isEmptyObject(_formState.validatingFields),
1404
+ });
1405
+ }
1406
+ };
1407
+ const _updateDirtyFields = () => {
1408
+ _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
1409
+ };
1410
+ const _setFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
1411
+ if (args && method && !_options.disabled) {
1412
+ _state.action = true;
1413
+ if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
1414
+ const fieldValues = method(get(_fields, name), args.argA, args.argB);
1415
+ shouldSetValues && set$1(_fields, name, fieldValues);
1416
+ }
1417
+ if (shouldUpdateFieldsAndState &&
1418
+ Array.isArray(get(_formState.errors, name))) {
1419
+ const errors = method(get(_formState.errors, name), args.argA, args.argB);
1420
+ shouldSetValues && set$1(_formState.errors, name, errors);
1421
+ unsetEmptyArray(_formState.errors, name);
1422
+ }
1423
+ if ((_proxyFormState.touchedFields ||
1424
+ _proxySubscribeFormState.touchedFields) &&
1425
+ shouldUpdateFieldsAndState &&
1426
+ Array.isArray(get(_formState.touchedFields, name))) {
1427
+ const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
1428
+ shouldSetValues && set$1(_formState.touchedFields, name, touchedFields);
1429
+ }
1430
+ if (_proxyFormState.dirtyFields || _proxySubscribeFormState.dirtyFields) {
1431
+ _updateDirtyFields();
1432
+ }
1433
+ _subjects.state.next({
1434
+ name,
1435
+ isDirty: _getDirty(name, values),
1436
+ dirtyFields: _formState.dirtyFields,
1437
+ errors: _formState.errors,
1438
+ isValid: _formState.isValid,
1439
+ });
1440
+ }
1441
+ else {
1442
+ set$1(_formValues, name, values);
1443
+ }
1444
+ };
1445
+ const updateErrors = (name, error) => {
1446
+ set$1(_formState.errors, name, error);
1447
+ _formState.errors = { ..._formState.errors };
1448
+ _subjects.state.next({
1449
+ errors: _formState.errors,
1450
+ });
1451
+ };
1452
+ const _setErrors = (errors) => {
1453
+ _formState.errors = errors;
1454
+ _subjects.state.next({
1455
+ errors: _formState.errors,
1456
+ isValid: false,
1457
+ });
1458
+ };
1459
+ const hasExplicitNullIntermediate = (name) => {
1460
+ const segments = isKey(name) ? [name] : stringToPath(name);
1461
+ let formValues = _formValues;
1462
+ let defaultValues = _defaultValues;
1463
+ for (let i = 0; i < segments.length - 1; i++) {
1464
+ const key = segments[i];
1465
+ formValues = isNullOrUndefined(formValues) ? formValues : formValues[key];
1466
+ defaultValues = isNullOrUndefined(defaultValues)
1467
+ ? defaultValues
1468
+ : defaultValues[key];
1469
+ if (formValues === null && defaultValues !== null) {
1470
+ return true;
1471
+ }
1472
+ }
1473
+ return false;
1474
+ };
1475
+ const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
1476
+ const field = get(_fields, name);
1477
+ if (field) {
1478
+ if (hasExplicitNullIntermediate(name)) {
1479
+ return;
1480
+ }
1481
+ const wasUnsetInFormValues = isUndefined(get(_formValues, name));
1482
+ const defaultValue = get(_formValues, name, isUndefined(value) ? get(_defaultValues, name) : value);
1483
+ isUndefined(defaultValue) ||
1484
+ (ref && ref.defaultChecked) ||
1485
+ shouldSkipSetValueAs
1486
+ ? set$1(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f))
1487
+ : setFieldValue(name, defaultValue);
1488
+ if (_state.mount && !_state.action) {
1489
+ _setValid();
1490
+ if (wasUnsetInFormValues &&
1491
+ _formState.isDirty &&
1492
+ (_proxyFormState.isDirty || _proxySubscribeFormState.isDirty)) {
1493
+ const isDirty = _getDirty();
1494
+ if (!isDirty) {
1495
+ _formState.isDirty = false;
1496
+ _subjects.state.next({ ..._formState });
1497
+ }
1498
+ }
1499
+ if (props.shouldUnregister &&
1500
+ wasUnsetInFormValues &&
1501
+ !isUndefined(get(_formValues, name)) &&
1502
+ isWatched(name, _names)) {
1503
+ _state.watch = true;
1504
+ }
1505
+ }
1506
+ }
1507
+ };
1508
+ const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
1509
+ let shouldUpdateField = false;
1510
+ let isPreviousDirty = false;
1511
+ const output = {
1512
+ name,
1513
+ };
1514
+ if (!_options.disabled) {
1515
+ if (!isBlurEvent || shouldDirty) {
1516
+ const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
1517
+ if (_proxyFormState.isDirty || _proxySubscribeFormState.isDirty) {
1518
+ isPreviousDirty = _formState.isDirty;
1519
+ _formState.isDirty = output.isDirty =
1520
+ !isCurrentFieldPristine || _getDirty();
1521
+ shouldUpdateField = isPreviousDirty !== output.isDirty;
1522
+ }
1523
+ isPreviousDirty = !!get(_formState.dirtyFields, name);
1524
+ if (isCurrentFieldPristine !== _formState.isDirty) {
1525
+ _formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
1526
+ }
1527
+ else {
1528
+ isCurrentFieldPristine
1529
+ ? unset(_formState.dirtyFields, name)
1530
+ : set$1(_formState.dirtyFields, name, true);
1531
+ }
1532
+ output.dirtyFields = _formState.dirtyFields;
1533
+ shouldUpdateField =
1534
+ shouldUpdateField ||
1535
+ ((_proxyFormState.dirtyFields ||
1536
+ _proxySubscribeFormState.dirtyFields) &&
1537
+ isPreviousDirty !== !isCurrentFieldPristine);
1538
+ }
1539
+ if (isBlurEvent) {
1540
+ const isPreviousFieldTouched = get(_formState.touchedFields, name);
1541
+ if (!isPreviousFieldTouched) {
1542
+ set$1(_formState.touchedFields, name, isBlurEvent);
1543
+ output.touchedFields = _formState.touchedFields;
1544
+ shouldUpdateField =
1545
+ shouldUpdateField ||
1546
+ ((_proxyFormState.touchedFields ||
1547
+ _proxySubscribeFormState.touchedFields) &&
1548
+ isPreviousFieldTouched !== isBlurEvent);
1549
+ }
1550
+ }
1551
+ shouldUpdateField && shouldRender && _subjects.state.next(output);
1552
+ }
1553
+ return shouldUpdateField ? output : {};
1554
+ };
1555
+ const shouldRenderByError = (name, isValid, error, fieldState) => {
1556
+ const previousFieldError = get(_formState.errors, name);
1557
+ const shouldUpdateValid = (_proxyFormState.isValid || _proxySubscribeFormState.isValid) &&
1558
+ isBoolean(isValid) &&
1559
+ _formState.isValid !== isValid;
1560
+ if (_options.delayError && error) {
1561
+ delayErrorCallback = debounce(() => updateErrors(name, error));
1562
+ delayErrorCallback(_options.delayError);
1563
+ }
1564
+ else {
1565
+ clearTimeout(timer);
1566
+ delayErrorCallback = null;
1567
+ error
1568
+ ? set$1(_formState.errors, name, error)
1569
+ : unset(_formState.errors, name);
1570
+ _formState.errors = { ..._formState.errors };
1571
+ }
1572
+ if ((error ? !deepEqual(previousFieldError, error) : previousFieldError) ||
1573
+ !isEmptyObject(fieldState) ||
1574
+ shouldUpdateValid) {
1575
+ const updatedFormState = {
1576
+ ...fieldState,
1577
+ ...(shouldUpdateValid && isBoolean(isValid) ? { isValid } : {}),
1578
+ errors: _formState.errors,
1579
+ name,
1580
+ };
1581
+ _formState = {
1582
+ ..._formState,
1583
+ ...updatedFormState,
1584
+ };
1585
+ _subjects.state.next(updatedFormState);
1586
+ }
1587
+ };
1588
+ const _runSchema = async (name) => {
1589
+ _updateIsValidating(name, true);
1590
+ return await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1591
+ };
1592
+ const executeSchemaAndUpdateState = async (names) => {
1593
+ const { errors } = await _runSchema(names);
1594
+ _updateIsValidating(names);
1595
+ if (names) {
1596
+ for (const name of names) {
1597
+ const error = get(errors, name);
1598
+ error
1599
+ ? _names.array.has(name) &&
1600
+ isObject(error) &&
1601
+ !Object.keys(error).some((key) => !Number.isNaN(Number(key)))
1602
+ ? updateFieldArrayRootError(_formState.errors, { [name]: error }, name)
1603
+ : set$1(_formState.errors, name, error)
1604
+ : unset(_formState.errors, name);
1605
+ }
1606
+ _formState.errors = { ..._formState.errors };
1607
+ }
1608
+ else {
1609
+ _formState.errors = errors;
1610
+ }
1611
+ return errors;
1612
+ };
1613
+ const validateForm = async ({ name, eventType, }) => {
1614
+ if (props.validate) {
1615
+ const result = await props.validate({
1616
+ formValues: _formValues,
1617
+ formState: _formState,
1618
+ name,
1619
+ eventType,
1620
+ });
1621
+ if (isObject(result)) {
1622
+ for (const key in result) {
1623
+ const error = result[key];
1624
+ if (error) {
1625
+ setError(`${FORM_ERROR_TYPE}.${key}`, {
1626
+ message: isString(error.message) ? error.message : '',
1627
+ type: error.type || INPUT_VALIDATION_RULES.validate,
1628
+ });
1629
+ }
1630
+ }
1631
+ }
1632
+ else if (isString(result) || !result) {
1633
+ setError(FORM_ERROR_TYPE, {
1634
+ message: result || '',
1635
+ type: INPUT_VALIDATION_RULES.validate,
1636
+ });
1637
+ }
1638
+ else {
1639
+ clearErrors(FORM_ERROR_TYPE);
1640
+ }
1641
+ return result;
1642
+ }
1643
+ return true;
1644
+ };
1645
+ const executeBuiltInValidation = async ({ fields, onlyCheckValid, name, eventType, context = {
1646
+ valid: true,
1647
+ runRootValidation: false,
1648
+ }, }) => {
1649
+ if (props.validate) {
1650
+ context.runRootValidation = true;
1651
+ const result = await validateForm({
1652
+ name,
1653
+ eventType,
1654
+ });
1655
+ if (!result) {
1656
+ context.valid = false;
1657
+ if (onlyCheckValid) {
1658
+ return context.valid;
1659
+ }
1660
+ }
1661
+ }
1662
+ for (const name in fields) {
1663
+ const field = fields[name];
1664
+ if (field) {
1665
+ const { _f, ...fieldValue } = field;
1666
+ if (_f) {
1667
+ const isFieldArrayRoot = _names.array.has(_f.name);
1668
+ const isPromiseFunction = field._f && hasPromiseValidation(field._f);
1669
+ const shouldTrackIsValidatingState = _proxyFormState.validatingFields ||
1670
+ _proxyFormState.isValidating ||
1671
+ _proxySubscribeFormState.validatingFields ||
1672
+ _proxySubscribeFormState.isValidating;
1673
+ if (isPromiseFunction && shouldTrackIsValidatingState) {
1674
+ _updateIsValidating([_f.name], true);
1675
+ }
1676
+ const fieldError = await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !onlyCheckValid, isFieldArrayRoot);
1677
+ if (isPromiseFunction && shouldTrackIsValidatingState) {
1678
+ _updateIsValidating([_f.name]);
1679
+ }
1680
+ if (fieldError[_f.name]) {
1681
+ context.valid = false;
1682
+ if (onlyCheckValid) {
1683
+ break;
1684
+ }
1685
+ }
1686
+ !onlyCheckValid &&
1687
+ (get(fieldError, _f.name)
1688
+ ? isFieldArrayRoot
1689
+ ? updateFieldArrayRootError(_formState.errors, fieldError, _f.name)
1690
+ : set$1(_formState.errors, _f.name, fieldError[_f.name])
1691
+ : unset(_formState.errors, _f.name));
1692
+ if (props.shouldUseNativeValidation && fieldError[_f.name]) {
1693
+ break;
1694
+ }
1695
+ }
1696
+ !isEmptyObject(fieldValue) &&
1697
+ (await executeBuiltInValidation({
1698
+ context,
1699
+ onlyCheckValid,
1700
+ fields: fieldValue,
1701
+ name: name,
1702
+ eventType,
1703
+ }));
1704
+ }
1705
+ }
1706
+ return context.valid;
1707
+ };
1708
+ const _removeUnmounted = () => {
1709
+ for (const name of _names.unMount) {
1710
+ const field = get(_fields, name);
1711
+ field &&
1712
+ (field._f.refs
1713
+ ? field._f.refs.every((ref) => !live(ref))
1714
+ : !live(field._f.ref)) &&
1715
+ unregister(name);
1716
+ }
1717
+ _names.unMount = new Set();
1718
+ };
1719
+ const _getDirty = (name, data) => !_options.disabled &&
1720
+ (name && data && set$1(_formValues, name, data),
1721
+ !deepEqual(_state.mount ? _formValues : _defaultValues, _defaultValues));
1722
+ const _getWatch = (names, defaultValue, isGlobal) => generateWatchOutput(names, _names, {
1723
+ ...(_state.mount
1724
+ ? _formValues
1725
+ : isUndefined(defaultValue)
1726
+ ? _defaultValues
1727
+ : isString(names)
1728
+ ? { [names]: defaultValue }
1729
+ : defaultValue),
1730
+ }, isGlobal, defaultValue);
1731
+ const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, _options.shouldUnregister ? get(_defaultValues, name, []) : []));
1732
+ const setFieldValue = (name, value, options = {}, skipClone = false, skipRender = false) => {
1733
+ const field = get(_fields, name);
1734
+ let fieldValue = value;
1735
+ if (field) {
1736
+ const fieldReference = field._f;
1737
+ if (fieldReference) {
1738
+ !fieldReference.disabled &&
1739
+ set$1(_formValues, name, getFieldValueAs(value, fieldReference));
1740
+ fieldValue =
1741
+ isHTMLElement(fieldReference.ref) && isNullOrUndefined(value)
1742
+ ? ''
1743
+ : value;
1744
+ if (isMultipleSelect(fieldReference.ref)) {
1745
+ [...fieldReference.ref.options].forEach((optionRef) => (optionRef.selected = fieldValue.includes(optionRef.value)));
1746
+ }
1747
+ else if (fieldReference.refs) {
1748
+ if (isCheckBoxInput(fieldReference.ref)) {
1749
+ fieldReference.refs.forEach((checkboxRef) => {
1750
+ if (!checkboxRef.defaultChecked || !checkboxRef.disabled) {
1751
+ if (Array.isArray(fieldValue)) {
1752
+ checkboxRef.checked = !!fieldValue.find((data) => data === checkboxRef.value);
1753
+ }
1754
+ else {
1755
+ checkboxRef.checked =
1756
+ fieldValue === checkboxRef.value || !!fieldValue;
1757
+ }
1758
+ }
1759
+ });
1760
+ }
1761
+ else {
1762
+ fieldReference.refs.forEach((radioRef) => (radioRef.checked = radioRef.value === fieldValue));
1763
+ }
1764
+ }
1765
+ else if (isFileInput(fieldReference.ref)) {
1766
+ fieldReference.ref.value = '';
1767
+ }
1768
+ else {
1769
+ fieldReference.ref.value = fieldValue;
1770
+ if (!fieldReference.ref.type && !skipRender) {
1771
+ _subjects.state.next({
1772
+ name,
1773
+ values: skipClone ? _formValues : cloneObject(_formValues),
1774
+ });
1775
+ }
1776
+ }
1777
+ }
1778
+ }
1779
+ (options.shouldDirty || options.shouldTouch) &&
1780
+ updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, !skipRender);
1781
+ options.shouldValidate && trigger(name);
1782
+ };
1783
+ const setFieldValues = (name, value, options, skipClone = false, skipRender = false) => {
1784
+ for (const fieldKey in value) {
1785
+ if (!value.hasOwnProperty(fieldKey)) {
1786
+ return;
1787
+ }
1788
+ const fieldValue = value[fieldKey];
1789
+ const fieldName = name + '.' + fieldKey;
1790
+ const field = get(_fields, fieldName);
1791
+ (_names.array.has(name) ||
1792
+ isObject(fieldValue) ||
1793
+ (field && !field._f)) &&
1794
+ !isDateObject(fieldValue)
1795
+ ? setFieldValues(fieldName, fieldValue, options, skipClone, skipRender)
1796
+ : setFieldValue(fieldName, fieldValue, options, skipClone, skipRender);
1797
+ }
1798
+ };
1799
+ const _setValue = (name, value, options, skipClone, skipStateEmit = false) => {
1800
+ const field = get(_fields, name);
1801
+ const isFieldArray = _names.array.has(name);
1802
+ const cloneValue = skipClone ? value : cloneObject(value);
1803
+ const previousValue = get(_formValues, name);
1804
+ const isValueUnchanged = deepEqual(previousValue, cloneValue);
1805
+ if (!isValueUnchanged) {
1806
+ set$1(_formValues, name, cloneValue);
1807
+ }
1808
+ if (isFieldArray) {
1809
+ _subjects.array.next({
1810
+ name,
1811
+ values: skipClone ? _formValues : cloneObject(_formValues),
1812
+ });
1813
+ if ((_proxyFormState.isDirty ||
1814
+ _proxyFormState.dirtyFields ||
1815
+ _proxySubscribeFormState.isDirty ||
1816
+ _proxySubscribeFormState.dirtyFields) &&
1817
+ options.shouldDirty) {
1818
+ _updateDirtyFields();
1819
+ if (!skipStateEmit) {
1820
+ _subjects.state.next({
1821
+ name,
1822
+ dirtyFields: _formState.dirtyFields,
1823
+ isDirty: _getDirty(name, cloneValue),
1824
+ });
1825
+ }
1826
+ }
1827
+ }
1828
+ else {
1829
+ const isEmpty = (Array.isArray(cloneValue) && !cloneValue.length) ||
1830
+ isEmptyObject(cloneValue);
1831
+ if (!field || field._f || isNullOrUndefined(cloneValue) || isEmpty) {
1832
+ setFieldValue(name, cloneValue, options, skipClone, skipStateEmit);
1833
+ }
1834
+ else {
1835
+ setFieldValues(name, cloneValue, options, skipClone, skipStateEmit);
1836
+ }
1837
+ }
1838
+ if (!isValueUnchanged && !skipStateEmit) {
1839
+ const watched = isWatched(name, _names);
1840
+ const values = skipClone ? _formValues : cloneObject(_formValues);
1841
+ _subjects.state.next({
1842
+ ...(watched && _formState),
1843
+ name: _state.mount || watched ? name : undefined,
1844
+ values,
1845
+ });
1846
+ }
1847
+ };
1848
+ const setValue = (name, value, options = {}) => _setValue(name, value, options, false);
1849
+ const setValues = (formValues, options = {}) => {
1850
+ const updatedFormValues = isFunction(formValues)
1851
+ ? formValues(_formValues)
1852
+ : formValues;
1853
+ if (!deepEqual(_formValues, updatedFormValues)) {
1854
+ _formValues = {
1855
+ ..._formValues,
1856
+ ...updatedFormValues,
1857
+ };
1858
+ const flattenedUpdates = flatten(updatedFormValues);
1859
+ for (const fieldName of _names.mount) {
1860
+ if (fieldName in flattenedUpdates) {
1861
+ _setValue(fieldName, flattenedUpdates[fieldName], options, true, true);
1862
+ }
1863
+ }
1864
+ _subjects.state.next({
1865
+ ..._formState,
1866
+ name: undefined,
1867
+ type: undefined,
1868
+ ...(_valuesSubscriberCount ? { values: _formValues } : {}),
1869
+ });
1870
+ if (options.shouldValidate) {
1871
+ _setValid();
1872
+ }
1873
+ }
1874
+ };
1875
+ const onChange = async (event) => {
1876
+ _state.mount = true;
1877
+ const target = event.target;
1878
+ let name = target.name;
1879
+ let isFieldValueUpdated = true;
1880
+ const field = get(_fields, name);
1881
+ const _updateIsFieldValueUpdated = (fieldValue) => {
1882
+ isFieldValueUpdated =
1883
+ Number.isNaN(fieldValue) ||
1884
+ (isDateObject(fieldValue) && isNaN(fieldValue.getTime())) ||
1885
+ deepEqual(fieldValue, get(_formValues, name, fieldValue));
1886
+ };
1887
+ if (field) {
1888
+ let error;
1889
+ let isValid;
1890
+ const fieldValue = target.type
1891
+ ? getFieldValue(field._f)
1892
+ : getEventValue(event);
1893
+ const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
1894
+ const hasNoValidationEffect = !hasValidation(field._f) &&
1895
+ !props.validate &&
1896
+ !_options.resolver &&
1897
+ !get(_formState.errors, name) &&
1898
+ !field._f.deps;
1899
+ const shouldSkipValidation = hasNoValidationEffect ||
1900
+ skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, _validationModeAfterSubmit, _validationModeBeforeSubmit);
1901
+ const watched = isWatched(name, _names, isBlurEvent);
1902
+ set$1(_formValues, name, fieldValue);
1903
+ if (isBlurEvent) {
1904
+ if (!target || !target.readOnly) {
1905
+ field._f.onBlur && field._f.onBlur(event);
1906
+ delayErrorCallback && delayErrorCallback(0);
1907
+ }
1908
+ }
1909
+ else if (field._f.onChange) {
1910
+ field._f.onChange(event);
1911
+ }
1912
+ const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent);
1913
+ const shouldRender = !isEmptyObject(fieldState) || watched;
1914
+ !isBlurEvent &&
1915
+ _subjects.state.next({
1916
+ name,
1917
+ type: event.type,
1918
+ ...(_valuesSubscriberCount
1919
+ ? { values: cloneObject(_formValues) }
1920
+ : {}),
1921
+ });
1922
+ if (shouldSkipValidation) {
1923
+ if ((!hasNoValidationEffect || !_formState.isValid) &&
1924
+ (_proxyFormState.isValid || _proxySubscribeFormState.isValid)) {
1925
+ if (_options.mode === 'onBlur') {
1926
+ if (isBlurEvent) {
1927
+ _setValid();
1928
+ }
1929
+ }
1930
+ else if (!isBlurEvent) {
1931
+ _setValid();
1932
+ }
1933
+ }
1934
+ return (shouldRender &&
1935
+ _subjects.state.next({ name, ...(watched ? {} : fieldState) }));
1936
+ }
1937
+ if (!_options.resolver && props.validate) {
1938
+ await validateForm({
1939
+ name: name,
1940
+ eventType: event.type,
1941
+ });
1942
+ }
1943
+ !isBlurEvent && watched && _subjects.state.next({ ..._formState });
1944
+ if (_options.resolver) {
1945
+ const { errors } = await _runSchema([name]);
1946
+ _updateIsValidating([name]);
1947
+ _updateIsFieldValueUpdated(fieldValue);
1948
+ if (!isFieldValueUpdated) {
1949
+ !isEmptyObject(fieldState) && _subjects.state.next(fieldState);
1950
+ return;
1951
+ }
1952
+ const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
1953
+ const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
1954
+ error = errorLookupResult.error;
1955
+ name = errorLookupResult.name;
1956
+ isValid = isEmptyObject(errors);
1957
+ }
1958
+ else {
1959
+ _updateIsValidating([name], true);
1960
+ error = (await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1961
+ _updateIsValidating([name]);
1962
+ _updateIsFieldValueUpdated(fieldValue);
1963
+ if (isFieldValueUpdated) {
1964
+ if (error) {
1965
+ isValid = false;
1966
+ }
1967
+ else if (_proxyFormState.isValid ||
1968
+ _proxySubscribeFormState.isValid) {
1969
+ isValid = await executeBuiltInValidation({
1970
+ fields: _fields,
1971
+ onlyCheckValid: true,
1972
+ name: name,
1973
+ eventType: event.type,
1974
+ });
1975
+ }
1976
+ }
1977
+ }
1978
+ if (isFieldValueUpdated) {
1979
+ field._f.deps &&
1980
+ (!Array.isArray(field._f.deps) || field._f.deps.length > 0) &&
1981
+ trigger(field._f.deps);
1982
+ shouldRenderByError(name, isValid, error, fieldState);
1983
+ }
1984
+ }
1985
+ };
1986
+ const _focusInput = (ref, key) => {
1987
+ if (get(_formState.errors, key) && ref.focus) {
1988
+ ref.focus();
1989
+ return 1;
1990
+ }
1991
+ return;
1992
+ };
1993
+ const trigger = async (name, options = {}) => {
1994
+ let isValid;
1995
+ let validationResult;
1996
+ const fieldNames = convertToArrayPayload(name);
1997
+ if (_options.resolver) {
1998
+ const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
1999
+ isValid = isEmptyObject(errors);
2000
+ validationResult = name
2001
+ ? !fieldNames.some((name) => get(errors, name))
2002
+ : isValid;
2003
+ }
2004
+ else if (name) {
2005
+ validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
2006
+ const field = get(_fields, fieldName);
2007
+ return await executeBuiltInValidation({
2008
+ fields: field && field._f ? { [fieldName]: field } : field,
2009
+ eventType: EVENTS.TRIGGER,
2010
+ });
2011
+ }))).every(Boolean);
2012
+ !(!validationResult && !_formState.isValid) && _setValid();
2013
+ }
2014
+ else {
2015
+ validationResult = isValid = await executeBuiltInValidation({
2016
+ fields: _fields,
2017
+ name,
2018
+ eventType: EVENTS.TRIGGER,
2019
+ });
2020
+ }
2021
+ _subjects.state.next({
2022
+ ...(!isString(name) ||
2023
+ ((_proxyFormState.isValid || _proxySubscribeFormState.isValid) &&
2024
+ isValid !== _formState.isValid)
2025
+ ? {}
2026
+ : { name }),
2027
+ ...(_options.resolver || !name ? { isValid } : {}),
2028
+ errors: _formState.errors,
2029
+ });
2030
+ options.shouldFocus &&
2031
+ !validationResult &&
2032
+ iterateFieldsByAction(_fields, _focusInput, name ? fieldNames : _names.mount);
2033
+ return validationResult;
2034
+ };
2035
+ const getValues = (fieldNames, config) => {
2036
+ let values = {
2037
+ ...(_state.mount ? _formValues : _defaultValues),
2038
+ };
2039
+ if (config) {
2040
+ values = extractFormValues(config.dirtyFields ? _formState.dirtyFields : _formState.touchedFields, values);
2041
+ }
2042
+ return isUndefined(fieldNames)
2043
+ ? values
2044
+ : isString(fieldNames)
2045
+ ? get(values, fieldNames)
2046
+ : fieldNames.map((name) => get(values, name));
2047
+ };
2048
+ const getFieldState = (name, formState) => ({
2049
+ invalid: !!get((formState || _formState).errors, name),
2050
+ isDirty: !!get((formState || _formState).dirtyFields, name),
2051
+ error: get((formState || _formState).errors, name),
2052
+ isValidating: !!get(_formState.validatingFields, name),
2053
+ isTouched: !!get((formState || _formState).touchedFields, name),
2054
+ });
2055
+ const clearErrors = (name) => {
2056
+ const names = name ? convertToArrayPayload(name) : undefined;
2057
+ names === null || names === void 0 ? void 0 : names.forEach((inputName) => unset(_formState.errors, inputName));
2058
+ if (names) {
2059
+ names.forEach((inputName) => {
2060
+ _subjects.state.next({
2061
+ name: inputName,
2062
+ errors: _formState.errors,
2063
+ });
2064
+ });
2065
+ }
2066
+ else {
2067
+ _subjects.state.next({
2068
+ errors: {},
2069
+ });
2070
+ }
2071
+ };
2072
+ const setError = (name, error, options) => {
2073
+ const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
2074
+ const currentError = get(_formState.errors, name) || {};
2075
+ const { ref: currentRef, message, type, ...restOfErrorTree } = currentError;
2076
+ set$1(_formState.errors, name, {
2077
+ ...restOfErrorTree,
2078
+ ...error,
2079
+ ref,
2080
+ });
2081
+ _subjects.state.next({
2082
+ name,
2083
+ errors: _formState.errors,
2084
+ isValid: false,
2085
+ });
2086
+ options && options.shouldFocus && ref && ref.focus && ref.focus();
2087
+ };
2088
+ const watch = (name, defaultValue) => {
2089
+ if (isFunction(name)) {
2090
+ _valuesSubscriberCount++;
2091
+ const { unsubscribe } = _subjects.state.subscribe({
2092
+ next: (payload) => 'values' in payload &&
2093
+ name(payload.values || _getWatch(undefined, defaultValue), payload),
2094
+ });
2095
+ let called = false;
2096
+ return {
2097
+ unsubscribe: () => {
2098
+ if (called) {
2099
+ return;
2100
+ }
2101
+ called = true;
2102
+ _valuesSubscriberCount--;
2103
+ unsubscribe();
2104
+ },
2105
+ };
2106
+ }
2107
+ return _getWatch(name, defaultValue, true);
2108
+ };
2109
+ const _subscribe = (props) => {
2110
+ var _a;
2111
+ const needsValues = !!((_a = props.formState) === null || _a === void 0 ? void 0 : _a.values);
2112
+ if (needsValues) {
2113
+ _valuesSubscriberCount++;
2114
+ }
2115
+ const { unsubscribe } = _subjects.state.subscribe({
2116
+ next: (formState) => {
2117
+ if (shouldSubscribeByName(props.name, formState.name, props.exact) &&
2118
+ shouldRenderFormState(formState, props.formState || _proxyFormState, _setFormState, props.reRenderRoot)) {
2119
+ const snapshot = { ..._formValues };
2120
+ props.callback({
2121
+ values: snapshot,
2122
+ ..._formState,
2123
+ ...formState,
2124
+ defaultValues: _defaultValues,
2125
+ });
2126
+ }
2127
+ },
2128
+ });
2129
+ if (!needsValues) {
2130
+ return unsubscribe;
2131
+ }
2132
+ let called = false;
2133
+ return () => {
2134
+ if (called) {
2135
+ return;
2136
+ }
2137
+ called = true;
2138
+ _valuesSubscriberCount--;
2139
+ unsubscribe();
2140
+ };
2141
+ };
2142
+ const subscribe = (props) => {
2143
+ _state.mount = true;
2144
+ _proxySubscribeFormState = {
2145
+ ..._proxySubscribeFormState,
2146
+ ...props.formState,
2147
+ };
2148
+ return _subscribe({
2149
+ ...props,
2150
+ formState: {
2151
+ ...defaultProxyFormState,
2152
+ ...props.formState,
2153
+ },
2154
+ });
2155
+ };
2156
+ const unregister = (name, options = {}) => {
2157
+ for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
2158
+ _names.mount.delete(fieldName);
2159
+ _names.array.delete(fieldName);
2160
+ if (!options.keepValue) {
2161
+ unset(_fields, fieldName);
2162
+ unset(_formValues, fieldName);
2163
+ }
2164
+ !options.keepError && unset(_formState.errors, fieldName);
2165
+ !options.keepDirty && unset(_formState.dirtyFields, fieldName);
2166
+ !options.keepTouched && unset(_formState.touchedFields, fieldName);
2167
+ !options.keepIsValidating &&
2168
+ unset(_formState.validatingFields, fieldName);
2169
+ !_options.shouldUnregister &&
2170
+ !options.keepDefaultValue &&
2171
+ unset(_defaultValues, fieldName);
2172
+ }
2173
+ _subjects.state.next({
2174
+ values: cloneObject(_formValues),
2175
+ });
2176
+ _subjects.state.next({
2177
+ ..._formState,
2178
+ ...(!options.keepDirty ? {} : { isDirty: _getDirty() }),
2179
+ });
2180
+ !options.keepIsValid && _setValid();
2181
+ };
2182
+ const _setDisabledField = ({ disabled, name, }) => {
2183
+ if ((isBoolean(disabled) && _state.mount) ||
2184
+ !!disabled ||
2185
+ _names.disabled.has(name)) {
2186
+ const wasDisabled = _names.disabled.has(name);
2187
+ const isDisabled = !!disabled;
2188
+ const disabledStateChanged = wasDisabled !== isDisabled;
2189
+ disabled ? _names.disabled.add(name) : _names.disabled.delete(name);
2190
+ disabledStateChanged && _state.mount && !_state.action && _setValid();
2191
+ }
2192
+ };
2193
+ const register = (name, options = {}) => {
2194
+ let field = get(_fields, name);
2195
+ const disabledIsDefined = isBoolean(options.disabled) || isBoolean(_options.disabled);
2196
+ const shouldRevalidateRemount = !_names.registerName.has(name) && field && field._f && !field._f.mount;
2197
+ set$1(_fields, name, {
2198
+ ...(field || {}),
2199
+ _f: {
2200
+ ...(field && field._f ? field._f : { ref: { name } }),
2201
+ name,
2202
+ mount: true,
2203
+ ...options,
2204
+ },
2205
+ });
2206
+ _names.mount.add(name);
2207
+ if (field && !shouldRevalidateRemount) {
2208
+ _setDisabledField({
2209
+ disabled: isBoolean(options.disabled)
2210
+ ? options.disabled
2211
+ : _options.disabled,
2212
+ name,
2213
+ });
2214
+ }
2215
+ else {
2216
+ updateValidAndValue(name, true, options.value);
2217
+ }
2218
+ return {
2219
+ ...(disabledIsDefined
2220
+ ? { disabled: options.disabled || _options.disabled }
2221
+ : {}),
2222
+ ...(_options.progressive
2223
+ ? {
2224
+ required: !!options.required,
2225
+ min: getRuleValue(options.min),
2226
+ max: getRuleValue(options.max),
2227
+ minLength: getRuleValue(options.minLength),
2228
+ maxLength: getRuleValue(options.maxLength),
2229
+ pattern: getRuleValue(options.pattern),
2230
+ }
2231
+ : {}),
2232
+ name,
2233
+ onChange,
2234
+ onBlur: onChange,
2235
+ ref: (ref) => {
2236
+ if (ref) {
2237
+ _names.registerName.add(name);
2238
+ register(name, options);
2239
+ _names.registerName.delete(name);
2240
+ field = get(_fields, name);
2241
+ const fieldRef = isUndefined(ref.value)
2242
+ ? ref.querySelectorAll
2243
+ ? ref.querySelectorAll('input,select,textarea')[0] || ref
2244
+ : ref
2245
+ : ref;
2246
+ const radioOrCheckbox = isRadioOrCheckbox(fieldRef);
2247
+ const refs = field._f.refs || [];
2248
+ if (radioOrCheckbox
2249
+ ? refs.find((option) => option === fieldRef)
2250
+ : fieldRef === field._f.ref) {
2251
+ return;
2252
+ }
2253
+ set$1(_fields, name, {
2254
+ _f: {
2255
+ ...field._f,
2256
+ ...(radioOrCheckbox
2257
+ ? {
2258
+ refs: [
2259
+ ...refs.filter(live),
2260
+ fieldRef,
2261
+ ...(Array.isArray(get(_defaultValues, name)) ? [{}] : []),
2262
+ ],
2263
+ ref: { type: fieldRef.type, name },
2264
+ }
2265
+ : { ref: fieldRef }),
2266
+ },
2267
+ });
2268
+ updateValidAndValue(name, false, undefined, fieldRef);
2269
+ }
2270
+ else {
2271
+ field = get(_fields, name, {});
2272
+ if (field._f) {
2273
+ field._f.mount = false;
2274
+ }
2275
+ (_options.shouldUnregister || options.shouldUnregister) &&
2276
+ !(isNameInFieldArray(_names.array, name) && _state.action) &&
2277
+ _names.unMount.add(name);
2278
+ }
2279
+ },
2280
+ };
2281
+ };
2282
+ const _focusError = () => _options.shouldFocusError &&
2283
+ !_options.shouldUseNativeValidation &&
2284
+ iterateFieldsByAction(_fields, _focusInput, _names.mount);
2285
+ const _disableForm = (disabled) => {
2286
+ if (isBoolean(disabled)) {
2287
+ _subjects.state.next({ disabled });
2288
+ iterateFieldsByAction(_fields, (ref, name) => {
2289
+ const currentField = get(_fields, name);
2290
+ if (currentField) {
2291
+ ref.disabled = currentField._f.disabled || disabled;
2292
+ if (Array.isArray(currentField._f.refs)) {
2293
+ currentField._f.refs.forEach((inputRef) => {
2294
+ inputRef.disabled = currentField._f.disabled || disabled;
2295
+ });
2296
+ }
2297
+ }
2298
+ }, 0, false);
2299
+ }
2300
+ };
2301
+ const handleSubmit = (onValid, onInvalid) => async (e) => {
2302
+ let onValidError = undefined;
2303
+ if (e) {
2304
+ e.preventDefault && e.preventDefault();
2305
+ e.persist &&
2306
+ e.persist();
2307
+ }
2308
+ let fieldValues = cloneObject(_formValues);
2309
+ _subjects.state.next({
2310
+ isSubmitting: true,
2311
+ });
2312
+ if (_options.resolver) {
2313
+ const { errors, values } = await _runSchema();
2314
+ _updateIsValidating();
2315
+ _formState.errors = errors;
2316
+ fieldValues = cloneObject(values);
2317
+ }
2318
+ else {
2319
+ await executeBuiltInValidation({
2320
+ fields: _fields,
2321
+ eventType: EVENTS.SUBMIT,
2322
+ });
2323
+ }
2324
+ if (_names.disabled.size) {
2325
+ for (const name of _names.disabled) {
2326
+ unset(fieldValues, name);
2327
+ }
2328
+ }
2329
+ unset(_formState.errors, ROOT_ERROR_TYPE);
2330
+ if (isEmptyObject(_formState.errors)) {
2331
+ _subjects.state.next({
2332
+ errors: {},
2333
+ });
2334
+ try {
2335
+ await onValid(fieldValues, e);
2336
+ }
2337
+ catch (error) {
2338
+ onValidError = error;
2339
+ }
2340
+ }
2341
+ else {
2342
+ if (onInvalid) {
2343
+ await onInvalid({ ..._formState.errors }, e);
2344
+ }
2345
+ _focusError();
2346
+ setTimeout(_focusError);
2347
+ }
2348
+ _subjects.state.next({
2349
+ isSubmitted: true,
2350
+ isSubmitting: false,
2351
+ isSubmitSuccessful: isEmptyObject(_formState.errors) && !onValidError,
2352
+ submitCount: _formState.submitCount + 1,
2353
+ errors: _formState.errors,
2354
+ });
2355
+ if (onValidError) {
2356
+ throw onValidError;
2357
+ }
2358
+ };
2359
+ const resetField = (name, options = {}) => {
2360
+ if (get(_fields, name)) {
2361
+ if (isUndefined(options.defaultValue)) {
2362
+ setValue(name, cloneObject(get(_defaultValues, name)));
2363
+ }
2364
+ else {
2365
+ setValue(name, options.defaultValue);
2366
+ set$1(_defaultValues, name, cloneObject(options.defaultValue));
2367
+ }
2368
+ if (!options.keepTouched) {
2369
+ unset(_formState.touchedFields, name);
2370
+ }
2371
+ if (!options.keepDirty) {
2372
+ unset(_formState.dirtyFields, name);
2373
+ _formState.isDirty = options.defaultValue
2374
+ ? _getDirty(name, cloneObject(get(_defaultValues, name)))
2375
+ : _getDirty();
2376
+ }
2377
+ if (!options.keepError) {
2378
+ unset(_formState.errors, name);
2379
+ _proxyFormState.isValid && _setValid();
2380
+ }
2381
+ _subjects.state.next({ ..._formState });
2382
+ }
2383
+ };
2384
+ const _reset = (formValues, keepStateOptions = {}) => {
2385
+ const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
2386
+ const cloneUpdatedValues = cloneObject(updatedValues);
2387
+ const isEmptyResetValues = isEmptyObject(formValues);
2388
+ const values = cloneUpdatedValues;
2389
+ if (!keepStateOptions.keepDefaultValues) {
2390
+ _defaultValues = updatedValues;
2391
+ }
2392
+ if (!keepStateOptions.keepValues) {
2393
+ if (keepStateOptions.keepDirtyValues) {
2394
+ const fieldsToCheck = new Set([
2395
+ ..._names.mount,
2396
+ ...Object.keys(getDirtyFields(_defaultValues, _formValues)),
2397
+ ]);
2398
+ for (const fieldName of Array.from(fieldsToCheck)) {
2399
+ const isDirty = get(_formState.dirtyFields, fieldName);
2400
+ const existingValue = get(_formValues, fieldName);
2401
+ const newValue = get(values, fieldName);
2402
+ if (isDirty && !isUndefined(existingValue)) {
2403
+ set$1(values, fieldName, existingValue);
2404
+ }
2405
+ else if (!isDirty && !isUndefined(newValue)) {
2406
+ setValue(fieldName, newValue);
2407
+ }
2408
+ }
2409
+ }
2410
+ else {
2411
+ if (isWeb && isUndefined(formValues)) {
2412
+ for (const name of _names.mount) {
2413
+ const field = get(_fields, name);
2414
+ if (field && field._f) {
2415
+ const fieldReference = Array.isArray(field._f.refs)
2416
+ ? field._f.refs[0]
2417
+ : field._f.ref;
2418
+ if (isHTMLElement(fieldReference)) {
2419
+ const form = fieldReference.closest('form');
2420
+ if (form) {
2421
+ form.reset();
2422
+ break;
2423
+ }
2424
+ }
2425
+ }
2426
+ }
2427
+ }
2428
+ if (keepStateOptions.keepFieldsRef) {
2429
+ for (const fieldName of _names.mount) {
2430
+ setValue(fieldName, get(values, fieldName));
2431
+ }
2432
+ }
2433
+ else {
2434
+ _fields = {};
2435
+ }
2436
+ }
2437
+ if (_options.shouldUnregister) {
2438
+ _formValues = keepStateOptions.keepDefaultValues
2439
+ ? cloneObject(_defaultValues)
2440
+ : {};
2441
+ if (keepStateOptions.keepFieldsRef) {
2442
+ for (const fieldName of _names.mount) {
2443
+ set$1(_formValues, fieldName, get(values, fieldName));
2444
+ }
2445
+ }
2446
+ }
2447
+ else {
2448
+ _formValues = cloneObject(values);
2449
+ }
2450
+ _subjects.array.next({
2451
+ values: { ...values },
2452
+ });
2453
+ _subjects.state.next({
2454
+ name: undefined,
2455
+ type: undefined,
2456
+ values: { ...values },
2457
+ });
2458
+ }
2459
+ _names = {
2460
+ mount: keepStateOptions.keepDirtyValues ? _names.mount : new Set(),
2461
+ unMount: new Set(),
2462
+ array: new Set(),
2463
+ registerName: new Set(),
2464
+ disabled: new Set(),
2465
+ watch: new Set(),
2466
+ watchAll: false,
2467
+ focus: '',
2468
+ };
2469
+ _state.mount =
2470
+ !_proxyFormState.isValid ||
2471
+ !!keepStateOptions.keepIsValid ||
2472
+ !!keepStateOptions.keepDirtyValues ||
2473
+ (!_options.shouldUnregister && !isEmptyObject(values));
2474
+ _state.watch = !!_options.shouldUnregister;
2475
+ _state.keepIsValid = !!keepStateOptions.keepIsValid;
2476
+ _state.action = false;
2477
+ if (!keepStateOptions.keepErrors) {
2478
+ _formState.errors = {};
2479
+ }
2480
+ _subjects.state.next({
2481
+ submitCount: keepStateOptions.keepSubmitCount
2482
+ ? _formState.submitCount
2483
+ : 0,
2484
+ isDirty: isEmptyResetValues
2485
+ ? false
2486
+ : keepStateOptions.keepDirty
2487
+ ? _formState.isDirty
2488
+ : keepStateOptions.keepValues
2489
+ ? _getDirty()
2490
+ : !!(keepStateOptions.keepDefaultValues &&
2491
+ !deepEqual(formValues, _defaultValues)),
2492
+ isSubmitted: keepStateOptions.keepIsSubmitted
2493
+ ? _formState.isSubmitted
2494
+ : false,
2495
+ dirtyFields: isEmptyResetValues
2496
+ ? {}
2497
+ : keepStateOptions.keepDirtyValues
2498
+ ? keepStateOptions.keepDefaultValues && _formValues
2499
+ ? getDirtyFields(_defaultValues, _formValues)
2500
+ : _formState.dirtyFields
2501
+ : keepStateOptions.keepDefaultValues && formValues
2502
+ ? getDirtyFields(_defaultValues, formValues)
2503
+ : keepStateOptions.keepDirty
2504
+ ? _formState.dirtyFields
2505
+ : {},
2506
+ touchedFields: keepStateOptions.keepTouched
2507
+ ? _formState.touchedFields
2508
+ : {},
2509
+ errors: keepStateOptions.keepErrors ? _formState.errors : {},
2510
+ isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful
2511
+ ? _formState.isSubmitSuccessful
2512
+ : false,
2513
+ isSubmitting: false,
2514
+ defaultValues: _defaultValues,
2515
+ });
2516
+ };
2517
+ const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
2518
+ ? formValues(_formValues)
2519
+ : formValues, { ..._options.resetOptions, ...keepStateOptions });
2520
+ const setFocus = (name, options = {}) => {
2521
+ const field = get(_fields, name);
2522
+ const fieldReference = field && field._f;
2523
+ if (fieldReference) {
2524
+ const fieldRef = fieldReference.refs
2525
+ ? fieldReference.refs[0]
2526
+ : fieldReference.ref;
2527
+ if (fieldRef.focus) {
2528
+ setTimeout(() => {
2529
+ fieldRef.focus();
2530
+ options.shouldSelect &&
2531
+ isFunction(fieldRef.select) &&
2532
+ fieldRef.select();
2533
+ });
2534
+ }
2535
+ }
2536
+ };
2537
+ const _setFormState = (updatedFormState) => {
2538
+ // `name`, `type`, and `values` describe the event that produced this
2539
+ // update, not the form's persisted state (they aren't part of
2540
+ // `FormState`). Merging them in would leak a stale `name`/`type` from
2541
+ // one event into a later, unrelated notification that doesn't specify
2542
+ // its own.
2543
+ const { name, type, values, ...formState } = updatedFormState;
2544
+ _formState = {
2545
+ ..._formState,
2546
+ ...formState,
2547
+ };
2548
+ };
2549
+ const _resetDefaultValues = () => isFunction(_options.defaultValues) &&
2550
+ _options.defaultValues().then((values) => {
2551
+ reset(values, _options.resetOptions);
2552
+ _subjects.state.next({
2553
+ isLoading: false,
2554
+ });
2555
+ });
2556
+ const resetDefaultValues = (values, options = {}) => {
2557
+ _defaultValues = cloneObject(values);
2558
+ if (!options.keepDirty) {
2559
+ const newDirtyFields = getDirtyFields(_defaultValues, _formValues);
2560
+ _formState.dirtyFields = newDirtyFields;
2561
+ _formState.isDirty = !isEmptyObject(newDirtyFields);
2562
+ }
2563
+ if (!options.keepIsValid) {
2564
+ _setValid();
2565
+ }
2566
+ _subjects.state.next({
2567
+ ..._formState,
2568
+ defaultValues: _defaultValues,
2569
+ });
2570
+ };
2571
+ const methods = {
2572
+ control: {
2573
+ register,
2574
+ unregister,
2575
+ getFieldState,
2576
+ handleSubmit,
2577
+ setError,
2578
+ _subscribe,
2579
+ _runSchema,
2580
+ _updateIsValidating,
2581
+ _focusError,
2582
+ _getWatch,
2583
+ _getDirty,
2584
+ _setValid,
2585
+ _setFieldArray,
2586
+ _setDisabledField,
2587
+ _setErrors,
2588
+ _getFieldArray,
2589
+ _reset,
2590
+ _resetDefaultValues,
2591
+ _removeUnmounted,
2592
+ _disableForm,
2593
+ _subjects,
2594
+ _proxyFormState,
2595
+ get _fields() {
2596
+ return _fields;
2597
+ },
2598
+ get _formValues() {
2599
+ return _formValues;
2600
+ },
2601
+ get _state() {
2602
+ return _state;
2603
+ },
2604
+ set _state(value) {
2605
+ _state = value;
2606
+ },
2607
+ get _defaultValues() {
2608
+ return _defaultValues;
2609
+ },
2610
+ get _names() {
2611
+ return _names;
2612
+ },
2613
+ set _names(value) {
2614
+ _names = value;
2615
+ },
2616
+ get _formState() {
2617
+ return _formState;
2618
+ },
2619
+ get _options() {
2620
+ return _options;
2621
+ },
2622
+ set _options(value) {
2623
+ _options = {
2624
+ ..._options,
2625
+ ...value,
2626
+ };
2627
+ _validationModeBeforeSubmit = getValidationModes(_options.mode);
2628
+ _validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
2629
+ },
2630
+ },
2631
+ subscribe,
2632
+ trigger,
2633
+ register,
2634
+ handleSubmit,
2635
+ watch,
2636
+ setValue,
2637
+ setValues,
2638
+ getValues,
2639
+ reset,
2640
+ resetField,
2641
+ resetDefaultValues,
2642
+ clearErrors,
2643
+ unregister,
2644
+ setError,
2645
+ setFocus,
2646
+ getFieldState,
2647
+ };
2648
+ return {
2649
+ ...methods,
2650
+ formControl: methods,
2651
+ };
2652
+ }
2653
+
2654
+ /**
2655
+ * Custom hook to manage the entire form.
2656
+ *
2657
+ * @remarks
2658
+ * [API](https://react-hook-form.com/docs/useform) • [Demo](https://codesandbox.io/s/react-hook-form-get-started-ts-5ksmm) • [Video](https://www.youtube.com/watch?v=RkXv4AXXC_4)
2659
+ *
2660
+ * @param props - form configuration and validation parameters.
2661
+ *
2662
+ * @returns methods - individual functions to manage the form state. {@link UseFormReturn}
2663
+ *
2664
+ * @example
2665
+ * ```tsx
2666
+ * function App() {
2667
+ * const { register, handleSubmit, watch, formState: { errors } } = useForm();
2668
+ * const onSubmit = data => console.log(data);
2669
+ *
2670
+ * console.log(watch("example"));
2671
+ *
2672
+ * return (
2673
+ * <form onSubmit={handleSubmit(onSubmit)}>
2674
+ * <input defaultValue="test" {...register("example")} />
2675
+ * <input {...register("exampleRequired", { required: true })} />
2676
+ * {errors.exampleRequired && <span>This field is required</span>}
2677
+ * <button>Submit</button>
2678
+ * </form>
2679
+ * );
2680
+ * }
2681
+ * ```
2682
+ */
2683
+ function useForm(props = {}) {
2684
+ const _formControl = React.useRef(undefined);
2685
+ const _values = React.useRef(undefined);
2686
+ const _formControlProp = React.useRef(props.formControl);
2687
+ const [formState, updateFormState] = React.useState(() => ({
2688
+ ...cloneObject(DEFAULT_FORM_STATE),
2689
+ isLoading: isFunction(props.defaultValues),
2690
+ errors: props.errors || {},
2691
+ disabled: props.disabled || false,
2692
+ defaultValues: isFunction(props.defaultValues)
2693
+ ? undefined
2694
+ : props.defaultValues,
2695
+ }));
2696
+ if (!_formControl.current ||
2697
+ (props.formControl && _formControlProp.current !== props.formControl)) {
2698
+ _formControlProp.current = props.formControl;
2699
+ if (props.formControl) {
2700
+ _formControl.current = {
2701
+ ...props.formControl,
2702
+ formState,
2703
+ };
2704
+ if (props.defaultValues && !isFunction(props.defaultValues)) {
2705
+ props.formControl.reset(props.defaultValues, props.resetOptions);
2706
+ }
2707
+ }
2708
+ else {
2709
+ const { formControl, ...rest } = createFormControl(props);
2710
+ _formControl.current = {
2711
+ ...rest,
2712
+ formState,
2713
+ };
2714
+ }
2715
+ }
2716
+ const control = _formControl.current.control;
2717
+ control._options = props;
2718
+ useIsomorphicLayoutEffect(() => {
2719
+ const sub = control._subscribe({
2720
+ formState: control._proxyFormState,
2721
+ callback: () => updateFormState({
2722
+ ...control._formState,
2723
+ defaultValues: control._defaultValues,
2724
+ }),
2725
+ reRenderRoot: true,
2726
+ });
2727
+ updateFormState((data) => ({
2728
+ ...data,
2729
+ isReady: true,
2730
+ }));
2731
+ control._formState.isReady = true;
2732
+ return sub;
2733
+ }, [control]);
2734
+ React.useEffect(() => control._disableForm(props.disabled), [control, props.disabled]);
2735
+ React.useEffect(() => {
2736
+ if (props.mode) {
2737
+ control._options.mode = props.mode;
2738
+ }
2739
+ if (props.reValidateMode) {
2740
+ control._options.reValidateMode = props.reValidateMode;
2741
+ }
2742
+ }, [control, props.mode, props.reValidateMode]);
2743
+ React.useEffect(() => {
2744
+ if (props.errors) {
2745
+ control._setErrors(props.errors);
2746
+ control._focusError();
2747
+ }
2748
+ }, [control, props.errors]);
2749
+ React.useEffect(() => {
2750
+ props.shouldUnregister &&
2751
+ control._subjects.state.next({
2752
+ values: control._getWatch(),
2753
+ });
2754
+ }, [control, props.shouldUnregister]);
2755
+ React.useEffect(() => {
2756
+ if (control._proxyFormState.isDirty) {
2757
+ const isDirty = control._getDirty();
2758
+ if (isDirty !== formState.isDirty) {
2759
+ control._subjects.state.next({
2760
+ isDirty,
2761
+ });
2762
+ }
2763
+ }
2764
+ }, [control, formState.isDirty]);
2765
+ React.useEffect(() => {
2766
+ var _a;
2767
+ if (props.values && !deepEqual(props.values, _values.current)) {
2768
+ control._reset(props.values, {
2769
+ keepFieldsRef: true,
2770
+ ...control._options.resetOptions,
2771
+ });
2772
+ if (!((_a = control._options.resetOptions) === null || _a === void 0 ? void 0 : _a.keepIsValid)) {
2773
+ control._setValid();
2774
+ }
2775
+ _values.current = props.values;
2776
+ updateFormState((state) => ({ ...state }));
2777
+ }
2778
+ else {
2779
+ control._resetDefaultValues();
2780
+ }
2781
+ }, [control, props.values]);
2782
+ React.useEffect(() => {
2783
+ if (!control._state.mount) {
2784
+ control._setValid();
2785
+ control._state.mount = true;
2786
+ }
2787
+ if (control._state.watch) {
2788
+ control._state.watch = false;
2789
+ control._subjects.state.next({ ...control._formState });
2790
+ }
2791
+ control._removeUnmounted();
2792
+ });
2793
+ _formControl.current.formState = React.useMemo(() => getProxyFormState(formState, control), [control, formState]);
2794
+ return _formControl.current;
2795
+ }
2796
+
2797
+ export { Controller, appendErrors, createFormControl, get, set$1 as set, useController, useForm, useFormState, useWatch };
2798
+ //# sourceMappingURL=index.esm.js.map