@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,160 @@
|
|
|
1
|
+
import { useI18n } from '@chobantonov/jsonforms-react-renderer-common/locale/translate';
|
|
2
|
+
import type { TimeValue } from './dateTime';
|
|
3
|
+
import type { ControlProps } from '@jsonforms/core';
|
|
4
|
+
import { useJsonForms } from '@jsonforms/react';
|
|
5
|
+
import { useEffect } from 'react';
|
|
6
|
+
import dayjs from 'dayjs';
|
|
7
|
+
import {
|
|
8
|
+
formatDate,
|
|
9
|
+
parseDateValue,
|
|
10
|
+
} from '@chobantonov/jsonforms-react-renderer-common/formats/dateValues';
|
|
11
|
+
import {
|
|
12
|
+
effectiveRestrict,
|
|
13
|
+
resolveDataBounds,
|
|
14
|
+
temporalBounds,
|
|
15
|
+
} from '@chobantonov/jsonforms-react-renderer-common/formats/temporalBounds';
|
|
16
|
+
import {
|
|
17
|
+
specDateSaveFormat,
|
|
18
|
+
specTimeSaveFormat,
|
|
19
|
+
specDateTimeSaveFormat,
|
|
20
|
+
warnOnSaveFormat,
|
|
21
|
+
} from '@chobantonov/jsonforms-react-renderer-common/formats/temporalFormats';
|
|
22
|
+
|
|
23
|
+
const saveFormats = {
|
|
24
|
+
date: specDateSaveFormat,
|
|
25
|
+
time: specTimeSaveFormat,
|
|
26
|
+
dateTime: specDateTimeSaveFormat,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const displayFormats = {
|
|
30
|
+
date: 'YYYY-MM-DD',
|
|
31
|
+
time: 'HH:mm',
|
|
32
|
+
dateTime: 'YYYY-MM-DD HH:mm',
|
|
33
|
+
};
|
|
34
|
+
const placeholderKeys = {
|
|
35
|
+
date: 'temporal.datePlaceholder',
|
|
36
|
+
time: 'temporal.timePlaceholder',
|
|
37
|
+
dateTime: 'temporal.dateTimePlaceholder',
|
|
38
|
+
} as const;
|
|
39
|
+
|
|
40
|
+
function resolveTimeViews(views: unknown, displayFormat: string) {
|
|
41
|
+
const timeViews = Array.isArray(views)
|
|
42
|
+
? views.filter((view) => ['hours', 'minutes', 'seconds'].includes(view))
|
|
43
|
+
: [];
|
|
44
|
+
const hasTimeViews = timeViews.length > 0;
|
|
45
|
+
return {
|
|
46
|
+
showHours: !hasTimeViews || timeViews.includes('hours'),
|
|
47
|
+
showMinutes: !hasTimeViews || timeViews.includes('minutes'),
|
|
48
|
+
useSeconds: hasTimeViews
|
|
49
|
+
? timeViews.includes('seconds')
|
|
50
|
+
: displayFormat.includes('s'),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function resolvePresentation(
|
|
55
|
+
options: NonNullable<ControlProps['config']>,
|
|
56
|
+
kind: keyof typeof saveFormats,
|
|
57
|
+
defaultPlaceholder: string,
|
|
58
|
+
) {
|
|
59
|
+
const ampm = options.ampm === true;
|
|
60
|
+
const displayFormat: string =
|
|
61
|
+
options[`${kind}Format`] ??
|
|
62
|
+
(kind === 'time' && ampm ? 'hh:mm a' : displayFormats[kind]);
|
|
63
|
+
const saveFormat: string = options[`${kind}SaveFormat`] ?? saveFormats[kind];
|
|
64
|
+
return {
|
|
65
|
+
ampm,
|
|
66
|
+
displayFormat,
|
|
67
|
+
saveFormat,
|
|
68
|
+
placeholder:
|
|
69
|
+
typeof options.placeholder === 'string'
|
|
70
|
+
? options.placeholder
|
|
71
|
+
: defaultPlaceholder,
|
|
72
|
+
...resolveTimeViews(options.views, displayFormat),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Shared serialization and bound policy for the three shadcn pickers. */
|
|
77
|
+
export function useTemporalControl(
|
|
78
|
+
props: ControlProps,
|
|
79
|
+
kind: keyof typeof saveFormats,
|
|
80
|
+
) {
|
|
81
|
+
const context = useJsonForms();
|
|
82
|
+
const options = { ...props.config, ...props.uischema.options };
|
|
83
|
+
const t = useI18n();
|
|
84
|
+
const presentation = resolvePresentation(
|
|
85
|
+
options,
|
|
86
|
+
kind,
|
|
87
|
+
t(placeholderKeys[kind]),
|
|
88
|
+
);
|
|
89
|
+
const { displayFormat, saveFormat, useSeconds } = presentation;
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
warnOnSaveFormat(props.schema.format, saveFormat);
|
|
92
|
+
}, [props.schema.format, saveFormat]);
|
|
93
|
+
const formats = [
|
|
94
|
+
saveFormat,
|
|
95
|
+
displayFormat,
|
|
96
|
+
'YYYY-MM-DDTHH:mm:ssZ',
|
|
97
|
+
'HH:mm:ssZ',
|
|
98
|
+
'HH:mm:ss',
|
|
99
|
+
];
|
|
100
|
+
const selected =
|
|
101
|
+
typeof props.data === 'string' ? parseDateValue(props.data, formats) : null;
|
|
102
|
+
const selectedTime: TimeValue | undefined = selected
|
|
103
|
+
? {
|
|
104
|
+
hours: selected.hour(),
|
|
105
|
+
minutes: selected.minute(),
|
|
106
|
+
seconds: selected.second(),
|
|
107
|
+
}
|
|
108
|
+
: undefined;
|
|
109
|
+
const precision = useSeconds ? 'second' : 'minute';
|
|
110
|
+
const schema = resolveDataBounds(
|
|
111
|
+
props.schema as Record<string, unknown>,
|
|
112
|
+
props.path,
|
|
113
|
+
context.core?.data,
|
|
114
|
+
);
|
|
115
|
+
const bounds = temporalBounds(
|
|
116
|
+
schema,
|
|
117
|
+
formats,
|
|
118
|
+
kind === 'date' ? 'day' : precision,
|
|
119
|
+
kind === 'time',
|
|
120
|
+
);
|
|
121
|
+
const restrict = effectiveRestrict(props.uischema.options, props.config);
|
|
122
|
+
const comparable = (value: Date) => {
|
|
123
|
+
const date = dayjs(value);
|
|
124
|
+
return kind === 'time' ? date.year(2000).month(0).date(1) : date;
|
|
125
|
+
};
|
|
126
|
+
const allowed = (value: Date) => {
|
|
127
|
+
if (!restrict) return true;
|
|
128
|
+
const date = comparable(value);
|
|
129
|
+
return (
|
|
130
|
+
!bounds.empty &&
|
|
131
|
+
!(bounds.min && date.isBefore(bounds.min)) &&
|
|
132
|
+
!(bounds.max && date.isAfter(bounds.max))
|
|
133
|
+
);
|
|
134
|
+
};
|
|
135
|
+
const disabledDate = (value: Date) =>
|
|
136
|
+
restrict &&
|
|
137
|
+
(bounds.empty ||
|
|
138
|
+
Boolean(bounds.min && dayjs(value).isBefore(bounds.min, 'day')) ||
|
|
139
|
+
Boolean(bounds.max && dayjs(value).isAfter(bounds.max, 'day')));
|
|
140
|
+
const commit = (value: Date) => {
|
|
141
|
+
const date = dayjs(value)
|
|
142
|
+
.second(useSeconds || kind === 'date' ? value.getSeconds() : 0)
|
|
143
|
+
.millisecond(0);
|
|
144
|
+
if (props.enabled && !props.readonly && allowed(date.toDate())) {
|
|
145
|
+
props.handleChange(props.path, formatDate(date, saveFormat));
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
options,
|
|
150
|
+
selected,
|
|
151
|
+
selectedTime,
|
|
152
|
+
...presentation,
|
|
153
|
+
displayText: selected ? formatDate(selected, displayFormat) : undefined,
|
|
154
|
+
allowed,
|
|
155
|
+
disabledDate,
|
|
156
|
+
commit,
|
|
157
|
+
min: restrict ? bounds.min?.toDate() : undefined,
|
|
158
|
+
max: restrict ? bounds.max?.toDate() : undefined,
|
|
159
|
+
};
|
|
160
|
+
}
|