@chobantonov/jsonforms-react-shadcn-extended-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 +30 -2
- package/lib/components/FileFeedback.d.ts +6 -0
- package/lib/components/ShadcnArrayFrame.d.ts +3 -0
- package/lib/components/ShadcnEditorButton.d.ts +5 -0
- package/lib/components/ShadcnEditorFrame.d.ts +3 -0
- package/lib/index.d.ts +13 -0
- package/lib/jsonforms-react-shadcn-extended.cjs.js +2 -0
- package/lib/jsonforms-react-shadcn-extended.cjs.js.map +1 -0
- package/lib/jsonforms-react-shadcn-extended.esm.js +1142 -0
- package/lib/jsonforms-react-shadcn-extended.esm.js.map +1 -0
- package/lib/renderers/AgGridArrayControlRenderer.d.ts +3 -0
- package/lib/renderers/ButtonRenderer.d.ts +7 -0
- package/lib/renderers/ColorControlRenderer.d.ts +6 -0
- package/lib/renderers/CronControlRenderer.d.ts +6 -0
- package/lib/renderers/DurationControlRenderer.d.ts +5 -0
- package/lib/renderers/FileControlRenderer.d.ts +15 -0
- package/lib/renderers/MarkupLabelRenderer.d.ts +3 -0
- package/lib/renderers/MaskControlRenderer.d.ts +5 -0
- package/lib/renderers/NullControlRenderer.d.ts +5 -0
- package/lib/renderers/ShadcnAgGridControlRenderer.d.ts +2 -0
- package/lib/renderers/ShadcnMonacoControlRenderer.d.ts +2 -0
- package/lib/renderers/SplitLayoutRenderer.d.ts +6 -0
- package/lib/renderers/index.d.ts +8 -0
- package/lib/theme.d.ts +8 -0
- package/lib/util/duration.d.ts +8 -0
- package/package.json +79 -3
- package/src/components/FileFeedback.tsx +51 -0
- package/src/components/ShadcnArrayFrame.tsx +53 -0
- package/src/components/ShadcnEditorButton.tsx +45 -0
- package/src/components/ShadcnEditorFrame.tsx +19 -0
- package/src/index.tsx +96 -0
- package/src/renderers/AgGridArrayControlRenderer.tsx +16 -0
- package/src/renderers/ButtonRenderer.tsx +49 -0
- package/src/renderers/ColorControlRenderer.tsx +336 -0
- package/src/renderers/CronControlRenderer.tsx +363 -0
- package/src/renderers/DurationControlRenderer.tsx +210 -0
- package/src/renderers/FileControlRenderer.tsx +294 -0
- package/src/renderers/MarkupLabelRenderer.tsx +17 -0
- package/src/renderers/MaskControlRenderer.tsx +65 -0
- package/src/renderers/NullControlRenderer.tsx +63 -0
- package/src/renderers/ShadcnAgGridControlRenderer.tsx +40 -0
- package/src/renderers/ShadcnMonacoControlRenderer.tsx +11 -0
- package/src/renderers/SplitLayoutRenderer.tsx +94 -0
- package/src/renderers/index.ts +9 -0
- package/src/theme.ts +35 -0
- package/src/util/duration.ts +37 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { FileFeedback } from '../components/FileFeedback';
|
|
2
|
+
import { File as FileIcon } from 'lucide-react';
|
|
3
|
+
import { Button } from '@jsonforms-react-shadcn-ui/button';
|
|
4
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
5
|
+
import {
|
|
6
|
+
FileArrayInput,
|
|
7
|
+
fileArrayTester,
|
|
8
|
+
fileItemSchema,
|
|
9
|
+
attachmentName,
|
|
10
|
+
} from '@chobantonov/jsonforms-react-renderer-common/controls/FileArrayInput';
|
|
11
|
+
import {
|
|
12
|
+
ControlProps,
|
|
13
|
+
JsonSchema,
|
|
14
|
+
RankedTester,
|
|
15
|
+
and,
|
|
16
|
+
rankWith,
|
|
17
|
+
schemaMatches,
|
|
18
|
+
uiTypeIs,
|
|
19
|
+
} from '@jsonforms/core';
|
|
20
|
+
import { withJsonFormsControlProps } from '@jsonforms/react';
|
|
21
|
+
import {
|
|
22
|
+
InputShell,
|
|
23
|
+
ShadcnCellMode,
|
|
24
|
+
ClearValueButton,
|
|
25
|
+
makeId,
|
|
26
|
+
} from '@chobantonov/jsonforms-react-shadcn-renderers';
|
|
27
|
+
import { Input } from '@jsonforms-react-shadcn-ui/input';
|
|
28
|
+
|
|
29
|
+
import React from 'react';
|
|
30
|
+
|
|
31
|
+
const FileActionButton = (
|
|
32
|
+
props: React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
33
|
+
) => <Button {...props} type='button' variant='ghost' size='sm' />;
|
|
34
|
+
const FilePill = (props: React.HTMLAttributes<HTMLSpanElement>) => (
|
|
35
|
+
<span {...props} className='bg-secondary text-secondary-foreground text-sm' />
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export type JsonSchemaWithContent = JsonSchema & {
|
|
39
|
+
contentEncoding?: string;
|
|
40
|
+
contentMediaType?: string;
|
|
41
|
+
formatMinimum?: number;
|
|
42
|
+
formatMaximum?: number;
|
|
43
|
+
formatExclusiveMinimum?: number;
|
|
44
|
+
formatExclusiveMaximum?: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const isStringFileSchema = (schema: JsonSchema): boolean =>
|
|
48
|
+
schema.type === 'string' &&
|
|
49
|
+
((schema as JsonSchemaWithContent).contentEncoding === 'base64' ||
|
|
50
|
+
schema.format === 'binary' ||
|
|
51
|
+
schema.format === 'byte');
|
|
52
|
+
|
|
53
|
+
const singleFileTester: RankedTester = rankWith(
|
|
54
|
+
2,
|
|
55
|
+
and(uiTypeIs('Control'), schemaMatches(isStringFileSchema)),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
export const fileControlTester: RankedTester = (ui, schema, context) =>
|
|
59
|
+
Math.max(
|
|
60
|
+
singleFileTester(ui, schema, context),
|
|
61
|
+
fileArrayTester(ui, schema, context),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const optionNumber = (value: unknown): number | undefined => {
|
|
65
|
+
const result = Number(value);
|
|
66
|
+
return value !== undefined && Number.isFinite(result) && result >= 0
|
|
67
|
+
? result
|
|
68
|
+
: undefined;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const readFile = (
|
|
72
|
+
file: File,
|
|
73
|
+
schema: JsonSchemaWithContent,
|
|
74
|
+
): Promise<string> =>
|
|
75
|
+
new Promise((resolve, reject) => {
|
|
76
|
+
const reader = new FileReader();
|
|
77
|
+
reader.onerror = () =>
|
|
78
|
+
reject(reader.error ?? new Error('Failed to read file'));
|
|
79
|
+
reader.onload = () => {
|
|
80
|
+
const dataUrl = String(reader.result ?? '');
|
|
81
|
+
if (schema.format === 'uri') {
|
|
82
|
+
resolve(dataUrl);
|
|
83
|
+
} else if (schema.format === 'binary') {
|
|
84
|
+
const marker = dataUrl.indexOf(';base64,');
|
|
85
|
+
resolve(
|
|
86
|
+
marker < 0
|
|
87
|
+
? dataUrl
|
|
88
|
+
: `${dataUrl.slice(0, marker)};filename=${encodeURIComponent(
|
|
89
|
+
file.name,
|
|
90
|
+
)}${dataUrl.slice(marker)}`,
|
|
91
|
+
);
|
|
92
|
+
} else {
|
|
93
|
+
resolve(dataUrl.slice(dataUrl.indexOf(',') + 1));
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
reader.readAsDataURL(file);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const ShadcnSingleFileControl = (props: ControlProps) => {
|
|
100
|
+
const fileInput = React.useRef<HTMLInputElement>(null);
|
|
101
|
+
const t = useI18n();
|
|
102
|
+
const [attachment, setAttachment] = React.useState<{
|
|
103
|
+
value: string;
|
|
104
|
+
name: string;
|
|
105
|
+
}>();
|
|
106
|
+
const [busy, setBusy] = React.useState(false);
|
|
107
|
+
const cell = React.useContext(ShadcnCellMode);
|
|
108
|
+
const [severity, setSeverity] = React.useState<'warning' | 'error'>(
|
|
109
|
+
'warning',
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const [localError, setLocalError] = React.useState('');
|
|
113
|
+
const [previousData, setPreviousData] = React.useState(props.data);
|
|
114
|
+
if (!Object.is(previousData, props.data)) {
|
|
115
|
+
setPreviousData(() => props.data);
|
|
116
|
+
setLocalError('');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!props.visible) return null;
|
|
120
|
+
const schema = props.schema as JsonSchemaWithContent;
|
|
121
|
+
const options = { ...props.config, ...props.uischema.options };
|
|
122
|
+
const id = makeId(props.path, props.label);
|
|
123
|
+
const minimum = optionNumber(
|
|
124
|
+
schema.formatMinimum ??
|
|
125
|
+
schema.formatExclusiveMinimum ??
|
|
126
|
+
options.formatMinimum ??
|
|
127
|
+
options.formatExclusiveMinimum,
|
|
128
|
+
);
|
|
129
|
+
const maximum = optionNumber(
|
|
130
|
+
schema.formatMaximum ??
|
|
131
|
+
schema.formatExclusiveMaximum ??
|
|
132
|
+
options.formatMaximum ??
|
|
133
|
+
options.formatExclusiveMaximum,
|
|
134
|
+
);
|
|
135
|
+
const exclusiveMin =
|
|
136
|
+
schema.formatMinimum === undefined &&
|
|
137
|
+
(schema.formatExclusiveMinimum !== undefined ||
|
|
138
|
+
options.formatExclusiveMinimum !== undefined);
|
|
139
|
+
const exclusiveMax =
|
|
140
|
+
schema.formatMaximum === undefined &&
|
|
141
|
+
(schema.formatExclusiveMaximum !== undefined ||
|
|
142
|
+
options.formatExclusiveMaximum !== undefined);
|
|
143
|
+
|
|
144
|
+
const displayName = props.data
|
|
145
|
+
? (attachmentName(props.data) ??
|
|
146
|
+
(attachment && attachment.value === props.data
|
|
147
|
+
? attachment.name
|
|
148
|
+
: t('file.attached')))
|
|
149
|
+
: '';
|
|
150
|
+
return (
|
|
151
|
+
<InputShell
|
|
152
|
+
{...props}
|
|
153
|
+
id={id}
|
|
154
|
+
label={props.label}
|
|
155
|
+
required={props.required}
|
|
156
|
+
description={props.description}
|
|
157
|
+
errors={props.errors}
|
|
158
|
+
>
|
|
159
|
+
<div className='shadcn-jsonforms-file-control group relative flex items-center min-w-0 w-full'>
|
|
160
|
+
<Input
|
|
161
|
+
ref={fileInput}
|
|
162
|
+
style={{ display: 'none' }}
|
|
163
|
+
id={id}
|
|
164
|
+
type='file'
|
|
165
|
+
accept={
|
|
166
|
+
schema.contentMediaType ||
|
|
167
|
+
(typeof options.accept === 'string' ? options.accept : undefined)
|
|
168
|
+
}
|
|
169
|
+
required={props.required}
|
|
170
|
+
disabled={!props.enabled || props.readonly || busy}
|
|
171
|
+
onChange={async (event) => {
|
|
172
|
+
const file = event.currentTarget.files?.[0];
|
|
173
|
+
if (!file) return;
|
|
174
|
+
setSeverity('warning');
|
|
175
|
+
if (
|
|
176
|
+
minimum !== undefined &&
|
|
177
|
+
(exclusiveMin ? file.size <= minimum : file.size < minimum)
|
|
178
|
+
) {
|
|
179
|
+
setLocalError(
|
|
180
|
+
t('file.rejected', {
|
|
181
|
+
name: file.name,
|
|
182
|
+
reason: t('file.sizeBound', {
|
|
183
|
+
name: file.name,
|
|
184
|
+
bound: t(exclusiveMin ? 'file.moreThan' : 'file.atLeast'),
|
|
185
|
+
limit: minimum,
|
|
186
|
+
}),
|
|
187
|
+
}),
|
|
188
|
+
);
|
|
189
|
+
event.currentTarget.value = '';
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (
|
|
193
|
+
maximum !== undefined &&
|
|
194
|
+
(exclusiveMax ? file.size >= maximum : file.size > maximum)
|
|
195
|
+
) {
|
|
196
|
+
setLocalError(
|
|
197
|
+
t('file.rejected', {
|
|
198
|
+
name: file.name,
|
|
199
|
+
reason: t('file.sizeBound', {
|
|
200
|
+
name: file.name,
|
|
201
|
+
bound: t(exclusiveMax ? 'file.lessThan' : 'file.atMost'),
|
|
202
|
+
limit: maximum,
|
|
203
|
+
}),
|
|
204
|
+
}),
|
|
205
|
+
);
|
|
206
|
+
event.currentTarget.value = '';
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
setBusy(true);
|
|
210
|
+
setLocalError('');
|
|
211
|
+
try {
|
|
212
|
+
const value = await readFile(file, schema);
|
|
213
|
+
props.handleChange(props.path, value);
|
|
214
|
+
setAttachment({ value, name: file.name });
|
|
215
|
+
} catch {
|
|
216
|
+
setSeverity('error');
|
|
217
|
+
setLocalError(t('file.readFailed'));
|
|
218
|
+
} finally {
|
|
219
|
+
setBusy(false);
|
|
220
|
+
}
|
|
221
|
+
}}
|
|
222
|
+
/>
|
|
223
|
+
<Button
|
|
224
|
+
type='button'
|
|
225
|
+
variant='ghost'
|
|
226
|
+
size='icon'
|
|
227
|
+
className='absolute left-1 z-10 h-7 w-7'
|
|
228
|
+
disabled={!props.enabled || props.readonly || busy}
|
|
229
|
+
onClick={() => fileInput.current?.click()}
|
|
230
|
+
aria-label={
|
|
231
|
+
props.label
|
|
232
|
+
? props.label + ': ' + t('file.select')
|
|
233
|
+
: t('file.select')
|
|
234
|
+
}
|
|
235
|
+
>
|
|
236
|
+
<FileIcon className='h-4 w-4' />
|
|
237
|
+
</Button>
|
|
238
|
+
<Input
|
|
239
|
+
readOnly
|
|
240
|
+
disabled={!props.enabled || props.readonly}
|
|
241
|
+
className={cell && localError ? 'pl-10 pr-16' : 'pl-10 pr-10'}
|
|
242
|
+
aria-label={props.label}
|
|
243
|
+
aria-invalid={Boolean(props.errors)}
|
|
244
|
+
value={displayName}
|
|
245
|
+
title={displayName}
|
|
246
|
+
/>
|
|
247
|
+
{cell && localError && (
|
|
248
|
+
<div className='absolute right-10'>
|
|
249
|
+
<FileFeedback message={localError} cell severity={severity} />
|
|
250
|
+
</div>
|
|
251
|
+
)}
|
|
252
|
+
<ClearValueButton
|
|
253
|
+
data={props.data}
|
|
254
|
+
enabled={props.enabled && !busy}
|
|
255
|
+
readonly={props.readonly}
|
|
256
|
+
clearable={options.clearable !== false}
|
|
257
|
+
onClear={() => {
|
|
258
|
+
props.handleChange(props.path, undefined);
|
|
259
|
+
setAttachment(undefined);
|
|
260
|
+
setLocalError('');
|
|
261
|
+
if (fileInput.current) fileInput.current.value = '';
|
|
262
|
+
}}
|
|
263
|
+
/>
|
|
264
|
+
</div>
|
|
265
|
+
{localError && !cell && (
|
|
266
|
+
<FileFeedback message={localError} severity={severity} />
|
|
267
|
+
)}
|
|
268
|
+
{busy ? <div role='status'>{t('file.reading')}</div> : null}
|
|
269
|
+
</InputShell>
|
|
270
|
+
);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export const ShadcnFileControl = (props: ControlProps) => {
|
|
274
|
+
const cell = React.useContext(ShadcnCellMode);
|
|
275
|
+
if (!fileItemSchema(props.schema, props.rootSchema))
|
|
276
|
+
return <ShadcnSingleFileControl {...props} />;
|
|
277
|
+
if (!props.visible) return null;
|
|
278
|
+
const id = makeId(props.path, props.label);
|
|
279
|
+
return (
|
|
280
|
+
<InputShell {...props} id={id}>
|
|
281
|
+
<FileArrayInput
|
|
282
|
+
{...props}
|
|
283
|
+
isValid={!props.errors}
|
|
284
|
+
cell={cell}
|
|
285
|
+
FeedbackComponent={FileFeedback}
|
|
286
|
+
id={id}
|
|
287
|
+
ButtonComponent={FileActionButton}
|
|
288
|
+
PillComponent={FilePill}
|
|
289
|
+
/>
|
|
290
|
+
</InputShell>
|
|
291
|
+
);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export const FileControlRenderer = withJsonFormsControlProps(ShadcnFileControl);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createMarkupLabelRenderer } from '@chobantonov/jsonforms-react-extended-renderers';
|
|
3
|
+
|
|
4
|
+
/** Block markup needs a block wrapper; inline labels keep inline semantics. */
|
|
5
|
+
export const ShadcnMarkupLabelRenderer = createMarkupLabelRenderer(
|
|
6
|
+
({ block, children }) => {
|
|
7
|
+
const Component = block ? 'div' : 'span';
|
|
8
|
+
return (
|
|
9
|
+
<Component
|
|
10
|
+
data-markup-typography
|
|
11
|
+
className='text-sm leading-relaxed [&_a]:text-primary [&_a]:underline [&_p]:my-2 [&_ul]:list-disc [&_ul]:pl-6'
|
|
12
|
+
>
|
|
13
|
+
{children}
|
|
14
|
+
</Component>
|
|
15
|
+
);
|
|
16
|
+
},
|
|
17
|
+
);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ControlProps } from '@jsonforms/core';
|
|
2
|
+
import {
|
|
3
|
+
ClearValueButton,
|
|
4
|
+
InputShell,
|
|
5
|
+
makeId,
|
|
6
|
+
} from '@chobantonov/jsonforms-react-shadcn-renderers';
|
|
7
|
+
import { withJsonFormsControlProps } from '@jsonforms/react';
|
|
8
|
+
import { extendedMaskTester } from '@chobantonov/jsonforms-react-extended-renderers';
|
|
9
|
+
import { Input } from '@jsonforms-react-shadcn-ui/input';
|
|
10
|
+
|
|
11
|
+
import React, { useRef, useCallback } from 'react';
|
|
12
|
+
import { useMaskedInput } from '@chobantonov/jsonforms-react-renderer-common/formats/useMaskedInput';
|
|
13
|
+
|
|
14
|
+
export const ShadcnMaskControl = React.memo(function ShadcnMaskControl(
|
|
15
|
+
props: ControlProps,
|
|
16
|
+
) {
|
|
17
|
+
const { data, enabled, path } = props;
|
|
18
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
19
|
+
const getInput = useCallback(() => inputRef.current, []);
|
|
20
|
+
const {
|
|
21
|
+
appliedUiSchemaOptions,
|
|
22
|
+
settings,
|
|
23
|
+
display,
|
|
24
|
+
onClear,
|
|
25
|
+
onChange,
|
|
26
|
+
onCompositionStart,
|
|
27
|
+
onCompositionEnd,
|
|
28
|
+
} = useMaskedInput(props, getInput, 'defer');
|
|
29
|
+
|
|
30
|
+
if (props.visible === false) return null;
|
|
31
|
+
const id = makeId(path, props.label);
|
|
32
|
+
return (
|
|
33
|
+
<InputShell {...props} id={id}>
|
|
34
|
+
<div className='group relative w-full'>
|
|
35
|
+
<ClearValueButton
|
|
36
|
+
clearable={appliedUiSchemaOptions.clearable !== false}
|
|
37
|
+
data={data}
|
|
38
|
+
enabled={enabled && !props.readonly}
|
|
39
|
+
onClear={onClear}
|
|
40
|
+
/>
|
|
41
|
+
<Input
|
|
42
|
+
ref={inputRef}
|
|
43
|
+
value={display}
|
|
44
|
+
onChange={onChange}
|
|
45
|
+
onCompositionStart={onCompositionStart}
|
|
46
|
+
onCompositionEnd={onCompositionEnd}
|
|
47
|
+
className='pr-10'
|
|
48
|
+
id={id}
|
|
49
|
+
disabled={!enabled || props.readonly}
|
|
50
|
+
aria-invalid={Boolean(props.errors)}
|
|
51
|
+
autoFocus={appliedUiSchemaOptions.focus}
|
|
52
|
+
style={{ width: '100%' }}
|
|
53
|
+
placeholder={
|
|
54
|
+
appliedUiSchemaOptions.placeholder ??
|
|
55
|
+
(typeof settings?.mask === 'string' ? settings.mask : undefined)
|
|
56
|
+
}
|
|
57
|
+
data-mask-input
|
|
58
|
+
/>
|
|
59
|
+
</div>
|
|
60
|
+
</InputShell>
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export const maskControlTester = extendedMaskTester;
|
|
65
|
+
export const MaskControlRenderer = withJsonFormsControlProps(ShadcnMaskControl);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ControlProps,
|
|
3
|
+
JsonSchema,
|
|
4
|
+
RankedTester,
|
|
5
|
+
and,
|
|
6
|
+
rankWith,
|
|
7
|
+
schemaMatches,
|
|
8
|
+
uiTypeIs,
|
|
9
|
+
} from '@jsonforms/core';
|
|
10
|
+
import { withJsonFormsControlProps } from '@jsonforms/react';
|
|
11
|
+
import {
|
|
12
|
+
InputShell,
|
|
13
|
+
makeId,
|
|
14
|
+
} from '@chobantonov/jsonforms-react-shadcn-renderers';
|
|
15
|
+
import { Checkbox } from '@jsonforms-react-shadcn-ui/checkbox';
|
|
16
|
+
|
|
17
|
+
import React from 'react';
|
|
18
|
+
|
|
19
|
+
export const nullControlTester: RankedTester = rankWith(
|
|
20
|
+
2,
|
|
21
|
+
and(
|
|
22
|
+
uiTypeIs('Control'),
|
|
23
|
+
schemaMatches((schema: JsonSchema) => schema.type === 'null'),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export const ShadcnNullControl = (props: ControlProps) => {
|
|
28
|
+
if (!props.visible) return null;
|
|
29
|
+
const id = makeId(props.path, props.label);
|
|
30
|
+
return (
|
|
31
|
+
<InputShell
|
|
32
|
+
{...props}
|
|
33
|
+
id={id}
|
|
34
|
+
label={undefined}
|
|
35
|
+
description={props.description}
|
|
36
|
+
errors={props.errors}
|
|
37
|
+
>
|
|
38
|
+
<label className='shadcn-jsonforms-checkbox-label' htmlFor={id}>
|
|
39
|
+
<Checkbox
|
|
40
|
+
className='shadcn-jsonforms-checkbox-control'
|
|
41
|
+
id={id}
|
|
42
|
+
checked={
|
|
43
|
+
props.data === null
|
|
44
|
+
? true
|
|
45
|
+
: props.data === undefined
|
|
46
|
+
? false
|
|
47
|
+
: 'indeterminate'
|
|
48
|
+
}
|
|
49
|
+
disabled={!props.enabled || props.readonly}
|
|
50
|
+
onCheckedChange={(checked) =>
|
|
51
|
+
props.handleChange(props.path, checked ? null : undefined)
|
|
52
|
+
}
|
|
53
|
+
/>
|
|
54
|
+
<span>
|
|
55
|
+
{props.label}
|
|
56
|
+
{props.required ? ' *' : ''}
|
|
57
|
+
</span>
|
|
58
|
+
</label>
|
|
59
|
+
</InputShell>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const NullControlRenderer = withJsonFormsControlProps(ShadcnNullControl);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createDeleteConfirmation } from '@chobantonov/jsonforms-react-renderer-common/interaction/createDeleteConfirmation';
|
|
2
|
+
import {
|
|
3
|
+
ErrorIndicator,
|
|
4
|
+
ShadcnGridCellFrame,
|
|
5
|
+
RowDetailFrame,
|
|
6
|
+
RowDetailEditButton,
|
|
7
|
+
useConfirmation,
|
|
8
|
+
} from '@chobantonov/jsonforms-react-shadcn-renderers';
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import { Plus, Trash2, Pencil, Eye, EyeOff } from 'lucide-react';
|
|
11
|
+
import { ShadcnArrayFrame } from '../components/ShadcnArrayFrame';
|
|
12
|
+
import { createAgGridControlRenderer } from '@chobantonov/jsonforms-react-extended-renderers';
|
|
13
|
+
import { ShadcnEditorButton } from '../components/ShadcnEditorButton';
|
|
14
|
+
import { ShadcnEditorFrame } from '../components/ShadcnEditorFrame';
|
|
15
|
+
const useAgGridRemoveConfirmation = createDeleteConfirmation(
|
|
16
|
+
useConfirmation,
|
|
17
|
+
'agGrid',
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const ShadcnAgGridControlRenderer = createAgGridControlRenderer({
|
|
21
|
+
RowErrorIndicator: ({ message }) => <ErrorIndicator errors={message} />,
|
|
22
|
+
Frame: ShadcnEditorFrame,
|
|
23
|
+
RowDetailButton: (props) => (
|
|
24
|
+
<RowDetailEditButton
|
|
25
|
+
label={props['aria-label'] ?? props.title ?? ''}
|
|
26
|
+
onClick={props.onClick}
|
|
27
|
+
disabled={props.disabled}
|
|
28
|
+
/>
|
|
29
|
+
),
|
|
30
|
+
RowDetailFrame,
|
|
31
|
+
useRemoveConfirmation: useAgGridRemoveConfirmation,
|
|
32
|
+
EditIcon: Pencil,
|
|
33
|
+
ShowDetailsIcon: Eye,
|
|
34
|
+
HideDetailsIcon: EyeOff,
|
|
35
|
+
CellFrame: ShadcnGridCellFrame,
|
|
36
|
+
ArrayFrame: ShadcnArrayFrame,
|
|
37
|
+
AddIcon: Plus,
|
|
38
|
+
RemoveIcon: Trash2,
|
|
39
|
+
Button: ShadcnEditorButton,
|
|
40
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createMonacoControlRenderer } from '@chobantonov/jsonforms-react-extended-renderers';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Maximize, Minimize } from 'lucide-react';
|
|
4
|
+
import { ShadcnEditorToggleButton } from '../components/ShadcnEditorButton';
|
|
5
|
+
import { ShadcnEditorFrame } from '../components/ShadcnEditorFrame';
|
|
6
|
+
export const ShadcnMonacoControlRenderer = createMonacoControlRenderer({
|
|
7
|
+
Frame: ShadcnEditorFrame,
|
|
8
|
+
Button: ShadcnEditorToggleButton,
|
|
9
|
+
MaximizeIcon: () => <Maximize aria-hidden='true' />,
|
|
10
|
+
MinimizeIcon: () => <Minimize aria-hidden='true' />,
|
|
11
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
2
|
+
import {
|
|
3
|
+
Layout,
|
|
4
|
+
LayoutProps,
|
|
5
|
+
RankedTester,
|
|
6
|
+
UISchemaElement,
|
|
7
|
+
and,
|
|
8
|
+
or,
|
|
9
|
+
rankWith,
|
|
10
|
+
uiTypeIs,
|
|
11
|
+
} from '@jsonforms/core';
|
|
12
|
+
|
|
13
|
+
export const hasSplitLayoutVariant = (uischema: UISchemaElement): boolean =>
|
|
14
|
+
String(uischema.options?.variant ?? '').toLowerCase() === 'splitter';
|
|
15
|
+
|
|
16
|
+
export const splitLayoutTester: RankedTester = rankWith(
|
|
17
|
+
5,
|
|
18
|
+
and(
|
|
19
|
+
or(uiTypeIs('HorizontalLayout'), uiTypeIs('VerticalLayout')),
|
|
20
|
+
hasSplitLayoutVariant,
|
|
21
|
+
),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
import React from 'react';
|
|
25
|
+
import { JsonFormsDispatch, withJsonFormsLayoutProps } from '@jsonforms/react';
|
|
26
|
+
import { useEffectiveElements } from '@chobantonov/jsonforms-react-renderer-common/layout/layoutContext';
|
|
27
|
+
import {
|
|
28
|
+
initialSplitSizes,
|
|
29
|
+
splitCssSize,
|
|
30
|
+
} from '@chobantonov/jsonforms-react-extended-renderers';
|
|
31
|
+
import {
|
|
32
|
+
ResizablePanelGroup,
|
|
33
|
+
ResizablePanel,
|
|
34
|
+
ResizableHandle,
|
|
35
|
+
} from '@jsonforms-react-shadcn-ui/resizable';
|
|
36
|
+
|
|
37
|
+
export const ShadcnSplitLayout = (props: LayoutProps) => {
|
|
38
|
+
const t = useI18n();
|
|
39
|
+
const layout = props.uischema as Layout;
|
|
40
|
+
const elements = useEffectiveElements(
|
|
41
|
+
layout.elements,
|
|
42
|
+
props.path,
|
|
43
|
+
props.config,
|
|
44
|
+
);
|
|
45
|
+
const horizontal = layout.type === 'HorizontalLayout';
|
|
46
|
+
const options = { ...props.config, ...layout.options };
|
|
47
|
+
const sizes = initialSplitSizes(elements);
|
|
48
|
+
if (!props.visible || !elements.length) return null;
|
|
49
|
+
return (
|
|
50
|
+
<ResizablePanelGroup
|
|
51
|
+
orientation={horizontal ? 'horizontal' : 'vertical'}
|
|
52
|
+
disabled={options.resizable === false}
|
|
53
|
+
data-layout-diagnostic={
|
|
54
|
+
options.wrap
|
|
55
|
+
? '`wrap` is not supported together with the splitter variant; ignored.'
|
|
56
|
+
: undefined
|
|
57
|
+
}
|
|
58
|
+
style={{
|
|
59
|
+
width: '100%',
|
|
60
|
+
minWidth: 0,
|
|
61
|
+
height: horizontal
|
|
62
|
+
? undefined
|
|
63
|
+
: (splitCssSize(options.height) ?? '20rem'),
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
{elements.map((element, index) => (
|
|
67
|
+
<React.Fragment key={index}>
|
|
68
|
+
{index > 0 && (
|
|
69
|
+
<ResizableHandle
|
|
70
|
+
withHandle
|
|
71
|
+
aria-label={t('layout.resizePane', { index })}
|
|
72
|
+
disabled={options.resizable === false}
|
|
73
|
+
/>
|
|
74
|
+
)}
|
|
75
|
+
<ResizablePanel
|
|
76
|
+
defaultSize={`${sizes[index]}%`}
|
|
77
|
+
minSize='1%'
|
|
78
|
+
style={{ overflow: 'auto', padding: 8 }}
|
|
79
|
+
>
|
|
80
|
+
<JsonFormsDispatch
|
|
81
|
+
schema={props.schema}
|
|
82
|
+
uischema={element}
|
|
83
|
+
path={props.path}
|
|
84
|
+
enabled={props.enabled}
|
|
85
|
+
renderers={props.renderers}
|
|
86
|
+
cells={props.cells}
|
|
87
|
+
/>
|
|
88
|
+
</ResizablePanel>
|
|
89
|
+
</React.Fragment>
|
|
90
|
+
))}
|
|
91
|
+
</ResizablePanelGroup>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
export const SplitLayoutRenderer = withJsonFormsLayoutProps(ShadcnSplitLayout);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './ButtonRenderer';
|
|
2
|
+
export * from './AgGridArrayControlRenderer';
|
|
3
|
+
export * from './ColorControlRenderer';
|
|
4
|
+
export * from './DurationControlRenderer';
|
|
5
|
+
export * from './FileControlRenderer';
|
|
6
|
+
export * from './NullControlRenderer';
|
|
7
|
+
export * from './SplitLayoutRenderer';
|
|
8
|
+
|
|
9
|
+
export * from './CronControlRenderer';
|
package/src/theme.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
|
|
3
|
+
export type ShadcnRendererSettings = {
|
|
4
|
+
accentColor?: string;
|
|
5
|
+
borderRadius?: number;
|
|
6
|
+
density?: 'comfortable' | 'compact';
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const defaultShadcnRendererSettings: ShadcnRendererSettings = {
|
|
10
|
+
accentColor: '#0f172a',
|
|
11
|
+
borderRadius: 6,
|
|
12
|
+
density: 'comfortable',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const createShadcnRendererStyle = (
|
|
16
|
+
settings: ShadcnRendererSettings = defaultShadcnRendererSettings,
|
|
17
|
+
dark = false,
|
|
18
|
+
) => {
|
|
19
|
+
const radius =
|
|
20
|
+
settings.borderRadius ?? defaultShadcnRendererSettings.borderRadius;
|
|
21
|
+
const configuredAccent =
|
|
22
|
+
settings.accentColor ?? defaultShadcnRendererSettings.accentColor;
|
|
23
|
+
const accent =
|
|
24
|
+
dark && configuredAccent === defaultShadcnRendererSettings.accentColor
|
|
25
|
+
? '#f8fafc'
|
|
26
|
+
: configuredAccent;
|
|
27
|
+
const compact = settings.density === 'compact';
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
'--shadcn-jsonforms-accent': accent,
|
|
31
|
+
'--shadcn-jsonforms-radius': `${radius}px`,
|
|
32
|
+
colorScheme: dark ? 'dark' : 'light',
|
|
33
|
+
fontSize: compact ? '13px' : '14px',
|
|
34
|
+
} as React.CSSProperties;
|
|
35
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EMPTY_DURATION,
|
|
3
|
+
parseDuration as parseComponents,
|
|
4
|
+
sanitizeComponents,
|
|
5
|
+
formatDurationComponents,
|
|
6
|
+
type DurationParts as Components,
|
|
7
|
+
} from '@chobantonov/jsonforms-react-renderer-common/formats/duration';
|
|
8
|
+
|
|
9
|
+
export interface DurationParts extends Components {
|
|
10
|
+
weeks: number;
|
|
11
|
+
}
|
|
12
|
+
export const EMPTY_DURATION_PARTS: DurationParts = {
|
|
13
|
+
weeks: 0,
|
|
14
|
+
...EMPTY_DURATION,
|
|
15
|
+
};
|
|
16
|
+
const WEEKS = /^P(?<weeks>\d+)W$/i;
|
|
17
|
+
const number = (value?: string) => (value ? Number.parseInt(value, 10) : 0);
|
|
18
|
+
|
|
19
|
+
export const parseDuration = (value: unknown): DurationParts | null => {
|
|
20
|
+
if (typeof value !== 'string' || !value.trim()) return null;
|
|
21
|
+
const week = value.trim().match(WEEKS);
|
|
22
|
+
if (week?.groups)
|
|
23
|
+
return { ...EMPTY_DURATION_PARTS, weeks: number(week.groups.weeks) };
|
|
24
|
+
const parts = parseComponents(value);
|
|
25
|
+
return parts ? { weeks: 0, ...parts } : null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const sanitizeDurationParts = (parts: DurationParts): DurationParts => {
|
|
29
|
+
const next = sanitizeComponents(parts);
|
|
30
|
+
return next.weeks ? { ...EMPTY_DURATION_PARTS, weeks: next.weeks } : next;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const formatDurationIso = (input: DurationParts): string => {
|
|
34
|
+
const parts = sanitizeDurationParts(input);
|
|
35
|
+
if (parts.weeks) return `P${parts.weeks}W`;
|
|
36
|
+
return formatDurationComponents(parts);
|
|
37
|
+
};
|