@contember/react-form 2.1.0-alpha.30 → 2.1.0-alpha.35

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 (146) hide show
  1. package/package.json +10 -10
  2. package/src/components/FormCheckbox.tsx +2 -1
  3. package/src/components/FormError.tsx +1 -1
  4. package/src/components/FormFieldStateProvider.tsx +0 -2
  5. package/src/components/FormInput.tsx +35 -32
  6. package/src/components/FormRadioInput.tsx +1 -1
  7. package/src/contexts.tsx +0 -2
  8. package/src/hooks/useFormInputValidationHandler.tsx +1 -1
  9. package/src/internal/useFormInputHandler.ts +6 -6
  10. package/dist/development/index.cjs +0 -30
  11. package/dist/development/index.cjs.map +0 -1
  12. package/dist/development/index.js +0 -30
  13. package/dist/development/index.js.map +0 -1
  14. package/dist/development/src/components/FormCheckbox.cjs +0 -83
  15. package/dist/development/src/components/FormCheckbox.cjs.map +0 -1
  16. package/dist/development/src/components/FormCheckbox.js +0 -67
  17. package/dist/development/src/components/FormCheckbox.js.map +0 -1
  18. package/dist/development/src/components/FormError.cjs +0 -22
  19. package/dist/development/src/components/FormError.cjs.map +0 -1
  20. package/dist/development/src/components/FormError.js +0 -22
  21. package/dist/development/src/components/FormError.js.map +0 -1
  22. package/dist/development/src/components/FormFieldScope.cjs +0 -33
  23. package/dist/development/src/components/FormFieldScope.cjs.map +0 -1
  24. package/dist/development/src/components/FormFieldScope.js +0 -33
  25. package/dist/development/src/components/FormFieldScope.js.map +0 -1
  26. package/dist/development/src/components/FormFieldStateProvider.cjs +0 -56
  27. package/dist/development/src/components/FormFieldStateProvider.cjs.map +0 -1
  28. package/dist/development/src/components/FormFieldStateProvider.js +0 -56
  29. package/dist/development/src/components/FormFieldStateProvider.js.map +0 -1
  30. package/dist/development/src/components/FormHasManyRelationScope.cjs +0 -33
  31. package/dist/development/src/components/FormHasManyRelationScope.cjs.map +0 -1
  32. package/dist/development/src/components/FormHasManyRelationScope.js +0 -33
  33. package/dist/development/src/components/FormHasManyRelationScope.js.map +0 -1
  34. package/dist/development/src/components/FormHasOneRelationScope.cjs +0 -33
  35. package/dist/development/src/components/FormHasOneRelationScope.cjs.map +0 -1
  36. package/dist/development/src/components/FormHasOneRelationScope.js +0 -33
  37. package/dist/development/src/components/FormHasOneRelationScope.js.map +0 -1
  38. package/dist/development/src/components/FormInput.cjs +0 -59
  39. package/dist/development/src/components/FormInput.cjs.map +0 -1
  40. package/dist/development/src/components/FormInput.js +0 -59
  41. package/dist/development/src/components/FormInput.js.map +0 -1
  42. package/dist/development/src/components/FormLabel.cjs +0 -34
  43. package/dist/development/src/components/FormLabel.cjs.map +0 -1
  44. package/dist/development/src/components/FormLabel.js +0 -34
  45. package/dist/development/src/components/FormLabel.js.map +0 -1
  46. package/dist/development/src/components/FormRadioInput.cjs +0 -55
  47. package/dist/development/src/components/FormRadioInput.cjs.map +0 -1
  48. package/dist/development/src/components/FormRadioInput.js +0 -55
  49. package/dist/development/src/components/FormRadioInput.js.map +0 -1
  50. package/dist/development/src/contexts.cjs +0 -13
  51. package/dist/development/src/contexts.cjs.map +0 -1
  52. package/dist/development/src/contexts.js +0 -13
  53. package/dist/development/src/contexts.js.map +0 -1
  54. package/dist/development/src/hooks/useFormInputValidationHandler.cjs +0 -80
  55. package/dist/development/src/hooks/useFormInputValidationHandler.cjs.map +0 -1
  56. package/dist/development/src/hooks/useFormInputValidationHandler.js +0 -64
  57. package/dist/development/src/hooks/useFormInputValidationHandler.js.map +0 -1
  58. package/dist/development/src/internal/useFormInputHandler.cjs +0 -122
  59. package/dist/development/src/internal/useFormInputHandler.cjs.map +0 -1
  60. package/dist/development/src/internal/useFormInputHandler.js +0 -122
  61. package/dist/development/src/internal/useFormInputHandler.js.map +0 -1
  62. package/dist/production/index.cjs +0 -30
  63. package/dist/production/index.cjs.map +0 -1
  64. package/dist/production/index.js +0 -30
  65. package/dist/production/index.js.map +0 -1
  66. package/dist/production/src/components/FormCheckbox.cjs +0 -71
  67. package/dist/production/src/components/FormCheckbox.cjs.map +0 -1
  68. package/dist/production/src/components/FormCheckbox.js +0 -55
  69. package/dist/production/src/components/FormCheckbox.js.map +0 -1
  70. package/dist/production/src/components/FormError.cjs +0 -22
  71. package/dist/production/src/components/FormError.cjs.map +0 -1
  72. package/dist/production/src/components/FormError.js +0 -22
  73. package/dist/production/src/components/FormError.js.map +0 -1
  74. package/dist/production/src/components/FormFieldScope.cjs +0 -25
  75. package/dist/production/src/components/FormFieldScope.cjs.map +0 -1
  76. package/dist/production/src/components/FormFieldScope.js +0 -25
  77. package/dist/production/src/components/FormFieldScope.js.map +0 -1
  78. package/dist/production/src/components/FormFieldStateProvider.cjs +0 -34
  79. package/dist/production/src/components/FormFieldStateProvider.cjs.map +0 -1
  80. package/dist/production/src/components/FormFieldStateProvider.js +0 -34
  81. package/dist/production/src/components/FormFieldStateProvider.js.map +0 -1
  82. package/dist/production/src/components/FormHasManyRelationScope.cjs +0 -25
  83. package/dist/production/src/components/FormHasManyRelationScope.cjs.map +0 -1
  84. package/dist/production/src/components/FormHasManyRelationScope.js +0 -25
  85. package/dist/production/src/components/FormHasManyRelationScope.js.map +0 -1
  86. package/dist/production/src/components/FormHasOneRelationScope.cjs +0 -25
  87. package/dist/production/src/components/FormHasOneRelationScope.cjs.map +0 -1
  88. package/dist/production/src/components/FormHasOneRelationScope.js +0 -25
  89. package/dist/production/src/components/FormHasOneRelationScope.js.map +0 -1
  90. package/dist/production/src/components/FormInput.cjs +0 -47
  91. package/dist/production/src/components/FormInput.cjs.map +0 -1
  92. package/dist/production/src/components/FormInput.js +0 -47
  93. package/dist/production/src/components/FormInput.js.map +0 -1
  94. package/dist/production/src/components/FormLabel.cjs +0 -26
  95. package/dist/production/src/components/FormLabel.cjs.map +0 -1
  96. package/dist/production/src/components/FormLabel.js +0 -26
  97. package/dist/production/src/components/FormLabel.js.map +0 -1
  98. package/dist/production/src/components/FormRadioInput.cjs +0 -43
  99. package/dist/production/src/components/FormRadioInput.cjs.map +0 -1
  100. package/dist/production/src/components/FormRadioInput.js +0 -43
  101. package/dist/production/src/components/FormRadioInput.js.map +0 -1
  102. package/dist/production/src/contexts.cjs +0 -13
  103. package/dist/production/src/contexts.cjs.map +0 -1
  104. package/dist/production/src/contexts.js +0 -13
  105. package/dist/production/src/contexts.js.map +0 -1
  106. package/dist/production/src/hooks/useFormInputValidationHandler.cjs +0 -80
  107. package/dist/production/src/hooks/useFormInputValidationHandler.cjs.map +0 -1
  108. package/dist/production/src/hooks/useFormInputValidationHandler.js +0 -64
  109. package/dist/production/src/hooks/useFormInputValidationHandler.js.map +0 -1
  110. package/dist/production/src/internal/useFormInputHandler.cjs +0 -122
  111. package/dist/production/src/internal/useFormInputHandler.cjs.map +0 -1
  112. package/dist/production/src/internal/useFormInputHandler.js +0 -122
  113. package/dist/production/src/internal/useFormInputHandler.js.map +0 -1
  114. package/dist/types/components/FormCheckbox.d.ts +0 -11
  115. package/dist/types/components/FormCheckbox.d.ts.map +0 -1
  116. package/dist/types/components/FormError.d.ts +0 -7
  117. package/dist/types/components/FormError.d.ts.map +0 -1
  118. package/dist/types/components/FormFieldScope.d.ts +0 -9
  119. package/dist/types/components/FormFieldScope.d.ts.map +0 -1
  120. package/dist/types/components/FormFieldStateProvider.d.ts +0 -36
  121. package/dist/types/components/FormFieldStateProvider.d.ts.map +0 -1
  122. package/dist/types/components/FormHasManyRelationScope.d.ts +0 -12
  123. package/dist/types/components/FormHasManyRelationScope.d.ts.map +0 -1
  124. package/dist/types/components/FormHasOneRelationScope.d.ts +0 -9
  125. package/dist/types/components/FormHasOneRelationScope.d.ts.map +0 -1
  126. package/dist/types/components/FormInput.d.ts +0 -13
  127. package/dist/types/components/FormInput.d.ts.map +0 -1
  128. package/dist/types/components/FormLabel.d.ts +0 -5
  129. package/dist/types/components/FormLabel.d.ts.map +0 -1
  130. package/dist/types/components/FormRadioInput.d.ts +0 -11
  131. package/dist/types/components/FormRadioInput.d.ts.map +0 -1
  132. package/dist/types/components/index.d.ts +0 -10
  133. package/dist/types/components/index.d.ts.map +0 -1
  134. package/dist/types/contexts.d.ts +0 -12
  135. package/dist/types/contexts.d.ts.map +0 -1
  136. package/dist/types/hooks/index.d.ts +0 -2
  137. package/dist/types/hooks/index.d.ts.map +0 -1
  138. package/dist/types/hooks/useFormInputValidationHandler.d.ts +0 -8
  139. package/dist/types/hooks/useFormInputValidationHandler.d.ts.map +0 -1
  140. package/dist/types/index.d.ts +0 -5
  141. package/dist/types/index.d.ts.map +0 -1
  142. package/dist/types/internal/useFormInputHandler.d.ts +0 -4
  143. package/dist/types/internal/useFormInputHandler.d.ts.map +0 -1
  144. package/dist/types/tsconfig.tsbuildinfo +0 -1
  145. package/dist/types/types/index.d.ts +0 -23
  146. package/dist/types/types/index.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contember/react-form",
