@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,400 @@
|
|
|
1
|
+
import { useTranslator } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
2
|
+
import { resolveCollapsed } from '@chobantonov/jsonforms-react-renderer-common/layout/groupState';
|
|
3
|
+
import { ArrayPanelToggle } from './ArrayPanelToggle';
|
|
4
|
+
import { findDetailUISchema as findUISchema } from '@chobantonov/jsonforms-react-renderer-common/core/detailUiSchema';
|
|
5
|
+
import { usePathErrorIndicator } from '@chobantonov/jsonforms-react-renderer-common/validation/errorSummary';
|
|
6
|
+
import {
|
|
7
|
+
Tooltip,
|
|
8
|
+
TooltipProvider,
|
|
9
|
+
TooltipTrigger,
|
|
10
|
+
TooltipContent,
|
|
11
|
+
} from '@jsonforms-react-shadcn-ui/tooltip';
|
|
12
|
+
import { ErrorIndicator } from './ErrorIndicator';
|
|
13
|
+
import { useColumnWidths } from '@chobantonov/jsonforms-react-renderer-common/collections/columnResize';
|
|
14
|
+
import { useTableSelection } from '@chobantonov/jsonforms-react-renderer-common/collections/useTableSelection';
|
|
15
|
+
import { PendingChangesProvider } from '@chobantonov/jsonforms-react-renderer-common/interaction/pendingChanges';
|
|
16
|
+
import { useCollectionPagination } from '@chobantonov/jsonforms-react-renderer-common/collections/collectionPagination';
|
|
17
|
+
import { useRowDetail } from '@chobantonov/jsonforms-react-renderer-common/collections/rowDetail';
|
|
18
|
+
import { CollectionPager } from './CollectionPager';
|
|
19
|
+
import { RowDetailToggle } from './RowDetailFrame';
|
|
20
|
+
import { useArrayPanelState } from '@chobantonov/jsonforms-react-renderer-common/collections/useArrayPanelState';
|
|
21
|
+
import {
|
|
22
|
+
and,
|
|
23
|
+
ArrayLayoutProps,
|
|
24
|
+
JsonSchema,
|
|
25
|
+
composePaths,
|
|
26
|
+
createControlElement,
|
|
27
|
+
createDefaultValue,
|
|
28
|
+
getFirstPrimitiveProp,
|
|
29
|
+
isObjectArrayWithNesting,
|
|
30
|
+
schemaTypeIs,
|
|
31
|
+
or,
|
|
32
|
+
uiTypeIs,
|
|
33
|
+
RankedTester,
|
|
34
|
+
rankWith,
|
|
35
|
+
Resolve,
|
|
36
|
+
} from '@jsonforms/core';
|
|
37
|
+
import { useJsonForms } from '@jsonforms/react';
|
|
38
|
+
import React from 'react';
|
|
39
|
+
import { Plus, Trash2 } from 'lucide-react';
|
|
40
|
+
import { shouldConfirm } from '@chobantonov/jsonforms-react-renderer-common/interaction/confirmation';
|
|
41
|
+
import { DeleteDialog } from './DeleteDialog';
|
|
42
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
43
|
+
import { ArrayTable } from './array/ArrayTable';
|
|
44
|
+
import { ArrayItemPanels } from './array/ArrayItemPanels';
|
|
45
|
+
import { ArrayListDetail } from './array/ArrayListDetail';
|
|
46
|
+
|
|
47
|
+
function usesDefaultDetail(detail: unknown) {
|
|
48
|
+
return (
|
|
49
|
+
!detail ||
|
|
50
|
+
(typeof detail === 'string' && detail.toUpperCase() === 'DEFAULT')
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function supportsDefaultTable(
|
|
55
|
+
{ arraySchema, rootSchema, config }: ArrayLayoutProps,
|
|
56
|
+
schema: JsonSchema,
|
|
57
|
+
) {
|
|
58
|
+
const nestedItems = isObjectArrayWithNesting(
|
|
59
|
+
createControlElement('#'),
|
|
60
|
+
arraySchema ?? ({ type: 'array', items: schema } as JsonSchema),
|
|
61
|
+
{ rootSchema, config },
|
|
62
|
+
);
|
|
63
|
+
if (nestedItems) return false;
|
|
64
|
+
return (
|
|
65
|
+
Boolean(schema.properties) ||
|
|
66
|
+
['string', 'number', 'integer', 'boolean', 'null'].includes(
|
|
67
|
+
schema.type as string,
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function arrayPresentation(
|
|
73
|
+
props: ArrayLayoutProps,
|
|
74
|
+
schema: JsonSchema,
|
|
75
|
+
options: NonNullable<ArrayLayoutProps['uischema']['options']>,
|
|
76
|
+
): 'list' | 'table' | 'panels' {
|
|
77
|
+
if (String(props.uischema.type) === 'ListWithDetail') return 'list';
|
|
78
|
+
if (options.table === true || options.format === 'table') return 'table';
|
|
79
|
+
if (options.table === false || !usesDefaultDetail(options.detail))
|
|
80
|
+
return 'panels';
|
|
81
|
+
return supportsDefaultTable(props, schema) ? 'table' : 'panels';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const ShadcnArrayRenderer = (props: ArrayLayoutProps) => {
|
|
85
|
+
const {
|
|
86
|
+
addItem,
|
|
87
|
+
moveUp,
|
|
88
|
+
moveDown,
|
|
89
|
+
cells,
|
|
90
|
+
config,
|
|
91
|
+
readonly,
|
|
92
|
+
data,
|
|
93
|
+
enabled,
|
|
94
|
+
label,
|
|
95
|
+
required,
|
|
96
|
+
path,
|
|
97
|
+
removeItems,
|
|
98
|
+
renderers,
|
|
99
|
+
rootSchema,
|
|
100
|
+
schema = {},
|
|
101
|
+
arraySchema,
|
|
102
|
+
uischema,
|
|
103
|
+
visible,
|
|
104
|
+
} = props;
|
|
105
|
+
const ctx = useJsonForms();
|
|
106
|
+
const options = { ...config, ...uischema.options };
|
|
107
|
+
const arrayErrors = usePathErrorIndicator(
|
|
108
|
+
path,
|
|
109
|
+
uischema.options,
|
|
110
|
+
!options.hideArraySummaryValidation,
|
|
111
|
+
);
|
|
112
|
+
const [expandedIndex, setExpandedIndex] = React.useState<number | undefined>(
|
|
113
|
+
() =>
|
|
114
|
+
data > 0 && !resolveCollapsed(uischema.options, config, 'array')
|
|
115
|
+
? 0
|
|
116
|
+
: undefined,
|
|
117
|
+
);
|
|
118
|
+
const removeItem = (index: number) => {
|
|
119
|
+
setExpandedIndex((current) =>
|
|
120
|
+
current === undefined || current < index
|
|
121
|
+
? current
|
|
122
|
+
: current === index
|
|
123
|
+
? undefined
|
|
124
|
+
: current - 1,
|
|
125
|
+
);
|
|
126
|
+
removeItems?.(path, [index])();
|
|
127
|
+
};
|
|
128
|
+
const moveItem = (index: number, direction: -1 | 1) => {
|
|
129
|
+
if (!enabled || readonly) return;
|
|
130
|
+
const target = index + direction;
|
|
131
|
+
if (target < 0 || target >= data) return;
|
|
132
|
+
setExpandedIndex((current) =>
|
|
133
|
+
current === index ? target : current === target ? index : current,
|
|
134
|
+
);
|
|
135
|
+
(direction === -1 ? moveUp : moveDown)?.(path, index)();
|
|
136
|
+
};
|
|
137
|
+
const translate = useTranslator();
|
|
138
|
+
const translations = {
|
|
139
|
+
addAriaLabel: translate('array.addAriaLabel', 'Add'),
|
|
140
|
+
addTooltip: translate('array.addTooltip', 'Add item'),
|
|
141
|
+
removeAriaLabel: translate('array.removeAriaLabel', 'Remove'),
|
|
142
|
+
removeTooltip: translate('array.removeTooltip', 'Remove item'),
|
|
143
|
+
upAriaLabel: translate('array.upAriaLabel', 'Move up') || 'Move up',
|
|
144
|
+
up: translate('array.up', 'Move up') || 'Move up',
|
|
145
|
+
downAriaLabel: translate('array.downAriaLabel', 'Move down') || 'Move down',
|
|
146
|
+
down: translate('array.down', 'Move down') || 'Move down',
|
|
147
|
+
};
|
|
148
|
+
const selection = useTableSelection({
|
|
149
|
+
path,
|
|
150
|
+
schema,
|
|
151
|
+
uischema,
|
|
152
|
+
config,
|
|
153
|
+
enabled,
|
|
154
|
+
readonly,
|
|
155
|
+
removeItems,
|
|
156
|
+
});
|
|
157
|
+
const columnSizes = useColumnWidths();
|
|
158
|
+
const [selectedItem, setSelectedItem] = React.useState(0);
|
|
159
|
+
const [pendingIndex, setPendingIndex] = React.useState<number>();
|
|
160
|
+
const panel = useArrayPanelState(uischema.options, config);
|
|
161
|
+
const canAdd =
|
|
162
|
+
enabled &&
|
|
163
|
+
!readonly &&
|
|
164
|
+
!options.disableAdd &&
|
|
165
|
+
!(
|
|
166
|
+
options.restrict &&
|
|
167
|
+
arraySchema.maxItems !== undefined &&
|
|
168
|
+
data >= arraySchema.maxItems
|
|
169
|
+
);
|
|
170
|
+
const canRemove =
|
|
171
|
+
!!removeItems &&
|
|
172
|
+
enabled &&
|
|
173
|
+
!readonly &&
|
|
174
|
+
!options.disableRemove &&
|
|
175
|
+
!(
|
|
176
|
+
options.restrict &&
|
|
177
|
+
arraySchema.minItems !== undefined &&
|
|
178
|
+
data <= arraySchema.minItems
|
|
179
|
+
);
|
|
180
|
+
const requestRemove = (index: number) => {
|
|
181
|
+
if (!canRemove) return;
|
|
182
|
+
const value = Resolve.data(
|
|
183
|
+
ctx.core?.data,
|
|
184
|
+
composePaths(path, String(index)),
|
|
185
|
+
);
|
|
186
|
+
if (
|
|
187
|
+
shouldConfirm(
|
|
188
|
+
{
|
|
189
|
+
options: uischema.options,
|
|
190
|
+
config,
|
|
191
|
+
catalogId: 'arrayLayout',
|
|
192
|
+
operation: 'delete',
|
|
193
|
+
},
|
|
194
|
+
[value],
|
|
195
|
+
)
|
|
196
|
+
)
|
|
197
|
+
setPendingIndex(index);
|
|
198
|
+
else removeItem(index);
|
|
199
|
+
};
|
|
200
|
+
const detail = React.useMemo(
|
|
201
|
+
() =>
|
|
202
|
+
findUISchema(
|
|
203
|
+
ctx.uischemas ?? [],
|
|
204
|
+
schema,
|
|
205
|
+
uischema.scope,
|
|
206
|
+
path,
|
|
207
|
+
// `items: true` resolves to a boolean schema; its generated layout is empty.
|
|
208
|
+
typeof schema === 'boolean' && schema
|
|
209
|
+
? () => createControlElement('#')
|
|
210
|
+
: undefined,
|
|
211
|
+
uischema,
|
|
212
|
+
rootSchema,
|
|
213
|
+
),
|
|
214
|
+
[ctx.uischemas, schema, uischema, path, rootSchema],
|
|
215
|
+
);
|
|
216
|
+
const childLabelProp =
|
|
217
|
+
uischema.options?.elementLabelProp ?? getFirstPrimitiveProp(schema);
|
|
218
|
+
|
|
219
|
+
const presentation = arrayPresentation(props, schema, options);
|
|
220
|
+
const table = presentation === 'table';
|
|
221
|
+
const page = useCollectionPagination(
|
|
222
|
+
Array.from({ length: data }, (_, i) => i),
|
|
223
|
+
uischema.options?.pagination,
|
|
224
|
+
config,
|
|
225
|
+
'array',
|
|
226
|
+
table,
|
|
227
|
+
);
|
|
228
|
+
const rowDetail = useRowDetail({
|
|
229
|
+
schema,
|
|
230
|
+
rootSchema,
|
|
231
|
+
uischema,
|
|
232
|
+
config,
|
|
233
|
+
path,
|
|
234
|
+
enabled,
|
|
235
|
+
readonly,
|
|
236
|
+
renderers,
|
|
237
|
+
cells,
|
|
238
|
+
});
|
|
239
|
+
if (!visible) return null;
|
|
240
|
+
const childLabelForIndex = (childPath: string, index: number) => {
|
|
241
|
+
if (!childLabelProp) {
|
|
242
|
+
return `${index}`;
|
|
243
|
+
}
|
|
244
|
+
const labelValue = Resolve.data(
|
|
245
|
+
ctx.core?.data,
|
|
246
|
+
composePaths(childPath, childLabelProp),
|
|
247
|
+
);
|
|
248
|
+
if (
|
|
249
|
+
labelValue === undefined ||
|
|
250
|
+
labelValue === null ||
|
|
251
|
+
Number.isNaN(labelValue)
|
|
252
|
+
) {
|
|
253
|
+
return '';
|
|
254
|
+
}
|
|
255
|
+
return `${labelValue}`;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const itemView = {
|
|
259
|
+
schema,
|
|
260
|
+
path,
|
|
261
|
+
renderers,
|
|
262
|
+
cells,
|
|
263
|
+
enabled,
|
|
264
|
+
detail,
|
|
265
|
+
indices: page.indices,
|
|
266
|
+
hideAvatar: Boolean(options.hideAvatar),
|
|
267
|
+
canRemove,
|
|
268
|
+
requestRemove,
|
|
269
|
+
childLabelForIndex,
|
|
270
|
+
removeLabel: translations.removeAriaLabel,
|
|
271
|
+
removeTooltip: translations.removeTooltip,
|
|
272
|
+
};
|
|
273
|
+
return (
|
|
274
|
+
<PendingChangesProvider changes={page.pending}>
|
|
275
|
+
<div className='shadcn-jsonforms-array'>
|
|
276
|
+
<div className='shadcn-jsonforms-array-header'>
|
|
277
|
+
<div className='flex items-center gap-2'>
|
|
278
|
+
<h3>
|
|
279
|
+
{label}
|
|
280
|
+
{required && !options.hideRequiredAsterisk && (
|
|
281
|
+
<span aria-hidden='true'> *</span>
|
|
282
|
+
)}
|
|
283
|
+
</h3>
|
|
284
|
+
{arrayErrors && (
|
|
285
|
+
<ErrorIndicator
|
|
286
|
+
local
|
|
287
|
+
errors={arrayErrors}
|
|
288
|
+
className='shadcn-jsonforms-array-errors'
|
|
289
|
+
/>
|
|
290
|
+
)}
|
|
291
|
+
</div>
|
|
292
|
+
<div className='shadcn-jsonforms-array-actions'>
|
|
293
|
+
<RowDetailToggle state={rowDetail} />
|
|
294
|
+
{table && (
|
|
295
|
+
<TooltipProvider>
|
|
296
|
+
<Tooltip>
|
|
297
|
+
<TooltipTrigger asChild>
|
|
298
|
+
<Button
|
|
299
|
+
type='button'
|
|
300
|
+
size='icon-sm'
|
|
301
|
+
variant='destructive'
|
|
302
|
+
aria-label={rowDetail.t('collection.deleteSelected')}
|
|
303
|
+
disabled={!selection.canDelete}
|
|
304
|
+
onClick={selection.request}
|
|
305
|
+
>
|
|
306
|
+
<Trash2 aria-hidden='true' className='h-4 w-4' />
|
|
307
|
+
</Button>
|
|
308
|
+
</TooltipTrigger>
|
|
309
|
+
<TooltipContent>
|
|
310
|
+
{rowDetail.t('collection.deleteSelected')}
|
|
311
|
+
</TooltipContent>
|
|
312
|
+
</Tooltip>
|
|
313
|
+
</TooltipProvider>
|
|
314
|
+
)}
|
|
315
|
+
<Button
|
|
316
|
+
type='button'
|
|
317
|
+
size='icon-sm'
|
|
318
|
+
aria-label={
|
|
319
|
+
translations?.addAriaLabel ??
|
|
320
|
+
translate('array.addAriaLabel', 'Add')
|
|
321
|
+
}
|
|
322
|
+
title={
|
|
323
|
+
translations?.addTooltip ??
|
|
324
|
+
translate('array.addTooltip', 'Add item')
|
|
325
|
+
}
|
|
326
|
+
disabled={!canAdd}
|
|
327
|
+
onClick={() => {
|
|
328
|
+
if (!canAdd) return;
|
|
329
|
+
if (!options.collapseNewItems) setExpandedIndex(data);
|
|
330
|
+
addItem(path, createDefaultValue(schema, rootSchema))();
|
|
331
|
+
}}
|
|
332
|
+
>
|
|
333
|
+
<Plus className='h-4 w-4' aria-hidden='true' />
|
|
334
|
+
</Button>
|
|
335
|
+
<ArrayPanelToggle panel={panel} label={label} />
|
|
336
|
+
</div>
|
|
337
|
+
</div>
|
|
338
|
+
<div id={panel.contentId} hidden={panel.collapsed}>
|
|
339
|
+
{presentation === 'list' ? (
|
|
340
|
+
<ArrayListDetail
|
|
341
|
+
{...itemView}
|
|
342
|
+
count={data}
|
|
343
|
+
label={label}
|
|
344
|
+
readonly={readonly}
|
|
345
|
+
selectedItem={selectedItem}
|
|
346
|
+
onSelect={setSelectedItem}
|
|
347
|
+
emptyMessage={() => translate('array.noDataMessage', 'No data')}
|
|
348
|
+
/>
|
|
349
|
+
) : table ? (
|
|
350
|
+
<ArrayTable
|
|
351
|
+
{...props}
|
|
352
|
+
schema={schema}
|
|
353
|
+
options={options}
|
|
354
|
+
rowDetail={rowDetail}
|
|
355
|
+
page={page}
|
|
356
|
+
selection={selection}
|
|
357
|
+
columnSizes={columnSizes}
|
|
358
|
+
translations={translations}
|
|
359
|
+
/>
|
|
360
|
+
) : (
|
|
361
|
+
<ArrayItemPanels
|
|
362
|
+
{...itemView}
|
|
363
|
+
config={config}
|
|
364
|
+
uischema={uischema}
|
|
365
|
+
expandedIndex={expandedIndex}
|
|
366
|
+
onExpand={setExpandedIndex}
|
|
367
|
+
onMove={moveItem}
|
|
368
|
+
canMove={enabled && !readonly}
|
|
369
|
+
count={data}
|
|
370
|
+
translations={translations}
|
|
371
|
+
/>
|
|
372
|
+
)}
|
|
373
|
+
{!table && <CollectionPager page={page} />}
|
|
374
|
+
</div>
|
|
375
|
+
<DeleteDialog
|
|
376
|
+
open={selection.confirming}
|
|
377
|
+
onCancel={selection.cancel}
|
|
378
|
+
onConfirm={selection.confirm}
|
|
379
|
+
/>
|
|
380
|
+
<DeleteDialog
|
|
381
|
+
open={pendingIndex !== undefined}
|
|
382
|
+
onCancel={() => setPendingIndex(undefined)}
|
|
383
|
+
onConfirm={() => {
|
|
384
|
+
if (canRemove && pendingIndex !== undefined && pendingIndex < data)
|
|
385
|
+
removeItem(pendingIndex);
|
|
386
|
+
setPendingIndex(undefined);
|
|
387
|
+
}}
|
|
388
|
+
/>
|
|
389
|
+
</div>
|
|
390
|
+
</PendingChangesProvider>
|
|
391
|
+
);
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
export const arrayControlTester: RankedTester = rankWith(
|
|
395
|
+
3,
|
|
396
|
+
and(
|
|
397
|
+
or(uiTypeIs('Control'), uiTypeIs('ListWithDetail')),
|
|
398
|
+
schemaTypeIs('array'),
|
|
399
|
+
),
|
|
400
|
+
);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ChevronDown, ChevronUp } from 'lucide-react';
|
|
4
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
5
|
+
import type { useArrayPanelState } from '@chobantonov/jsonforms-react-renderer-common/collections/useArrayPanelState';
|
|
6
|
+
|
|
7
|
+
export function ArrayPanelToggle({
|
|
8
|
+
panel,
|
|
9
|
+
label,
|
|
10
|
+
}: {
|
|
11
|
+
panel: ReturnType<typeof useArrayPanelState>;
|
|
12
|
+
label?: string;
|
|
13
|
+
}) {
|
|
14
|
+
const t = useI18n();
|
|
15
|
+
if (!panel.collapsible) return null;
|
|
16
|
+
return (
|
|
17
|
+
<Button
|
|
18
|
+
type='button'
|
|
19
|
+
variant='ghost'
|
|
20
|
+
size='icon-sm'
|
|
21
|
+
aria-label={label || t('control.array')}
|
|
22
|
+
aria-expanded={!panel.collapsed}
|
|
23
|
+
aria-controls={panel.contentId}
|
|
24
|
+
onClick={panel.toggle}
|
|
25
|
+
>
|
|
26
|
+
{panel.collapsed ? (
|
|
27
|
+
<ChevronDown aria-hidden='true' />
|
|
28
|
+
) : (
|
|
29
|
+
<ChevronUp aria-hidden='true' />
|
|
30
|
+
)}
|
|
31
|
+
</Button>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Pagination,
|
|
3
|
+
PaginationContent,
|
|
4
|
+
PaginationItem,
|
|
5
|
+
} from '@jsonforms-react-shadcn-ui/pagination';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
8
|
+
import {
|
|
9
|
+
Select,
|
|
10
|
+
SelectTrigger,
|
|
11
|
+
SelectValue,
|
|
12
|
+
SelectContent,
|
|
13
|
+
SelectItem,
|
|
14
|
+
} from '@jsonforms-react-shadcn-ui/select';
|
|
15
|
+
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
16
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
17
|
+
import { CollectionPage } from '@chobantonov/jsonforms-react-renderer-common/collections/collectionPagination';
|
|
18
|
+
export const CollectionPager = ({ page }: { page: CollectionPage }) => {
|
|
19
|
+
const t = useI18n();
|
|
20
|
+
if (!page.enabled || !page.total) return null;
|
|
21
|
+
return (
|
|
22
|
+
<div data-collection-footer className='border-t py-3'>
|
|
23
|
+
<Pagination
|
|
24
|
+
aria-label={t('collection.pagination')}
|
|
25
|
+
className='flex flex-wrap items-center justify-end gap-2'
|
|
26
|
+
>
|
|
27
|
+
<Select
|
|
28
|
+
value={String(page.size)}
|
|
29
|
+
onValueChange={(value) => page.change(page.current, Number(value))}
|
|
30
|
+
>
|
|
31
|
+
<SelectTrigger aria-label={t('collection.pageSize')} className='w-20'>
|
|
32
|
+
<SelectValue />
|
|
33
|
+
</SelectTrigger>
|
|
34
|
+
<SelectContent>
|
|
35
|
+
{page.choices.map((size) => (
|
|
36
|
+
<SelectItem key={size} value={String(size)}>
|
|
37
|
+
{size}
|
|
38
|
+
</SelectItem>
|
|
39
|
+
))}
|
|
40
|
+
</SelectContent>
|
|
41
|
+
</Select>
|
|
42
|
+
<PaginationContent>
|
|
43
|
+
<PaginationItem>
|
|
44
|
+
<Button
|
|
45
|
+
type='button'
|
|
46
|
+
variant='outline'
|
|
47
|
+
size='icon-sm'
|
|
48
|
+
aria-label={t('collection.previous')}
|
|
49
|
+
disabled={page.current === 1}
|
|
50
|
+
onClick={() => page.change(page.current - 1)}
|
|
51
|
+
>
|
|
52
|
+
<ChevronLeft />
|
|
53
|
+
</Button>
|
|
54
|
+
</PaginationItem>
|
|
55
|
+
<PaginationItem>
|
|
56
|
+
<span aria-live='polite'>
|
|
57
|
+
{page.current} / {page.pages}
|
|
58
|
+
</span>
|
|
59
|
+
</PaginationItem>
|
|
60
|
+
<PaginationItem>
|
|
61
|
+
<Button
|
|
62
|
+
type='button'
|
|
63
|
+
variant='outline'
|
|
64
|
+
size='icon-sm'
|
|
65
|
+
aria-label={t('collection.next')}
|
|
66
|
+
disabled={page.current === page.pages}
|
|
67
|
+
onClick={() => page.change(page.current + 1)}
|
|
68
|
+
>
|
|
69
|
+
<ChevronRight />
|
|
70
|
+
</Button>
|
|
71
|
+
</PaginationItem>
|
|
72
|
+
</PaginationContent>
|
|
73
|
+
</Pagination>
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
4
|
+
import {
|
|
5
|
+
Dialog,
|
|
6
|
+
DialogContent,
|
|
7
|
+
DialogDescription,
|
|
8
|
+
DialogFooter,
|
|
9
|
+
DialogHeader,
|
|
10
|
+
DialogTitle,
|
|
11
|
+
} from '@jsonforms-react-shadcn-ui/dialog';
|
|
12
|
+
|
|
13
|
+
type CombinatorSwitchDialogProps = {
|
|
14
|
+
open: boolean;
|
|
15
|
+
onCancel: () => void;
|
|
16
|
+
onConfirm: () => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const CombinatorSwitchDialog = ({
|
|
20
|
+
open,
|
|
21
|
+
onCancel,
|
|
22
|
+
onConfirm,
|
|
23
|
+
}: CombinatorSwitchDialogProps) => {
|
|
24
|
+
const t = useI18n();
|
|
25
|
+
return (
|
|
26
|
+
<Dialog open={open} onOpenChange={(nextOpen) => !nextOpen && onCancel()}>
|
|
27
|
+
<DialogContent>
|
|
28
|
+
<DialogHeader>
|
|
29
|
+
<DialogTitle>{t('combinator.clearTitle')}</DialogTitle>
|
|
30
|
+
<DialogDescription>{t('combinator.clearMessage')}</DialogDescription>
|
|
31
|
+
</DialogHeader>
|
|
32
|
+
<DialogFooter>
|
|
33
|
+
<Button type='button' variant='outline' onClick={onCancel}>
|
|
34
|
+
{t('confirm.decline')}
|
|
35
|
+
</Button>
|
|
36
|
+
<Button type='button' onClick={onConfirm}>
|
|
37
|
+
{t('confirm.accept')}
|
|
38
|
+
</Button>
|
|
39
|
+
</DialogFooter>
|
|
40
|
+
</DialogContent>
|
|
41
|
+
</Dialog>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
4
|
+
import {
|
|
5
|
+
Dialog,
|
|
6
|
+
DialogContent,
|
|
7
|
+
DialogDescription,
|
|
8
|
+
DialogFooter,
|
|
9
|
+
DialogHeader,
|
|
10
|
+
DialogTitle,
|
|
11
|
+
} from '@jsonforms-react-shadcn-ui/dialog';
|
|
12
|
+
|
|
13
|
+
export const DeleteDialog = ({
|
|
14
|
+
open,
|
|
15
|
+
onCancel,
|
|
16
|
+
onConfirm,
|
|
17
|
+
}: {
|
|
18
|
+
open: boolean;
|
|
19
|
+
onCancel: () => void;
|
|
20
|
+
onConfirm: () => void;
|
|
21
|
+
}) => {
|
|
22
|
+
const t = useI18n();
|
|
23
|
+
return (
|
|
24
|
+
<Dialog open={open} onOpenChange={(open) => !open && onCancel()}>
|
|
25
|
+
<DialogContent>
|
|
26
|
+
<DialogHeader>
|
|
27
|
+
<DialogTitle>{t('confirm.delete.title')}</DialogTitle>
|
|
28
|
+
<DialogDescription>{t('confirm.delete.message')}</DialogDescription>
|
|
29
|
+
</DialogHeader>
|
|
30
|
+
<DialogFooter>
|
|
31
|
+
<Button type='button' variant='outline' onClick={onCancel}>
|
|
32
|
+
{t('confirm.decline')}
|
|
33
|
+
</Button>
|
|
34
|
+
<Button type='button' variant='destructive' onClick={onConfirm}>
|
|
35
|
+
{t('confirm.accept')}
|
|
36
|
+
</Button>
|
|
37
|
+
</DialogFooter>
|
|
38
|
+
</DialogContent>
|
|
39
|
+
</Dialog>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ScrollRegion } from '../components/ScrollRegion';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Maximize2, Minimize2 } from 'lucide-react';
|
|
4
|
+
import { DialogContent } from '@jsonforms-react-shadcn-ui/dialog';
|
|
5
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
6
|
+
import {
|
|
7
|
+
useDetailDialog,
|
|
8
|
+
DetailDialogOptions,
|
|
9
|
+
} from '@chobantonov/jsonforms-react-renderer-common/interaction/detailDialog';
|
|
10
|
+
import { useTranslator } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
11
|
+
|
|
12
|
+
export const DetailDialogContent = ({
|
|
13
|
+
options = {},
|
|
14
|
+
open,
|
|
15
|
+
children,
|
|
16
|
+
...props
|
|
17
|
+
}: React.ComponentProps<typeof DialogContent> & {
|
|
18
|
+
options?: DetailDialogOptions;
|
|
19
|
+
open: boolean;
|
|
20
|
+
}) => {
|
|
21
|
+
const geometry = useDetailDialog(open, options);
|
|
22
|
+
const t = useTranslator();
|
|
23
|
+
const label = geometry.maximized
|
|
24
|
+
? t('dialog.restore', 'Restore dialog')
|
|
25
|
+
: t('dialog.maximize', 'Maximize dialog');
|
|
26
|
+
const parts = React.Children.toArray(children);
|
|
27
|
+
return (
|
|
28
|
+
<DialogContent
|
|
29
|
+
{...props}
|
|
30
|
+
tabIndex={-1}
|
|
31
|
+
style={{
|
|
32
|
+
...props.style,
|
|
33
|
+
...geometry.style,
|
|
34
|
+
width: geometry.style.width ?? 640,
|
|
35
|
+
display: 'flex',
|
|
36
|
+
flexDirection: 'column',
|
|
37
|
+
overflow: 'hidden',
|
|
38
|
+
// Geometry must follow the pointer without the primitive's transition delay.
|
|
39
|
+
transitionProperty: 'none',
|
|
40
|
+
left: `calc(50% + ${geometry.offset.x}px)`,
|
|
41
|
+
top: `calc(50% + ${geometry.offset.y}px)`,
|
|
42
|
+
translate: '-50% -50%',
|
|
43
|
+
transform: 'none',
|
|
44
|
+
}}
|
|
45
|
+
onOpenAutoFocus={(event) => {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
(event.target as HTMLElement).focus();
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
{geometry.options.maximizable !== false && (
|
|
51
|
+
<Button
|
|
52
|
+
type='button'
|
|
53
|
+
variant='ghost'
|
|
54
|
+
size='icon-sm'
|
|
55
|
+
className='absolute right-10 top-2'
|
|
56
|
+
aria-label={label}
|
|
57
|
+
title={label}
|
|
58
|
+
onClick={geometry.toggle}
|
|
59
|
+
>
|
|
60
|
+
{geometry.maximized ? <Minimize2 /> : <Maximize2 />}
|
|
61
|
+
</Button>
|
|
62
|
+
)}
|
|
63
|
+
<div
|
|
64
|
+
{...geometry.dragProps}
|
|
65
|
+
style={{ ...geometry.dragProps.style, flexShrink: 0 }}
|
|
66
|
+
className='min-w-0 pr-16'
|
|
67
|
+
>
|
|
68
|
+
{parts[0]}
|
|
69
|
+
</div>
|
|
70
|
+
<ScrollRegion
|
|
71
|
+
data-detail-dialog-body
|
|
72
|
+
style={{ flex: '1 1 auto', minHeight: 0 }}
|
|
73
|
+
>
|
|
74
|
+
{parts.slice(1, -1)}
|
|
75
|
+
</ScrollRegion>
|
|
76
|
+
<div
|
|
77
|
+
data-detail-dialog-footer
|
|
78
|
+
style={{ flexShrink: 0, display: 'flex', justifyContent: 'flex-end' }}
|
|
79
|
+
>
|
|
80
|
+
{parts[parts.length - 1]}
|
|
81
|
+
</div>
|
|
82
|
+
</DialogContent>
|
|
83
|
+
);
|
|
84
|
+
};
|