@chobantonov/jsonforms-react-shadcn-renderers 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +157 -2
- package/lib/additional/LabelRenderer.d.ts +4 -0
- package/lib/additional/index.d.ts +1 -0
- package/lib/cells/BooleanCell.d.ts +3 -0
- package/lib/cells/Cell.d.ts +3 -0
- package/lib/cells/CompositeCell.d.ts +9 -0
- package/lib/cells/CompositeDetailDialog.d.ts +3 -0
- package/lib/cells/EnumCell.d.ts +3 -0
- package/lib/cells/NumberCell.d.ts +3 -0
- package/lib/cells/NumberFormatCell.d.ts +4 -0
- package/lib/cells/TextCell.d.ts +3 -0
- package/lib/cells/asCell.d.ts +12 -0
- package/lib/cells/index.d.ts +7 -0
- package/lib/complex/AdditionalProperties.d.ts +4 -0
- package/lib/complex/AnyOfRenderer.d.ts +7 -0
- package/lib/complex/ArrayChoicesControl.d.ts +6 -0
- package/lib/complex/ArrayControlRenderer.d.ts +4 -0
- package/lib/complex/ArrayPanelToggle.d.ts +6 -0
- package/lib/complex/CollectionPager.d.ts +5 -0
- package/lib/complex/CombinatorSwitchDialog.d.ts +8 -0
- package/lib/complex/DeleteDialog.d.ts +6 -0
- package/lib/complex/DetailDialogContent.d.ts +7 -0
- package/lib/complex/ErrorIndicator.d.ts +7 -0
- package/lib/complex/MixedRenderer.d.ts +6 -0
- package/lib/complex/ObjectRenderer.d.ts +3 -0
- package/lib/complex/OneOfRenderer.d.ts +5 -0
- package/lib/complex/RecursiveTreeRenderer.d.ts +4 -0
- package/lib/complex/RowDetailFrame.d.ts +16 -0
- package/lib/complex/ScalarCompositionRenderer.d.ts +4 -0
- package/lib/complex/TupleAdditionalItems.d.ts +4 -0
- package/lib/complex/TupleControlRenderer.d.ts +6 -0
- package/lib/complex/TupleField.d.ts +4 -0
- package/lib/complex/array/ArrayItemPanels.d.ts +18 -0
- package/lib/complex/array/ArrayItemViewProps.d.ts +11 -0
- package/lib/complex/array/ArrayListDetail.d.ts +9 -0
- package/lib/complex/array/ArrayTable.d.ts +21 -0
- package/lib/complex/index.d.ts +10 -0
- package/lib/complex/mixed/JsonTypeIcon.d.ts +5 -0
- package/lib/complex/mixed/MixedWidgets.d.ts +22 -0
- package/lib/complex/mixed/useConfirmation.d.ts +6 -0
- package/lib/components/ClearValueButton.d.ts +12 -0
- package/lib/components/ScrollRegion.d.ts +4 -0
- package/lib/components/TimePicker.d.ts +13 -0
- package/lib/components/index.d.ts +2 -0
- package/lib/controls/AnyOfStringOrEnumControl.d.ts +4 -0
- package/lib/controls/BooleanControl.d.ts +4 -0
- package/lib/controls/BooleanToggleControl.d.ts +4 -0
- package/lib/controls/ChoiceCards.d.ts +1 -0
- package/lib/controls/DateControl.d.ts +4 -0
- package/lib/controls/DateTimeControl.d.ts +4 -0
- package/lib/controls/EnumControl.d.ts +5 -0
- package/lib/controls/InputControl.d.ts +30 -0
- package/lib/controls/IntegerControl.d.ts +4 -0
- package/lib/controls/NumberControl.d.ts +4 -0
- package/lib/controls/OneOfEnumControl.d.ts +3 -0
- package/lib/controls/PasswordControl.d.ts +9 -0
- package/lib/controls/RadioGroupControl.d.ts +4 -0
- package/lib/controls/SliderControl.d.ts +4 -0
- package/lib/controls/TextControl.d.ts +4 -0
- package/lib/controls/TimeControl.d.ts +4 -0
- package/lib/controls/index.d.ts +15 -0
- package/lib/index.d.ts +6 -0
- package/lib/jsonforms-react-shadcn.cjs.js +3 -0
- package/lib/jsonforms-react-shadcn.cjs.js.map +1 -0
- package/lib/jsonforms-react-shadcn.esm.js +4040 -0
- package/lib/jsonforms-react-shadcn.esm.js.map +1 -0
- package/lib/layouts/CategorizationLayout.d.ts +7 -0
- package/lib/layouts/GroupLayout.d.ts +4 -0
- package/lib/layouts/HorizontalLayout.d.ts +4 -0
- package/lib/layouts/Layout.d.ts +5 -0
- package/lib/layouts/ValidationIndicator.d.ts +4 -0
- package/lib/layouts/VerticalLayout.d.ts +4 -0
- package/lib/layouts/index.d.ts +4 -0
- package/lib/renderers.d.ts +8 -0
- package/lib/util/dateTime.d.ts +12 -0
- package/lib/util/groupState.d.ts +1 -0
- package/lib/util/useTemporalControl.d.ts +28 -0
- package/package.json +86 -3
- package/src/additional/LabelRenderer.tsx +8 -0
- package/src/additional/index.ts +1 -0
- package/src/cells/BooleanCell.tsx +26 -0
- package/src/cells/Cell.tsx +101 -0
- package/src/cells/CompositeCell.tsx +275 -0
- package/src/cells/CompositeDetailDialog.tsx +79 -0
- package/src/cells/EnumCell.tsx +74 -0
- package/src/cells/NumberCell.tsx +51 -0
- package/src/cells/NumberFormatCell.tsx +47 -0
- package/src/cells/TextCell.tsx +40 -0
- package/src/cells/asCell.tsx +79 -0
- package/src/cells/index.ts +7 -0
- package/src/complex/AdditionalProperties.tsx +453 -0
- package/src/complex/AnyOfRenderer.tsx +341 -0
- package/src/complex/ArrayChoicesControl.tsx +303 -0
- package/src/complex/ArrayControlRenderer.tsx +400 -0
- package/src/complex/ArrayPanelToggle.tsx +33 -0
- package/src/complex/CollectionPager.tsx +76 -0
- package/src/complex/CombinatorSwitchDialog.tsx +43 -0
- package/src/complex/DeleteDialog.tsx +41 -0
- package/src/complex/DetailDialogContent.tsx +84 -0
- package/src/complex/ErrorIndicator.tsx +136 -0
- package/src/complex/MixedRenderer.tsx +262 -0
- package/src/complex/ObjectRenderer.tsx +43 -0
- package/src/complex/OneOfRenderer.tsx +14 -0
- package/src/complex/RecursiveTreeRenderer.tsx +20 -0
- package/src/complex/RowDetailFrame.tsx +158 -0
- package/src/complex/ScalarCompositionRenderer.tsx +14 -0
- package/src/complex/TupleAdditionalItems.tsx +94 -0
- package/src/complex/TupleControlRenderer.tsx +54 -0
- package/src/complex/TupleField.tsx +41 -0
- package/src/complex/array/ArrayItemPanels.tsx +217 -0
- package/src/complex/array/ArrayItemViewProps.ts +15 -0
- package/src/complex/array/ArrayListDetail.tsx +165 -0
- package/src/complex/array/ArrayTable.tsx +535 -0
- package/src/complex/index.ts +16 -0
- package/src/complex/mixed/JsonTypeIcon.tsx +41 -0
- package/src/complex/mixed/MixedWidgets.tsx +326 -0
- package/src/complex/mixed/useConfirmation.tsx +34 -0
- package/src/components/ClearValueButton.tsx +56 -0
- package/src/components/ScrollRegion.tsx +27 -0
- package/src/components/TimePicker.tsx +250 -0
- package/src/components/index.ts +2 -0
- package/src/controls/AnyOfStringOrEnumControl.tsx +44 -0
- package/src/controls/BooleanControl.tsx +67 -0
- package/src/controls/BooleanToggleControl.tsx +58 -0
- package/src/controls/ChoiceCards.tsx +9 -0
- package/src/controls/DateControl.tsx +240 -0
- package/src/controls/DateTimeControl.tsx +187 -0
- package/src/controls/EnumControl.tsx +159 -0
- package/src/controls/InputControl.tsx +258 -0
- package/src/controls/IntegerControl.tsx +14 -0
- package/src/controls/NumberControl.tsx +14 -0
- package/src/controls/OneOfEnumControl.tsx +13 -0
- package/src/controls/PasswordControl.tsx +216 -0
- package/src/controls/RadioGroupControl.tsx +72 -0
- package/src/controls/SliderControl.tsx +77 -0
- package/src/controls/TextControl.tsx +50 -0
- package/src/controls/TimeControl.tsx +135 -0
- package/src/controls/index.ts +19 -0
- package/src/index.tsx +10 -0
- package/src/layouts/CategorizationLayout.tsx +248 -0
- package/src/layouts/GroupLayout.tsx +210 -0
- package/src/layouts/HorizontalLayout.tsx +12 -0
- package/src/layouts/Layout.tsx +62 -0
- package/src/layouts/ValidationIndicator.tsx +40 -0
- package/src/layouts/VerticalLayout.tsx +12 -0
- package/src/layouts/index.ts +4 -0
- package/src/renderers.ts +225 -0
- package/src/styles.css +482 -0
- package/src/tailwind-theme.cjs +42 -0
- package/src/theme.css +43 -0
- package/src/util/dateTime.ts +80 -0
- package/src/util/groupState.ts +5 -0
- package/src/util/useTemporalControl.ts +160 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCompositeDraft,
|
|
3
|
+
type CompositeDetailDialogProps,
|
|
4
|
+
} from '@chobantonov/jsonforms-react-renderer-common/cells/useCompositeDraft';
|
|
5
|
+
import { DetailDialogContent } from '../complex/DetailDialogContent';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
8
|
+
import {
|
|
9
|
+
Dialog,
|
|
10
|
+
DialogHeader,
|
|
11
|
+
DialogTitle,
|
|
12
|
+
DialogFooter,
|
|
13
|
+
} from '@jsonforms-react-shadcn-ui/dialog';
|
|
14
|
+
import { JsonFormsContext } from '@jsonforms/react';
|
|
15
|
+
import { ShadcnCellMode } from './asCell';
|
|
16
|
+
import { PendingChangesProvider } from '@chobantonov/jsonforms-react-renderer-common/interaction/pendingChanges';
|
|
17
|
+
|
|
18
|
+
export const CompositeDetailDialog = (props: CompositeDetailDialogProps) => {
|
|
19
|
+
const { open, title, label, options, t, children } = props;
|
|
20
|
+
const dialog = useCompositeDraft(props);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Dialog
|
|
24
|
+
open={open}
|
|
25
|
+
onOpenChange={(next) => {
|
|
26
|
+
if (!next) dialog.cancel();
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
<DetailDialogContent
|
|
30
|
+
open={open}
|
|
31
|
+
options={options.dialog}
|
|
32
|
+
className='max-w-2xl'
|
|
33
|
+
aria-label={label}
|
|
34
|
+
aria-describedby={undefined}
|
|
35
|
+
>
|
|
36
|
+
<DialogHeader>
|
|
37
|
+
<DialogTitle>{title}</DialogTitle>
|
|
38
|
+
</DialogHeader>
|
|
39
|
+
<JsonFormsContext.Provider value={dialog.context as any}>
|
|
40
|
+
<PendingChangesProvider changes={dialog.pending}>
|
|
41
|
+
<ShadcnCellMode.Provider value={false}>
|
|
42
|
+
<div className='p-1'>{children}</div>
|
|
43
|
+
</ShadcnCellMode.Provider>
|
|
44
|
+
</PendingChangesProvider>
|
|
45
|
+
</JsonFormsContext.Provider>
|
|
46
|
+
{dialog.conflicted && (
|
|
47
|
+
<p role='alert'>
|
|
48
|
+
{t(
|
|
49
|
+
'composite.applyConflict',
|
|
50
|
+
dialog.defaultMessage('composite.applyConflict'),
|
|
51
|
+
)}
|
|
52
|
+
</p>
|
|
53
|
+
)}
|
|
54
|
+
<DialogFooter>
|
|
55
|
+
{options.showEmptyButton === true && (
|
|
56
|
+
<Button
|
|
57
|
+
type='button'
|
|
58
|
+
variant='outline'
|
|
59
|
+
disabled={!dialog.canEmpty}
|
|
60
|
+
onClick={dialog.clear}
|
|
61
|
+
>
|
|
62
|
+
{dialog.buttonLabel(options.emptyLabel, 'composite.empty')}
|
|
63
|
+
</Button>
|
|
64
|
+
)}
|
|
65
|
+
<Button type='button' variant='outline' onClick={dialog.cancel}>
|
|
66
|
+
{dialog.buttonLabel(options.cancelLabel, 'composite.cancel')}
|
|
67
|
+
</Button>
|
|
68
|
+
<Button
|
|
69
|
+
type='button'
|
|
70
|
+
disabled={!dialog.canApply}
|
|
71
|
+
onClick={dialog.apply}
|
|
72
|
+
>
|
|
73
|
+
{dialog.buttonLabel(options.okLabel, 'composite.apply')}
|
|
74
|
+
</Button>
|
|
75
|
+
</DialogFooter>
|
|
76
|
+
</DetailDialogContent>
|
|
77
|
+
</Dialog>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useTranslator,
|
|
3
|
+
useI18n,
|
|
4
|
+
} from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
5
|
+
import {
|
|
6
|
+
enumToEnumOptionMapper,
|
|
7
|
+
oneOfToEnumOptionMapper,
|
|
8
|
+
getI18nKeyPrefix,
|
|
9
|
+
CellProps,
|
|
10
|
+
} from '@jsonforms/core';
|
|
11
|
+
|
|
12
|
+
import isEqual from 'lodash/isEqual';
|
|
13
|
+
import React from 'react';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
Select,
|
|
17
|
+
SelectContent,
|
|
18
|
+
SelectItem,
|
|
19
|
+
SelectTrigger,
|
|
20
|
+
SelectValue,
|
|
21
|
+
} from '@jsonforms-react-shadcn-ui/select';
|
|
22
|
+
|
|
23
|
+
export const ShadcnEnumCell = ({
|
|
24
|
+
data,
|
|
25
|
+
enabled,
|
|
26
|
+
visible,
|
|
27
|
+
id,
|
|
28
|
+
path,
|
|
29
|
+
handleChange,
|
|
30
|
+
errors,
|
|
31
|
+
schema,
|
|
32
|
+
uischema,
|
|
33
|
+
}: CellProps) => {
|
|
34
|
+
const t = useI18n();
|
|
35
|
+
const translate = useTranslator();
|
|
36
|
+
if (visible === false) return null;
|
|
37
|
+
const prefix = getI18nKeyPrefix(schema, uischema, path);
|
|
38
|
+
const choices = schema.oneOf?.map((entry) =>
|
|
39
|
+
oneOfToEnumOptionMapper(entry, translate, prefix),
|
|
40
|
+
);
|
|
41
|
+
const values =
|
|
42
|
+
choices?.map((entry) => entry.value) ??
|
|
43
|
+
schema.enum ??
|
|
44
|
+
(Object.prototype.hasOwnProperty.call(schema, 'const')
|
|
45
|
+
? [schema.const]
|
|
46
|
+
: []);
|
|
47
|
+
const index = values.findIndex((value) => isEqual(value, data));
|
|
48
|
+
return (
|
|
49
|
+
<Select
|
|
50
|
+
value={index < 0 ? '' : `option-${index}`}
|
|
51
|
+
disabled={!enabled}
|
|
52
|
+
onValueChange={(value) =>
|
|
53
|
+
handleChange(path, values[Number(value.replace('option-', ''))])
|
|
54
|
+
}
|
|
55
|
+
>
|
|
56
|
+
<SelectTrigger
|
|
57
|
+
className='w-full min-w-0'
|
|
58
|
+
id={id}
|
|
59
|
+
aria-label={path || t('control.value')}
|
|
60
|
+
aria-invalid={Boolean(errors)}
|
|
61
|
+
>
|
|
62
|
+
<SelectValue placeholder={t('enum.select')} />
|
|
63
|
+
</SelectTrigger>
|
|
64
|
+
<SelectContent>
|
|
65
|
+
{values.map((value, index) => (
|
|
66
|
+
<SelectItem key={index} value={`option-${index}`}>
|
|
67
|
+
{choices?.[index].label ??
|
|
68
|
+
enumToEnumOptionMapper(value, translate, prefix).label}
|
|
69
|
+
</SelectItem>
|
|
70
|
+
))}
|
|
71
|
+
</SelectContent>
|
|
72
|
+
</Select>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
2
|
+
import { ClearValueButton } from '../components/ClearValueButton';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { CellProps } from '@jsonforms/core';
|
|
5
|
+
import { Input } from '@jsonforms-react-shadcn-ui/input';
|
|
6
|
+
|
|
7
|
+
export const ShadcnNumberCell = ({
|
|
8
|
+
config,
|
|
9
|
+
uischema,
|
|
10
|
+
data,
|
|
11
|
+
enabled,
|
|
12
|
+
visible,
|
|
13
|
+
id,
|
|
14
|
+
path,
|
|
15
|
+
handleChange,
|
|
16
|
+
errors,
|
|
17
|
+
schema,
|
|
18
|
+
}: CellProps) => {
|
|
19
|
+
const t = useI18n();
|
|
20
|
+
return visible === false ? null : (
|
|
21
|
+
<div className='group relative w-full'>
|
|
22
|
+
<Input
|
|
23
|
+
className='pr-10'
|
|
24
|
+
id={id}
|
|
25
|
+
type='number'
|
|
26
|
+
step={schema.type === 'integer' ? 1 : 'any'}
|
|
27
|
+
aria-label={path || t('control.value')}
|
|
28
|
+
aria-invalid={Boolean(errors)}
|
|
29
|
+
value={data ?? ''}
|
|
30
|
+
disabled={!enabled}
|
|
31
|
+
onChange={(event) => {
|
|
32
|
+
const value = event.currentTarget.value;
|
|
33
|
+
handleChange(
|
|
34
|
+
path,
|
|
35
|
+
value === ''
|
|
36
|
+
? undefined
|
|
37
|
+
: schema.type === 'integer'
|
|
38
|
+
? Math.trunc(Number(value))
|
|
39
|
+
: Number(value),
|
|
40
|
+
);
|
|
41
|
+
}}
|
|
42
|
+
/>
|
|
43
|
+
<ClearValueButton
|
|
44
|
+
clearable={uischema.options?.clearable ?? config?.clearable ?? true}
|
|
45
|
+
data={data}
|
|
46
|
+
enabled={enabled}
|
|
47
|
+
onClear={() => handleChange(path, undefined)}
|
|
48
|
+
/>
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ShadcnNumberCell } from './NumberCell';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import {
|
|
4
|
+
CellProps,
|
|
5
|
+
Formatted,
|
|
6
|
+
isNumberFormatControl,
|
|
7
|
+
rankWith,
|
|
8
|
+
} from '@jsonforms/core';
|
|
9
|
+
import { Input } from '@jsonforms-react-shadcn-ui/input';
|
|
10
|
+
import { Textarea } from '@jsonforms-react-shadcn-ui/textarea';
|
|
11
|
+
import { ClearValueButton } from '../components/ClearValueButton';
|
|
12
|
+
export const numberFormatCellTester = rankWith(4, isNumberFormatControl);
|
|
13
|
+
export const ShadcnNumberFormatCell = (
|
|
14
|
+
props: CellProps & Partial<Formatted<number>>,
|
|
15
|
+
) => {
|
|
16
|
+
if (props.visible === false) return null;
|
|
17
|
+
const { toFormatted, fromFormatted } = props;
|
|
18
|
+
if (!toFormatted || !fromFormatted) return <ShadcnNumberCell {...props} />;
|
|
19
|
+
const options = { ...props.config, ...props.uischema.options };
|
|
20
|
+
const Component = options.multi ? Textarea : Input;
|
|
21
|
+
return (
|
|
22
|
+
<div className='group relative w-full'>
|
|
23
|
+
<Component
|
|
24
|
+
id={props.id}
|
|
25
|
+
className='pr-10'
|
|
26
|
+
disabled={!props.enabled}
|
|
27
|
+
value={toFormatted(props.data)}
|
|
28
|
+
aria-invalid={Boolean(props.errors)}
|
|
29
|
+
autoFocus={options.focus}
|
|
30
|
+
placeholder={options.placeholder}
|
|
31
|
+
maxLength={props.schema.maxLength}
|
|
32
|
+
onChange={(event) =>
|
|
33
|
+
props.handleChange(
|
|
34
|
+
props.path,
|
|
35
|
+
fromFormatted(event.currentTarget.value),
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
/>
|
|
39
|
+
<ClearValueButton
|
|
40
|
+
data={props.data}
|
|
41
|
+
enabled={props.enabled}
|
|
42
|
+
clearable={options.clearable !== false}
|
|
43
|
+
onClear={() => props.handleChange(props.path, undefined)}
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
2
|
+
import { ClearValueButton } from '../components/ClearValueButton';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { CellProps } from '@jsonforms/core';
|
|
5
|
+
import { Input } from '@jsonforms-react-shadcn-ui/input';
|
|
6
|
+
|
|
7
|
+
export const ShadcnTextCell = ({
|
|
8
|
+
config,
|
|
9
|
+
uischema,
|
|
10
|
+
data,
|
|
11
|
+
enabled,
|
|
12
|
+
visible,
|
|
13
|
+
id,
|
|
14
|
+
path,
|
|
15
|
+
handleChange,
|
|
16
|
+
errors,
|
|
17
|
+
}: CellProps) => {
|
|
18
|
+
const t = useI18n();
|
|
19
|
+
return visible === false ? null : (
|
|
20
|
+
<div className='group relative w-full'>
|
|
21
|
+
<Input
|
|
22
|
+
className='pr-10'
|
|
23
|
+
id={id}
|
|
24
|
+
aria-label={path || t('control.value')}
|
|
25
|
+
aria-invalid={Boolean(errors)}
|
|
26
|
+
value={data ?? ''}
|
|
27
|
+
disabled={!enabled}
|
|
28
|
+
onChange={(event) =>
|
|
29
|
+
handleChange(path, event.currentTarget.value || undefined)
|
|
30
|
+
}
|
|
31
|
+
/>
|
|
32
|
+
<ClearValueButton
|
|
33
|
+
clearable={uischema.options?.clearable ?? config?.clearable ?? true}
|
|
34
|
+
data={data}
|
|
35
|
+
enabled={enabled}
|
|
36
|
+
onClear={() => handleChange(path, undefined)}
|
|
37
|
+
/>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React, { createContext } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
CellProps,
|
|
4
|
+
ControlElement,
|
|
5
|
+
JsonSchema,
|
|
6
|
+
UISchemaElement,
|
|
7
|
+
} from '@jsonforms/core';
|
|
8
|
+
import { withJsonFormsCellProps } from '@jsonforms/react';
|
|
9
|
+
import { ErrorIndicator } from '../complex/ErrorIndicator';
|
|
10
|
+
|
|
11
|
+
export const ShadcnCellMode = createContext(false);
|
|
12
|
+
|
|
13
|
+
/** DispatchCell paths already include the field scope; connected controls must not append it again. */
|
|
14
|
+
export const asShadcnCell = <P extends { uischema?: UISchemaElement }>(
|
|
15
|
+
Control: React.ComponentType<P>,
|
|
16
|
+
): React.ComponentType<P> => {
|
|
17
|
+
const Cell = (props: P) => (
|
|
18
|
+
<ShadcnCellMode.Provider value={true}>
|
|
19
|
+
<Control
|
|
20
|
+
{...props}
|
|
21
|
+
uischema={{ ...props.uischema, scope: '#', label: false } as any}
|
|
22
|
+
/>
|
|
23
|
+
</ShadcnCellMode.Provider>
|
|
24
|
+
);
|
|
25
|
+
return Cell;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** AG Grid cells fill a row; center short controls such as checkboxes vertically. */
|
|
29
|
+
const ConnectedGridCellFrame = withJsonFormsCellProps(
|
|
30
|
+
({
|
|
31
|
+
children,
|
|
32
|
+
errors,
|
|
33
|
+
path,
|
|
34
|
+
schema,
|
|
35
|
+
uischema,
|
|
36
|
+
}: React.PropsWithChildren<CellProps>) => (
|
|
37
|
+
<div
|
|
38
|
+
className='shadcn-jsonforms-grid-cell'
|
|
39
|
+
style={{
|
|
40
|
+
display: 'flex',
|
|
41
|
+
alignItems: 'center',
|
|
42
|
+
height: '100%',
|
|
43
|
+
minWidth: 0,
|
|
44
|
+
width: '100%',
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
<div
|
|
48
|
+
className='shadcn-jsonforms-grid-cell-content'
|
|
49
|
+
style={{ flex: 1, minWidth: 0 }}
|
|
50
|
+
>
|
|
51
|
+
{children}
|
|
52
|
+
</div>
|
|
53
|
+
{errors &&
|
|
54
|
+
uischema.options?.summary?.type !== 'Label' &&
|
|
55
|
+
schema.type !== 'object' &&
|
|
56
|
+
schema.type !== 'array' && (
|
|
57
|
+
<ErrorIndicator
|
|
58
|
+
local
|
|
59
|
+
errors={errors}
|
|
60
|
+
path={path}
|
|
61
|
+
className='shadcn-jsonforms-cell-error'
|
|
62
|
+
/>
|
|
63
|
+
)}
|
|
64
|
+
</div>
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
export const ShadcnGridCellFrame = (
|
|
69
|
+
props: React.PropsWithChildren<{
|
|
70
|
+
schema?: JsonSchema;
|
|
71
|
+
uischema?: UISchemaElement;
|
|
72
|
+
path: string;
|
|
73
|
+
}>,
|
|
74
|
+
) => (
|
|
75
|
+
<ConnectedGridCellFrame
|
|
76
|
+
{...props}
|
|
77
|
+
uischema={props.uischema as ControlElement}
|
|
78
|
+
/>
|
|
79
|
+
);
|