@rjsf/core 6.0.0-alpha.0 → 6.0.0-beta.2

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 (301) hide show
  1. package/dist/core.umd.js +1680 -809
  2. package/dist/index.esm.js +2166 -1198
  3. package/dist/index.esm.js.map +4 -4
  4. package/dist/index.js +2221 -1299
  5. package/dist/index.js.map +4 -4
  6. package/lib/components/Form.d.ts +22 -9
  7. package/lib/components/Form.d.ts.map +1 -0
  8. package/lib/components/Form.js +368 -312
  9. package/lib/components/RichDescription.d.ts +20 -0
  10. package/lib/components/RichDescription.d.ts.map +1 -0
  11. package/lib/components/RichDescription.js +17 -0
  12. package/lib/components/fields/ArrayField.d.ts +20 -9
  13. package/lib/components/fields/ArrayField.d.ts.map +1 -0
  14. package/lib/components/fields/ArrayField.js +212 -206
  15. package/lib/components/fields/BooleanField.d.ts +1 -0
  16. package/lib/components/fields/BooleanField.d.ts.map +1 -0
  17. package/lib/components/fields/BooleanField.js +6 -14
  18. package/lib/components/fields/LayoutGridField.d.ts +480 -0
  19. package/lib/components/fields/LayoutGridField.d.ts.map +1 -0
  20. package/lib/components/fields/LayoutGridField.js +711 -0
  21. package/lib/components/fields/LayoutHeaderField.d.ts +12 -0
  22. package/lib/components/fields/LayoutHeaderField.d.ts.map +1 -0
  23. package/lib/components/fields/LayoutHeaderField.js +23 -0
  24. package/lib/components/fields/LayoutMultiSchemaField.d.ts +28 -0
  25. package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -0
  26. package/lib/components/fields/LayoutMultiSchemaField.js +114 -0
  27. package/lib/components/fields/MultiSchemaField.d.ts +1 -0
  28. package/lib/components/fields/MultiSchemaField.d.ts.map +1 -0
  29. package/lib/components/fields/MultiSchemaField.js +31 -31
  30. package/lib/components/fields/NullField.d.ts +1 -0
  31. package/lib/components/fields/NullField.d.ts.map +1 -0
  32. package/lib/components/fields/NullField.js +0 -1
  33. package/lib/components/fields/NumberField.d.ts +1 -0
  34. package/lib/components/fields/NumberField.d.ts.map +1 -0
  35. package/lib/components/fields/NumberField.js +2 -3
  36. package/lib/components/fields/ObjectField.d.ts +1 -0
  37. package/lib/components/fields/ObjectField.d.ts.map +1 -0
  38. package/lib/components/fields/ObjectField.js +146 -141
  39. package/lib/components/fields/SchemaField.d.ts +1 -0
  40. package/lib/components/fields/SchemaField.d.ts.map +1 -0
  41. package/lib/components/fields/SchemaField.js +10 -20
  42. package/lib/components/fields/StringField.d.ts +1 -0
  43. package/lib/components/fields/StringField.d.ts.map +1 -0
  44. package/lib/components/fields/StringField.js +1 -3
  45. package/lib/components/fields/index.d.ts +1 -0
  46. package/lib/components/fields/index.d.ts.map +1 -0
  47. package/lib/components/fields/index.js +14 -9
  48. package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -0
  49. package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts.map +1 -0
  50. package/lib/components/templates/ArrayFieldDescriptionTemplate.js +0 -1
  51. package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +8 -0
  52. package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -0
  53. package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +17 -0
  54. package/lib/components/templates/ArrayFieldItemTemplate.d.ts +4 -3
  55. package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -0
  56. package/lib/components/templates/ArrayFieldItemTemplate.js +7 -6
  57. package/lib/components/templates/ArrayFieldTemplate.d.ts +2 -1
  58. package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -0
  59. package/lib/components/templates/ArrayFieldTemplate.js +3 -4
  60. package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -0
  61. package/lib/components/templates/ArrayFieldTitleTemplate.d.ts.map +1 -0
  62. package/lib/components/templates/ArrayFieldTitleTemplate.js +0 -1
  63. package/lib/components/templates/BaseInputTemplate.d.ts +1 -0
  64. package/lib/components/templates/BaseInputTemplate.d.ts.map +1 -0
  65. package/lib/components/templates/BaseInputTemplate.js +0 -1
  66. package/lib/components/templates/ButtonTemplates/AddButton.d.ts +1 -0
  67. package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -0
  68. package/lib/components/templates/ButtonTemplates/AddButton.js +1 -2
  69. package/lib/components/templates/ButtonTemplates/IconButton.d.ts +1 -0
  70. package/lib/components/templates/ButtonTemplates/IconButton.d.ts.map +1 -0
  71. package/lib/components/templates/ButtonTemplates/IconButton.js +4 -5
  72. package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts +1 -0
  73. package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts.map +1 -0
  74. package/lib/components/templates/ButtonTemplates/SubmitButton.js +0 -1
  75. package/lib/components/templates/ButtonTemplates/index.d.ts +1 -0
  76. package/lib/components/templates/ButtonTemplates/index.d.ts.map +1 -0
  77. package/lib/components/templates/ButtonTemplates/index.js +3 -4
  78. package/lib/components/templates/DescriptionField.d.ts +1 -0
  79. package/lib/components/templates/DescriptionField.d.ts.map +1 -0
  80. package/lib/components/templates/DescriptionField.js +3 -8
  81. package/lib/components/templates/ErrorList.d.ts +1 -0
  82. package/lib/components/templates/ErrorList.d.ts.map +1 -0
  83. package/lib/components/templates/ErrorList.js +0 -1
  84. package/lib/components/templates/FieldErrorTemplate.d.ts +1 -0
  85. package/lib/components/templates/FieldErrorTemplate.d.ts.map +1 -0
  86. package/lib/components/templates/FieldErrorTemplate.js +0 -1
  87. package/lib/components/templates/FieldHelpTemplate.d.ts +1 -0
  88. package/lib/components/templates/FieldHelpTemplate.d.ts.map +1 -0
  89. package/lib/components/templates/FieldHelpTemplate.js +0 -1
  90. package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts +1 -0
  91. package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts.map +1 -0
  92. package/lib/components/templates/FieldTemplate/FieldTemplate.js +1 -2
  93. package/lib/components/templates/FieldTemplate/Label.d.ts +1 -0
  94. package/lib/components/templates/FieldTemplate/Label.d.ts.map +1 -0
  95. package/lib/components/templates/FieldTemplate/Label.js +0 -1
  96. package/lib/components/templates/FieldTemplate/index.d.ts +2 -1
  97. package/lib/components/templates/FieldTemplate/index.d.ts.map +1 -0
  98. package/lib/components/templates/FieldTemplate/index.js +1 -2
  99. package/lib/components/templates/GridTemplate.d.ts +8 -0
  100. package/lib/components/templates/GridTemplate.d.ts.map +1 -0
  101. package/lib/components/templates/GridTemplate.js +10 -0
  102. package/lib/components/templates/ObjectFieldTemplate.d.ts +1 -0
  103. package/lib/components/templates/ObjectFieldTemplate.d.ts.map +1 -0
  104. package/lib/components/templates/ObjectFieldTemplate.js +2 -3
  105. package/lib/components/templates/TitleField.d.ts +1 -0
  106. package/lib/components/templates/TitleField.d.ts.map +1 -0
  107. package/lib/components/templates/TitleField.js +0 -1
  108. package/lib/components/templates/UnsupportedField.d.ts +1 -0
  109. package/lib/components/templates/UnsupportedField.d.ts.map +1 -0
  110. package/lib/components/templates/UnsupportedField.js +0 -1
  111. package/lib/components/templates/WrapIfAdditionalTemplate.d.ts +1 -0
  112. package/lib/components/templates/WrapIfAdditionalTemplate.d.ts.map +1 -0
  113. package/lib/components/templates/WrapIfAdditionalTemplate.js +10 -6
  114. package/lib/components/templates/index.d.ts +1 -0
  115. package/lib/components/templates/index.d.ts.map +1 -0
  116. package/lib/components/templates/index.js +19 -16
  117. package/lib/components/widgets/AltDateTimeWidget.d.ts +1 -0
  118. package/lib/components/widgets/AltDateTimeWidget.d.ts.map +1 -0
  119. package/lib/components/widgets/AltDateTimeWidget.js +0 -1
  120. package/lib/components/widgets/AltDateWidget.d.ts +1 -0
  121. package/lib/components/widgets/AltDateWidget.d.ts.map +1 -0
  122. package/lib/components/widgets/AltDateWidget.js +0 -1
  123. package/lib/components/widgets/CheckboxWidget.d.ts +1 -0
  124. package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -0
  125. package/lib/components/widgets/CheckboxWidget.js +2 -4
  126. package/lib/components/widgets/CheckboxesWidget.d.ts +1 -0
  127. package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -0
  128. package/lib/components/widgets/CheckboxesWidget.js +0 -1
  129. package/lib/components/widgets/ColorWidget.d.ts +1 -0
  130. package/lib/components/widgets/ColorWidget.d.ts.map +1 -0
  131. package/lib/components/widgets/ColorWidget.js +0 -1
  132. package/lib/components/widgets/DateTimeWidget.d.ts +1 -0
  133. package/lib/components/widgets/DateTimeWidget.d.ts.map +1 -0
  134. package/lib/components/widgets/DateTimeWidget.js +0 -1
  135. package/lib/components/widgets/DateWidget.d.ts +1 -0
  136. package/lib/components/widgets/DateWidget.d.ts.map +1 -0
  137. package/lib/components/widgets/DateWidget.js +0 -1
  138. package/lib/components/widgets/EmailWidget.d.ts +1 -0
  139. package/lib/components/widgets/EmailWidget.d.ts.map +1 -0
  140. package/lib/components/widgets/EmailWidget.js +0 -1
  141. package/lib/components/widgets/FileWidget.d.ts +1 -0
  142. package/lib/components/widgets/FileWidget.d.ts.map +1 -0
  143. package/lib/components/widgets/FileWidget.js +3 -5
  144. package/lib/components/widgets/HiddenWidget.d.ts +1 -0
  145. package/lib/components/widgets/HiddenWidget.d.ts.map +1 -0
  146. package/lib/components/widgets/HiddenWidget.js +0 -1
  147. package/lib/components/widgets/PasswordWidget.d.ts +1 -0
  148. package/lib/components/widgets/PasswordWidget.d.ts.map +1 -0
  149. package/lib/components/widgets/PasswordWidget.js +0 -1
  150. package/lib/components/widgets/RadioWidget.d.ts +1 -0
  151. package/lib/components/widgets/RadioWidget.d.ts.map +1 -0
  152. package/lib/components/widgets/RadioWidget.js +3 -4
  153. package/lib/components/widgets/RangeWidget.d.ts +1 -0
  154. package/lib/components/widgets/RangeWidget.d.ts.map +1 -0
  155. package/lib/components/widgets/RangeWidget.js +0 -1
  156. package/lib/components/widgets/RatingWidget.d.ts +15 -0
  157. package/lib/components/widgets/RatingWidget.d.ts.map +1 -0
  158. package/lib/components/widgets/RatingWidget.js +63 -0
  159. package/lib/components/widgets/SelectWidget.d.ts +1 -0
  160. package/lib/components/widgets/SelectWidget.d.ts.map +1 -0
  161. package/lib/components/widgets/SelectWidget.js +4 -5
  162. package/lib/components/widgets/TextWidget.d.ts +1 -0
  163. package/lib/components/widgets/TextWidget.d.ts.map +1 -0
  164. package/lib/components/widgets/TextWidget.js +0 -1
  165. package/lib/components/widgets/TextareaWidget.d.ts +1 -0
  166. package/lib/components/widgets/TextareaWidget.d.ts.map +1 -0
  167. package/lib/components/widgets/TextareaWidget.js +0 -1
  168. package/lib/components/widgets/TimeWidget.d.ts +1 -0
  169. package/lib/components/widgets/TimeWidget.d.ts.map +1 -0
  170. package/lib/components/widgets/TimeWidget.js +0 -1
  171. package/lib/components/widgets/URLWidget.d.ts +1 -0
  172. package/lib/components/widgets/URLWidget.d.ts.map +1 -0
  173. package/lib/components/widgets/URLWidget.js +0 -1
  174. package/lib/components/widgets/UpDownWidget.d.ts +1 -0
  175. package/lib/components/widgets/UpDownWidget.d.ts.map +1 -0
  176. package/lib/components/widgets/UpDownWidget.js +0 -1
  177. package/lib/components/widgets/index.d.ts +1 -0
  178. package/lib/components/widgets/index.d.ts.map +1 -0
  179. package/lib/components/widgets/index.js +21 -20
  180. package/lib/getDefaultRegistry.d.ts +1 -0
  181. package/lib/getDefaultRegistry.d.ts.map +1 -0
  182. package/lib/getDefaultRegistry.js +3 -4
  183. package/lib/index.d.ts +7 -5
  184. package/lib/index.d.ts.map +1 -0
  185. package/lib/index.js +5 -5
  186. package/lib/tsconfig.tsbuildinfo +1 -1
  187. package/lib/withTheme.d.ts +2 -1
  188. package/lib/withTheme.d.ts.map +1 -0
  189. package/lib/withTheme.js +7 -8
  190. package/package.json +46 -37
  191. package/src/components/Form.tsx +127 -41
  192. package/src/components/RichDescription.tsx +50 -0
  193. package/src/components/fields/ArrayField.tsx +34 -24
  194. package/src/components/fields/BooleanField.tsx +6 -14
  195. package/src/components/fields/LayoutGridField.tsx +967 -0
  196. package/src/components/fields/LayoutHeaderField.tsx +49 -0
  197. package/src/components/fields/LayoutMultiSchemaField.tsx +228 -0
  198. package/src/components/fields/MultiSchemaField.tsx +9 -4
  199. package/src/components/fields/NullField.tsx +1 -1
  200. package/src/components/fields/NumberField.tsx +5 -5
  201. package/src/components/fields/ObjectField.tsx +32 -24
  202. package/src/components/fields/SchemaField.tsx +17 -30
  203. package/src/components/fields/StringField.tsx +2 -2
  204. package/src/components/fields/index.ts +7 -1
  205. package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +2 -2
  206. package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +85 -0
  207. package/src/components/templates/ArrayFieldItemTemplate.tsx +18 -57
  208. package/src/components/templates/ArrayFieldTemplate.tsx +10 -8
  209. package/src/components/templates/ArrayFieldTitleTemplate.tsx +2 -2
  210. package/src/components/templates/BaseInputTemplate.tsx +4 -4
  211. package/src/components/templates/ButtonTemplates/IconButton.tsx +9 -36
  212. package/src/components/templates/ButtonTemplates/SubmitButton.tsx +1 -1
  213. package/src/components/templates/ButtonTemplates/index.ts +1 -1
  214. package/src/components/templates/DescriptionField.tsx +9 -15
  215. package/src/components/templates/FieldErrorTemplate.tsx +1 -1
  216. package/src/components/templates/FieldHelpTemplate.tsx +1 -1
  217. package/src/components/templates/FieldTemplate/FieldTemplate.tsx +2 -2
  218. package/src/components/templates/GridTemplate.tsx +15 -0
  219. package/src/components/templates/ObjectFieldTemplate.tsx +5 -3
  220. package/src/components/templates/TitleField.tsx +1 -1
  221. package/src/components/templates/UnsupportedField.tsx +1 -1
  222. package/src/components/templates/WrapIfAdditionalTemplate.tsx +14 -4
  223. package/src/components/templates/index.ts +4 -0
  224. package/src/components/widgets/AltDateWidget.tsx +9 -6
  225. package/src/components/widgets/CheckboxWidget.tsx +5 -5
  226. package/src/components/widgets/CheckboxesWidget.tsx +2 -2
  227. package/src/components/widgets/ColorWidget.tsx +1 -1
  228. package/src/components/widgets/DateTimeWidget.tsx +1 -1
  229. package/src/components/widgets/DateWidget.tsx +1 -1
  230. package/src/components/widgets/EmailWidget.tsx +1 -1
  231. package/src/components/widgets/FileWidget.tsx +5 -5
  232. package/src/components/widgets/PasswordWidget.tsx +1 -1
  233. package/src/components/widgets/RadioWidget.tsx +3 -3
  234. package/src/components/widgets/RangeWidget.tsx +1 -1
  235. package/src/components/widgets/RatingWidget.tsx +129 -0
  236. package/src/components/widgets/SelectWidget.tsx +4 -3
  237. package/src/components/widgets/TextWidget.tsx +1 -1
  238. package/src/components/widgets/TextareaWidget.tsx +3 -3
  239. package/src/components/widgets/TimeWidget.tsx +1 -1
  240. package/src/components/widgets/URLWidget.tsx +1 -1
  241. package/src/components/widgets/UpDownWidget.tsx +1 -1
  242. package/src/components/widgets/index.ts +3 -1
  243. package/src/getDefaultRegistry.ts +1 -1
  244. package/src/index.ts +3 -2
  245. package/src/tsconfig.json +14 -6
  246. package/src/withTheme.tsx +4 -3
  247. package/LICENSE.md +0 -201
  248. package/lib/components/Form.js.map +0 -1
  249. package/lib/components/fields/ArrayField.js.map +0 -1
  250. package/lib/components/fields/BooleanField.js.map +0 -1
  251. package/lib/components/fields/MultiSchemaField.js.map +0 -1
  252. package/lib/components/fields/NullField.js.map +0 -1
  253. package/lib/components/fields/NumberField.js.map +0 -1
  254. package/lib/components/fields/ObjectField.js.map +0 -1
  255. package/lib/components/fields/SchemaField.js.map +0 -1
  256. package/lib/components/fields/StringField.js.map +0 -1
  257. package/lib/components/fields/index.js.map +0 -1
  258. package/lib/components/templates/ArrayFieldDescriptionTemplate.js.map +0 -1
  259. package/lib/components/templates/ArrayFieldItemTemplate.js.map +0 -1
  260. package/lib/components/templates/ArrayFieldTemplate.js.map +0 -1
  261. package/lib/components/templates/ArrayFieldTitleTemplate.js.map +0 -1
  262. package/lib/components/templates/BaseInputTemplate.js.map +0 -1
  263. package/lib/components/templates/ButtonTemplates/AddButton.js.map +0 -1
  264. package/lib/components/templates/ButtonTemplates/IconButton.js.map +0 -1
  265. package/lib/components/templates/ButtonTemplates/SubmitButton.js.map +0 -1
  266. package/lib/components/templates/ButtonTemplates/index.js.map +0 -1
  267. package/lib/components/templates/DescriptionField.js.map +0 -1
  268. package/lib/components/templates/ErrorList.js.map +0 -1
  269. package/lib/components/templates/FieldErrorTemplate.js.map +0 -1
  270. package/lib/components/templates/FieldHelpTemplate.js.map +0 -1
  271. package/lib/components/templates/FieldTemplate/FieldTemplate.js.map +0 -1
  272. package/lib/components/templates/FieldTemplate/Label.js.map +0 -1
  273. package/lib/components/templates/FieldTemplate/index.js.map +0 -1
  274. package/lib/components/templates/ObjectFieldTemplate.js.map +0 -1
  275. package/lib/components/templates/TitleField.js.map +0 -1
  276. package/lib/components/templates/UnsupportedField.js.map +0 -1
  277. package/lib/components/templates/WrapIfAdditionalTemplate.js.map +0 -1
  278. package/lib/components/templates/index.js.map +0 -1
  279. package/lib/components/widgets/AltDateTimeWidget.js.map +0 -1
  280. package/lib/components/widgets/AltDateWidget.js.map +0 -1
  281. package/lib/components/widgets/CheckboxWidget.js.map +0 -1
  282. package/lib/components/widgets/CheckboxesWidget.js.map +0 -1
  283. package/lib/components/widgets/ColorWidget.js.map +0 -1
  284. package/lib/components/widgets/DateTimeWidget.js.map +0 -1
  285. package/lib/components/widgets/DateWidget.js.map +0 -1
  286. package/lib/components/widgets/EmailWidget.js.map +0 -1
  287. package/lib/components/widgets/FileWidget.js.map +0 -1
  288. package/lib/components/widgets/HiddenWidget.js.map +0 -1
  289. package/lib/components/widgets/PasswordWidget.js.map +0 -1
  290. package/lib/components/widgets/RadioWidget.js.map +0 -1
  291. package/lib/components/widgets/RangeWidget.js.map +0 -1
  292. package/lib/components/widgets/SelectWidget.js.map +0 -1
  293. package/lib/components/widgets/TextWidget.js.map +0 -1
  294. package/lib/components/widgets/TextareaWidget.js.map +0 -1
  295. package/lib/components/widgets/TimeWidget.js.map +0 -1
  296. package/lib/components/widgets/URLWidget.js.map +0 -1
  297. package/lib/components/widgets/UpDownWidget.js.map +0 -1
  298. package/lib/components/widgets/index.js.map +0 -1
  299. package/lib/getDefaultRegistry.js.map +0 -1
  300. package/lib/index.js.map +0 -1
  301. package/lib/withTheme.js.map +0 -1
