@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.
Files changed (154) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -2
  3. package/lib/additional/LabelRenderer.d.ts +4 -0
  4. package/lib/additional/index.d.ts +1 -0
  5. package/lib/cells/BooleanCell.d.ts +3 -0
  6. package/lib/cells/Cell.d.ts +3 -0
  7. package/lib/cells/CompositeCell.d.ts +9 -0
  8. package/lib/cells/CompositeDetailDialog.d.ts +3 -0
  9. package/lib/cells/EnumCell.d.ts +3 -0
  10. package/lib/cells/NumberCell.d.ts +3 -0
  11. package/lib/cells/NumberFormatCell.d.ts +4 -0
  12. package/lib/cells/TextCell.d.ts +3 -0
  13. package/lib/cells/asCell.d.ts +12 -0
  14. package/lib/cells/index.d.ts +7 -0
  15. package/lib/complex/AdditionalProperties.d.ts +4 -0
  16. package/lib/complex/AnyOfRenderer.d.ts +7 -0
  17. package/lib/complex/ArrayChoicesControl.d.ts +6 -0
  18. package/lib/complex/ArrayControlRenderer.d.ts +4 -0
  19. package/lib/complex/ArrayPanelToggle.d.ts +6 -0
  20. package/lib/complex/CollectionPager.d.ts +5 -0
  21. package/lib/complex/CombinatorSwitchDialog.d.ts +8 -0
  22. package/lib/complex/DeleteDialog.d.ts +6 -0
  23. package/lib/complex/DetailDialogContent.d.ts +7 -0
  24. package/lib/complex/ErrorIndicator.d.ts +7 -0
  25. package/lib/complex/MixedRenderer.d.ts +6 -0
  26. package/lib/complex/ObjectRenderer.d.ts +3 -0
  27. package/lib/complex/OneOfRenderer.d.ts +5 -0
  28. package/lib/complex/RecursiveTreeRenderer.d.ts +4 -0
  29. package/lib/complex/RowDetailFrame.d.ts +16 -0
  30. package/lib/complex/ScalarCompositionRenderer.d.ts +4 -0
  31. package/lib/complex/TupleAdditionalItems.d.ts +4 -0
  32. package/lib/complex/TupleControlRenderer.d.ts +6 -0
  33. package/lib/complex/TupleField.d.ts +4 -0
  34. package/lib/complex/array/ArrayItemPanels.d.ts +18 -0
  35. package/lib/complex/array/ArrayItemViewProps.d.ts +11 -0
  36. package/lib/complex/array/ArrayListDetail.d.ts +9 -0
  37. package/lib/complex/array/ArrayTable.d.ts +21 -0
  38. package/lib/complex/index.d.ts +10 -0
  39. package/lib/complex/mixed/JsonTypeIcon.d.ts +5 -0
  40. package/lib/complex/mixed/MixedWidgets.d.ts +22 -0
  41. package/lib/complex/mixed/useConfirmation.d.ts +6 -0
  42. package/lib/components/ClearValueButton.d.ts +12 -0
  43. package/lib/components/ScrollRegion.d.ts +4 -0
  44. package/lib/components/TimePicker.d.ts +13 -0
  45. package/lib/components/index.d.ts +2 -0
  46. package/lib/controls/AnyOfStringOrEnumControl.d.ts +4 -0
  47. package/lib/controls/BooleanControl.d.ts +4 -0
  48. package/lib/controls/BooleanToggleControl.d.ts +4 -0
  49. package/lib/controls/ChoiceCards.d.ts +1 -0
  50. package/lib/controls/DateControl.d.ts +4 -0
  51. package/lib/controls/DateTimeControl.d.ts +4 -0
  52. package/lib/controls/EnumControl.d.ts +5 -0
  53. package/lib/controls/InputControl.d.ts +30 -0
  54. package/lib/controls/IntegerControl.d.ts +4 -0
  55. package/lib/controls/NumberControl.d.ts +4 -0
  56. package/lib/controls/OneOfEnumControl.d.ts +3 -0
  57. package/lib/controls/PasswordControl.d.ts +9 -0
  58. package/lib/controls/RadioGroupControl.d.ts +4 -0
  59. package/lib/controls/SliderControl.d.ts +4 -0
  60. package/lib/controls/TextControl.d.ts +4 -0
  61. package/lib/controls/TimeControl.d.ts +4 -0
  62. package/lib/controls/index.d.ts +15 -0
  63. package/lib/index.d.ts +6 -0
  64. package/lib/jsonforms-react-shadcn.cjs.js +3 -0
  65. package/lib/jsonforms-react-shadcn.cjs.js.map +1 -0
  66. package/lib/jsonforms-react-shadcn.esm.js +4040 -0
  67. package/lib/jsonforms-react-shadcn.esm.js.map +1 -0
  68. package/lib/layouts/CategorizationLayout.d.ts +7 -0
  69. package/lib/layouts/GroupLayout.d.ts +4 -0
  70. package/lib/layouts/HorizontalLayout.d.ts +4 -0
  71. package/lib/layouts/Layout.d.ts +5 -0
  72. package/lib/layouts/ValidationIndicator.d.ts +4 -0
  73. package/lib/layouts/VerticalLayout.d.ts +4 -0
  74. package/lib/layouts/index.d.ts +4 -0
  75. package/lib/renderers.d.ts +8 -0
  76. package/lib/util/dateTime.d.ts +12 -0
  77. package/lib/util/groupState.d.ts +1 -0
  78. package/lib/util/useTemporalControl.d.ts +28 -0
  79. package/package.json +86 -3
  80. package/src/additional/LabelRenderer.tsx +8 -0
  81. package/src/additional/index.ts +1 -0
  82. package/src/cells/BooleanCell.tsx +26 -0
  83. package/src/cells/Cell.tsx +101 -0
  84. package/src/cells/CompositeCell.tsx +275 -0
  85. package/src/cells/CompositeDetailDialog.tsx +79 -0
  86. package/src/cells/EnumCell.tsx +74 -0
  87. package/src/cells/NumberCell.tsx +51 -0
  88. package/src/cells/NumberFormatCell.tsx +47 -0
  89. package/src/cells/TextCell.tsx +40 -0
  90. package/src/cells/asCell.tsx +79 -0
  91. package/src/cells/index.ts +7 -0
  92. package/src/complex/AdditionalProperties.tsx +453 -0
  93. package/src/complex/AnyOfRenderer.tsx +341 -0
  94. package/src/complex/ArrayChoicesControl.tsx +303 -0
  95. package/src/complex/ArrayControlRenderer.tsx +400 -0
  96. package/src/complex/ArrayPanelToggle.tsx +33 -0
  97. package/src/complex/CollectionPager.tsx +76 -0
  98. package/src/complex/CombinatorSwitchDialog.tsx +43 -0
  99. package/src/complex/DeleteDialog.tsx +41 -0
  100. package/src/complex/DetailDialogContent.tsx +84 -0
  101. package/src/complex/ErrorIndicator.tsx +136 -0
  102. package/src/complex/MixedRenderer.tsx +262 -0
  103. package/src/complex/ObjectRenderer.tsx +43 -0
  104. package/src/complex/OneOfRenderer.tsx +14 -0
  105. package/src/complex/RecursiveTreeRenderer.tsx +20 -0
  106. package/src/complex/RowDetailFrame.tsx +158 -0
  107. package/src/complex/ScalarCompositionRenderer.tsx +14 -0
  108. package/src/complex/TupleAdditionalItems.tsx +94 -0
  109. package/src/complex/TupleControlRenderer.tsx +54 -0
  110. package/src/complex/TupleField.tsx +41 -0
  111. package/src/complex/array/ArrayItemPanels.tsx +217 -0
  112. package/src/complex/array/ArrayItemViewProps.ts +15 -0
  113. package/src/complex/array/ArrayListDetail.tsx +165 -0
  114. package/src/complex/array/ArrayTable.tsx +535 -0
  115. package/src/complex/index.ts +16 -0
  116. package/src/complex/mixed/JsonTypeIcon.tsx +41 -0
  117. package/src/complex/mixed/MixedWidgets.tsx +326 -0
  118. package/src/complex/mixed/useConfirmation.tsx +34 -0
  119. package/src/components/ClearValueButton.tsx +56 -0
  120. package/src/components/ScrollRegion.tsx +27 -0
  121. package/src/components/TimePicker.tsx +250 -0
  122. package/src/components/index.ts +2 -0
  123. package/src/controls/AnyOfStringOrEnumControl.tsx +44 -0
  124. package/src/controls/BooleanControl.tsx +67 -0
  125. package/src/controls/BooleanToggleControl.tsx +58 -0
  126. package/src/controls/ChoiceCards.tsx +9 -0
  127. package/src/controls/DateControl.tsx +240 -0
  128. package/src/controls/DateTimeControl.tsx +187 -0
  129. package/src/controls/EnumControl.tsx +159 -0
  130. package/src/controls/InputControl.tsx +258 -0
  131. package/src/controls/IntegerControl.tsx +14 -0
  132. package/src/controls/NumberControl.tsx +14 -0
  133. package/src/controls/OneOfEnumControl.tsx +13 -0
  134. package/src/controls/PasswordControl.tsx +216 -0
  135. package/src/controls/RadioGroupControl.tsx +72 -0
  136. package/src/controls/SliderControl.tsx +77 -0
  137. package/src/controls/TextControl.tsx +50 -0
  138. package/src/controls/TimeControl.tsx +135 -0
  139. package/src/controls/index.ts +19 -0
  140. package/src/index.tsx +10 -0
  141. package/src/layouts/CategorizationLayout.tsx +248 -0
  142. package/src/layouts/GroupLayout.tsx +210 -0
  143. package/src/layouts/HorizontalLayout.tsx +12 -0
  144. package/src/layouts/Layout.tsx +62 -0
  145. package/src/layouts/ValidationIndicator.tsx +40 -0
  146. package/src/layouts/VerticalLayout.tsx +12 -0
  147. package/src/layouts/index.ts +4 -0
  148. package/src/renderers.ts +225 -0
  149. package/src/styles.css +482 -0
  150. package/src/tailwind-theme.cjs +42 -0
  151. package/src/theme.css +43 -0
  152. package/src/util/dateTime.ts +80 -0
  153. package/src/util/groupState.ts +5 -0
  154. 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
+ }