@contember/react-form 2.0.0-alpha.3 → 2.0.0-alpha.30

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 (206) hide show
  1. package/api-extractor.json +3 -0
  2. package/dist/development/index.cjs +16 -12
  3. package/dist/development/index.cjs.map +1 -1
  4. package/dist/development/index.js +14 -10
  5. package/dist/development/index.js.map +1 -1
  6. package/dist/development/{components → src/components}/FormCheckbox.cjs +12 -9
  7. package/dist/development/src/components/FormCheckbox.cjs.map +1 -0
  8. package/dist/development/{components → src/components}/FormCheckbox.js +13 -10
  9. package/dist/development/src/components/FormCheckbox.js.map +1 -0
  10. package/dist/development/{components → src/components}/FormError.cjs +5 -5
  11. package/dist/development/src/components/FormError.cjs.map +1 -0
  12. package/dist/development/{components → src/components}/FormError.js +6 -6
  13. package/dist/development/src/components/FormError.js.map +1 -0
  14. package/dist/development/src/components/FormFieldScope.cjs +33 -0
  15. package/dist/development/src/components/FormFieldScope.cjs.map +1 -0
  16. package/dist/development/src/components/FormFieldScope.js +33 -0
  17. package/dist/development/src/components/FormFieldScope.js.map +1 -0
  18. package/dist/development/src/components/FormFieldStateProvider.cjs +56 -0
  19. package/dist/development/src/components/FormFieldStateProvider.cjs.map +1 -0
  20. package/dist/development/src/components/FormFieldStateProvider.js +56 -0
  21. package/dist/development/src/components/FormFieldStateProvider.js.map +1 -0
  22. package/dist/development/src/components/FormHasManyRelationScope.cjs +33 -0
  23. package/dist/development/src/components/FormHasManyRelationScope.cjs.map +1 -0
  24. package/dist/development/src/components/FormHasManyRelationScope.js +33 -0
  25. package/dist/development/src/components/FormHasManyRelationScope.js.map +1 -0
  26. package/dist/development/src/components/FormHasOneRelationScope.cjs +33 -0
  27. package/dist/development/src/components/FormHasOneRelationScope.cjs.map +1 -0
  28. package/dist/development/src/components/FormHasOneRelationScope.js +33 -0
  29. package/dist/development/src/components/FormHasOneRelationScope.js.map +1 -0
  30. package/dist/development/{components → src/components}/FormInput.cjs +13 -8
  31. package/dist/development/src/components/FormInput.cjs.map +1 -0
  32. package/dist/development/{components → src/components}/FormInput.js +14 -9
  33. package/dist/development/src/components/FormInput.js.map +1 -0
  34. package/dist/development/{components → src/components}/FormLabel.cjs +8 -6
  35. package/dist/development/src/components/FormLabel.cjs.map +1 -0
  36. package/dist/development/{components → src/components}/FormLabel.js +9 -7
  37. package/dist/development/src/components/FormLabel.js.map +1 -0
  38. package/dist/development/{components → src/components}/FormRadioInput.cjs +19 -15
  39. package/dist/development/src/components/FormRadioInput.cjs.map +1 -0
  40. package/dist/development/{components → src/components}/FormRadioInput.js +20 -16
  41. package/dist/development/src/components/FormRadioInput.js.map +1 -0
  42. package/dist/development/src/contexts.cjs +13 -0
  43. package/dist/development/src/contexts.cjs.map +1 -0
  44. package/dist/development/src/contexts.js +13 -0
  45. package/dist/development/src/contexts.js.map +1 -0
  46. package/dist/{production → development/src}/hooks/useFormInputValidationHandler.cjs +12 -3
  47. package/dist/development/src/hooks/useFormInputValidationHandler.cjs.map +1 -0
  48. package/dist/{production → development/src}/hooks/useFormInputValidationHandler.js +12 -3
  49. package/dist/development/src/hooks/useFormInputValidationHandler.js.map +1 -0
  50. package/dist/development/src/internal/useFormInputHandler.cjs.map +1 -0
  51. package/dist/development/src/internal/useFormInputHandler.js.map +1 -0
  52. package/dist/production/index.cjs +16 -12
  53. package/dist/production/index.cjs.map +1 -1
  54. package/dist/production/index.js +14 -10
  55. package/dist/production/index.js.map +1 -1
  56. package/dist/production/{components → src/components}/FormCheckbox.cjs +7 -4
  57. package/dist/production/src/components/FormCheckbox.cjs.map +1 -0
  58. package/dist/production/{components → src/components}/FormCheckbox.js +8 -5
  59. package/dist/production/src/components/FormCheckbox.js.map +1 -0
  60. package/dist/production/{components → src/components}/FormError.cjs +5 -5
  61. package/dist/production/src/components/FormError.cjs.map +1 -0
  62. package/dist/production/{components → src/components}/FormError.js +6 -6
  63. package/dist/production/src/components/FormError.js.map +1 -0
  64. package/dist/production/src/components/FormFieldScope.cjs +25 -0
  65. package/dist/production/src/components/FormFieldScope.cjs.map +1 -0
  66. package/dist/production/src/components/FormFieldScope.js +25 -0
  67. package/dist/production/src/components/FormFieldScope.js.map +1 -0
  68. package/dist/production/src/components/FormFieldStateProvider.cjs +34 -0
  69. package/dist/production/src/components/FormFieldStateProvider.cjs.map +1 -0
  70. package/dist/production/src/components/FormFieldStateProvider.js +34 -0
  71. package/dist/production/src/components/FormFieldStateProvider.js.map +1 -0
  72. package/dist/production/src/components/FormHasManyRelationScope.cjs +25 -0
  73. package/dist/production/src/components/FormHasManyRelationScope.cjs.map +1 -0
  74. package/dist/production/src/components/FormHasManyRelationScope.js +25 -0
  75. package/dist/production/src/components/FormHasManyRelationScope.js.map +1 -0
  76. package/dist/production/src/components/FormHasOneRelationScope.cjs +25 -0
  77. package/dist/production/src/components/FormHasOneRelationScope.cjs.map +1 -0
  78. package/dist/production/src/components/FormHasOneRelationScope.js +25 -0
  79. package/dist/production/src/components/FormHasOneRelationScope.js.map +1 -0
  80. package/dist/production/{components → src/components}/FormInput.cjs +9 -4
  81. package/dist/production/src/components/FormInput.cjs.map +1 -0
  82. package/dist/production/{components → src/components}/FormInput.js +10 -5
  83. package/dist/production/src/components/FormInput.js.map +1 -0
  84. package/dist/production/{components → src/components}/FormLabel.cjs +7 -5
  85. package/dist/production/src/components/FormLabel.cjs.map +1 -0
  86. package/dist/production/{components → src/components}/FormLabel.js +8 -6
  87. package/dist/production/src/components/FormLabel.js.map +1 -0
  88. package/dist/production/{components → src/components}/FormRadioInput.cjs +15 -11
  89. package/dist/production/src/components/FormRadioInput.cjs.map +1 -0
  90. package/dist/production/{components → src/components}/FormRadioInput.js +16 -12
  91. package/dist/production/src/components/FormRadioInput.js.map +1 -0
  92. package/dist/production/src/contexts.cjs +13 -0
  93. package/dist/production/src/contexts.cjs.map +1 -0
  94. package/dist/production/src/contexts.js +13 -0
  95. package/dist/production/src/contexts.js.map +1 -0
  96. package/dist/{development → production/src}/hooks/useFormInputValidationHandler.cjs +12 -3
  97. package/dist/production/src/hooks/useFormInputValidationHandler.cjs.map +1 -0
  98. package/dist/{development → production/src}/hooks/useFormInputValidationHandler.js +12 -3
  99. package/dist/production/src/hooks/useFormInputValidationHandler.js.map +1 -0
  100. package/dist/production/src/internal/useFormInputHandler.cjs.map +1 -0
  101. package/dist/production/src/internal/useFormInputHandler.js.map +1 -0
  102. package/dist/types/components/FormCheckbox.d.ts.map +1 -1
  103. package/dist/types/components/FormError.d.ts.map +1 -1
  104. package/dist/types/components/FormFieldScope.d.ts +2 -1
  105. package/dist/types/components/FormFieldScope.d.ts.map +1 -1
  106. package/dist/types/components/FormFieldStateProvider.d.ts +36 -0
  107. package/dist/types/components/FormFieldStateProvider.d.ts.map +1 -0
  108. package/dist/types/components/FormHasManyRelationScope.d.ts +2 -1
  109. package/dist/types/components/FormHasManyRelationScope.d.ts.map +1 -1
  110. package/dist/types/components/FormHasOneRelationScope.d.ts +2 -1
  111. package/dist/types/components/FormHasOneRelationScope.d.ts.map +1 -1
  112. package/dist/types/components/FormInput.d.ts.map +1 -1
  113. package/dist/types/components/FormLabel.d.ts.map +1 -1
  114. package/dist/types/components/FormRadioInput.d.ts +1 -1
  115. package/dist/types/components/FormRadioInput.d.ts.map +1 -1
  116. package/dist/types/components/index.d.ts +1 -0
  117. package/dist/types/components/index.d.ts.map +1 -1
  118. package/dist/types/contexts.d.ts +10 -6
  119. package/dist/types/contexts.d.ts.map +1 -1
  120. package/dist/types/hooks/useFormInputValidationHandler.d.ts.map +1 -1
  121. package/dist/types/internal/useFormInputHandler.d.ts.map +1 -1
  122. package/dist/types/tsconfig.tsbuildinfo +1 -1
  123. package/dist/types/types/index.d.ts +12 -0
  124. package/dist/types/types/index.d.ts.map +1 -1
  125. package/package.json +8 -16
  126. package/src/components/FormCheckbox.tsx +32 -21
  127. package/src/components/FormError.tsx +6 -6
  128. package/src/components/FormFieldScope.tsx +17 -12
  129. package/src/components/FormFieldStateProvider.tsx +71 -0
  130. package/src/components/FormHasManyRelationScope.tsx +18 -13
  131. package/src/components/FormHasOneRelationScope.tsx +17 -13
  132. package/src/components/FormInput.tsx +12 -5
  133. package/src/components/FormLabel.tsx +8 -6
  134. package/src/components/FormRadioInput.tsx +22 -15
  135. package/src/components/index.ts +1 -0
  136. package/src/contexts.tsx +18 -0
  137. package/src/hooks/useFormInputValidationHandler.tsx +13 -3
  138. package/src/tsconfig.json +5 -2
  139. package/src/types/index.ts +13 -0
  140. package/tsconfig.json +7 -0
  141. package/tsdoc.json +6 -0
  142. package/dist/development/components/FormCheckbox.cjs.map +0 -1
  143. package/dist/development/components/FormCheckbox.js.map +0 -1
  144. package/dist/development/components/FormError.cjs.map +0 -1
  145. package/dist/development/components/FormError.js.map +0 -1
  146. package/dist/development/components/FormFieldScope.cjs +0 -23
  147. package/dist/development/components/FormFieldScope.cjs.map +0 -1
  148. package/dist/development/components/FormFieldScope.js +0 -23
  149. package/dist/development/components/FormFieldScope.js.map +0 -1
  150. package/dist/development/components/FormHasManyRelationScope.cjs +0 -23
  151. package/dist/development/components/FormHasManyRelationScope.cjs.map +0 -1
  152. package/dist/development/components/FormHasManyRelationScope.js +0 -23
  153. package/dist/development/components/FormHasManyRelationScope.js.map +0 -1
  154. package/dist/development/components/FormHasOneRelationScope.cjs +0 -23
  155. package/dist/development/components/FormHasOneRelationScope.cjs.map +0 -1
  156. package/dist/development/components/FormHasOneRelationScope.js +0 -23
  157. package/dist/development/components/FormHasOneRelationScope.js.map +0 -1
  158. package/dist/development/components/FormInput.cjs.map +0 -1
  159. package/dist/development/components/FormInput.js.map +0 -1
  160. package/dist/development/components/FormLabel.cjs.map +0 -1
  161. package/dist/development/components/FormLabel.js.map +0 -1
  162. package/dist/development/components/FormRadioInput.cjs.map +0 -1
  163. package/dist/development/components/FormRadioInput.js.map +0 -1
  164. package/dist/development/contexts.cjs +0 -14
  165. package/dist/development/contexts.cjs.map +0 -1
  166. package/dist/development/contexts.js +0 -14
  167. package/dist/development/contexts.js.map +0 -1
  168. package/dist/development/hooks/useFormInputValidationHandler.cjs.map +0 -1
  169. package/dist/development/hooks/useFormInputValidationHandler.js.map +0 -1
  170. package/dist/development/internal/useFormInputHandler.cjs.map +0 -1
  171. package/dist/development/internal/useFormInputHandler.js.map +0 -1
  172. package/dist/production/components/FormCheckbox.cjs.map +0 -1
  173. package/dist/production/components/FormCheckbox.js.map +0 -1
  174. package/dist/production/components/FormError.cjs.map +0 -1
  175. package/dist/production/components/FormError.js.map +0 -1
  176. package/dist/production/components/FormFieldScope.cjs +0 -15
  177. package/dist/production/components/FormFieldScope.cjs.map +0 -1
  178. package/dist/production/components/FormFieldScope.js +0 -15
  179. package/dist/production/components/FormFieldScope.js.map +0 -1
  180. package/dist/production/components/FormHasManyRelationScope.cjs +0 -15
  181. package/dist/production/components/FormHasManyRelationScope.cjs.map +0 -1
  182. package/dist/production/components/FormHasManyRelationScope.js +0 -15
  183. package/dist/production/components/FormHasManyRelationScope.js.map +0 -1
  184. package/dist/production/components/FormHasOneRelationScope.cjs +0 -15
  185. package/dist/production/components/FormHasOneRelationScope.cjs.map +0 -1
  186. package/dist/production/components/FormHasOneRelationScope.js +0 -15
  187. package/dist/production/components/FormHasOneRelationScope.js.map +0 -1
  188. package/dist/production/components/FormInput.cjs.map +0 -1
  189. package/dist/production/components/FormInput.js.map +0 -1
  190. package/dist/production/components/FormLabel.cjs.map +0 -1
  191. package/dist/production/components/FormLabel.js.map +0 -1
  192. package/dist/production/components/FormRadioInput.cjs.map +0 -1
  193. package/dist/production/components/FormRadioInput.js.map +0 -1
  194. package/dist/production/contexts.cjs +0 -14
  195. package/dist/production/contexts.cjs.map +0 -1
  196. package/dist/production/contexts.js +0 -14
  197. package/dist/production/contexts.js.map +0 -1
  198. package/dist/production/hooks/useFormInputValidationHandler.cjs.map +0 -1
  199. package/dist/production/hooks/useFormInputValidationHandler.js.map +0 -1
  200. package/dist/production/internal/useFormInputHandler.cjs.map +0 -1
  201. package/dist/production/internal/useFormInputHandler.js.map +0 -1
  202. package/src/contexts.ts +0 -12
  203. /package/dist/development/{internal → src/internal}/useFormInputHandler.cjs +0 -0
  204. /package/dist/development/{internal → src/internal}/useFormInputHandler.js +0 -0
  205. /package/dist/production/{internal → src/internal}/useFormInputHandler.cjs +0 -0
  206. /package/dist/production/{internal → src/internal}/useFormInputHandler.js +0 -0
