@chobantonov/jsonforms-react-antd-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 (312) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +103 -2
  3. package/lib/additional/LabelRenderer.d.ts +13 -0
  4. package/lib/additional/ListWithDetailMasterItem.d.ts +9 -0
  5. package/lib/additional/ListWithDetailRenderer.d.ts +8 -0
  6. package/lib/additional/index.d.ts +4 -0
  7. package/lib/additional/unwrapped.d.ts +6 -0
  8. package/lib/antd-controls/AntdCheckbox.d.ts +10 -0
  9. package/lib/antd-controls/AntdClearValueButton.d.ts +44 -0
  10. package/lib/antd-controls/AntdClearableInput.d.ts +19 -0
  11. package/lib/antd-controls/AntdDatePicker.d.ts +7 -0
  12. package/lib/antd-controls/AntdDateTimePicker.d.ts +7 -0
  13. package/lib/antd-controls/AntdFile.d.ts +7 -0
  14. package/lib/antd-controls/AntdInputInteger.d.ts +3 -0
  15. package/lib/antd-controls/AntdInputNumber.d.ts +3 -0
  16. package/lib/antd-controls/AntdInputNumberFormat.d.ts +6 -0
  17. package/lib/antd-controls/AntdInputText.d.ts +6 -0
  18. package/lib/antd-controls/AntdNumericInput.d.ts +9 -0
  19. package/lib/antd-controls/AntdOtp.d.ts +33 -0
  20. package/lib/antd-controls/AntdPassword.d.ts +6 -0
  21. package/lib/antd-controls/AntdRadioGroup.d.ts +6 -0
  22. package/lib/antd-controls/AntdRevealButton.d.ts +32 -0
  23. package/lib/antd-controls/AntdSelect.d.ts +7 -0
  24. package/lib/antd-controls/AntdSlider.d.ts +21 -0
  25. package/lib/antd-controls/AntdTimePicker.d.ts +6 -0
  26. package/lib/antd-controls/AntdToggle.d.ts +6 -0
  27. package/lib/antd-controls/FileFeedback.d.ts +6 -0
  28. package/lib/antd-controls/index.d.ts +18 -0
  29. package/lib/antd-controls/useTemporalPicker.d.ts +49 -0
  30. package/lib/cells/AntdCompositeCell.d.ts +8 -0
  31. package/lib/cells/BooleanCell.d.ts +6 -0
  32. package/lib/cells/BooleanToggleCell.d.ts +5 -0
  33. package/lib/cells/CompositeDetailDialog.d.ts +15 -0
  34. package/lib/cells/CustomizableCells.d.ts +9 -0
  35. package/lib/cells/DateCell.d.ts +6 -0
  36. package/lib/cells/EnumCell.d.ts +11 -0
  37. package/lib/cells/IntegerCell.d.ts +6 -0
  38. package/lib/cells/NumberCell.d.ts +10 -0
  39. package/lib/cells/NumberFormatCell.d.ts +10 -0
  40. package/lib/cells/OneOfEnumCell.d.ts +11 -0
  41. package/lib/cells/PasswordCell.d.ts +5 -0
  42. package/lib/cells/TextCell.d.ts +10 -0
  43. package/lib/cells/TimeCell.d.ts +6 -0
  44. package/lib/cells/index.d.ts +14 -0
  45. package/lib/complex/AdditionalProperties.d.ts +4 -0
  46. package/lib/complex/AnyOfRenderer.d.ts +31 -0
  47. package/lib/complex/ArrayControlRenderer.d.ts +8 -0
  48. package/lib/complex/ChipsControl.d.ts +22 -0
  49. package/lib/complex/CollectionPager.d.ts +5 -0
  50. package/lib/complex/DataCell.d.ts +16 -0
  51. package/lib/complex/DeleteDialog.d.ts +14 -0
  52. package/lib/complex/DetailModal.d.ts +6 -0
  53. package/lib/complex/EnumArrayRenderer.d.ts +6 -0
  54. package/lib/complex/ErrorFeedback.d.ts +6 -0
  55. package/lib/complex/MixedRenderer.d.ts +6 -0
  56. package/lib/complex/MultiSelectControl.d.ts +17 -0
  57. package/lib/complex/ObjectRenderer.d.ts +5 -0
  58. package/lib/complex/OneOfRenderer.d.ts +6 -0
  59. package/lib/complex/OneOfTabRenderer.d.ts +5 -0
  60. package/lib/complex/RecursiveTreeRenderer.d.ts +4 -0
  61. package/lib/complex/RowDetailFrame.d.ts +10 -0
  62. package/lib/complex/ScalarCompositionRenderer.d.ts +4 -0
  63. package/lib/complex/TabSwitchConfirmDialog.d.ts +9 -0
  64. package/lib/complex/TableControl.d.ts +9 -0
  65. package/lib/complex/TableToolbar.d.ts +21 -0
  66. package/lib/complex/TupleAdditionalItems.d.ts +13 -0
  67. package/lib/complex/TupleControlRenderer.d.ts +6 -0
  68. package/lib/complex/TupleField.d.ts +4 -0
  69. package/lib/complex/ValidationIcon.d.ts +8 -0
  70. package/lib/complex/additionalProperties/AntdAdditionalPropertyActions.d.ts +9 -0
  71. package/lib/complex/additionalProperties/AntdAdditionalPropertyRenameDialog.d.ts +11 -0
  72. package/lib/complex/index.d.ts +20 -0
  73. package/lib/complex/mixed/AntdJsonTypeIcon.d.ts +4 -0
  74. package/lib/complex/mixed/AntdMixedNavigationContext.d.ts +5 -0
  75. package/lib/complex/mixed/AntdMixedSplitPane.d.ts +5 -0
  76. package/lib/complex/mixed/AntdMixedTree.d.ts +15 -0
  77. package/lib/complex/mixed/AntdMixedTypeSelector.d.ts +12 -0
  78. package/lib/complex/mixed/AntdNestedMixedNavigation.d.ts +7 -0
  79. package/lib/complex/mixed/mixedTree.d.ts +2 -0
  80. package/lib/complex/unwrapped.d.ts +10 -0
  81. package/lib/controls/AnyOfStringOrEnumControl.d.ts +9 -0
  82. package/lib/controls/BooleanControl.d.ts +6 -0
  83. package/lib/controls/BooleanToggleControl.d.ts +6 -0
  84. package/lib/controls/ChoiceCards.d.ts +1 -0
  85. package/lib/controls/DateControl.d.ts +6 -0
  86. package/lib/controls/DateTimeControl.d.ts +6 -0
  87. package/lib/controls/EnumControl.d.ts +7 -0
  88. package/lib/controls/FileControl.d.ts +7 -0
  89. package/lib/controls/InputControl.d.ts +6 -0
  90. package/lib/controls/IntegerControl.d.ts +6 -0
  91. package/lib/controls/NativeControl.d.ts +6 -0
  92. package/lib/controls/NumberControl.d.ts +6 -0
  93. package/lib/controls/OneOfEnumControl.d.ts +7 -0
  94. package/lib/controls/OneOfRadioGroupControl.d.ts +6 -0
  95. package/lib/controls/PasswordControl.d.ts +18 -0
  96. package/lib/controls/PasswordOtpControl.d.ts +38 -0
  97. package/lib/controls/RadioGroup.d.ts +3 -0
  98. package/lib/controls/RadioGroupControl.d.ts +6 -0
  99. package/lib/controls/SliderControl.d.ts +6 -0
  100. package/lib/controls/TextControl.d.ts +6 -0
  101. package/lib/controls/TimeControl.d.ts +6 -0
  102. package/lib/controls/index.d.ts +20 -0
  103. package/lib/controls/unwrapped.d.ts +19 -0
  104. package/lib/index.d.ts +50 -0
  105. package/lib/jsonforms-react-antd.cjs.js +39 -0
  106. package/lib/jsonforms-react-antd.cjs.js.map +1 -0
  107. package/lib/jsonforms-react-antd.esm.js +4235 -0
  108. package/lib/jsonforms-react-antd.esm.js.map +1 -0
  109. package/lib/layouts/ArrayLayout.d.ts +5 -0
  110. package/lib/layouts/ArrayLayoutRenderer.d.ts +8 -0
  111. package/lib/layouts/ArrayPanel.d.ts +7 -0
  112. package/lib/layouts/ArrayToolbar.d.ts +17 -0
  113. package/lib/layouts/CategorizationAccordionLayout.d.ts +21 -0
  114. package/lib/layouts/CategorizationLayout.d.ts +14 -0
  115. package/lib/layouts/CategorizationStepperLayout.d.ts +10 -0
  116. package/lib/layouts/CategoryHeader.d.ts +39 -0
  117. package/lib/layouts/ContainerIndicator.d.ts +37 -0
  118. package/lib/layouts/GroupLayout.d.ts +6 -0
  119. package/lib/layouts/HorizontalLayout.d.ts +10 -0
  120. package/lib/layouts/ValidationIndicator.d.ts +13 -0
  121. package/lib/layouts/VerticalLayout.d.ts +10 -0
  122. package/lib/layouts/arrayTitle.d.ts +2 -0
  123. package/lib/layouts/index.d.ts +11 -0
  124. package/lib/layouts/unwrapped.d.ts +11 -0
  125. package/lib/locale/index.d.ts +1 -0
  126. package/lib/util/additionalPropertyName.d.ts +2 -0
  127. package/lib/util/arrayChoices.d.ts +2 -0
  128. package/lib/util/categoryState.d.ts +3 -0
  129. package/lib/util/cellFrame.d.ts +27 -0
  130. package/lib/util/cellMode.d.ts +29 -0
  131. package/lib/util/clearAffordance.d.ts +1 -0
  132. package/lib/util/combinators.d.ts +1 -0
  133. package/lib/util/compositeActions.d.ts +1 -0
  134. package/lib/util/compositeSummary.d.ts +1 -0
  135. package/lib/util/configNamespaces.d.ts +1 -0
  136. package/lib/util/confirmation.d.ts +2 -0
  137. package/lib/util/datejs.d.ts +4 -0
  138. package/lib/util/debounce.d.ts +1 -0
  139. package/lib/util/dynamicProperties.d.ts +1 -0
  140. package/lib/util/focus.d.ts +1 -0
  141. package/lib/util/groupState.d.ts +1 -0
  142. package/lib/util/index.d.ts +25 -0
  143. package/lib/util/layout.d.ts +18 -0
  144. package/lib/util/layoutSizing.d.ts +6 -0
  145. package/lib/util/literalPropertySchema.d.ts +1 -0
  146. package/lib/util/locale.d.ts +68 -0
  147. package/lib/util/numeric.d.ts +1 -0
  148. package/lib/util/pendingChanges.d.ts +2 -0
  149. package/lib/util/preTouchErrors.d.ts +2 -0
  150. package/lib/util/rendererLocale.d.ts +2 -0
  151. package/lib/util/temporalBounds.d.ts +35 -0
  152. package/lib/util/temporalFormats.d.ts +26 -0
  153. package/lib/util/theme.d.ts +9 -0
  154. package/lib/util/translate.d.ts +1 -0
  155. package/lib/util/tuple.d.ts +2 -0
  156. package/lib/util/useConfirmation.d.ts +7 -0
  157. package/lib/util/validationIndicator.d.ts +2 -0
  158. package/lib/util/visuallyHidden.d.ts +1 -0
  159. package/package.json +89 -3
  160. package/src/additional/LabelRenderer.tsx +21 -0
  161. package/src/additional/ListWithDetailMasterItem.tsx +124 -0
  162. package/src/additional/ListWithDetailRenderer.tsx +243 -0
  163. package/src/additional/index.ts +14 -0
  164. package/src/additional/unwrapped.ts +8 -0
  165. package/src/antd-controls/AntdCheckbox.tsx +56 -0
  166. package/src/antd-controls/AntdClearValueButton.tsx +96 -0
  167. package/src/antd-controls/AntdClearableInput.tsx +63 -0
  168. package/src/antd-controls/AntdDatePicker.tsx +26 -0
  169. package/src/antd-controls/AntdDateTimePicker.tsx +31 -0
  170. package/src/antd-controls/AntdFile.tsx +395 -0
  171. package/src/antd-controls/AntdInputInteger.tsx +10 -0
  172. package/src/antd-controls/AntdInputNumber.tsx +10 -0
  173. package/src/antd-controls/AntdInputNumberFormat.tsx +63 -0
  174. package/src/antd-controls/AntdInputText.tsx +124 -0
  175. package/src/antd-controls/AntdNumericInput.tsx +83 -0
  176. package/src/antd-controls/AntdOtp.tsx +132 -0
  177. package/src/antd-controls/AntdPassword.tsx +106 -0
  178. package/src/antd-controls/AntdRadioGroup.tsx +60 -0
  179. package/src/antd-controls/AntdRevealButton.tsx +74 -0
  180. package/src/antd-controls/AntdSelect.tsx +113 -0
  181. package/src/antd-controls/AntdSlider.tsx +114 -0
  182. package/src/antd-controls/AntdTimePicker.tsx +25 -0
  183. package/src/antd-controls/AntdToggle.tsx +70 -0
  184. package/src/antd-controls/FileFeedback.tsx +37 -0
  185. package/src/antd-controls/index.ts +18 -0
  186. package/src/antd-controls/useTemporalPicker.ts +130 -0
  187. package/src/cells/AntdCompositeCell.tsx +228 -0
  188. package/src/cells/BooleanCell.tsx +33 -0
  189. package/src/cells/BooleanToggleCell.tsx +38 -0
  190. package/src/cells/CompositeDetailDialog.tsx +100 -0
  191. package/src/cells/CustomizableCells.ts +9 -0
  192. package/src/cells/DateCell.tsx +17 -0
  193. package/src/cells/EnumCell.tsx +30 -0
  194. package/src/cells/IntegerCell.tsx +17 -0
  195. package/src/cells/NumberCell.tsx +20 -0
  196. package/src/cells/NumberFormatCell.tsx +37 -0
  197. package/src/cells/OneOfEnumCell.tsx +32 -0
  198. package/src/cells/PasswordCell.tsx +22 -0
  199. package/src/cells/TextCell.tsx +22 -0
  200. package/src/cells/TimeCell.tsx +17 -0
  201. package/src/cells/index.ts +40 -0
  202. package/src/complex/AdditionalProperties.tsx +422 -0
  203. package/src/complex/AnyOfRenderer.tsx +158 -0
  204. package/src/complex/ArrayControlRenderer.tsx +121 -0
  205. package/src/complex/ChipsControl.tsx +205 -0
  206. package/src/complex/CollectionPager.tsx +26 -0
  207. package/src/complex/DataCell.tsx +82 -0
  208. package/src/complex/DeleteDialog.tsx +44 -0
  209. package/src/complex/DetailModal.tsx +110 -0
  210. package/src/complex/EnumArrayRenderer.tsx +148 -0
  211. package/src/complex/ErrorFeedback.tsx +51 -0
  212. package/src/complex/MixedRenderer.tsx +325 -0
  213. package/src/complex/MultiSelectControl.tsx +205 -0
  214. package/src/complex/ObjectRenderer.tsx +55 -0
  215. package/src/complex/OneOfRenderer.tsx +299 -0
  216. package/src/complex/OneOfTabRenderer.tsx +123 -0
  217. package/src/complex/RecursiveTreeRenderer.tsx +20 -0
  218. package/src/complex/RowDetailFrame.tsx +99 -0
  219. package/src/complex/ScalarCompositionRenderer.tsx +14 -0
  220. package/src/complex/TabSwitchConfirmDialog.tsx +36 -0
  221. package/src/complex/TableControl.tsx +646 -0
  222. package/src/complex/TableToolbar.tsx +80 -0
  223. package/src/complex/TupleAdditionalItems.tsx +100 -0
  224. package/src/complex/TupleControlRenderer.tsx +78 -0
  225. package/src/complex/TupleField.tsx +44 -0
  226. package/src/complex/ValidationIcon.tsx +30 -0
  227. package/src/complex/additionalProperties/AntdAdditionalPropertyActions.tsx +56 -0
  228. package/src/complex/additionalProperties/AntdAdditionalPropertyRenameDialog.tsx +56 -0
  229. package/src/complex/index.ts +48 -0
  230. package/src/complex/mixed/AntdJsonTypeIcon.tsx +40 -0
  231. package/src/complex/mixed/AntdMixedNavigationContext.ts +8 -0
  232. package/src/complex/mixed/AntdMixedSplitPane.tsx +51 -0
  233. package/src/complex/mixed/AntdMixedTree.tsx +287 -0
  234. package/src/complex/mixed/AntdMixedTypeSelector.tsx +60 -0
  235. package/src/complex/mixed/AntdNestedMixedNavigation.tsx +39 -0
  236. package/src/complex/mixed/mixedTree.ts +9 -0
  237. package/src/complex/unwrapped.ts +15 -0
  238. package/src/controls/AnyOfStringOrEnumControl.tsx +123 -0
  239. package/src/controls/BooleanControl.tsx +17 -0
  240. package/src/controls/BooleanToggleControl.tsx +24 -0
  241. package/src/controls/ChoiceCards.tsx +13 -0
  242. package/src/controls/DateControl.tsx +19 -0
  243. package/src/controls/DateTimeControl.tsx +22 -0
  244. package/src/controls/EnumControl.tsx +29 -0
  245. package/src/controls/FileControl.tsx +44 -0
  246. package/src/controls/InputControl.tsx +94 -0
  247. package/src/controls/IntegerControl.tsx +16 -0
  248. package/src/controls/NativeControl.tsx +79 -0
  249. package/src/controls/NumberControl.tsx +18 -0
  250. package/src/controls/OneOfEnumControl.tsx +32 -0
  251. package/src/controls/OneOfRadioGroupControl.tsx +25 -0
  252. package/src/controls/PasswordControl.tsx +43 -0
  253. package/src/controls/PasswordOtpControl.tsx +61 -0
  254. package/src/controls/RadioGroup.tsx +8 -0
  255. package/src/controls/RadioGroupControl.tsx +21 -0
  256. package/src/controls/SliderControl.tsx +19 -0
  257. package/src/controls/TextControl.tsx +17 -0
  258. package/src/controls/TimeControl.tsx +20 -0
  259. package/src/controls/index.ts +69 -0
  260. package/src/controls/unwrapped.ts +35 -0
  261. package/src/index.ts +267 -0
  262. package/src/layouts/ArrayLayout.tsx +435 -0
  263. package/src/layouts/ArrayLayoutRenderer.tsx +54 -0
  264. package/src/layouts/ArrayPanel.tsx +51 -0
  265. package/src/layouts/ArrayToolbar.tsx +67 -0
  266. package/src/layouts/CategorizationAccordionLayout.tsx +217 -0
  267. package/src/layouts/CategorizationLayout.tsx +149 -0
  268. package/src/layouts/CategorizationStepperLayout.tsx +164 -0
  269. package/src/layouts/CategoryHeader.tsx +107 -0
  270. package/src/layouts/ContainerIndicator.tsx +83 -0
  271. package/src/layouts/GroupLayout.tsx +307 -0
  272. package/src/layouts/HorizontalLayout.tsx +50 -0
  273. package/src/layouts/ValidationIndicator.tsx +43 -0
  274. package/src/layouts/VerticalLayout.tsx +50 -0
  275. package/src/layouts/arrayTitle.tsx +30 -0
  276. package/src/layouts/index.ts +35 -0
  277. package/src/layouts/unwrapped.ts +17 -0
  278. package/src/locale/index.ts +1 -0
  279. package/src/util/additionalPropertyName.ts +11 -0
  280. package/src/util/arrayChoices.ts +21 -0
  281. package/src/util/categoryState.ts +17 -0
  282. package/src/util/cellFrame.tsx +52 -0
  283. package/src/util/cellMode.tsx +145 -0
  284. package/src/util/clearAffordance.ts +2 -0
  285. package/src/util/combinators.ts +6 -0
  286. package/src/util/compositeActions.ts +2 -0
  287. package/src/util/compositeSummary.ts +2 -0
  288. package/src/util/configNamespaces.ts +4 -0
  289. package/src/util/confirmation.ts +15 -0
  290. package/src/util/datejs.tsx +42 -0
  291. package/src/util/debounce.ts +2 -0
  292. package/src/util/dynamicProperties.ts +6 -0
  293. package/src/util/focus.ts +2 -0
  294. package/src/util/groupState.ts +8 -0
  295. package/src/util/index.ts +25 -0
  296. package/src/util/layout.tsx +121 -0
  297. package/src/util/layoutSizing.ts +33 -0
  298. package/src/util/literalPropertySchema.ts +2 -0
  299. package/src/util/locale.ts +222 -0
  300. package/src/util/numeric.ts +2 -0
  301. package/src/util/pendingChanges.tsx +6 -0
  302. package/src/util/preTouchErrors.ts +10 -0
  303. package/src/util/rendererLocale.ts +10 -0
  304. package/src/util/temporalBounds.ts +106 -0
  305. package/src/util/temporalFormats.ts +95 -0
  306. package/src/util/theme.ts +9 -0
  307. package/src/util/translate.ts +6 -0
  308. package/src/util/tuple.ts +16 -0
  309. package/src/util/uiSchemaCycle.tsx +2 -0
  310. package/src/util/useConfirmation.tsx +25 -0
  311. package/src/util/validationIndicator.ts +10 -0
  312. package/src/util/visuallyHidden.ts +2 -0
