@contember/create 2.0.0-alpha.26 → 2.0.0-alpha.28
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/package.json +2 -2
- package/resources/templates/template-workspace/admin/lib/datagrid/cells.tsx +24 -10
- package/resources/templates/template-workspace/admin/lib/datagrid/columns.tsx +2 -2
- package/resources/templates/template-workspace/admin/lib/datagrid/filters/enum.tsx +49 -22
- package/resources/templates/template-workspace/admin/lib/form/container.tsx +42 -45
- package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +20 -2
- package/resources/templates/template-workspace/admin/lib/form/select.tsx +10 -3
- package/resources/templates/template-workspace/admin/lib/form/ui.tsx +1 -1
- package/resources/templates/template-workspace/admin/lib/form/upload-repeaters.tsx +43 -46
- package/resources/templates/template-workspace/admin/lib/form/upload.tsx +27 -30
- package/resources/templates/template-workspace/admin/lib/labels/enum-labels.ts +9 -0
- package/resources/templates/template-workspace/admin/lib/labels/field-labels.ts +7 -0
- package/resources/templates/template-workspace/admin/lib/labels/index.ts +2 -0
- package/resources/templates/template-workspace/admin/lib/ui/input.tsx +14 -5
- package/resources/templates/template-workspace/admin/lib/ui/textarea.tsx +9 -1
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/create",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.28",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"bin": "dist/production/run.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@contember/cli-common": "2.0.0-alpha.
|
|
7
|
+
"@contember/cli-common": "2.0.0-alpha.28",
|
|
8
8
|
"chalk": "^5.3.0",
|
|
9
9
|
"fs-extra": "^11.2.0",
|
|
10
10
|
"js-yaml": "^4.1.0"
|
|
@@ -2,7 +2,17 @@ import * as React from 'react'
|
|
|
2
2
|
import { ReactNode } from 'react'
|
|
3
3
|
import { DataGridEnumFieldTooltip, DataGridHasManyTooltip, DataGridHasOneTooltip } from './filters'
|
|
4
4
|
import { DataGridTooltipLabel } from './ui'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Component,
|
|
7
|
+
Field,
|
|
8
|
+
FieldView,
|
|
9
|
+
HasMany,
|
|
10
|
+
HasOne,
|
|
11
|
+
SugaredRelativeEntityList,
|
|
12
|
+
SugaredRelativeSingleEntity,
|
|
13
|
+
SugaredRelativeSingleField,
|
|
14
|
+
} from '@contember/interface'
|
|
15
|
+
import { useEnumOptionsFormatter } from '../labels'
|
|
6
16
|
|
|
7
17
|
export type DataGridHasOneCellProps = {
|
|
8
18
|
field: SugaredRelativeSingleEntity['field']
|
|
@@ -47,18 +57,22 @@ export const DataGridHasManyCell = Component(({ field, filterName, children, too
|
|
|
47
57
|
export type DataGridEnumCellProps = {
|
|
48
58
|
field: SugaredRelativeSingleField['field']
|
|
49
59
|
filterName?: string
|
|
50
|
-
options
|
|
60
|
+
options?: Record<string, ReactNode>
|
|
51
61
|
tooltipActions?: ReactNode
|
|
52
62
|
}
|
|
53
63
|
|
|
54
64
|
export const DataGridEnumCell = Component(({ field, options, filterName, tooltipActions }: DataGridEnumCellProps) => {
|
|
65
|
+
const enumOptionsProvider = useEnumOptionsFormatter()
|
|
55
66
|
return (
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
<FieldView<string> field={field} render={it => {
|
|
68
|
+
const resolvedOptions = options ?? enumOptionsProvider(it.schema.enumName!)
|
|
69
|
+
return it.value ? (
|
|
70
|
+
<DataGridEnumFieldTooltip value={it.value} field={field} name={filterName} actions={tooltipActions}>
|
|
71
|
+
<DataGridTooltipLabel>
|
|
72
|
+
{resolvedOptions[it.value]}
|
|
73
|
+
</DataGridTooltipLabel>
|
|
74
|
+
</DataGridEnumFieldTooltip>
|
|
75
|
+
) : null
|
|
76
|
+
}} />
|
|
63
77
|
)
|
|
64
|
-
})
|
|
78
|
+
}, ({ field }) => <Field field={field} />, 'DataGridEnumCell')
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
DataViewTextFilter,
|
|
16
16
|
} from '@contember/react-dataview'
|
|
17
17
|
import { formatBoolean, formatDate, formatDateTime, formatNumber } from '../formatting'
|
|
18
|
-
import { DataGridEnumCell, DataGridHasManyCell,
|
|
18
|
+
import { DataGridEnumCell, DataGridHasManyCell, DataGridHasOneCell } from './cells'
|
|
19
19
|
import { cn } from '../utils'
|
|
20
20
|
import {
|
|
21
21
|
DataGridBooleanFilterControls,
|
|
@@ -155,7 +155,7 @@ export const DataGridDateTimeColumn = Component<DataGridDateTimeColumnProps>(({
|
|
|
155
155
|
export type DataGridEnumColumnProps = {
|
|
156
156
|
field: string
|
|
157
157
|
header: ReactNode
|
|
158
|
-
options
|
|
158
|
+
options?: Record<string, ReactNode>
|
|
159
159
|
children?: ReactNode
|
|
160
160
|
filter?: ReactNode
|
|
161
161
|
tooltipActions?: ReactNode
|
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { ReactNode, useCallback } from 'react'
|
|
3
3
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../ui/tooltip'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
DataViewEnumFilter,
|
|
6
|
+
DataViewEnumFilterProps,
|
|
7
|
+
DataViewEnumFilterTrigger,
|
|
8
|
+
DataViewNullFilterTrigger,
|
|
9
|
+
UseDataViewEnumFilter,
|
|
10
|
+
useDataViewEnumFilterArgs,
|
|
11
|
+
useDataViewEnumFilterFactory,
|
|
12
|
+
useDataViewFilterName,
|
|
13
|
+
} from '@contember/react-dataview'
|
|
5
14
|
import { Component } from '@contember/interface'
|
|
6
15
|
import { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover'
|
|
7
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
DataGridActiveFilterUI,
|
|
18
|
+
DataGridExcludeActionButtonUI,
|
|
19
|
+
DataGridFilterActionButtonUI,
|
|
20
|
+
DataGridFilterSelectItemUI,
|
|
21
|
+
DataGridFilterSelectTriggerUI,
|
|
22
|
+
DataGridSingleFilterUI,
|
|
23
|
+
} from '../ui'
|
|
8
24
|
import { DataGridNullFilter } from './common'
|
|
9
25
|
import { dict } from '../../dict'
|
|
10
26
|
import { DataGridFilterMobileHiding } from './mobile'
|
|
27
|
+
import { useEnumOptionsFormatter } from '../../labels'
|
|
11
28
|
|
|
12
29
|
export type DataGridEnumFilterProps =
|
|
13
30
|
& Omit<DataViewEnumFilterProps, 'children'>
|
|
14
31
|
& {
|
|
15
|
-
options
|
|
32
|
+
options?: Record<string, ReactNode>
|
|
16
33
|
label?: ReactNode
|
|
17
34
|
}
|
|
18
35
|
|
|
@@ -53,24 +70,27 @@ export const DataGridEnumFieldTooltip = ({ children, actions, value, ...props }:
|
|
|
53
70
|
|
|
54
71
|
|
|
55
72
|
export const DataGridEnumFilterList = ({ options }: {
|
|
56
|
-
options
|
|
57
|
-
}) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
73
|
+
options?: Record<string, ReactNode>
|
|
74
|
+
}) => {
|
|
75
|
+
const resolvedOptions = useEnumOptions(options)
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
{Object.entries(resolvedOptions).map(([value, label]) => (
|
|
79
|
+
<DataViewEnumFilterTrigger action={'unset'} value={value} key={value}>
|
|
80
|
+
<DataGridActiveFilterUI>
|
|
81
|
+
{label}
|
|
82
|
+
</DataGridActiveFilterUI>
|
|
83
|
+
</DataViewEnumFilterTrigger>
|
|
84
|
+
))}
|
|
85
|
+
|
|
86
|
+
<DataViewNullFilterTrigger action={'unset'}>
|
|
61
87
|
<DataGridActiveFilterUI>
|
|
62
|
-
{
|
|
88
|
+
<span className={'italic'}>{dict.datagrid.na}</span>
|
|
63
89
|
</DataGridActiveFilterUI>
|
|
64
|
-
</
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
<DataGridActiveFilterUI>
|
|
69
|
-
<span className={'italic'}>{dict.datagrid.na}</span>
|
|
70
|
-
</DataGridActiveFilterUI>
|
|
71
|
-
</DataViewNullFilterTrigger>
|
|
72
|
-
</>
|
|
73
|
-
)
|
|
90
|
+
</DataViewNullFilterTrigger>
|
|
91
|
+
</>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
74
94
|
const DataGridEnumFilterSelectItem = ({ value, children, filterFactory }: {
|
|
75
95
|
value: string
|
|
76
96
|
children: ReactNode
|
|
@@ -91,7 +111,7 @@ const DataGridEnumFilterSelectItem = ({ value, children, filterFactory }: {
|
|
|
91
111
|
|
|
92
112
|
}
|
|
93
113
|
export const DataGridEnumFilterSelect = ({ options, label }: {
|
|
94
|
-
options
|
|
114
|
+
options?: Record<string, ReactNode>
|
|
95
115
|
label?: ReactNode
|
|
96
116
|
}) => {
|
|
97
117
|
return (
|
|
@@ -107,12 +127,13 @@ export const DataGridEnumFilterSelect = ({ options, label }: {
|
|
|
107
127
|
}
|
|
108
128
|
|
|
109
129
|
export const DataGridEnumFilterControls = ({ options }: {
|
|
110
|
-
options
|
|
130
|
+
options?: Record<string, ReactNode>
|
|
111
131
|
}) => {
|
|
112
132
|
const filterFactory = useDataViewEnumFilterFactory(useDataViewFilterName())
|
|
133
|
+
const resolvedOptions = useEnumOptions(options)
|
|
113
134
|
return (
|
|
114
135
|
<div className={'relative flex flex-col gap-2'}>
|
|
115
|
-
{Object.entries(
|
|
136
|
+
{Object.entries(resolvedOptions).map(([value, label]) => (
|
|
116
137
|
<DataGridEnumFilterSelectItem value={value} key={value} filterFactory={filterFactory}>
|
|
117
138
|
{label}
|
|
118
139
|
</DataGridEnumFilterSelectItem>
|
|
@@ -121,3 +142,9 @@ export const DataGridEnumFilterControls = ({ options }: {
|
|
|
121
142
|
</div>
|
|
122
143
|
)
|
|
123
144
|
}
|
|
145
|
+
|
|
146
|
+
const useEnumOptions = (preferred: Record<string, ReactNode> | undefined): Record<string, ReactNode> => {
|
|
147
|
+
const enumOptionsProvider = useEnumOptionsFormatter()
|
|
148
|
+
const enumName = useDataViewEnumFilterArgs().enumName
|
|
149
|
+
return preferred ?? enumOptionsProvider(enumName)
|
|
150
|
+
}
|
|
@@ -2,63 +2,60 @@ import * as React from 'react'
|
|
|
2
2
|
import { ReactNode } from 'react'
|
|
3
3
|
import { FormContainerUI, FormDescriptionUI, FormErrorUI, FormLabelUI, FormLabelWrapperUI } from './ui'
|
|
4
4
|
import { useErrorFormatter } from '../errors'
|
|
5
|
-
import { Component } from '@contember/interface'
|
|
6
|
-
import { FormError, FormLabel } from '@contember/react-form'
|
|
5
|
+
import { Component, ErrorAccessor } from '@contember/interface'
|
|
6
|
+
import { FormError, FormFieldStateProvider, FormLabel, useFormFieldState } from '@contember/react-form'
|
|
7
|
+
import { useFieldLabelFormatter } from '../labels'
|
|
7
8
|
|
|
8
9
|
export interface FormContainerProps {
|
|
9
10
|
label?: ReactNode
|
|
10
11
|
description?: ReactNode
|
|
11
12
|
children: ReactNode
|
|
12
|
-
errors?: ReactNode
|
|
13
|
+
errors?: ErrorAccessor.Error[] | ReactNode
|
|
13
14
|
required?: boolean
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
|
|
17
|
-
export const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
</FormLabelUI>
|
|
24
|
-
}
|
|
25
|
-
</FormLabelWrapperUI>
|
|
26
|
-
<div>
|
|
27
|
-
{children}
|
|
28
|
-
</div>
|
|
29
|
-
<div>
|
|
30
|
-
{description && <FormDescriptionUI>
|
|
31
|
-
{description}
|
|
32
|
-
</FormDescriptionUI>}
|
|
33
|
-
{errors}
|
|
34
|
-
</div>
|
|
35
|
-
</FormContainerUI>
|
|
36
|
-
)
|
|
18
|
+
export const FormContainer = Component(({ children, description, label, required, errors }: FormContainerProps) => {
|
|
19
|
+
const errorsNode = Array.isArray(errors) ? undefined : errors
|
|
20
|
+
const errorsList = Array.isArray(errors) ? errors : []
|
|
21
|
+
const state = useFormFieldState()
|
|
22
|
+
const fieldLabelFormatter = useFieldLabelFormatter()
|
|
23
|
+
label ??= state?.field ? fieldLabelFormatter(state.field.entityName, state.field.fieldName) : undefined
|
|
37
24
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
25
|
+
const inner = <>
|
|
26
|
+
<FormContainerUI>
|
|
27
|
+
<FormLabelWrapperUI>
|
|
28
|
+
{label && <FormLabel>
|
|
29
|
+
<FormLabelUI required={required}>
|
|
30
|
+
{label}
|
|
31
|
+
</FormLabelUI>
|
|
32
|
+
</FormLabel>}
|
|
33
|
+
</FormLabelWrapperUI>
|
|
34
|
+
<div>
|
|
35
|
+
{children}
|
|
36
|
+
</div>
|
|
37
|
+
<div>
|
|
38
|
+
{description && <FormDescriptionUI>
|
|
39
|
+
{description}
|
|
40
|
+
</FormDescriptionUI>}
|
|
54
41
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
<FormError formatter={useErrorFormatter()}>
|
|
43
|
+
<FormErrorUI />
|
|
44
|
+
</FormError>
|
|
45
|
+
{errorsNode}
|
|
46
|
+
</div>
|
|
47
|
+
</FormContainerUI>
|
|
48
|
+
</>
|
|
49
|
+
return state !== undefined
|
|
50
|
+
? inner
|
|
51
|
+
: <FormFieldStateProvider required={required} errors={errorsList} dirty={false}>{inner}</FormFieldStateProvider>
|
|
52
|
+
}, ({ children, label, description }) => <>
|
|
61
53
|
{label}
|
|
62
54
|
{children}
|
|
63
55
|
{description}
|
|
64
56
|
</>)
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated use `FormContainer` instead
|
|
60
|
+
*/
|
|
61
|
+
export const StandaloneFormContainer = FormContainer
|
|
@@ -4,9 +4,20 @@ import { CheckboxInput, Input, RadioInput } from '../ui/input'
|
|
|
4
4
|
import { cn } from '../utils'
|
|
5
5
|
import { TextareaAutosize } from '../ui/textarea'
|
|
6
6
|
import { FormLabelUI } from './ui'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
FormCheckbox,
|
|
9
|
+
FormCheckboxProps,
|
|
10
|
+
FormFieldScope,
|
|
11
|
+
FormInput,
|
|
12
|
+
FormInputProps,
|
|
13
|
+
FormLabel,
|
|
14
|
+
FormRadioInput,
|
|
15
|
+
FormRadioItemProps,
|
|
16
|
+
useFormFieldState,
|
|
17
|
+
} from '@contember/react-form'
|
|
8
18
|
import { FormContainer, FormContainerProps } from './container'
|
|
9
19
|
import { Component, Field } from '@contember/interface'
|
|
20
|
+
import { useEnumOptionsFormatter } from '../labels'
|
|
10
21
|
|
|
11
22
|
|
|
12
23
|
export type InputFieldProps =
|
|
@@ -77,7 +88,7 @@ export type RadioEnumFieldProps =
|
|
|
77
88
|
& Omit<FormContainerProps, 'children'>
|
|
78
89
|
& {
|
|
79
90
|
required?: boolean
|
|
80
|
-
options
|
|
91
|
+
options?: Record<string, ReactNode> | Array<{ value: null | string | number | boolean; label: React.ReactNode }>
|
|
81
92
|
orientation?: 'horizontal' | 'vertical'
|
|
82
93
|
inputProps?: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'defaultValue'>
|
|
83
94
|
}
|
|
@@ -95,6 +106,13 @@ export const RadioEnumField = Component<RadioEnumFieldProps>(({ field, label, de
|
|
|
95
106
|
type RadioEnumFieldInnerProps = Pick<RadioEnumFieldProps, 'field' | 'options' | 'orientation' | 'inputProps' | 'defaultValue' | 'isNonbearing' | 'required'>
|
|
96
107
|
|
|
97
108
|
const RadioEnumFieldInner: React.FC<RadioEnumFieldInnerProps> = ({ field, inputProps, isNonbearing, required, options, orientation, defaultValue }) => {
|
|
109
|
+
const enumLabelsFormatter = useEnumOptionsFormatter()
|
|
110
|
+
const enumName = useFormFieldState()?.field?.enumName
|
|
111
|
+
options ??= enumName ? enumLabelsFormatter(enumName) : undefined
|
|
112
|
+
if (!options) {
|
|
113
|
+
throw new Error('RadioEnumField: options are required')
|
|
114
|
+
}
|
|
115
|
+
|
|
98
116
|
const normalizedOptions = React.useMemo(() => {
|
|
99
117
|
return Array.isArray(options) ? options : Object.entries(options).map(([value, label]) => ({ value, label }))
|
|
100
118
|
}, [options])
|
|
@@ -15,12 +15,12 @@ import {
|
|
|
15
15
|
import * as React from 'react'
|
|
16
16
|
import { useCallback, useMemo } from 'react'
|
|
17
17
|
import { FormContainer, FormContainerProps } from './container'
|
|
18
|
-
import { FormFieldScope, FormHasManyRelationScope, FormHasOneRelationScope, useFormFieldId } from '@contember/react-form'
|
|
18
|
+
import { FormFieldScope, FormHasManyRelationScope, FormHasOneRelationScope, useFormFieldId, useFormFieldState } from '@contember/react-form'
|
|
19
19
|
import { Component, Field, RecursionTerminator, SugaredRelativeSingleField, useEntityBeforePersist, useField } from '@contember/interface'
|
|
20
20
|
import { Popover, PopoverTrigger } from '../ui/popover'
|
|
21
21
|
import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
|
|
22
22
|
import { dict } from '../dict'
|
|
23
|
-
|
|
23
|
+
import { useEnumOptionsFormatter } from '../labels'
|
|
24
24
|
|
|
25
25
|
export type SelectFieldProps =
|
|
26
26
|
& SelectInputProps
|
|
@@ -78,7 +78,7 @@ export type SelectEnumFieldProps =
|
|
|
78
78
|
& Omit<FormContainerProps, 'children'>
|
|
79
79
|
& {
|
|
80
80
|
field: SugaredRelativeSingleField['field']
|
|
81
|
-
options
|
|
81
|
+
options?: Record<string, React.ReactNode> | { value: null | string | number | boolean; label: React.ReactNode }[]
|
|
82
82
|
placeholder?: React.ReactNode
|
|
83
83
|
defaultValue?: string
|
|
84
84
|
required?: boolean
|
|
@@ -112,6 +112,12 @@ const SelectEnumFieldInner = ({ field, options, placeholder, required }: SelectE
|
|
|
112
112
|
}
|
|
113
113
|
}, [fieldAccessorGetter, required]))
|
|
114
114
|
const id = useFormFieldId()
|
|
115
|
+
const enumLabelsFormatter = useEnumOptionsFormatter()
|
|
116
|
+
const enumName = useFormFieldState()?.field?.enumName
|
|
117
|
+
options ??= enumName ? enumLabelsFormatter(enumName) : undefined
|
|
118
|
+
if (!options) {
|
|
119
|
+
throw new Error('SelectEnumFields: options are required')
|
|
120
|
+
}
|
|
115
121
|
const normalizedOptions = useMemo(() => {
|
|
116
122
|
return Array.isArray(options) ? options : Object.entries(options).map(([value, label]) => ({ value, label }))
|
|
117
123
|
}, [options])
|
|
@@ -119,6 +125,7 @@ const SelectEnumFieldInner = ({ field, options, placeholder, required }: SelectE
|
|
|
119
125
|
return normalizedOptions.find(it => it.value === fieldAccessor.value)
|
|
120
126
|
}, [fieldAccessor.value, normalizedOptions])
|
|
121
127
|
|
|
128
|
+
|
|
122
129
|
return (
|
|
123
130
|
<Popover open={open} onOpenChange={setOpen}>
|
|
124
131
|
<SelectInputWrapperUI>
|
|
@@ -20,7 +20,7 @@ export const FormLabelWrapperUI = uic('div', {
|
|
|
20
20
|
displayName: 'FormLabelWrapper',
|
|
21
21
|
})
|
|
22
22
|
export const FormLabelUI = uic(Label, {
|
|
23
|
-
baseClass: 'text-left',
|
|
23
|
+
baseClass: 'text-left data-[required]:after:text-destructive data-[required]:after:content-[attr(data-required-content)] after:ml-1',
|
|
24
24
|
displayName: 'FormLabel',
|
|
25
25
|
variants: {
|
|
26
26
|
required: {
|
|
@@ -17,7 +17,7 @@ import * as React from 'react'
|
|
|
17
17
|
import { ReactNode, useId, useMemo, useState } from 'react'
|
|
18
18
|
import { FormContainer, FormContainerProps } from './container'
|
|
19
19
|
import { Component } from '@contember/interface'
|
|
20
|
-
import { FormErrorContext, FormFieldIdContext } from '@contember/react-form'
|
|
20
|
+
import { FormErrorContext, FormFieldIdContext, FormFieldStateProvider } from '@contember/react-form'
|
|
21
21
|
import {
|
|
22
22
|
UploadedAnyView,
|
|
23
23
|
UploadedAudioView,
|
|
@@ -134,52 +134,49 @@ const FileRepeaterFieldInner = Component<FileRepeaterFieldInnerProps>(({
|
|
|
134
134
|
// entity,
|
|
135
135
|
// }) ?? []).flatMap(it => it.errors?.errors ?? [])
|
|
136
136
|
|
|
137
|
-
const id = useId()
|
|
138
137
|
return (
|
|
139
|
-
<
|
|
140
|
-
<
|
|
141
|
-
<
|
|
142
|
-
<
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
<
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
<
|
|
155
|
-
<
|
|
156
|
-
|
|
157
|
-
<
|
|
158
|
-
<
|
|
159
|
-
<
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
<
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
</FormErrorContext.Provider>
|
|
182
|
-
</FormFieldIdContext.Provider>
|
|
138
|
+
<FormFieldStateProvider>
|
|
139
|
+
<FormContainer description={description} label={label}>
|
|
140
|
+
<Repeater {...props} initialEntityCount={0}>
|
|
141
|
+
<UploaderRepeaterItemsWrapperUI>
|
|
142
|
+
|
|
143
|
+
<MultiUploader baseField={baseField} fileType={fileTypeWithUploader}>
|
|
144
|
+
<UploaderHasFile>
|
|
145
|
+
<UploaderProgress />
|
|
146
|
+
</UploaderHasFile>
|
|
147
|
+
<UploaderDropzone dropzonePlaceholder={dropzonePlaceholder} />
|
|
148
|
+
</MultiUploader>
|
|
149
|
+
|
|
150
|
+
<RepeaterSortable>
|
|
151
|
+
|
|
152
|
+
<RepeaterSortableEachItem>
|
|
153
|
+
<div className="flex">
|
|
154
|
+
<UploaderRepeaterDropIndicator position={'before'} />
|
|
155
|
+
<RepeaterSortableItemNode>
|
|
156
|
+
<UploaderRepeaterItemUI>
|
|
157
|
+
<RepeaterSortableItemActivator>
|
|
158
|
+
<UploaderRepeaterHandleUI />
|
|
159
|
+
</RepeaterSortableItemActivator>
|
|
160
|
+
{children}
|
|
161
|
+
</UploaderRepeaterItemUI>
|
|
162
|
+
</RepeaterSortableItemNode>
|
|
163
|
+
<UploaderRepeaterDropIndicator position={'after'} />
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
</RepeaterSortableEachItem>
|
|
168
|
+
|
|
169
|
+
<RepeaterSortableDragOverlay>
|
|
170
|
+
<UploaderRepeaterDragOverlayUI>
|
|
171
|
+
{children}
|
|
172
|
+
</UploaderRepeaterDragOverlayUI>
|
|
173
|
+
</RepeaterSortableDragOverlay>
|
|
174
|
+
|
|
175
|
+
</RepeaterSortable>
|
|
176
|
+
</UploaderRepeaterItemsWrapperUI>
|
|
177
|
+
</Repeater>
|
|
178
|
+
</FormContainer>
|
|
179
|
+
</FormFieldStateProvider>
|
|
183
180
|
)
|
|
184
181
|
}, ({ baseField, label, description, children, fileType, ...props }) => {
|
|
185
182
|
return <>
|
|
@@ -16,10 +16,10 @@ import {
|
|
|
16
16
|
VideoFileTypeProps,
|
|
17
17
|
} from '@contember/react-uploader'
|
|
18
18
|
import * as React from 'react'
|
|
19
|
-
import { ReactNode,
|
|
19
|
+
import { ReactNode, useMemo, useState } from 'react'
|
|
20
20
|
import { FormContainer, FormContainerProps } from './container'
|
|
21
21
|
import { Component, DisconnectEntityTrigger, EntityView, useEntity } from '@contember/interface'
|
|
22
|
-
import {
|
|
22
|
+
import { FormFieldStateProvider } from '@contember/react-form'
|
|
23
23
|
import { UploadedAnyView, UploadedAudioView, UploadedImageView, UploadedVideoView, UploaderDropzone, UploaderItemUI } from '../upload'
|
|
24
24
|
import { UploaderProgress } from '../upload/upload-progress'
|
|
25
25
|
|
|
@@ -106,35 +106,32 @@ const UploadFieldInner = Component((({ baseField, label, description, children,
|
|
|
106
106
|
// entity,
|
|
107
107
|
// }) ?? []).flatMap(it => it.errors?.errors ?? [])
|
|
108
108
|
|
|
109
|
-
const id = useId()
|
|
110
109
|
return (
|
|
111
|
-
<
|
|
112
|
-
<
|
|
113
|
-
<
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
<
|
|
117
|
-
<
|
|
118
|
-
<
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
<
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
</FormErrorContext.Provider>
|
|
137
|
-
</FormFieldIdContext.Provider>
|
|
110
|
+
<FormFieldStateProvider>
|
|
111
|
+
<FormContainer description={description} label={label}>
|
|
112
|
+
<div className="flex">
|
|
113
|
+
|
|
114
|
+
<Uploader baseField={baseField} fileType={fileTypeWithUploader}>
|
|
115
|
+
<UploaderBase baseField={baseField}>
|
|
116
|
+
<UploaderHasFile>
|
|
117
|
+
<UploaderProgress />
|
|
118
|
+
</UploaderHasFile>
|
|
119
|
+
</UploaderBase>
|
|
120
|
+
|
|
121
|
+
<UploaderItemUI>
|
|
122
|
+
<EntityView render={entity => {
|
|
123
|
+
entity = baseField ? entity.getEntity({ field: baseField }) : entity
|
|
124
|
+
if (entity.getField(urlField).value === null) {
|
|
125
|
+
return <UploaderDropzone inactiveOnUpload dropzonePlaceholder={dropzonePlaceholder} />
|
|
126
|
+
} else {
|
|
127
|
+
return children
|
|
128
|
+
}
|
|
129
|
+
}} />
|
|
130
|
+
</UploaderItemUI>
|
|
131
|
+
</Uploader>
|
|
132
|
+
</div>
|
|
133
|
+
</FormContainer>
|
|
134
|
+
</FormFieldStateProvider>
|
|
138
135
|
)
|
|
139
136
|
}), ({ fileType, children, baseField }) => {
|
|
140
137
|
return <>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SugaredRelativeSingleField, TreeNodeEnvironmentFactory, useEnvironment } from '@contember/interface'
|
|
2
|
+
import { createContext } from '@contember/react-utils'
|
|
3
|
+
import { ReactNode, useMemo } from 'react'
|
|
4
|
+
|
|
5
|
+
export type EnumOptionsFormatter = (enumName: string) => Record<string, ReactNode>
|
|
6
|
+
|
|
7
|
+
export const [, useEnumOptionsFormatter, EnumOptionsFormatterProvider] = createContext<EnumOptionsFormatter>('EnumOptionsFormatterContext', enumName => {
|
|
8
|
+
throw new Error('EnumOptionsFormatterProvider is not provided')
|
|
9
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createContext } from '@contember/react-utils'
|
|
2
|
+
import { ReactNode } from 'react'
|
|
3
|
+
|
|
4
|
+
export type FieldLabelFormatter = (entityName: string, fieldName: string) => ReactNode | null
|
|
5
|
+
|
|
6
|
+
export const [, useFieldLabelFormatter, FieldLabelFormatterProvider] = createContext<FieldLabelFormatter>('FieldLabelContext', (entityName, fieldName) => null)
|
|
7
|
+
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import { uic, uiconfig } from '../utils'
|
|
2
2
|
|
|
3
3
|
export const inputConfig = uiconfig({
|
|
4
|
-
baseClass:
|
|
4
|
+
baseClass: `
|
|
5
|
+
flex w-full bg-background
|
|
6
|
+
file:border-0 file:bg-transparent file:text-sm file:font-medium
|
|
7
|
+
placeholder:text-muted-foreground
|
|
8
|
+
focus-visible:outline-none
|
|
9
|
+
disabled:cursor-not-allowed disabled:opacity-50
|
|
10
|
+
read-only:bg-gray-100
|
|
11
|
+
` /*data-[dirty]:border-yellow-500 focus-visible:data-[dirty]:border-input*/ + `
|
|
12
|
+
data-[invalid]:border-destructive data-[invalid]:ring-destructive
|
|
13
|
+
`,
|
|
5
14
|
variants: {
|
|
6
|
-
variant: {
|
|
7
|
-
default: 'border border-input ring-offset-background focus-visible:ring-2 focus-visible:ring-ring',
|
|
8
|
-
ghost: 'border-none focus-visible:ring-transparent',
|
|
9
|
-
},
|
|
10
15
|
inputSize: {
|
|
11
16
|
default: 'h-10 rounded-md p-2 text-sm',
|
|
12
17
|
sm: 'h-8 rounded p-1 text-sm',
|
|
13
18
|
lg: 'h-12 rounded-lg p-3 text-lg',
|
|
14
19
|
},
|
|
20
|
+
variant: {
|
|
21
|
+
default: 'border border-input ring-offset-background focus-visible:ring-2 focus-visible:ring-ring',
|
|
22
|
+
ghost: 'border-transparent border-b focus-visible:ring-transparent rounded-none',
|
|
23
|
+
},
|
|
15
24
|
},
|
|
16
25
|
defaultVariants: {
|
|
17
26
|
variant: 'default',
|
|
@@ -3,7 +3,15 @@ import { uic } from '../utils'
|
|
|
3
3
|
import { ComponentProps, forwardRef, useRef } from 'react'
|
|
4
4
|
|
|
5
5
|
export const Textarea = uic('textarea', {
|
|
6
|
-
baseClass:
|
|
6
|
+
baseClass: `
|
|
7
|
+
w-full bg-background rounded-md border border-input px-3 py-2 text-sm shadow-sm
|
|
8
|
+
placeholder:text-muted-foreground
|
|
9
|
+
focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring
|
|
10
|
+
disabled:cursor-not-allowed disabled:opacity-50
|
|
11
|
+
read-only:bg-gray-100
|
|
12
|
+
` /*data-[dirty]:border-yellow-500 focus-visible:data-[dirty]:border-input*/ + `
|
|
13
|
+
data-[invalid]:border-destructive data-[invalid]:ring-destructive
|
|
14
|
+
`,
|
|
7
15
|
displayName: 'Textarea',
|
|
8
16
|
})
|
|
9
17
|
|