@@ -0,0 +1,967 @@
1
+ import { ComponentType, PureComponent, ReactNode } from 'react';
2
+ import {
3
+ ANY_OF_KEY,
4
+ ErrorSchema,
5
+ FieldProps,
6
+ FormContextType,
7
+ GenericObjectType,
8
+ getDiscriminatorFieldFromSchema,
9
+ getTemplate,
10
+ getTestIds,
11
+ getUiOptions,
12
+ hashObject,
13
+ ID_KEY,
14
+ IdSchema,
15
+ lookupFromFormContext,
16
+ mergeObjects,
17
+ ONE_OF_KEY,
18
+ PROPERTIES_KEY,
19
+ READONLY_KEY,
20
+ RJSFSchema,
21
+ Registry,
22
+ SchemaUtilsType,
23
+ StrictRJSFSchema,
24
+ UI_OPTIONS_KEY,
25
+ UiSchema,
26
+ } from '@rjsf/utils';
27
+ import cloneDeep from 'lodash/cloneDeep';
28
+ import each from 'lodash/each';
29
+ import flatten from 'lodash/flatten';
30
+ import get from 'lodash/get';
31
+ import has from 'lodash/has';
32
+ import includes from 'lodash/includes';
33
+ import intersection from 'lodash/intersection';
34
+ import isEmpty from 'lodash/isEmpty';
35
+ import isFunction from 'lodash/isFunction';
36
+ import isEqual from 'lodash/isEqual';
37
+ import isObject from 'lodash/isObject';
38
+ import isPlainObject from 'lodash/isPlainObject';
39
+ import isString from 'lodash/isString';
40
+ import isUndefined from 'lodash/isUndefined';
41
+ import set from 'lodash/set';
42
+
43
+ /** The enumeration of the three different Layout GridTemplate type values
44
+ */
45
+ export enum GridType {
46
+ ROW = 'ui:row',
47
+ COLUMN = 'ui:col',
48
+ COLUMNS = 'ui:columns',
49
+ CONDITION = 'ui:condition',
50
+ }
51
+
52
+ /** The enumeration of the different operators within a condition
53
+ */
54
+ export enum Operators {
55
+ ALL = 'all',
56
+ SOME = 'some',
57
+ NONE = 'none',
58
+ }
59
+
60
+ /** Type used to represent an object that contains anything */
61
+ type ConfigObject = Record<string, any>;
62
+
63
+ export interface GridProps extends GenericObjectType {
64
+ /** The optional operator to use when comparing a field's value with the expected value for `GridType.CONDITION`
65
+ */
66
+ operator?: Operators;
67
+ /** The optional name of the field from which to get the value for `GridType.CONDITION`
68
+ */
69
+ field?: string;
70
+ /** The optional expected value against which to compare the field's value using the `operator`
71
+ */
72
+ value?: unknown;
73
+ }
74
+
75
+ export type GridSchemaType = {
76
+ /** The limited set of props which are keyed using the `GridType` enumeration and return an object
77
+ */
78
+ [gridType in GridType]?: object;
79
+ };
80
+
81
+ /** The types which comprise the possibilities for the `layoutGridSchema` prop
82
+ */
83
+ export type LayoutGridSchemaType = GridSchemaType | ConfigObject | string;
84
+
85
+ export interface LayoutGridFieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>
86
+ extends FieldProps<T, S, F> {
87
+ /** Optional string or object used to describe the current level of the `LayoutGridField`
88
+ */
89
+ layoutGridSchema?: LayoutGridSchemaType;
90
+ }
91
+
92
+ /** The regular expression that is used to detect whether a string contains a lookup key
93
+ */
94
+ export const LOOKUP_REGEX = /^\$lookup=(.+)/;
95
+
96
+ /** The constant representing the main layout grid schema option name in the `uiSchema`
97
+ */
98
+ export const LAYOUT_GRID_UI_OPTION = 'layoutGrid';
99
+
100
+ /** The constant representing the main layout grid schema option name in the `uiSchema`
101
+ */
102
+ export const LAYOUT_GRID_OPTION = `ui:${LAYOUT_GRID_UI_OPTION}`;
103
+
104
+ /** The constant representing the global UI Options object potentially contained within the `uiSchema`
105
+ */
106
+ export const UI_GLOBAL_OPTIONS = 'ui:global_options';
107
+
108
+ /** Type used to return options list and whether it has a discriminator */
109
+ type OneOfOptionsInfoType<S extends StrictRJSFSchema = RJSFSchema> = { options: S[]; hasDiscriminator: boolean };
110
+
111
+ /** Type used to represent a React-based rendering component */
112
+ type RenderComponent = ComponentType<any>;
113
+
114
+ /** Type used to determine what are the UIComponent and props from the grid schema */
115
+ type UIComponentPropsType = {
116
+ /** The name of the component */
117
+ name: string;
118
+ /** The render component if specified */
119
+ UIComponent: RenderComponent | null;
120
+ /** Any uiProps associated with the render component */
121
+ uiProps: ConfigObject;
122
+ /** The special case where the component is immediately rendered */
123
+ rendered: ReactNode;
124
+ };
125
+
126
+ /** Returns either the `value` if it is non-nullish or the fallback
127
+ *
128
+ * @param [value] - The potential value to return if it is non-nullish
129
+ * @param [fallback] - The fallback value to return if `value` is nullish
130
+ * @returns - `value` if it is non-nullish otherwise `fallback`
131
+ */
132
+ function getNonNullishValue<T = unknown>(value?: T, fallback?: T): T | undefined {
133
+ return value ?? fallback;
134
+ }
135
+
136
+ /** The `LayoutGridField` will render a schema, uiSchema and formData combination out into a GridTemplate in the shape
137
+ * described in the uiSchema. To define the grid to use to render the elements within a field in the schema, provide in
138
+ * the uiSchema for that field the object contained under a `ui:layoutGrid` element. E.g. (as a JSON object):
139
+ *
140
+ * ```
141
+ * {
142
+ * "field1" : {
143
+ * "ui:field": "LayoutGridField",
144
+ * "ui:layoutGrid": {
145
+ * "ui:row": { ... }
146
+ * }
147
+ * }
148
+ * }
149
+ * ```
150
+ *
151
+ * The outermost level of a `LayoutGridField` is the `ui:row` that defines the nested rows, columns, and/or condition
152
+ * elements (i.e. "grid elements") in the grid. This definition is either a simple "grid elements" OR an object with
153
+ * native `GridTemplate` implementation specific props and a `children` array of "grid elements". E.g. (as JSON objects):
154
+ *
155
+ * Simple `ui:row` definition, without additional `GridTemplate` props:
156
+ * ```
157
+ * "ui:row": [
158
+ * { "ui:row"|"ui:col"|"ui:columns"|"ui:condition": ... },
159
+ * ...
160
+ * ]
161
+ * ```
162
+ *
163
+ * Complex `ui:row` definition, with additional `GridTemplate` (this example uses @mui/material/Grid2 native props):
164
+ * ```
165
+ * "ui:row": {
166
+ * "spacing": 2,
167
+ * "size": { md": 4 },
168
+ * "alignContent": "flex-start",
169
+ * "className": "GridRow",
170
+ * "children": [
171
+ * { "ui:row"|"ui:col"|"ui:columns"|"ui:condition": ... },
172
+ * ...
173
+ * ]
174
+ * }
175
+ * ```
176
+ *
177
+ * NOTE: Special note about the native `className` prop values. All className values will automatically be looked up in
178
+ * the `formContext.lookupMap` in case they have been defined using a CSS-in-JS approach. In other words, from the
179
+ * example above, if the `Form` was constructed with a `lookupMap` set to `{ GridRow: cssInJs.GridRowClass }`
180
+ * then when rendered, the native `GridTemplate` will get the `className` with the value from
181
+ * `cssInJs.GridRowClass`. This automatic lookup will happen for any of the "grid elements" when rendering with
182
+ * `GridTemplate` props. If multiple className values are present, for example:
183
+ * `{ className: 'GridRow GridColumn' }`, the classNames are split apart, looked up individually, and joined
184
+ * together to form one className with the values from `cssInJs.GridRowClass` and `cssInJs.GridColumnClass`.
185
+ *
186
+ * The `ui:col` grid element is used to specify the list of columns within a grid row. A `ui:col` element can take on
187
+ * several forms: 1) a simple list of dotted-path field names within the root field; 2) a list of objects containing the
188
+ * dotted-path field `name` any other props that are gathered into `ui:options` for the field; 3) a list with a one-off
189
+ * `render` functional component with or without a non-field `name` identifier and any other to-be-spread props; and
190
+ * 4) an object with native `GridTemplate` implementation specific props and a `children` array with 1) or 2) or even a
191
+ * nested `ui:row` or a `ui:condition` containing a `ui:row` (although this should be used carefully). E.g.
192
+ * (as JSON objects):
193
+ *
194
+ * Simple `ui:col` definition, without additional `GridTemplate` props and form 1 only children:
195
+ * ```
196
+ * "ui:col": ["innerField", "inner.grandChild", ...]
197
+ * ```
198
+ *
199
+ * Complicated `ui:col` definition, without additional `GridTemplate` props and form 2 only children:
200
+ * ```
201
+ * "ui:col": [
202
+ * { "name": "innerField", "fullWidth": true },
203
+ * { "name": "inner.grandChild", "convertOther": true },
204
+ * ...
205
+ * ]
206
+ * ```
207
+ *
208
+ * More complicated `ui:col` definition, without additional `GridTemplate` props and form 2 children, one being a
209
+ * one-off `render` functional component without a non-field `name` identifier
210
+ * ```
211
+ * "ui:col": [
212
+ * "innerField",
213
+ * {
214
+ * "render": "WizardNavButton",
215
+ * "isNext": true,
216
+ * "size": "large"
217
+ * }
218
+ * ]
219
+ * ```
220
+ *
221
+ * Most complicated `ui:col` definition, additional `GridTemplate` props and form 1, 2 and 3 children (this example
222
+ * uses @mui/material/Grid2 native props):
223
+ * ```
224
+ * "ui:col": {
225
+ * "size": { "md": 4 },
226
+ * "className": "GridColumn",
227
+ * "children": [
228
+ * "innerField",
229
+ * { "name": "inner.grandChild", "convertOther": true },
230
+ * { "name": "customRender", "render": "CustomRender", toSpread: "prop-value" }
231
+ * { "ui:row|ui:condition": ... }
232
+ * ...
233
+ * ]
234
+ * }
235
+ * ```
236
+ *
237
+ * NOTE: If a `name` prop does not exist or its value does not match any field in a schema, then it is assumed to be a
238
+ * custom `render` component. If the `render` prop does not exist, a null render will occur. If `render` is a
239
+ * string, its value will be looked up in the `formContext.lookupMap` first before defaulting to a null render.
240
+ *
241
+ * The `ui:columns` grid element is syntactic sugar to specify a set of `ui:col` columns that all share the same set of
242
+ * native `GridTemplate` props. In other words rather than writing the following configuration that renders a
243
+ * `<GridTemplate>` element with 3 `<GridTemplate column className="GridColumn col-md-4">` nodes and 2
244
+ * `<GridTemplate column className="col-md-6">` nodes within it (one for each of the fields contained in the `children`
245
+ * list):
246
+ *
247
+ * ```
248
+ * "ui:row": {
249
+ * "children": [
250
+ * {
251
+ * "ui:col": {
252
+ * "className": "GridColumn col-md-4",
253
+ * "children": ["innerField"],
254
+ * }
255
+ * },
256
+ * {
257
+ * "ui:col": {
258
+ * "className": "GridColumn col-md-4",
259
+ * "children": ["inner.grandChild"],
260
+ * }
261
+ * },
262
+ * {
263
+ * "ui:col": {
264
+ * "className": "GridColumn col-md-4",
265
+ * "children": [{ "name": "inner.grandChild2" }],
266
+ * }
267
+ * },
268
+ * {
269
+ * "ui:col": {
270
+ * "className": "col-md-6",
271
+ * "children": ["innerField2"],
272
+ * }
273
+ * },
274
+ * {
275
+ * "ui:col": {
276
+ * "className": "col-md-6",
277
+ * "children": ["inner.grandChild3"],
278
+ * }
279
+ * },
280
+
281
+ * ]
282
+ * }
283
+ * ```
284
+ *
285
+ * One can write this instead:
286
+ * ```
287
+ * "ui:row": {
288
+ * "children": [
289
+ * {
290
+ * "ui:columns": {
291
+ * "className": "GridColumn col-md-4",
292
+ * "children": ["innerField", "inner.grandChild", { "name": "inner.grandChild2", "convertOther": true }],
293
+ * }
294
+ * },
295
+ * {
296
+ * "ui:columns": {
297
+ * "className": "col-md-6",
298
+ * "children": ["innerField2", "inner.grandChild3"],
299
+ * }
300
+ * }
301
+ * ]
302
+ * }
303
+ * ```
304
+ *
305
+ * NOTE: This syntax differs from
306
+ * `"ui:col": { "className": "col-md-6", "children": ["innerField2", "inner.grandChild3"] }` in that
307
+ * the `ui:col` will render the two children fields inside a single `<GridTemplate "className": "col-md-6",>`
308
+ * element.
309
+ *
310
+ * The final grid element, `ui:condition`, allows for conditionally displaying "grid elements" within a row based on the
311
+ * current value of a field as it relates to a (list of) hard-coded value(s). There are four elements that make up a
312
+ * `ui:condition`: 1) the dotted-path `field` name within the root field that makes up the left-side of the condition;
313
+ * 2) the hard-coded `value` (single or list) that makes up the right-side of the condition; 3) the `operator` that
314
+ * controls how the left and right sides of the condition are compared; and 4) the `children` array that defines the
315
+ * "grid elements" to display if the condition passes.
316
+ *
317
+ * A `ui:condition` uses one of three `operators` when deciding if a condition passes: 1) The `all` operator will pass
318
+ * when the right-side and left-side contains all the same value(s); 2) the `some` operator will pass when the
319
+ * right-side and left-side contain as least one value in common; 3) the `none` operator will pass when the right-side
320
+ * and left-side do not contain any values in common. E.g. (as JSON objects):
321
+ *
322
+ * Here is how to render an if-then-else for `field2` which is an enum that has 3 known values and supports allowing
323
+ * any other value:
324
+ * ```
325
+ * "ui:row": [
326
+ * {
327
+ * "ui:condition": {
328
+ * "field": "field2",
329
+ * "operator": "all",
330
+ * "value": "value1",
331
+ * "children": [
332
+ * { "ui:row": [...] },
333
+ * ],
334
+ * }
335
+ * },
336
+ * {
337
+ * "ui:condition": {
338
+ * "field": "field2",
339
+ * "operator": "some",
340
+ * "value": ["value2", "value3"],
341
+ * "children": [
342
+ * { "ui:row": [...] },
343
+ * ],
344
+ * }
345
+ * },
346
+ * {
347
+ * "ui:condition": {
348
+ * "field": "field2",
349
+ * "operator": "none",
350
+ * "value": ["value1", "value2", "value3"],
351
+ * "children": [
352
+ * { "ui:row": [...] },
353
+ * ],
354
+ * }
355
+ * }
356
+ * ]
357
+ * ```
358
+ */
359
+ export default class LayoutGridField<
360
+ T = any,
361
+ S extends StrictRJSFSchema = RJSFSchema,
362
+ F extends FormContextType = any,
363
+ > extends PureComponent<LayoutGridFieldProps<T, S, F>> {
364
+ static defaultProps = {
365
+ layoutGridSchema: undefined,
366
+ };
367
+
368
+ static TEST_IDS = getTestIds();
369
+ /** Computes the uiSchema for the field with `name` from the `uiProps` and `uiSchema` provided. The field UI Schema
370
+ * will always contain a copy of the global options from the `uiSchema` (so they can be passed down) as well as
371
+ * copying them into the local ui options. When the `forceReadonly` flag is true, then the field UI Schema is
372
+ * updated to make "readonly" be true. When the `schemaReadonly` flag is true AND the field UI Schema does NOT have
373
+ * the flag already provided, then we also make "readonly" true. We always make sure to return the final value of the
374
+ * field UI Schema's "readonly" flag as `uiReadonly` along with the `fieldUiSchema` in the return value.
375
+ *
376
+ * @param field - The name of the field to pull the existing UI Schema for
377
+ * @param uiProps - Any props that should be put into the field's uiSchema
378
+ * @param [uiSchema] - The optional UI Schema from which to get the UI schema for the field
379
+ * @param [schemaReadonly] - Optional flag indicating whether the schema indicates the field is readonly
380
+ * @param [forceReadonly] - Optional flag indicating whether the Form itself is in readonly mode
381
+ */
382
+ static computeFieldUiSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
383
+ field: string,
384
+ uiProps: ConfigObject,
385
+ uiSchema?: UiSchema<T, S, F>,
386
+ schemaReadonly?: boolean,
387
+ forceReadonly?: boolean,
388
+ ) {
389
+ const globalUiOptions = get(uiSchema, [UI_GLOBAL_OPTIONS], {});
390
+ const localUiSchema = get(uiSchema, field);
391
+ const localUiOptions = { ...get(localUiSchema, [UI_OPTIONS_KEY], {}), ...uiProps, ...globalUiOptions };
392
+ const fieldUiSchema = { ...localUiSchema };
393
+ if (!isEmpty(localUiOptions)) {
394
+ set(fieldUiSchema, [UI_OPTIONS_KEY], localUiOptions);
395
+ }
396
+ if (!isEmpty(globalUiOptions)) {
397
+ // pass the global uiOptions down to the field uiSchema so that they can be applied to all nested fields
398
+ set(fieldUiSchema, [UI_GLOBAL_OPTIONS], globalUiOptions);
399
+ }
400
+ let { readonly: uiReadonly } = getUiOptions<T, S, F>(fieldUiSchema);
401
+ if (forceReadonly === true || (isUndefined(uiReadonly) && schemaReadonly === true)) {
402
+ // If we are forcing all widgets to be readonly, OR the schema indicates it is readonly AND the uiSchema does not
403
+ // have an overriding value, then update the uiSchema to set readonly to true. Doing this will
404
+ uiReadonly = true;
405
+ if (has(localUiOptions, READONLY_KEY)) {
406
+ // If the local options has the key value provided in it, then set that one to true
407
+ set(fieldUiSchema, [UI_OPTIONS_KEY, READONLY_KEY], true);
408
+ } else {
409
+ // otherwise set the `ui:` version
410
+ set(fieldUiSchema, `ui:${READONLY_KEY}`, true);
411
+ }
412
+ }
413
+ return { fieldUiSchema, uiReadonly };
414
+ }
415
+
416
+ /** Given an `operator`, `datum` and `value` determines whether this condition is considered matching. Matching
417
+ * depends on the `operator`. The `datum` and `value` are converted into arrays if they aren't already and then the
418
+ * contents of the two arrays are compared using the `operator`. When `operator` is All, then the two arrays must be
419
+ * equal to match. When `operator` is SOME then the intersection of the two arrays must have at least one value in
420
+ * common to match. When `operator` is NONE then the intersection of the two arrays must not have any values in common
421
+ * to match.
422
+ *
423
+ * @param [operator] - The optional operator for the condition
424
+ * @param [datum] - The optional datum for the condition, this can be an item or a list of items of type unknown
425
+ * @param [value='$0m3tH1nG Un3xP3cT3d'] The optional value for the condition, defaulting to a highly unlikely value
426
+ * to avoid comparing two undefined elements when `value` was forgotten in the condition definition.
427
+ * This can be an item or a list of items of type unknown
428
+ * @returns - True if the condition matches, false otherwise
429
+ */
430
+ static conditionMatches(operator?: Operators, datum?: unknown, value: unknown = '$0m3tH1nG Un3xP3cT3d'): boolean {
431
+ const data = flatten([datum]).sort();
432
+ const values = flatten([value]).sort();
433
+ switch (operator) {
434
+ case Operators.ALL:
435
+ return isEqual(data, values);
436
+ case Operators.SOME:
437
+ return intersection(data, values).length > 0;
438
+ case Operators.NONE:
439
+ return intersection(data, values).length === 0;
440
+ default:
441
+ return false;
442
+ }
443
+ }
444
+
445
+ /** From within the `layoutGridSchema` finds the `children` and any extra `gridProps` from the object keyed by
446
+ * `schemaKey`. If the `children` contains extra `gridProps` and those props contain a `className` string, try to
447
+ * lookup whether that `className` has a replacement value in the `registry` using the `FORM_CONTEXT_LOOKUP_BASE`.
448
+ * When the `className` value contains multiple classNames separated by a space, the lookup will look for a
449
+ * replacement value for each `className` and combine them into one.
450
+ *
451
+ * @param layoutGridSchema - The GridSchemaType instance from which to obtain the `schemaKey` children and extra props
452
+ * @param schemaKey - A `GridType` value, used to get the children and extra props from within the `layoutGridSchema`
453
+ * @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
454
+ * @returns - An object containing the list of `LayoutGridSchemaType` `children` and any extra `gridProps`
455
+ * @throws - A `TypeError` when the `children` is not an array
456
+ */
457
+ static findChildrenAndProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
458
+ layoutGridSchema: GridSchemaType,
459
+ schemaKey: GridType,
460
+ registry: Registry<T, S, F>,
461
+ ) {
462
+ let gridProps: GridProps = {};
463
+ let children = layoutGridSchema[schemaKey];
464
+ if (isPlainObject(children)) {
465
+ const { children: elements, className: toMapClassNames, ...otherProps } = children as ConfigObject;
466
+ children = elements;
467
+ if (toMapClassNames) {
468
+ const classes = toMapClassNames.split(' ');
469
+ const className = classes.map((ele: string) => lookupFromFormContext<T, S, F>(registry, ele, ele)).join(' ');
470
+ gridProps = { ...otherProps, className };
471
+ } else {
472
+ gridProps = otherProps;
473
+ }
474
+ }
475
+ if (!Array.isArray(children)) {
476
+ throw new TypeError(`Expected array for "${schemaKey}" in ${JSON.stringify(layoutGridSchema)}`);
477
+ }
478
+ return { children: children as LayoutGridSchemaType[], gridProps };
479
+ }
480
+
481
+ /** Generates an idSchema for the `schema` using `@rjsf`'s `toIdSchema` util, passing the `baseIdSchema`'s `$id` value
482
+ * as the id prefix.
483
+ *
484
+ * @param schemaUtils - The `SchemaUtilsType` used to call `toIdSchema`
485
+ * @param schema - The schema to generate the idSchema for
486
+ * @param baseIdSchema - The IdSchema for the base
487
+ * @param formData - The formData to pass the `toIdSchema`
488
+ * @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
489
+ * @returns - The generated `idSchema` for the `schema`
490
+ */
491
+ static getIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
492
+ schemaUtils: SchemaUtilsType<T, S, F>,
493
+ baseIdSchema: IdSchema<T>,
494
+ formData: FieldProps['formData'],
495
+ schema: S = {} as S,
496
+ idSeparator?: string,
497
+ ): FieldProps<T, S, F>['idSchema'] {
498
+ const baseId = get(baseIdSchema, ID_KEY);
499
+ return schemaUtils.toIdSchema(schema, baseId, formData, baseId, idSeparator);
500
+ }
501
+
502
+ /** Given a `dottedPath` to a field in the `initialSchema`, iterate through each individual path in the schema until
503
+ * the leaf path is found and returned (along with whether that leaf path `isRequired`) OR no schema exists for an
504
+ * element in the path. If the leaf schema element happens to be a oneOf/anyOf then also return the oneOf/anyOf as
505
+ * `options`.
506
+ *
507
+ * @param schemaUtils - The `SchemaUtilsType` used to call `retrieveSchema`
508
+ * @param dottedPath - The dotted-path to the field for which to get the schema
509
+ * @param initialSchema - The initial schema to start the search from
510
+ * @param formData - The formData, useful for resolving a oneOf/anyOf selection in the path hierarchy
511
+ * @param initialIdSchema - The initial idSchema to start the search from
512
+ * @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
513
+ * @returns - An object containing the destination schema, isRequired and isReadonly flags for the field and options
514
+ * info if a oneOf/anyOf
515
+ */
516
+ static getSchemaDetailsForField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
517
+ schemaUtils: SchemaUtilsType<T, S, F>,
518
+ dottedPath: string,
519
+ initialSchema: S,
520
+ formData: FieldProps<T, S, F>['formData'],
521
+ initialIdSchema: IdSchema<T>,
522
+ idSeparator?: string,
523
+ ): {
524
+ schema?: S;
525
+ isRequired: boolean;
526
+ isReadonly?: boolean;
527
+ optionsInfo?: OneOfOptionsInfoType<S>;
528
+ idSchema: IdSchema<T>;
529
+ } {
530
+ let rawSchema: S = initialSchema;
531
+ let idSchema = initialIdSchema;
532
+ const parts: string[] = dottedPath.split('.');
533
+ const leafPath: string | undefined = parts.pop(); // pop off the last element in the list as the leaf
534
+ let schema: S | undefined = schemaUtils.retrieveSchema(rawSchema, formData); // always returns an object
535
+ let innerData = formData;
536
+ let isReadonly: boolean | undefined = schema.readOnly;
537
+
538
+ // For all the remaining path parts
539
+ parts.forEach((part) => {
540
+ // dive into the properties of the current schema (when it exists) and get the schema for the next part
541
+ if (has(schema, PROPERTIES_KEY)) {
542
+ rawSchema = get(schema, [PROPERTIES_KEY, part], {}) as S;
543
+ idSchema = get(idSchema, part, {}) as IdSchema<T>;
544
+ } else if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
545
+ const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
546
+ // When the schema represents a oneOf/anyOf, find the selected schema for it and grab the inner part
547
+ const selectedSchema = schemaUtils.findSelectedOptionInXxxOf(schema, part, xxx, innerData);
548
+ const selectedIdSchema = LayoutGridField.getIdSchema<T, S, F>(
549
+ schemaUtils,
550
+ idSchema,
551
+ formData,
552
+ selectedSchema,
553
+ idSeparator,
554
+ );
555
+ rawSchema = get(selectedSchema, [PROPERTIES_KEY, part], {}) as S;
556
+ idSchema = get(selectedIdSchema, part, {}) as IdSchema<T>;
557
+ } else {
558
+ rawSchema = {} as S;
559
+ }
560
+ // Now drill into the innerData for the part, returning an empty object by default if it doesn't exist
561
+ innerData = get(innerData, part, {}) as T;
562
+ // Resolve any `$ref`s for the current rawSchema
563
+ schema = schemaUtils.retrieveSchema(rawSchema, innerData);
564
+ isReadonly = getNonNullishValue(schema.readOnly, isReadonly);
565
+ });
566
+
567
+ let optionsInfo: OneOfOptionsInfoType<S> | undefined;
568
+ let isRequired = false;
569
+ // retrieveSchema will return an empty schema in the worst case scenario, convert it to undefined
570
+ if (isEmpty(schema)) {
571
+ schema = undefined;
572
+ }
573
+ if (schema && leafPath) {
574
+ // When we have both a schema and a leafPath...
575
+ if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
576
+ const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
577
+ // Grab the selected schema for the oneOf/anyOf value for the leafPath using the innerData
578
+ schema = schemaUtils.findSelectedOptionInXxxOf(schema, leafPath, xxx, innerData);
579
+ // Generate the idSchema for the oneOf/anyOf value then merge with the existing `idSchema`
580
+ const rawIdSchema = LayoutGridField.getIdSchema<T, S, F>(schemaUtils, idSchema, formData, schema, idSeparator);
581
+ idSchema = mergeObjects(rawIdSchema, idSchema) as IdSchema<T>;
582
+ }
583
+ isRequired = schema !== undefined && Array.isArray(schema.required) && includes(schema.required, leafPath);
584
+ // Now grab the schema from the leafPath of the current schema properties
585
+ schema = get(schema, [PROPERTIES_KEY, leafPath]) as S | undefined;
586
+ // Resolve any `$ref`s for the current schema
587
+ schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
588
+ idSchema = get(idSchema, leafPath, {}) as IdSchema<T>;
589
+ isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
590
+ if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
591
+ const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
592
+ // Set the options if we have a schema with a oneOf/anyOf
593
+ const discriminator = getDiscriminatorFieldFromSchema(schema);
594
+ optionsInfo = { options: schema[xxx] as S[], hasDiscriminator: !!discriminator };
595
+ }
596
+ }
597
+
598
+ return { schema, isRequired, isReadonly, optionsInfo, idSchema };
599
+ }
600
+
601
+ /** Gets the custom render component from the `render`, by either determining that it is either already a function or
602
+ * it is a non-function value that can be used to look up the function in the registry. If no function can be found,
603
+ * null is returned.
604
+ *
605
+ * @param render - The potential render function or lookup name to one
606
+ * @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
607
+ * @returns - Either a render function if available, or null if not
608
+ */
609
+ static getCustomRenderComponent<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
610
+ render: string | RenderComponent,
611
+ registry: Registry<T, S, F>,
612
+ ): RenderComponent | null {
613
+ let customRenderer = render;
614
+ if (isString(customRenderer)) {
615
+ customRenderer = lookupFromFormContext<T, S, F>(registry, customRenderer);
616
+ }
617
+ if (isFunction(customRenderer)) {
618
+ return customRenderer;
619
+ }
620
+ return null;
621
+ }
622
+
623
+ /** Extract the `name`, and optional `render` and all other props from the `gridSchema`. We look up the `render` to
624
+ * see if can be resolved to a UIComponent. If `name` does not exist and there is an optional `render` UIComponent, we
625
+ * set the `rendered` component with only specified props for that component in the object.
626
+ *
627
+ * @param registry - The `@rjsf` Registry from which to look up `classNames` if they are present in the extra props
628
+ * @param gridSchema - The string or object that represents the configuration for the grid field
629
+ * @returns - The UIComponentPropsType computed from the gridSchema
630
+ */
631
+ static computeUIComponentPropsFromGridSchema<
632
+ T = any,
633
+ S extends StrictRJSFSchema = RJSFSchema,
634
+ F extends FormContextType = any,
635
+ >(registry: Registry<T, S, F>, gridSchema?: string | ConfigObject): UIComponentPropsType {
636
+ let name: string;
637
+ let UIComponent: RenderComponent | null = null;
638
+ let uiProps: ConfigObject = {};
639
+ let rendered: ReactNode | undefined;
640
+ if (isString(gridSchema) || isUndefined(gridSchema)) {
641
+ name = gridSchema ?? '';
642
+ } else {
643
+ const { name: innerName, render, ...innerProps } = gridSchema;
644
+ name = innerName;
645
+ uiProps = innerProps;
646
+ if (!isEmpty(uiProps)) {
647
+ // Transform any `$lookup=` in the uiProps props with the appropriate value
648
+ each(uiProps, (prop: ConfigObject, key: string) => {
649
+ if (isString(prop)) {
650
+ const match: string[] | null = LOOKUP_REGEX.exec(prop);
651
+ if (Array.isArray(match) && match.length > 1) {
652
+ const name = match[1];
653
+ uiProps[key] = lookupFromFormContext(registry, name, name);
654
+ }
655
+ }
656
+ });
657
+ }
658
+ UIComponent = LayoutGridField.getCustomRenderComponent<T, S, F>(render, registry);
659
+ if (!innerName && UIComponent) {
660
+ rendered = <UIComponent {...innerProps} data-testid={LayoutGridField.TEST_IDS.uiComponent} />;
661
+ }
662
+ }
663
+ return { name, UIComponent, uiProps, rendered };
664
+ }
665
+
666
+ /** Constructs an `LayoutGridField` with the given `props`
667
+ *
668
+ * @param props - The `LayoutGridField` for this template
669
+ */
670
+ constructor(props: LayoutGridFieldProps<T, S, F>) {
671
+ super(props);
672
+ }
673
+
674
+ /** Generates an `onChange` handler for the field associated with the `dottedPath`. This handler will clone and update
675
+ * the `formData` with the new `value` and the `errorSchema` if an `errSchema` is provided. After updating those two
676
+ * elements, they will then be passed on to the `onChange` handler of the `LayoutFieldGrid`.
677
+ *
678
+ * @param dottedPath - The dotted-path to the field for which to generate the onChange handler
679
+ * @returns - The `onChange` handling function for the `dottedPath` field
680
+ */
681
+ onFieldChange = (dottedPath: string) => {
682
+ return (value: unknown, errSchema?: ErrorSchema<T>, id?: string) => {
683
+ const { onChange, errorSchema, formData } = this.props;
684
+ const newFormData = cloneDeep(formData || ({} as T));
685
+ let newErrorSchema = errorSchema;
686
+ if (errSchema && errorSchema) {
687
+ newErrorSchema = cloneDeep(errorSchema);
688
+ set(newErrorSchema, dottedPath, errSchema);
689
+ }
690
+ set(newFormData as object, dottedPath, value);
691
+ onChange(newFormData, newErrorSchema, id);
692
+ };
693
+ };
694
+
695
+ /** Renders the `children` of the `GridType.CONDITION` if it passes. The `layoutGridSchema` for the
696
+ * `GridType.CONDITION` is separated into the `children` and other `gridProps`. The `gridProps` are used to extract
697
+ * the `operator`, `field` and `value` of the condition. If the condition matches, then all of the `children` are
698
+ * rendered, otherwise null is returned.
699
+ *
700
+ * @param layoutGridSchema - The string or object that represents the configuration for the grid field
701
+ * @returns - The rendered the children for the `GridType.CONDITION` or null
702
+ */
703
+ renderCondition(layoutGridSchema: GridSchemaType) {
704
+ const { formData, registry } = this.props;
705
+ const { children, gridProps } = LayoutGridField.findChildrenAndProps<T, S, F>(
706
+ layoutGridSchema,
707
+ GridType.CONDITION,
708
+ registry,
709
+ );
710
+ const { operator, field = '', value } = gridProps;
711
+ const fieldData = get(formData, field, null);
712
+ if (LayoutGridField.conditionMatches(operator, fieldData, value)) {
713
+ return this.renderChildren(children);
714
+ }
715
+ return null;
716
+ }
717
+
718
+ /** Renders a material-ui `GridTemplate` as an item. The `layoutGridSchema` for the `GridType.COLUMN` is separated
719
+ * into the `children` and other `gridProps`. The `gridProps` will be spread onto the outer `GridTemplate`. Inside
720
+ * the `GridTemplate` all the `children` are rendered.
721
+ *
722
+ * @param layoutGridSchema - The string or object that represents the configuration for the grid field
723
+ * @returns - The rendered `GridTemplate` containing the children for the `GridType.COLUMN`
724
+ */
725
+ renderCol(layoutGridSchema: GridSchemaType) {
726
+ const { registry, uiSchema } = this.props;
727
+ const { children, gridProps } = LayoutGridField.findChildrenAndProps<T, S, F>(
728
+ layoutGridSchema,
729
+ GridType.COLUMN,
730
+ registry,
731
+ );
732
+ const uiOptions = getUiOptions<T, S, F>(uiSchema);
733
+ const GridTemplate = getTemplate<'GridTemplate', T, S, F>('GridTemplate', registry, uiOptions);
734
+
735
+ return (
736
+ <GridTemplate column data-testid={LayoutGridField.TEST_IDS.col} {...gridProps}>
737
+ {this.renderChildren(children)}
738
+ </GridTemplate>
739
+ );
740
+ }
741
+
742
+ /** Renders a material-ui `GridTemplate` as an item. The `layoutGridSchema` for the `GridType.COLUMNS` is separated
743
+ * into the `children` and other `gridProps`. The `children` is iterated on and `gridProps` will be spread onto the
744
+ * outer `GridTemplate`. Each child will have their own rendered `GridTemplate`.
745
+ *
746
+ * @param layoutGridSchema - The string or object that represents the configuration for the grid field
747
+ * @returns - The rendered `GridTemplate` containing the children for the `GridType.COLUMNS`
748
+ */
749
+ renderColumns(layoutGridSchema: GridSchemaType) {
750
+ const { registry, uiSchema } = this.props;
751
+ const { children, gridProps } = LayoutGridField.findChildrenAndProps<T, S, F>(
752
+ layoutGridSchema,
753
+ GridType.COLUMNS,
754
+ registry,
755
+ );
756
+ const uiOptions = getUiOptions<T, S, F>(uiSchema);
757
+ const GridTemplate = getTemplate<'GridTemplate', T, S, F>('GridTemplate', registry, uiOptions);
758
+
759
+ return children.map((child) => (
760
+ <GridTemplate
761
+ column
762
+ key={`column-${hashObject(child)}`}
763
+ data-testid={LayoutGridField.TEST_IDS.col}
764
+ {...gridProps}
765
+ >
766
+ {this.renderChildren([child])}
767
+ </GridTemplate>
768
+ ));
769
+ }
770
+
771
+ /** Renders a material-ui `GridTemplate` as a container. The
772
+ * `layoutGridSchema` for the `GridType.ROW` is separated into the `children` and other `gridProps`. The `gridProps`
773
+ * will be spread onto the outer `GridTemplate`. Inside of the `GridTemplate` all of the `children` are rendered.
774
+ *
775
+ * @param layoutGridSchema - The string or object that represents the configuration for the grid field
776
+ * @returns - The rendered `GridTemplate` containing the children for the `GridType.ROW`
777
+ */
778
+ renderRow(layoutGridSchema: GridSchemaType) {
779
+ const { registry, uiSchema } = this.props;
780
+ const { children, gridProps } = LayoutGridField.findChildrenAndProps<T, S, F>(
781
+ layoutGridSchema,
782
+ GridType.ROW,
783
+ registry,
784
+ );
785
+ const uiOptions = getUiOptions<T, S, F>(uiSchema);
786
+ const GridTemplate = getTemplate<'GridTemplate', T, S, F>('GridTemplate', registry, uiOptions);
787
+
788
+ return (
789
+ <GridTemplate {...gridProps} data-testid={LayoutGridField.TEST_IDS.row}>
790
+ {this.renderChildren(children)}
791
+ </GridTemplate>
792
+ );
793
+ }
794
+
795
+ /** Iterates through all the `childrenLayoutGridSchema`, rendering a nested `LayoutGridField` for each item in the
796
+ * list, passing all the props for the current `LayoutGridField` along, updating the `schema` by calling
797
+ * `retrieveSchema()` on it to resolve any `$ref`s. In addition to the updated `schema`, each item in
798
+ * `childrenLayoutGridSchema` is passed as `layoutGridSchema`.
799
+ *
800
+ * @param childrenLayoutGridSchema - The list of strings or objects that represents the configurations for the
801
+ * children fields
802
+ * @returns - The nested `LayoutGridField`s
803
+ */
804
+ renderChildren(childrenLayoutGridSchema: LayoutGridSchemaType[]) {
805
+ const { registry, schema: rawSchema, formData } = this.props;
806
+ const { schemaUtils } = registry;
807
+ const schema = schemaUtils.retrieveSchema(rawSchema, formData);
808
+
809
+ return childrenLayoutGridSchema.map((layoutGridSchema) => (
810
+ <LayoutGridField<T, S, F>
811
+ {...this.props}
812
+ key={`layoutGrid-${hashObject(layoutGridSchema)}`}
813
+ schema={schema}
814
+ layoutGridSchema={layoutGridSchema}
815
+ />
816
+ ));
817
+ }
818
+
819
+ /** Renders the field described by `gridSchema`. If `gridSchema` is not an object, then is will be assumed
820
+ * to be the dotted-path to the field in the schema. Otherwise, we extract the `name`, and optional `render` and all
821
+ * other props. If `name` does not exist and there is an optional `render`, we return the `render` component with only
822
+ * specified props for that component. If `name` exists, we take the name, the initial & root schemas and the formData
823
+ * and get the destination schema, is required state and optional oneOf/anyOf options for it. If the destination
824
+ * schema was located along with oneOf/anyOf options then a `LayoutMultiSchemaField` will be rendered with the
825
+ * `uiSchema`, `errorSchema`, `idSchema` and `formData` drilled down to the dotted-path field, spreading any other
826
+ * props from `gridSchema` into the `ui:options`. If the destination schema located without any oneOf/anyOf options,
827
+ * then a `SchemaField` will be rendered with the same props as mentioned in the previous sentence. If no destination
828
+ * schema was located, but a custom render component was found, then it will be rendered with many of the non-event
829
+ * handling props. If none of the previous render paths are valid, then a null is returned.
830
+ *
831
+ * @param gridSchema - The string or object that represents the configuration for the grid field
832
+ * @returns - One of `LayoutMultiSchemaField`, `SchemaField`, a custom render component or null, depending
833
+ */
834
+ renderField(gridSchema?: ConfigObject | string) {
835
+ const {
836
+ schema: initialSchema,
837
+ uiSchema,
838
+ errorSchema,
839
+ idSchema,
840
+ onBlur,
841
+ onFocus,
842
+ formData,
843
+ readonly,
844
+ registry,
845
+ idSeparator,
846
+ layoutGridSchema, // Used to pull this out of otherProps since we don't want to pass it through
847
+ ...otherProps
848
+ } = this.props;
849
+ const { fields, schemaUtils } = registry;
850
+ const { SchemaField, LayoutMultiSchemaField } = fields;
851
+ const uiComponentProps = LayoutGridField.computeUIComponentPropsFromGridSchema(registry, gridSchema);
852
+ if (uiComponentProps.rendered) {
853
+ return uiComponentProps.rendered;
854
+ }
855
+ const { name, UIComponent, uiProps } = uiComponentProps;
856
+ const {
857
+ schema,
858
+ isRequired,
859
+ isReadonly,
860
+ optionsInfo,
861
+ idSchema: fieldIdSchema,
862
+ } = LayoutGridField.getSchemaDetailsForField<T, S, F>(
863
+ schemaUtils,
864
+ name,
865
+ initialSchema,
866
+ formData,
867
+ idSchema,
868
+ idSeparator,
869
+ );
870
+
871
+ if (schema) {
872
+ const Field = optionsInfo?.hasDiscriminator ? LayoutMultiSchemaField : SchemaField;
873
+ // Call this function to get the appropriate UISchema, which will always have its `readonly` state matching the
874
+ // `uiReadonly` flag that it returns. This is done since the `SchemaField` will always defer to the `readonly`
875
+ // state in the uiSchema over anything in the props or schema. Because we are implementing the "readonly" state of
876
+ // the `Form` via the prop passed to `LayoutGridField` we need to make sure the uiSchema always has a true value
877
+ // when it is needed
878
+ const { fieldUiSchema, uiReadonly } = LayoutGridField.computeFieldUiSchema<T, S, F>(
879
+ name,
880
+ uiProps,
881
+ uiSchema,
882
+ isReadonly,
883
+ readonly,
884
+ );
885
+
886
+ return (
887
+ <Field
888
+ data-testid={
889
+ optionsInfo?.hasDiscriminator
890
+ ? LayoutGridField.TEST_IDS.layoutMultiSchemaField
891
+ : LayoutGridField.TEST_IDS.field
892
+ }
893
+ {...otherProps}
894
+ name={name}
895
+ required={isRequired}
896
+ readonly={uiReadonly}
897
+ schema={schema}
898
+ uiSchema={fieldUiSchema}
899
+ errorSchema={get(errorSchema, name)}
900
+ idSchema={fieldIdSchema}
901
+ idSeparator={idSeparator}
902
+ formData={get(formData, name)}
903
+ onChange={this.onFieldChange(name)}
904
+ onBlur={onBlur}
905
+ onFocus={onFocus}
906
+ options={optionsInfo?.options}
907
+ registry={registry}
908
+ />
909
+ );
910
+ }
911
+
912
+ if (UIComponent) {
913
+ return (
914
+ <UIComponent
915
+ data-testid={LayoutGridField.TEST_IDS.uiComponent}
916
+ {...otherProps}
917
+ name={name}
918
+ required={isRequired}
919
+ formData={formData}
920
+ readOnly={!!isReadonly || readonly}
921
+ errorSchema={errorSchema}
922
+ uiSchema={uiSchema}
923
+ schema={initialSchema}
924
+ idSchema={idSchema}
925
+ idSeparator={idSeparator}
926
+ onBlur={onBlur}
927
+ onFocus={onFocus}
928
+ registry={registry}
929
+ {...uiProps}
930
+ />
931
+ );
932
+ }
933
+ return null;
934
+ }
935
+
936
+ /** Renders the `LayoutGridField`. If there isn't a `layoutGridSchema` prop defined, then try pulling it out of the
937
+ * `uiSchema` via `ui:LayoutGridField`. If `layoutGridSchema` is an object, then check to see if any of the properties
938
+ * match one of the `GridType`s. If so, call the appropriate render function for the type. Otherwise, just call the
939
+ * generic `renderField()` function with the `layoutGridSchema`.
940
+ *
941
+ * @returns - the rendered `LayoutGridField`
942
+ */
943
+ render() {
944
+ const { uiSchema } = this.props;
945
+ let { layoutGridSchema } = this.props;
946
+ const uiOptions = getUiOptions<T, S, F>(uiSchema);
947
+ if (!layoutGridSchema && LAYOUT_GRID_UI_OPTION in uiOptions && isObject(uiOptions[LAYOUT_GRID_UI_OPTION])) {
948
+ layoutGridSchema = uiOptions[LAYOUT_GRID_UI_OPTION];
949
+ }
950
+
951
+ if (isObject(layoutGridSchema)) {
952
+ if (GridType.ROW in layoutGridSchema) {
953
+ return this.renderRow(layoutGridSchema as GridSchemaType);
954
+ }
955
+ if (GridType.COLUMN in layoutGridSchema) {
956
+ return this.renderCol(layoutGridSchema as GridSchemaType);
957
+ }
958
+ if (GridType.COLUMNS in layoutGridSchema) {
959
+ return this.renderColumns(layoutGridSchema as GridSchemaType);
960
+ }
961
+ if (GridType.CONDITION in layoutGridSchema) {
962
+ return this.renderCondition(layoutGridSchema as GridSchemaType);
963
+ }
964
+ }
965
+ return this.renderField(layoutGridSchema);
966
+ }
967
+ }