@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,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useTupleAdditionalItems,
|
|
3
|
+
type TupleAdditionalItemsProps,
|
|
4
|
+
} from '@chobantonov/jsonforms-react-renderer-common/tuple/useTupleAdditionalItems';
|
|
5
|
+
import { DeleteDialog } from './DeleteDialog';
|
|
6
|
+
import { PendingChangesProvider } from '@chobantonov/jsonforms-react-renderer-common/interaction/pendingChanges';
|
|
7
|
+
import { CollectionPager } from './CollectionPager';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
10
|
+
import { Trash2, Plus } from 'lucide-react';
|
|
11
|
+
|
|
12
|
+
export type { TupleAdditionalItemsProps } from '@chobantonov/jsonforms-react-renderer-common/tuple/useTupleAdditionalItems';
|
|
13
|
+
|
|
14
|
+
export const TupleAdditionalItems = (props: TupleAdditionalItemsProps) => {
|
|
15
|
+
const { renderItem, positionLabel } = props;
|
|
16
|
+
const { t, message, canAdd, canDelete, add, deletion, visibleIndices, page } =
|
|
17
|
+
useTupleAdditionalItems(props);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<section
|
|
21
|
+
data-tuple-additional
|
|
22
|
+
style={{
|
|
23
|
+
marginTop: 16,
|
|
24
|
+
paddingTop: 12,
|
|
25
|
+
borderTop: `1px solid ${'var(--border)'}`,
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
<DeleteDialog
|
|
29
|
+
open={deletion.confirming}
|
|
30
|
+
onCancel={deletion.cancel}
|
|
31
|
+
onConfirm={deletion.confirm}
|
|
32
|
+
/>
|
|
33
|
+
<header
|
|
34
|
+
style={{
|
|
35
|
+
display: 'flex',
|
|
36
|
+
alignItems: 'center',
|
|
37
|
+
justifyContent: 'space-between',
|
|
38
|
+
gap: 8,
|
|
39
|
+
marginBottom: 8,
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
<strong>{t('tuple.additionalItems')}</strong>
|
|
43
|
+
<Button
|
|
44
|
+
size='icon-sm'
|
|
45
|
+
type='button'
|
|
46
|
+
variant='ghost'
|
|
47
|
+
disabled={!canAdd}
|
|
48
|
+
onClick={add}
|
|
49
|
+
title={t('tuple.add')}
|
|
50
|
+
aria-label={t('tuple.add')}
|
|
51
|
+
data-tuple-add
|
|
52
|
+
>
|
|
53
|
+
<Plus className='h-4 w-4' />
|
|
54
|
+
</Button>
|
|
55
|
+
</header>
|
|
56
|
+
<PendingChangesProvider changes={page.pending}>
|
|
57
|
+
{visibleIndices.map((index) => (
|
|
58
|
+
<div
|
|
59
|
+
key={index}
|
|
60
|
+
style={{
|
|
61
|
+
display: 'flex',
|
|
62
|
+
alignItems: 'flex-start',
|
|
63
|
+
gap: 8,
|
|
64
|
+
marginBottom: 8,
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
<div style={{ flex: 1, minWidth: 0 }}>{renderItem(index)}</div>
|
|
68
|
+
<Button
|
|
69
|
+
size='icon-sm'
|
|
70
|
+
type='button'
|
|
71
|
+
variant='ghost'
|
|
72
|
+
className='text-destructive'
|
|
73
|
+
disabled={!canDelete}
|
|
74
|
+
onClick={() => deletion.request(index)}
|
|
75
|
+
title={t('tuple.delete', { label: positionLabel(index) })}
|
|
76
|
+
aria-label={t('tuple.delete', {
|
|
77
|
+
label: positionLabel(index),
|
|
78
|
+
})}
|
|
79
|
+
data-tuple-delete={index}
|
|
80
|
+
>
|
|
81
|
+
<Trash2 className='h-4 w-4' />
|
|
82
|
+
</Button>
|
|
83
|
+
</div>
|
|
84
|
+
))}
|
|
85
|
+
</PendingChangesProvider>
|
|
86
|
+
<CollectionPager page={page} />
|
|
87
|
+
{message && (
|
|
88
|
+
<span className='text-destructive' role='alert' data-tuple-draft>
|
|
89
|
+
{message}
|
|
90
|
+
</span>
|
|
91
|
+
)}
|
|
92
|
+
</section>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useTupleControl } from '@chobantonov/jsonforms-react-renderer-common/tuple/useTupleControl';
|
|
2
|
+
import {
|
|
3
|
+
connectTupleControl,
|
|
4
|
+
TupleControlContent,
|
|
5
|
+
type TupleControlProps,
|
|
6
|
+
} from '@chobantonov/jsonforms-react-renderer-common/tuple/TupleControlContent';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import type { RankedTester } from '@jsonforms/core';
|
|
9
|
+
import { InputShell } from '../controls/InputControl';
|
|
10
|
+
import { tupleControlTester } from '@chobantonov/jsonforms-react-renderer-common/tuple/tupleSchema';
|
|
11
|
+
import { TupleAdditionalItems } from './TupleAdditionalItems';
|
|
12
|
+
import { TupleField } from './TupleField';
|
|
13
|
+
|
|
14
|
+
export const tupleControlRendererTester: RankedTester = tupleControlTester;
|
|
15
|
+
|
|
16
|
+
export const TupleControl = (props: TupleControlProps) => {
|
|
17
|
+
const { label, required, visible } = props;
|
|
18
|
+
const model = useTupleControl(props);
|
|
19
|
+
const { options, shownErrors } = model;
|
|
20
|
+
if (!visible) return null;
|
|
21
|
+
const content = (
|
|
22
|
+
<TupleControlContent
|
|
23
|
+
props={props}
|
|
24
|
+
model={model}
|
|
25
|
+
TupleField={TupleField}
|
|
26
|
+
TupleAdditionalItems={TupleAdditionalItems}
|
|
27
|
+
gap={16}
|
|
28
|
+
diagnostic={(message) => (
|
|
29
|
+
<span className='text-destructive' role='alert' data-tuple-diagnostic>
|
|
30
|
+
{message}
|
|
31
|
+
</span>
|
|
32
|
+
)}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
return (
|
|
36
|
+
<InputShell
|
|
37
|
+
{...props}
|
|
38
|
+
id={props.id}
|
|
39
|
+
label={label}
|
|
40
|
+
required={required}
|
|
41
|
+
errors={shownErrors || undefined}
|
|
42
|
+
>
|
|
43
|
+
{options.showBorder === false ? (
|
|
44
|
+
<div data-tuple-control>{content}</div>
|
|
45
|
+
) : (
|
|
46
|
+
<div data-tuple-control className='rounded-md border p-3'>
|
|
47
|
+
{content}
|
|
48
|
+
</div>
|
|
49
|
+
)}
|
|
50
|
+
</InputShell>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const TupleControlRenderer = connectTupleControl(TupleControl);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
TupleField as CommonTupleField,
|
|
4
|
+
type TupleFieldProps,
|
|
5
|
+
} from '@chobantonov/jsonforms-react-renderer-common/tuple/TupleField';
|
|
6
|
+
export type { TupleFieldProps } from '@chobantonov/jsonforms-react-renderer-common/tuple/TupleField';
|
|
7
|
+
import { CompositeDetailDialog } from '../cells/CompositeDetailDialog';
|
|
8
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
9
|
+
import { Pencil } from 'lucide-react';
|
|
10
|
+
export function TupleField(props: TupleFieldProps) {
|
|
11
|
+
return (
|
|
12
|
+
<CommonTupleField
|
|
13
|
+
{...props}
|
|
14
|
+
CompositeDetailDialog={CompositeDetailDialog}
|
|
15
|
+
gap={8}
|
|
16
|
+
legendStyle={{ marginBottom: 4, fontSize: 14, color: 'inherit' }}
|
|
17
|
+
renderEditButton={(label, disabled, open) => (
|
|
18
|
+
<Button
|
|
19
|
+
size='icon-sm'
|
|
20
|
+
type='button'
|
|
21
|
+
variant='ghost'
|
|
22
|
+
disabled={disabled}
|
|
23
|
+
onClick={open}
|
|
24
|
+
title={label}
|
|
25
|
+
aria-label={label}
|
|
26
|
+
>
|
|
27
|
+
<Pencil className='h-4 w-4' />
|
|
28
|
+
</Button>
|
|
29
|
+
)}
|
|
30
|
+
renderError={(message, draft) => (
|
|
31
|
+
<span
|
|
32
|
+
className='text-destructive'
|
|
33
|
+
role='alert'
|
|
34
|
+
data-tuple-draft={draft || undefined}
|
|
35
|
+
>
|
|
36
|
+
{message}
|
|
37
|
+
</span>
|
|
38
|
+
)}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
2
|
+
import { ItemValidationIndicator } from '@chobantonov/jsonforms-react-renderer-common/validation/ItemValidationIndicator';
|
|
3
|
+
import { ContainerValidationIndicator } from '../../layouts/ValidationIndicator';
|
|
4
|
+
import { ArrayLayoutProps, composePaths } from '@jsonforms/core';
|
|
5
|
+
import { JsonFormsDispatch } from '@jsonforms/react';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import {
|
|
8
|
+
Trash2,
|
|
9
|
+
ChevronUp,
|
|
10
|
+
ChevronDown,
|
|
11
|
+
ArrowUp,
|
|
12
|
+
ArrowDown,
|
|
13
|
+
} from 'lucide-react';
|
|
14
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
15
|
+
import {
|
|
16
|
+
Collapsible,
|
|
17
|
+
CollapsibleTrigger,
|
|
18
|
+
CollapsibleContent,
|
|
19
|
+
} from '@jsonforms-react-shadcn-ui/collapsible';
|
|
20
|
+
import type { ArrayItemViewProps } from './ArrayItemViewProps';
|
|
21
|
+
const ArrayItemPanel = ({
|
|
22
|
+
label,
|
|
23
|
+
index,
|
|
24
|
+
open,
|
|
25
|
+
onOpenChange,
|
|
26
|
+
hideAvatar,
|
|
27
|
+
actions,
|
|
28
|
+
indicator,
|
|
29
|
+
children,
|
|
30
|
+
}: React.PropsWithChildren<{
|
|
31
|
+
label: string;
|
|
32
|
+
index: number;
|
|
33
|
+
open: boolean;
|
|
34
|
+
onOpenChange: (open: boolean) => void;
|
|
35
|
+
hideAvatar: boolean;
|
|
36
|
+
actions: React.ReactNode;
|
|
37
|
+
indicator: React.ReactNode;
|
|
38
|
+
}>) => {
|
|
39
|
+
const t = useI18n();
|
|
40
|
+
return (
|
|
41
|
+
<Collapsible
|
|
42
|
+
open={open}
|
|
43
|
+
onOpenChange={onOpenChange}
|
|
44
|
+
className='shadcn-jsonforms-array-item'
|
|
45
|
+
>
|
|
46
|
+
<div className='relative flex items-center'>
|
|
47
|
+
<CollapsibleTrigger
|
|
48
|
+
render={<Button type='button' variant='ghost' />}
|
|
49
|
+
className='h-auto min-w-0 flex-1 justify-start gap-3 whitespace-normal text-left'
|
|
50
|
+
aria-label={label || String(index + 1)}
|
|
51
|
+
>
|
|
52
|
+
{!hideAvatar && (
|
|
53
|
+
<span
|
|
54
|
+
data-array-index
|
|
55
|
+
aria-label={`${t('array.indexLabel')} ${index + 1}`}
|
|
56
|
+
className='flex h-8 w-8 shrink-0 items-center justify-center rounded-full border bg-muted text-muted-foreground'
|
|
57
|
+
>
|
|
58
|
+
{index + 1}
|
|
59
|
+
</span>
|
|
60
|
+
)}
|
|
61
|
+
<span className='flex min-w-0 flex-1 items-center gap-2 pe-10'>
|
|
62
|
+
<span className='min-w-0'>
|
|
63
|
+
{hideAvatar ? `${index + 1} ${label}` : label}
|
|
64
|
+
</span>
|
|
65
|
+
<span className='flex shrink-0 items-center leading-none'>
|
|
66
|
+
{indicator}
|
|
67
|
+
</span>
|
|
68
|
+
</span>
|
|
69
|
+
{open ? (
|
|
70
|
+
<ChevronUp aria-hidden='true' />
|
|
71
|
+
) : (
|
|
72
|
+
<ChevronDown aria-hidden='true' />
|
|
73
|
+
)}
|
|
74
|
+
</CollapsibleTrigger>
|
|
75
|
+
<div className='absolute right-10 flex items-center gap-1'>
|
|
76
|
+
{actions}
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
<CollapsibleContent keepMounted hidden={!open} className='px-3 pb-3'>
|
|
80
|
+
{children}
|
|
81
|
+
</CollapsibleContent>
|
|
82
|
+
</Collapsible>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
type ArrayItemPanelsProps = ArrayItemViewProps &
|
|
87
|
+
Pick<ArrayLayoutProps, 'config' | 'uischema'> & {
|
|
88
|
+
expandedIndex?: number;
|
|
89
|
+
onExpand: (index: number | undefined) => void;
|
|
90
|
+
onMove: (index: number, direction: -1 | 1) => void;
|
|
91
|
+
canMove: boolean;
|
|
92
|
+
count: number;
|
|
93
|
+
translations: {
|
|
94
|
+
upAriaLabel: string;
|
|
95
|
+
up: string;
|
|
96
|
+
downAriaLabel: string;
|
|
97
|
+
down: string;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const ArrayItemActions = ({
|
|
102
|
+
index,
|
|
103
|
+
settings,
|
|
104
|
+
}: {
|
|
105
|
+
index: number;
|
|
106
|
+
settings: ArrayItemPanelsProps;
|
|
107
|
+
}) => {
|
|
108
|
+
const t = useI18n();
|
|
109
|
+
const {
|
|
110
|
+
uischema,
|
|
111
|
+
config,
|
|
112
|
+
translations,
|
|
113
|
+
canMove,
|
|
114
|
+
count,
|
|
115
|
+
removeLabel,
|
|
116
|
+
removeTooltip,
|
|
117
|
+
canRemove,
|
|
118
|
+
onMove,
|
|
119
|
+
requestRemove,
|
|
120
|
+
} = settings;
|
|
121
|
+
return (
|
|
122
|
+
<>
|
|
123
|
+
{(uischema.options?.showSortButtons ?? config?.showSortButtons) && (
|
|
124
|
+
<>
|
|
125
|
+
<Button
|
|
126
|
+
type='button'
|
|
127
|
+
variant='ghost'
|
|
128
|
+
size='icon'
|
|
129
|
+
aria-label={translations.upAriaLabel}
|
|
130
|
+
title={translations.up}
|
|
131
|
+
disabled={!canMove || index === 0}
|
|
132
|
+
onClick={() => onMove(index, -1)}
|
|
133
|
+
>
|
|
134
|
+
<ArrowUp aria-hidden='true' />
|
|
135
|
+
</Button>
|
|
136
|
+
<Button
|
|
137
|
+
type='button'
|
|
138
|
+
variant='ghost'
|
|
139
|
+
size='icon'
|
|
140
|
+
aria-label={translations.downAriaLabel}
|
|
141
|
+
title={translations.down}
|
|
142
|
+
disabled={!canMove || index === count - 1}
|
|
143
|
+
onClick={() => onMove(index, 1)}
|
|
144
|
+
>
|
|
145
|
+
<ArrowDown aria-hidden='true' />
|
|
146
|
+
</Button>
|
|
147
|
+
</>
|
|
148
|
+
)}
|
|
149
|
+
<Button
|
|
150
|
+
variant='destructive'
|
|
151
|
+
size='icon'
|
|
152
|
+
className='h-7 w-7'
|
|
153
|
+
aria-label={removeLabel || t('array.removeAriaLabel')}
|
|
154
|
+
title={removeTooltip || t('array.removeTooltip')}
|
|
155
|
+
type='button'
|
|
156
|
+
disabled={!canRemove}
|
|
157
|
+
onClick={() => requestRemove(index)}
|
|
158
|
+
>
|
|
159
|
+
<Trash2 className='h-4 w-4' aria-hidden='true' />
|
|
160
|
+
</Button>
|
|
161
|
+
</>
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export function ArrayItemPanels(props: ArrayItemPanelsProps) {
|
|
166
|
+
const {
|
|
167
|
+
schema,
|
|
168
|
+
path,
|
|
169
|
+
enabled,
|
|
170
|
+
cells,
|
|
171
|
+
renderers,
|
|
172
|
+
detail,
|
|
173
|
+
indices,
|
|
174
|
+
hideAvatar,
|
|
175
|
+
childLabelForIndex,
|
|
176
|
+
config,
|
|
177
|
+
uischema,
|
|
178
|
+
expandedIndex,
|
|
179
|
+
onExpand,
|
|
180
|
+
} = props;
|
|
181
|
+
return (
|
|
182
|
+
<>
|
|
183
|
+
{indices.map((index) => {
|
|
184
|
+
const childPath = composePaths(path, `${index}`);
|
|
185
|
+
const childLabel = childLabelForIndex(childPath, index);
|
|
186
|
+
return (
|
|
187
|
+
<ArrayItemPanel
|
|
188
|
+
key={childPath}
|
|
189
|
+
label={childLabel}
|
|
190
|
+
indicator={
|
|
191
|
+
<ItemValidationIndicator
|
|
192
|
+
Indicator={ContainerValidationIndicator}
|
|
193
|
+
path={childPath}
|
|
194
|
+
options={uischema.options}
|
|
195
|
+
config={config}
|
|
196
|
+
/>
|
|
197
|
+
}
|
|
198
|
+
index={index}
|
|
199
|
+
open={expandedIndex === index}
|
|
200
|
+
onOpenChange={(open) => onExpand(open ? index : undefined)}
|
|
201
|
+
hideAvatar={hideAvatar}
|
|
202
|
+
actions={<ArrayItemActions index={index} settings={props} />}
|
|
203
|
+
>
|
|
204
|
+
<JsonFormsDispatch
|
|
205
|
+
schema={schema}
|
|
206
|
+
uischema={detail}
|
|
207
|
+
path={childPath}
|
|
208
|
+
enabled={enabled}
|
|
209
|
+
renderers={renderers}
|
|
210
|
+
cells={cells}
|
|
211
|
+
/>
|
|
212
|
+
</ArrayItemPanel>
|
|
213
|
+
);
|
|
214
|
+
})}
|
|
215
|
+
</>
|
|
216
|
+
);
|
|
217
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ArrayLayoutProps, UISchemaElement } from '@jsonforms/core';
|
|
2
|
+
|
|
3
|
+
export type ArrayItemViewProps = Pick<
|
|
4
|
+
ArrayLayoutProps,
|
|
5
|
+
'schema' | 'path' | 'enabled' | 'cells' | 'renderers'
|
|
6
|
+
> & {
|
|
7
|
+
detail: UISchemaElement;
|
|
8
|
+
indices: number[];
|
|
9
|
+
hideAvatar: boolean;
|
|
10
|
+
canRemove: boolean;
|
|
11
|
+
requestRemove: (index: number) => void;
|
|
12
|
+
childLabelForIndex: (path: string, index: number) => string;
|
|
13
|
+
removeLabel: string;
|
|
14
|
+
removeTooltip: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
2
|
+
import { ScrollRegion } from '../../components/ScrollRegion';
|
|
3
|
+
import {
|
|
4
|
+
ResizablePanelGroup,
|
|
5
|
+
ResizablePanel,
|
|
6
|
+
ResizableHandle,
|
|
7
|
+
} from '@jsonforms-react-shadcn-ui/resizable';
|
|
8
|
+
import { ArrayLayoutProps, composePaths } from '@jsonforms/core';
|
|
9
|
+
import { JsonFormsDispatch } from '@jsonforms/react';
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { Check, Trash2 } from 'lucide-react';
|
|
12
|
+
import {
|
|
13
|
+
Item,
|
|
14
|
+
ItemGroup,
|
|
15
|
+
ItemContent,
|
|
16
|
+
ItemActions,
|
|
17
|
+
} from '@jsonforms-react-shadcn-ui/item';
|
|
18
|
+
import { Avatar, AvatarFallback } from '@jsonforms-react-shadcn-ui/avatar';
|
|
19
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
20
|
+
import type { ArrayItemViewProps } from './ArrayItemViewProps';
|
|
21
|
+
export function ArrayListDetail({
|
|
22
|
+
schema,
|
|
23
|
+
path,
|
|
24
|
+
enabled,
|
|
25
|
+
cells,
|
|
26
|
+
renderers,
|
|
27
|
+
detail,
|
|
28
|
+
indices,
|
|
29
|
+
count,
|
|
30
|
+
label,
|
|
31
|
+
readonly,
|
|
32
|
+
selectedItem,
|
|
33
|
+
emptyMessage,
|
|
34
|
+
...itemProps
|
|
35
|
+
}: ArrayItemViewProps &
|
|
36
|
+
Pick<ArrayLayoutProps, 'label' | 'readonly'> & {
|
|
37
|
+
count: number;
|
|
38
|
+
selectedItem: number;
|
|
39
|
+
onSelect: (index: number) => void;
|
|
40
|
+
emptyMessage: () => string;
|
|
41
|
+
}) {
|
|
42
|
+
if (count === 0)
|
|
43
|
+
return (
|
|
44
|
+
<div className='py-6 text-center text-muted-foreground'>
|
|
45
|
+
{emptyMessage()}
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
const activeIndex = Math.min(selectedItem, count - 1);
|
|
49
|
+
return (
|
|
50
|
+
<ResizablePanelGroup orientation='horizontal' style={{ height: 'auto' }}>
|
|
51
|
+
<ResizablePanel defaultSize='25%' minSize='15%' maxSize='60%'>
|
|
52
|
+
<ScrollRegion
|
|
53
|
+
className='shadcn-jsonforms-list-navigation'
|
|
54
|
+
style={{ maxHeight: '20rem' }}
|
|
55
|
+
>
|
|
56
|
+
<ItemGroup
|
|
57
|
+
className='min-w-0 rounded-lg border p-1'
|
|
58
|
+
aria-label={label}
|
|
59
|
+
>
|
|
60
|
+
{indices.map((index) => {
|
|
61
|
+
const selected = activeIndex === index;
|
|
62
|
+
const itemLabel = itemProps.childLabelForIndex(
|
|
63
|
+
composePaths(path, String(index)),
|
|
64
|
+
index,
|
|
65
|
+
);
|
|
66
|
+
return (
|
|
67
|
+
<ArrayListItem
|
|
68
|
+
key={index}
|
|
69
|
+
index={index}
|
|
70
|
+
selected={selected}
|
|
71
|
+
itemLabel={itemLabel}
|
|
72
|
+
{...itemProps}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
})}
|
|
76
|
+
</ItemGroup>
|
|
77
|
+
</ScrollRegion>
|
|
78
|
+
</ResizablePanel>
|
|
79
|
+
<ResizableHandle withHandle />
|
|
80
|
+
<ResizablePanel minSize='25%'>
|
|
81
|
+
<div className='min-w-0 space-y-3 ps-3' role='tabpanel'>
|
|
82
|
+
<JsonFormsDispatch
|
|
83
|
+
schema={schema}
|
|
84
|
+
uischema={detail}
|
|
85
|
+
path={composePaths(path, String(activeIndex))}
|
|
86
|
+
enabled={enabled && !readonly}
|
|
87
|
+
renderers={renderers}
|
|
88
|
+
cells={cells}
|
|
89
|
+
/>
|
|
90
|
+
</div>
|
|
91
|
+
</ResizablePanel>
|
|
92
|
+
</ResizablePanelGroup>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function ArrayListItem({
|
|
97
|
+
index,
|
|
98
|
+
selected,
|
|
99
|
+
itemLabel,
|
|
100
|
+
hideAvatar,
|
|
101
|
+
canRemove,
|
|
102
|
+
removeLabel,
|
|
103
|
+
removeTooltip,
|
|
104
|
+
onSelect,
|
|
105
|
+
requestRemove,
|
|
106
|
+
}: Pick<
|
|
107
|
+
ArrayItemViewProps,
|
|
108
|
+
'hideAvatar' | 'canRemove' | 'removeLabel' | 'removeTooltip' | 'requestRemove'
|
|
109
|
+
> & {
|
|
110
|
+
index: number;
|
|
111
|
+
selected: boolean;
|
|
112
|
+
itemLabel: string;
|
|
113
|
+
onSelect: (index: number) => void;
|
|
114
|
+
}) {
|
|
115
|
+
const t = useI18n();
|
|
116
|
+
return (
|
|
117
|
+
<Item
|
|
118
|
+
role='listitem'
|
|
119
|
+
size='sm'
|
|
120
|
+
variant={selected ? 'muted' : 'default'}
|
|
121
|
+
className='flex-nowrap gap-1 p-1'
|
|
122
|
+
>
|
|
123
|
+
<ItemContent className='min-w-0'>
|
|
124
|
+
<Button
|
|
125
|
+
type='button'
|
|
126
|
+
variant='ghost'
|
|
127
|
+
className='h-auto min-h-12 w-full min-w-0 justify-start gap-3 whitespace-nowrap text-left'
|
|
128
|
+
aria-pressed={selected}
|
|
129
|
+
aria-label={itemLabel || String(index + 1)}
|
|
130
|
+
onClick={() => onSelect(index)}
|
|
131
|
+
>
|
|
132
|
+
{!hideAvatar && (
|
|
133
|
+
<Avatar
|
|
134
|
+
data-array-index
|
|
135
|
+
aria-label={`${t('array.indexLabel')} ${index + 1}`}
|
|
136
|
+
className='border'
|
|
137
|
+
>
|
|
138
|
+
<AvatarFallback>{index + 1}</AvatarFallback>
|
|
139
|
+
</Avatar>
|
|
140
|
+
)}
|
|
141
|
+
<span className='min-w-0 flex-1 truncate'>
|
|
142
|
+
{hideAvatar ? `${index + 1} ${itemLabel}` : itemLabel}
|
|
143
|
+
</span>
|
|
144
|
+
{selected && (
|
|
145
|
+
<Check className='h-4 w-4 shrink-0' aria-hidden='true' />
|
|
146
|
+
)}
|
|
147
|
+
</Button>
|
|
148
|
+
</ItemContent>
|
|
149
|
+
<ItemActions className='shrink-0'>
|
|
150
|
+
<Button
|
|
151
|
+
type='button'
|
|
152
|
+
variant='ghost'
|
|
153
|
+
size='icon'
|
|
154
|
+
className='h-6 w-6 bg-destructive/10 text-destructive hover:bg-destructive/20 hover:text-destructive'
|
|
155
|
+
aria-label={removeLabel}
|
|
156
|
+
title={removeTooltip}
|
|
157
|
+
disabled={!canRemove}
|
|
158
|
+
onClick={() => requestRemove(index)}
|
|
159
|
+
>
|
|
160
|
+
<Trash2 className='h-3 w-3' aria-hidden='true' />
|
|
161
|
+
</Button>
|
|
162
|
+
</ItemActions>
|
|
163
|
+
</Item>
|
|
164
|
+
);
|
|
165
|
+
}
|