@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,136 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CircleAlert } from 'lucide-react';
|
|
3
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
4
|
+
import {
|
|
5
|
+
Tooltip,
|
|
6
|
+
TooltipProvider,
|
|
7
|
+
TooltipTrigger,
|
|
8
|
+
TooltipContent,
|
|
9
|
+
} from '@jsonforms-react-shadcn-ui/tooltip';
|
|
10
|
+
import {
|
|
11
|
+
Popover,
|
|
12
|
+
PopoverContent,
|
|
13
|
+
PopoverTrigger,
|
|
14
|
+
} from '@jsonforms-react-shadcn-ui/popover';
|
|
15
|
+
import {
|
|
16
|
+
ErrorSummaryList,
|
|
17
|
+
useErrorFeedback,
|
|
18
|
+
} from '@chobantonov/jsonforms-react-renderer-common/validation/errorSummary';
|
|
19
|
+
|
|
20
|
+
export const ErrorIndicator = ({
|
|
21
|
+
errors,
|
|
22
|
+
className,
|
|
23
|
+
path,
|
|
24
|
+
local = false,
|
|
25
|
+
}: {
|
|
26
|
+
errors: string;
|
|
27
|
+
className?: string;
|
|
28
|
+
path?: string;
|
|
29
|
+
local?: boolean;
|
|
30
|
+
}) => {
|
|
31
|
+
const { open, setOpen, count, entries, message } = useErrorFeedback(
|
|
32
|
+
errors,
|
|
33
|
+
path,
|
|
34
|
+
local,
|
|
35
|
+
);
|
|
36
|
+
const timer = React.useRef<ReturnType<typeof setTimeout>>();
|
|
37
|
+
const trigger = React.useRef<HTMLButtonElement>(null);
|
|
38
|
+
const content = React.useRef<HTMLDivElement>(null);
|
|
39
|
+
const cancelClose = () => {
|
|
40
|
+
if (timer.current) clearTimeout(timer.current);
|
|
41
|
+
};
|
|
42
|
+
const show = () => {
|
|
43
|
+
cancelClose();
|
|
44
|
+
setOpen(true);
|
|
45
|
+
};
|
|
46
|
+
const scheduleClose = () => {
|
|
47
|
+
cancelClose();
|
|
48
|
+
timer.current = setTimeout(() => {
|
|
49
|
+
if (
|
|
50
|
+
trigger.current !== document.activeElement &&
|
|
51
|
+
!content.current?.contains(document.activeElement)
|
|
52
|
+
)
|
|
53
|
+
setOpen(false);
|
|
54
|
+
}, 200);
|
|
55
|
+
};
|
|
56
|
+
React.useEffect(
|
|
57
|
+
() => () => {
|
|
58
|
+
if (timer.current) clearTimeout(timer.current);
|
|
59
|
+
},
|
|
60
|
+
[],
|
|
61
|
+
);
|
|
62
|
+
if (count <= 1)
|
|
63
|
+
return (
|
|
64
|
+
<TooltipProvider>
|
|
65
|
+
<Tooltip onOpenChange={setOpen}>
|
|
66
|
+
<TooltipTrigger asChild>
|
|
67
|
+
<Button
|
|
68
|
+
type='button'
|
|
69
|
+
variant='ghost'
|
|
70
|
+
size='icon-sm'
|
|
71
|
+
className={`h-6 w-6 shrink-0 p-0 text-destructive ${
|
|
72
|
+
className ?? ''
|
|
73
|
+
}`}
|
|
74
|
+
aria-label={errors}
|
|
75
|
+
>
|
|
76
|
+
<CircleAlert className='h-4 w-4' aria-hidden='true' />
|
|
77
|
+
</Button>
|
|
78
|
+
</TooltipTrigger>
|
|
79
|
+
<TooltipContent className='max-w-sm whitespace-pre-line'>
|
|
80
|
+
{message}
|
|
81
|
+
</TooltipContent>
|
|
82
|
+
</Tooltip>
|
|
83
|
+
</TooltipProvider>
|
|
84
|
+
);
|
|
85
|
+
return (
|
|
86
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
87
|
+
<PopoverTrigger asChild>
|
|
88
|
+
<Button
|
|
89
|
+
type='button'
|
|
90
|
+
variant='ghost'
|
|
91
|
+
size='icon-sm'
|
|
92
|
+
ref={trigger}
|
|
93
|
+
onPointerEnter={show}
|
|
94
|
+
onPointerLeave={scheduleClose}
|
|
95
|
+
onFocus={show}
|
|
96
|
+
onBlur={scheduleClose}
|
|
97
|
+
onClick={(event) => {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
show();
|
|
100
|
+
}}
|
|
101
|
+
className={`h-6 w-6 shrink-0 p-0 text-destructive ${className ?? ''}`}
|
|
102
|
+
aria-label={errors}
|
|
103
|
+
>
|
|
104
|
+
<CircleAlert className='h-4 w-4' aria-hidden='true' />
|
|
105
|
+
</Button>
|
|
106
|
+
</PopoverTrigger>
|
|
107
|
+
|
|
108
|
+
<PopoverContent
|
|
109
|
+
className='w-auto'
|
|
110
|
+
align='start'
|
|
111
|
+
onOpenAutoFocus={(event) => event.preventDefault()}
|
|
112
|
+
onCloseAutoFocus={(event) => event.preventDefault()}
|
|
113
|
+
onPointerEnter={cancelClose}
|
|
114
|
+
onPointerLeave={scheduleClose}
|
|
115
|
+
onFocusCapture={cancelClose}
|
|
116
|
+
onBlurCapture={scheduleClose}
|
|
117
|
+
>
|
|
118
|
+
<div ref={content}>
|
|
119
|
+
<ErrorSummaryList
|
|
120
|
+
entries={entries}
|
|
121
|
+
renderToggle={(label, toggle, expanded) => (
|
|
122
|
+
<Button
|
|
123
|
+
type='button'
|
|
124
|
+
variant='link'
|
|
125
|
+
onClick={toggle}
|
|
126
|
+
aria-expanded={expanded}
|
|
127
|
+
>
|
|
128
|
+
{label}
|
|
129
|
+
</Button>
|
|
130
|
+
)}
|
|
131
|
+
/>
|
|
132
|
+
</div>
|
|
133
|
+
</PopoverContent>
|
|
134
|
+
</Popover>
|
|
135
|
+
);
|
|
136
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MixedNodeControl,
|
|
3
|
+
MixedDetailControl,
|
|
4
|
+
MixedCodeControl,
|
|
5
|
+
} from '@chobantonov/jsonforms-react-renderer-common/mixed/MixedDetailControl';
|
|
6
|
+
import { mixedParentNode } from '@chobantonov/jsonforms-react-renderer-common/mixed/mixedTreeActions';
|
|
7
|
+
import { useMixedRenderer } from '@chobantonov/jsonforms-react-renderer-common/mixed/useMixedRenderer';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { ContainerValidationIndicator } from '../layouts/ValidationIndicator';
|
|
10
|
+
import {
|
|
11
|
+
Breadcrumb,
|
|
12
|
+
BreadcrumbList,
|
|
13
|
+
BreadcrumbItem,
|
|
14
|
+
BreadcrumbLink,
|
|
15
|
+
BreadcrumbPage,
|
|
16
|
+
BreadcrumbSeparator,
|
|
17
|
+
} from '@jsonforms-react-shadcn-ui/breadcrumb';
|
|
18
|
+
import { validateAdditionalPropertyName } from '@chobantonov/jsonforms-react-renderer-common/objects/additionalPropertyName';
|
|
19
|
+
import {
|
|
20
|
+
ResizablePanelGroup,
|
|
21
|
+
ResizablePanel,
|
|
22
|
+
ResizableHandle,
|
|
23
|
+
} from '@jsonforms-react-shadcn-ui/resizable';
|
|
24
|
+
import { schemaForType } from '@chobantonov/jsonforms-react-renderer-common/mixed/mixedSchema';
|
|
25
|
+
export {
|
|
26
|
+
schemaForType,
|
|
27
|
+
isArrayElementPath,
|
|
28
|
+
isMixedSchema,
|
|
29
|
+
isMixedControl,
|
|
30
|
+
mixedControlTester,
|
|
31
|
+
} from '@chobantonov/jsonforms-react-renderer-common/mixed/mixedSchema';
|
|
32
|
+
export type { JsonDataType } from '@chobantonov/jsonforms-react-renderer-common/mixed/mixedSchema';
|
|
33
|
+
import { ControlProps } from '@jsonforms/core';
|
|
34
|
+
import { withJsonFormsControlProps } from '@jsonforms/react';
|
|
35
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
36
|
+
import {
|
|
37
|
+
Collapsible,
|
|
38
|
+
CollapsibleContent,
|
|
39
|
+
CollapsibleTrigger,
|
|
40
|
+
} from '@jsonforms-react-shadcn-ui/collapsible';
|
|
41
|
+
import { ChevronDown, ChevronUp } from 'lucide-react';
|
|
42
|
+
import {
|
|
43
|
+
MixedNavigationContext,
|
|
44
|
+
MixedTree,
|
|
45
|
+
MixedTypeSelector,
|
|
46
|
+
NestedMixedNavigation,
|
|
47
|
+
} from './mixed/MixedWidgets';
|
|
48
|
+
import { useConfirmation } from './mixed/useConfirmation';
|
|
49
|
+
import { MixedTreeNode } from '@chobantonov/jsonforms-react-renderer-common/mixed/mixedTree';
|
|
50
|
+
|
|
51
|
+
export const MixedRendererComponent = (props: ControlProps) => {
|
|
52
|
+
const { description, label, path, rootSchema, uischema } = props;
|
|
53
|
+
const confirmation = useConfirmation();
|
|
54
|
+
const model = useMixedRenderer(props, confirmation.request);
|
|
55
|
+
const {
|
|
56
|
+
appliedOptions,
|
|
57
|
+
structuredLayout,
|
|
58
|
+
t,
|
|
59
|
+
collapsible,
|
|
60
|
+
expanded,
|
|
61
|
+
setSelectedPath,
|
|
62
|
+
selectedType,
|
|
63
|
+
tree,
|
|
64
|
+
selectedNode,
|
|
65
|
+
canRenameNode,
|
|
66
|
+
} = model;
|
|
67
|
+
const parentNavigation = React.useContext(MixedNavigationContext);
|
|
68
|
+
|
|
69
|
+
const renderedControl = (
|
|
70
|
+
<MixedDetailControl
|
|
71
|
+
{...model.detailProps}
|
|
72
|
+
selectedType={selectedType}
|
|
73
|
+
selectedSchema={model.selectedSchema}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
const isStructuredType =
|
|
77
|
+
selectedType === 'object' || selectedType === 'array';
|
|
78
|
+
|
|
79
|
+
const selector = <MixedTypeSelector {...model.selectorProps} />;
|
|
80
|
+
const validateNodeRename = (node: MixedTreeNode, nextName: string) => {
|
|
81
|
+
const oldName = node.path[node.path.length - 1];
|
|
82
|
+
const parent = mixedParentNode(tree, node);
|
|
83
|
+
if (!parent || typeof oldName !== 'string' || !canRenameNode(node)) {
|
|
84
|
+
return t('mixed.renameBlocked');
|
|
85
|
+
}
|
|
86
|
+
const result = validateAdditionalPropertyName({
|
|
87
|
+
name: nextName,
|
|
88
|
+
currentName: oldName,
|
|
89
|
+
data: parent.data,
|
|
90
|
+
schema: schemaForType(parent.schema, 'object', rootSchema),
|
|
91
|
+
rootSchema,
|
|
92
|
+
validate: model.jsonforms.core?.ajv
|
|
93
|
+
? (schema, value) =>
|
|
94
|
+
Boolean(model.jsonforms.core!.ajv!.validate(schema, value))
|
|
95
|
+
: undefined,
|
|
96
|
+
});
|
|
97
|
+
if (result.error === 'required')
|
|
98
|
+
return t('additionalProperties.nameRequired');
|
|
99
|
+
if (result.error === 'already-defined')
|
|
100
|
+
return t('additionalProperties.nameTaken', { name: nextName });
|
|
101
|
+
if (result.error)
|
|
102
|
+
return t('additionalProperties.nameInvalid', { name: nextName });
|
|
103
|
+
return undefined;
|
|
104
|
+
};
|
|
105
|
+
const renameNode = (node: MixedTreeNode, nextName: string) => {
|
|
106
|
+
if (!validateNodeRename(node, nextName)) model.renameNode(node, nextName);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
if (!props.visible) return null;
|
|
110
|
+
|
|
111
|
+
if (structuredLayout === 'code') return <MixedCodeControl {...props} />;
|
|
112
|
+
|
|
113
|
+
if (structuredLayout === 'tree' && parentNavigation && isStructuredType) {
|
|
114
|
+
return (
|
|
115
|
+
<NestedMixedNavigation
|
|
116
|
+
description={description}
|
|
117
|
+
label={label}
|
|
118
|
+
onView={() => parentNavigation.selectPath(path)}
|
|
119
|
+
selector={selector}
|
|
120
|
+
/>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const content = (
|
|
125
|
+
<div
|
|
126
|
+
data-structured-layout={structuredLayout}
|
|
127
|
+
className='jsonforms-mixed-renderer min-w-0 space-y-2'
|
|
128
|
+
>
|
|
129
|
+
{confirmation.dialog}
|
|
130
|
+
{isStructuredType ? (
|
|
131
|
+
<Collapsible
|
|
132
|
+
open={expanded}
|
|
133
|
+
onOpenChange={model.setExpanded}
|
|
134
|
+
className='min-w-0'
|
|
135
|
+
>
|
|
136
|
+
{label && uischema.label !== false && (
|
|
137
|
+
<div className='shadcn-jsonforms-label mb-2'>{label}</div>
|
|
138
|
+
)}
|
|
139
|
+
<div className='flex items-center gap-3'>
|
|
140
|
+
<div className='w-36 shrink-0'>{selector}</div>
|
|
141
|
+
{model.validation.show && (
|
|
142
|
+
<ContainerValidationIndicator count={model.validation.count} />
|
|
143
|
+
)}
|
|
144
|
+
{collapsible ? (
|
|
145
|
+
<CollapsibleTrigger
|
|
146
|
+
render={<Button type='button' variant='ghost' />}
|
|
147
|
+
className='flex-1 justify-end'
|
|
148
|
+
aria-label={label || t('control.value')}
|
|
149
|
+
>
|
|
150
|
+
{expanded ? (
|
|
151
|
+
<ChevronUp aria-hidden='true' />
|
|
152
|
+
) : (
|
|
153
|
+
<ChevronDown aria-hidden='true' />
|
|
154
|
+
)}
|
|
155
|
+
</CollapsibleTrigger>
|
|
156
|
+
) : (
|
|
157
|
+
<span className='flex-1' />
|
|
158
|
+
)}
|
|
159
|
+
</div>
|
|
160
|
+
<CollapsibleContent keepMounted hidden={!expanded} className='pt-3'>
|
|
161
|
+
{structuredLayout === 'nested' && renderedControl}
|
|
162
|
+
{structuredLayout === 'tree' && tree && selectedNode && (
|
|
163
|
+
<ResizablePanelGroup orientation='horizontal' className='min-w-0'>
|
|
164
|
+
<ResizablePanel
|
|
165
|
+
defaultSize='30%'
|
|
166
|
+
minSize='20%'
|
|
167
|
+
className='pr-3'
|
|
168
|
+
>
|
|
169
|
+
<MixedTree
|
|
170
|
+
root={tree}
|
|
171
|
+
selectedPath={selectedNode.path}
|
|
172
|
+
onSelect={(node) => setSelectedPath(node.path)}
|
|
173
|
+
canDelete={model.canDeleteNode}
|
|
174
|
+
canRename={canRenameNode}
|
|
175
|
+
onDelete={model.deleteNode}
|
|
176
|
+
onRename={renameNode}
|
|
177
|
+
validateRename={validateNodeRename}
|
|
178
|
+
/>
|
|
179
|
+
</ResizablePanel>
|
|
180
|
+
<ResizableHandle withHandle />
|
|
181
|
+
<ResizablePanel minSize='30%' className='pl-3'>
|
|
182
|
+
<div className='min-w-0 space-y-2'>
|
|
183
|
+
<Breadcrumb aria-label={t('mixed.valuePath')}>
|
|
184
|
+
<BreadcrumbList>
|
|
185
|
+
{[
|
|
186
|
+
[],
|
|
187
|
+
...selectedNode.path.map((_, index) =>
|
|
188
|
+
selectedNode.path.slice(0, index + 1),
|
|
189
|
+
),
|
|
190
|
+
].map((nodePath, index) => (
|
|
191
|
+
<React.Fragment key={index}>
|
|
192
|
+
{index > 0 && <BreadcrumbSeparator />}
|
|
193
|
+
<BreadcrumbItem>
|
|
194
|
+
{index === selectedNode.path.length ? (
|
|
195
|
+
<BreadcrumbPage>
|
|
196
|
+
{index === 0
|
|
197
|
+
? label || t('control.value')
|
|
198
|
+
: String(nodePath[index - 1])}
|
|
199
|
+
</BreadcrumbPage>
|
|
200
|
+
) : (
|
|
201
|
+
<BreadcrumbLink asChild>
|
|
202
|
+
<button
|
|
203
|
+
type='button'
|
|
204
|
+
onClick={() => setSelectedPath(nodePath)}
|
|
205
|
+
>
|
|
206
|
+
{index === 0
|
|
207
|
+
? label || t('control.value')
|
|
208
|
+
: String(nodePath[index - 1])}
|
|
209
|
+
</button>
|
|
210
|
+
</BreadcrumbLink>
|
|
211
|
+
)}
|
|
212
|
+
</BreadcrumbItem>
|
|
213
|
+
</React.Fragment>
|
|
214
|
+
))}
|
|
215
|
+
</BreadcrumbList>
|
|
216
|
+
</Breadcrumb>
|
|
217
|
+
<MixedNodeControl
|
|
218
|
+
{...model.detailProps}
|
|
219
|
+
node={selectedNode}
|
|
220
|
+
{...model.nodeEditorProps}
|
|
221
|
+
MixedTypeSelector={MixedTypeSelector}
|
|
222
|
+
wrapStructured={(children) => (
|
|
223
|
+
<div className='space-y-2'>{children}</div>
|
|
224
|
+
)}
|
|
225
|
+
/>
|
|
226
|
+
</div>
|
|
227
|
+
</ResizablePanel>
|
|
228
|
+
</ResizablePanelGroup>
|
|
229
|
+
)}
|
|
230
|
+
</CollapsibleContent>
|
|
231
|
+
</Collapsible>
|
|
232
|
+
) : (
|
|
233
|
+
<>
|
|
234
|
+
{label && uischema.label !== false && (
|
|
235
|
+
<div className='shadcn-jsonforms-label'>
|
|
236
|
+
{label}
|
|
237
|
+
{props.required && !appliedOptions.hideRequiredAsterisk && ' *'}
|
|
238
|
+
</div>
|
|
239
|
+
)}
|
|
240
|
+
<div
|
|
241
|
+
className={
|
|
242
|
+
selectedType && selectedType !== 'null'
|
|
243
|
+
? 'jsonforms-mixed-renderer-primitive'
|
|
244
|
+
: ''
|
|
245
|
+
}
|
|
246
|
+
>
|
|
247
|
+
{selector}
|
|
248
|
+
<div className='min-w-0'>{renderedControl}</div>
|
|
249
|
+
</div>
|
|
250
|
+
</>
|
|
251
|
+
)}
|
|
252
|
+
</div>
|
|
253
|
+
);
|
|
254
|
+
return structuredLayout === 'nested' || parentNavigation ? (
|
|
255
|
+
content
|
|
256
|
+
) : (
|
|
257
|
+
<MixedNavigationContext.Provider value={model.navigation}>
|
|
258
|
+
{content}
|
|
259
|
+
</MixedNavigationContext.Provider>
|
|
260
|
+
);
|
|
261
|
+
};
|
|
262
|
+
export const MixedRenderer = withJsonFormsControlProps(MixedRendererComponent);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
createObjectRenderer,
|
|
4
|
+
type ObjectFrameProps,
|
|
5
|
+
} from '@chobantonov/jsonforms-react-renderer-common/objects/ObjectDetail';
|
|
6
|
+
export { objectControlTester } from '@chobantonov/jsonforms-react-renderer-common/objects/ObjectDetail';
|
|
7
|
+
import { ErrorIndicator } from './ErrorIndicator';
|
|
8
|
+
import { AdditionalProperties } from './AdditionalProperties';
|
|
9
|
+
|
|
10
|
+
const ObjectFrame = ({
|
|
11
|
+
path,
|
|
12
|
+
title,
|
|
13
|
+
errors,
|
|
14
|
+
detail,
|
|
15
|
+
additional,
|
|
16
|
+
}: ObjectFrameProps) => {
|
|
17
|
+
return (
|
|
18
|
+
<div className={path ? 'shadcn-jsonforms-object' : undefined}>
|
|
19
|
+
{title && (
|
|
20
|
+
<div className='flex items-center gap-1'>
|
|
21
|
+
<h3>{title}</h3>
|
|
22
|
+
{errors && <ErrorIndicator local errors={errors} />}
|
|
23
|
+
</div>
|
|
24
|
+
)}
|
|
25
|
+
{!title && errors && (
|
|
26
|
+
<div
|
|
27
|
+
role='alert'
|
|
28
|
+
className='text-sm text-destructive whitespace-pre-line'
|
|
29
|
+
>
|
|
30
|
+
{errors}
|
|
31
|
+
</div>
|
|
32
|
+
)}
|
|
33
|
+
{detail}
|
|
34
|
+
{additional}
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const ShadcnObjectRenderer = createObjectRenderer(
|
|
40
|
+
AdditionalProperties,
|
|
41
|
+
ObjectFrame,
|
|
42
|
+
true,
|
|
43
|
+
);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
CombinatorRendererProps,
|
|
4
|
+
isOneOfControl,
|
|
5
|
+
rankWith,
|
|
6
|
+
} from '@jsonforms/core';
|
|
7
|
+
import { withJsonFormsOneOfProps } from '@jsonforms/react';
|
|
8
|
+
import { ShadcnAnyOfRenderer } from './AnyOfRenderer';
|
|
9
|
+
|
|
10
|
+
export const ShadcnOneOfRenderer = (props: CombinatorRendererProps) => (
|
|
11
|
+
<ShadcnAnyOfRenderer {...props} combinator='oneOf' />
|
|
12
|
+
);
|
|
13
|
+
export const oneOfControlTester = rankWith(3, isOneOfControl);
|
|
14
|
+
export const ShadcnOneOfControl = withJsonFormsOneOfProps(ShadcnOneOfRenderer);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useConfirmation } from './mixed/useConfirmation';
|
|
3
|
+
import {
|
|
4
|
+
createRecursiveTreeRenderer,
|
|
5
|
+
recursiveTreeTester,
|
|
6
|
+
} from '@chobantonov/jsonforms-react-renderer-common/mixed/RecursiveTreeRenderer';
|
|
7
|
+
import { ContainerValidationIndicator } from '../layouts/ValidationIndicator';
|
|
8
|
+
import { MixedTree as Tree } from './mixed/MixedWidgets';
|
|
9
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
10
|
+
export { recursiveTreeTester };
|
|
11
|
+
export const RecursiveTreeRenderer = createRecursiveTreeRenderer(
|
|
12
|
+
Tree,
|
|
13
|
+
ContainerValidationIndicator,
|
|
14
|
+
({ children, onClick }) => (
|
|
15
|
+
<Button variant='link' type='button' onClick={onClick}>
|
|
16
|
+
{children}
|
|
17
|
+
</Button>
|
|
18
|
+
),
|
|
19
|
+
useConfirmation,
|
|
20
|
+
);
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { ScrollRegion } from '../components/ScrollRegion';
|
|
2
|
+
import { DetailDialogContent } from '../complex/DetailDialogContent';
|
|
3
|
+
import { Eye, EyeOff, Pencil } from 'lucide-react';
|
|
4
|
+
import {
|
|
5
|
+
Tooltip,
|
|
6
|
+
TooltipProvider,
|
|
7
|
+
TooltipTrigger,
|
|
8
|
+
TooltipContent,
|
|
9
|
+
} from '@jsonforms-react-shadcn-ui/tooltip';
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import {
|
|
12
|
+
type RowDetailState,
|
|
13
|
+
createRowDetailToggle,
|
|
14
|
+
createRowDetailFrame,
|
|
15
|
+
} from '@chobantonov/jsonforms-react-renderer-common/collections/rowDetail';
|
|
16
|
+
import {
|
|
17
|
+
Dialog,
|
|
18
|
+
DialogHeader,
|
|
19
|
+
DialogTitle,
|
|
20
|
+
DialogFooter,
|
|
21
|
+
} from '@jsonforms-react-shadcn-ui/dialog';
|
|
22
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
23
|
+
import {
|
|
24
|
+
ResizablePanelGroup,
|
|
25
|
+
ResizablePanel,
|
|
26
|
+
ResizableHandle,
|
|
27
|
+
} from '@jsonforms-react-shadcn-ui/resizable';
|
|
28
|
+
const RowDialog = ({ state }: { state: RowDetailState }) => {
|
|
29
|
+
const { options, t } = state;
|
|
30
|
+
return (
|
|
31
|
+
<Dialog
|
|
32
|
+
open={!!state.selection}
|
|
33
|
+
onOpenChange={(open) => !open && state.close()}
|
|
34
|
+
>
|
|
35
|
+
<DetailDialogContent
|
|
36
|
+
open={!!state.selection}
|
|
37
|
+
options={options.dialog}
|
|
38
|
+
aria-describedby={undefined}
|
|
39
|
+
>
|
|
40
|
+
<DialogHeader>
|
|
41
|
+
<DialogTitle>{t('collection.editDetails')}</DialogTitle>
|
|
42
|
+
</DialogHeader>
|
|
43
|
+
<div className='p-1'>
|
|
44
|
+
{state.conflict && <p role='alert'>{t('composite.applyConflict')}</p>}
|
|
45
|
+
{state.content}
|
|
46
|
+
</div>
|
|
47
|
+
<DialogFooter>
|
|
48
|
+
<Button type='button' variant='outline' onClick={state.close}>
|
|
49
|
+
{t('composite.cancel')}
|
|
50
|
+
</Button>
|
|
51
|
+
<Button
|
|
52
|
+
type='button'
|
|
53
|
+
disabled={!state.enabled || state.conflict}
|
|
54
|
+
onClick={state.apply}
|
|
55
|
+
>
|
|
56
|
+
{t('composite.apply')}
|
|
57
|
+
</Button>
|
|
58
|
+
</DialogFooter>
|
|
59
|
+
</DetailDialogContent>
|
|
60
|
+
</Dialog>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
const RowPanel = ({
|
|
64
|
+
state,
|
|
65
|
+
children,
|
|
66
|
+
}: React.PropsWithChildren<{ state: RowDetailState }>) => {
|
|
67
|
+
const { options, panelOpen } = state;
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
<ResizablePanelGroup
|
|
71
|
+
orientation={options.placement === 'bottom' ? 'vertical' : 'horizontal'}
|
|
72
|
+
// Percentage-sized panels need a definite height, even with one panel.
|
|
73
|
+
style={{
|
|
74
|
+
height:
|
|
75
|
+
panelOpen && options.placement === 'bottom' ? '40rem' : '32rem',
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
<ResizablePanel defaultSize='55%' minSize='20%'>
|
|
79
|
+
<ScrollRegion
|
|
80
|
+
className='shadcn-jsonforms-collection-pane'
|
|
81
|
+
style={{ height: '100%' }}
|
|
82
|
+
>
|
|
83
|
+
{children}
|
|
84
|
+
</ScrollRegion>
|
|
85
|
+
</ResizablePanel>
|
|
86
|
+
{panelOpen && options.resizable !== false && (
|
|
87
|
+
<ResizableHandle withHandle />
|
|
88
|
+
)}
|
|
89
|
+
{panelOpen && (
|
|
90
|
+
<ResizablePanel minSize='20%'>
|
|
91
|
+
<ScrollRegion style={{ height: '100%' }}>
|
|
92
|
+
<div className='p-3'>
|
|
93
|
+
{state.content ?? state.t('collection.selectItem')}
|
|
94
|
+
</div>
|
|
95
|
+
</ScrollRegion>
|
|
96
|
+
</ResizablePanel>
|
|
97
|
+
)}
|
|
98
|
+
</ResizablePanelGroup>
|
|
99
|
+
</div>
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const RowDetailFrame = createRowDetailFrame(RowDialog, RowPanel);
|
|
104
|
+
|
|
105
|
+
export const RowDetailToggle = createRowDetailToggle((toggle) => (
|
|
106
|
+
<div className='flex items-center'>
|
|
107
|
+
<TooltipProvider>
|
|
108
|
+
<Tooltip>
|
|
109
|
+
<TooltipTrigger asChild>
|
|
110
|
+
<Button
|
|
111
|
+
type='button'
|
|
112
|
+
variant='ghost'
|
|
113
|
+
size='icon-sm'
|
|
114
|
+
aria-label={toggle.label}
|
|
115
|
+
aria-expanded={toggle.expanded}
|
|
116
|
+
onClick={toggle.toggle}
|
|
117
|
+
>
|
|
118
|
+
{toggle.expanded ? (
|
|
119
|
+
<EyeOff aria-hidden='true' />
|
|
120
|
+
) : (
|
|
121
|
+
<Eye aria-hidden='true' />
|
|
122
|
+
)}
|
|
123
|
+
</Button>
|
|
124
|
+
</TooltipTrigger>
|
|
125
|
+
<TooltipContent>{toggle.label}</TooltipContent>
|
|
126
|
+
</Tooltip>
|
|
127
|
+
</TooltipProvider>
|
|
128
|
+
</div>
|
|
129
|
+
));
|
|
130
|
+
|
|
131
|
+
/** Shared row edit action for native tables and AG Grid. */
|
|
132
|
+
export const RowDetailEditButton = ({
|
|
133
|
+
label,
|
|
134
|
+
onClick,
|
|
135
|
+
disabled,
|
|
136
|
+
}: {
|
|
137
|
+
label: string;
|
|
138
|
+
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
139
|
+
disabled?: boolean;
|
|
140
|
+
}) => (
|
|
141
|
+
<TooltipProvider>
|
|
142
|
+
<Tooltip>
|
|
143
|
+
<TooltipTrigger asChild>
|
|
144
|
+
<Button
|
|
145
|
+
type='button'
|
|
146
|
+
variant='ghost'
|
|
147
|
+
size='icon-sm'
|
|
148
|
+
aria-label={label}
|
|
149
|
+
disabled={disabled}
|
|
150
|
+
onClick={onClick}
|
|
151
|
+
>
|
|
152
|
+
<Pencil className='h-4 w-4' aria-hidden='true' />
|
|
153
|
+
</Button>
|
|
154
|
+
</TooltipTrigger>
|
|
155
|
+
<TooltipContent>{label}</TooltipContent>
|
|
156
|
+
</Tooltip>
|
|
157
|
+
</TooltipProvider>
|
|
158
|
+
);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ControlProps } from '@jsonforms/core';
|
|
3
|
+
import { withJsonFormsControlProps } from '@jsonforms/react';
|
|
4
|
+
import { ScalarCompositionControl } from '@chobantonov/jsonforms-react-renderer-common/composition/ScalarCompositionControl';
|
|
5
|
+
export { scalarCompositionTester } from '@chobantonov/jsonforms-react-renderer-common/composition/useScalarComposition';
|
|
6
|
+
const MESSAGE_STYLE: React.CSSProperties = { marginBottom: 16 };
|
|
7
|
+
|
|
8
|
+
export default withJsonFormsControlProps((props: ControlProps) => (
|
|
9
|
+
<ScalarCompositionControl
|
|
10
|
+
{...props}
|
|
11
|
+
errorClassName='text-destructive text-sm'
|
|
12
|
+
errorStyle={MESSAGE_STYLE}
|
|
13
|
+
/>
|
|
14
|
+
));
|