3
3
  "license": "Apache-2.0",
4
- "version": "2.1.0-alpha.30",
4
+ "version": "2.1.0-alpha.35",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "./dist/production/index.js",
@@ -30,21 +30,21 @@
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",
33
- "url": "https://github.com/contember/interface.git",
33
+ "url": "git+https://github.com/contember/contember.git",
34
34
  "directory": "packages/react-form"
35
35
  },
36
36
  "dependencies": {
37
- "@contember/react-binding": "2.1.0-alpha.30",
38
- "@contember/react-utils": "2.1.0-alpha.30",
39
- "@contember/utilities": "2.1.0-alpha.30",
40
- "@radix-ui/react-slot": "^1.1.0"
37
+ "@contember/react-binding": "workspace:*",
38
+ "@contember/react-utils": "workspace:*",
39
+ "@contember/utilities": "workspace:*",
40
+ "@radix-ui/react-slot": "catalog:"
41
41
  },
42
42
  "peerDependencies": {
43
- "react": "^18 || ^19",
44
- "react-dom": "^18 || ^19"
43
+ "react": "catalog:",
44
+ "react-dom": "catalog:"
45
45
  },
46
46
  "devDependencies": {
47
- "react": "^18.3.1",
48
- "react-dom": "^18.3.1"
47
+ "react": "catalog:",
48
+ "react-dom": "catalog:"
49
49
  }
