@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,535 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CollectionErrorNavigation,
|
|
3
|
+
RowErrorCount,
|
|
4
|
+
} from '@chobantonov/jsonforms-react-renderer-common/collections/CollectionErrorNavigation';
|
|
5
|
+
import { ItemProvider } from '@chobantonov/jsonforms-react-renderer-common/cells/CellSummary';
|
|
6
|
+
import {
|
|
7
|
+
Tooltip,
|
|
8
|
+
TooltipProvider,
|
|
9
|
+
TooltipTrigger,
|
|
10
|
+
TooltipContent,
|
|
11
|
+
} from '@jsonforms-react-shadcn-ui/tooltip';
|
|
12
|
+
import { ErrorIndicator } from '../ErrorIndicator';
|
|
13
|
+
import {
|
|
14
|
+
ColumnResizeHandle,
|
|
15
|
+
useColumnWidths,
|
|
16
|
+
} from '@chobantonov/jsonforms-react-renderer-common/collections/columnResize';
|
|
17
|
+
import {
|
|
18
|
+
tableColumnFields,
|
|
19
|
+
tableColumnStyle,
|
|
20
|
+
TableColumnDefinition,
|
|
21
|
+
} from '@chobantonov/jsonforms-react-renderer-common/collections/tableColumns';
|
|
22
|
+
import { useTableSelection } from '@chobantonov/jsonforms-react-renderer-common/collections/useTableSelection';
|
|
23
|
+
import { Checkbox } from '@jsonforms-react-shadcn-ui/checkbox';
|
|
24
|
+
import { useRowDetail } from '@chobantonov/jsonforms-react-renderer-common/collections/rowDetail';
|
|
25
|
+
import { CollectionPager } from '../CollectionPager';
|
|
26
|
+
import { RowDetailFrame, RowDetailEditButton } from '../RowDetailFrame';
|
|
27
|
+
import {
|
|
28
|
+
ArrayLayoutProps,
|
|
29
|
+
CellProps,
|
|
30
|
+
composePaths,
|
|
31
|
+
createCleanLabel,
|
|
32
|
+
Resolve,
|
|
33
|
+
} from '@jsonforms/core';
|
|
34
|
+
import { DispatchCell, withJsonFormsCellProps } from '@jsonforms/react';
|
|
35
|
+
import React from 'react';
|
|
36
|
+
import { ChevronUp, ChevronDown } from 'lucide-react';
|
|
37
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
38
|
+
import type { CollectionPage } from '@chobantonov/jsonforms-react-renderer-common/collections/collectionPagination';
|
|
39
|
+
const TableCellErrors = withJsonFormsCellProps(
|
|
40
|
+
({ errors, path, schema, uischema }: CellProps) =>
|
|
41
|
+
errors &&
|
|
42
|
+
uischema.options?.summary?.type !== 'Label' &&
|
|
43
|
+
schema.type !== 'object' &&
|
|
44
|
+
schema.type !== 'array' ? (
|
|
45
|
+
<ErrorIndicator
|
|
46
|
+
local
|
|
47
|
+
errors={errors}
|
|
48
|
+
path={path}
|
|
49
|
+
className='shadcn-jsonforms-cell-error'
|
|
50
|
+
/>
|
|
51
|
+
) : null,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
type ArrayTableProps = ArrayLayoutProps & {
|
|
55
|
+
options: NonNullable<ArrayLayoutProps['uischema']['options']>;
|
|
56
|
+
rowDetail: ReturnType<typeof useRowDetail>;
|
|
57
|
+
page: CollectionPage;
|
|
58
|
+
selection: ReturnType<typeof useTableSelection>;
|
|
59
|
+
columnSizes: ReturnType<typeof useColumnWidths>;
|
|
60
|
+
translations: {
|
|
61
|
+
upAriaLabel: string;
|
|
62
|
+
up: string;
|
|
63
|
+
downAriaLabel: string;
|
|
64
|
+
down: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export function ArrayTable(props: ArrayTableProps) {
|
|
69
|
+
const {
|
|
70
|
+
schema,
|
|
71
|
+
rootSchema,
|
|
72
|
+
uischema,
|
|
73
|
+
path,
|
|
74
|
+
label,
|
|
75
|
+
options,
|
|
76
|
+
rowDetail,
|
|
77
|
+
page,
|
|
78
|
+
selection,
|
|
79
|
+
columnSizes,
|
|
80
|
+
} = props;
|
|
81
|
+
const [columnWidths] = columnSizes;
|
|
82
|
+
const columns = resolveTableColumns(
|
|
83
|
+
schema,
|
|
84
|
+
rootSchema,
|
|
85
|
+
uischema,
|
|
86
|
+
options,
|
|
87
|
+
columnWidths,
|
|
88
|
+
);
|
|
89
|
+
const objectRows = Boolean(schema.properties);
|
|
90
|
+
const hasRowActions = Boolean(rowDetail.options || options.showSortButtons);
|
|
91
|
+
const tableWidth = columnWidths.__selection
|
|
92
|
+
? Object.values(columnWidths).reduce((sum, width) => sum + width, 0)
|
|
93
|
+
: undefined;
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<RowDetailFrame state={rowDetail}>
|
|
97
|
+
<div
|
|
98
|
+
className='min-w-0 w-full max-w-full overflow-x-auto'
|
|
99
|
+
style={{ contain: 'inline-size' }}
|
|
100
|
+
>
|
|
101
|
+
<table
|
|
102
|
+
className='text-sm'
|
|
103
|
+
style={{
|
|
104
|
+
flexShrink: 0,
|
|
105
|
+
minWidth: tableWidth,
|
|
106
|
+
width: tableWidth ?? '100%',
|
|
107
|
+
tableLayout: columnWidths.__selection ? 'fixed' : 'auto',
|
|
108
|
+
}}
|
|
109
|
+
aria-label={label}
|
|
110
|
+
>
|
|
111
|
+
{objectRows && (
|
|
112
|
+
<ArrayTableHead
|
|
113
|
+
columns={columns}
|
|
114
|
+
columnSizes={columnSizes}
|
|
115
|
+
page={page}
|
|
116
|
+
selection={selection}
|
|
117
|
+
selectPageLabel={rowDetail.t('collection.selectPage')}
|
|
118
|
+
hasRowActions={hasRowActions}
|
|
119
|
+
schema={schema}
|
|
120
|
+
options={options}
|
|
121
|
+
/>
|
|
122
|
+
)}
|
|
123
|
+
<tbody>
|
|
124
|
+
{page.indices.map((index) => (
|
|
125
|
+
<ArrayTableRow
|
|
126
|
+
key={composePaths(path, String(index))}
|
|
127
|
+
table={props}
|
|
128
|
+
index={index}
|
|
129
|
+
columns={columns}
|
|
130
|
+
hasRowActions={hasRowActions}
|
|
131
|
+
/>
|
|
132
|
+
))}
|
|
133
|
+
</tbody>
|
|
134
|
+
</table>
|
|
135
|
+
<CollectionErrorNavigation
|
|
136
|
+
options={uischema.options}
|
|
137
|
+
renderAction={renderErrorNavigationButton}
|
|
138
|
+
path={path}
|
|
139
|
+
reveal={(index) => {
|
|
140
|
+
page.change(Math.floor(index / page.size) + 1);
|
|
141
|
+
if (rowDetail.options) {
|
|
142
|
+
rowDetail.setPanelOpen(true);
|
|
143
|
+
rowDetail.open(index);
|
|
144
|
+
}
|
|
145
|
+
}}
|
|
146
|
+
/>
|
|
147
|
+
<CollectionPager page={page} />
|
|
148
|
+
</div>
|
|
149
|
+
</RowDetailFrame>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function resolveTableColumns(
|
|
154
|
+
schema: ArrayLayoutProps['schema'],
|
|
155
|
+
rootSchema: ArrayLayoutProps['rootSchema'],
|
|
156
|
+
uischema: ArrayLayoutProps['uischema'],
|
|
157
|
+
options: ArrayTableProps['options'],
|
|
158
|
+
columnWidths: Record<string, number>,
|
|
159
|
+
) {
|
|
160
|
+
const definitions = uischema.options?.columnDefs as
|
|
161
|
+
| TableColumnDefinition[]
|
|
162
|
+
| undefined;
|
|
163
|
+
const properties = schema.properties ?? { value: schema };
|
|
164
|
+
const objectRows = Boolean(schema.properties);
|
|
165
|
+
return tableColumnFields(
|
|
166
|
+
properties,
|
|
167
|
+
objectRows ? definitions : undefined,
|
|
168
|
+
Object.keys(properties),
|
|
169
|
+
).map((field) => {
|
|
170
|
+
const definition = definitions?.find((column) => column.field === field);
|
|
171
|
+
const rowBound = definitions?.some(
|
|
172
|
+
(column) => column.field === field && column.scope === '#',
|
|
173
|
+
);
|
|
174
|
+
const source = rowBound ? schema : properties[field];
|
|
175
|
+
const column = source.$ref
|
|
176
|
+
? Resolve.schema(source, '#', rootSchema)
|
|
177
|
+
: source;
|
|
178
|
+
const style = tableColumnStyle(definition);
|
|
179
|
+
const width = columnWidths[field];
|
|
180
|
+
const cellOptions = options.cells?.[field];
|
|
181
|
+
return {
|
|
182
|
+
field,
|
|
183
|
+
column,
|
|
184
|
+
definition,
|
|
185
|
+
propertyBound: objectRows && !rowBound,
|
|
186
|
+
cellOptions,
|
|
187
|
+
editorOptions: {
|
|
188
|
+
...cellOptions,
|
|
189
|
+
...(rowBound ? { summaryOnly: true } : {}),
|
|
190
|
+
},
|
|
191
|
+
header: columnHeader(field, column.title, definition),
|
|
192
|
+
maxWidth: style.maxWidth,
|
|
193
|
+
style:
|
|
194
|
+
width === undefined
|
|
195
|
+
? style
|
|
196
|
+
: { ...style, width, minWidth: width, maxWidth: width },
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function selectionColumnStyle(width = 32) {
|
|
202
|
+
return { width, minWidth: 32, maxWidth: width };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function ArrayTableHead({
|
|
206
|
+
columns,
|
|
207
|
+
columnSizes,
|
|
208
|
+
page,
|
|
209
|
+
selection,
|
|
210
|
+
selectPageLabel,
|
|
211
|
+
hasRowActions,
|
|
212
|
+
schema,
|
|
213
|
+
options,
|
|
214
|
+
}: Pick<
|
|
215
|
+
ArrayTableProps,
|
|
216
|
+
'columnSizes' | 'page' | 'selection' | 'schema' | 'options'
|
|
217
|
+
> & {
|
|
218
|
+
columns: ReturnType<typeof resolveTableColumns>;
|
|
219
|
+
selectPageLabel: string;
|
|
220
|
+
hasRowActions: boolean;
|
|
221
|
+
}) {
|
|
222
|
+
const [columnWidths, setColumnWidths] = columnSizes;
|
|
223
|
+
const selectedCount = page.indices.filter((index) =>
|
|
224
|
+
selection.selected.includes(index),
|
|
225
|
+
).length;
|
|
226
|
+
const pageChecked =
|
|
227
|
+
selectedCount > 0 && selectedCount < page.indices.length
|
|
228
|
+
? 'indeterminate'
|
|
229
|
+
: selectedCount > 0;
|
|
230
|
+
return (
|
|
231
|
+
<thead>
|
|
232
|
+
<tr className='border-b'>
|
|
233
|
+
<th
|
|
234
|
+
data-column-key='__selection'
|
|
235
|
+
style={selectionColumnStyle(columnWidths.__selection)}
|
|
236
|
+
className='p-2 text-center'
|
|
237
|
+
>
|
|
238
|
+
<Checkbox
|
|
239
|
+
className='shadcn-jsonforms-row-selection align-middle'
|
|
240
|
+
aria-label={selectPageLabel}
|
|
241
|
+
disabled={!selection.selectable || !page.indices.length}
|
|
242
|
+
checked={pageChecked}
|
|
243
|
+
onCheckedChange={(checked) =>
|
|
244
|
+
selection.setSelected(
|
|
245
|
+
checked === true
|
|
246
|
+
? [...new Set([...selection.selected, ...page.indices])]
|
|
247
|
+
: selection.selected.filter((i) => !page.indices.includes(i)),
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
/>
|
|
251
|
+
</th>
|
|
252
|
+
{columns.map(({ field, definition, header, style }) => (
|
|
253
|
+
<th
|
|
254
|
+
key={field}
|
|
255
|
+
data-column-key={field}
|
|
256
|
+
style={style}
|
|
257
|
+
className='relative p-2 pe-4 text-left font-medium'
|
|
258
|
+
>
|
|
259
|
+
{header}
|
|
260
|
+
{schema.required?.includes(field) &&
|
|
261
|
+
!(
|
|
262
|
+
options.cells?.[field]?.hideRequiredAsterisk ??
|
|
263
|
+
options.hideRequiredAsterisk
|
|
264
|
+
) && <span aria-hidden='true'> *</span>}
|
|
265
|
+
<ColumnResizeHandle
|
|
266
|
+
colors={{
|
|
267
|
+
border: 'hsl(var(--muted-foreground) / 0.5)',
|
|
268
|
+
active: 'hsl(var(--primary))',
|
|
269
|
+
focus: 'hsl(var(--ring))',
|
|
270
|
+
}}
|
|
271
|
+
field={header}
|
|
272
|
+
definition={definition}
|
|
273
|
+
width={columnWidths[field]}
|
|
274
|
+
onResizeStart={(widths) => setColumnWidths(widths)}
|
|
275
|
+
onResize={(value) =>
|
|
276
|
+
setColumnWidths((current) => ({
|
|
277
|
+
...current,
|
|
278
|
+
[field]: value,
|
|
279
|
+
}))
|
|
280
|
+
}
|
|
281
|
+
/>
|
|
282
|
+
</th>
|
|
283
|
+
))}
|
|
284
|
+
{hasRowActions && (
|
|
285
|
+
<th
|
|
286
|
+
data-column-key='__actions'
|
|
287
|
+
style={{ width: columnWidths.__actions ?? 1 }}
|
|
288
|
+
className='whitespace-nowrap p-2'
|
|
289
|
+
/>
|
|
290
|
+
)}
|
|
291
|
+
</tr>
|
|
292
|
+
</thead>
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function ArrayRowActions({
|
|
297
|
+
index,
|
|
298
|
+
rowDetail,
|
|
299
|
+
showSortButtons,
|
|
300
|
+
path,
|
|
301
|
+
enabled,
|
|
302
|
+
readonly,
|
|
303
|
+
data,
|
|
304
|
+
moveUp,
|
|
305
|
+
moveDown,
|
|
306
|
+
translations,
|
|
307
|
+
}: Pick<
|
|
308
|
+
ArrayTableProps,
|
|
309
|
+
| 'rowDetail'
|
|
310
|
+
| 'path'
|
|
311
|
+
| 'enabled'
|
|
312
|
+
| 'readonly'
|
|
313
|
+
| 'data'
|
|
314
|
+
| 'moveUp'
|
|
315
|
+
| 'moveDown'
|
|
316
|
+
| 'translations'
|
|
317
|
+
> & { index: number; showSortButtons: boolean }) {
|
|
318
|
+
const editable = enabled && !readonly;
|
|
319
|
+
return (
|
|
320
|
+
<div className='flex w-max flex-nowrap items-center gap-1'>
|
|
321
|
+
{rowDetail.options && (
|
|
322
|
+
<RowDetailEditButton
|
|
323
|
+
label={rowDetail.t('collection.editDetails')}
|
|
324
|
+
onClick={(event) => {
|
|
325
|
+
event.stopPropagation();
|
|
326
|
+
if (rowDetail.options?.presentation === 'panel')
|
|
327
|
+
rowDetail.setPanelOpen(true);
|
|
328
|
+
rowDetail.open(index);
|
|
329
|
+
}}
|
|
330
|
+
/>
|
|
331
|
+
)}
|
|
332
|
+
<RowErrorCount
|
|
333
|
+
path={path}
|
|
334
|
+
index={index}
|
|
335
|
+
renderIndicator={(message) => <ErrorIndicator errors={message} />}
|
|
336
|
+
/>
|
|
337
|
+
{showSortButtons && (
|
|
338
|
+
<>
|
|
339
|
+
<Button
|
|
340
|
+
type='button'
|
|
341
|
+
variant='ghost'
|
|
342
|
+
size='icon'
|
|
343
|
+
className='h-7 w-7'
|
|
344
|
+
aria-label={translations.upAriaLabel}
|
|
345
|
+
title={translations.up}
|
|
346
|
+
disabled={!editable || index === 0}
|
|
347
|
+
onClick={moveUp?.(path, index)}
|
|
348
|
+
>
|
|
349
|
+
<ChevronUp className='h-4 w-4' aria-hidden='true' />
|
|
350
|
+
</Button>
|
|
351
|
+
<Button
|
|
352
|
+
type='button'
|
|
353
|
+
variant='ghost'
|
|
354
|
+
size='icon'
|
|
355
|
+
className='h-7 w-7'
|
|
356
|
+
aria-label={translations.downAriaLabel}
|
|
357
|
+
title={translations.down}
|
|
358
|
+
disabled={!editable || index === data - 1}
|
|
359
|
+
onClick={moveDown?.(path, index)}
|
|
360
|
+
>
|
|
361
|
+
<ChevronDown className='h-4 w-4' aria-hidden='true' />
|
|
362
|
+
</Button>
|
|
363
|
+
</>
|
|
364
|
+
)}
|
|
365
|
+
</div>
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function renderErrorNavigationButton(
|
|
370
|
+
label: string,
|
|
371
|
+
onClick: () => void,
|
|
372
|
+
icon: React.ReactNode,
|
|
373
|
+
) {
|
|
374
|
+
return (
|
|
375
|
+
<TooltipProvider>
|
|
376
|
+
<Tooltip>
|
|
377
|
+
<TooltipTrigger asChild>
|
|
378
|
+
<Button
|
|
379
|
+
type='button'
|
|
380
|
+
variant='outline'
|
|
381
|
+
size='icon'
|
|
382
|
+
className='h-7 w-7'
|
|
383
|
+
aria-label={label}
|
|
384
|
+
onClick={onClick}
|
|
385
|
+
>
|
|
386
|
+
{icon}
|
|
387
|
+
</Button>
|
|
388
|
+
</TooltipTrigger>
|
|
389
|
+
<TooltipContent>{label}</TooltipContent>
|
|
390
|
+
</Tooltip>
|
|
391
|
+
</TooltipProvider>
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function columnHeader(
|
|
396
|
+
field: string,
|
|
397
|
+
title: string | undefined,
|
|
398
|
+
definition: TableColumnDefinition | undefined,
|
|
399
|
+
) {
|
|
400
|
+
return definition?.headerName ?? title ?? createCleanLabel(field);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function ArrayTableRow({
|
|
404
|
+
table,
|
|
405
|
+
index,
|
|
406
|
+
columns,
|
|
407
|
+
hasRowActions,
|
|
408
|
+
}: {
|
|
409
|
+
table: ArrayTableProps;
|
|
410
|
+
index: number;
|
|
411
|
+
columns: ReturnType<typeof resolveTableColumns>;
|
|
412
|
+
hasRowActions: boolean;
|
|
413
|
+
}) {
|
|
414
|
+
const {
|
|
415
|
+
path,
|
|
416
|
+
enabled,
|
|
417
|
+
readonly,
|
|
418
|
+
data,
|
|
419
|
+
moveUp,
|
|
420
|
+
moveDown,
|
|
421
|
+
translations,
|
|
422
|
+
rowDetail,
|
|
423
|
+
options,
|
|
424
|
+
selection,
|
|
425
|
+
renderers,
|
|
426
|
+
cells,
|
|
427
|
+
} = table;
|
|
428
|
+
const [columnWidths] = table.columnSizes;
|
|
429
|
+
|
|
430
|
+
const actionProps = {
|
|
431
|
+
rowDetail,
|
|
432
|
+
showSortButtons: options.showSortButtons,
|
|
433
|
+
path,
|
|
434
|
+
enabled,
|
|
435
|
+
readonly,
|
|
436
|
+
data,
|
|
437
|
+
moveUp,
|
|
438
|
+
moveDown,
|
|
439
|
+
translations,
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
const rowPath = composePaths(path, String(index));
|
|
443
|
+
const panel = rowDetail.options?.presentation === 'panel';
|
|
444
|
+
const current =
|
|
445
|
+
panel && rowDetail.panelOpen && rowDetail.selection?.index === index;
|
|
446
|
+
return (
|
|
447
|
+
<tr
|
|
448
|
+
className={current ? 'border-b bg-accent' : 'border-b'}
|
|
449
|
+
aria-current={current || undefined}
|
|
450
|
+
onClick={() => {
|
|
451
|
+
if (panel) {
|
|
452
|
+
rowDetail.open(index);
|
|
453
|
+
}
|
|
454
|
+
}}
|
|
455
|
+
>
|
|
456
|
+
<td
|
|
457
|
+
className='p-2 text-center'
|
|
458
|
+
style={selectionColumnStyle(columnWidths.__selection)}
|
|
459
|
+
onClick={(event) => event.stopPropagation()}
|
|
460
|
+
>
|
|
461
|
+
<Checkbox
|
|
462
|
+
className='shadcn-jsonforms-row-selection align-middle'
|
|
463
|
+
aria-label={rowDetail.t('collection.selectRow', {
|
|
464
|
+
index: index + 1,
|
|
465
|
+
})}
|
|
466
|
+
disabled={!selection.selectable}
|
|
467
|
+
checked={selection.selected.includes(index)}
|
|
468
|
+
onCheckedChange={(checked) =>
|
|
469
|
+
selection.setSelected(
|
|
470
|
+
checked === true
|
|
471
|
+
? [...selection.selected, index]
|
|
472
|
+
: selection.selected.filter((i) => i !== index),
|
|
473
|
+
)
|
|
474
|
+
}
|
|
475
|
+
/>
|
|
476
|
+
</td>
|
|
477
|
+
{columns.map(
|
|
478
|
+
({
|
|
479
|
+
field,
|
|
480
|
+
column,
|
|
481
|
+
style,
|
|
482
|
+
maxWidth,
|
|
483
|
+
propertyBound,
|
|
484
|
+
editorOptions,
|
|
485
|
+
cellOptions,
|
|
486
|
+
}) => {
|
|
487
|
+
const cellPath = propertyBound
|
|
488
|
+
? composePaths(rowPath, field)
|
|
489
|
+
: rowPath;
|
|
490
|
+
return (
|
|
491
|
+
<td
|
|
492
|
+
key={field}
|
|
493
|
+
style={style}
|
|
494
|
+
className='shadcn-jsonforms-table-cell p-2'
|
|
495
|
+
>
|
|
496
|
+
<div style={{ maxWidth, overflow: 'hidden' }}>
|
|
497
|
+
<ItemProvider path={rowPath}>
|
|
498
|
+
<DispatchCell
|
|
499
|
+
schema={column}
|
|
500
|
+
uischema={{
|
|
501
|
+
type: 'Control',
|
|
502
|
+
scope: propertyBound ? '#/properties/' + field : '#',
|
|
503
|
+
options: editorOptions,
|
|
504
|
+
}}
|
|
505
|
+
path={cellPath}
|
|
506
|
+
enabled={enabled && !readonly && !(column as any).readOnly}
|
|
507
|
+
renderers={renderers}
|
|
508
|
+
cells={cells}
|
|
509
|
+
/>
|
|
510
|
+
</ItemProvider>
|
|
511
|
+
<TableCellErrors
|
|
512
|
+
schema={column}
|
|
513
|
+
uischema={{
|
|
514
|
+
type: 'Control',
|
|
515
|
+
scope: '#',
|
|
516
|
+
options: cellOptions,
|
|
517
|
+
}}
|
|
518
|
+
path={cellPath}
|
|
519
|
+
/>
|
|
520
|
+
</div>
|
|
521
|
+
</td>
|
|
522
|
+
);
|
|
523
|
+
},
|
|
524
|
+
)}
|
|
525
|
+
{hasRowActions && (
|
|
526
|
+
<td
|
|
527
|
+
className='whitespace-nowrap p-2'
|
|
528
|
+
style={{ width: columnWidths.__actions ?? 1 }}
|
|
529
|
+
>
|
|
530
|
+
<ArrayRowActions index={index} {...actionProps} />
|
|
531
|
+
</td>
|
|
532
|
+
)}
|
|
533
|
+
</tr>
|
|
534
|
+
);
|
|
535
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './AdditionalProperties';
|
|
2
|
+
export {
|
|
3
|
+
AllOfRenderer as ShadcnAllOfRenderer,
|
|
4
|
+
AllOfControl as ShadcnAllOfControl,
|
|
5
|
+
allOfControlTester,
|
|
6
|
+
} from '@chobantonov/jsonforms-react-renderer-common/composition/AllOfRenderer';
|
|
7
|
+
export * from './AnyOfRenderer';
|
|
8
|
+
export * from './ArrayControlRenderer';
|
|
9
|
+
export * from '@chobantonov/jsonforms-react-renderer-common/composition/CombinatorProperties';
|
|
10
|
+
export * from './CombinatorSwitchDialog';
|
|
11
|
+
export * from './MixedRenderer';
|
|
12
|
+
export * from './ObjectRenderer';
|
|
13
|
+
|
|
14
|
+
export * from './OneOfRenderer';
|
|
15
|
+
|
|
16
|
+
export * from './TupleControlRenderer';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
// Keep the shapes in sync with the Svelte renderers' JsonTypeIcon.
|
|
4
|
+
export const JsonTypeIcon = ({
|
|
5
|
+
type,
|
|
6
|
+
active = false,
|
|
7
|
+
}: {
|
|
8
|
+
type: string | null;
|
|
9
|
+
active?: boolean;
|
|
10
|
+
}) => (
|
|
11
|
+
<svg
|
|
12
|
+
aria-hidden='true'
|
|
13
|
+
data-json-type={type}
|
|
14
|
+
className={`h-4 w-4 shrink-0 fill-none stroke-current ${
|
|
15
|
+
active ? 'text-foreground' : 'text-muted-foreground'
|
|
16
|
+
}`}
|
|
17
|
+
viewBox='0 0 24 24'
|
|
18
|
+
strokeWidth='2.5'
|
|
19
|
+
strokeLinecap='round'
|
|
20
|
+
strokeLinejoin='round'
|
|
21
|
+
>
|
|
22
|
+
{type === 'object' && (
|
|
23
|
+
<path d='M8 3c-1.5 0-3 1-3 3v3c0 1.5-1 2-2 2 1 0 2 .5 2 2v3c0 2 1.5 3 3 3M16 3c1.5 0 3 1 3 3v3c0 1.5 1 2 2 2-1 0-2 .5-2 2v3c0 2-1.5 3-3 3' />
|
|
24
|
+
)}
|
|
25
|
+
{type === 'array' && <path d='M8 4H5v16h3M16 4h3v16h-3' />}
|
|
26
|
+
{type === 'string' && <path strokeWidth='2' d='M7 8h10M7 12h10M7 16h6' />}
|
|
27
|
+
{(type === 'number' || type === 'integer') && (
|
|
28
|
+
<g strokeWidth='2'>
|
|
29
|
+
<path d='M9 4v16M15 4v16' />
|
|
30
|
+
<path d='M4 9h16M4 15h16' />
|
|
31
|
+
</g>
|
|
32
|
+
)}
|
|
33
|
+
{type === 'boolean' && <path d='M4 12l5 5L20 7' strokeWidth='3' />}
|
|
34
|
+
{type === 'null' && (
|
|
35
|
+
<g strokeWidth='2'>
|
|
36
|
+
<circle cx='12' cy='12' r='9' />
|
|
37
|
+
<path d='M18.5 5.5l-13 13' />
|
|
38
|
+
</g>
|
|
39
|
+
)}
|
|
40
|
+
</svg>
|
|
41
|
+
);
|