@@ -1,22 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const contexts = require("./contexts.cjs");
4
- const FormError = require("./components/FormError.cjs");
5
- const FormCheckbox = require("./components/FormCheckbox.cjs");
6
- const FormFieldScope = require("./components/FormFieldScope.cjs");
7
- const FormHasOneRelationScope = require("./components/FormHasOneRelationScope.cjs");
8
- const FormHasManyRelationScope = require("./components/FormHasManyRelationScope.cjs");
9
- const FormInput = require("./components/FormInput.cjs");
10
- const FormLabel = require("./components/FormLabel.cjs");
11
- const FormRadioInput = require("./components/FormRadioInput.cjs");
12
- const useFormInputValidationHandler = require("./hooks/useFormInputValidationHandler.cjs");
13
- exports.FormErrorContext = contexts.FormErrorContext;
14
- exports.FormFieldIdContext = contexts.FormFieldIdContext;
3
+ const contexts = require("./src/contexts.cjs");
4
+ const FormError = require("./src/components/FormError.cjs");
5
+ const FormCheckbox = require("./src/components/FormCheckbox.cjs");
6
+ const FormFieldScope = require("./src/components/FormFieldScope.cjs");
7
+ const FormFieldStateProvider = require("./src/components/FormFieldStateProvider.cjs");
8
+ const FormHasOneRelationScope = require("./src/components/FormHasOneRelationScope.cjs");
9
+ const FormHasManyRelationScope = require("./src/components/FormHasManyRelationScope.cjs");
10
+ const FormInput = require("./src/components/FormInput.cjs");
11
+ const FormLabel = require("./src/components/FormLabel.cjs");
12
+ const FormRadioInput = require("./src/components/FormRadioInput.cjs");
13
+ const useFormInputValidationHandler = require("./src/hooks/useFormInputValidationHandler.cjs");
14
+ exports.FormFieldStateContext = contexts.FormFieldStateContext;
15
15
  exports.useFormError = contexts.useFormError;
16
16
  exports.useFormFieldId = contexts.useFormFieldId;
17
+ exports.useFormFieldState = contexts.useFormFieldState;
17
18
  exports.FormError = FormError.FormError;
18
19
  exports.FormCheckbox = FormCheckbox.FormCheckbox;
19
20
  exports.FormFieldScope = FormFieldScope.FormFieldScope;
21
+ exports.FormErrorContext = FormFieldStateProvider.FormErrorContext;
22
+ exports.FormFieldIdContext = FormFieldStateProvider.FormFieldIdContext;
23
+ exports.FormFieldStateProvider = FormFieldStateProvider.FormFieldStateProvider;
20
24
  exports.FormHasOneRelationScope = FormHasOneRelationScope.FormHasOneRelationScope;
21
25
  exports.FormHasManyRelationScope = FormHasManyRelationScope.FormHasManyRelationScope;
22
26
  exports.FormInput = FormInput.FormInput;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,19 +1,22 @@