50
50
  }
@@ -34,6 +34,7 @@ export const FormCheckbox = Component<FormCheckboxProps>(({ field, isNonbearing,
34
34
  const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)
35
35
  const [checkboxRef, setCheckboxRef] = React.useState<HTMLInputElement | null>(null)
36
36
 
37
+ // biome-ignore lint/correctness/useExhaustiveDependencies: intentional
37
38
  useEffect(() => {
38
39
  if (!checkboxRef) {
39
40
  return
@@ -44,7 +45,7 @@ export const FormCheckbox = Component<FormCheckboxProps>(({ field, isNonbearing,
44
45
  return (
45
46
  <SlotInput
46
47
  ref={it => {
47
- (ref as any).current = checkboxRef
48
+ ;(ref as any).current = checkboxRef
48
49
  setCheckboxRef(it)
49
50
  }}
50
51
  type="checkbox"
@@ -4,7 +4,7 @@ import { BindingError, ErrorAccessor } from '@contember/react-binding'
4
4
 
5
5
  export const FormError = ({ children, formatter }: {
6
6
  formatter: (errors: ErrorAccessor.Error[]) => ReactNode[]
7
- children: ReactElement
7
+ children: ReactElement<any>
8
8
  }) => {
9
9
  const formState = useFormFieldState()
10
10
  if (!formState) {
@@ -34,7 +34,6 @@ export const FormFieldIdContext = {
34
34
  Provider: ({ children, value }: { children: React.ReactNode; value: string }) => {
35
35
  const state = useFormFieldState()
36
36
  if (import.meta.env.DEV) {
37
- // eslint-disable-next-line react-hooks/rules-of-hooks
38
37
  useEffect(() => {
39
38
  console.warn('FormFieldIdContext.Provider is deprecated, use FormFieldStateProvider instead')
40
39
  }, [])
@@ -57,7 +56,6 @@ export const FormErrorContext = {
57
56
  Provider: ({ children, value }: { children: React.ReactNode; value: ErrorAccessor.Error[] }) => {
58
57
  const state = useFormFieldState()
59
58
  if (import.meta.env.DEV) {
60
- // eslint-disable-next-line react-hooks/rules-of-hooks
61
59
  useEffect(() => {
62
60
  console.warn('FormErrorContext.Provider is deprecated, use FormFieldStateProvider instead')
63
61
  }, [])
@@ -21,39 +21,42 @@ export interface FormInputProps {
21
21
  parseValue?: FormInputHandler['parseValue']
22
22
  }
23
23
 
24
- export const FormInput = Component<FormInputProps>(({ field, isNonbearing, defaultValue, formatValue: formatValueIn, parseValue: parseValueIn, ...props }) => {
25
- const accessor = useField(field)
24
+ export const FormInput = Component<FormInputProps>(
25
+ ({ field, isNonbearing, defaultValue, formatValue: formatValueIn, parseValue: parseValueIn, ...props }) => {
26
+ const accessor = useField(field)
26
27
 
27
- const formState = useFormFieldState()
28
- const id = formState?.htmlId
29
- const hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0
30
- const dirty = formState?.dirty ?? accessor.hasUnpersistedChanges
31
- const required = formState?.required ?? !accessor.schema.nullable
28
+ const formState = useFormFieldState()
29
+ const id = formState?.htmlId
30
+ const hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0
31
+ const dirty = formState?.dirty ?? accessor.hasUnpersistedChanges
32
+ const required = formState?.required ?? !accessor.schema.nullable
32
33
 
33
- const [state, setState] = useState<any>(undefined)
34
+ const [state, setState] = useState<any>(undefined)
34
35
 
35
- const { parseValue, formatValue, defaultInputProps } = useFormInputHandler(accessor, { formatValue: formatValueIn, parseValue: parseValueIn })
36
- const accessorGetter = accessor.getAccessor
37
- const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)
36
+ const { parseValue, formatValue, defaultInputProps } = useFormInputHandler(accessor, { formatValue: formatValueIn, parseValue: parseValueIn })
37
+ const accessorGetter = accessor.getAccessor
38
+ const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)
38
39
 
39
- return (
40
- <SlotInput
41
- ref={ref}
42
- value={formatValue(accessor.value, { state, setState })}
43
- data-invalid={dataAttribute(hasErrors)}
44
- data-dirty={dataAttribute(dirty)}
45
- data-required={dataAttribute(required)}
46
- onFocus={onFocus}
47
- onBlur={onBlur}
48
- onChange={useReferentiallyStableCallback<ChangeEventHandler<HTMLInputElement>>(e => {
49
- accessorGetter().updateValue(parseValue(e.target.value, { state, setState }))
50
- })}
51
- {...defaultInputProps}
52
- id={id ? `${id}-input` : undefined}
53
- required={required}
54
- {...props}
55
- />
56
- )
57
- }, ({ field, isNonbearing, defaultValue }) => {
58
- return <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue} />
59
- })
40
+ return (
41
+ <SlotInput
42
+ ref={ref}
43
+ value={formatValue(accessor.value, { state, setState })}
44
+ data-invalid={dataAttribute(hasErrors)}
45
+ data-dirty={dataAttribute(dirty)}
46
+ data-required={dataAttribute(required)}
47
+ onFocus={onFocus}
48
+ onBlur={onBlur}
49
+ onChange={useReferentiallyStableCallback<ChangeEventHandler<HTMLInputElement>>(e => {
50
+ accessorGetter().updateValue(parseValue(e.target.value, { state, setState }))
51
+ })}
52
+ {...defaultInputProps}
53
+ id={id ? `${id}-input` : undefined}
54
+ required={required}
55
+ {...props}
56
+ />
57
+ )
58
+ },
59
+ ({ field, isNonbearing, defaultValue }) => {
60
+ return <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue} />
61
+ },
62
+ )
@@ -48,5 +48,5 @@ export const FormRadioInput = Component<FormRadioItemProps>(({ field, value, def
48
48
  />
49
49
  )
50
50
  }, ({ field, isNonbearing, defaultValue }) => {
51
- return <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue}/>
51
+ return <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue} />
52
52
  })
package/src/contexts.tsx CHANGED
@@ -1,12 +1,10 @@
1
1
  import { createContext } from '@contember/react-utils'
2
2
  import { FormFieldState } from './types'
3
3
 
4
-
5
4
  const FormFieldStateContext_ = createContext<FormFieldState | undefined>('FormFieldStateContext', undefined)
6
5
  export const FormFieldStateContext = FormFieldStateContext_[0]
7
6
  export const useFormFieldState = FormFieldStateContext_[1]
8
7
 
9
-
10
8
  /**
11
9
  * @deprecated use `useFormState` instead
12
10
  */
@@ -4,7 +4,7 @@ import { FieldAccessor, useEntityBeforePersist } from '@contember/react-binding'
4
4
 
5
5
  export const useFormInputValidationHandler = (field: FieldAccessor<any>) => {
6
6
  const accessorGetter = field.getAccessor
7
- const validationMessage = useRef<string>()
7
+ const validationMessage = useRef<string>(undefined)
8
8
  const [focus, setFocus] = React.useState(false)
9
9
  const inputRef = React.useRef<HTMLInputElement>(null)
10
10
  useEntityBeforePersist(useCallback(() => {
@@ -125,10 +125,10 @@ const toLocalDate = (date: Date) => {
125
125
  return '0'.repeat(Math.max(0, length - str.length)) + str
126
126
  }
127
127
 
128
- return pad(date.getFullYear(), 4) +
129
- '-' + pad(date.getMonth() + 1) +
130
- '-' + pad(date.getDate()) +
131
- 'T' + pad(date.getHours()) +
132
- ':' + pad(date.getMinutes()) +
133
- ':' + pad(date.getSeconds())
128
+ return pad(date.getFullYear(), 4)
129
+ + '-' + pad(date.getMonth() + 1)
130
+ + '-' + pad(date.getDate())
131
+ + 'T' + pad(date.getHours())
132
+ + ':' + pad(date.getMinutes())
133
+ + ':' + pad(date.getSeconds())
134
134
  }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
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
- exports.useFormError = contexts.useFormError;
16
- exports.useFormFieldId = contexts.useFormFieldId;
17
- exports.useFormFieldState = contexts.useFormFieldState;
18
- exports.FormError = FormError.FormError;
19
- exports.FormCheckbox = FormCheckbox.FormCheckbox;
20
- exports.FormFieldScope = FormFieldScope.FormFieldScope;
21
- exports.FormErrorContext = FormFieldStateProvider.FormErrorContext;
22
- exports.FormFieldIdContext = FormFieldStateProvider.FormFieldIdContext;
23
- exports.FormFieldStateProvider = FormFieldStateProvider.FormFieldStateProvider;
24
- exports.FormHasOneRelationScope = FormHasOneRelationScope.FormHasOneRelationScope;
25
- exports.FormHasManyRelationScope = FormHasManyRelationScope.FormHasManyRelationScope;
26
- exports.FormInput = FormInput.FormInput;
27
- exports.FormLabel = FormLabel.FormLabel;
28
- exports.FormRadioInput = FormRadioInput.FormRadioInput;
29
- exports.useFormInputValidationHandler = useFormInputValidationHandler.useFormInputValidationHandler;
30
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,30 +0,0 @@
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";
12
- export {
13
- FormCheckbox,
14
- FormError,
15
- FormErrorContext,
16
- FormFieldIdContext,
17
- FormFieldScope,
18
- FormFieldStateContext,
19
- FormFieldStateProvider,
20
- FormHasManyRelationScope,
21
- FormHasOneRelationScope,
22
- FormInput,
23
- FormLabel,
24
- FormRadioInput,
25
- useFormError,
26
- useFormFieldId,
27
- useFormFieldState,
28
- useFormInputValidationHandler
29
- };
30
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const jsxDevRuntime = require("react/jsx-dev-runtime");
4
- const React = require("react");
5
- const reactBinding = require("@contember/react-binding");
6
- const contexts = require("../contexts.cjs");
7
- const utilities = require("@contember/utilities");
8
- const reactSlot = require("@radix-ui/react-slot");
9
- const useFormInputValidationHandler = require("../hooks/useFormInputValidationHandler.cjs");
10
- function _interopNamespaceDefault(e) {
11
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
12
- if (e) {
13
- for (const k in e) {
14
- if (k !== "default") {
15
- const d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: () => e[k]
19
- });
20
- }
21
- }
22
- }
23
- n.default = e;
24
- return Object.freeze(n);
25
- }
26
- const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
27
- const SlotInput = reactSlot.Slot;
28
- const FormCheckbox = reactBinding.Component(({ field, isNonbearing, defaultValue, ...props }) => {
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;
34
- const value = accessor.value;
35
- const accessorGetter = accessor.getAccessor;
36
- const { ref, onFocus, onBlur } = useFormInputValidationHandler.useFormInputValidationHandler(accessor);
37
- const [checkboxRef, setCheckboxRef] = React__namespace.useState(null);
38
- React.useEffect(() => {
39
- if (!checkboxRef) {
40
- return;
41
- }
42
- checkboxRef.indeterminate = value === null;
43
- }, [checkboxRef, ref, value]);
44
- return /* @__PURE__ */ jsxDevRuntime.jsxDEV(
45
- SlotInput,
46
- {
47
- ref: (it) => {
48
- ref.current = checkboxRef;
49
- setCheckboxRef(it);
50
- },
51
- type: "checkbox",
52
- checked: accessor.value === true,
53
- "data-state": value === null ? "indeterminate" : value ? "checked" : "unchecked",
54
- "data-invalid": utilities.dataAttribute(hasErrors),
55
- "data-dirty": utilities.dataAttribute(dirty),
56
- id: id ? `${id}-input` : void 0,
57
- onFocus,
58
- onBlur,
59
- onChange: React.useCallback((e) => {
60
- accessorGetter().updateValue(e.target.checked);
61
- }, [accessorGetter]),
62
- ...props
63
- },
64
- void 0,
65
- false,
66
- {
67
- fileName: "/home/runner/work/contember/contember/packages/react-form/src/components/FormCheckbox.tsx",
68
- lineNumber: 45,
69
- columnNumber: 3
70
- },
71
- void 0
72
- );
73
- }, ({ field, isNonbearing, defaultValue }, env) => {
74
- const node = reactBinding.TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode();
75
- const resolvedDefaultValue = defaultValue !== void 0 ? defaultValue : node.field.defaultValue ?? (node.field.nullable ? null : false);
76
- return /* @__PURE__ */ jsxDevRuntime.jsxDEV(reactBinding.Field, { field, isNonbearing, defaultValue: resolvedDefaultValue }, void 0, false, {
77
- fileName: "/home/runner/work/contember/contember/packages/react-form/src/components/FormCheckbox.tsx",
78
- lineNumber: 68,
79
- columnNumber: 9
80
- }, void 0);
81
- });
82
- exports.FormCheckbox = FormCheckbox;
83
- //# sourceMappingURL=FormCheckbox.cjs.map
@@ -1 +0,0 @@
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","jsxDEV","dataAttribute","useCallback","this","TreeNodeEnvironmentFactory","Field"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,YAAYA,UAAA;AASL,MAAA,eAAeC,uBAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AACvG,QAAA,WAAWC,sBAAkB,KAAK;AAExC,QAAM,YAAYC,SAAAA,kBAAkB;AACpC,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,IAAA;AAED,gBAAY,gBAAgB,UAAU;AAAA,EACpC,GAAA,CAAC,aAAa,KAAK,KAAK,CAAC;AAG3B,SAAAC,8BAAA;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,IAhBL;AAAA,IAAA;AAAA,IAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA;AAAA,IAAAC;AAAAA,EAiBA;AAEF,GAAG,CAAC,EAAE,OAAO,cAAc,aAAA,GAAgB,QAAQ;AAC5C,QAAA,OAAOC,aAAAA,2BAA2B,0BAA0B,KAAK,EAAE,MAAM,CAAC,EAAE,eAAe;AAC3F,QAAA,uBAAuB,iBAAiB,SAAY,eAAgB,KAAK,MAAM,iBAAiB,KAAK,MAAM,WAAW,OAAO;AAEnI,SAAQJ,8BAAA,OAAAK,oBAAA,EAAM,OAAc,cAA4B,cAAc,qBAA/D,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAAqF,GAAAF,MAAA;AAC7F,CAAC;;"}
@@ -1,67 +0,0 @@
1
- import { jsxDEV } from "react/jsx-dev-runtime";
2
- import * as React from "react";
3
- import { useEffect, useCallback } from "react";
4
- import { Component, useField, TreeNodeEnvironmentFactory, Field } from "@contember/react-binding";
5
- import { useFormFieldState } from "../contexts.js";
6
- import { dataAttribute } from "@contember/utilities";
7
- import { Slot } from "@radix-ui/react-slot";
8
- import { useFormInputValidationHandler } from "../hooks/useFormInputValidationHandler.js";
9
- const SlotInput = Slot;
10
- const FormCheckbox = Component(({ field, isNonbearing, defaultValue, ...props }) => {
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;
16
- const value = accessor.value;
17
- const accessorGetter = accessor.getAccessor;
18
- const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor);
19
- const [checkboxRef, setCheckboxRef] = React.useState(null);
20
- useEffect(() => {
21
- if (!checkboxRef) {
22
- return;
23
- }
24
- checkboxRef.indeterminate = value === null;
25
- }, [checkboxRef, ref, value]);
26
- return /* @__PURE__ */ jsxDEV(
27
- SlotInput,
28
- {
29
- ref: (it) => {
30
- ref.current = checkboxRef;
31
- setCheckboxRef(it);
32
- },
33
- type: "checkbox",
34
- checked: accessor.value === true,
35
- "data-state": value === null ? "indeterminate" : value ? "checked" : "unchecked",
36
- "data-invalid": dataAttribute(hasErrors),
37
- "data-dirty": dataAttribute(dirty),
38
- id: id ? `${id}-input` : void 0,
39
- onFocus,
40
- onBlur,
41
- onChange: useCallback((e) => {
42
- accessorGetter().updateValue(e.target.checked);
43
- }, [accessorGetter]),
44
- ...props
45
- },
46
- void 0,
47
- false,
48
- {
49
- fileName: "/home/runner/work/contember/contember/packages/react-form/src/components/FormCheckbox.tsx",
50
- lineNumber: 45,
51
- columnNumber: 3
52
- },
53
- void 0
54
- );
55
- }, ({ field, isNonbearing, defaultValue }, env) => {
56
- const node = TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode();
57
- const resolvedDefaultValue = defaultValue !== void 0 ? defaultValue : node.field.defaultValue ?? (node.field.nullable ? null : false);
58
- return /* @__PURE__ */ jsxDEV(Field, { field, isNonbearing, defaultValue: resolvedDefaultValue }, void 0, false, {
59
- fileName: "/home/runner/work/contember/contember/packages/react-form/src/components/FormCheckbox.tsx",
60
- lineNumber: 68,
61
- columnNumber: 9
62
- }, void 0);
63
- });
64
- export {
65
- FormCheckbox
66
- };
67
- //# sourceMappingURL=FormCheckbox.js.map
@@ -1 +0,0 @@
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":["this"],"mappings":";;;;;;;;AAeA,MAAM,YAAY;AASL,MAAA,eAAe,UAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AACvG,QAAA,WAAW,SAAkB,KAAK;AAExC,QAAM,YAAY,kBAAkB;AACpC,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,IAAA;AAED,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,IAhBL;AAAA,IAAA;AAAA,IAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA;AAAA,IAAAA;AAAAA,EAiBA;AAEF,GAAG,CAAC,EAAE,OAAO,cAAc,aAAA,GAAgB,QAAQ;AAC5C,QAAA,OAAO,2BAA2B,0BAA0B,KAAK,EAAE,MAAM,CAAC,EAAE,eAAe;AAC3F,QAAA,uBAAuB,iBAAiB,SAAY,eAAgB,KAAK,MAAM,iBAAiB,KAAK,MAAM,WAAW,OAAO;AAEnI,SAAQ,uBAAA,OAAA,EAAM,OAAc,cAA4B,cAAc,qBAA/D,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAAqF,GAAAA,MAAA;AAC7F,CAAC;"}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const React = require("react");
4
- const contexts = require("../contexts.cjs");
5
- const reactBinding = require("@contember/react-binding");
6
- const FormError = ({ children, formatter }) => {
7
- const formState = contexts.useFormFieldState();
8
- if (!formState) {
9
- throw new reactBinding.BindingError("FormError must be used inside a FormField");
10
- }
11
- const { errors, htmlId } = formState;
12
- const formatted = React.useMemo(() => formatter(errors ?? []).filter((it, index, arr) => arr.indexOf(it) === index), [errors, formatter]);
13
- return formatted.map((it, index) => {
14
- return React.cloneElement(children, {
15
- key: index,
16
- ...htmlId ? { id: `${htmlId}-error-${index}` } : {},
17
- children: it
18
- });
19
- });
20
- };
21
- exports.FormError = FormError;
22
- //# sourceMappingURL=FormError.cjs.map
@@ -1 +0,0 @@
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,kBAAkB;AACpC,MAAI,CAAC,WAAW;AACT,UAAA,IAAIC,0BAAa,2CAA2C;AAAA,EAAA;AAE7D,QAAA,EAAE,QAAQ,OAAA,IAAW;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,22 +0,0 @@
1
- import { useMemo, cloneElement } from "react";
2
- import { useFormFieldState } from "../contexts.js";
3
- import { BindingError } from "@contember/react-binding";
4
- const FormError = ({ children, formatter }) => {
5
- const formState = useFormFieldState();
6
- if (!formState) {
7
- throw new BindingError("FormError must be used inside a FormField");
8
- }
9
- const { errors, htmlId } = formState;
10
- const formatted = useMemo(() => formatter(errors ?? []).filter((it, index, arr) => arr.indexOf(it) === index), [errors, formatter]);
11
- return formatted.map((it, index) => {
12
- return cloneElement(children, {
13
- key: index,
14
- ...htmlId ? { id: `${htmlId}-error-${index}` } : {},
15
- children: it
16
- });
17
- });
18
- };
19
- export {
20
- FormError
21
- };
22
- //# sourceMappingURL=FormError.js.map
@@ -1 +0,0 @@
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,kBAAkB;AACpC,MAAI,CAAC,WAAW;AACT,UAAA,IAAI,aAAa,2CAA2C;AAAA,EAAA;AAE7D,QAAA,EAAE,QAAQ,OAAA,IAAW;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;"}
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const jsxDevRuntime = require("react/jsx-dev-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__ */ jsxDevRuntime.jsxDEV(
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
- void 0,
23
- false,
24
- {
25
- fileName: "/home/runner/work/contember/contember/packages/react-form/src/components/FormFieldScope.tsx",
26
- lineNumber: 20,
27
- columnNumber: 3
28
- },
29
- void 0
30
- );
31
- };
32
- exports.FormFieldScope = FormFieldScope;
33
- //# sourceMappingURL=FormFieldScope.cjs.map
@@ -1 +0,0 @@
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","jsxDEV","FormFieldStateProvider","this"],"mappings":";;;;;;AAWO,MAAM,iBAAiB,CAAC,EAAE,OAAO,UAAU,eAAoC;AACrF,QAAM,gBAAgBA,aAAAA,SAAS,EAAE,OAAO;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,8BAAA;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,IANF;AAAA,IAAA;AAAA,IAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA;AAAA,IAAAC;AAAAA,EAOA;AAEF;;"}
@@ -1,33 +0,0 @@
1
- import { jsxDEV } from "react/jsx-dev-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__ */ jsxDEV(
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
- void 0,
21
- false,
22
- {
23
- fileName: "/home/runner/work/contember/contember/packages/react-form/src/components/FormFieldScope.tsx",
24
- lineNumber: 20,
25
- columnNumber: 3
26
- },
27
- void 0
28
- );
29
- };
30
- export {
31
- FormFieldScope
32
- };
33
- //# sourceMappingURL=FormFieldScope.js.map
@@ -1 +0,0 @@
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":["this"],"mappings":";;;;AAWO,MAAM,iBAAiB,CAAC,EAAE,OAAO,UAAU,eAAoC;AACrF,QAAM,gBAAgB,SAAS,EAAE,OAAO;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,IANF;AAAA,IAAA;AAAA,IAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA;AAAA,IAAAA;AAAAA,EAOA;AAEF;"}