@contember/react-form 2.0.0-alpha.4 → 2.0.0-alpha.40
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.
- package/api-extractor.json +3 -0
- package/dist/development/index.cjs +16 -12
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +14 -10
- package/dist/development/index.js.map +1 -1
- package/dist/development/{components → src/components}/FormCheckbox.cjs +12 -9
- package/dist/development/src/components/FormCheckbox.cjs.map +1 -0
- package/dist/development/{components → src/components}/FormCheckbox.js +13 -10
- package/dist/development/src/components/FormCheckbox.js.map +1 -0
- package/dist/development/{components → src/components}/FormError.cjs +5 -5
- package/dist/development/src/components/FormError.cjs.map +1 -0
- package/dist/development/{components → src/components}/FormError.js +6 -6
- package/dist/development/src/components/FormError.js.map +1 -0
- package/dist/development/src/components/FormFieldScope.cjs +33 -0
- package/dist/development/src/components/FormFieldScope.cjs.map +1 -0
- package/dist/development/src/components/FormFieldScope.js +33 -0
- package/dist/development/src/components/FormFieldScope.js.map +1 -0
- package/dist/development/src/components/FormFieldStateProvider.cjs +56 -0
- package/dist/development/src/components/FormFieldStateProvider.cjs.map +1 -0
- package/dist/development/src/components/FormFieldStateProvider.js +56 -0
- package/dist/development/src/components/FormFieldStateProvider.js.map +1 -0
- package/dist/development/src/components/FormHasManyRelationScope.cjs +33 -0
- package/dist/development/src/components/FormHasManyRelationScope.cjs.map +1 -0
- package/dist/development/src/components/FormHasManyRelationScope.js +33 -0
- package/dist/development/src/components/FormHasManyRelationScope.js.map +1 -0
- package/dist/development/src/components/FormHasOneRelationScope.cjs +33 -0
- package/dist/development/src/components/FormHasOneRelationScope.cjs.map +1 -0
- package/dist/development/src/components/FormHasOneRelationScope.js +33 -0
- package/dist/development/src/components/FormHasOneRelationScope.js.map +1 -0
- package/dist/development/{components → src/components}/FormInput.cjs +13 -8
- package/dist/development/src/components/FormInput.cjs.map +1 -0
- package/dist/development/{components → src/components}/FormInput.js +14 -9
- package/dist/development/src/components/FormInput.js.map +1 -0
- package/dist/development/{components → src/components}/FormLabel.cjs +8 -6
- package/dist/development/src/components/FormLabel.cjs.map +1 -0
- package/dist/development/{components → src/components}/FormLabel.js +9 -7
- package/dist/development/src/components/FormLabel.js.map +1 -0
- package/dist/development/{components → src/components}/FormRadioInput.cjs +19 -15
- package/dist/development/src/components/FormRadioInput.cjs.map +1 -0
- package/dist/development/{components → src/components}/FormRadioInput.js +20 -16
- package/dist/development/src/components/FormRadioInput.js.map +1 -0
- package/dist/development/src/contexts.cjs +13 -0
- package/dist/development/src/contexts.cjs.map +1 -0
- package/dist/development/src/contexts.js +13 -0
- package/dist/development/src/contexts.js.map +1 -0
- package/dist/{production → development/src}/hooks/useFormInputValidationHandler.cjs +12 -3
- package/dist/development/src/hooks/useFormInputValidationHandler.cjs.map +1 -0
- package/dist/{production → development/src}/hooks/useFormInputValidationHandler.js +12 -3
- package/dist/development/src/hooks/useFormInputValidationHandler.js.map +1 -0
- package/dist/development/src/internal/useFormInputHandler.cjs.map +1 -0
- package/dist/development/src/internal/useFormInputHandler.js.map +1 -0
- package/dist/production/index.cjs +16 -12
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +14 -10
- package/dist/production/index.js.map +1 -1
- package/dist/production/{components → src/components}/FormCheckbox.cjs +7 -4
- package/dist/production/src/components/FormCheckbox.cjs.map +1 -0
- package/dist/production/{components → src/components}/FormCheckbox.js +8 -5
- package/dist/production/src/components/FormCheckbox.js.map +1 -0
- package/dist/production/{components → src/components}/FormError.cjs +5 -5
- package/dist/production/src/components/FormError.cjs.map +1 -0
- package/dist/production/{components → src/components}/FormError.js +6 -6
- package/dist/production/src/components/FormError.js.map +1 -0
- package/dist/production/src/components/FormFieldScope.cjs +25 -0
- package/dist/production/src/components/FormFieldScope.cjs.map +1 -0
- package/dist/production/src/components/FormFieldScope.js +25 -0
- package/dist/production/src/components/FormFieldScope.js.map +1 -0
- package/dist/production/src/components/FormFieldStateProvider.cjs +34 -0
- package/dist/production/src/components/FormFieldStateProvider.cjs.map +1 -0
- package/dist/production/src/components/FormFieldStateProvider.js +34 -0
- package/dist/production/src/components/FormFieldStateProvider.js.map +1 -0
- package/dist/production/src/components/FormHasManyRelationScope.cjs +25 -0
- package/dist/production/src/components/FormHasManyRelationScope.cjs.map +1 -0
- package/dist/production/src/components/FormHasManyRelationScope.js +25 -0
- package/dist/production/src/components/FormHasManyRelationScope.js.map +1 -0
- package/dist/production/src/components/FormHasOneRelationScope.cjs +25 -0
- package/dist/production/src/components/FormHasOneRelationScope.cjs.map +1 -0
- package/dist/production/src/components/FormHasOneRelationScope.js +25 -0
- package/dist/production/src/components/FormHasOneRelationScope.js.map +1 -0
- package/dist/production/{components → src/components}/FormInput.cjs +9 -4
- package/dist/production/src/components/FormInput.cjs.map +1 -0
- package/dist/production/{components → src/components}/FormInput.js +10 -5
- package/dist/production/src/components/FormInput.js.map +1 -0
- package/dist/production/{components → src/components}/FormLabel.cjs +7 -5
- package/dist/production/src/components/FormLabel.cjs.map +1 -0
- package/dist/production/{components → src/components}/FormLabel.js +8 -6
- package/dist/production/src/components/FormLabel.js.map +1 -0
- package/dist/production/{components → src/components}/FormRadioInput.cjs +15 -11
- package/dist/production/src/components/FormRadioInput.cjs.map +1 -0
- package/dist/production/{components → src/components}/FormRadioInput.js +16 -12
- package/dist/production/src/components/FormRadioInput.js.map +1 -0
- package/dist/production/src/contexts.cjs +13 -0
- package/dist/production/src/contexts.cjs.map +1 -0
- package/dist/production/src/contexts.js +13 -0
- package/dist/production/src/contexts.js.map +1 -0
- package/dist/{development → production/src}/hooks/useFormInputValidationHandler.cjs +12 -3
- package/dist/production/src/hooks/useFormInputValidationHandler.cjs.map +1 -0
- package/dist/{development → production/src}/hooks/useFormInputValidationHandler.js +12 -3
- package/dist/production/src/hooks/useFormInputValidationHandler.js.map +1 -0
- package/dist/production/src/internal/useFormInputHandler.cjs.map +1 -0
- package/dist/production/src/internal/useFormInputHandler.js.map +1 -0
- package/dist/types/components/FormCheckbox.d.ts.map +1 -1
- package/dist/types/components/FormError.d.ts.map +1 -1
- package/dist/types/components/FormFieldScope.d.ts +2 -1
- package/dist/types/components/FormFieldScope.d.ts.map +1 -1
- package/dist/types/components/FormFieldStateProvider.d.ts +36 -0
- package/dist/types/components/FormFieldStateProvider.d.ts.map +1 -0
- package/dist/types/components/FormHasManyRelationScope.d.ts +5 -1
- package/dist/types/components/FormHasManyRelationScope.d.ts.map +1 -1
- package/dist/types/components/FormHasOneRelationScope.d.ts +2 -1
- package/dist/types/components/FormHasOneRelationScope.d.ts.map +1 -1
- package/dist/types/components/FormInput.d.ts.map +1 -1
- package/dist/types/components/FormLabel.d.ts.map +1 -1
- package/dist/types/components/FormRadioInput.d.ts +1 -1
- package/dist/types/components/FormRadioInput.d.ts.map +1 -1
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/index.d.ts.map +1 -1
- package/dist/types/contexts.d.ts +10 -6
- package/dist/types/contexts.d.ts.map +1 -1
- package/dist/types/hooks/useFormInputValidationHandler.d.ts.map +1 -1
- package/dist/types/internal/useFormInputHandler.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types/index.d.ts +12 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +10 -17
- package/src/components/FormCheckbox.tsx +32 -21
- package/src/components/FormError.tsx +6 -6
- package/src/components/FormFieldScope.tsx +17 -12
- package/src/components/FormFieldStateProvider.tsx +71 -0
- package/src/components/FormHasManyRelationScope.tsx +22 -14
- package/src/components/FormHasOneRelationScope.tsx +17 -13
- package/src/components/FormInput.tsx +12 -5
- package/src/components/FormLabel.tsx +8 -6
- package/src/components/FormRadioInput.tsx +22 -15
- package/src/components/index.ts +1 -0
- package/src/contexts.tsx +18 -0
- package/src/hooks/useFormInputValidationHandler.tsx +13 -3
- package/src/tsconfig.json +5 -2
- package/src/types/index.ts +13 -0
- package/tsconfig.json +7 -0
- package/tsdoc.json +6 -0
- package/dist/development/components/FormCheckbox.cjs.map +0 -1
- package/dist/development/components/FormCheckbox.js.map +0 -1
- package/dist/development/components/FormError.cjs.map +0 -1
- package/dist/development/components/FormError.js.map +0 -1
- package/dist/development/components/FormFieldScope.cjs +0 -23
- package/dist/development/components/FormFieldScope.cjs.map +0 -1
- package/dist/development/components/FormFieldScope.js +0 -23
- package/dist/development/components/FormFieldScope.js.map +0 -1
- package/dist/development/components/FormHasManyRelationScope.cjs +0 -23
- package/dist/development/components/FormHasManyRelationScope.cjs.map +0 -1
- package/dist/development/components/FormHasManyRelationScope.js +0 -23
- package/dist/development/components/FormHasManyRelationScope.js.map +0 -1
- package/dist/development/components/FormHasOneRelationScope.cjs +0 -23
- package/dist/development/components/FormHasOneRelationScope.cjs.map +0 -1
- package/dist/development/components/FormHasOneRelationScope.js +0 -23
- package/dist/development/components/FormHasOneRelationScope.js.map +0 -1
- package/dist/development/components/FormInput.cjs.map +0 -1
- package/dist/development/components/FormInput.js.map +0 -1
- package/dist/development/components/FormLabel.cjs.map +0 -1
- package/dist/development/components/FormLabel.js.map +0 -1
- package/dist/development/components/FormRadioInput.cjs.map +0 -1
- package/dist/development/components/FormRadioInput.js.map +0 -1
- package/dist/development/contexts.cjs +0 -14
- package/dist/development/contexts.cjs.map +0 -1
- package/dist/development/contexts.js +0 -14
- package/dist/development/contexts.js.map +0 -1
- package/dist/development/hooks/useFormInputValidationHandler.cjs.map +0 -1
- package/dist/development/hooks/useFormInputValidationHandler.js.map +0 -1
- package/dist/development/internal/useFormInputHandler.cjs.map +0 -1
- package/dist/development/internal/useFormInputHandler.js.map +0 -1
- package/dist/production/components/FormCheckbox.cjs.map +0 -1
- package/dist/production/components/FormCheckbox.js.map +0 -1
- package/dist/production/components/FormError.cjs.map +0 -1
- package/dist/production/components/FormError.js.map +0 -1
- package/dist/production/components/FormFieldScope.cjs +0 -15
- package/dist/production/components/FormFieldScope.cjs.map +0 -1
- package/dist/production/components/FormFieldScope.js +0 -15
- package/dist/production/components/FormFieldScope.js.map +0 -1
- package/dist/production/components/FormHasManyRelationScope.cjs +0 -15
- package/dist/production/components/FormHasManyRelationScope.cjs.map +0 -1
- package/dist/production/components/FormHasManyRelationScope.js +0 -15
- package/dist/production/components/FormHasManyRelationScope.js.map +0 -1
- package/dist/production/components/FormHasOneRelationScope.cjs +0 -15
- package/dist/production/components/FormHasOneRelationScope.cjs.map +0 -1
- package/dist/production/components/FormHasOneRelationScope.js +0 -15
- package/dist/production/components/FormHasOneRelationScope.js.map +0 -1
- package/dist/production/components/FormInput.cjs.map +0 -1
- package/dist/production/components/FormInput.js.map +0 -1
- package/dist/production/components/FormLabel.cjs.map +0 -1
- package/dist/production/components/FormLabel.js.map +0 -1
- package/dist/production/components/FormRadioInput.cjs.map +0 -1
- package/dist/production/components/FormRadioInput.js.map +0 -1
- package/dist/production/contexts.cjs +0 -14
- package/dist/production/contexts.cjs.map +0 -1
- package/dist/production/contexts.js +0 -14
- package/dist/production/contexts.js.map +0 -1
- package/dist/production/hooks/useFormInputValidationHandler.cjs.map +0 -1
- package/dist/production/hooks/useFormInputValidationHandler.js.map +0 -1
- package/dist/production/internal/useFormInputHandler.cjs.map +0 -1
- package/dist/production/internal/useFormInputHandler.js.map +0 -1
- package/src/contexts.ts +0 -12
- /package/dist/development/{internal → src/internal}/useFormInputHandler.cjs +0 -0
- /package/dist/development/{internal → src/internal}/useFormInputHandler.js +0 -0
- /package/dist/production/{internal → src/internal}/useFormInputHandler.cjs +0 -0
- /package/dist/production/{internal → src/internal}/useFormInputHandler.js +0 -0
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.0.0-alpha.
|
|
4
|
+
"version": "2.0.0-alpha.40",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/production/index.js",
|
|
@@ -11,28 +11,22 @@
|
|
|
11
11
|
"types": "./dist/types/index.d.ts",
|
|
12
12
|
"development": "./dist/development/index.js",
|
|
13
13
|
"production": "./dist/production/index.js",
|
|
14
|
+
"typescript": "./src/index.ts",
|
|
14
15
|
"default": "./dist/production/index.js"
|
|
15
16
|
},
|
|
16
17
|
"require": {
|
|
17
18
|
"types": "./dist/types/index.d.ts",
|
|
18
19
|
"development": "./dist/development/index.cjs",
|
|
19
20
|
"production": "./dist/production/index.cjs",
|
|
21
|
+
"typescript": "./src/index.ts",
|
|
20
22
|
"default": "./dist/production/index.cjs"
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
},
|
|
24
|
-
"files": [
|
|
25
|
-
"dist/",
|
|
26
|
-
"src/"
|
|
27
|
-
],
|
|
28
26
|
"typings": "./dist/types/index.d.ts",
|
|
29
27
|
"scripts": {
|
|
30
|
-
"build": "yarn build:js:dev && yarn build:js:prod",
|
|
31
|
-
"build:js:dev": "NODE_ENV=development vite build --mode development",
|
|
32
|
-
"build:js:prod": "vite build --mode production",
|
|
33
28
|
"ae:build": "api-extractor run --local",
|
|
34
|
-
"ae:test": "api-extractor run"
|
|
35
|
-
"test": "vitest"
|
|
29
|
+
"ae:test": "api-extractor run"
|
|
36
30
|
},
|
|
37
31
|
"repository": {
|
|
38
32
|
"type": "git",
|
|
@@ -40,10 +34,10 @@
|
|
|
40
34
|
"directory": "packages/react-form"
|
|
41
35
|
},
|
|
42
36
|
"dependencies": {
|
|
43
|
-
"@contember/react-binding": "2.0.0-alpha.
|
|
44
|
-
"@contember/react-utils": "2.0.0-alpha.
|
|
45
|
-
"@contember/utilities": "2.0.0-alpha.
|
|
46
|
-
"@radix-ui/react-slot": "^1.0
|
|
37
|
+
"@contember/react-binding": "2.0.0-alpha.40",
|
|
38
|
+
"@contember/react-utils": "2.0.0-alpha.40",
|
|
39
|
+
"@contember/utilities": "2.0.0-alpha.40",
|
|
40
|
+
"@radix-ui/react-slot": "^1.1.0"
|
|
47
41
|
},
|
|
48
42
|
"peerDependencies": {
|
|
49
43
|
"react": "^18 || ^19",
|
|
@@ -52,6 +46,5 @@
|
|
|
52
46
|
"devDependencies": {
|
|
53
47
|
"react": "^18.3.1",
|
|
54
48
|
"react-dom": "^18.3.1"
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { ChangeEventHandler, ReactElement, useCallback, useEffect } from 'react'
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
Component,
|
|
5
|
+
Field,
|
|
6
|
+
OptionallyVariableFieldValue,
|
|
7
|
+
SugaredRelativeSingleField,
|
|
8
|
+
TreeNodeEnvironmentFactory,
|
|
9
|
+
useField,
|
|
10
|
+
} from '@contember/react-binding'
|
|
11
|
+
import { useFormFieldState } from '../contexts'
|
|
5
12
|
import { dataAttribute } from '@contember/utilities'
|
|
6
13
|
import { useFormInputValidationHandler } from '../hooks'
|
|
7
14
|
import { Slot } from '@radix-ui/react-slot'
|
|
@@ -16,10 +23,13 @@ export interface FormCheckboxProps {
|
|
|
16
23
|
}
|
|
17
24
|
|
|
18
25
|
export const FormCheckbox = Component<FormCheckboxProps>(({ field, isNonbearing, defaultValue, ...props }) => {
|
|
19
|
-
const id = useFormFieldId()
|
|
20
26
|
const accessor = useField<boolean>(field)
|
|
27
|
+
|
|
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
|
|
21
32
|
const value = accessor.value
|
|
22
|
-
const errors = useFormError() ?? accessor.errors?.errors ?? []
|
|
23
33
|
const accessorGetter = accessor.getAccessor
|
|
24
34
|
const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)
|
|
25
35
|
const [checkboxRef, setCheckboxRef] = React.useState<HTMLInputElement | null>(null)
|
|
@@ -32,23 +42,24 @@ export const FormCheckbox = Component<FormCheckboxProps>(({ field, isNonbearing,
|
|
|
32
42
|
}, [checkboxRef, ref, value])
|
|
33
43
|
|
|
34
44
|
return (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
<SlotInput
|
|
46
|
+
ref={it => {
|
|
47
|
+
(ref as any).current = checkboxRef
|
|
48
|
+
setCheckboxRef(it)
|
|
49
|
+
}}
|
|
50
|
+
type="checkbox"
|
|
51
|
+
checked={accessor.value === true}
|
|
52
|
+
data-state={value === null ? 'indeterminate' : (value ? 'checked' : 'unchecked')}
|
|
53
|
+
data-invalid={dataAttribute(hasErrors)}
|
|
54
|
+
data-dirty={dataAttribute(dirty)}
|
|
55
|
+
id={id ? `${id}-input` : undefined}
|
|
56
|
+
onFocus={onFocus}
|
|
57
|
+
onBlur={onBlur}
|
|
58
|
+
onChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {
|
|
59
|
+
accessorGetter().updateValue(e.target.checked)
|
|
60
|
+
}, [accessorGetter])}
|
|
61
|
+
{...props}
|
|
62
|
+
/>
|
|
52
63
|
)
|
|
53
64
|
}, ({ field, isNonbearing, defaultValue }, env) => {
|
|
54
65
|
const node = TreeNodeEnvironmentFactory.createEnvironmentForField(env, { field }).getSubTreeNode()
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { cloneElement, ReactElement, ReactNode, useMemo } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { useFormFieldState } from '../contexts'
|
|
3
3
|
import { BindingError, ErrorAccessor } from '@contember/react-binding'
|
|
4
4
|
|
|
5
5
|
export const FormError = ({ children, formatter }: {
|
|
6
6
|
formatter: (errors: ErrorAccessor.Error[]) => ReactNode[]
|
|
7
7
|
children: ReactElement
|
|
8
8
|
}) => {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const formatted = useMemo(() => formatter(errors ?? []), [errors, formatter])
|
|
12
|
-
if (errors === undefined || id === undefined) {
|
|
9
|
+
const formState = useFormFieldState()
|
|
10
|
+
if (!formState) {
|
|
13
11
|
throw new BindingError('FormError must be used inside a FormField')
|
|
14
12
|
}
|
|
13
|
+
const { errors, htmlId } = formState
|
|
14
|
+
const formatted = useMemo(() => formatter(errors ?? []).filter((it, index, arr) => arr.indexOf(it) === index), [errors, formatter])
|
|
15
15
|
return formatted.map((it, index) => {
|
|
16
16
|
return cloneElement(children, {
|
|
17
17
|
key: index,
|
|
18
|
-
...{ id: `${
|
|
18
|
+
...(htmlId ? { id: `${htmlId}-error-${index}` } : {}),
|
|
19
19
|
children: it,
|
|
20
20
|
})
|
|
21
21
|
})
|
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
|
-
import {
|
|
3
|
-
import { FormErrorContext, FormFieldIdContext } from '../contexts'
|
|
2
|
+
import { useMemo } from 'react'
|
|
4
3
|
import { SugaredRelativeSingleField, useField } from '@contember/react-binding'
|
|
5
|
-
|
|
6
|
-
const emptyArr: [] = []
|
|
4
|
+
import { FormFieldStateProvider } from './FormFieldStateProvider'
|
|
7
5
|
|
|
8
6
|
export type FormFieldScopeProps = {
|
|
9
7
|
field: SugaredRelativeSingleField['field']
|
|
10
8
|
children: React.ReactNode
|
|
9
|
+
required?: boolean
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
export const FormFieldScope = ({ field, children }: FormFieldScopeProps) => {
|
|
14
|
-
const id = useId()
|
|
12
|
+
export const FormFieldScope = ({ field, children, required }: FormFieldScopeProps) => {
|
|
15
13
|
const fieldAccessor = useField({ field })
|
|
16
|
-
const
|
|
14
|
+
const entityName = fieldAccessor.getParent().name
|
|
15
|
+
const fieldName = fieldAccessor.fieldName
|
|
16
|
+
const enumName = fieldAccessor.schema.enumName ?? undefined
|
|
17
|
+
const fieldInfo = useMemo(() => ({ entityName, fieldName, enumName }), [entityName, fieldName, enumName])
|
|
18
|
+
|
|
17
19
|
return (
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
<FormFieldStateProvider
|
|
21
|
+
errors={fieldAccessor.errors?.errors}
|
|
22
|
+
required={required ?? !fieldAccessor.schema.nullable}
|
|
23
|
+
dirty={fieldAccessor.hasUnpersistedChanges}
|
|
24
|
+
field={fieldInfo}
|
|
25
|
+
>
|
|
26
|
+
{children}
|
|
27
|
+
</FormFieldStateProvider>
|
|
23
28
|
)
|
|
24
29
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ErrorAccessor } from '@contember/react-binding'
|
|
2
|
+
import { useEffect, useId, useMemo } from 'react'
|
|
3
|
+
import { FormFieldStateContext, useFormFieldState } from '../contexts'
|
|
4
|
+
import { FormFieldState } from '../types'
|
|
5
|
+
|
|
6
|
+
const emptyArr: [] = []
|
|
7
|
+
|
|
8
|
+
export type FormFieldStateProvider =
|
|
9
|
+
& Partial<FormFieldState>
|
|
10
|
+
& {
|
|
11
|
+
children: React.ReactNode
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const FormFieldStateProvider = ({ children, required = false, errors = emptyArr, dirty = false, htmlId, field }: FormFieldStateProvider) => {
|
|
15
|
+
const generatedId = useId()
|
|
16
|
+
htmlId ??= generatedId
|
|
17
|
+
const value = useMemo(() => ({ htmlId, required, errors, dirty, field }), [htmlId, required, errors, dirty, field])
|
|
18
|
+
return <FormFieldStateContext.Provider value={value}>{children}</FormFieldStateContext.Provider>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* BC for
|
|
23
|
+
* <FormFieldIdContext.Provider value={id}>
|
|
24
|
+
* <FormErrorContext.Provider value={[]}>
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated use `FormFieldStateProvider` instead
|
|
29
|
+
*/
|
|
30
|
+
export const FormFieldIdContext = {
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated use `FormFieldStateProvider` instead
|
|
33
|
+
*/
|
|
34
|
+
Provider: ({ children, value }: { children: React.ReactNode; value: string }) => {
|
|
35
|
+
const state = useFormFieldState()
|
|
36
|
+
if (import.meta.env.DEV) {
|
|
37
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
console.warn('FormFieldIdContext.Provider is deprecated, use FormFieldStateProvider instead')
|
|
40
|
+
}, [])
|
|
41
|
+
}
|
|
42
|
+
return (
|
|
43
|
+
<FormFieldStateProvider {...state} htmlId={value}>
|
|
44
|
+
{children}
|
|
45
|
+
</FormFieldStateProvider>
|
|
46
|
+
)
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated use `FormFieldStateProvider` instead
|
|
52
|
+
*/
|
|
53
|
+
export const FormErrorContext = {
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated use `FormFieldStateProvider` instead
|
|
56
|
+
*/
|
|
57
|
+
Provider: ({ children, value }: { children: React.ReactNode; value: ErrorAccessor.Error[] }) => {
|
|
58
|
+
const state = useFormFieldState()
|
|
59
|
+
if (import.meta.env.DEV) {
|
|
60
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
console.warn('FormErrorContext.Provider is deprecated, use FormFieldStateProvider instead')
|
|
63
|
+
}, [])
|
|
64
|
+
}
|
|
65
|
+
return (
|
|
66
|
+
<FormFieldStateProvider {...state} errors={value}>
|
|
67
|
+
{children}
|
|
68
|
+
</FormFieldStateProvider>
|
|
69
|
+
)
|
|
70
|
+
},
|
|
71
|
+
}
|
|
@@ -1,24 +1,32 @@
|
|
|
1
|
-
import { SugaredRelativeEntityList, useEntityList } from '@contember/react-binding'
|
|
1
|
+
import { HasManyRelationMarker, SugaredRelativeEntityList, useEntityList } from '@contember/react-binding'
|
|
2
2
|
import * as React from 'react'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const emptyArr: [] = []
|
|
3
|
+
import { FormFieldStateProvider } from './FormFieldStateProvider'
|
|
4
|
+
import { useMemo } from 'react'
|
|
7
5
|
|
|
8
6
|
export type FormHasManyRelationScopeProps = {
|
|
9
7
|
field: SugaredRelativeEntityList['field']
|
|
8
|
+
orderBy?: SugaredRelativeEntityList['orderBy']
|
|
9
|
+
limit?: SugaredRelativeEntityList['limit']
|
|
10
|
+
offset?: SugaredRelativeEntityList['offset']
|
|
10
11
|
children: React.ReactNode
|
|
12
|
+
required?: boolean
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
export const FormHasManyRelationScope = ({
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
15
|
+
export const FormHasManyRelationScope = ({ children, required, ...props }: FormHasManyRelationScopeProps) => {
|
|
16
|
+
const entityRelation = useEntityList(props)
|
|
17
|
+
const entityName = entityRelation.getParent()!.name
|
|
18
|
+
const marker = entityRelation.getMarker() as HasManyRelationMarker
|
|
19
|
+
const fieldName = marker.parameters.field
|
|
20
|
+
const fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName])
|
|
21
|
+
|
|
17
22
|
return (
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
<FormFieldStateProvider
|
|
24
|
+
errors={entityRelation.errors?.errors}
|
|
25
|
+
dirty={entityRelation.hasUnpersistedChanges}
|
|
26
|
+
required={required}
|
|
27
|
+
field={fieldInfo}
|
|
28
|
+
>
|
|
29
|
+
{children}
|
|
30
|
+
</FormFieldStateProvider>
|
|
23
31
|
)
|
|
24
32
|
}
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const emptyArr: [] = []
|
|
2
|
+
import { HasOneRelationMarker, SugaredRelativeSingleEntity, useEntity } from '@contember/react-binding'
|
|
3
|
+
import { FormFieldStateProvider } from './FormFieldStateProvider'
|
|
4
|
+
import { useMemo } from 'react'
|
|
7
5
|
|
|
8
6
|
export type FormHasOneRelationScopeProps = {
|
|
9
7
|
field: SugaredRelativeSingleEntity['field']
|
|
10
8
|
children: React.ReactNode
|
|
9
|
+
required?: boolean
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
export const FormHasOneRelationScope = ({ field, children }: FormHasOneRelationScopeProps) => {
|
|
14
|
-
const id = useId()
|
|
12
|
+
export const FormHasOneRelationScope = ({ field, children, required }: FormHasOneRelationScopeProps) => {
|
|
15
13
|
const entityRelation = useEntity({ field })
|
|
16
|
-
const
|
|
14
|
+
const marker = entityRelation.getMarker() as HasOneRelationMarker
|
|
15
|
+
const fieldName = marker.parameters.field
|
|
16
|
+
const entityName = entityRelation.getParent()!.name
|
|
17
|
+
const fieldInfo = useMemo(() => ({ entityName, fieldName }), [entityName, fieldName])
|
|
17
18
|
return (
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
<FormFieldStateProvider
|
|
20
|
+
errors={entityRelation.errors?.errors}
|
|
21
|
+
dirty={entityRelation.hasUnpersistedChanges}
|
|
22
|
+
required={required}
|
|
23
|
+
field={fieldInfo}
|
|
24
|
+
>
|
|
25
|
+
{children}
|
|
26
|
+
</FormFieldStateProvider>
|
|
23
27
|
)
|
|
24
28
|
}
|
|
@@ -4,7 +4,7 @@ import { Slot } from '@radix-ui/react-slot'
|
|
|
4
4
|
import { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'
|
|
5
5
|
import { dataAttribute } from '@contember/utilities'
|
|
6
6
|
import { useFormInputHandler } from '../internal/useFormInputHandler'
|
|
7
|
-
import {
|
|
7
|
+
import { useFormFieldState } from '../contexts'
|
|
8
8
|
import { useFormInputValidationHandler } from '../hooks/useFormInputValidationHandler'
|
|
9
9
|
import { FormInputHandler } from '../types'
|
|
10
10
|
|
|
@@ -21,9 +21,14 @@ export interface FormInputProps {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export const FormInput = Component<FormInputProps>(({ field, isNonbearing, defaultValue, formatValue: formatValueIn, parseValue: parseValueIn, ...props }) => {
|
|
24
|
-
const id = useFormFieldId()
|
|
25
24
|
const accessor = useField(field)
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
const formState = useFormFieldState()
|
|
27
|
+
const id = formState?.htmlId
|
|
28
|
+
const hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0
|
|
29
|
+
const dirty = formState?.dirty ?? accessor.hasUnpersistedChanges
|
|
30
|
+
const required = formState?.required ?? !accessor.schema.nullable
|
|
31
|
+
|
|
27
32
|
const { parseValue, formatValue, defaultInputProps } = useFormInputHandler(accessor, { formatValue: formatValueIn, parseValue: parseValueIn })
|
|
28
33
|
const accessorGetter = accessor.getAccessor
|
|
29
34
|
const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)
|
|
@@ -32,7 +37,9 @@ export const FormInput = Component<FormInputProps>(({ field, isNonbearing, defau
|
|
|
32
37
|
<SlotInput
|
|
33
38
|
ref={ref}
|
|
34
39
|
value={formatValue(accessor.value)}
|
|
35
|
-
data-invalid={dataAttribute(
|
|
40
|
+
data-invalid={dataAttribute(hasErrors)}
|
|
41
|
+
data-dirty={dataAttribute(dirty)}
|
|
42
|
+
data-required={dataAttribute(required)}
|
|
36
43
|
onFocus={onFocus}
|
|
37
44
|
onBlur={onBlur}
|
|
38
45
|
onChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {
|
|
@@ -40,7 +47,7 @@ export const FormInput = Component<FormInputProps>(({ field, isNonbearing, defau
|
|
|
40
47
|
}, [accessorGetter, parseValue])}
|
|
41
48
|
{...defaultInputProps}
|
|
42
49
|
id={id ? `${id}-input` : undefined}
|
|
43
|
-
required={
|
|
50
|
+
required={required}
|
|
44
51
|
{...props}
|
|
45
52
|
/>
|
|
46
53
|
)
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { Slot } from '@radix-ui/react-slot'
|
|
3
3
|
import { dataAttribute } from '@contember/utilities'
|
|
4
|
-
import {
|
|
4
|
+
import { useFormFieldState } from '../contexts'
|
|
5
5
|
import { BindingError } from '@contember/react-binding'
|
|
6
6
|
|
|
7
7
|
export const FormLabel = (props: {
|
|
8
8
|
children: React.ReactElement
|
|
9
9
|
}) => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
throw new BindingError('FormLabel must be used inside a FormField')
|
|
10
|
+
const formState = useFormFieldState()
|
|
11
|
+
if (!formState) {
|
|
12
|
+
throw new BindingError('FormError must be used inside a FormField')
|
|
14
13
|
}
|
|
14
|
+
const { errors, htmlId, dirty, required } = formState
|
|
15
15
|
return (
|
|
16
16
|
<Slot
|
|
17
17
|
data-invalid={dataAttribute(errors.length > 0)}
|
|
18
|
-
{
|
|
18
|
+
data-dirty={dataAttribute(dirty)}
|
|
19
|
+
data-required={dataAttribute(required)}
|
|
20
|
+
{...(htmlId ? { htmlFor: `${htmlId}-input` } : {})}
|
|
19
21
|
{...props}
|
|
20
22
|
/>
|
|
21
23
|
)
|
|
@@ -1,45 +1,52 @@
|
|
|
1
1
|
import { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, useField } from '@contember/react-binding'
|
|
2
|
+
import { dataAttribute } from '@contember/utilities'
|
|
3
|
+
import { Slot } from '@radix-ui/react-slot'
|
|
2
4
|
import * as React from 'react'
|
|
3
5
|
import { ChangeEventHandler, useCallback } from 'react'
|
|
4
|
-
import {
|
|
5
|
-
import { useFormError, useFormFieldId } from '../contexts'
|
|
6
|
+
import { useFormFieldState } from '../contexts'
|
|
6
7
|
import { useFormInputValidationHandler } from '../hooks'
|
|
7
|
-
import { dataAttribute } from '@contember/utilities'
|
|
8
8
|
|
|
9
9
|
const SlotInput = Slot as React.ForwardRefExoticComponent<React.RefAttributes<HTMLInputElement> & React.InputHTMLAttributes<HTMLInputElement>>
|
|
10
10
|
|
|
11
11
|
export interface FormRadioItemProps {
|
|
12
12
|
field: SugaredRelativeSingleField['field']
|
|
13
|
-
value: string
|
|
13
|
+
value: string | null | number | boolean
|
|
14
14
|
isNonbearing?: boolean
|
|
15
15
|
defaultValue?: OptionallyVariableFieldValue
|
|
16
16
|
children: React.ReactNode
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export const FormRadioInput = Component<FormRadioItemProps>(({ field, value, defaultValue, isNonbearing, ...props }) => {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const
|
|
20
|
+
const accessor = useField(field)
|
|
21
|
+
|
|
22
|
+
const formState = useFormFieldState()
|
|
23
|
+
const id = formState?.htmlId
|
|
24
|
+
const hasErrors = (formState?.errors.length ?? accessor.errors?.errors?.length ?? 0) > 0
|
|
25
|
+
const dirty = formState?.dirty ?? accessor.hasUnpersistedChanges
|
|
26
|
+
|
|
23
27
|
const accessorGetter = accessor.getAccessor
|
|
24
28
|
const { ref, onFocus, onBlur } = useFormInputValidationHandler(accessor)
|
|
25
29
|
|
|
30
|
+
const handleChange = useCallback<ChangeEventHandler<HTMLInputElement>>(e => {
|
|
31
|
+
accessorGetter().updateValue(value)
|
|
32
|
+
}, [accessorGetter, value])
|
|
33
|
+
|
|
26
34
|
return (
|
|
27
35
|
<SlotInput
|
|
28
36
|
ref={ref}
|
|
29
37
|
type="radio"
|
|
30
|
-
value={value}
|
|
38
|
+
value={typeof value === 'string' ? value : undefined}
|
|
31
39
|
checked={accessor.value === value}
|
|
32
|
-
data-invalid={dataAttribute(
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
data-invalid={dataAttribute(hasErrors)}
|
|
41
|
+
data-dirty={dataAttribute(dirty)}
|
|
42
|
+
name={id ? id + '-input' : undefined}
|
|
43
|
+
id={id ? `${id}-input` : undefined}
|
|
35
44
|
onFocus={onFocus}
|
|
36
45
|
onBlur={onBlur}
|
|
37
|
-
onChange={
|
|
38
|
-
accessorGetter().updateValue(value)
|
|
39
|
-
}, [accessorGetter, value])}
|
|
46
|
+
onChange={handleChange}
|
|
40
47
|
{...props}
|
|
41
48
|
/>
|
|
42
49
|
)
|
|
43
50
|
}, ({ field, isNonbearing, defaultValue }) => {
|
|
44
|
-
return <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue}
|
|
51
|
+
return <Field field={field} isNonbearing={isNonbearing} defaultValue={defaultValue}/>
|
|
45
52
|
})
|
package/src/components/index.ts
CHANGED
package/src/contexts.tsx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createContext } from '@contember/react-utils'
|
|
2
|
+
import { FormFieldState } from './types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const FormFieldStateContext_ = createContext<FormFieldState | undefined>('FormFieldStateContext', undefined)
|
|
6
|
+
export const FormFieldStateContext = FormFieldStateContext_[0]
|
|
7
|
+
export const useFormFieldState = FormFieldStateContext_[1]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated use `useFormState` instead
|
|
12
|
+
*/
|
|
13
|
+
export const useFormFieldId = () => useFormFieldState()?.htmlId
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated use `useFormState` instead
|
|
17
|
+
*/
|
|
18
|
+
export const useFormError = () => useFormFieldState()?.errors
|
|
@@ -25,9 +25,12 @@ export const useFormInputValidationHandler = (field: FieldAccessor<any>) => {
|
|
|
25
25
|
const previousMessage = validationMessage.current
|
|
26
26
|
validationMessage.current = message
|
|
27
27
|
|
|
28
|
+
const accessor = accessorGetter()
|
|
28
29
|
// if there is no message, we want to clear the error
|
|
29
30
|
if (!message) {
|
|
30
|
-
|
|
31
|
+
if (previousMessage) {
|
|
32
|
+
clearSpecificError(accessor, previousMessage)
|
|
33
|
+
}
|
|
31
34
|
return
|
|
32
35
|
}
|
|
33
36
|
if (message === previousMessage) {
|
|
@@ -41,8 +44,8 @@ export const useFormInputValidationHandler = (field: FieldAccessor<any>) => {
|
|
|
41
44
|
// if the input is not focused, we want to show the error message
|
|
42
45
|
// also, even the input is focused, we want to replace the previous message
|
|
43
46
|
if (!focus || !!previousMessage) {
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
accessor.clearErrors()
|
|
48
|
+
accessor.addError(message)
|
|
46
49
|
}
|
|
47
50
|
})
|
|
48
51
|
|
|
@@ -60,3 +63,10 @@ export const useFormInputValidationHandler = (field: FieldAccessor<any>) => {
|
|
|
60
63
|
}, [accessorGetter]),
|
|
61
64
|
}
|
|
62
65
|
}
|
|
66
|
+
|
|
67
|
+
const clearSpecificError = (field: FieldAccessor<any>, message: string) => {
|
|
68
|
+
const errors = field.errors?.errors ?? []
|
|
69
|
+
const error = errors.filter(e => !(e.type === 'validation' && e.message === message))
|
|
70
|
+
field.clearErrors()
|
|
71
|
+
error.forEach(e => field.addError(e))
|
|
72
|
+
}
|
package/src/tsconfig.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../../tsconfig.settings.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"outDir": "../dist/types"
|
|
4
|
+
"outDir": "../dist/types",
|
|
5
|
+
"types": [
|
|
6
|
+
"vite/client"
|
|
7
|
+
]
|
|
5
8
|
},
|
|
6
9
|
"references": [
|
|
7
10
|
{ "path": "../../react-binding/src" },
|
|
8
11
|
{ "path": "../../react-utils/src" },
|
|
9
|
-
{ "path": "../../utilities/src" }
|
|
12
|
+
{ "path": "../../utilities/src" }
|
|
10
13
|
]
|
|
11
14
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorAccessor } from '@contember/react-binding'
|
|
1
2
|
import * as React from 'react'
|
|
2
3
|
|
|
3
4
|
export type FormInputHandler = {
|
|
@@ -5,3 +6,15 @@ export type FormInputHandler = {
|
|
|
5
6
|
formatValue: (value: any) => string
|
|
6
7
|
defaultInputProps?: React.InputHTMLAttributes<HTMLInputElement>
|
|
7
8
|
}
|
|
9
|
+
|
|
10
|
+
export type FormFieldState = {
|
|
11
|
+
htmlId: string
|
|
12
|
+
errors: ErrorAccessor.Error[]
|
|
13
|
+
required: boolean
|
|
14
|
+
dirty: boolean
|
|
15
|
+
field?: {
|
|
16
|
+
entityName: string
|
|
17
|
+
fieldName: string
|
|
18
|
+
enumName?: string
|
|
19
|
+
}
|
|
20
|
+
}
|
package/tsconfig.json
ADDED
package/tsdoc.json
ADDED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormCheckbox.cjs","sources":["../../../src/components/FormCheckbox.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ChangeEventHandler, ReactElement, useCallback, useEffect } from 'react'\nimport { Component, Field, OptionallyVariableFieldValue, SugaredRelativeSingleField, TreeNodeEnvironmentFactory, useField } from '@contember/react-binding'\nimport { useFormError, useFormFieldId } 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 id = useFormFieldId()\n\tconst accessor = useField<boolean>(field)\n\tconst value = accessor.value\n\tconst errors = useFormError() ?? accessor.errors?.errors ?? []\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\t<SlotInput\n\t\t\t\tref={it => {\n\t\t\t\t\t(ref as any).current = checkboxRef\n\t\t\t\t\tsetCheckboxRef(it)\n\t\t\t\t}}\n\t\t\t\ttype=\"checkbox\"\n\t\t\t\tchecked={accessor.value === true}\n\t\t\t\tdata-state={value === null ? 'indeterminate' : (value ? 'checked' : 'unchecked')}\n\t\t\t\tdata-invalid={dataAttribute(errors.length > 0)}\n\t\t\t\tid={`${id}-input`}\n\t\t\t\tonFocus={onFocus}\n\t\t\t\tonBlur={onBlur}\n\t\t\t\tonChange={useCallback<ChangeEventHandler<HTMLInputElement>>(e => {\n\t\t\t\t\taccessorGetter().updateValue(e.target.checked)\n\t\t\t\t}, [accessorGetter])}\n\t\t\t\t{...props}\n\t\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","useFormFieldId","useField","useFormError","useFormInputValidationHandler","React","useEffect","jsxDEV","dataAttribute","useCallback","this","TreeNodeEnvironmentFactory","Field"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,YAAYA,UAAAA;AASL,MAAA,eAAeC,uBAA6B,CAAC,EAAE,OAAO,cAAc,cAAc,GAAG,YAAY;AAC7G,QAAM,KAAKC,SAAAA;AACL,QAAA,WAAWC,sBAAkB,KAAK;AACxC,QAAM,QAAQ,SAAS;AACvB,QAAM,SAASC,SAAAA,aAAa,KAAK,SAAS,QAAQ,UAAU;AAC5D,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;AAG1B,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,UAAA,cAAc,OAAO,SAAS,CAAC;AAAA,MAC7C,IAAI,GAAG,EAAE;AAAA,MACT;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,IAfL;AAAA,IAAA;AAAA,IAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA;AAAA,IAAAC;AAAAA,EAAA;AAkBH,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,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;;"}
|