1
- import { FormErrorContext, FormFieldIdContext, useFormError, useFormFieldId } from "./contexts.js";
2
- import { FormError } from "./components/FormError.js";
3
- import { FormCheckbox } from "./components/FormCheckbox.js";
4
- import { FormFieldScope } from "./components/FormFieldScope.js";
5
- import { FormHasOneRelationScope } from "./components/FormHasOneRelationScope.js";
6
- import { FormHasManyRelationScope } from "./components/FormHasManyRelationScope.js";
7
- import { FormInput } from "./components/FormInput.js";
8
- import { FormLabel } from "./components/FormLabel.js";
9
- import { FormRadioInput } from "./components/FormRadioInput.js";
10
- import { useFormInputValidationHandler } from "./hooks/useFormInputValidationHandler.js";
1
+ import { FormFieldStateContext, useFormError, useFormFieldId, useFormFieldState } from "./src/contexts.js";
2
+ import { FormError } from "./src/components/FormError.js";
3
+ import { FormCheckbox } from "./src/components/FormCheckbox.js";
4
+ import { FormFieldScope } from "./src/components/FormFieldScope.js";
5
+ import { FormErrorContext, FormFieldIdContext, FormFieldStateProvider } from "./src/components/FormFieldStateProvider.js";
6
+ import { FormHasOneRelationScope } from "./src/components/FormHasOneRelationScope.js";
7
+ import { FormHasManyRelationScope } from "./src/components/FormHasManyRelationScope.js";
8
+ import { FormInput } from "./src/components/FormInput.js";
9
+ import { FormLabel } from "./src/components/FormLabel.js";
10
+ import { FormRadioInput } from "./src/components/FormRadioInput.js";
11
+ import { useFormInputValidationHandler } from "./src/hooks/useFormInputValidationHandler.js";
11
12
  export {
12
13
  FormCheckbox,
13
14
  FormError,
14
15
  FormErrorContext,
15
16
  FormFieldIdContext,
16
17
  FormFieldScope,
18
+ FormFieldStateContext,
19
+ FormFieldStateProvider,
17
20
  FormHasManyRelationScope,
18
21
  FormHasOneRelationScope,
19
22
  FormInput,
@@ -21,6 +24,7 @@ export {
21
24
  FormRadioInput,
22
25
  useFormError,
23
26
  useFormFieldId,
27
+ useFormFieldState,
24
28
  useFormInputValidationHandler
25
29
  };
26
30
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -26,10 +26,12 @@ function _interopNamespaceDefault(e) {
26
26
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
27
27
  const SlotInput = reactSlot.Slot;
28
28
  const FormCheckbox = reactBinding.Component(({ field, isNonbearing, defaultValue, ...props }) => {
29
- const id = contexts.useFormFieldId();
30
29
  const accessor = reactBinding.useField(field);
30
+ const formState = contexts.useFormFieldState();
31
+ const id = formState?.htmlId;
32
+ const hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0;
33
+ const dirty = formState?.dirty ?? accessor.hasUnpersistedChanges;
31
34
  const value = accessor.value;
32
- const errors = contexts.useFormError() ?? accessor.errors?.errors ?? [];
33
35
  const accessorGetter = accessor.getAccessor;
34
36
  const { ref, onFocus, onBlur } = useFormInputValidationHandler.useFormInputValidationHandler(accessor);
35
37
  const [checkboxRef, setCheckboxRef] = React__namespace.useState(null);
@@ -49,8 +51,9 @@ const FormCheckbox = reactBinding.Component(({ field, isNonbearing, defaultValue
49
51
  type: "checkbox",
50
52
  checked: accessor.value === true,
51
53
  "data-state": value === null ? "indeterminate" : value ? "checked" : "unchecked",
52
- "data-invalid": utilities.dataAttribute(errors.length > 0),
53
- id: `${id}-input`,
54
+ "data-invalid": utilities.dataAttribute(hasErrors),
55
+ "data-dirty": utilities.dataAttribute(dirty),
56
+ id: id ? `${id}-input` : void 0,
54
57
  onFocus,
55
58
  onBlur,
56
59
  onChange: React.useCallback((e) => {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormCheckbox.cjs","sources":["../../../../../packages/react-form/src/components/FormCheckbox.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ReactElement, useCallback, useEffect } from 'react'\nimport {\n\tComponent,\n\tField,\n\tOptionallyVariableFieldValue,\n\tSugaredRelativeSingleField,\n\tTreeNodeEnvironmentFactory,\n\tuseField,\n} from '@contember/react-binding'\nimport { useFormFieldState } from '../contexts'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormInputValidationHandler } from '../hooks'\nimport { Slot } from '@radix-ui/react-slot'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormCheckboxProps {\n\tfield: SugaredRelativeSingleField['field']\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: ReactElement<HTMLInputElement, 'input'>\n}\n\nexport const FormCheckbox = Component<FormCheckboxProps>(({ field, isNonbearing, defaultValue, ...props }) => {\n\tconst accessor = useField<boolean>(field)\n\n\tconst formState = useFormFieldState()\n\tconst id = formState?.htmlId\n\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\tconst value = accessor.value\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\tconst [checkboxRef, setCheckboxRef] = React.useState<HTMLInputElement | null>(null)\n\n\tuseEffect(() => {\n\t\tif (!checkboxRef) {\n\t\t\treturn\n\t\t}\n\t\tcheckboxRef.indeterminate = value === null\n\t}, [checkboxRef, ref, value])\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={it => {\n\t\t\t\t(ref as any).current = checkboxRef\n\t\t\t\tsetCheckboxRef(it)\n\t\t\t}}\n\t\t\ttype=\"checkbox\"\n\t\t\tchecked={accessor.value === true}\n\t\t\tdata-state={value === null ? 'indeterminate' : (value ? 'checked' : 'unchecked')}\n\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\taccessorGetter().updateValue(e.target.checked)\n\t\t\t}, [accessorGetter])}\n\t\t\t{...props}\n\t\t/>\n\t)\n}, ({ field, isNonbearing, defaultValue }, env) => {\n\tconst node = TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode()\n\tconst resolvedDefaultValue = defaultValue !== undefined ? defaultValue : (node.field.defaultValue ?? (node.field.nullable ? null : false))\n\n\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={resolvedDefaultValue} />\n})\n"],"names":["Slot","Component","useField","useFormFieldState","useFormInputValidationHandler","React","useEffect","jsx","dataAttribute","useCallback","TreeNodeEnvironmentFactory","Field"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,YAAYA,UAAAA;AASL,MAAA,eAAeC,uBAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AACvG,QAAA,WAAWC,sBAAkB,KAAK;AAExC,QAAM,YAAYC,SAAAA;AAClB,QAAM,KAAK,WAAW;AAChB,QAAA,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACjF,QAAA,QAAQ,WAAW,SAAS,SAAS;AAC3C,QAAM,QAAQ,SAAS;AACvB,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAO,IAAIC,8BAAAA,8BAA8B,QAAQ;AACvE,QAAM,CAAC,aAAa,cAAc,IAAIC,iBAAM,SAAkC,IAAI;AAElFC,QAAAA,UAAU,MAAM;AACf,QAAI,CAAC,aAAa;AACjB;AAAA,IACD;AACA,gBAAY,gBAAgB,UAAU;AAAA,EACpC,GAAA,CAAC,aAAa,KAAK,KAAK,CAAC;AAG3B,SAAAC,2BAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,KAAK,CAAM,OAAA;AACT,YAAY,UAAU;AACvB,uBAAe,EAAE;AAAA,MAClB;AAAA,MACA,MAAK;AAAA,MACL,SAAS,SAAS,UAAU;AAAA,MAC5B,cAAY,UAAU,OAAO,kBAAmB,QAAQ,YAAY;AAAA,MACpE,gBAAcC,wBAAc,SAAS;AAAA,MACrC,cAAYA,wBAAc,KAAK;AAAA,MAC/B,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB;AAAA,MACA;AAAA,MACA,UAAUC,MAAAA,YAAkD,CAAK,MAAA;AAChE,uBAAiB,EAAA,YAAY,EAAE,OAAO,OAAO;AAAA,MAAA,GAC3C,CAAC,cAAc,CAAC;AAAA,MAClB,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP,GAAG,CAAC,EAAE,OAAO,cAAc,aAAA,GAAgB,QAAQ;AAC5C,QAAA,OAAOC,wCAA2B,0BAA0B,KAAK,EAAE,MAAO,CAAA,EAAE;AAC5E,QAAA,uBAAuB,iBAAiB,SAAY,eAAgB,KAAK,MAAM,iBAAiB,KAAK,MAAM,WAAW,OAAO;AAEnI,SAAQH,2BAAAA,IAAAI,aAAAA,OAAA,EAAM,OAAc,cAA4B,cAAc,qBAAsB,CAAA;AAC7F,CAAC;;"}
@@ -2,16 +2,18 @@ import { jsx } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import { useEffect, useCallback } from "react";
4
4
  import { Component, useField, TreeNodeEnvironmentFactory, Field } from "@contember/react-binding";
5
- import { useFormFieldId, useFormError } from "../contexts.js";
5
+ import { useFormFieldState } from "../contexts.js";
6
6
  import { dataAttribute } from "@contember/utilities";
7
7
  import { Slot } from "@radix-ui/react-slot";
8
8
  import { useFormInputValidationHandler } from "../hooks/useFormInputValidationHandler.js";
9
9
  const SlotInput = Slot;
10
10
  const FormCheckbox = Component(({ field, isNonbearing, defaultValue, ...props }) => {
11
- const id = useFormFieldId();
12
11
  const accessor = useField(field);
12
+ const formState = useFormFieldState();
13
+ const id = formState?.htmlId;
14
+ const hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0;
15
+ const dirty = formState?.dirty ?? accessor.hasUnpersistedChanges;
13
16
  const value = accessor.value;
14
- const errors = useFormError() ?? accessor.errors?.errors ?? [];
15
17
  const accessorGetter = accessor.getAccessor;
16
18
  const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor);
17
19
  const [checkboxRef, setCheckboxRef] = React.useState(null);
@@ -31,8 +33,9 @@ const FormCheckbox = Component(({ field, isNonbearing, defaultValue, ...props })
31
33
  type: "checkbox",
32
34
  checked: accessor.value === true,
33
35
  "data-state": value === null ? "indeterminate" : value ? "checked" : "unchecked",
34
- "data-invalid": dataAttribute(errors.length > 0),
35
- id: `${id}-input`,
36
+ "data-invalid": dataAttribute(hasErrors),
37
+ "data-dirty": dataAttribute(dirty),
38
+ id: id ? `${id}-input` : void 0,
36
39
  onFocus,
37
40
  onBlur,
38
41
  onChange: useCallback((e) => {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormCheckbox.js","sources":["../../../../../packages/react-form/src/components/FormCheckbox.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ReactElement, useCallback, useEffect } from 'react'\nimport {\n\tComponent,\n\tField,\n\tOptionallyVariableFieldValue,\n\tSugaredRelativeSingleField,\n\tTreeNodeEnvironmentFactory,\n\tuseField,\n} from '@contember/react-binding'\nimport { useFormFieldState } from '../contexts'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormInputValidationHandler } from '../hooks'\nimport { Slot } from '@radix-ui/react-slot'\n\nconst SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>\n\nexport interface FormCheckboxProps {\n\tfield: SugaredRelativeSingleField['field']\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: ReactElement<HTMLInputElement, 'input'>\n}\n\nexport const FormCheckbox = Component<FormCheckboxProps>(({ field, isNonbearing, defaultValue, ...props }) => {\n\tconst accessor = useField<boolean>(field)\n\n\tconst formState = useFormFieldState()\n\tconst id = formState?.htmlId\n\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\tconst value = accessor.value\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\tconst [checkboxRef, setCheckboxRef] = React.useState<HTMLInputElement | null>(null)\n\n\tuseEffect(() => {\n\t\tif (!checkboxRef) {\n\t\t\treturn\n\t\t}\n\t\tcheckboxRef.indeterminate = value === null\n\t}, [checkboxRef, ref, value])\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={it => {\n\t\t\t\t(ref as any).current = checkboxRef\n\t\t\t\tsetCheckboxRef(it)\n\t\t\t}}\n\t\t\ttype=\"checkbox\"\n\t\t\tchecked={accessor.value === true}\n\t\t\tdata-state={value === null ? 'indeterminate' : (value ? 'checked' : 'unchecked')}\n\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\taccessorGetter().updateValue(e.target.checked)\n\t\t\t}, [accessorGetter])}\n\t\t\t{...props}\n\t\t/>\n\t)\n}, ({ field, isNonbearing, defaultValue }, env) => {\n\tconst node = TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode()\n\tconst resolvedDefaultValue = defaultValue !== undefined ? defaultValue : (node.field.defaultValue ?? (node.field.nullable ? null : false))\n\n\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={resolvedDefaultValue} />\n})\n"],"names":[],"mappings":";;;;;;;;AAeA,MAAM,YAAY;AASL,MAAA,eAAe,UAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AACvG,QAAA,WAAW,SAAkB,KAAK;AAExC,QAAM,YAAY;AAClB,QAAM,KAAK,WAAW;AAChB,QAAA,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACjF,QAAA,QAAQ,WAAW,SAAS,SAAS;AAC3C,QAAM,QAAQ,SAAS;AACvB,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAO,IAAI,8BAA8B,QAAQ;AACvE,QAAM,CAAC,aAAa,cAAc,IAAI,MAAM,SAAkC,IAAI;AAElF,YAAU,MAAM;AACf,QAAI,CAAC,aAAa;AACjB;AAAA,IACD;AACA,gBAAY,gBAAgB,UAAU;AAAA,EACpC,GAAA,CAAC,aAAa,KAAK,KAAK,CAAC;AAG3B,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,KAAK,CAAM,OAAA;AACT,YAAY,UAAU;AACvB,uBAAe,EAAE;AAAA,MAClB;AAAA,MACA,MAAK;AAAA,MACL,SAAS,SAAS,UAAU;AAAA,MAC5B,cAAY,UAAU,OAAO,kBAAmB,QAAQ,YAAY;AAAA,MACpE,gBAAc,cAAc,SAAS;AAAA,MACrC,cAAY,cAAc,KAAK;AAAA,MAC/B,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB;AAAA,MACA;AAAA,MACA,UAAU,YAAkD,CAAK,MAAA;AAChE,uBAAiB,EAAA,YAAY,EAAE,OAAO,OAAO;AAAA,MAAA,GAC3C,CAAC,cAAc,CAAC;AAAA,MAClB,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP,GAAG,CAAC,EAAE,OAAO,cAAc,aAAA,GAAgB,QAAQ;AAC5C,QAAA,OAAO,2BAA2B,0BAA0B,KAAK,EAAE,MAAO,CAAA,EAAE;AAC5E,QAAA,uBAAuB,iBAAiB,SAAY,eAAgB,KAAK,MAAM,iBAAiB,KAAK,MAAM,WAAW,OAAO;AAEnI,SAAQ,oBAAA,OAAA,EAAM,OAAc,cAA4B,cAAc,qBAAsB,CAAA;AAC7F,CAAC;"}
@@ -4,16 +4,16 @@ const React = require("react");
4
4
  const contexts = require("../contexts.cjs");
5
5
  const reactBinding = require("@contember/react-binding");
6
6
  const FormError = ({ children, formatter }) => {
7
- const errors = contexts.useFormError();
8
- const id = contexts.useFormFieldId();
9
- const formatted = React.useMemo(() => formatter(errors ?? []), [errors, formatter]);
10
- if (errors === void 0 || id === void 0) {
7
+ const formState = contexts.useFormFieldState();
8
+ if (!formState) {
11
9
  throw new reactBinding.BindingError("FormError must be used inside a FormField");
12
10
  }
11
+ const { errors, htmlId } = formState;
12
+ const formatted = React.useMemo(() => formatter(errors ?? []).filter((it, index, arr) => arr.indexOf(it) === index), [errors, formatter]);
13
13
  return formatted.map((it, index) => {
14
14
  return React.cloneElement(children, {
15
15
  key: index,
16
- ...{ id: `${id}-error-${index}` },
16
+ ...htmlId ? { id: `${htmlId}-error-${index}` } : {},
17
17
  children: it
18
18
  });
19
19
  });
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormError.cjs","sources":["../../../../../packages/react-form/src/components/FormError.tsx"],"sourcesContent":["import { cloneElement, ReactElement, ReactNode, useMemo } from 'react'\nimport { useFormFieldState } from '../contexts'\nimport { BindingError, ErrorAccessor } from '@contember/react-binding'\n\nexport const FormError = ({ children, formatter }: {\n\tformatter: (errors: ErrorAccessor.Error[]) => ReactNode[]\n\tchildren: ReactElement\n}) => {\n\tconst formState = useFormFieldState()\n\tif (!formState) {\n\t\tthrow new BindingError('FormError must be used inside a FormField')\n\t}\n\tconst { errors, htmlId } = formState\n\tconst formatted = useMemo(() => formatter(errors ?? []).filter((it, index, arr) => arr.indexOf(it) === index), [errors, formatter])\n\treturn formatted.map((it, index) => {\n\t\treturn cloneElement(children, {\n\t\t\tkey: index,\n\t\t\t...(htmlId ? { id: `${htmlId}-error-${index}` } : {}),\n\t\t\tchildren: it,\n\t\t})\n\t})\n}\n"],"names":["useFormFieldState","BindingError","useMemo","cloneElement"],"mappings":";;;;;AAIO,MAAM,YAAY,CAAC,EAAE,UAAU,gBAGhC;AACL,QAAM,YAAYA,SAAAA;AAClB,MAAI,CAAC,WAAW;AACT,UAAA,IAAIC,aAAAA,aAAa,2CAA2C;AAAA,EACnE;AACM,QAAA,EAAE,QAAQ,OAAW,IAAA;AACrB,QAAA,YAAYC,cAAQ,MAAM,UAAU,UAAU,EAAE,EAAE,OAAO,CAAC,IAAI,OAAO,QAAQ,IAAI,QAAQ,EAAE,MAAM,KAAK,GAAG,CAAC,QAAQ,SAAS,CAAC;AAClI,SAAO,UAAU,IAAI,CAAC,IAAI,UAAU;AACnC,WAAOC,MAAAA,aAAa,UAAU;AAAA,MAC7B,KAAK;AAAA,MACL,GAAI,SAAS,EAAE,IAAI,GAAG,MAAM,UAAU,KAAK,GAAG,IAAI,CAAC;AAAA,MACnD,UAAU;AAAA,IAAA,CACV;AAAA,EAAA,CACD;AACF;;"}
@@ -1,17 +1,17 @@
1
1
  import { useMemo, cloneElement } from "react";
2
- import { useFormError, useFormFieldId } from "../contexts.js";
2
+ import { useFormFieldState } from "../contexts.js";
3
3
  import { BindingError } from "@contember/react-binding";
4
4
  const FormError = ({ children, formatter }) => {
5
- const errors = useFormError();
6
- const id = useFormFieldId();
7
- const formatted = useMemo(() => formatter(errors ?? []), [errors, formatter]);
8
- if (errors === void 0 || id === void 0) {
5
+ const formState = useFormFieldState();
6
+ if (!formState) {
9
7
  throw new BindingError("FormError must be used inside a FormField");
10
8
  }
9
+ const { errors, htmlId } = formState;
10
+ const formatted = useMemo(() => formatter(errors ?? []).filter((it, index, arr) => arr.indexOf(it) === index), [errors, formatter]);
11
11
  return formatted.map((it, index) => {
12
12
  return cloneElement(children, {
13
13
  key: index,
14
- ...{ id: `${id}-error-${index}` },
14
+ ...htmlId ? { id: `${htmlId}-error-${index}` } : {},
15
15
  children: it
16
16
  });
17
17
  });
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormError.js","sources":["../../../../../packages/react-form/src/components/FormError.tsx"],"sourcesContent":["import { cloneElement, ReactElement, ReactNode, useMemo } from 'react'\nimport { useFormFieldState } from '../contexts'\nimport { BindingError, ErrorAccessor } from '@contember/react-binding'\n\nexport const FormError = ({ children, formatter }: {\n\tformatter: (errors: ErrorAccessor.Error[]) => ReactNode[]\n\tchildren: ReactElement\n}) => {\n\tconst formState = useFormFieldState()\n\tif (!formState) {\n\t\tthrow new BindingError('FormError must be used inside a FormField')\n\t}\n\tconst { errors, htmlId } = formState\n\tconst formatted = useMemo(() => formatter(errors ?? []).filter((it, index, arr) => arr.indexOf(it) === index), [errors, formatter])\n\treturn formatted.map((it, index) => {\n\t\treturn cloneElement(children, {\n\t\t\tkey: index,\n\t\t\t...(htmlId ? { id: `${htmlId}-error-${index}` } : {}),\n\t\t\tchildren: it,\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,YAAY,CAAC,EAAE,UAAU,gBAGhC;AACL,QAAM,YAAY;AAClB,MAAI,CAAC,WAAW;AACT,UAAA,IAAI,aAAa,2CAA2C;AAAA,EACnE;AACM,QAAA,EAAE,QAAQ,OAAW,IAAA;AACrB,QAAA,YAAY,QAAQ,MAAM,UAAU,UAAU,EAAE,EAAE,OAAO,CAAC,IAAI,OAAO,QAAQ,IAAI,QAAQ,EAAE,MAAM,KAAK,GAAG,CAAC,QAAQ,SAAS,CAAC;AAClI,SAAO,UAAU,IAAI,CAAC,IAAI,UAAU;AACnC,WAAO,aAAa,UAAU;AAAA,MAC7B,KAAK;AAAA,MACL,GAAI,SAAS,EAAE,IAAI,GAAG,MAAM,UAAU,KAAK,GAAG,IAAI,CAAC;AAAA,MACnD,UAAU;AAAA,IAAA,CACV;AAAA,EAAA,CACD;AACF;"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const reactBinding = require("@contember/react-binding");
6
+ const FormFieldStateProvider = require("./FormFieldStateProvider.cjs");
7
+ const FormFieldScope = ({ field, children, required }) => {
8
+ const fieldAccessor = reactBinding.useField({ field });
9
+ const entityName = fieldAccessor.getParent().name;
10
+ const fieldName = fieldAccessor.fieldName;
11
+ const enumName = fieldAccessor.schema.enumName ?? void 0;
12
+ const fieldInfo = React.useMemo(() => ({ entityName, fieldName, enumName }), [entityName, fieldName, enumName]);
13
+ return /* @__PURE__ */ jsxRuntime.jsx(
14
+ FormFieldStateProvider.FormFieldStateProvider,
15
+ {
16
+ errors: fieldAccessor.errors?.errors,
17
+ required: required ?? !fieldAccessor.schema.nullable,
18
+ dirty: fieldAccessor.hasUnpersistedChanges,
19
+ field: fieldInfo,
20
+ children
21
+ }
22
+ );
23
+ };
24
+ exports.FormFieldScope = FormFieldScope;
25
+ //# sourceMappingURL=FormFieldScope.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormFieldScope.cjs","sources":["../../../../../packages/react-form/src/components/FormFieldScope.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMemo } from 'react'\nimport { SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport { FormFieldStateProvider } from './FormFieldStateProvider'\n\nexport type FormFieldScopeProps = {\n\tfield: SugaredRelativeSingleField['field']\n\tchildren: React.ReactNode\n\trequired?: boolean\n}\n\nexport const FormFieldScope = ({ field, children, required }: FormFieldScopeProps) => {\n\tconst fieldAccessor = useField({ field })\n\tconst entityName = fieldAccessor.getParent().name\n\tconst fieldName = fieldAccessor.fieldName\n\tconst enumName = fieldAccessor.schema.enumName ?? undefined\n\tconst fieldInfo = useMemo(() => ({ entityName, fieldName, enumName }), [entityName, fieldName, enumName])\n\n\treturn (\n\t\t<FormFieldStateProvider\n\t\t\terrors={fieldAccessor.errors?.errors}\n\t\t\trequired={required ?? !fieldAccessor.schema.nullable}\n\t\t\tdirty={fieldAccessor.hasUnpersistedChanges}\n\t\t\tfield={fieldInfo}\n\t\t>\n\t\t\t{children}\n\t\t</FormFieldStateProvider>\n\t)\n}\n"],"names":["useField","useMemo","jsx","FormFieldStateProvider"],"mappings":";;;;;;AAWO,MAAM,iBAAiB,CAAC,EAAE,OAAO,UAAU,eAAoC;AACrF,QAAM,gBAAgBA,aAAAA,SAAS,EAAE,MAAO,CAAA;AAClC,QAAA,aAAa,cAAc,UAAA,EAAY;AAC7C,QAAM,YAAY,cAAc;AAC1B,QAAA,WAAW,cAAc,OAAO,YAAY;AAClD,QAAM,YAAYC,MAAAA,QAAQ,OAAO,EAAE,YAAY,WAAW,SAAS,IAAI,CAAC,YAAY,WAAW,QAAQ,CAAC;AAGvG,SAAAC,2BAAA;AAAA,IAACC,uBAAA;AAAA,IAAA;AAAA,MACA,QAAQ,cAAc,QAAQ;AAAA,MAC9B,UAAU,YAAY,CAAC,cAAc,OAAO;AAAA,MAC5C,OAAO,cAAc;AAAA,MACrB,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EAAA;AAGJ;;"}
@@ -0,0 +1,25 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import { useField } from "@contember/react-binding";
4
+ import { FormFieldStateProvider } from "./FormFieldStateProvider.js";
5
+ const FormFieldScope = ({ field, children, required }) => {
6
+ const fieldAccessor = useField({ field });
7
+ const entityName = fieldAccessor.getParent().name;
8
+ const fieldName = fieldAccessor.fieldName;
9
+ const enumName = fieldAccessor.schema.enumName ?? void 0;
10
+ const fieldInfo = useMemo(() => ({ entityName, fieldName, enumName }), [entityName, fieldName, enumName]);
11
+ return /* @__PURE__ */ jsx(
12
+ FormFieldStateProvider,
13
+ {
14
+ errors: fieldAccessor.errors?.errors,
15
+ required: required ?? !fieldAccessor.schema.nullable,
16
+ dirty: fieldAccessor.hasUnpersistedChanges,
17
+ field: fieldInfo,
18
+ children
19
+ }
20
+ );
21
+ };
22
+ export {
23
+ FormFieldScope
24
+ };
25
+ //# sourceMappingURL=FormFieldScope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormFieldScope.js","sources":["../../../../../packages/react-form/src/components/FormFieldScope.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMemo } from 'react'\nimport { SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport { FormFieldStateProvider } from './FormFieldStateProvider'\n\nexport type FormFieldScopeProps = {\n\tfield: SugaredRelativeSingleField['field']\n\tchildren: React.ReactNode\n\trequired?: boolean\n}\n\nexport const FormFieldScope = ({ field, children, required }: FormFieldScopeProps) => {\n\tconst fieldAccessor = useField({ field })\n\tconst entityName = fieldAccessor.getParent().name\n\tconst fieldName = fieldAccessor.fieldName\n\tconst enumName = fieldAccessor.schema.enumName ?? undefined\n\tconst fieldInfo = useMemo(() => ({ entityName, fieldName, enumName }), [entityName, fieldName, enumName])\n\n\treturn (\n\t\t<FormFieldStateProvider\n\t\t\terrors={fieldAccessor.errors?.errors}\n\t\t\trequired={required ?? !fieldAccessor.schema.nullable}\n\t\t\tdirty={fieldAccessor.hasUnpersistedChanges}\n\t\t\tfield={fieldInfo}\n\t\t>\n\t\t\t{children}\n\t\t</FormFieldStateProvider>\n\t)\n}\n"],"names":[],"mappings":";;;;AAWO,MAAM,iBAAiB,CAAC,EAAE,OAAO,UAAU,eAAoC;AACrF,QAAM,gBAAgB,SAAS,EAAE,MAAO,CAAA;AAClC,QAAA,aAAa,cAAc,UAAA,EAAY;AAC7C,QAAM,YAAY,cAAc;AAC1B,QAAA,WAAW,cAAc,OAAO,YAAY;AAClD,QAAM,YAAY,QAAQ,OAAO,EAAE,YAAY,WAAW,SAAS,IAAI,CAAC,YAAY,WAAW,QAAQ,CAAC;AAGvG,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,QAAQ,cAAc,QAAQ;AAAA,MAC9B,UAAU,YAAY,CAAC,cAAc,OAAO;AAAA,MAC5C,OAAO,cAAc;AAAA,MACrB,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EAAA;AAGJ;"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const contexts = require("../contexts.cjs");
6
+ const emptyArr = [];
7
+ const FormFieldStateProvider = ({ children, required = false, errors = emptyArr, dirty = false, htmlId, field }) => {
8
+ const generatedId = React.useId();
9
+ htmlId ?? (htmlId = generatedId);
10
+ const value = React.useMemo(() => ({ htmlId, required, errors, dirty, field }), [htmlId, required, errors, dirty, field]);
11
+ return /* @__PURE__ */ jsxRuntime.jsx(contexts.FormFieldStateContext.Provider, { value, children });
12
+ };
13
+ const FormFieldIdContext = {
14
+ /**
15
+ * @deprecated use `FormFieldStateProvider` instead
16
+ */
17
+ Provider: ({ children, value }) => {
18
+ const state = contexts.useFormFieldState();
19
+ return /* @__PURE__ */ jsxRuntime.jsx(FormFieldStateProvider, { ...state, htmlId: value, children });
20
+ }
21
+ };
22
+ const FormErrorContext = {
23
+ /**
24
+ * @deprecated use `FormFieldStateProvider` instead
25
+ */
26
+ Provider: ({ children, value }) => {
27
+ const state = contexts.useFormFieldState();
28
+ return /* @__PURE__ */ jsxRuntime.jsx(FormFieldStateProvider, { ...state, errors: value, children });
29
+ }
30
+ };
31
+ exports.FormErrorContext = FormErrorContext;
32
+ exports.FormFieldIdContext = FormFieldIdContext;
33
+ exports.FormFieldStateProvider = FormFieldStateProvider;
34
+ //# sourceMappingURL=FormFieldStateProvider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormFieldStateProvider.cjs","sources":["../../../../../packages/react-form/src/components/FormFieldStateProvider.tsx"],"sourcesContent":["import { ErrorAccessor } from '@contember/react-binding'\nimport { useEffect, useId, useMemo } from 'react'\nimport { FormFieldStateContext, useFormFieldState } from '../contexts'\nimport { FormFieldState } from '../types'\n\nconst emptyArr: [] = []\n\nexport type FormFieldStateProvider =\n\t& Partial<FormFieldState>\n\t& {\n\t\tchildren: React.ReactNode\n\t}\n\nexport const FormFieldStateProvider = ({ children, required = false, errors = emptyArr, dirty = false, htmlId, field }: FormFieldStateProvider) => {\n\tconst generatedId = useId()\n\thtmlId ??= generatedId\n\tconst value = useMemo(() => ({ htmlId, required, errors, dirty, field }), [htmlId, required, errors, dirty, field])\n\treturn <FormFieldStateContext.Provider value={value}>{children}</FormFieldStateContext.Provider>\n}\n\n/**\n * BC for\n * \t<FormFieldIdContext.Provider value={id}>\n * \t<FormErrorContext.Provider value={[]}>\n */\n\n/**\n * @deprecated use `FormFieldStateProvider` instead\n */\nexport const FormFieldIdContext = {\n\t/**\n\t * @deprecated use `FormFieldStateProvider` instead\n\t */\n\tProvider: ({ children, value }: { children: React.ReactNode; value: string }) => {\n\t\tconst state = useFormFieldState()\n\t\tif (import.meta.env.DEV) {\n\t\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\t\tuseEffect(() => {\n\t\t\t\tconsole.warn('FormFieldIdContext.Provider is deprecated, use FormFieldStateProvider instead')\n\t\t\t}, [])\n\t\t}\n\t\treturn (\n\t\t\t<FormFieldStateProvider {...state} htmlId={value}>\n\t\t\t\t{children}\n\t\t\t</FormFieldStateProvider>\n\t\t)\n\t},\n}\n\n/**\n * @deprecated use `FormFieldStateProvider` instead\n */\nexport const FormErrorContext = {\n\t/**\n\t * @deprecated use `FormFieldStateProvider` instead\n\t */\n\tProvider: ({ children, value }: { children: React.ReactNode; value: ErrorAccessor.Error[] }) => {\n\t\tconst state = useFormFieldState()\n\t\tif (import.meta.env.DEV) {\n\t\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\t\tuseEffect(() => {\n\t\t\t\tconsole.warn('FormErrorContext.Provider is deprecated, use FormFieldStateProvider instead')\n\t\t\t}, [])\n\t\t}\n\t\treturn (\n\t\t\t<FormFieldStateProvider {...state} errors={value}>\n\t\t\t\t{children}\n\t\t\t</FormFieldStateProvider>\n\t\t)\n\t},\n}\n"],"names":["useId","useMemo","FormFieldStateContext","useFormFieldState"],"mappings":";;;;;AAKA,MAAM,WAAe,CAAA;AAQd,MAAM,yBAAyB,CAAC,EAAE,UAAU,WAAW,OAAO,SAAS,UAAU,QAAQ,OAAO,QAAQ,MAAA,MAAoC;AAClJ,QAAM,cAAcA,MAAAA;AACT,aAAA,SAAA;AACX,QAAM,QAAQC,MAAAA,QAAQ,OAAO,EAAE,QAAQ,UAAU,QAAQ,OAAO,MAAM,IAAI,CAAC,QAAQ,UAAU,QAAQ,OAAO,KAAK,CAAC;AAClH,wCAAQC,SAAAA,sBAAsB,UAAtB,EAA+B,OAAe,UAAS;AAChE;AAWO,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAIjC,UAAU,CAAC,EAAE,UAAU,YAA0D;AAChF,UAAM,QAAQC,SAAAA;0CAQZ,wBAAwB,EAAA,GAAG,OAAO,QAAQ,OACzC,UACF;AAAA,EAEF;AACD;AAKO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAI/B,UAAU,CAAC,EAAE,UAAU,YAAyE;AAC/F,UAAM,QAAQA,SAAAA;0CAQZ,wBAAwB,EAAA,GAAG,OAAO,QAAQ,OACzC,UACF;AAAA,EAEF;AACD;;;;"}
@@ -0,0 +1,34 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useId, useMemo } from "react";
3
+ import { FormFieldStateContext, useFormFieldState } from "../contexts.js";
4
+ const emptyArr = [];
5
+ const FormFieldStateProvider = ({ children, required = false, errors = emptyArr, dirty = false, htmlId, field }) => {
6
+ const generatedId = useId();
7
+ htmlId ?? (htmlId = generatedId);
8
+ const value = useMemo(() => ({ htmlId, required, errors, dirty, field }), [htmlId, required, errors, dirty, field]);
9
+ return /* @__PURE__ */ jsx(FormFieldStateContext.Provider, { value, children });
10
+ };
11
+ const FormFieldIdContext = {
12
+ /**
13
+ * @deprecated use `FormFieldStateProvider` instead
14
+ */
15
+ Provider: ({ children, value }) => {
16
+ const state = useFormFieldState();
17
+ return /* @__PURE__ */ jsx(FormFieldStateProvider, { ...state, htmlId: value, children });
18
+ }
19
+ };
20
+ const FormErrorContext = {
21
+ /**
22
+ * @deprecated use `FormFieldStateProvider` instead
23
+ */
24
+ Provider: ({ children, value }) => {
25
+ const state = useFormFieldState();
26
+ return /* @__PURE__ */ jsx(FormFieldStateProvider, { ...state, errors: value, children });
27
+ }
28
+ };
29
+ export {
30
+ FormErrorContext,
31
+ FormFieldIdContext,
32
+ FormFieldStateProvider
33
+ };
34
+ //# sourceMappingURL=FormFieldStateProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormFieldStateProvider.js","sources":["../../../../../packages/react-form/src/components/FormFieldStateProvider.tsx"],"sourcesContent":["import { ErrorAccessor } from '@contember/react-binding'\nimport { useEffect, useId, useMemo } from 'react'\nimport { FormFieldStateContext, useFormFieldState } from '../contexts'\nimport { FormFieldState } from '../types'\n\nconst emptyArr: [] = []\n\nexport type FormFieldStateProvider =\n\t& Partial<FormFieldState>\n\t& {\n\t\tchildren: React.ReactNode\n\t}\n\nexport const FormFieldStateProvider = ({ children, required = false, errors = emptyArr, dirty = false, htmlId, field }: FormFieldStateProvider) => {\n\tconst generatedId = useId()\n\thtmlId ??= generatedId\n\tconst value = useMemo(() => ({ htmlId, required, errors, dirty, field }), [htmlId, required, errors, dirty, field])\n\treturn <FormFieldStateContext.Provider value={value}>{children}</FormFieldStateContext.Provider>\n}\n\n/**\n * BC for\n * \t<FormFieldIdContext.Provider value={id}>\n * \t<FormErrorContext.Provider value={[]}>\n */\n\n/**\n * @deprecated use `FormFieldStateProvider` instead\n */\nexport const FormFieldIdContext = {\n\t/**\n\t * @deprecated use `FormFieldStateProvider` instead\n\t */\n\tProvider: ({ children, value }: { children: React.ReactNode; value: string }) => {\n\t\tconst state = useFormFieldState()\n\t\tif (import.meta.env.DEV) {\n\t\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\t\tuseEffect(() => {\n\t\t\t\tconsole.warn('FormFieldIdContext.Provider is deprecated, use FormFieldStateProvider instead')\n\t\t\t}, [])\n\t\t}\n\t\treturn (\n\t\t\t<FormFieldStateProvider {...state} htmlId={value}>\n\t\t\t\t{children}\n\t\t\t</FormFieldStateProvider>\n\t\t)\n\t},\n}\n\n/**\n * @deprecated use `FormFieldStateProvider` instead\n */\nexport const FormErrorContext = {\n\t/**\n\t * @deprecated use `FormFieldStateProvider` instead\n\t */\n\tProvider: ({ children, value }: { children: React.ReactNode; value: ErrorAccessor.Error[] }) => {\n\t\tconst state = useFormFieldState()\n\t\tif (import.meta.env.DEV) {\n\t\t\t// eslint-disable-next-line react-hooks/rules-of-hooks\n\t\t\tuseEffect(() => {\n\t\t\t\tconsole.warn('FormErrorContext.Provider is deprecated, use FormFieldStateProvider instead')\n\t\t\t}, [])\n\t\t}\n\t\treturn (\n\t\t\t<FormFieldStateProvider {...state} errors={value}>\n\t\t\t\t{children}\n\t\t\t</FormFieldStateProvider>\n\t\t)\n\t},\n}\n"],"names":[],"mappings":";;;AAKA,MAAM,WAAe,CAAA;AAQd,MAAM,yBAAyB,CAAC,EAAE,UAAU,WAAW,OAAO,SAAS,UAAU,QAAQ,OAAO,QAAQ,MAAA,MAAoC;AAClJ,QAAM,cAAc;AACT,aAAA,SAAA;AACX,QAAM,QAAQ,QAAQ,OAAO,EAAE,QAAQ,UAAU,QAAQ,OAAO,MAAM,IAAI,CAAC,QAAQ,UAAU,QAAQ,OAAO,KAAK,CAAC;AAClH,6BAAQ,sBAAsB,UAAtB,EAA+B,OAAe,UAAS;AAChE;AAWO,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA,EAIjC,UAAU,CAAC,EAAE,UAAU,YAA0D;AAChF,UAAM,QAAQ;+BAQZ,wBAAwB,EAAA,GAAG,OAAO,QAAQ,OACzC,UACF;AAAA,EAEF;AACD;AAKO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAI/B,UAAU,CAAC,EAAE,UAAU,YAAyE;AAC/F,UAAM,QAAQ;+BAQZ,wBAAwB,EAAA,GAAG,OAAO,QAAQ,OACzC,UACF;AAAA,EAEF;AACD;"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const reactBinding = require("@contember/react-binding");
5
+ const FormFieldStateProvider = require("./FormFieldStateProvider.cjs");
6
+ const React = require("react");
7
+ const FormHasManyRelationScope = ({ field, children, required }) => {
8
+ const entityRelation = reactBinding.useEntityList({ field });
9
+ const entityName = entityRelation.getParent().name;
10
+ const marker = entityRelation.getMarker();
11
+ const fieldName = marker.parameters.field;
12
+ const fieldInfo = React.useMemo(() => ({ entityName, fieldName }), [entityName, fieldName]);
13
+ return /* @__PURE__ */ jsxRuntime.jsx(
14
+ FormFieldStateProvider.FormFieldStateProvider,
15
+ {
16
+ errors: entityRelation.errors?.errors,
17
+ dirty: entityRelation.hasUnpersistedChanges,
18
+ required,
19
+ field: fieldInfo,
20
+ children
21
+ }
22
+ );
23
+ };
24
+ exports.FormHasManyRelationScope = FormHasManyRelationScope;
25
+ //# sourceMappingURL=FormHasManyRelationScope.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormHasManyRelationScope.cjs","sources":["../../../../../packages/react-form/src/components/FormHasManyRelationScope.tsx"],"sourcesContent":["import { HasManyRelationMarker, SugaredRelativeEntityList, useEntityList } from '@contember/react-binding'\nimport * as React from 'react'\nimport { FormFieldStateProvider } from './FormFieldStateProvider'\nimport { useMemo } from 'react'\n\nexport type FormHasManyRelationScopeProps = {\n\tfield: SugaredRelativeEntityList['field']\n\tchildren: React.ReactNode\n\trequired?: boolean\n}\n\nexport const FormHasManyRelationScope = ({ field, children, required }: FormHasManyRelationScopeProps) => {\n\tconst entityRelation = useEntityList({ field })\n\tconst entityName = entityRelation.getParent()!.name\n\tconst marker = entityRelation.getMarker() as HasManyRelationMarker\n\tconst fieldName = marker.parameters.field\n\tconst fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName])\n\n\treturn (\n\t\t<FormFieldStateProvider\n\t\t\terrors={entityRelation.errors?.errors}\n\t\t\tdirty={entityRelation.hasUnpersistedChanges}\n\t\t\trequired={required}\n\t\t\tfield={fieldInfo}\n\t\t>\n\t\t\t{children}\n\t\t</FormFieldStateProvider>\n\t)\n}\n"],"names":["useEntityList","useMemo","jsx","FormFieldStateProvider"],"mappings":";;;;;;AAWO,MAAM,2BAA2B,CAAC,EAAE,OAAO,UAAU,eAA8C;AACzG,QAAM,iBAAiBA,aAAAA,cAAc,EAAE,MAAO,CAAA;AACxC,QAAA,aAAa,eAAe,UAAA,EAAa;AACzC,QAAA,SAAS,eAAe;AACxB,QAAA,YAAY,OAAO,WAAW;AAC9B,QAAA,YAAYC,cAAQ,OAAO,EAAE,YAAY,UAAc,IAAA,CAAC,YAAY,SAAS,CAAC;AAGnF,SAAAC,2BAAA;AAAA,IAACC,uBAAA;AAAA,IAAA;AAAA,MACA,QAAQ,eAAe,QAAQ;AAAA,MAC/B,OAAO,eAAe;AAAA,MACtB;AAAA,MACA,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EAAA;AAGJ;;"}
@@ -0,0 +1,25 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useEntityList } from "@contember/react-binding";
3
+ import { FormFieldStateProvider } from "./FormFieldStateProvider.js";
4
+ import { useMemo } from "react";
5
+ const FormHasManyRelationScope = ({ field, children, required }) => {
6
+ const entityRelation = useEntityList({ field });
7
+ const entityName = entityRelation.getParent().name;
8
+ const marker = entityRelation.getMarker();
9
+ const fieldName = marker.parameters.field;
10
+ const fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName]);
11
+ return /* @__PURE__ */ jsx(
12
+ FormFieldStateProvider,
13
+ {
14
+ errors: entityRelation.errors?.errors,
15
+ dirty: entityRelation.hasUnpersistedChanges,
16
+ required,
17
+ field: fieldInfo,
18
+ children
19
+ }
20
+ );
21
+ };
22
+ export {
23
+ FormHasManyRelationScope
24
+ };
25
+ //# sourceMappingURL=FormHasManyRelationScope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormHasManyRelationScope.js","sources":["../../../../../packages/react-form/src/components/FormHasManyRelationScope.tsx"],"sourcesContent":["import { HasManyRelationMarker, SugaredRelativeEntityList, useEntityList } from '@contember/react-binding'\nimport * as React from 'react'\nimport { FormFieldStateProvider } from './FormFieldStateProvider'\nimport { useMemo } from 'react'\n\nexport type FormHasManyRelationScopeProps = {\n\tfield: SugaredRelativeEntityList['field']\n\tchildren: React.ReactNode\n\trequired?: boolean\n}\n\nexport const FormHasManyRelationScope = ({ field, children, required }: FormHasManyRelationScopeProps) => {\n\tconst entityRelation = useEntityList({ field })\n\tconst entityName = entityRelation.getParent()!.name\n\tconst marker = entityRelation.getMarker() as HasManyRelationMarker\n\tconst fieldName = marker.parameters.field\n\tconst fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName])\n\n\treturn (\n\t\t<FormFieldStateProvider\n\t\t\terrors={entityRelation.errors?.errors}\n\t\t\tdirty={entityRelation.hasUnpersistedChanges}\n\t\t\trequired={required}\n\t\t\tfield={fieldInfo}\n\t\t>\n\t\t\t{children}\n\t\t</FormFieldStateProvider>\n\t)\n}\n"],"names":[],"mappings":";;;;AAWO,MAAM,2BAA2B,CAAC,EAAE,OAAO,UAAU,eAA8C;AACzG,QAAM,iBAAiB,cAAc,EAAE,MAAO,CAAA;AACxC,QAAA,aAAa,eAAe,UAAA,EAAa;AACzC,QAAA,SAAS,eAAe;AACxB,QAAA,YAAY,OAAO,WAAW;AAC9B,QAAA,YAAY,QAAQ,OAAO,EAAE,YAAY,UAAc,IAAA,CAAC,YAAY,SAAS,CAAC;AAGnF,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,QAAQ,eAAe,QAAQ;AAAA,MAC/B,OAAO,eAAe;AAAA,MACtB;AAAA,MACA,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EAAA;AAGJ;"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const reactBinding = require("@contember/react-binding");
5
+ const FormFieldStateProvider = require("./FormFieldStateProvider.cjs");
6
+ const React = require("react");
7
+ const FormHasOneRelationScope = ({ field, children, required }) => {
8
+ const entityRelation = reactBinding.useEntity({ field });
9
+ const marker = entityRelation.getMarker();
10
+ const fieldName = marker.parameters.field;
11
+ const entityName = entityRelation.getParent().name;
12
+ const fieldInfo = React.useMemo(() => ({ entityName, fieldName }), [entityName, fieldName]);
13
+ return /* @__PURE__ */ jsxRuntime.jsx(
14
+ FormFieldStateProvider.FormFieldStateProvider,
15
+ {
16
+ errors: entityRelation.errors?.errors,
17
+ dirty: entityRelation.hasUnpersistedChanges,
18
+ required,
19
+ field: fieldInfo,
20
+ children
21
+ }
22
+ );
23
+ };
24
+ exports.FormHasOneRelationScope = FormHasOneRelationScope;
25
+ //# sourceMappingURL=FormHasOneRelationScope.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormHasOneRelationScope.cjs","sources":["../../../../../packages/react-form/src/components/FormHasOneRelationScope.tsx"],"sourcesContent":["import * as React from 'react'\nimport { HasOneRelationMarker, SugaredRelativeSingleEntity, useEntity } from '@contember/react-binding'\nimport { FormFieldStateProvider } from './FormFieldStateProvider'\nimport { useMemo } from 'react'\n\nexport type FormHasOneRelationScopeProps = {\n\tfield: SugaredRelativeSingleEntity['field']\n\tchildren: React.ReactNode\n\trequired?: boolean\n}\n\nexport const FormHasOneRelationScope = ({ field, children, required }: FormHasOneRelationScopeProps) => {\n\tconst entityRelation = useEntity({ field })\n\tconst marker = entityRelation.getMarker() as HasOneRelationMarker\n\tconst fieldName = marker.parameters.field\n\tconst entityName = entityRelation.getParent()!.name\n\tconst fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName])\n\treturn (\n\t\t<FormFieldStateProvider\n\t\t\terrors={entityRelation.errors?.errors}\n\t\t\tdirty={entityRelation.hasUnpersistedChanges}\n\t\t\trequired={required}\n\t\t\tfield={fieldInfo}\n\t\t>\n\t\t\t{children}\n\t\t</FormFieldStateProvider>\n\t)\n}\n"],"names":["useEntity","useMemo","jsx","FormFieldStateProvider"],"mappings":";;;;;;AAWO,MAAM,0BAA0B,CAAC,EAAE,OAAO,UAAU,eAA6C;AACvG,QAAM,iBAAiBA,aAAAA,UAAU,EAAE,MAAO,CAAA;AACpC,QAAA,SAAS,eAAe;AACxB,QAAA,YAAY,OAAO,WAAW;AAC9B,QAAA,aAAa,eAAe,UAAA,EAAa;AACzC,QAAA,YAAYC,cAAQ,OAAO,EAAE,YAAY,UAAc,IAAA,CAAC,YAAY,SAAS,CAAC;AAEnF,SAAAC,2BAAA;AAAA,IAACC,uBAAA;AAAA,IAAA;AAAA,MACA,QAAQ,eAAe,QAAQ;AAAA,MAC/B,OAAO,eAAe;AAAA,MACtB;AAAA,MACA,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EAAA;AAGJ;;"}
@@ -0,0 +1,25 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useEntity } from "@contember/react-binding";
3
+ import { FormFieldStateProvider } from "./FormFieldStateProvider.js";
4
+ import { useMemo } from "react";
5
+ const FormHasOneRelationScope = ({ field, children, required }) => {
6
+ const entityRelation = useEntity({ field });
7
+ const marker = entityRelation.getMarker();
8
+ const fieldName = marker.parameters.field;
9
+ const entityName = entityRelation.getParent().name;
10
+ const fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName]);
11
+ return /* @__PURE__ */ jsx(
12
+ FormFieldStateProvider,
13
+ {
14
+ errors: entityRelation.errors?.errors,
15
+ dirty: entityRelation.hasUnpersistedChanges,
16
+ required,
17
+ field: fieldInfo,
18
+ children
19
+ }
20
+ );
21
+ };
22
+ export {
23
+ FormHasOneRelationScope
24
+ };
25
+ //# sourceMappingURL=FormHasOneRelationScope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormHasOneRelationScope.js","sources":["../../../../../packages/react-form/src/components/FormHasOneRelationScope.tsx"],"sourcesContent":["import * as React from 'react'\nimport { HasOneRelationMarker, SugaredRelativeSingleEntity, useEntity } from '@contember/react-binding'\nimport { FormFieldStateProvider } from './FormFieldStateProvider'\nimport { useMemo } from 'react'\n\nexport type FormHasOneRelationScopeProps = {\n\tfield: SugaredRelativeSingleEntity['field']\n\tchildren: React.ReactNode\n\trequired?: boolean\n}\n\nexport const FormHasOneRelationScope = ({ field, children, required }: FormHasOneRelationScopeProps) => {\n\tconst entityRelation = useEntity({ field })\n\tconst marker = entityRelation.getMarker() as HasOneRelationMarker\n\tconst fieldName = marker.parameters.field\n\tconst entityName = entityRelation.getParent()!.name\n\tconst fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName])\n\treturn (\n\t\t<FormFieldStateProvider\n\t\t\terrors={entityRelation.errors?.errors}\n\t\t\tdirty={entityRelation.hasUnpersistedChanges}\n\t\t\trequired={required}\n\t\t\tfield={fieldInfo}\n\t\t>\n\t\t\t{children}\n\t\t</FormFieldStateProvider>\n\t)\n}\n"],"names":[],"mappings":";;;;AAWO,MAAM,0BAA0B,CAAC,EAAE,OAAO,UAAU,eAA6C;AACvG,QAAM,iBAAiB,UAAU,EAAE,MAAO,CAAA;AACpC,QAAA,SAAS,eAAe;AACxB,QAAA,YAAY,OAAO,WAAW;AAC9B,QAAA,aAAa,eAAe,UAAA,EAAa;AACzC,QAAA,YAAY,QAAQ,OAAO,EAAE,YAAY,UAAc,IAAA,CAAC,YAAY,SAAS,CAAC;AAEnF,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,QAAQ,eAAe,QAAQ;AAAA,MAC/B,OAAO,eAAe;AAAA,MACtB;AAAA,MACA,OAAO;AAAA,MAEN;AAAA,IAAA;AAAA,EAAA;AAGJ;"}
@@ -10,9 +10,12 @@ const contexts = require("../contexts.cjs");
10
10
  const useFormInputValidationHandler = require("../hooks/useFormInputValidationHandler.cjs");
11
11
  const SlotInput = reactSlot.Slot;
12
12
  const FormInput = reactBinding.Component(({ field, isNonbearing, defaultValue, formatValue: formatValueIn, parseValue: parseValueIn, ...props }) => {
13
- const id = contexts.useFormFieldId();
14
13
  const accessor = reactBinding.useField(field);
15
- const errors = contexts.useFormError() ?? accessor.errors?.errors ?? [];
14
+ const formState = contexts.useFormFieldState();
15
+ const id = formState?.htmlId;
16
+ const hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0;
17
+ const dirty = formState?.dirty ?? accessor.hasUnpersistedChanges;
18
+ const required = formState?.required ?? !accessor.schema.nullable;
16
19
  const { parseValue, formatValue, defaultInputProps } = useFormInputHandler.useFormInputHandler(accessor, { formatValue: formatValueIn, parseValue: parseValueIn });
17
20
  const accessorGetter = accessor.getAccessor;
18
21
  const { ref, onFocus, onBlur } = useFormInputValidationHandler.useFormInputValidationHandler(accessor);
@@ -21,7 +24,9 @@ const FormInput = reactBinding.Component(({ field, isNonbearing, defaultValue, f
21
24
  {
22
25
  ref,
23
26
  value: formatValue(accessor.value),
24
- "data-invalid": utilities.dataAttribute(errors.length > 0),
27
+ "data-invalid": utilities.dataAttribute(hasErrors),
28
+ "data-dirty": utilities.dataAttribute(dirty),
29
+ "data-required": utilities.dataAttribute(required),
25
30
  onFocus,
26
31
  onBlur,
27
32
  onChange: React.useCallback((e) => {
@@ -29,7 +34,7 @@ const FormInput = reactBinding.Component(({ field, isNonbearing, defaultValue, f
29
34
  }, [accessorGetter, parseValue]),
30
35
  ...defaultInputProps,
31
36
  id: id ? `${id}-input` : void 0,
32
- required: !accessor.schema.nullable,
37
+ required,
33
38
  ...props
34
39
  }
35
40
  );
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormInput.cjs","sources":["../../../../../packages/react-form/src/components/FormInput.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ComponentType, useCallback } from 'react'\nimport { Slot } from '@radix-ui/react-slot'\nimport { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'\nimport { dataAttribute } from '@contember/utilities'\nimport { useFormInputHandler } from '../internal/useFormInputHandler'\nimport { useFormFieldState } from '../contexts'\nimport { useFormInputValidationHandler } from '../hooks/useFormInputValidationHandler'\nimport { FormInputHandler } from '../types'\n\ntype InputProps = React.JSX.IntrinsicElements['input']\nconst SlotInput = Slot as ComponentType<InputProps>\n\nexport interface FormInputProps {\n\tfield: SugaredRelativeSingleField['field']\n\tisNonbearing?: boolean\n\tdefaultValue?: OptionallyVariableFieldValue\n\tchildren: React.ReactElement\n\tformatValue?: FormInputHandler['formatValue']\n\tparseValue?: FormInputHandler['parseValue']\n}\n\nexport const FormInput = Component<FormInputProps>(({ field, isNonbearing, defaultValue, formatValue: formatValueIn, parseValue: parseValueIn, ...props }) => {\n\tconst accessor = useField(field)\n\n\tconst formState = useFormFieldState()\n\tconst id = formState?.htmlId\n\tconst hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0\n\tconst dirty = formState?.dirty ?? accessor.hasUnpersistedChanges\n\tconst required = formState?.required ?? !accessor.schema.nullable\n\n\tconst { parseValue, formatValue, defaultInputProps } = useFormInputHandler(accessor, { formatValue: formatValueIn, parseValue: parseValueIn })\n\tconst accessorGetter = accessor.getAccessor\n\tconst { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)\n\n\treturn (\n\t\t<SlotInput\n\t\t\tref={ref}\n\t\t\tvalue={formatValue(accessor.value)}\n\t\t\tdata-invalid={dataAttribute(hasErrors)}\n\t\t\tdata-dirty={dataAttribute(dirty)}\n\t\t\tdata-required={dataAttribute(required)}\n\t\t\tonFocus={onFocus}\n\t\t\tonBlur={onBlur}\n\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\taccessorGetter().updateValue(parseValue(e.target.value))\n\t\t\t}, [accessorGetter, parseValue])}\n\t\t\t{...defaultInputProps}\n\t\t\tid={id ? `${id}-input` : undefined}\n\t\t\trequired={required}\n\t\t\t{...props}\n\t\t/>\n\t)\n}, ({ field, isNonbearing, defaultValue }) => {\n\treturn <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue} />\n})\n"],"names":["Slot","Component","useField","useFormFieldState","useFormInputHandler","useFormInputValidationHandler","jsx","dataAttribute","useCallback","Field"],"mappings":";;;;;;;;;;AAWA,MAAM,YAAYA,UAAAA;AAWX,MAAM,YAAYC,aAAA,UAA0B,CAAC,EAAE,OAAO,cAAc,cAAc,aAAa,eAAe,YAAY,cAAc,GAAG,YAAY;AACvJ,QAAA,WAAWC,sBAAS,KAAK;AAE/B,QAAM,YAAYC,SAAAA;AAClB,QAAM,KAAK,WAAW;AAChB,QAAA,aAAa,WAAW,OAAO,UAAU,SAAS,QAAQ,QAAQ,UAAU,KAAK;AACjF,QAAA,QAAQ,WAAW,SAAS,SAAS;AAC3C,QAAM,WAAW,WAAW,YAAY,CAAC,SAAS,OAAO;AAEzD,QAAM,EAAE,YAAY,aAAa,kBAAsB,IAAAC,oBAAA,oBAAoB,UAAU,EAAE,aAAa,eAAe,YAAY,aAAc,CAAA;AAC7I,QAAM,iBAAiB,SAAS;AAChC,QAAM,EAAE,KAAK,SAAS,OAAO,IAAIC,8BAAAA,8BAA8B,QAAQ;AAGtE,SAAAC,2BAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA;AAAA,MACA,OAAO,YAAY,SAAS,KAAK;AAAA,MACjC,gBAAcC,wBAAc,SAAS;AAAA,MACrC,cAAYA,wBAAc,KAAK;AAAA,MAC/B,iBAAeA,wBAAc,QAAQ;AAAA,MACrC;AAAA,MACA;AAAA,MACA,UAAUC,MAAAA,YAAkD,CAAK,MAAA;AAChE,uBAAA,EAAiB,YAAY,WAAW,EAAE,OAAO,KAAK,CAAC;AAAA,MAAA,GACrD,CAAC,gBAAgB,UAAU,CAAC;AAAA,MAC9B,GAAG;AAAA,MACJ,IAAI,KAAK,GAAG,EAAE,WAAW;AAAA,MACzB;AAAA,MACC,GAAG;AAAA,IAAA;AAAA,EAAA;AAGP,GAAG,CAAC,EAAE,OAAO,cAAc,mBAAmB;AAC7C,SAAQF,2BAAAA,IAAAG,aAAAA,OAAA,EAAM,OAAc,cAA4B,aAA4B,CAAA;AACrF,CAAC;;"}
@@ -4,13 +4,16 @@ import { Slot } from "@radix-ui/react-slot";
4
4
  import { Component, useField, Field } from "@contember/react-binding";
5
5
  import { dataAttribute } from "@contember/utilities";
6
6
  import { useFormInputHandler } from "../internal/useFormInputHandler.js";
7
- import { useFormFieldId, useFormError } from "../contexts.js";
7
+ import { useFormFieldState } from "../contexts.js";
8
8
  import { useFormInputValidationHandler } from "../hooks/useFormInputValidationHandler.js";
9
9
  const SlotInput = Slot;
10
10
  const FormInput = Component(({ field, isNonbearing, defaultValue, formatValue: formatValueIn, parseValue: parseValueIn, ...props }) => {
11
- const id = useFormFieldId();
12
11
  const accessor = useField(field);
13
- const errors = useFormError() ?? accessor.errors?.errors ?? [];
12
+ const formState = useFormFieldState();
13
+ const id = formState?.htmlId;
14
+ const hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0;
15
+ const dirty = formState?.dirty ?? accessor.hasUnpersistedChanges;
16
+ const required = formState?.required ?? !accessor.schema.nullable;
14
17
  const { parseValue, formatValue, defaultInputProps } = useFormInputHandler(accessor, { formatValue: formatValueIn, parseValue: parseValueIn });
15
18
  const accessorGetter = accessor.getAccessor;
16
19
  const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor);
@@ -19,7 +22,9 @@ const FormInput = Component(({ field, isNonbearing, defaultValue, formatValue: f
19
22
  {
20
23
  ref,
21
24
  value: formatValue(accessor.value),
22
- "data-invalid": dataAttribute(errors.length > 0),
25
+ "data-invalid": dataAttribute(hasErrors),
26
+ "data-dirty": dataAttribute(dirty),
27
+ "data-required": dataAttribute(required),
23
28
  onFocus,
24
29
  onBlur,
25
30
  onChange: useCallback((e) => {
@@ -27,7 +32,7 @@ const FormInput = Component(({ field, isNonbearing, defaultValue, formatValue: f
27
32
  }, [accessorGetter, parseValue]),
28
33
  ...defaultInputProps,
29
34
  id: id ? `${id}-input` : void 0,
30
- required: !accessor.schema.nullable,
35
+ required,
31
36
  ...props
32
37
  }
33
38
  );