@@ -0,0 +1,299 @@
1
+ import { useCombinatorSelection } from '@chobantonov/jsonforms-react-renderer-common/composition/useCombinatorSelection';
2
+ import { discriminatorBranch } from '@chobantonov/jsonforms-react-renderer-common/composition/discriminatorBranch';
3
+ import {
4
+ useJsonForms,
5
+ JsonFormsDispatch,
6
+ withJsonFormsOneOfProps,
7
+ } from '@jsonforms/react';
8
+ import { isArrayElementPath } from '@chobantonov/jsonforms-react-renderer-common/mixed/mixedSchema';
9
+ import {
10
+ isUnselectedBranchValue,
11
+ clearedBranchValue,
12
+ } from '@chobantonov/jsonforms-react-renderer-common/composition/combinators';
13
+ import { CombinatorBranch } from '@chobantonov/jsonforms-react-renderer-common/composition/CombinatorBranch';
14
+ import React, { useCallback, useState } from 'react';
15
+ import isEmpty from 'lodash/isEmpty';
16
+ import { shouldConfirm } from '../util/confirmation';
17
+
18
+ import { TabSwitchConfirmDialog } from './TabSwitchConfirmDialog';
19
+
20
+ import {
21
+ CombinatorRendererProps,
22
+ createDefaultValue,
23
+ isDescriptionHidden,
24
+ isOneOfControl,
25
+ RankedTester,
26
+ rankWith,
27
+ } from '@jsonforms/core';
28
+ import { Select, Form } from 'antd';
29
+ import { CombinatorProperties } from '@chobantonov/jsonforms-react-renderer-common/composition/CombinatorProperties';
30
+ import merge from 'lodash/merge';
31
+ import { useFocus } from '../util';
32
+ import { branchChangeData, discardedByBranchChange } from '../util/combinators';
33
+
34
+ export const OneOfRenderer = ({
35
+ handleChange,
36
+ schema,
37
+ path,
38
+ renderers,
39
+ cells,
40
+ rootSchema,
41
+ id,
42
+ visible,
43
+ indexOfFittingSchema,
44
+ uischema,
45
+ uischemas,
46
+ data,
47
+ enabled,
48
+ config,
49
+ required,
50
+ errors,
51
+ label,
52
+ description,
53
+ }: CombinatorRendererProps) => {
54
+ const formContext = useJsonForms();
55
+ indexOfFittingSchema =
56
+ discriminatorBranch(schema, rootSchema, 'oneOf', data) ??
57
+ indexOfFittingSchema;
58
+ const [confirmDialogOpen, setConfirmDialogOpen] = useState(false);
59
+ const [selectedIndex, setSelectedIndex] = useState(
60
+ indexOfFittingSchema !== null && indexOfFittingSchema !== undefined
61
+ ? indexOfFittingSchema
62
+ : !isEmpty(data)
63
+ ? 0 // uses the first schema and report errors if not empty
64
+ : null,
65
+ );
66
+ const [newSelectedIndex, setNewSelectedIndex] = useState<number | null>(0);
67
+
68
+ /*
69
+ The displayed branch follows the data until the user picks one.
70
+
71
+ Section 18 asks the form to show the branch that fits the existing value -
72
+ "if the value matches a later oneOf branch, display that branch" - and the
73
+ selection was derived once, at mount, and never again. A discriminated
74
+ oneOf therefore went stale the moment its discriminator changed: choosing
75
+ "Post" left the collection-point field on screen, which is the whole
76
+ mechanism by which a schema, with no UI rule, decides which fields exist.
77
+
78
+ Once the user selects a branch themselves the choice is theirs, and the
79
+ write that selection makes puts the data on the branch anyway. A value
80
+ that fits *nothing* leaves the display where it is: section 18 keeps a
81
+ fallback branch on screen "alongside validation errors, while retaining
82
+ the incoming data for correction", and blanking the form mid-edit would
83
+ hide the very field the correction needs.
84
+ */
85
+ const [chosen, setChosen] = useState(false);
86
+ const [previousInput, setPreviousInput] = useState({
87
+ initialized: false,
88
+ data,
89
+ indexOfFittingSchema,
90
+ });
91
+ if (
92
+ !previousInput.initialized ||
93
+ previousInput.data !== data ||
94
+ previousInput.indexOfFittingSchema !== indexOfFittingSchema
95
+ ) {
96
+ setPreviousInput({ initialized: true, data, indexOfFittingSchema });
97
+ if (isUnselectedBranchValue(data, indexOfFittingSchema)) {
98
+ setChosen(false);
99
+ setSelectedIndex(null);
100
+ setConfirmDialogOpen(false);
101
+ } else if (
102
+ !chosen &&
103
+ indexOfFittingSchema != null &&
104
+ indexOfFittingSchema >= 0
105
+ ) {
106
+ setSelectedIndex(indexOfFittingSchema);
107
+ }
108
+ }
109
+ const handleClose = useCallback(
110
+ () => setConfirmDialogOpen(false),
111
+ [setConfirmDialogOpen],
112
+ );
113
+ const cancel = useCallback(() => {
114
+ setConfirmDialogOpen(false);
115
+ }, [setConfirmDialogOpen]);
116
+ const { selectionError, renderInfos: oneOfRenderInfos } =
117
+ useCombinatorSelection(
118
+ { schema, rootSchema, uischema, path, uischemas },
119
+ 'oneOf',
120
+ formContext.core,
121
+ );
122
+
123
+ /*
124
+ A branch change initializes from the new branch's generated defaults and
125
+ carries the enclosing schema's own properties across. It used to write the
126
+ generated defaults alone, which silently dropped every enclosing value -
127
+ `name` in the specification's worked example - on every switch, and on a
128
+ clear.
129
+ */
130
+ const openNewTab = (newIndex: number | null) => {
131
+ const defaults =
132
+ newIndex !== null
133
+ ? createDefaultValue(oneOfRenderInfos[newIndex].schema, rootSchema)
134
+ : clearedBranchValue(
135
+ isArrayElementPath(formContext.core?.data, path),
136
+ oneOfRenderInfos.map((info) => info.schema),
137
+ );
138
+ handleChange(path, branchChangeData(data, defaults, schema));
139
+ setSelectedIndex(newIndex);
140
+ };
141
+
142
+ const confirm = () => {
143
+ openNewTab(newSelectedIndex);
144
+ setConfirmDialogOpen(false);
145
+ };
146
+
147
+ const handleTabChange = (value: string | null) => {
148
+ const newOneOfIndex =
149
+ value === null || value === undefined ? null : parseInt(value, 10);
150
+
151
+ // Re-selecting the branch already in use is not a change.
152
+ if (newOneOfIndex === selectedIndex) {
153
+ return;
154
+ }
155
+ setChosen(true);
156
+
157
+ setNewSelectedIndex(newOneOfIndex);
158
+ /*
159
+ Was `!isEmpty(data)`, which is close to `always` but not the policy:
160
+ it could not be configured, and lodash's `isEmpty` calls `0` and `false`
161
+ empty - values section 14 explicitly counts as existing. Clearing the
162
+ selection (`null`) is a branchChange too, and used to skip the prompt
163
+ entirely.
164
+ */
165
+ if (
166
+ shouldConfirm(
167
+ {
168
+ options: uischema.options as Record<string, unknown> | undefined,
169
+ config,
170
+ catalogId: 'oneOf',
171
+ operation: 'branchChange',
172
+ },
173
+ // Only what the switch actually discards: the enclosing properties
174
+ // survive it, so they are not values being thrown away.
175
+ [discardedByBranchChange(data, schema)],
176
+ )
177
+ ) {
178
+ setConfirmDialogOpen(true);
179
+ return;
180
+ }
181
+ openNewTab(newOneOfIndex);
182
+ };
183
+
184
+ const [focused, onFocus, onBlur] = useFocus();
185
+
186
+ const appliedUiSchemaOptions = merge({}, config, uischema.options);
187
+ const isValid = errors.length === 0 && !selectionError;
188
+ const showDescription = !isDescriptionHidden(
189
+ visible,
190
+ description,
191
+ focused,
192
+ appliedUiSchemaOptions.showUnfocusedDescription,
193
+ );
194
+
195
+ const help = !isValid
196
+ ? selectionError || errors
197
+ : showDescription
198
+ ? description
199
+ : null;
200
+ const style = { width: '100%' };
201
+
202
+ if (!visible) {
203
+ return null;
204
+ }
205
+
206
+ if (oneOfRenderInfos.length === 1) {
207
+ const branch = oneOfRenderInfos[0];
208
+ return (
209
+ <>
210
+ <CombinatorProperties
211
+ schema={schema}
212
+ combinatorKeyword={'oneOf'}
213
+ path={path}
214
+ rootSchema={rootSchema}
215
+ />
216
+ <CombinatorBranch
217
+ options={uischema.options}
218
+ schema={branch.schema}
219
+ path={path}
220
+ >
221
+ <JsonFormsDispatch
222
+ schema={branch.schema}
223
+ uischema={branch.uischema}
224
+ path={path}
225
+ renderers={renderers}
226
+ cells={cells}
227
+ enabled={enabled}
228
+ />
229
+ </CombinatorBranch>
230
+ </>
231
+ );
232
+ }
233
+
234
+ return (
235
+ <>
236
+ <CombinatorProperties
237
+ schema={schema}
238
+ combinatorKeyword={'oneOf'}
239
+ path={path}
240
+ rootSchema={rootSchema}
241
+ />
242
+ <Form.Item
243
+ required={required && !appliedUiSchemaOptions.hideRequiredAsterisk}
244
+ hasFeedback={!isValid}
245
+ validateStatus={isValid ? 'success' : 'error'}
246
+ label={label}
247
+ help={help}
248
+ style={style}
249
+ htmlFor={id + '-input'}
250
+ id={id}
251
+ >
252
+ <Select
253
+ id={id + '-input'}
254
+ aria-invalid={!isValid}
255
+ disabled={!enabled}
256
+ autoFocus={appliedUiSchemaOptions.focus}
257
+ placeholder={appliedUiSchemaOptions.placeholder}
258
+ onFocus={onFocus}
259
+ onBlur={onBlur}
260
+ value={selectedIndex?.toString()}
261
+ onChange={handleTabChange}
262
+ allowClear={enabled}
263
+ options={oneOfRenderInfos.map((info, idx) => ({
264
+ value: String(idx),
265
+ label: info.label,
266
+ }))}
267
+ />
268
+ </Form.Item>
269
+
270
+ {selectedIndex !== undefined && selectedIndex !== null && (
271
+ <CombinatorBranch
272
+ options={uischema.options}
273
+ schema={oneOfRenderInfos[selectedIndex].schema}
274
+ path={path}
275
+ >
276
+ <JsonFormsDispatch
277
+ uischema={oneOfRenderInfos[selectedIndex].uischema}
278
+ schema={oneOfRenderInfos[selectedIndex].schema}
279
+ path={path}
280
+ renderers={renderers}
281
+ cells={cells}
282
+ />
283
+ </CombinatorBranch>
284
+ )}
285
+
286
+ <TabSwitchConfirmDialog
287
+ cancel={cancel}
288
+ confirm={confirm}
289
+ id={'oneOf-' + id}
290
+ open={confirmDialogOpen}
291
+ handleClose={handleClose}
292
+ />
293
+ </>
294
+ );
295
+ };
296
+
297
+ export const oneOfControlTester: RankedTester = rankWith(3, isOneOfControl);
298
+
299
+ export default withJsonFormsOneOfProps(OneOfRenderer);
@@ -0,0 +1,123 @@
1
+ import React, { useCallback, useState } from 'react';
2
+ import isEmpty from 'lodash/isEmpty';
3
+
4
+ import { TabSwitchConfirmDialog } from './TabSwitchConfirmDialog';
5
+
6
+ import {
7
+ and,
8
+ CombinatorRendererProps,
9
+ createCombinatorRenderInfos,
10
+ createDefaultValue,
11
+ isOneOfControl,
12
+ JsonSchema,
13
+ optionIs,
14
+ RankedTester,
15
+ rankWith,
16
+ } from '@jsonforms/core';
17
+ import { Tabs } from 'antd';
18
+ import { JsonFormsDispatch, withJsonFormsOneOfProps } from '@jsonforms/react';
19
+ import { CombinatorProperties } from '@chobantonov/jsonforms-react-renderer-common/composition/CombinatorProperties';
20
+
21
+ const OneOfTabRenderer = ({
22
+ handleChange,
23
+ schema,
24
+ path,
25
+ renderers,
26
+ cells,
27
+ rootSchema,
28
+ id,
29
+ visible,
30
+ indexOfFittingSchema = 0,
31
+ uischema,
32
+ uischemas,
33
+ data,
34
+ }: CombinatorRendererProps) => {
35
+ const [confirmDialogOpen, setConfirmDialogOpen] = useState(false);
36
+ const [selectedIndex, setSelectedIndex] = useState(indexOfFittingSchema);
37
+ const [newSelectedIndex, setNewSelectedIndex] = useState(0);
38
+ const handleClose = useCallback(
39
+ () => setConfirmDialogOpen(false),
40
+ [setConfirmDialogOpen],
41
+ );
42
+ const oneOfRenderInfos = createCombinatorRenderInfos(
43
+ (schema as JsonSchema).oneOf ?? [],
44
+ rootSchema,
45
+ 'oneOf',
46
+ uischema,
47
+ path,
48
+ uischemas,
49
+ );
50
+
51
+ const openNewTab = (newIndex: number) => {
52
+ handleChange(
53
+ path,
54
+ createDefaultValue(oneOfRenderInfos[newIndex].schema, rootSchema),
55
+ );
56
+ setSelectedIndex(newIndex);
57
+ };
58
+
59
+ const confirm = () => {
60
+ openNewTab(newSelectedIndex);
61
+ setConfirmDialogOpen(false);
62
+ };
63
+
64
+ const handleTabChange = (value: string) => {
65
+ const newOneOfIndex = parseInt(value, 10);
66
+
67
+ setNewSelectedIndex(newOneOfIndex);
68
+ if (isEmpty(data)) {
69
+ openNewTab(newOneOfIndex);
70
+ } else {
71
+ setConfirmDialogOpen(true);
72
+ }
73
+ };
74
+
75
+ if (!visible) {
76
+ return null;
77
+ }
78
+
79
+ return (
80
+ <>
81
+ <CombinatorProperties
82
+ schema={schema}
83
+ combinatorKeyword={'oneOf'}
84
+ path={path}
85
+ rootSchema={rootSchema}
86
+ />
87
+ <Tabs
88
+ defaultActiveKey={String(selectedIndex)}
89
+ onChange={handleTabChange}
90
+ items={oneOfRenderInfos.map(
91
+ (oneOfRenderInfo, idx) =>
92
+ ({
93
+ label: oneOfRenderInfo.label,
94
+ key: String(idx),
95
+ children: (
96
+ <JsonFormsDispatch
97
+ schema={oneOfRenderInfo.schema}
98
+ uischema={oneOfRenderInfo.uischema}
99
+ path={path}
100
+ renderers={renderers}
101
+ cells={cells}
102
+ />
103
+ ),
104
+ }) as any,
105
+ )}
106
+ ></Tabs>
107
+ <TabSwitchConfirmDialog
108
+ cancel={handleClose}
109
+ confirm={confirm}
110
+ id={'oneOf-' + id}
111
+ open={confirmDialogOpen}
112
+ handleClose={handleClose}
113
+ />
114
+ </>
115
+ );
116
+ };
117
+
118
+ export const oneOfTabControlTester: RankedTester = rankWith(
119
+ 4,
120
+ and(isOneOfControl, optionIs('variant', 'tab')),
121
+ );
122
+
123
+ export default withJsonFormsOneOfProps(OneOfTabRenderer);
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { useConfirmation } from '../util/useConfirmation';
3
+ import {
4
+ createRecursiveTreeRenderer,
5
+ recursiveTreeTester,
6
+ } from '@chobantonov/jsonforms-react-renderer-common/mixed/RecursiveTreeRenderer';
7
+ import { ContainerValidationIndicator } from '../layouts/ValidationIndicator';
8
+ import { AntdMixedTree as Tree } from './mixed/AntdMixedTree';
9
+ import { Button } from 'antd';
10
+ export { recursiveTreeTester };
11
+ export const RecursiveTreeRenderer = createRecursiveTreeRenderer(
12
+ Tree,
13
+ ContainerValidationIndicator,
14
+ ({ children, onClick }) => (
15
+ <Button type='link' onClick={onClick}>
16
+ {children}
17
+ </Button>
18
+ ),
19
+ useConfirmation,
20
+ );
@@ -0,0 +1,99 @@
1
+ import { DetailModal } from '../complex/DetailModal';
2
+ import React from 'react';
3
+ import { Splitter, Empty, Button, Tooltip } from 'antd';
4
+ import { EyeOutlined, EyeInvisibleOutlined } from '@ant-design/icons';
5
+ import {
6
+ type RowDetailState,
7
+ createRowDetailToggle,
8
+ createRowDetailFrame,
9
+ } from '@chobantonov/jsonforms-react-renderer-common/collections/rowDetail';
10
+ const RowDialog = ({ state }: { state: RowDetailState }) => {
11
+ const { options, t } = state;
12
+ return (
13
+ <DetailModal
14
+ options={options.dialog}
15
+ open={!!state.selection}
16
+ title={t('collection.editDetails')}
17
+ onCancel={state.close}
18
+ onOk={state.apply}
19
+ okText={t('composite.apply')}
20
+ cancelText={t('composite.cancel')}
21
+ okButtonProps={{ disabled: !state.enabled || state.conflict }}
22
+ styles={{ body: { maxHeight: '65vh', overflow: 'auto' } }}
23
+ >
24
+ {state.conflict && <p role='alert'>{t('composite.applyConflict')}</p>}
25
+ {state.content}
26
+ </DetailModal>
27
+ );
28
+ };
29
+ const RowPanel = ({
30
+ state,
31
+ children,
32
+ }: React.PropsWithChildren<{ state: RowDetailState }>) => {
33
+ const { options, panelOpen, t } = state;
34
+ return (
35
+ <div>
36
+ <Splitter
37
+ orientation={options.placement === 'bottom' ? 'vertical' : 'horizontal'}
38
+ style={{
39
+ height: panelOpen
40
+ ? options.placement === 'bottom'
41
+ ? '40rem'
42
+ : '32rem'
43
+ : 'auto',
44
+ maxWidth: '100%',
45
+ }}
46
+ >
47
+ <Splitter.Panel
48
+ defaultSize='55%'
49
+ min='20%'
50
+ resizable={options.resizable !== false}
51
+ >
52
+ <div
53
+ style={{
54
+ height: panelOpen ? '100%' : undefined,
55
+ minWidth: 0,
56
+ minHeight: 0,
57
+ overflow: 'auto',
58
+ }}
59
+ >
60
+ {children}
61
+ </div>
62
+ </Splitter.Panel>
63
+ {panelOpen && (
64
+ <Splitter.Panel min='20%' resizable={options.resizable !== false}>
65
+ <div
66
+ style={{
67
+ padding: 12,
68
+ height: '100%',
69
+ minWidth: 0,
70
+ minHeight: 0,
71
+ overflow: 'auto',
72
+ }}
73
+ >
74
+ {state.content ?? (
75
+ <Empty description={t('collection.selectItem')} />
76
+ )}
77
+ </div>
78
+ </Splitter.Panel>
79
+ )}
80
+ </Splitter>
81
+ </div>
82
+ );
83
+ };
84
+
85
+ export const RowDetailFrame = createRowDetailFrame(RowDialog, RowPanel);
86
+
87
+ export const RowDetailToggle = createRowDetailToggle((toggle) => (
88
+ <div style={{ display: 'inline-flex' }}>
89
+ <Tooltip title={toggle.label}>
90
+ <Button
91
+ shape='circle'
92
+ aria-label={toggle.label}
93
+ aria-expanded={toggle.expanded}
94
+ icon={toggle.expanded ? <EyeInvisibleOutlined /> : <EyeOutlined />}
95
+ onClick={toggle.toggle}
96
+ />
97
+ </Tooltip>
98
+ </div>
99
+ ));
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import type { ControlProps } from '@jsonforms/core';
3
+ import { withJsonFormsControlProps } from '@jsonforms/react';
4
+ import { ScalarCompositionControl } from '@chobantonov/jsonforms-react-renderer-common/composition/ScalarCompositionControl';
5
+ export { scalarCompositionTester } from '@chobantonov/jsonforms-react-renderer-common/composition/useScalarComposition';
6
+ const MESSAGE_STYLE: React.CSSProperties = { marginTop: -16, marginBottom: 16 };
7
+
8
+ export default withJsonFormsControlProps((props: ControlProps) => (
9
+ <ScalarCompositionControl
10
+ {...props}
11
+ errorClassName='ant-form-item-explain ant-form-item-explain-error'
12
+ errorStyle={MESSAGE_STYLE}
13
+ />
14
+ ));
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { useI18n } from '../util/translate';
3
+
4
+ import { Modal } from 'antd';
5
+
6
+ export interface TabSwitchConfirmDialogProps {
7
+ open: boolean;
8
+ handleClose: () => void;
9
+ confirm: () => void;
10
+ cancel: () => void;
11
+ id: string;
12
+ }
13
+
14
+ export const TabSwitchConfirmDialog = ({
15
+ open,
16
+ handleClose,
17
+ confirm,
18
+ cancel,
19
+ }: TabSwitchConfirmDialogProps) => {
20
+ const t = useI18n();
21
+ return (
22
+ <Modal
23
+ title={t('confirm.branchChange.title')}
24
+ open={open}
25
+ afterClose={handleClose}
26
+ onOk={confirm}
27
+ onCancel={cancel}
28
+ okText={t('confirm.accept')}
29
+ cancelText={t('confirm.decline')}
30
+ aria-labelledby='alert-dialog-title'
31
+ aria-describedby='alert-dialog-description'
32
+ >
33
+ <p>{t('confirm.branchChange.message')}</p>
34
+ </Modal>
35
+ );
36
+ };