@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,453 @@
|
|
|
1
|
+
import { literalPropertySchema } from '@chobantonov/jsonforms-react-renderer-common/objects/literalPropertySchema';
|
|
2
|
+
import { renamePropertyKey } from '@chobantonov/jsonforms-react-renderer-common/objects/additionalProperties';
|
|
3
|
+
import {
|
|
4
|
+
DynamicPropertyProvider,
|
|
5
|
+
clearedDynamicPropertyValue,
|
|
6
|
+
} from '@chobantonov/jsonforms-react-renderer-common/objects/dynamicProperties';
|
|
7
|
+
import {
|
|
8
|
+
useAdditionalPropertyEntries,
|
|
9
|
+
useAdditionalPropertyActions,
|
|
10
|
+
type AdditionalPropertiesProps,
|
|
11
|
+
} from '@chobantonov/jsonforms-react-renderer-common/objects/useAdditionalPropertyEntries';
|
|
12
|
+
|
|
13
|
+
import { IsolatedPropertyEditor } from '@chobantonov/jsonforms-react-renderer-common/objects/IsolatedPropertyEditor';
|
|
14
|
+
import {
|
|
15
|
+
needsIsolatedEditor,
|
|
16
|
+
assignOwnProperty,
|
|
17
|
+
validateAdditionalPropertyName,
|
|
18
|
+
} from '@chobantonov/jsonforms-react-renderer-common/objects/additionalPropertyName';
|
|
19
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
20
|
+
import { ErrorIndicator } from './ErrorIndicator';
|
|
21
|
+
import {
|
|
22
|
+
useNameConstraintMessage,
|
|
23
|
+
usePropertyNameErrors,
|
|
24
|
+
useAdditionalPropertyErrors,
|
|
25
|
+
} from '@chobantonov/jsonforms-react-renderer-common/validation/errorSummary';
|
|
26
|
+
import { DeleteDialog } from './DeleteDialog';
|
|
27
|
+
import { PendingChangesProvider } from '@chobantonov/jsonforms-react-renderer-common/interaction/pendingChanges';
|
|
28
|
+
import { CollectionPager } from './CollectionPager';
|
|
29
|
+
import type { JsonSchema } from '@jsonforms/core';
|
|
30
|
+
import { JsonFormsDispatch } from '@jsonforms/react';
|
|
31
|
+
import { Pencil, Plus, Trash2 } from 'lucide-react';
|
|
32
|
+
import React, { useState } from 'react';
|
|
33
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
34
|
+
import { Card } from '@jsonforms-react-shadcn-ui/card';
|
|
35
|
+
import {
|
|
36
|
+
Dialog,
|
|
37
|
+
DialogContent,
|
|
38
|
+
DialogDescription,
|
|
39
|
+
DialogFooter,
|
|
40
|
+
DialogHeader,
|
|
41
|
+
DialogTitle,
|
|
42
|
+
} from '@jsonforms-react-shadcn-ui/dialog';
|
|
43
|
+
import { Input } from '@jsonforms-react-shadcn-ui/input';
|
|
44
|
+
|
|
45
|
+
export type { AdditionalPropertiesProps } from '@chobantonov/jsonforms-react-renderer-common/objects/useAdditionalPropertyEntries';
|
|
46
|
+
|
|
47
|
+
export const AdditionalProperties = (props: AdditionalPropertiesProps) => {
|
|
48
|
+
const {
|
|
49
|
+
embedded = false,
|
|
50
|
+
cells,
|
|
51
|
+
|
|
52
|
+
data,
|
|
53
|
+
enabled,
|
|
54
|
+
handleChange,
|
|
55
|
+
label,
|
|
56
|
+
path,
|
|
57
|
+
readonly,
|
|
58
|
+
renderers,
|
|
59
|
+
rootSchema,
|
|
60
|
+
schema,
|
|
61
|
+
} = props;
|
|
62
|
+
const [newPropertyName, setNewPropertyName] = useState('');
|
|
63
|
+
const [renamingPropertyName, setRenamingPropertyName] = useState<
|
|
64
|
+
string | null
|
|
65
|
+
>(null);
|
|
66
|
+
const [renameValue, setRenameValue] = useState('');
|
|
67
|
+
const entries = useAdditionalPropertyEntries(props);
|
|
68
|
+
const {
|
|
69
|
+
objectSchema,
|
|
70
|
+
appliedOptions,
|
|
71
|
+
objectData,
|
|
72
|
+
page,
|
|
73
|
+
additionalPropertyItems,
|
|
74
|
+
shouldShow,
|
|
75
|
+
} = entries;
|
|
76
|
+
const additionalPropertiesTitle =
|
|
77
|
+
typeof objectSchema.additionalProperties === 'object' &&
|
|
78
|
+
typeof objectSchema.additionalProperties.title === 'string'
|
|
79
|
+
? objectSchema.additionalProperties.title
|
|
80
|
+
: undefined;
|
|
81
|
+
|
|
82
|
+
const t = useI18n();
|
|
83
|
+
const constraintMessage = useNameConstraintMessage();
|
|
84
|
+
const validatePropertyName = (
|
|
85
|
+
name: string,
|
|
86
|
+
value: any,
|
|
87
|
+
nameSchema: JsonSchema,
|
|
88
|
+
root: JsonSchema,
|
|
89
|
+
currentName?: string,
|
|
90
|
+
) => {
|
|
91
|
+
const result = validateAdditionalPropertyName({
|
|
92
|
+
name,
|
|
93
|
+
data: value,
|
|
94
|
+
schema: nameSchema,
|
|
95
|
+
rootSchema: root,
|
|
96
|
+
currentName,
|
|
97
|
+
allowEmptyName: appliedOptions.allowEmptyPropertyNames === true,
|
|
98
|
+
});
|
|
99
|
+
return (
|
|
100
|
+
constraintMessage(result.errors) ??
|
|
101
|
+
(result.error
|
|
102
|
+
? t(
|
|
103
|
+
result.error === 'already-defined'
|
|
104
|
+
? 'additionalProperties.nameTaken'
|
|
105
|
+
: result.error === 'required'
|
|
106
|
+
? 'additionalProperties.nameRequired'
|
|
107
|
+
: 'additionalProperties.nameInvalid',
|
|
108
|
+
{ name },
|
|
109
|
+
)
|
|
110
|
+
: undefined)
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
const propertyName = newPropertyName;
|
|
114
|
+
const propertyNameError = validatePropertyName(
|
|
115
|
+
propertyName,
|
|
116
|
+
data,
|
|
117
|
+
schema,
|
|
118
|
+
rootSchema,
|
|
119
|
+
);
|
|
120
|
+
const {
|
|
121
|
+
addPropertyDisabled,
|
|
122
|
+
removePropertyDisabled,
|
|
123
|
+
deletion,
|
|
124
|
+
addProperty,
|
|
125
|
+
removeProperty,
|
|
126
|
+
} = useAdditionalPropertyActions(props, entries, {
|
|
127
|
+
restrict: Boolean(appliedOptions.restrict),
|
|
128
|
+
propertyName,
|
|
129
|
+
propertyNameError,
|
|
130
|
+
setNewPropertyName,
|
|
131
|
+
});
|
|
132
|
+
const renameProperty = (propertyToRename: string) => {
|
|
133
|
+
const trimmed = renameValue;
|
|
134
|
+
const renameError = validatePropertyName(
|
|
135
|
+
trimmed,
|
|
136
|
+
data,
|
|
137
|
+
schema,
|
|
138
|
+
rootSchema,
|
|
139
|
+
propertyToRename,
|
|
140
|
+
);
|
|
141
|
+
if (trimmed === propertyToRename) {
|
|
142
|
+
setRenamingPropertyName(null);
|
|
143
|
+
setRenameValue('');
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (renameError || !objectData) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const updatedData = renamePropertyKey(
|
|
151
|
+
objectData,
|
|
152
|
+
propertyToRename,
|
|
153
|
+
trimmed,
|
|
154
|
+
);
|
|
155
|
+
handleChange(path, updatedData);
|
|
156
|
+
setRenamingPropertyName(null);
|
|
157
|
+
setRenameValue('');
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const closeRenameDialog = () => {
|
|
161
|
+
setRenamingPropertyName(null);
|
|
162
|
+
setRenameValue('');
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const renameError = renamingPropertyName
|
|
166
|
+
? validatePropertyName(
|
|
167
|
+
renameValue,
|
|
168
|
+
data,
|
|
169
|
+
schema,
|
|
170
|
+
rootSchema,
|
|
171
|
+
renamingPropertyName,
|
|
172
|
+
)
|
|
173
|
+
: undefined;
|
|
174
|
+
const renameDisabled = !enabled || readonly || Boolean(renameError);
|
|
175
|
+
|
|
176
|
+
const propertyErrors = useAdditionalPropertyErrors(path);
|
|
177
|
+
const nameErrors = usePropertyNameErrors(path);
|
|
178
|
+
if (!shouldShow) return null;
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<PendingChangesProvider changes={page.pending}>
|
|
182
|
+
<>
|
|
183
|
+
<DeleteDialog
|
|
184
|
+
open={deletion.confirming}
|
|
185
|
+
onCancel={deletion.cancel}
|
|
186
|
+
onConfirm={deletion.confirm}
|
|
187
|
+
/>
|
|
188
|
+
<Card
|
|
189
|
+
className='jsonforms-additional-properties my-1 min-w-full'
|
|
190
|
+
style={
|
|
191
|
+
embedded
|
|
192
|
+
? { border: 0, boxShadow: 'none', padding: 0, margin: 0 }
|
|
193
|
+
: undefined
|
|
194
|
+
}
|
|
195
|
+
>
|
|
196
|
+
<div className={embedded ? 'py-2' : 'px-4 py-2'}>
|
|
197
|
+
<div className='flex flex-col gap-2 md:flex-row md:gap-4'>
|
|
198
|
+
{additionalPropertiesTitle ? (
|
|
199
|
+
<div className='md:flex md:h-10 md:items-center md:pt-6'>
|
|
200
|
+
<span className='text-sm text-foreground'>
|
|
201
|
+
{additionalPropertiesTitle}
|
|
202
|
+
{propertyErrors && (
|
|
203
|
+
<ErrorIndicator local errors={propertyErrors} />
|
|
204
|
+
)}
|
|
205
|
+
</span>
|
|
206
|
+
</div>
|
|
207
|
+
) : null}
|
|
208
|
+
<div className='min-w-0 flex-1'>
|
|
209
|
+
<label
|
|
210
|
+
className='mb-1 block text-sm font-medium text-foreground'
|
|
211
|
+
htmlFor='shadcn-additional-property-name'
|
|
212
|
+
>
|
|
213
|
+
{t('additionalProperties.namePlaceholder')}
|
|
214
|
+
</label>
|
|
215
|
+
<div className='relative pr-12'>
|
|
216
|
+
<Input
|
|
217
|
+
id='shadcn-additional-property-name'
|
|
218
|
+
className='shadcn-jsonforms-input'
|
|
219
|
+
aria-label={
|
|
220
|
+
label
|
|
221
|
+
? t('additionalProperties.addTo', { label })
|
|
222
|
+
: t('additionalProperties.add')
|
|
223
|
+
}
|
|
224
|
+
aria-invalid={
|
|
225
|
+
newPropertyName !== '' && Boolean(propertyNameError)
|
|
226
|
+
}
|
|
227
|
+
disabled={!enabled || readonly}
|
|
228
|
+
type='text'
|
|
229
|
+
value={newPropertyName}
|
|
230
|
+
onChange={(event) =>
|
|
231
|
+
setNewPropertyName(event.currentTarget.value)
|
|
232
|
+
}
|
|
233
|
+
onKeyDown={(event) => {
|
|
234
|
+
if (event.key === 'Enter') {
|
|
235
|
+
addProperty();
|
|
236
|
+
}
|
|
237
|
+
}}
|
|
238
|
+
/>
|
|
239
|
+
<Button
|
|
240
|
+
className='absolute right-0 top-0 h-10 w-10 shrink-0'
|
|
241
|
+
disabled={addPropertyDisabled}
|
|
242
|
+
size='icon'
|
|
243
|
+
type='button'
|
|
244
|
+
aria-label={t('additionalProperties.add')}
|
|
245
|
+
title={t('additionalProperties.add')}
|
|
246
|
+
onClick={addProperty}
|
|
247
|
+
>
|
|
248
|
+
<Plus className='h-4 w-4' />
|
|
249
|
+
</Button>
|
|
250
|
+
</div>
|
|
251
|
+
{newPropertyName !== '' && propertyNameError ? (
|
|
252
|
+
<div
|
|
253
|
+
className='jsonforms-additional-properties-error mt-1 text-sm text-destructive'
|
|
254
|
+
role='alert'
|
|
255
|
+
>
|
|
256
|
+
{propertyNameError}
|
|
257
|
+
</div>
|
|
258
|
+
) : null}
|
|
259
|
+
</div>
|
|
260
|
+
</div>
|
|
261
|
+
</div>
|
|
262
|
+
<div
|
|
263
|
+
className={`jsonforms-additional-properties-list flex flex-col gap-2${
|
|
264
|
+
embedded ? '' : ' px-4'
|
|
265
|
+
}`}
|
|
266
|
+
>
|
|
267
|
+
{page.indices
|
|
268
|
+
.map((index) => additionalPropertyItems[index])
|
|
269
|
+
.map((item) => (
|
|
270
|
+
<div
|
|
271
|
+
className='jsonforms-additional-property relative'
|
|
272
|
+
key={item.propertyName}
|
|
273
|
+
>
|
|
274
|
+
<div className='flex min-h-6 items-center justify-between gap-2 mb-2'>
|
|
275
|
+
<span
|
|
276
|
+
data-property-name-label={item.propertyName}
|
|
277
|
+
className={`inline-flex min-w-0 items-center gap-1 text-sm font-medium ${
|
|
278
|
+
nameErrors.has(item.propertyName)
|
|
279
|
+
? 'text-destructive'
|
|
280
|
+
: ''
|
|
281
|
+
}`}
|
|
282
|
+
>
|
|
283
|
+
<span className='min-w-0 break-all'>
|
|
284
|
+
{item.propertyName || '\u00a0'}
|
|
285
|
+
</span>
|
|
286
|
+
{nameErrors.get(item.propertyName) && (
|
|
287
|
+
<ErrorIndicator
|
|
288
|
+
local
|
|
289
|
+
errors={nameErrors.get(item.propertyName)!}
|
|
290
|
+
/>
|
|
291
|
+
)}
|
|
292
|
+
</span>
|
|
293
|
+
{enabled ? (
|
|
294
|
+
<div className='jsonforms-additional-property-actions flex shrink-0 items-center gap-0.5'>
|
|
295
|
+
<Button
|
|
296
|
+
className='h-6 w-6 text-muted-foreground [&_svg]:size-3'
|
|
297
|
+
variant='ghost'
|
|
298
|
+
size='icon'
|
|
299
|
+
disabled={readonly}
|
|
300
|
+
type='button'
|
|
301
|
+
aria-label={t('additionalProperties.renameNamed', {
|
|
302
|
+
name: item.propertyName,
|
|
303
|
+
})}
|
|
304
|
+
title={t('additionalProperties.renameNamed', {
|
|
305
|
+
name: item.propertyName,
|
|
306
|
+
})}
|
|
307
|
+
onClick={() => {
|
|
308
|
+
setRenamingPropertyName(item.propertyName);
|
|
309
|
+
setRenameValue(item.propertyName);
|
|
310
|
+
}}
|
|
311
|
+
>
|
|
312
|
+
<Pencil className='h-4 w-4' />
|
|
313
|
+
</Button>
|
|
314
|
+
<Button
|
|
315
|
+
className='h-6 w-6 bg-destructive/10 text-destructive hover:bg-destructive/20 [&_svg]:size-3'
|
|
316
|
+
variant='destructive'
|
|
317
|
+
size='icon'
|
|
318
|
+
disabled={removePropertyDisabled}
|
|
319
|
+
type='button'
|
|
320
|
+
aria-label={t('additionalProperties.deleteNamed', {
|
|
321
|
+
name: item.propertyName,
|
|
322
|
+
})}
|
|
323
|
+
title={t('additionalProperties.deleteNamed', {
|
|
324
|
+
name: item.propertyName,
|
|
325
|
+
})}
|
|
326
|
+
onClick={() => removeProperty(item.propertyName)}
|
|
327
|
+
>
|
|
328
|
+
<Trash2 className='h-4 w-4' />
|
|
329
|
+
</Button>
|
|
330
|
+
</div>
|
|
331
|
+
) : null}
|
|
332
|
+
</div>
|
|
333
|
+
<div className='jsonforms-additional-property-control min-w-0'>
|
|
334
|
+
{needsIsolatedEditor(item.propertyName) ? (
|
|
335
|
+
<>
|
|
336
|
+
<IsolatedPropertyEditor
|
|
337
|
+
value={objectData?.[item.propertyName]}
|
|
338
|
+
schema={literalPropertySchema(
|
|
339
|
+
item.schema,
|
|
340
|
+
rootSchema,
|
|
341
|
+
)}
|
|
342
|
+
uischema={{
|
|
343
|
+
type: 'Control',
|
|
344
|
+
scope: '#',
|
|
345
|
+
label: false,
|
|
346
|
+
}}
|
|
347
|
+
enabled={Boolean(enabled)}
|
|
348
|
+
readonly={readonly}
|
|
349
|
+
renderers={renderers}
|
|
350
|
+
cells={cells}
|
|
351
|
+
onChange={(value) =>
|
|
352
|
+
handleChange(
|
|
353
|
+
path,
|
|
354
|
+
assignOwnProperty(
|
|
355
|
+
{ ...objectData },
|
|
356
|
+
item.propertyName,
|
|
357
|
+
value === undefined
|
|
358
|
+
? clearedDynamicPropertyValue(
|
|
359
|
+
item.schema,
|
|
360
|
+
rootSchema,
|
|
361
|
+
objectData?.[item.propertyName],
|
|
362
|
+
)
|
|
363
|
+
: value,
|
|
364
|
+
),
|
|
365
|
+
)
|
|
366
|
+
}
|
|
367
|
+
/>
|
|
368
|
+
</>
|
|
369
|
+
) : (
|
|
370
|
+
<DynamicPropertyProvider
|
|
371
|
+
path={item.path}
|
|
372
|
+
schema={item.schema}
|
|
373
|
+
rootSchema={rootSchema}
|
|
374
|
+
>
|
|
375
|
+
<JsonFormsDispatch
|
|
376
|
+
schema={item.schema}
|
|
377
|
+
uischema={{ ...item.uischema, label: false } as any}
|
|
378
|
+
path={item.path}
|
|
379
|
+
enabled={enabled}
|
|
380
|
+
renderers={renderers}
|
|
381
|
+
cells={cells}
|
|
382
|
+
readonly={readonly}
|
|
383
|
+
/>
|
|
384
|
+
</DynamicPropertyProvider>
|
|
385
|
+
)}
|
|
386
|
+
</div>
|
|
387
|
+
</div>
|
|
388
|
+
))}
|
|
389
|
+
</div>
|
|
390
|
+
<div className={embedded ? undefined : 'px-4 pb-4'}>
|
|
391
|
+
<CollectionPager page={page} />
|
|
392
|
+
</div>
|
|
393
|
+
</Card>
|
|
394
|
+
|
|
395
|
+
<Dialog
|
|
396
|
+
open={renamingPropertyName !== null}
|
|
397
|
+
onOpenChange={(dialogOpen) => {
|
|
398
|
+
if (!dialogOpen) closeRenameDialog();
|
|
399
|
+
}}
|
|
400
|
+
>
|
|
401
|
+
<DialogContent className='max-w-sm'>
|
|
402
|
+
<DialogHeader>
|
|
403
|
+
<DialogTitle>{t('additionalProperties.renameTitle')}</DialogTitle>
|
|
404
|
+
<DialogDescription>
|
|
405
|
+
{t('additionalProperties.renameDialogDescription')}
|
|
406
|
+
</DialogDescription>
|
|
407
|
+
</DialogHeader>
|
|
408
|
+
<form
|
|
409
|
+
onSubmit={(event) => {
|
|
410
|
+
event.preventDefault();
|
|
411
|
+
if (renamingPropertyName) {
|
|
412
|
+
renameProperty(renamingPropertyName);
|
|
413
|
+
}
|
|
414
|
+
}}
|
|
415
|
+
>
|
|
416
|
+
<label
|
|
417
|
+
className='mb-2 block text-sm font-medium'
|
|
418
|
+
htmlFor='shadcn-rename-property'
|
|
419
|
+
>
|
|
420
|
+
{t('additionalProperties.renamePropertyNameLabel')}
|
|
421
|
+
</label>
|
|
422
|
+
<Input
|
|
423
|
+
id='shadcn-rename-property'
|
|
424
|
+
autoFocus
|
|
425
|
+
disabled={readonly}
|
|
426
|
+
value={renameValue}
|
|
427
|
+
aria-invalid={Boolean(renameError)}
|
|
428
|
+
onChange={(event) => setRenameValue(event.currentTarget.value)}
|
|
429
|
+
/>
|
|
430
|
+
{renameError ? (
|
|
431
|
+
<p className='mt-2 text-sm text-destructive' role='alert'>
|
|
432
|
+
{renameError}
|
|
433
|
+
</p>
|
|
434
|
+
) : null}
|
|
435
|
+
<DialogFooter className='mt-4'>
|
|
436
|
+
<Button
|
|
437
|
+
type='button'
|
|
438
|
+
variant='outline'
|
|
439
|
+
onClick={closeRenameDialog}
|
|
440
|
+
>
|
|
441
|
+
{t('combinator.cancel')}
|
|
442
|
+
</Button>
|
|
443
|
+
<Button type='submit' disabled={renameDisabled}>
|
|
444
|
+
{t('additionalProperties.renameConfirm')}
|
|
445
|
+
</Button>
|
|
446
|
+
</DialogFooter>
|
|
447
|
+
</form>
|
|
448
|
+
</DialogContent>
|
|
449
|
+
</Dialog>
|
|
450
|
+
</>
|
|
451
|
+
</PendingChangesProvider>
|
|
452
|
+
);
|
|
453
|
+
};
|